/* =============================================================
   Clean Cooking Transition Dashboard
   Design tokens follow the bundled dataviz reference palette.
   Light + dark are both selected sets (dark is not an auto-flip).
   ============================================================= */

.viz-root {
  /* ---- surfaces & ink (light) ---- */
  --page:            #f9f9f7;
  --surface-1:       #fcfcfb;
  --surface-2:       #f4f3ef;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --gridline:        #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --shadow:          rgba(11, 11, 11, 0.08);
  --success-text:    #006300;

  /* ---- categorical slots (light) ---- */
  --series-1: #2a78d6;  /* blue    */
  --series-2: #1baf7a;  /* aqua    */
  --series-3: #eda100;  /* yellow  */
  --series-4: #008300;  /* green   */
  --series-5: #4a3aa7;  /* violet  */
  --series-6: #e34948;  /* red     */
  --series-7: #e87ba4;  /* magenta */
  --series-8: #eb6834;  /* orange  */

  /* ---- sequential blue ramp (light) ---- */
  --seq-100: #cde2fb; --seq-250: #86b6ef; --seq-400: #3987e5;
  --seq-450: #2a78d6; --seq-550: #1c5cab; --seq-700: #0d366b;

  /* ---- status (fixed, never themed) ---- */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;

  /* ---- de-emphasis (emphasis charts) ---- */
  --muted-mark: #c3c2b7;

  --radius: 10px;
  --tab-h: 42px;
  --header-h: 92px;

  color-scheme: light;
}

.viz-root[data-theme="dark"] {
  --page:            #0d0d0d;
  --surface-1:       #1a1a19;
  --surface-2:       #232321;
  --text-primary:    #ffffff;
  --text-secondary:  #c3c2b7;
  --text-muted:      #898781;
  --gridline:        #2c2c2a;
  --baseline:        #383835;
  --border:          rgba(255, 255, 255, 0.10);
  --shadow:          rgba(0, 0, 0, 0.45);
  --success-text:    #0ca30c;

  --series-1: #3987e5; --series-2: #199e70; --series-3: #c98500; --series-4: #008300;
  --series-5: #9085e9; --series-6: #e66767; --series-7: #d55181; --series-8: #d95926;

  --seq-100: #184f95; --seq-250: #256abf; --seq-400: #3987e5;
  --seq-450: #5598e7; --seq-550: #86b6ef; --seq-700: #cde2fb;

  --muted-mark: #383835;

  color-scheme: dark;
}

/* -------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* leave room for fixed header + tab strip */
  padding-top: var(--header-h);
  padding-bottom: var(--tab-h);
}

h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ================= FIXED HEADER ================= */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--shadow);
}
.app-header__title { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.app-header__mark { font-size: 30px; line-height: 1; }
.app-header h1 { font-size: 19px; letter-spacing: -0.01em; }
.app-header__sub { margin: 2px 0 0; font-size: 12px; color: var(--text-secondary); }

.app-header__controls { margin-left: auto; display: flex; gap: 8px; flex: 0 0 auto; }
.ctrl-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; font: inherit; font-size: 12px; font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer;
}
.ctrl-btn:hover { color: var(--text-primary); border-color: var(--baseline); }
.ctrl-btn[aria-pressed="true"] { color: var(--text-primary); border-color: var(--series-1); box-shadow: inset 0 0 0 1px var(--series-1); }
.ctrl-btn__icon { font-size: 14px; }

/* KPI ribbon in header */
.kpi-ribbon { display: flex; gap: 22px; flex: 1 1 auto; overflow: hidden; }
.kpi-chip { display: flex; flex-direction: column; min-width: 0; }
.kpi-chip__val { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; }
.kpi-chip__label { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-chip__val small { font-size: 12px; font-weight: 500; color: var(--text-secondary); }

@media (max-width: 1080px) {
  .kpi-ribbon { display: none; }
}

/* ================= SHEET AREA ================= */
.sheet-area {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 24px 40px;
  outline: none;
}
.sheet-head { margin-bottom: 18px; }
.sheet-head h2 { font-size: 22px; letter-spacing: -0.01em; }
.sheet-head p { margin: 6px 0 0; color: var(--text-secondary); max-width: 74ch; }

/* grid */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, 1fr); }
.grid + .grid { margin-top: 16px; }
.col-1 { grid-column: span 1; }
.col-2 { grid-column: span 2; }
.col-3 { grid-column: span 3; }
.col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; }
.col-8 { grid-column: span 8; }
.col-9 { grid-column: span 9; }
.col-10 { grid-column: span 10; }
.col-11 { grid-column: span 11; }
.col-12 { grid-column: span 12; }
@media (max-width: 900px) {
  [class*="col-"] { grid-column: span 12; }
}

/* card */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 14px;
  box-shadow: 0 1px 2px var(--shadow);
  display: flex; flex-direction: column;
}
.card__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.card__title { font-size: 14px; font-weight: 600; }
.card__sub { font-size: 12px; color: var(--text-muted); margin: 0 0 10px; }
.card__note { font-size: 11px; color: var(--text-muted); margin-top: 10px; }
.card__note a { color: var(--text-secondary); text-decoration: underline; }

/* table-view toggle */
.viewtab {
  font: inherit; font-size: 11px; font-weight: 500;
  color: var(--text-muted); background: none; border: none;
  cursor: pointer; padding: 2px 6px; border-radius: 6px;
}
.viewtab:hover { color: var(--text-primary); background: var(--surface-2); }
.viewtab[aria-pressed="true"] { color: var(--series-1); }

