:root {
  color-scheme: dark;
  --page: #0e1626;
  --sidebar: #111b2e;
  --card: #1c2742;
  --tile: #172036;
  --border: #2a3758;
  --hairline: #243150;
  --text: #eef2fa;
  --text-2: #a9b4cc;
  --muted: #8390ad;
  --accent: #5b9cff;
  --accent-strong: #3987e5;
  --accent-wash: rgba(57, 135, 229, 0.16);
  /* status: marks/dots use the fixed status palette, text uses lighter readable tints */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-text: #34c38f;
  --bad-text: #ff6b7a;
  --warn-text: #f0a63a;
  /* chart series (validated against the card surface, dark mode) */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --radius: 16px;
  --radius-sm: 12px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 76px; flex: none; background: var(--sidebar); border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column; align-items: center; padding: 16px 0; gap: 6px;
  position: sticky; top: 0; height: 100vh;
}
.logo { width: 52px; height: 44px; display: grid; place-items: center; margin-bottom: 14px; }
.logo img { width: 100%; height: 100%; object-fit: contain; }
.top-logo { height: 26px; width: auto; margin-right: 12px; }
.topbar > .top-logo + .crumb { margin-right: auto; }
.login-logo { height: 56px; width: auto; display: block; margin-bottom: 20px; }
.nav-link {
  width: 52px; height: 46px; border-radius: 12px; display: grid; place-items: center; color: var(--text-2);
  position: relative;
}
.nav-link:hover { background: var(--tile); text-decoration: none; color: var(--text); }
.nav-link.active { background: #1e3a6b; color: var(--text); }
.nav-link .tip {
  position: absolute; left: 60px; background: #0b1220; border: 1px solid var(--border); color: var(--text);
  padding: 4px 10px; border-radius: 8px; white-space: nowrap; font-size: 12px; opacity: 0; pointer-events: none;
  transition: opacity .12s; z-index: 20;
}
.nav-link:hover .tip, .nav-link:focus-visible .tip { opacity: 1; }
.sidebar .spacer { flex: 1; }
.sidebar form button { background: none; border: 0; cursor: pointer; }

.main { flex: 1; min-width: 0; }
.topbar {
  height: 64px; border-bottom: 1px solid var(--hairline); display: flex; align-items: center;
  justify-content: space-between; padding: 0 32px; gap: 16px; background: rgba(17, 27, 46, 0.6);
  position: sticky; top: 0; backdrop-filter: blur(6px); z-index: 10;
}
.crumb { color: var(--text-2); font-size: 15px; }
.crumb b { color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 18px; color: var(--text-2); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; background: var(--good); }
.dot.warn { background: var(--warning); }
.dot.bad { background: var(--critical); }
.pill { border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--text-2); }

.content { padding: 28px 32px 48px; max-width: 1360px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; flex-wrap: wrap; margin-bottom: 24px; }
.eyebrow { color: var(--accent); font-weight: 700; letter-spacing: .12em; font-size: 12px; text-transform: uppercase; }
h1 { font-size: 30px; margin: 6px 0 6px; font-weight: 700; letter-spacing: -0.01em; }
.subtitle { color: var(--text-2); margin: 0; max-width: 520px; }
h2 { font-size: 18px; margin: 0; font-weight: 650; }
.card-sub { color: var(--text-2); font-size: 13px; margin: 4px 0 0; }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; max-width: 640px; }
.filter {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px 6px;
  display: flex; flex-direction: column; min-width: 130px;
}
.filter label { font-size: 11px; color: var(--text-2); }
.filter select {
  background: transparent; border: 0; color: var(--text); font: inherit; font-size: 14px; padding: 0; outline: none;
  cursor: pointer;
}
.filter select option { background: var(--card); }
.filter:focus-within { border-color: var(--accent-strong); }
.clear-filters { align-self: center; font-size: 13px; }
.filter-context { color: var(--text-2); font-size: 12px; margin: -12px 0 18px; }

/* ---------- cards ---------- */
.grid { display: grid; gap: 18px; }
.kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 18px; }
.two { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); margin-bottom: 18px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.card-head a { font-size: 13px; font-weight: 600; white-space: nowrap; }

