/* KARVED client report — theme tokens.
   Light theme is the default: white page, blue as the working colour, gold as the accent.
   The original dark palette is kept under [data-theme="dark"]; set that attribute on <html> to switch. */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f6fb;
  --text: #0d1129;
  --text-2: #3d4460;
  --text-muted: #6e7691;
  --text-faint: #8a91a6;
  --line: #e3e7f0;
  --line-strong: #cbd2e1;
  --primary: #1d4ed8;
  --primary-hover: #1a45bf;
  --primary-wash: rgba(29, 78, 216, 0.08);
  --primary-ring: rgba(29, 78, 216, 0.35);
  --accent: #c4a44a;
  --accent-light: #e8d5a3;
  --accent-text: #8a6f1f;
  --accent-ring: rgba(196, 164, 74, 0.6);
  --accent-gradient: linear-gradient(90deg, #c4a44a, #e8d5a3);
  --chart-1: #1d4ed8;
  --chart-1-hover: #3b66e3;
  --chart-2: #a47e22;
  --chart-2-hover: #b8912f;
  --chart-muted: #7f8aa3;
  --chart-muted-hover: #949eb5;
  --chart-grid: rgba(13, 17, 41, 0.08);
  --chart-axis: rgba(13, 17, 41, 0.3);
  --chart-wash: rgba(29, 78, 216, 0.1);
  --chart-crosshair: rgba(29, 78, 216, 0.35);
  --chart-heat-rgb: 29, 78, 216;
  --chart-heat-ink-strong: #ffffff;
  --chart-heat-ink-weak: #0d1129;
  --tooltip-bg: #0d1129;
  --tooltip-border: rgba(255, 255, 255, 0.15);
  --tooltip-text: #ffffff;
  --tooltip-body: #b8b0a0;
  --card-shadow: 0 1px 2px rgba(13, 17, 41, 0.04);
  --radius: 8px;
  --head: 'Norwester', 'Montserrat', system-ui, sans-serif;
  --body: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #0d1129;
  --surface: #111828;
  --surface-2: rgba(255, 255, 255, 0.04);
  --text: #ffffff;
  --text-2: #b8b0a0;
  --text-muted: #b8b0a0;
  --text-faint: #6a6458;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --primary: #e8d5a3;
  --primary-hover: #f3e6c4;
  --primary-wash: rgba(232, 213, 163, 0.08);
  --primary-ring: rgba(232, 213, 163, 0.35);
  --accent: #c4a44a;
  --accent-light: #e8d5a3;
  --accent-text: #e8d5a3;
  --accent-ring: rgba(232, 213, 163, 0.45);
  --chart-1: #e8d5a3;
  --chart-1-hover: #f3e6c4;
  --chart-2: #6a6458;
  --chart-2-hover: #857e70;
  --chart-muted: #6a6458;
  --chart-muted-hover: #857e70;
  --chart-grid: rgba(255, 255, 255, 0.08);
  --chart-axis: rgba(255, 255, 255, 0.3);
  --chart-wash: rgba(232, 213, 163, 0.1);
  --chart-crosshair: rgba(232, 213, 163, 0.35);
  --chart-heat-rgb: 232, 213, 163;
  --chart-heat-ink-strong: #0d1129;
  --chart-heat-ink-weak: #ffffff;
  --tooltip-bg: #080808;
  --tooltip-border: rgba(232, 213, 163, 0.25);
  --card-shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-2);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.55;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand .logo { height: 44px; width: auto; }
.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.24em;
  color: var(--primary);
  text-transform: uppercase;
}
h1 {
  font-family: var(--head);
  font-weight: 400;
  text-transform: uppercase;
  color: var(--text);
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1;
  margin: 4px 0 0;
  letter-spacing: 0.01em;
}
.status { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--text-muted); }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
}
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--accent);
  transform: rotate(45deg);
}
.badge.demo { color: var(--accent-text); border-color: var(--accent-ring); }
.gold-rule { height: 2px; background: var(--accent-gradient); margin: 24px 0; opacity: 0.9; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 4px;
  padding: 10px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.btn-gold { background: var(--accent-gradient); color: #0d1129; }
.btn-gold:hover { filter: brightness(1.05); }
.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary-ring);
  padding: 7px 14px;
}
.btn-ghost:hover { background: var(--primary-wash); }
.btn:focus-visible, select:focus-visible, .seg button:focus-visible, .btn-table:focus-visible, summary:focus-visible, input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.btn[disabled] { opacity: 0.5; cursor: progress; }

/* ---------- banner ---------- */
.banner {
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 24px;
  color: var(--text);
  font-size: 14px;
}
.banner p { margin: 0; }
.banner p + p { margin-top: 6px; color: var(--text-2); }
.banner strong { color: var(--primary); font-weight: 600; }
.banner a { color: var(--primary); }

/* ---------- filters ---------- */
.filters {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 3px;
  gap: 2px;
  flex-wrap: wrap;
  background: var(--surface);
}
.seg button {
  background: transparent;
  border: 0;
  border-radius: 4px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
}
.seg button:hover { color: var(--text); background: var(--surface-2); }
.seg button[aria-pressed='true'] { background: var(--primary-wash); color: var(--primary); font-weight: 600; }
.select { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }
.select span { font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; font-size: 11px; }
.select select {
  appearance: none;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%231D4ED8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 34px 8px 12px;
  color: var(--text);
  font-size: 13px;
  max-width: 220px;
}
:root[data-theme='dark'] .select select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23E8D5A3' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}

main { transition: opacity 0.2s; }
main.loading { opacity: 0.45; pointer-events: none; }