/* ================= HERO FIGURE ================= */
.hero {
  display: flex; flex-direction: column; justify-content: center;
  background:
    radial-gradient(140% 120% at 100% 0%, color-mix(in srgb, var(--series-1) 14%, transparent), transparent 60%),
    var(--surface-1);
}
.hero__value { font-size: 62px; font-weight: 600; letter-spacing: -0.03em; line-height: 1; }
.hero__unit { font-size: 24px; font-weight: 500; color: var(--text-secondary); }
.hero__label { font-size: 15px; color: var(--text-secondary); margin-top: 10px; max-width: 40ch; }
.hero__meta { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* ================= STAT TILE ================= */
.stat { gap: 6px; }
.stat__label { font-size: 12px; color: var(--text-secondary); }
.stat__value { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.stat__value small { font-size: 15px; font-weight: 500; color: var(--text-secondary); }
.stat__delta { font-size: 12px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.stat__delta--good { color: var(--success-text); }
.stat__delta--bad  { color: var(--critical); }
.stat__delta--flat { color: var(--text-muted); }
.stat__foot { font-size: 11px; color: var(--text-muted); margin-top: auto; padding-top: 8px; }

/* ================= SVG CHART CHROME ================= */
.chart { width: 100%; display: block; }
.chart text { font-family: inherit; }
.axis-label, .tick-label { fill: var(--text-muted); font-size: 11px; }
.tick-label--y { text-anchor: end; }
.axis-title { fill: var(--text-secondary); font-size: 11px; font-weight: 500; }
.gridline { stroke: var(--gridline); stroke-width: 1; shape-rendering: crispEdges; }
.baseline { stroke: var(--baseline); stroke-width: 1; shape-rendering: crispEdges; }
.direct-label { fill: var(--text-primary); font-size: 11px; font-weight: 600; }
.direct-label--sec { fill: var(--text-secondary); font-weight: 500; }
.crosshair { stroke: var(--baseline); stroke-width: 1; pointer-events: none; }
.hit { fill: transparent; cursor: crosshair; }
.mark-hover { filter: brightness(1.08); }

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 12px; }
.legend__item { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-secondary); }
.legend__key { width: 16px; height: 3px; border-radius: 2px; flex: 0 0 auto; }
.legend__key--dot { width: 10px; height: 10px; border-radius: 50%; }

/* ================= TABLE VIEW ================= */
.dtable-wrap { overflow-x: auto; }
table.dtable { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.dtable caption { text-align: left; color: var(--text-muted); font-size: 11px; padding-bottom: 8px; }
table.dtable th, table.dtable td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--gridline); white-space: nowrap; }
table.dtable th:first-child, table.dtable td:first-child { text-align: left; }
table.dtable thead th { color: var(--text-secondary); font-weight: 600; border-bottom: 1px solid var(--baseline); position: sticky; top: 0; background: var(--surface-1); }
table.dtable tbody tr:hover { background: var(--surface-2); }
table.dtable th[aria-sort] { cursor: pointer; user-select: none; }
table.dtable th[aria-sort]::after { content: " ↕"; color: var(--text-muted); }
table.dtable th[aria-sort="ascending"]::after { content: " ↑"; color: var(--series-1); }
table.dtable th[aria-sort="descending"]::after { content: " ↓"; color: var(--series-1); }
.cellkey { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 7px; vertical-align: baseline; }

/* ================= TOOLTIP ================= */
.viz-tooltip {
  position: fixed; z-index: 80; pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px var(--shadow);
  padding: 9px 11px; font-size: 12px; min-width: 120px;
  color: var(--text-secondary);
  transform: translate(-50%, calc(-100% - 12px));
}
.viz-tooltip__title { color: var(--text-primary); font-weight: 600; margin-bottom: 6px; }
.viz-tooltip__row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.viz-tooltip__row + .viz-tooltip__row { margin-top: 3px; }
.viz-tooltip__name { display: inline-flex; align-items: center; gap: 6px; }
.viz-tooltip__line { width: 12px; height: 2px; border-radius: 2px; }
.viz-tooltip__val { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ================= EXCEL-STYLE TAB STRIP ================= */
.tab-strip {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--tab-h);
  z-index: 50;
  display: flex; align-items: flex-end; gap: 2px;
  padding: 0 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  position: relative;
  font: inherit; font-size: 12.5px; font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 8px 15px; margin-top: 6px;
  cursor: pointer; white-space: nowrap; flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 7px;
}
.tab:hover { color: var(--text-primary); }
.tab__dot { width: 8px; height: 8px; border-radius: 2px; background: var(--series-1); opacity: 0.55; }
.tab[aria-selected="true"] {
  color: var(--text-primary);
  background: var(--surface-1);
  margin-top: 0;
  padding-bottom: 12px;
  font-weight: 600;
  box-shadow: 0 -2px 0 var(--series-1) inset;
}
.tab[aria-selected="true"] .tab__dot { opacity: 1; }

/* misc */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 500; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-secondary); background: var(--surface-2); }
.pill--warn { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, var(--border)); }
.caveat { font-size: 11.5px; color: var(--text-muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.caveat strong { color: var(--text-secondary); }
.bar-note { font-size: 11px; color: var(--text-muted); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* texture (accessibility) — applied to fills when body[data-a11y="on"] */
.viz-root[data-a11y="on"] .use-texture { /* renderer swaps fills to pattern refs */ }
