:root {
  --bg: #000;
  --panel: #0a0a0a;
  --text: #ececec;
  --muted: #8b8b8b;
  --faint: #555;
  --line: #1d1d1d;
  --grid: #161616;
  --accent: #e8875f;
  --added: #8fd16a;
  --removed: #ef6f6f;
  --hover: #141414;
  --sans: "Geist", system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #fbfbfa;
  --panel: #f3f3f1;
  --text: #161616;
  --muted: #6b6b6b;
  --faint: #a5a5a5;
  --line: #e4e4e1;
  --grid: #ececea;
  --accent: #c45a32;
  --added: #3d8f1f;
  --removed: #c93a3a;
  --hover: #efefec;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 13px/1.45 var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  height: 60px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.brand { font-size: 23px; letter-spacing: -0.03em; text-decoration: none; white-space: nowrap; }
.brand span { font-weight: 300; color: var(--muted); }
.groups, .tabs { display: flex; gap: 22px; height: 100%; align-items: stretch; }
.groups button { font-size: 12px; color: var(--muted); white-space: nowrap; }
.groups button.active { color: var(--text); }
.divider { width: 1px; height: 28px; background: var(--line); flex: none; }
.tabs button { position: relative; color: var(--muted); white-space: nowrap; }
.tabs button.active { color: var(--text); }
.tabs button.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--accent);
}
.tabs button:hover, .groups button:hover { color: var(--text); }
.tools { margin-left: auto; display: flex; align-items: center; gap: 18px; flex: none; }
.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.check input { accent-color: var(--accent); margin: 0; }
.icon { color: var(--muted); display: grid; place-items: center; }
.icon:hover { color: var(--text); }

/* layout */
.layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 250px; min-height: 0; }
main { padding: 26px 28px 20px; min-width: 0; display: flex; flex-direction: column; }
.sidebar { border-left: 1px solid var(--line); padding: 22px 18px; }
.footer {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  border-top: 1px solid var(--line); padding: 12px 28px; color: var(--muted); font-size: 11px;
}

/* view header */
.view-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.view-head h1 { font-size: 22px; font-weight: 500; letter-spacing: -0.02em; margin: 0; }
.view-head .sub { color: var(--muted); font-size: 11px; }
.view-head .right { margin-left: auto; display: flex; gap: 16px; align-items: center; }
.controls { display: flex; gap: 22px; flex-wrap: wrap; margin: 14px 0 4px; align-items: center; }
.chips { display: flex; gap: 14px; row-gap: 8px; align-items: center; flex-wrap: wrap; }
.chips + .chips { padding-left: 22px; border-left: 1px solid var(--line); }
.chip { color: var(--muted); font-size: 11.5px; padding-bottom: 3px; border-bottom: 1px solid transparent; white-space: nowrap; }
.chip.active { color: var(--text); border-bottom-color: var(--text); }
.chip:hover { color: var(--text); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 18px; margin: 22px 0 18px; }
.kpi .label { color: var(--muted); font-size: 11.5px; display: flex; gap: 6px; align-items: center; }
.kpi .value { font-size: 34px; letter-spacing: -0.03em; font-weight: 400; line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 13px; color: var(--muted); margin-left: 3px; letter-spacing: 0; }
.kpi .hint { color: var(--muted); font-size: 11px; }
.kpi.lead .value { color: var(--accent); }

/* charts */
/* A fixed height: flex-growing would track the sidebar's length and stretch the chart. */
.chart { position: relative; height: clamp(340px, calc(100vh - 420px), 680px); margin-top: 6px; }
.chart .u-legend { display: none; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; display: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; font-size: 11.5px; min-width: 150px; max-width: 320px;
}
.tooltip .t-title { color: var(--muted); margin-bottom: 4px; }
.tooltip .t-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.tooltip .t-row span:first-child { display: flex; gap: 6px; align-items: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; display: inline-block; }
.note { color: var(--muted); font-size: 11px; margin-top: 10px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* sidebar */
.side-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.side-head h2 { font-size: 15px; font-weight: 500; margin: 0; }
.side-head h2 small { color: var(--muted); font-weight: 400; font-size: 11px; margin-left: 6px; }
.side-actions { display: flex; gap: 12px; font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.side-actions button:hover { color: var(--text); }
.search { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--text); padding: 6px 0; font: inherit; font-size: 12px; margin-bottom: 14px; outline: none; }
.search::placeholder { color: var(--faint); }
.side-section { font-size: 11.5px; font-weight: 500; margin: 16px 0 6px; display: flex; justify-content: space-between; }
.side-section .chips { gap: 10px; }
.series-list { list-style: none; margin: 0; padding: 0; }
.series-list li button {
  width: 100%; display: flex; align-items: center; gap: 9px; padding: 6px 4px; border-radius: 4px; text-align: left;
}
.series-list li button:hover { background: var(--hover); }
.series-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.series-list .share { color: var(--muted); font-size: 11px; }
.series-list .off { color: var(--faint); }
.series-list .off .dot { background: transparent !important; box-shadow: inset 0 0 0 1px var(--faint); }
.facts { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 16px; font-size: 11.5px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0 0 9px; }

/* bars (churn) */
.bars { margin-top: 18px; display: grid; gap: 2px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 170px) 1fr 120px; gap: 14px; align-items: center; padding: 5px 0; }
.bar-row .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: flex; height: 12px; gap: 1px; }
.bar-track .a { background: var(--added); opacity: .85; }
.bar-track .r { background: var(--removed); opacity: .85; }
.bar-row .figures { text-align: right; font-size: 11.5px; color: var(--muted); }
.bar-row .figures b { font-weight: 400; color: var(--added); }
.bar-row .figures i { font-style: normal; color: var(--removed); }