/* ---------- KPI tiles ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 18px 20px 16px;
  min-width: 0;
}
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.kpi-value {
  font-family: var(--head);
  font-size: clamp(30px, 3.2vw, 40px);
  line-height: 1.1;
  color: var(--primary);
  margin: 8px 0 6px;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}
.kpi-sub { font-size: 13px; color: var(--text-2); line-height: 1.45; }
.kpi-sub .delta { color: var(--text); font-weight: 600; }

/* ---------- cards & grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 20px 22px;
  min-width: 0;
}
.card.wide { grid-column: 1 / -1; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}
.card h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text);
}
.card .sub { margin: 4px 0 0; font-size: 13px; color: var(--text-muted); }
.btn-table {
  flex: none;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--text-muted);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 10px;
  cursor: pointer;
}
.btn-table:hover { color: var(--text); }
.btn-table[aria-pressed='true'] { color: var(--primary); border-color: var(--primary-ring); }
.chart-box { position: relative; height: 300px; }
.chart-box.short { height: 260px; }
.empty {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 120px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

.section-note { margin: -8px 0 16px; font-size: 13px; color: var(--text-muted); max-width: 72ch; }
.section-title {
  font-family: var(--head);
  font-weight: 400;
  text-transform: uppercase;
  color: var(--text);
  font-size: 24px;
  margin: 40px 0 16px;
}

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--line); color: var(--text); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.muted { color: var(--text-2); }
tbody tr:hover td { background: var(--surface-2); }
.table-view { max-height: 360px; overflow: auto; }
tr.selected td { background: var(--primary-wash); }
tr.selected td:first-child { box-shadow: inset 2px 0 0 var(--primary); }

/* ---------- cohort heatmap ---------- */
.cohort td, .cohort th { text-align: center; padding: 0; border: 0; vertical-align: middle; }
.cohort th { padding: 6px 4px; }
.cohort th:first-child, .cohort td.row-head { text-align: left; padding: 0 12px 0 0; white-space: nowrap; color: var(--text-muted); font-size: 12px; }
.cohort td.size { color: var(--text-muted); font-size: 12px; padding-right: 10px; text-align: right; font-variant-numeric: tabular-nums; }
.cohort td.cell { padding: 1px; }
.cohort .cell span {
  display: block;
  min-width: 42px;
  padding: 7px 4px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.cohort tbody tr:hover td { background: transparent; }
.scale { display: flex; align-items: center; gap: 10px; font-size: 12px; margin-top: 12px; color: var(--text-muted); }
.scale i { display: block; width: 140px; height: 8px; border-radius: 2px; background: linear-gradient(90deg, rgba(var(--chart-heat-rgb), 0.08), rgba(var(--chart-heat-rgb), 0.92)); }

/* ---------- data check ---------- */
details.check {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  margin-top: 40px;
}
details.check > summary {
  cursor: pointer;
  list-style: none;
  padding: 18px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
details.check > summary::-webkit-details-marker { display: none; }
details.check > summary h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text);
}
details.check > summary .sub { font-size: 13px; color: var(--text-muted); margin: 2px 0 0; }
details.check > summary::after {
  content: '';
  flex: none;
  width: 8px;
  height: 8px;
  border-right: 1.5px solid var(--primary);
  border-bottom: 1.5px solid var(--primary);
  transform: rotate(45deg);
  transition: transform 0.2s;
}
details.check[open] > summary::after { transform: rotate(-135deg); }
.check-body { padding: 0 22px 22px; }
.check-body h3 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--primary);
  margin: 28px 0 10px;
}
.check-body p { margin: 0 0 8px; }
.check-body ul { margin: 0; padding-left: 0; list-style: none; }
.check-body li { position: relative; padding-left: 18px; margin-bottom: 6px; }
.check-body li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 0.65em;
  width: 5px;
  height: 5px;
  background: var(--accent);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12px;
  color: var(--text);
  background: var(--surface);
}
.chip b { font-weight: 600; color: var(--text-muted); margin-left: 6px; }
.chip.churn, .chip.renew { border-color: var(--accent-ring); }
.chip.churn::after { content: 'counts as left'; margin-left: 8px; color: var(--accent-text); font-size: 11px; }
.chip.renew::after { content: 'counts as renewed'; margin-left: 8px; color: var(--accent-text); font-size: 11px; }
.flag {
  display: inline-block;
  border: 1px solid var(--accent-ring);
  color: var(--accent-text);
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 1px 6px;
}
.pipe { padding: 12px 0; border-bottom: 1px solid var(--line); }
.pipe:last-child { border-bottom: 0; }
.pipe-name { color: var(--text); font-weight: 600; }
.defs dt { color: var(--text); font-weight: 600; margin-top: 10px; }
.defs dd { margin: 2px 0 0; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--primary);
}
.foot { margin-top: 32px; font-size: 12px; color: var(--text-faint); }

/* ---------- login ---------- */
.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 16px;
  z-index: 10;
}
.login form {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 32px 28px;
}
.login h1 { font-size: 32px; }
.login p { margin: 12px 0 20px; font-size: 14px; }
.login input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 12px 14px;
  color: var(--text);
  margin-bottom: 14px;
}
.login .btn { width: 100%; }
.login .err { color: var(--accent-text); font-size: 13px; margin: -4px 0 12px; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .app { padding: 20px 16px 48px; }
  .kpis { gap: 10px; }
  .kpi { padding: 14px; }
  .card { padding: 16px; }
  .chart-box { height: 260px; }
  .filters { gap: 12px; }
  .select { width: 100%; justify-content: space-between; }
  .select select { max-width: none; flex: 1; }
  .status { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
