/* Retro Rabbit OS. Colour roles follow the dataviz reference palette (validated
   light + dark); status colours are reserved for state, never for series. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --axis-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --hover: rgba(11, 11, 11, 0.04);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --good-ink: #006300;
  --bad-ink: #b42323;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;

  --seq-250: #86b6ef;
  --seq-350: #5598e7;
  --seq-450: #2a78d6;
  --seq-550: #1c5cab;
  --seq-600: #184f95;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --neutral: #a3a29b;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9c9a92;
    --axis-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --hover: rgba(255, 255, 255, 0.05);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --good-ink: #0ca30c;
    --bad-ink: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --seq-250: #184f95;
    --seq-350: #1c5cab;
    --seq-450: #2a78d6;
    --seq-550: #5598e7;
    --seq-600: #86b6ef;
    --neutral: #6d6c66;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #9c9a92;
  --axis-muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --hover: rgba(255, 255, 255, 0.05);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --good-ink: #0ca30c;
  --bad-ink: #e66767;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --seq-250: #184f95;
  --seq-350: #1c5cab;
  --seq-450: #2a78d6;
  --seq-550: #5598e7;
  --seq-600: #86b6ef;
  --neutral: #6d6c66;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- shell ---- */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.nav {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 18px 14px; border-right: 1px solid var(--border); background: var(--surface-1);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--text-primary); color: var(--surface-1); font-weight: 700; font-size: 12px; letter-spacing: 0.5px;
}
.brand-name { font-size: 15px; font-weight: 600; }
.brand-name b { color: var(--accent-ink); }
#nav-links { display: flex; flex-direction: column; gap: 2px; }
#nav-links a {
  padding: 8px 10px; border-radius: 8px; color: var(--text-secondary); font-weight: 500;
  display: flex; justify-content: space-between; align-items: center;
}
#nav-links a:hover { background: var(--hover); text-decoration: none; }
#nav-links a.active { background: var(--surface-2); color: var(--text-primary); }
#nav-links .pill { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--critical); color: #fff; }
.nav-foot { margin-top: auto; font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 6px; }
.src { display: flex; align-items: center; gap: 6px; }
.src .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex: none; }
.src.stale .dot { background: var(--warning); }
.src.err .dot { background: var(--critical); }
.src.busy .dot { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: 0.3; } }

.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; background: color-mix(in srgb, var(--page) 92%, transparent);
  backdrop-filter: blur(6px); border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 6px; cursor: pointer; color: var(--text-secondary); font-weight: 500; }
