/* ============================================================
   Seven Affiliates — shared design system
   Every page (dashboard, media report, login) uses these tokens
   so the whole app feels like one consistent product.
   ============================================================ */

:root {
  --sa-blue: #2f5cff;
  --sa-blue-dark: #1f47db;
  --sa-blue-light: #eef3ff;
  --sa-green: #16a34a;
  --sa-green-light: #ecfdf3;
  --sa-red: #dc2626;
  --sa-red-light: #fef2f2;

  --sa-bg: #f7f8fa;
  --sa-card: #ffffff;
  --sa-border: #e6e8ec;
  --sa-text: #14161a;
  --sa-text-secondary: #6b7280;
  --sa-text-muted: #9ca3af;

  --sa-radius: 10px;
  --sa-radius-sm: 7px;
  --sa-sidebar-w: 248px;
  --sa-sidebar-w-collapsed: 76px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--sa-bg);
  color: var(--sa-text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: var(--sa-sidebar-w);
  flex-shrink: 0;
  background: var(--sa-card);
  border-right: 1px solid var(--sa-border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  transition: width 0.18s ease;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar.collapsed {
  width: var(--sa-sidebar-w-collapsed);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
  margin-bottom: 28px;
}

.sa-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
}

.sa-logo-mark {
  width: 30px;
  height: 30px;
  object-fit: contain;
  flex-shrink: 0;
  display: none;
}

.sa-logo-full {
  height: 38px;
  width: auto;
  object-fit: contain;
}

.sidebar.collapsed .sa-logo-mark { display: block; }
.sidebar.collapsed .sa-logo-full { display: none; }

.sidebar.collapsed .nav-label,
.sidebar.collapsed .profile-text,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .profile-logout-btn {
  display: none;
}

.sidebar-collapse-btn {
  border: 1px solid var(--sa-border);
  background: var(--sa-card);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--sa-text-secondary);
  flex-shrink: 0;
}
.sidebar-collapse-btn:hover {
  background: var(--sa-bg);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
}

.nav-section {
  margin-bottom: 2px;
}

.nav-item,
.nav-parent {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: var(--sa-radius-sm);
  color: var(--sa-text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 2px;
  white-space: nowrap;
}

.nav-item:hover,
.nav-parent:hover {
  background: var(--sa-bg);
  color: var(--sa-text);
}

.nav-item.active {
  background: var(--sa-blue-light);
  color: var(--sa-blue-dark);
}

.nav-item.disabled {
  cursor: default;
  opacity: 0.55;
}
.nav-item.disabled:hover {
  background: none;
  color: var(--sa-text-secondary);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-icon svg {
  width: 18px;
  height: 18px;
}

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  background: var(--sa-bg);
  color: var(--sa-text-muted);
  border: 1px solid var(--sa-border);
  padding: 1px 6px;
  border-radius: 20px;
}

.nav-chevron {
  margin-left: auto;
  transition: transform 0.15s ease;
  color: var(--sa-text-muted);
  flex-shrink: 0;
}
.nav-parent.open .nav-chevron {
  transform: rotate(90deg);
}

.nav-children {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.18s ease;
  padding-left: 29px;
}
.nav-parent.open + .nav-children {
  max-height: 240px;
}

.sidebar-profile {
  border-top: 1px solid var(--sa-border);
  padding-top: 14px;
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sa-blue-light);
  color: var(--sa-blue-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.profile-text {
  overflow: hidden;
  white-space: nowrap;
}
.profile-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--sa-text);
}
.profile-id {
  font-size: 12px;
  color: var(--sa-text-muted);
}

/* ---------- Main content ---------- */

