/* Meridian Analytics: layout = fixed left nav + sticky top bar + calm card grid.
   Palette: validated reference data-viz palette (blue/orange/aqua), warm-neutral surfaces. */
:root {
  color-scheme: light;
  --plane: #f9f9f7; --surface: #fcfcfb; --sunken: #f1f0ec;
  --ink: #0b0b0b; --ink2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --border: rgba(11,11,11,.10);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a;
  --accent: #2a78d6; --accent-ink: #ffffff;
  --good: #006300; --bad: #b42d2d; --warn-band: rgba(235,104,52,.13);
  --seq0:#cde2fb; --seq1:#9ec5f4; --seq2:#6da7ec; --seq3:#3987e5; --seq4:#256abf; --seq5:#184f95; --seq6:#0d366b;
  --on-hi: #ffffff;
  --shadow: 0 1px 2px rgba(11,11,11,.04), 0 6px 20px -12px rgba(11,11,11,.12);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane: #0d0d0d; --surface: #1a1a19; --sunken: #232321;
    --ink: #f0efec; --ink2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,.10);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70;
    --accent: #3987e5; --accent-ink: #0b0b0b;
    --good: #0ca30c; --bad: #e66767; --warn-band: rgba(217,89,38,.22);
    --seq0:#0d366b; --seq1:#104281; --seq2:#184f95; --seq3:#1c5cab; --seq4:#3987e5; --seq5:#6da7ec; --seq6:#9ec5f4;
    --on-hi: #0b0b0b;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d; --surface: #1a1a19; --sunken: #232321;
  --ink: #f0efec; --ink2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,.10);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  --accent: #3987e5; --accent-ink: #0b0b0b;
  --good: #0ca30c; --bad: #e66767; --warn-band: rgba(217,89,38,.22);
  --seq0:#0d366b; --seq1:#104281; --seq2:#184f95; --seq3:#1c5cab; --seq4:#3987e5; --seq5:#6da7ec; --seq6:#9ec5f4;
  --on-hi: #0b0b0b;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 96px; }
body { margin: 0; background: var(--plane); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -.01em; text-wrap: balance; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
p { margin: 0; }
a { color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -48px; background: var(--ink); color: var(--plane); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip:focus { top: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.num, .kpi-v, td.n, th.n, .tabular { font-variant-numeric: tabular-nums; }

.app { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 24px 16px; display: flex; flex-direction: column; gap: 28px; border-right: 1px solid var(--border); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-size: 15px; letter-spacing: -.01em; padding: 0 8px; }
.brand strong { font-weight: 700; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { text-decoration: none; padding: 8px 12px; border-radius: 8px; color: var(--ink2); transition: background .15s, color .15s; }
#nav a:hover { background: var(--sunken); color: var(--ink); }
#nav a.active { background: var(--sunken); color: var(--ink); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.side-note { margin-top: auto; padding: 0 8px; font-size: 12px; color: var(--ink2); }

.content { min-width: 0; }
.top { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; padding: 14px 32px; background: var(--plane); border-bottom: 1px solid var(--border); box-shadow: 0 6px 14px -10px rgba(11,11,11,.28); }
.top-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--ink2); }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.custom { display: contents; }
.fld { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.fld > span { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink2); }
select, input[type="date"], input[type="search"] { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-height: 36px; max-width: 100%; }
select:hover, input:hover { border-color: var(--axis); }
.btn { font: inherit; font-weight: 600; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 14px; min-height: 36px; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--sunken); border-color: var(--axis); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink2); }
.btn.ghost:hover { background: var(--sunken); }
.btn.icon { padding: 0; width: 36px; display: inline-grid; place-items: center; }

main { padding: 24px 32px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1440px; outline: none; }
.scope { color: var(--ink2); font-size: 13px; min-height: 20px; }
.sec { display: block; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.span2 { grid-column: 1 / -1; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; }
.kpis .kpi { grid-column: span 2; }
.kpis .kpi:nth-child(n+4) { grid-column: span 3; }
#overview { container-type: inline-size; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 16px 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kpi.enter { animation: rise .45s ease both; }
.kpi:nth-child(2){animation-delay:.04s}.kpi:nth-child(3){animation-delay:.08s}.kpi:nth-child(4){animation-delay:.12s}.kpi:nth-child(5){animation-delay:.16s}
.kpi-l { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink2); }
.kpi-v { white-space: nowrap; font-size: 28px; font-weight: 650; letter-spacing: -.02em; line-height: 1.15; }
.delta { flex-wrap: wrap; font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.delta.good { color: var(--good); } .delta.bad { color: var(--bad); } .delta.flat { color: var(--ink2); }
.delta small { font-weight: 400; color: var(--ink2); }
@container (min-width: 1100px) { .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); } .kpis .kpi, .kpis .kpi:nth-child(n+4) { grid-column: span 1; } .kpi .kpi-v { font-size: 22px; } }
.kpi svg { display: block; width: 100%; height: 36px; overflow: visible; margin-top: 4px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px 14px; box-shadow: var(--shadow); min-width: 0; position: relative; }
.panel-h { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.panel-h.row { flex-direction: row; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 12px; }
.sub { font-size: 12.5px; color: var(--ink2); }
.tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chart { position: relative; width: 100%; min-height: 120px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.ax { fill: var(--ink2); font-size: 11px; font-variant-numeric: tabular-nums; }
.lbl { fill: var(--ink); font-size: 12px; font-variant-numeric: tabular-nums; }
.lbl2 { fill: var(--ink2); font-size: 11.5px; }
.grid-l { stroke: var(--grid); stroke-width: 1; }
.axis-l { stroke: var(--axis); stroke-width: 1; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 8px 0 0; padding: 0; font-size: 12.5px; color: var(--ink2); }
.legend li { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.band { background: var(--warn-band); outline: 1px solid var(--s2); width: 14px; }
.tip { position: fixed; z-index: 60; pointer-events: none; background: var(--ink); color: var(--plane); padding: 8px 10px; border-radius: 8px; font-size: 12.5px; line-height: 1.45; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 260px; font-variant-numeric: tabular-nums; }
.tip b { font-weight: 650; } .tip .r { display: flex; justify-content: space-between; gap: 14px; }
.tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

details.tbl { margin-top: 8px; font-size: 12.5px; }
details.tbl summary { cursor: pointer; color: var(--ink2); width: fit-content; padding: 4px 0; }
.tbl-wrap { overflow-x: auto; max-width: 100%; }
.tbl-wrap.flush { margin: 0 -4px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data th.n, table.data td.n { text-align: right; }
table.data thead th { font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink2); position: sticky; top: 0; background: var(--surface); }
table.data thead th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; padding: 2px 4px; margin: -2px -4px; border-radius: 6px; text-transform: inherit; letter-spacing: inherit; }
table.data thead th button:hover { color: var(--ink); }
table.data thead th button:focus-visible { outline: 2px solid var(--accent); }
table.data tbody tr:hover { background: var(--sunken); }
td.name { white-space: normal; min-width: 180px; } td.name small { display: block; color: var(--ink2); }
.bar { display: inline-block; height: 8px; border-radius: 4px; background: var(--s1); vertical-align: middle; margin-right: 8px; min-width: 2px; }
.more { margin-top: 8px; }
.empty { padding: 28px 8px; text-align: center; color: var(--ink2); }

.cohort { border-collapse: separate; border-spacing: 2px; table-layout: fixed; font-size: 11px; font-variant-numeric: tabular-nums; width: 100%; min-width: 440px; }
.cohort th { font-weight: 600; color: var(--ink2); padding: 2px 2px; text-align: center; white-space: nowrap; }
.cohort th.rh { width: 52px; } .cohort th.bw { width: 40px; }
.cohort th.rh { text-align: left; }
.cohort td { text-align: center; padding: 5px 0; border-radius: 4px; min-width: 0; color: var(--ink); }
.cohort td.hi { color: var(--on-hi); }
.cohort td.na { background: transparent; }

.foot { color: var(--ink2); font-size: 12.5px; display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 1px solid var(--grid); }

/* skeleton loading */
[data-loading]::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: linear-gradient(100deg, var(--surface) 30%, var(--sunken) 50%, var(--surface) 70%) 0 0 / 220% 100%; animation: shimmer 1.3s linear infinite; z-index: 2; }
.kpi.sk { min-height: 128px; }
.kpi.sk::after { content: ""; position: absolute; inset: 0; background: inherit; }
.kpi.sk { position: relative; overflow: hidden; background: linear-gradient(100deg, var(--surface) 30%, var(--sunken) 50%, var(--surface) 70%) 0 0 / 220% 100%; animation: shimmer 1.3s linear infinite; }
@keyframes shimmer { to { background-position: -120% 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; align-items: center; gap: 12px; padding: 10px 16px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .side-note { display: none; }
  .brand { flex: none; }
  #nav { flex-direction: row; flex: none; }
  #nav a { white-space: nowrap; }
  #nav a.active { box-shadow: inset 0 -3px 0 var(--accent); }
  .top { position: static; padding: 14px 16px; }
  main { padding: 16px 16px 40px; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .kpis .kpi, .kpis .kpi:nth-child(n+4) { grid-column: span 1; }
  html { scroll-padding-top: 12px; }
}
@media (max-width: 520px) {
  .kpis .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .kpi-v { font-size: 21px; }
  .kpi { padding: 12px 12px 10px; }
  .kpi-l { font-size: 10.5px; }
  .delta small { display: block; }
  .panel { padding: 14px 14px 10px; }
  .fld { flex: 1 1 140px; }
  .filters { width: 100%; }
  .filters select, .filters input { width: 100%; }
}

@media print {
  :root, :root[data-theme="dark"] { color-scheme: light; --plane:#fff; --surface:#fff; --sunken:#f4f4f2; --ink:#111; --ink2:#444; --grid:#ddd; --axis:#bbb; --border:#ccc; --s1:#2a78d6; --s2:#eb6834; --s3:#1baf7a; --good:#006300; --bad:#a22; --shadow:none; --warn-band: rgba(235,104,52,.18); --on-hi:#fff; --seq0:#cde2fb; --seq1:#9ec5f4; --seq2:#6da7ec; --seq3:#3987e5; --seq4:#256abf; --seq5:#184f95; --seq6:#0d366b; }
  .side, .filters, .skip, .btn, .tools, details.tbl, #tip { display: none !important; }
  .app { display: block; }
  .top { position: static; border: 0; padding: 0 0 8px; background: none; }
  main { padding: 0; max-width: none; }
  .panel, .kpi { break-inside: avoid; box-shadow: none; }
  .kpis { grid-template-columns: repeat(5, 1fr); gap: 8px; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  [data-loading]::after { display: none; }
  body { font-size: 11px; }
}
