/* ═══════════════════════════════════════════════════════════════════════════
   DM Attribution — design system
   Navy chrome · cool canvas · DM indigo accent · mint for money
   Type: IBM Plex Sans (tabular figures for all numbers)
   ═══════════════════════════════════════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  /* Brand */
  --navy: #0E1633;
  --navy-2: #17214A;
  --navy-line: rgba(255,255,255,.07);
  --indigo: #2D40EA;
  --indigo-soft: #EEF0FE;
  --mint: #1DE5A7;
  --mint-ink: #0B8F66;
  --mint-soft: #E6FBF4;

  /* Neutrals */
  --canvas: #F5F7FB;
  --surface: #FFFFFF;
  --line: #E4E8F1;
  --line-soft: #EEF1F6;
  --ink: #101828;
  --ink-2: #344054;
  --muted: #5B6478;
  --faint: #8A93A6;

  /* Funnel stages — one color per stage, used everywhere */
  --s-lead: #8B98F6;
  --s-app: #2D40EA;
  --s-call: #0EA5E9;
  --s-sale: #10B981;

  /* Status */
  --ok: #0B8F66;   --ok-bg: #E6FBF4;   --ok-line: #B5F0DC;
  --warn: #B45309; --warn-bg: #FFF7E8; --warn-line: #FBDDA5;
  --err: #C0262D;  --err-bg: #FEF0F0;  --err-line: #F8C9CB;

  /* Legacy aliases (older pages use these) */
  --bg: var(--canvas); --border: var(--line); --border-light: var(--line-soft);
  --text: var(--ink); --text-muted: var(--muted); --text-faint: var(--faint);
  --primary: var(--indigo); --green: var(--ok); --green-bg: var(--ok-bg); --green-border: var(--ok-line);
  --red: var(--err); --red-bg: var(--err-bg); --red-border: var(--err-line);
  --yellow: var(--warn); --yellow-bg: var(--warn-bg); --yellow-border: var(--warn-line);
  --purple: var(--s-app); --purple-bg: var(--indigo-soft);

  --sidebar-width: 244px;
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px;
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--canvas); color: var(--ink);
  font-family: var(--font); font-size: 14px; line-height: 1.5;
  font-feature-settings: 'tnum' 1, 'cv05' 1;
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 2px solid var(--indigo); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width); background: var(--navy); color: #C9CEE0;
  position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 50;
}
.sidebar-brand { padding: 22px 20px 18px; border-bottom: 1px solid var(--navy-line); }
.sidebar-brand img { height: 22px; width: auto; display: block; }
.sidebar-brand .product { margin-top: 10px; font-size: 12px; color: #8C93B3; letter-spacing: .01em; }
/* old brand markup fallback */
.sidebar-brand .logo { display: none; }
.sidebar-brand .name { font-size: 15px; font-weight: 600; color: #fff; }
.sidebar-brand .sub { font-size: 12px; color: #8C93B3; }

.sidebar-nav { flex: 1; padding: 14px 12px; overflow-y: auto; }
.nav-section + .nav-section { margin-top: 14px; }
.nav-section-label { font-size: 12px; font-weight: 500; color: #6E769A; padding: 6px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; margin: 1px 0;
  border-radius: var(--r-sm); color: #B7BDD4; text-decoration: none; font-size: 14px; font-weight: 500;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--navy-2); color: #fff; }
.nav-item.active { background: var(--navy-2); color: #fff; box-shadow: inset 2px 0 0 var(--mint); }
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-item.active .icon { opacity: 1; color: var(--mint); }
.nav-badge { margin-left: auto; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: rgba(255,255,255,.1); color: #fff; }
.nav-badge.alert { background: #3A1F3A; color: #FFB4BA; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--navy-line); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--indigo); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 12px; }
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 12px; color: #8C93B3; text-transform: capitalize; }
.logout-btn { background: none; border: 0; color: #8C93B3; cursor: pointer; padding: 6px; border-radius: var(--r-sm); display: grid; place-items: center; }
.logout-btn svg { width: 16px; height: 16px; }
.logout-btn:hover { background: var(--navy-2); color: #fff; }

/* ── Page frame ──────────────────────────────────────────────────────────── */
.main { margin-left: var(--sidebar-width); min-width: 0; }
.topbar {
  height: 64px; padding: 0 32px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--canvas); position: sticky; top: 0; z-index: 40; border-bottom: 1px solid transparent;
}
.topbar.scrolled { background: rgba(245,247,251,.92); backdrop-filter: blur(8px); border-bottom-color: var(--line); }
.topbar h1 { font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.content { padding: 8px 32px 48px; max-width: 1440px; }

.section-label { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 28px 0 12px; }

/* ── Buttons & inputs ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 500 13px var(--font); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: #CDD3E0; background: #FAFBFD; }
.btn-primary { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.btn-primary:hover { background: #2434D0; border-color: #2434D0; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn-danger { color: var(--err); }
.btn-danger:hover { background: var(--err-bg); border-color: var(--err-line); }
.btn-push { color: var(--indigo); border-color: #C9CFFB; background: var(--indigo-soft); }
.btn-pushed { color: var(--ok); border-color: var(--ok-line); background: var(--ok-bg); cursor: default; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  width: 100%; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); font: 14px var(--font);
}
textarea { height: auto; padding: 10px 12px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(45,64,234,.12); }
label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }

/* Segmented control (period picker etc.) */
.seg { display: inline-flex; background: #E9ECF4; border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: none; font: 500 13px var(--font); color: var(--muted); padding: 5px 12px; border-radius: 6px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(16,24,40,.08); }

/* ── Panels ──────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); margin-bottom: 20px; overflow: hidden; }
.card-head { padding: 18px 22px; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; border-bottom: 1px solid var(--line-soft); }
.card-head h2 { font-size: 15px; font-weight: 600; }
.card-head p { font-size: 13px; color: var(--muted); margin-top: 2px; max-width: 72ch; }
.card-body { padding: 20px 22px; }

/* Stat tiles — quiet by design; the funnel pipeline is the hero */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px 18px; }
.stat-card .label { font-size: 13px; color: var(--muted); }
.stat-card .value { font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; line-height: 1.15; }
.stat-card .sub { font-size: 12px; color: var(--faint); margin-top: 4px; }
.stat-card.green .value, .stat-card.highlight .value { color: var(--mint-ink); }
.stat-card.blue .value { color: var(--indigo); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 16px; background: #FAFBFD; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 16px; border-bottom: 1px solid var(--line-soft); font-size: 13px; color: var(--ink-2); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #FAFBFD; }
td.num, th.num { text-align: right; }
.mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.mono-sm { font-family: var(--mono); font-size: 11px; color: var(--faint); word-break: break-all; }
.trunc { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Names (affiliates, offers): one line, truncate, full name on hover ─── */
.nm { display: inline-flex; align-items: baseline; gap: 6px; max-width: 220px; white-space: nowrap; }
.nm-t { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.nm-id { font-size: 11px; color: var(--faint); flex-shrink: 0; }
.faint { color: var(--faint); }
.nowrap { white-space: nowrap; }
.sub-line { font-size: 12px; color: var(--faint); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.person { font-weight: 500; color: var(--ink); white-space: nowrap; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px 24px; }
.detail-grid .k { font-size: 12px; color: var(--faint); }
.detail-grid .v { font-size: 13px; color: var(--ink-2); margin-top: 2px; word-break: break-all; }

/* ── Badges (stage colors match the chart) ───────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: #EEF1F6; color: var(--ink-2); white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge-lead { background: #F0F2FE; color: #4B5BD8; }
.badge-application { background: var(--indigo-soft); color: var(--s-app); }
.badge-call_booked, .badge-call, .badge-qualified_call { background: #E8F6FD; color: #0371A8; }
.badge-sale { background: var(--mint-soft); color: var(--mint-ink); }
.badge-click, .badge-pageview { background: #EEF1F6; color: var(--muted); }
.badge-confirmed, .badge-sent { background: var(--ok-bg); color: var(--ok); }
.badge-pending, .badge-review { background: var(--warn-bg); color: var(--warn); }
.badge-failed { background: var(--err-bg); color: var(--err); }
.badge-dismissed, .badge-skipped { background: #EEF1F6; color: var(--muted); }
.badge-HTO { background: var(--indigo-soft); color: var(--indigo); }
.badge-MTO { background: #E8F6FD; color: #0371A8; }
.badge-LTO { background: var(--mint-soft); color: var(--mint-ink); }
.badge-admin { background: var(--err-bg); color: var(--err); }
.badge-manager { background: var(--indigo-soft); color: var(--indigo); }
.badge-marketing { background: #E8F6FD; color: #0371A8; }
.badge-viewer { background: #EEF1F6; color: var(--muted); }

/* ── Status pill ─────────────────────────────────────────────────────────── */
.status-pill { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px; border-radius: 999px; font-size: 12px; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); }
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; }
.status-ok .dot { background: var(--s-sale); box-shadow: 0 0 0 3px var(--ok-bg); }
.status-warn .dot { background: #F59E0B; box-shadow: 0 0 0 3px var(--warn-bg); }
.status-err { color: var(--err); border-color: var(--err-line); }
.status-err .dot { background: var(--err); box-shadow: 0 0 0 3px var(--err-bg); }

/* ── Toggle ──────────────────────────────────────────────────────────────── */
.toggle { position: relative; width: 36px; height: 20px; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: #D0D5E2; border-radius: 20px; cursor: pointer; transition: background .15s; }
.toggle-slider::before { content: ''; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform .15s; }
.toggle input:checked + .toggle-slider { background: var(--indigo); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(14,22,51,.45); z-index: 1000; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--r-lg); width: 560px; max-width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 48px -12px rgba(14,22,51,.3); }
.modal-head { padding: 18px 22px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line-soft); }
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: 0; font-size: 22px; color: var(--faint); cursor: pointer; line-height: 1; }
.modal-body { padding: 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line-soft); display: flex; justify-content: flex-end; gap: 8px; }
.form-row { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-hint { font-size: 12px; color: var(--faint); margin-top: 5px; }

/* ── States ──────────────────────────────────────────────────────────────── */
.empty { padding: 48px 24px; text-align: center; color: var(--faint); }
.empty-icon { font-size: 26px; margin-bottom: 10px; }
.empty h3 { font-size: 15px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.loading { padding: 32px; text-align: center; color: var(--faint); font-size: 13px; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--indigo); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast { position: fixed; bottom: 24px; right: 24px; background: var(--navy); color: #fff; border-radius: var(--r-md); padding: 12px 16px; font-size: 13px; z-index: 1100; opacity: 0; transform: translateY(6px); transition: opacity .18s, transform .18s; pointer-events: none; max-width: 340px; }
#toast.show { opacity: 1; transform: none; }
#toast.tok { box-shadow: inset 3px 0 0 var(--mint); }
#toast.terr { box-shadow: inset 3px 0 0 #FF6B72; }

.pagination { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 14px; }
.pagination button { height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); cursor: pointer; font: 13px var(--font); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination .current { font-size: 13px; color: var(--muted); }

.acc-main { cursor: pointer; }
.acc-drawer { display: none; background: #FAFBFD; border-top: 1px solid var(--line-soft); }
.acc-drawer.open { display: block; }
.toggle-icon { color: var(--faint); font-size: 10px; display: inline-block; transition: transform .15s; }
.toggle-icon.open { transform: rotate(90deg); }

/* ═══ Overview: funnel pipeline (the hero) ═════════════════════════════════ */
.pipeline { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; margin-bottom: 20px; }
.stage { position: relative; padding: 22px 24px 20px; }
.stage + .stage { border-left: 1px solid var(--line-soft); }
.stage-bar { position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--c); }
.stage-name { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.stage-name i { width: 8px; height: 8px; border-radius: 2px; background: var(--c); }
.stage-value { font-size: 34px; font-weight: 600; letter-spacing: -.025em; line-height: 1.1; margin-top: 10px; }
.stage-sub { font-size: 12px; color: var(--faint); margin-top: 6px; min-height: 18px; }
.stage-delta { font-weight: 500; }
.stage-delta.up { color: var(--ok); } .stage-delta.down { color: var(--err); }
.stage-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stage-rate { font-size: 12px; font-weight: 600; color: var(--ink-2); background: #F2F4F9; border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.stage-rate small { font-size: 12px; font-weight: 400; color: var(--faint); }
.stage-arrow {
  position: absolute; left: 0; top: 50%; transform: translate(-50%, -50%); z-index: 2;
  width: 20px; height: 20px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--faint);
}
.stage-arrow svg { width: 10px; height: 10px; }
.stage.money .stage-value { color: var(--mint-ink); }

.ov-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 20px; align-items: start; }
.legend { display: flex; gap: 6px; flex-wrap: wrap; }
.legend button { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; height: 28px; padding: 0 11px; font: 500 12px var(--font); color: var(--ink-2); cursor: pointer; }
.legend button i { width: 10px; height: 3px; border-radius: 2px; background: var(--c); }
.legend button.off { color: var(--faint); background: #FAFBFD; }
.legend button.off i { background: #D0D5E2; }
.chart-box { position: relative; height: 380px; padding: 8px 18px 14px; }

.rank { list-style: none; }
.rank li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 22px; border-bottom: 1px solid var(--line-soft); }
.rank li:last-child { border-bottom: 0; }
.rank .who { font-size: 13px; font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank .what { font-size: 12px; color: var(--faint); }
.rank .amt { font-size: 13px; font-weight: 600; text-align: right; color: var(--ink); }
.rank .meter { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--line-soft); overflow: hidden; }
.rank .meter span { display: block; height: 100%; background: var(--indigo); border-radius: 2px; }

.health { display: grid; grid-template-columns: repeat(4, 1fr); }
.health > div { padding: 16px 22px; }
.health > div + div { border-left: 1px solid var(--line-soft); }
.health .k { font-size: 12px; color: var(--muted); }
.health .v { font-size: 20px; font-weight: 600; margin-top: 2px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1100px) { .ov-grid { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .main { margin-left: 0; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .pipeline, .health { grid-template-columns: 1fr 1fr; }
  .stage:nth-child(3) { border-left: 0; }
  .stage:nth-child(n+3) { border-top: 1px solid var(--line-soft); }
  .stage-arrow { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}