.main {
  flex: 1;
  min-width: 0;
  padding: 26px 32px 60px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.page-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: var(--sa-radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 16px;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-primary {
  background: var(--sa-blue);
  color: #fff;
}
.btn-primary:hover {
  background: var(--sa-blue-dark);
}

.btn-outline {
  background: var(--sa-card);
  color: var(--sa-text);
  border-color: var(--sa-border);
}
.btn-outline:hover {
  background: var(--sa-bg);
}

.btn-ghost {
  background: transparent;
  color: var(--sa-text-secondary);
  border-color: var(--sa-border);
}
.btn-ghost:hover {
  background: var(--sa-bg);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12.5px;
}

/* ---------- "Viewing account" banner (Admin using View Account) ---------- */

.viewing-banner {
  background: #fef3c7;
  border-bottom: 1px solid #fcd34d;
  color: #78350f;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13.5px;
}
.viewing-banner-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.viewing-banner .btn-outline {
  background: transparent;
  border-color: #78350f;
  color: #78350f;
}
.viewing-banner .btn-outline:hover {
  background: rgba(120, 53, 15, 0.08);
}

/* ---------- Cards ---------- */

.card {
  background: var(--sa-card);
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius);
  padding: 20px;
}

.top-row {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 16px;
  margin-bottom: 20px;
}

.balance-label {
  font-size: 13px;
  color: var(--sa-text-secondary);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

.balance-amount {
  font-size: 30px;
  font-weight: 700;
  margin: 8px 0 6px;
  letter-spacing: -0.01em;
}

.balance-note {
  font-size: 12.5px;
  color: var(--sa-text-muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

.promote-card {
  display: flex;
  flex-direction: column;
}

.promote-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
}

.promote-sub {
  font-size: 12.5px;
  color: var(--sa-text-secondary);
  margin-bottom: 16px;
}

.promote-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.select,
.date-input {
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius-sm);
  padding: 8px 12px;
  font-size: 13.5px;
  background: var(--sa-card);
  color: var(--sa-text);
}

.promote-link-box {
  flex: 1;
  min-width: 220px;
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--sa-text-secondary);
  background: var(--sa-bg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--sa-border);
  background: var(--sa-card);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--sa-text-secondary);
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--sa-bg);
}

/* ---------- Date filter bar ---------- */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.date-range-group {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius-sm);
  padding: 4px 6px;
  background: var(--sa-card);
}

.date-range-group .date-input {
  border: none;
  padding: 4px 6px;
}

.date-arrow {
  color: var(--sa-text-muted);
}

/* ---------- KPI row ---------- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--sa-card);
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius);
  padding: 15px 16px;
  cursor: pointer;
}

.kpi-card.active {
  background: var(--sa-blue-light);
  border-color: #c9d8ff;
}

.kpi-label {
  font-size: 12.5px;
  color: var(--sa-text-secondary);
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.kpi-change {
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
}
.kpi-change.up { color: var(--sa-green); }
.kpi-change.down { color: var(--sa-red); }
.kpi-change.flat { color: var(--sa-text-muted); }

/* ---------- Chart card ---------- */

.chart-card {
  margin-bottom: 20px;
}

.chart-card-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 14px;
}

.chart-wrap {
  position: relative;
  height: 300px;
}

/* ---------- Section headers ---------- */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
}

.section-link {
  font-size: 13px;
  font-weight: 600;
  color: var(--sa-blue);
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
}

table.sa-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.sa-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--sa-text-muted);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--sa-border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

table.sa-table th.sortable:hover {
  color: var(--sa-text);
}

table.sa-table th .sort-arrow {
  margin-left: 4px;
  opacity: 0.4;
  font-size: 10px;
}
table.sa-table th.sort-active .sort-arrow {
  opacity: 1;
  color: var(--sa-blue);
}

table.sa-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--sa-border);
  white-space: nowrap;
}

table.sa-table tbody tr:hover {
  background: var(--sa-bg);
}

table.sa-table tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--sa-border);
  border-bottom: none;
  background: var(--sa-bg);
}

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
}
.pill-blue { background: var(--sa-blue-light); color: var(--sa-blue-dark); }
.pill-green { background: var(--sa-green-light); color: var(--sa-green); }
.pill-red { background: var(--sa-red-light); color: var(--sa-red); }
.pill-gray { background: var(--sa-bg); color: var(--sa-text-secondary); border: 1px solid var(--sa-border); }

/* ---------- Commission plan cards ---------- */

.plan-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.plan-card {
  background: var(--sa-card);
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius);
  padding: 20px;
}

.plan-brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.plan-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.plan-brand {
  font-size: 15px;
  font-weight: 700;
}

.plan-detail {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 12px;
}

.plan-desc {
  font-size: 12.5px;
  color: var(--sa-text-secondary);
  line-height: 1.5;
}

.glossary-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--sa-border);
}
.glossary-item:last-child {
  border-bottom: none;
}
.glossary-term {
  font-size: 13.5px;
  font-weight: 700;
  margin-bottom: 4px;
}
.glossary-desc {
  font-size: 13px;
  color: var(--sa-text-secondary);
  line-height: 1.55;
}

@media (max-width: 980px) {
  .plan-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Payments summary cards ---------- */

.summary-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.summary-card {
  background: var(--sa-card);
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius);
  padding: 18px 20px;
}

.summary-label {
  font-size: 12.5px;
  color: var(--sa-text-secondary);
  font-weight: 600;
  margin-bottom: 8px;
}