/* heatmap */
.heat { margin-top: 18px; display: grid; gap: 3px; }
.heat-row { display: grid; gap: 3px; align-items: center; }
.heat-cell { height: 30px; border-radius: 3px; background: var(--grid); position: relative; }
.heat-label { color: var(--muted); font-size: 11px; }
.heat-cell[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; bottom: 120%; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); padding: 4px 8px; border-radius: 4px; white-space: nowrap; font-size: 11px; z-index: 3;
}

/* timeline */
.timeline { margin-top: 18px; position: relative; }
.tl-axis { position: relative; height: 22px; margin-left: 180px; border-bottom: 1px solid var(--line); }
.tl-axis span { position: absolute; transform: translateX(-50%); color: var(--muted); font-size: 11px; white-space: nowrap; }
.tl-row { display: grid; grid-template-columns: 180px 1fr; align-items: center; height: 19px; }
.tl-row:hover { background: var(--hover); }
.tl-name { font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 10px; }
.tl-name span { color: var(--muted); }
.tl-track { position: relative; height: 100%; }
.tl-bar { position: absolute; top: 5px; height: 9px; border-radius: 2px; min-width: 4px; }
.tl-week { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--grid); }

/* tables */
.table-wrap { margin-top: 18px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { text-align: left; font-weight: 400; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; }
th.sorted { color: var(--text); }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.r, th.r { text-align: right; }
tr.row { cursor: pointer; }
tr.row:hover td { background: var(--hover); }
tr.detail td { color: var(--muted); padding: 4px 10px 14px; }
tr.detail p { margin: 0 0 6px; max-width: 880px; white-space: pre-line; }
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

/* text views */
.weeks { margin-top: 20px; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.week { padding: 16px 18px; border: 1px solid var(--line); margin: 0 -1px -1px 0; }
.week h3 { margin: 0 0 10px; font-size: 13px; font-weight: 500; display: flex; justify-content: space-between; }
.week h3 span { color: var(--muted); font-weight: 400; font-size: 11.5px; }
.week ol { margin: 0 0 10px; padding-left: 18px; }
.week li { margin-bottom: 6px; color: var(--text); }
.week .kind { font-size: 11px; color: var(--muted); margin: 8px 0 4px; }
.week .challenge li::marker { color: var(--accent); }
.cards { margin-top: 20px; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.card { padding: 16px 18px; scroll-margin-top: 20px; border: 1px solid var(--line); margin: 0 -1px -1px 0; }
.card h3 { margin: 0 0 6px; font-size: 14px; font-weight: 500; }
.card .k { color: var(--muted); font-size: 11px; margin-top: 10px; }
.card p { margin: 2px 0 0; }
.empty { color: var(--muted); padding: 40px 0; }

@media (max-width: 900px) {
  .topbar { padding: 10px 16px 0; gap: 18px; row-gap: 4px; height: auto; flex-wrap: wrap; overflow: visible; }
  .divider { display: none; }
  .tools { order: 2; }
  .tabs { order: 3; width: 100%; height: 40px; overflow-x: auto; scrollbar-width: none; }
  .tools .check { display: none; }
  .layout { grid-template-columns: 1fr; }
  main { padding: 20px 16px; }
  .sidebar { border-left: 0; border-top: 1px solid var(--line); padding: 20px 16px; }
  .footer { padding: 12px 16px; }
  .kpi .value { font-size: 26px; }
  .chart { height: 340px; }
  .tl-axis { margin-left: 110px; }
  .tl-row { grid-template-columns: 110px 1fr; }
  .bar-row { grid-template-columns: 90px 1fr 96px; gap: 8px; }
}