a.kpi { display: block; color: inherit; transition: border-color .12s, transform .12s; }
a.kpi:hover { text-decoration: none; border-color: var(--accent-strong); }
.kpi .label { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); }
.kpi .value { font-size: 30px; font-weight: 700; margin: 10px 0 4px; letter-spacing: -0.01em; }
.kpi .note { font-size: 13px; color: var(--text-2); }
.est { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 0 5px; margin-left: 6px; vertical-align: 2px; letter-spacing: 0; text-transform: none; font-weight: 500; }

.t-good { color: var(--good-text); }
.t-bad { color: var(--bad-text); }
.t-warn { color: var(--warn-text); }
.t-muted { color: var(--muted); }

/* funnel */
.funnel { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; align-items: stretch; }
.step { background: var(--tile); border-radius: var(--radius-sm); padding: 16px; position: relative; color: inherit; display: block; }
a.step:hover { text-decoration: none; outline: 1px solid var(--accent-strong); }
.step:not(:last-child)::after { content: "›"; position: absolute; right: -9px; top: 50%; transform: translateY(-50%); color: var(--text-2); font-size: 18px; }
.step .big { font-size: 26px; font-weight: 700; }
.step .lbl { color: var(--text-2); margin: 4px 0 8px; }
.step .sub { font-size: 13px; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.tile { background: var(--tile); border-radius: var(--radius-sm); padding: 14px 16px; }
.tile .lbl { color: var(--text-2); font-size: 13px; }
.tile .big { font-size: 20px; font-weight: 700; margin-top: 4px; }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); padding: 10px 8px; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
td { padding: 12px 8px; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.name { font-weight: 600; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
td a { color: inherit; }
td a:hover { color: var(--accent); }
.heat { border-radius: 6px; padding: 3px 8px; display: inline-block; min-width: 46px; text-align: center; }

/* alerts & queue */
.alert { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--hairline); align-items: flex-start; }
.alert:last-child { border-bottom: 0; }
.alert .sev { flex: none; margin-top: 4px; }
.alert .body { flex: 1; min-width: 0; }
.alert .title { font-weight: 650; font-size: 15px; color: var(--text); }
.alert .detail { color: var(--text-2); font-size: 13px; }
.alert .owner { flex: none; background: var(--tile); border-radius: 10px; padding: 8px 12px; font-size: 12px; color: var(--text-2); text-align: center; }
.sev-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.sev-critical { color: var(--bad-text); }
.sev-high { color: var(--warn-text); }
.sev-medium { color: var(--text-2); }
.sev-icon { width: 14px; height: 14px; }

.queue-item { background: var(--tile); border-radius: var(--radius-sm); padding: 16px 18px; display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; color: inherit; }
a.queue-item:hover { text-decoration: none; outline: 1px solid var(--accent-strong); }
.queue-item .title { font-weight: 650; font-size: 15px; }
.queue-item .detail { color: var(--text-2); font-size: 13px; margin-top: 4px; }
.queue-item .val { text-align: right; flex: none; }
.queue-item .val b { color: var(--bad-text); font-size: 16px; display: block; }
.queue-item .val span { color: var(--text-2); font-size: 12px; }

/* status badge */
.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; border: 1px solid var(--border); color: var(--text); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.badge.good::before { background: var(--good); }
.badge.bad::before { background: var(--critical); }
.badge.warn::before { background: var(--warning); }
.badge.info::before { background: var(--accent-strong); }

/* chart */
.chart-box { position: relative; height: 260px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 16px; color: var(--text-2); font-size: 13px; margin-top: 12px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 8px; }
.swatch-line { width: 18px; height: 2px; background: var(--series-1); display: inline-block; border-radius: 2px; }
.swatch-dash { width: 18px; height: 0; border-top: 2px dashed var(--serious); display: inline-block; }
.table-toggle { font-size: 13px; color: var(--accent); cursor: pointer; background: none; border: 0; padding: 0; }
.sr-table { margin-top: 12px; }

/* forms / buttons */
.btn { background: var(--accent-strong); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: #2a78d6; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], select.input {
  background: var(--tile); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; width: 100%;
}
input:focus, select.input:focus { outline: none; border-color: var(--accent-strong); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select.input { width: auto; }
.notice { background: var(--tile); border: 1px solid var(--border); border-left: 3px solid var(--warning); border-radius: 10px; padding: 12px 14px; color: var(--text-2); font-size: 13px; margin-bottom: 18px; }
.notice.ok { border-left-color: var(--good); }
.notice.err { border-left-color: var(--critical); }
code, pre { background: var(--tile); border-radius: 6px; padding: 1px 6px; font-size: 12.5px; }
pre { padding: 12px; overflow-x: auto; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; }
.login-card h1 { font-size: 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; color: var(--text-2); font-size: 13px; margin-bottom: 6px; }
.error { color: var(--bad-text); font-size: 13px; margin-bottom: 12px; }

/* agent view */
.status-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.status-chips button { background: var(--card); border: 1px solid var(--border); color: var(--text-2); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.status-chips button.on { border-color: var(--accent-strong); color: var(--text); background: var(--accent-wash); }

@media (max-width: 1100px) {
  .two { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .funnel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .step:not(:last-child)::after { display: none; }
}
@media (max-width: 640px) {
  .sidebar { display: none; }
  .content { padding: 20px 16px 40px; }
  .topbar { padding: 0 16px; }
  .kpis, .tiles { grid-template-columns: minmax(0, 1fr); }
  .filters { justify-content: flex-start; }
  .topbar-right .pill { display: none; }
}

/* ---------- v2: period selector, lead flow, trend, detail ---------- */
.head-controls { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.periods { display: inline-flex; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.periods a { color: var(--text-2); font-size: 13px; padding: 5px 12px; border-radius: 8px; white-space: nowrap; }
.periods a:hover { text-decoration: none; color: var(--text); background: var(--tile); }
.periods a.on { background: var(--accent-strong); color: #fff; font-weight: 600; }
.unit { font-size: 15px; font-weight: 500; color: var(--text-2); margin-left: 3px; }
a.kpi.cta { border-style: dashed; }
a.kpi.cta .value { color: var(--text-2); }

.flow { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.flow-col { background: var(--tile); border-radius: var(--radius-sm); padding: 14px; min-width: 0; }
.flow-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--hairline); }
.flow-head span { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-2); }
.flow-head b { font-size: 20px; }
.flow-stage { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 7px 8px; margin: 0 -8px; border-radius: 8px; color: var(--text); font-size: 13px; }
.flow-stage:hover { background: rgba(255, 255, 255, 0.04); text-decoration: none; }
.flow-name { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flow-count { font-weight: 700; font-variant-numeric: tabular-nums; }
.flow-bar { grid-column: 1 / -1; height: 4px; background: var(--hairline); border-radius: 4px; overflow: hidden; }
.flow-bar i { display: block; height: 100%; background: var(--series-1); border-radius: 4px; }
.flow-empty { font-size: 13px; margin: 6px 0; }
.tone-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--accent-strong); }
.tone-dot.good { background: var(--good); }
.tone-dot.bad { background: var(--critical); }
.tone-dot.warn { background: var(--warning); }
.tone-dot.neutral { background: var(--muted); }

.trend-totals { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: -4px 0 12px; color: var(--text-2); font-size: 13px; }
.trend-totals div { display: inline-flex; align-items: center; gap: 8px; }
.trend-totals b { color: var(--text); font-size: 15px; }
.swatch-line.s1 { background: var(--series-1); }
.swatch-line.s2 { background: var(--series-2); }
.swatch-line.s3 { background: var(--series-3); }
.swatch-line.s4 { background: var(--series-4); }

.empty-chart { height: 260px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 8px; border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 24px; color: var(--text-2); font-size: 13px; }
.empty-chart b { color: var(--text); font-size: 15px; }

.timeline { list-style: none; margin: 12px 0 0; padding: 0 0 0 14px; border-left: 2px solid var(--hairline); }
.timeline li { position: relative; padding: 0 0 14px 14px; display: flex; gap: 14px; }
.timeline li::before { content: ""; position: absolute; left: -21px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent-strong); border: 2px solid var(--card); }
.timeline .when { color: var(--text-2); font-variant-numeric: tabular-nums; min-width: 96px; }

.rate-input { width: 110px !important; text-align: right; padding: 7px 10px !important; }
.summary-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; }
.summary-tiles .kpi .value { margin-bottom: 0; }

@media (max-width: 1100px) { .flow { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) { .summary-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } .head-controls { align-items: flex-start; } }
@media (max-width: 640px) { .flow { grid-template-columns: minmax(0, 1fr); } }