.summary-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.balance-edit-input {
  width: 100%;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius-sm);
  padding: 6px 10px;
  color: var(--sa-text);
  background: var(--sa-bg);
  font-family: inherit;
}
.balance-edit-input:focus {
  outline: none;
  border-color: var(--sa-blue);
  background: var(--sa-card);
}

@media (max-width: 720px) {
  .summary-row {
    grid-template-columns: 1fr;
  }
}

/* ---------- Report toolbar ---------- */

.report-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.report-toolbar-left,
.report-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-input {
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius-sm);
  padding: 8px 12px;
  font-size: 13.5px;
  width: 240px;
  background: var(--sa-card);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--sa-text-secondary);
}

.pagination button {
  border: 1px solid var(--sa-border);
  background: var(--sa-card);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  color: var(--sa-text-secondary);
}
.pagination button:hover:not(:disabled) {
  background: var(--sa-bg);
}
.pagination button.active {
  background: var(--sa-blue);
  color: #fff;
  border-color: var(--sa-blue);
}
.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- Dropdown (Select Columns) ---------- */

.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--sa-card);
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius-sm);
  box-shadow: 0 8px 24px rgba(20, 22, 26, 0.08);
  padding: 10px;
  min-width: 200px;
  z-index: 20;
  display: none;
}
.dropdown-menu.open {
  display: block;
}

.dropdown-menu label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 6px 4px;
  cursor: pointer;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 26, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--sa-card);
  border-radius: var(--sa-radius);
  padding: 24px;
  width: 340px;
  text-align: center;
}

.modal h3 {
  margin: 0 0 8px;
  font-size: 16px;
}
.modal p {
  color: var(--sa-text-secondary);
  font-size: 13.5px;
  margin: 0 0 18px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--sa-text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 200;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Login page ---------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sa-bg);
}

.login-card {
  width: 340px;
  background: var(--sa-card);
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius);
  padding: 32px;
}

.login-title {
  font-size: 18px;
  font-weight: 700;
  margin: 18px 0 4px;
  text-align: center;
}

.login-sub {
  font-size: 13px;
  color: var(--sa-text-secondary);
  text-align: center;
  margin-bottom: 22px;
}

.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--sa-text-secondary);
}
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--sa-border);
  border-radius: var(--sa-radius-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--sa-card);
  color: var(--sa-text);
}
.field textarea {
  resize: vertical;
  min-height: 64px;
}
.field-note {
  font-size: 12px;
  color: var(--sa-text-muted);
  margin-top: 5px;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ---------- Wide modal (Manage Account) ---------- */

.modal-wide {
  width: 560px;
  max-width: 92vw;
  text-align: left;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-wide h3 {
  text-align: left;
}

.manage-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--sa-border);
  margin-bottom: 18px;
}
.manage-tab-btn {
  padding: 9px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  color: var(--sa-text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.manage-tab-btn:hover {
  color: var(--sa-text);
}
.manage-tab-btn.active {
  color: var(--sa-blue);
  border-bottom-color: var(--sa-blue);
}
.manage-tab-panel {
  display: none;
}
.manage-tab-panel.active {
  display: block;
}
.manage-danger-row {
  display: flex;
  gap: 8px;
  padding-top: 14px;
  margin-top: 6px;
  border-top: 1px solid var(--sa-border);
}

.login-error {
  background: var(--sa-red-light);
  color: var(--sa-red);
  border-radius: var(--sa-radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

.login-card .btn-primary {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
}

.login-forgot-row {
  text-align: center;
  margin-top: 16px;
}

.login-forgot-link {
  font-size: 13px;
  color: var(--sa-text-secondary);
  text-decoration: none;
}
.login-forgot-link:hover {
  color: var(--sa-blue);
  text-decoration: underline;
}

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  .top-row {
    grid-template-columns: 1fr;
  }
  .kpi-row {
    grid-template-columns: repeat(3, 1fr);
  }
}

.mobile-menu-btn {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 720px) {
  .sidebar {
    position: fixed;
    z-index: 50;
    left: -100%;
    top: 0;
    transition: left 0.2s ease;
  }
  .sidebar.mobile-open {
    left: 0;
  }
  .main {
    padding: 18px;
  }
  .kpi-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .page-header {
    flex-wrap: wrap;
    gap: 10px;
  }
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--sa-border);
    background: var(--sa-card);
    color: var(--sa-text);
    cursor: pointer;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 60;
    box-shadow: 0 2px 8px rgba(20, 22, 26, 0.08);
  }
  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20, 22, 26, 0.35);
    z-index: 40;
  }
  .main {
    padding-top: 66px;
  }
}