.seg button[aria-checked="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); cursor: pointer; }
.btn {
  border: 1px solid var(--border); background: var(--surface-1); padding: 5px 12px; border-radius: 8px;
  cursor: pointer; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.icon { padding: 5px 9px; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn[disabled] { opacity: 0.5; cursor: default; }

.view { padding: 20px 24px 60px; display: flex; flex-direction: column; gap: 20px; transition: opacity 0.15s; }
.view.loading { opacity: 0.55; }

/* ---- grid & cards ---- */
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-7-5 { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
.span2 { grid-column: span 2; }
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-title { margin: 0; font-size: 14px; font-weight: 600; }
.card-sub { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.card-actions { display: flex; gap: 6px; flex: none; }
.section-title { margin: 6px 0 -6px; font-size: 13px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.empty { color: var(--text-muted); font-size: 13px; padding: 18px 0; text-align: center; }
.note { font-size: 12px; color: var(--text-muted); margin-top: 10px; }

/* ---- stat tiles ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; min-width: 0; box-shadow: var(--shadow);
}
.tile.hero { grid-row: span 2; justify-content: space-between; }
.tile .label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
.tile.hero .value { font-size: 52px; line-height: 1.05; }
.tile .sub { font-size: 12px; color: var(--text-muted); }
.tile .delta { font-size: 12px; font-weight: 500; }
.delta.up-good, .delta.down-good { color: var(--good-ink); }
.delta.up-bad, .delta.down-bad { color: var(--bad-ink); }
.delta.flat { color: var(--text-muted); }
.tile svg.spark { margin-top: 4px; }
.tile.clickable { cursor: pointer; }
.tile.clickable:hover { border-color: var(--baseline); }
.tile.selected { box-shadow: 0 0 0 2px var(--accent); }

/* ---- badges ---- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; white-space: nowrap; color: var(--text-secondary); }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--b, var(--neutral)); flex: none; }
.badge.s-paying, .badge.h-paying, .badge.ok { --b: var(--good); }
.badge.h-offline { --b: var(--good); }
.badge.s-unpaid, .badge.h-atRisk, .badge.sev-critical, .badge.bad { --b: var(--critical); }
.badge.sev-error { --b: var(--serious); }
.badge.sev-warning, .badge.warn { --b: var(--warning); }
.badge.s-managed, .badge.h-free { --b: var(--series-7); }
.badge.s-trialing { --b: var(--series-1); }
.badge.s-expiredActive { --b: var(--series-2); }
.badge.s-churned { --b: var(--series-5); }
.badge.s-dormant, .badge.sev-noise, .badge.sev-restart, .badge.h-ended, .badge.h-internal { --b: var(--neutral); }
.badge.e-none { --b: var(--neutral); }
.badge.e-solo { --b: var(--seq-250); }
.badge.e-team { --b: var(--seq-450); }
.badge.e-repeat { --b: var(--seq-600); }

/* ---- attention ---- */
.attention { display: flex; flex-direction: column; }
.att {
  display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 10px; align-items: start;
  padding: 10px 4px; border-top: 1px solid var(--grid); cursor: pointer;
}
.att:first-child { border-top: 0; }
.att:hover { background: var(--hover); }
.att .icon { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; }
.att.critical .icon { background: var(--critical); }
.att.warning .icon { background: var(--warning); color: #0b0b0b; }
.att.opportunity .icon { background: var(--good); }
.att.info .icon { background: var(--neutral); }
.att .t { font-weight: 500; }
.att .d { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }
.att .lvl { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.allclear { display: flex; gap: 10px; align-items: center; color: var(--text-secondary); padding: 6px 0; }
.allclear .icon { width: 20px; height: 20px; border-radius: 50%; background: var(--good); color: #fff; display: grid; place-items: center; font-size: 12px; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--grid); vertical-align: top; white-space: nowrap; }
th { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; user-select: none; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text-primary); }
th .arrow { font-size: 10px; margin-left: 3px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--hover); }
tbody tr:last-child td { border-bottom: 0; }
td .sub { display: block; font-size: 11px; color: var(--text-muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
td.wrap { white-space: normal; word-break: break-word; min-width: 240px; }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.table-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.search { border: 1px solid var(--border); background: var(--surface-1); border-radius: 8px; padding: 5px 10px; min-width: 200px; color: var(--text-primary); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface-1); border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--text-primary); color: var(--surface-1); border-color: var(--text-primary); }
.more { margin-top: 8px; }
.inline-bar { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.inline-bar .track { width: 48px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.inline-bar .fill { height: 100%; background: var(--seq-450); border-radius: 0 3px 3px 0; }
details.sample summary { cursor: pointer; color: var(--text-muted); font-size: 12px; }
details.sample pre { white-space: pre-wrap; word-break: break-word; font-size: 11px; background: var(--surface-2); padding: 8px; border-radius: 6px; margin: 6px 0 0; max-height: 200px; overflow: auto; }

/* ---- charts ---- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart svg:focus { outline: none; }
.chart svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 0 0 8px; font-size: 12px; color: var(--text-secondary); }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 2px; background: var(--c); }
.legend .ln { width: 14px; height: 2px; border-radius: 1px; background: var(--c); }
.axis text { fill: var(--axis-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.base-line { stroke: var(--baseline); stroke-width: 1; shape-rendering: crispEdges; }
.crosshair { stroke: var(--text-muted); stroke-width: 1; shape-rendering: crispEdges; pointer-events: none; }
.bar-col:hover .bar, .bar-col.hot .bar { filter: brightness(1.12); }
.end-label { fill: var(--text-secondary); font-size: 11px; font-weight: 500; }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; min-width: 120px; max-width: 320px;
  background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
}
.tooltip .tt-title { color: var(--text-muted); margin-bottom: 4px; }
.tooltip .tt-row { display: grid; grid-template-columns: 14px auto 1fr; align-items: center; gap: 6px; }
.tooltip .tt-row .k { width: 12px; height: 2px; background: var(--c); border-radius: 1px; }
.tooltip .tt-row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip .tt-row .n { color: var(--text-secondary); }

/* funnel */
.funnel { display: flex; flex-direction: column; gap: 10px; }
.fstage { display: grid; grid-template-columns: minmax(130px, 200px) minmax(0, 1fr); gap: 12px; align-items: center; }
.fstage .fl { font-size: 13px; color: var(--text-secondary); line-height: 1.3; }
.fstage .fl .fp { display: block; font-size: 11px; color: var(--text-muted); }
.fstage .ftrack { position: relative; height: 24px; display: flex; align-items: center; gap: 8px; }
.fstage .fbar { height: 22px; border-radius: 0 4px 4px 0; min-width: 2px; background: var(--c); }
.fstage .fv { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* meters */
.meter { display: flex; align-items: center; gap: 8px; }
.meter .track { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; min-width: 40px; }
.meter .fill { height: 100%; border-radius: 0 3px 3px 0; background: var(--c, var(--seq-450)); }

/* lifecycle tiles */
.life { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.life .tile .value { font-size: 22px; }

/* health strip */
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

/* drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.25); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31; width: min(720px, 100vw);
  background: var(--page); border-left: 1px solid var(--border); overflow-y: auto;
  padding: 20px 22px 60px; box-shadow: -10px 0 40px rgba(0, 0, 0, 0.15);
  display: flex; flex-direction: column; gap: 16px;
}
.drawer h2 { margin: 0; font-size: 20px; }
.drawer .facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 16px; }
.drawer .fact .k { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.drawer .fact .v { font-weight: 500; word-break: break-word; }
.drawer .fact .sub { display: block; font-size: 12px; font-weight: 400; color: var(--text-muted); }
.drawer-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.error-box { border: 1px solid var(--critical); border-radius: 8px; padding: 10px 12px; color: var(--bad-ink); background: color-mix(in srgb, var(--critical) 8%, transparent); }

@media (max-width: 1100px) {
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-7-5 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 800px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  #nav-links { flex-direction: row; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .value { font-size: 22px; }
  #nav-links a { white-space: nowrap; }
  .nav-foot { display: none; }
  .topbar { padding: 12px 16px; position: static; }
  .view { padding: 16px 16px 40px; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .span2 { grid-column: auto; }
  .tile.hero { grid-row: auto; }
  .tile.hero .value { font-size: 40px; }
  .fstage { grid-template-columns: minmax(0, 1fr); gap: 4px; }
}

/* setup steps */
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; color: var(--text-secondary); }
.steps code, .note code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* search */
.search-box { position: relative; flex: 1 1 260px; max-width: 420px; }
.search-box input { width: 100%; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); border-radius: 8px; padding: 6px 10px; font: inherit; }
.search-results { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0; max-height: 420px; overflow-y: auto; background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15); padding: 4px; }
.search-results .sr { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 9px; border-radius: 7px; cursor: pointer; }
.search-results .sr:hover, .search-results .sr.on { background: var(--hover); }
.search-results .sr .l { font-weight: 500; }
.search-results .sr .s { display: block; font-size: 12px; color: var(--text-muted); }
.search-results .sr .t { font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-right: 6px; }
.search-results .empty { padding: 10px; }

/* health badges */
.badge.hl-healthy { --b: var(--good); }
.badge.hl-watch { --b: var(--warning); }
.badge.hl-atRisk { --b: var(--critical); }
.badge.hl-inactive, .badge.hl-none { --b: var(--neutral); }
.badge.st-open { --b: var(--series-1); }
.badge.st-done, .badge.st-completed { --b: var(--good); }
.badge.st-dropped { --b: var(--neutral); }

/* note feed */
.notes { display: flex; flex-direction: column; }
.note-row { padding: 10px 4px; border-top: 1px solid var(--grid); cursor: pointer; }
.note-row:first-child { border-top: 0; }
.note-row:hover { background: var(--hover); }
.note-row .txt { white-space: pre-wrap; word-break: break-word; }
.note-row .meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.chip-s { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); margin-left: 4px; }

/* board drawer */
.topic { display: flex; flex-direction: column; gap: 6px; }
.topic h3 { margin: 6px 0 0; font-size: 14px; }
.bnote { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--surface-1); }
.bnote .txt { white-space: pre-wrap; word-break: break-word; }
.bnote .meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.summary-text { white-space: pre-wrap; font-size: 13px; color: var(--text-secondary); }
@media (max-width: 800px) { .search-box { order: 3; max-width: none; flex-basis: 100%; } }
