/* Koru K9 Metrics - styles.
   Tokens follow the Koru K9 website: ink, clay, blue, gold, cream/oat/sand
   surfaces, Fraunces for headings and Inter for everything else. Series
   colours are the validated data palette (see docs/DASHBOARD.md). */

:root {
  color-scheme: light;
  --cream: #FDFCF8; --oat: #F5F1E8; --sand: #EAE3D4; --line: #E5DFD2;
  --ink: #22303A; --ink-2: #3A4C58; --text: #3D4852; --muted: #75818B;
  --clay: #C97043; --clay-dark: #B25E35; --blue: #5D7E9C; --blue-deep: #41586E; --blue-soft: #DCE5EC; --gold: #DFA958;

  --bg: var(--oat); --surface: var(--cream); --surface-2: #FFFFFF;
  --border: var(--line); --shadow: 0 4px 14px rgba(34,48,58,.07);
  --grid: #EDE8DC; --baseline: #D8D1C2;
  --accent: var(--clay); --accent-ink: #FFFFFF; --link: var(--blue-deep);

  /* categorical series - validated light */
  --s1: #C97043; --s2: #3F7FBF; --s3: #2E8F5E; --s4: #D9951F; --s5: #8E5BB0; --s6: #1F9C9C; --s7: #C83E4D; --s8: #6B5BD6;
  /* ordinal (funnel) */
  --ord1: #D48E64; --ord2: #C97043; --ord3: #A8552F; --ord4: #7E3E21;
  /* sequential heat: from surface to clay-dark */
  --heat-lo: 253, 252, 248; --heat-hi: 178, 94, 53;
  /* status */
  --good: #3C6B49; --warn: #B8841A; --bad: #B5373F; --good-bg: rgba(78,125,91,.14); --warn-bg: rgba(223,169,88,.18); --bad-bg: rgba(181,55,63,.12);
  --radius: 14px; --radius-sm: 8px;
  --font: 'Inter', -apple-system, system-ui, 'Segoe UI', sans-serif;
  --serif: 'Fraunces', Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14191D; --surface: #1B2228; --surface-2: #222B32; --border: #2E3940; --grid: #273037; --baseline: #3A4650;
    --ink: #F3EFE6; --ink-2: #D8D3C8; --text: #CFC9BC; --muted: #8E9AA3; --link: #9DB7CF; --blue-soft: #2A3B48;
    --s1: #D17A49; --s2: #4F8FD0; --s3: #36A36E; --s4: #BD8A22; --s5: #9C7FD0; --s6: #2EA8A8; --s7: #DB5B66; --s8: #8A7CE0;
    --ord1: #8A4526; --ord2: #B05A33; --ord3: #C97043; --ord4: #E0A480;
    --heat-lo: 27, 34, 40; --heat-hi: 224, 164, 128;
    --good: #5FB27A; --warn: #DFA958; --bad: #E66B74; --good-bg: rgba(95,178,122,.16); --warn-bg: rgba(223,169,88,.16); --bad-bg: rgba(230,107,116,.14);
    --shadow: 0 4px 14px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14191D; --surface: #1B2228; --surface-2: #222B32; --border: #2E3940; --grid: #273037; --baseline: #3A4650;
  --ink: #F3EFE6; --ink-2: #D8D3C8; --text: #CFC9BC; --muted: #8E9AA3; --link: #9DB7CF; --blue-soft: #2A3B48;
  --s1: #D17A49; --s2: #4F8FD0; --s3: #36A36E; --s4: #BD8A22; --s5: #9C7FD0; --s6: #2EA8A8; --s7: #DB5B66; --s8: #8A7CE0;
  --ord1: #8A4526; --ord2: #B05A33; --ord3: #C97043; --ord4: #E0A480;
  --heat-lo: 27, 34, 40; --heat-hi: 224, 164, 128;
  --good: #5FB27A; --warn: #DFA958; --bad: #E66B74; --good-bg: rgba(95,178,122,.16); --warn-bg: rgba(223,169,88,.16); --bad-bg: rgba(230,107,116,.14);
  --shadow: 0 4px 14px rgba(0,0,0,.25);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.5; -webkit-font-smoothing: antialiased; min-height: 100vh; }
h1, h2, h3, h4 { font-family: var(--serif); color: var(--ink); font-weight: 600; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; }
h4.sub-head { font-size: .95rem; margin: 12px 0 4px; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }

/* ---------------------------------------------------------------- header */
header.site { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 24px; height: 64px; padding: 0 24px; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.brand .logo { height: 36px; width: auto; display: block; }
:root[data-theme="dark"] .brand .logo { filter: invert(1) hue-rotate(180deg) brightness(1.6); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand .logo { filter: invert(1) hue-rotate(180deg) brightness(1.6); } }
.brand .product { font-family: var(--serif); font-size: 1.05rem; color: var(--clay); font-weight: 600; border-left: 1px solid var(--border); padding-left: 12px; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav-link { padding: 8px 12px; border-radius: var(--radius-sm); color: var(--ink-2); font-weight: 500; white-space: nowrap; font-size: .95rem; }
.nav-link:hover { background: var(--oat); color: var(--ink); text-decoration: none; }
:root[data-theme="dark"] .nav-link:hover { background: var(--surface-2); }
.nav-link.on { color: var(--clay); }
.nav-link.soon { color: var(--muted); }
.soon-tag { font-size: .65rem; font-weight: 700; letter-spacing: .08em; margin-left: 6px; padding: 1px 6px; border-radius: 100px; background: var(--sand); color: var(--ink-2); vertical-align: middle; }
:root[data-theme="dark"] .soon-tag { background: var(--surface-2); }
.site-tools { flex-shrink: 0; }

/* ------------------------------------------------------------- filter bar */
.filter-bar { position: sticky; top: 64px; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 24px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; }
.filter { display: flex; flex-direction: column; gap: 3px; }
.filter-label { font-size: .68rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.filters select, .filters input[type=date] { font: inherit; font-size: .9rem; color: var(--ink); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 10px; min-width: 120px; }
.filters select:focus, .filters input:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
.window-summary { margin-top: 6px; font-size: .8rem; color: var(--muted); }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-2); padding: 5px 11px; border-radius: 100px; font-size: .85rem; font-weight: 500; }
.chip:hover { border-color: var(--ink-2); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
:root[data-theme="dark"] .chip.on { background: var(--clay); border-color: var(--clay); }
.btn-sm { background: var(--surface-2); border: 1px solid var(--border); color: var(--ink); padding: 6px 12px; border-radius: 100px; font-size: .85rem; font-weight: 500; }
.btn-sm:hover { border-color: var(--ink); }
.btn-sm.reset { align-self: flex-end; }
.link { background: none; border: 0; color: var(--link); padding: 0; font-weight: 500; }
.link:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- layout */
.page { max-width: 1480px; margin: 0 auto; padding: 20px 24px 60px; }
.page.refreshing { opacity: .6; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 18px; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.card.wide { margin-top: 18px; }
.card-head { margin-bottom: 12px; }
.card-sub { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.card-body > .chips { margin-bottom: 12px; }
.chart-host { width: 100%; min-height: 200px; }
.empty { text-align: center; padding: 80px 20px; color: var(--muted); }
.empty h2 { margin-bottom: 8px; }

/* ----------------------------------------------------------------- tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.tiles + div .tiles, .tiles + .tiles { margin-top: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile.clickable { cursor: pointer; }
.tile.clickable:hover { border-color: var(--clay); }
.tile-label { font-size: .78rem; font-weight: 600; color: var(--muted); letter-spacing: .02em; display: flex; gap: 8px; align-items: center; }
.tag { font-size: .62rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 1px 6px; border-radius: 100px; background: var(--blue-soft); color: var(--blue-deep); }
:root[data-theme="dark"] .tag { color: #cfe0ee; }
.tile-value { font-family: var(--serif); font-size: 1.9rem; color: var(--ink); line-height: 1.1; margin: 6px 0 8px; font-weight: 600; }
.tile-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .8rem; min-height: 28px; }
.tile-spark { margin-left: auto; }
.delta { font-weight: 700; padding: 1px 7px; border-radius: 100px; }
.delta.good { color: var(--good); background: var(--good-bg); }
.delta.bad { color: var(--bad); background: var(--bad-bg); }
.delta.neutral { color: var(--ink-2); background: var(--sand); }
:root[data-theme="dark"] .delta.neutral { background: var(--surface-2); }
.has-def { cursor: help; border-bottom: 1px dotted var(--muted); }
.split-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.pill { flex: 1 1 140px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; display: flex; flex-direction: column; }
.pill strong { font-family: var(--serif); font-size: 1.2rem; color: var(--ink); }
.pill span { font-size: .75rem; color: var(--muted); }
.pill.clickable { cursor: pointer; }
.pill.clickable:hover { border-color: var(--clay); }

/* ---------------------------------------------------------------- charts */
svg.chart { display: block; overflow: visible; font-family: var(--font); }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .baseline { stroke: var(--baseline); stroke-width: 1; }
svg.chart .axis { fill: var(--muted); font-size: 11px; }
svg.chart .cat { fill: var(--ink-2); font-size: 12px; }
svg.chart .val { fill: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
svg.chart .val.strong { fill: var(--ink); font-weight: 600; }
svg.chart .end-label { fill: var(--ink); font-size: 12px; font-weight: 600; }
svg.chart .conv { fill: var(--muted); font-size: 11px; }
svg.chart .crosshair { stroke: var(--muted); stroke-width: 1; }
svg.chart .col.lift path, svg.chart .bar.lift path { filter: brightness(1.12); }
svg.chart .bar.selected path { stroke: var(--ink); stroke-width: 1.5; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: .8rem; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.legend-key.line { height: 3px; width: 16px; border-radius: 2px; }
.spark { display: inline-block; vertical-align: middle; }

/* tooltip */
.tip { position: fixed; z-index: 100; display: none; background: var(--ink); color: #F3EFE6; padding: 10px 12px; border-radius: var(--radius-sm); font-size: .8rem; max-width: 340px; box-shadow: 0 10px 30px rgba(0,0,0,.25); pointer-events: none; }
:root[data-theme="dark"] .tip { background: #F3EFE6; color: var(--ink); }
.tip-title { font-weight: 700; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tip-row strong { font-variant-numeric: tabular-nums; }
.tip-key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; flex-shrink: 0; }
.tip-label { opacity: .8; }
.tip-line { margin-top: 4px; opacity: .9; line-height: 1.45; }

/* meters */
.meter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 22px; margin-bottom: 10px; }
.meter-grid.one { grid-template-columns: 1fr; }
.meter-head { display: flex; justify-content: space-between; gap: 8px; font-size: .82rem; margin-bottom: 5px; }
.meter-label { font-weight: 600; color: var(--ink-2); }
.meter-val { color: var(--muted); font-variant-numeric: tabular-nums; }
.meter-track { position: relative; height: 10px; border-radius: 100px; background: var(--sand); overflow: visible; }
:root[data-theme="dark"] .meter-track { background: var(--surface-2); }
.meter-fill { height: 100%; border-radius: 100px; background: var(--clay); }
.meter-fill.good { background: var(--good); }
.meter-fill.warn { background: var(--warn); }
.meter-fill.bad { background: var(--bad); }
.meter-pace { position: absolute; top: -3px; width: 2px; height: 16px; background: var(--ink); border-radius: 1px; }
.meter-foot { font-size: .75rem; color: var(--muted); margin-top: 4px; }

/* heatmap */
.scroll-x { overflow-x: auto; }
table.heat { border-collapse: separate; border-spacing: 3px; font-size: .85rem; width: 100%; }
table.heat th { text-align: left; font-weight: 600; color: var(--ink-2); padding: 6px 8px; white-space: nowrap; }
table.heat thead th { text-align: center; }
table.heat td { text-align: center; padding: 8px 6px; border-radius: 6px; font-variant-numeric: tabular-nums; color: var(--ink); min-width: 64px; }
table.heat td.heat-cell { background: color-mix(in srgb, rgb(var(--heat-hi)) calc(var(--t) * 100%), rgb(var(--heat-lo))); }
table.heat td.heat-cell.dark { color: #fff; }
:root[data-theme="dark"] table.heat td.heat-cell.dark { color: #1B2228; }
table.heat td.heat-empty { color: var(--muted); background: var(--surface-2); }
table.heat td.tot, table.heat th.tot { font-weight: 600; color: var(--ink-2); background: var(--surface-2); }
table.heat td.heat-cell:hover { outline: 2px solid var(--ink); }

/* ---------------------------------------------------------------- tables */
.table-wrap { margin-top: 6px; }
.table-bar { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; margin-bottom: 6px; }
table.data { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.data th { text-align: left; font-weight: 600; color: var(--muted); font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; padding: 8px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; }
table.data th.sorted { color: var(--ink); }
table.data th.num, table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td { padding: 7px 8px; border-bottom: 1px solid var(--grid); color: var(--ink-2); white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
table.data td.txt:first-child { color: var(--ink); font-weight: 500; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--oat); }
:root[data-theme="dark"] table.data tr.clickable:hover td { background: var(--surface-2); }
table.data tfoot td { font-weight: 600; color: var(--ink); border-top: 1px solid var(--border); border-bottom: 0; }
.more { margin-top: 8px; }

/* ------------------------------------------------------------------ notes */
.note { font-size: .85rem; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--blue); border-radius: var(--radius-sm); padding: 10px 14px; margin: 0 0 14px; }
.note.info { border-left-color: var(--blue); }
.note.warn { border-left-color: var(--warn); }
.note.bad { border-left-color: var(--bad); }
.card-body .note { margin-bottom: 12px; }
.goal-controls { margin: 0 0 14px; }

/* ----------------------------------------------------------------- drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(920px, 94vw); background: var(--surface); border-left: 1px solid var(--border); box-shadow: -10px 0 40px rgba(0,0,0,.18); z-index: 60; transform: translateX(100%); transition: transform .22s ease; display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-body { padding: 16px 20px; overflow: auto; }
body.drawer-open::after { content: ''; position: fixed; inset: 0; background: rgba(34,48,58,.25); z-index: 50; }

/* ------------------------------------------------------------------ footer */
.site-foot { max-width: 1480px; margin: 0 auto; padding: 0 24px 40px; }
.provenance { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: .78rem; color: var(--muted); border-top: 1px solid var(--border); padding-top: 14px; }
.about { display: none; margin-top: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; font-size: .85rem; }
.about.open { display: block; }
.about h3 { margin-bottom: 10px; }
.defs { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin-top: 12px; }
.defs dt { font-weight: 600; color: var(--ink-2); text-transform: capitalize; }
.defs dd { color: var(--text); }

/* --------------------------------------------------------------- skeleton */
.skeleton { background: linear-gradient(90deg, var(--sand) 25%, var(--surface-2) 50%, var(--sand) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius); }
:root[data-theme="dark"] .skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%); background-size: 200% 100%; }
.skeleton.tile { height: 110px; }
.skeleton.card { height: 320px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

@media (max-width: 720px) {
  header.site { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .filter-bar { position: static; padding: 10px 16px; }
  .page { padding: 14px 16px 40px; }
  .tile-value { font-size: 1.5rem; }
}
@media print { header.site, .filter-bar, .site-tools, .table-bar, .more { display: none; } .card { break-inside: avoid; box-shadow: none; } }

/* ------------------------------------------------------------ data health */
.health-banner { display: flex; align-items: baseline; gap: 12px; padding: 14px 18px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid var(--border); background: var(--surface); border-left-width: 5px; }
.health-banner.ok { border-left-color: var(--good); }
.health-banner.warning { border-left-color: var(--warn); }
.health-banner.error { border-left-color: var(--bad); }
.health-banner strong { font-family: var(--serif); font-size: 1.15rem; color: var(--ink); }
.finding { display: grid; grid-template-columns: 120px 150px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--grid); font-size: .88rem; align-items: start; }
.finding:last-child { border-bottom: 0; }
.finding .sev { font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 2px 8px; border-radius: 100px; text-align: center; }
.finding.error .sev { background: var(--bad-bg); color: var(--bad); }
.finding.warning .sev { background: var(--warn-bg); color: var(--warn); }
.finding.info .sev { background: var(--blue-soft); color: var(--blue-deep); }
:root[data-theme="dark"] .finding.info .sev { color: #cfe0ee; }
.finding .cat { font-weight: 600; color: var(--ink); }
.finding .msg { color: var(--text); }
.pill-ok, .pill-bad { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 100px; }
.pill-ok { background: var(--good-bg); color: var(--good); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }
.kv-row { display: flex; gap: 10px; align-items: center; font-size: .88rem; margin-bottom: 10px; flex-wrap: wrap; }
@media (max-width: 720px) { .finding { grid-template-columns: 1fr; gap: 4px; } }
