/* ==========================================================================
   Mugs SOP Monitor · Half Million theme
   Brand tokens live here. Swap the hex values for official HM brand codes.
   ========================================================================== */
:root {
  /* brand */
  --hm-green-900: #0b3d2c;
  --hm-green-800: #0f4a36;
  --hm-green-700: #135c43;
  --hm-sand: #e9dcc0;
  --hm-sand-2: #d9c7a3;
  --hm-gold: #b8862c;
  --hm-black: #14181a;

  /* surfaces + ink (light) */
  --bg: #f5efe4;
  --surface: #fffdf8;
  --surface-2: #f7f1e6;
  --ink: #15211b;
  --ink-2: #44514a;
  --muted: #6f786f;
  --line: rgba(21, 33, 27, 0.09);
  --line-strong: rgba(21, 33, 27, 0.16);
  --accent: #0a7d55;
  --accent-ink: #fffdf8;
  --focus: rgba(10, 125, 85, 0.35);

  /* chart series (validated with the dataviz palette checker) */
  --s-direct: #0a7d55;
  --s-split: #b8862c;
  --grid: rgba(21, 33, 27, 0.08);

  /* status */
  --high: #b3261e; --high-bg: #fbe8e4;
  --med: #8f6210;  --med-bg: #f7edd6;
  --low: #3b5d8a;  --low-bg: #e7edf6;
  --ok: #0a6e4b;   --ok-bg: #e2f1e9;

  /* depth: shadows instead of hard borders */
  --shadow-sm: 0 0 0 1px var(--line), 0 1px 2px rgba(21, 33, 27, 0.04);
  --shadow-md: 0 0 0 1px var(--line), 0 1px 2px rgba(21, 33, 27, 0.04), 0 12px 32px -16px rgba(21, 33, 27, 0.18);

  /* motion */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  /* type */
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Manrope", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius: 16px;
  --radius-sm: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1310; --surface: #13201a; --surface-2: #182822;
    --ink: #efe7d6; --ink-2: #c9c0ad; --muted: #8f978c;
    --line: rgba(239, 231, 214, 0.08); --line-strong: rgba(239, 231, 214, 0.16);
    --accent: #2f9e74; --accent-ink: #0b1310; --focus: rgba(47, 158, 116, 0.45);
    --s-direct: #16805a; --s-split: #b8862c; --grid: rgba(239, 231, 214, 0.07);
    --high: #f28b7d; --high-bg: rgba(242, 139, 125, 0.12);
    --med: #e2b45a;  --med-bg: rgba(226, 180, 90, 0.12);
    --low: #9ab8e0;  --low-bg: rgba(154, 184, 224, 0.12);
    --ok: #6fcf9f;   --ok-bg: rgba(111, 207, 159, 0.12);
    --shadow-sm: 0 0 0 1px var(--line);
    --shadow-md: 0 0 0 1px var(--line), 0 16px 40px -20px rgba(0, 0, 0, 0.6);
    --hm-green-900: #0a2219; --hm-green-800: #0d2b20; --hm-green-700: #12392b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1310; --surface: #13201a; --surface-2: #182822;
  --ink: #efe7d6; --ink-2: #c9c0ad; --muted: #8f978c;
  --line: rgba(239, 231, 214, 0.08); --line-strong: rgba(239, 231, 214, 0.16);
  --accent: #2f9e74; --accent-ink: #0b1310; --focus: rgba(47, 158, 116, 0.45);
  --s-direct: #16805a; --s-split: #b8862c; --grid: rgba(239, 231, 214, 0.07);
  --high: #f28b7d; --high-bg: rgba(242, 139, 125, 0.12);
  --med: #e2b45a;  --med-bg: rgba(226, 180, 90, 0.12);
  --low: #9ab8e0;  --low-bg: rgba(154, 184, 224, 0.12);
  --ok: #6fcf9f;   --ok-bg: rgba(111, 207, 159, 0.12);
  --shadow-sm: 0 0 0 1px var(--line);
  --shadow-md: 0 0 0 1px var(--line), 0 16px 40px -20px rgba(0, 0, 0, 0.6);
  --hm-green-900: #0a2219; --hm-green-800: #0d2b20; --hm-green-700: #12392b;
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
.wrap { max-width: 1680px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 32px; } }
@media (min-width: 1280px) { .wrap { padding: 0 48px; } }
h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 600; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
svg { flex-shrink: 0; }

.eyebrow {
  font-size: 12px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--hm-sand-2);
}
.eyebrow.dark { color: var(--accent); }
.display { font-family: var(--font-display); font-weight: 500; font-size: clamp(28px, 4vw, 40px); letter-spacing: -0.02em; margin-top: 10px; }
.display.sm { font-size: 26px; }
.section-title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 999px; border: 0; cursor: pointer;
  font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: transform 160ms var(--ease-out), background-color 200ms ease, box-shadow 200ms ease, opacity 200ms ease;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:active:not(:disabled), .icon-btn:active { transform: scale(0.97); }
.btn-primary { background: var(--hm-green-900); color: var(--hm-sand); box-shadow: 0 1px 0 rgba(255,255,255,.08) inset, 0 6px 16px -8px rgba(11, 61, 44, 0.6); }
:root[data-theme="dark"] .btn-primary { background: var(--hm-sand); color: var(--hm-green-900); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { background: var(--hm-sand); color: #0b3d2c; } }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-on-dark { background: rgba(233, 220, 192, 0.12); color: var(--hm-sand); box-shadow: 0 0 0 1px rgba(233, 220, 192, 0.22) inset; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 999px; border: 0; background: transparent; cursor: pointer;
  display: inline-grid; place-items: center; color: var(--ink-2);
  transition: transform 160ms var(--ease-out), background-color 200ms ease;
}
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .i-sun { display: none; }
:root[data-theme="dark"] .icon-btn .i-sun { display: block; }
:root[data-theme="dark"] .icon-btn .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-btn .i-sun { display: block; }
  :root:not([data-theme="light"]) .icon-btn .i-moon { display: none; }
}
@media (hover: hover) and (pointer: fine) {
  .btn-ghost:hover, .icon-btn:hover { background: var(--line); }
  .btn-primary:hover:not(:disabled) { box-shadow: 0 1px 0 rgba(255,255,255,.08) inset, 0 10px 22px -10px rgba(11, 61, 44, 0.7); }
  .btn-on-dark:hover { background: rgba(233, 220, 192, 0.2); }
}
button.link { background: none; border: 0; padding: 0; color: var(--hm-sand); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-weight: 600; }

/* ---------- nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--hm-green-900) 0%, transparent);
  transition: background-color 240ms ease, box-shadow 240ms ease, -webkit-backdrop-filter 240ms ease, backdrop-filter 240ms ease;
  color: var(--hm-sand);
}
.nav.scrolled {
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(14px); backdrop-filter: saturate(160%) blur(14px);
  box-shadow: 0 1px 0 var(--line);
  color: var(--ink);
}
.nav-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 68px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; min-width: 0; }
.monogram {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: var(--hm-sand); color: #0b3d2c;
  font-family: var(--font-display); font-weight: 600; font-size: 14px; letter-spacing: 0.02em;
}
.nav.scrolled .monogram { background: #0b3d2c; color: var(--hm-sand); }
.monogram.sm { width: 24px; height: 24px; font-size: 9px; background: #0b3d2c; color: var(--hm-sand); vertical-align: middle; margin-right: 6px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.brand-sub { font-size: 12px; opacity: 0.7; white-space: nowrap; }
.nav-actions { display: flex; align-items: center; gap: 4px; }
.nav:not(.scrolled) .btn-ghost, .nav:not(.scrolled) .icon-btn { color: var(--hm-sand); }
.nav:not(.scrolled) .btn-primary { background: var(--hm-sand); color: #0b3d2c; }
@media (max-width: 640px) {
  .brand-sub, #btnHelp { display: none; }
  .btn-primary span { display: none; }
  .btn-primary { width: 40px; padding: 0; }
}

/* ---------- hero ---------- */
.hero {
  position: relative; margin-top: -68px; padding: 120px 0 72px;
  color: var(--hm-sand); background: var(--hm-green-900); overflow: hidden; isolation: isolate;
}
.hero-bg {
  position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(60% 80% at 85% 10%, rgba(184, 134, 44, 0.22), transparent 60%),
    radial-gradient(50% 70% at 10% 100%, rgba(47, 158, 116, 0.28), transparent 65%),
    linear-gradient(180deg, var(--hm-green-800), var(--hm-green-900));
}
.hero-bg::after {
  content: ""; position: absolute; inset: 0; opacity: 0.08; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.hero-inner { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 48px; align-items: center; }
.hero h1 {
  font-family: var(--font-display); font-weight: 500; letter-spacing: -0.025em;
  font-size: clamp(36px, 6vw, 64px); line-height: 1.04; margin-top: 16px; color: #f6eedc;
}
.hero h1 em { font-style: italic; color: var(--hm-sand-2); }
.hero .lead { margin-top: 20px; max-width: 52ch; font-size: 17px; color: rgba(233, 220, 192, 0.78); }
.hero-report .lead { font-size: 15px; }

/* drop zone */
.drop {
  position: relative; border-radius: 24px; padding: 28px; text-align: center; outline: none; cursor: pointer;
  background: rgba(255, 253, 248, 0.05);
  box-shadow: 0 0 0 1px rgba(233, 220, 192, 0.16) inset, 0 30px 60px -30px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: background-color 200ms ease, box-shadow 200ms ease, transform 200ms var(--ease-out);
}
.drop::before {
  content: ""; position: absolute; inset: 10px; border-radius: 16px; pointer-events: none;
  border: 1.5px dashed rgba(233, 220, 192, 0.24); transition: border-color 200ms ease;
}
.drop.over { background: rgba(255, 253, 248, 0.1); transform: scale(1.01); }
.drop.over::before, .drop:focus-visible::before { border-color: var(--hm-sand); }
@media (hover: hover) and (pointer: fine) { .drop:hover::before { border-color: rgba(233, 220, 192, 0.5); } }
.mugs { width: min(220px, 70%); height: auto; display: block; margin: 8px auto 18px; overflow: visible; }
.mug path { fill: currentColor; }
.mug .h { fill: none; stroke: currentColor; stroke-width: 6; stroke-linecap: round; }
.m1 { color: #d9c7a3; }
.m2 { color: #2f9e74; }
.m3 { color: #0e1311; }
.m3 path:first-child { stroke: rgba(233, 220, 192, 0.35); stroke-width: 1.5; }
.drop-body { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.drop-title { font-size: 17px; color: #f6eedc; }
.drop-sub { color: rgba(233, 220, 192, 0.75); font-size: 14px; }
.drop-note { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 12px; color: rgba(233, 220, 192, 0.6); }
.drop-note svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; }
.drop-again, .drop-clear, .drop-original { display: none; }

/* hero after a file is loaded: compact */
body.has-data .hero { padding: 104px 0 40px; }
body.has-data .hero-intro { display: none; }
body.has-data .hero-report { display: block !important; }
body.has-data .hero h1 { font-size: clamp(30px, 4.4vw, 46px); margin-top: 10px; }
body.has-data .hero-inner { grid-template-columns: 1fr auto; align-items: end; }
body.has-data .drop { padding: 0; background: none; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
body.has-data .drop::before, body.has-data .mugs, body.has-data .drop-body { display: none; }
body.has-data .drop-again, body.has-data .drop-clear { display: inline-flex; }
body.has-data .drop { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; cursor: default; }
body.has-data .drop-clear { background: transparent; }
body.has-data .drop.over .drop-again { background: rgba(233, 220, 192, 0.3); }

@media (max-width: 860px) {
  .hero-inner, body.has-data .hero-inner { grid-template-columns: 1fr; gap: 32px; }
  .hero { padding-bottom: 48px; }
}

/* ---------- main ---------- */
.main { padding-top: 28px; padding-bottom: 64px; }
.error { margin-bottom: 16px; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--high-bg); color: var(--high); font-weight: 600; }

.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 20px; margin-top: 20px; }
@media (min-width: 720px) { .panel { padding: 24px; } }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }

/* settings */
.settings { margin-top: 0; }
.settings-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select, .filters select, .search {
  height: 42px; border-radius: var(--radius-sm); border: 0; padding: 0 12px; min-width: 0; font-size: 15px;
  background: var(--surface-2); color: var(--ink); box-shadow: 0 0 0 1px var(--line) inset;
  transition: box-shadow 160ms ease;
}
.field input:focus, .field select:focus, .filters select:focus, .search:focus-within { outline: none; box-shadow: 0 0 0 1px var(--accent) inset, 0 0 0 4px var(--focus); }
.input-suffix { position: relative; display: flex; }
.input-suffix input { width: 100%; padding-right: 44px; }
.input-suffix em { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 13px; pointer-events: none; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); gap: 14px; }
@media (max-width: 600px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 14px; }
  .kpi .value { font-size: 28px; }
  .settings-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
}
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 18px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi .label { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: 0.02em; display: flex; align-items: center; gap: 8px; }
.kpi .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.kpi .value { font-family: var(--font-display); font-weight: 500; font-size: 34px; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums lining-nums; margin-top: 6px; }
.kpi .note { font-size: 12.5px; color: var(--muted); }
.kpi.high .label { color: var(--high); }
.kpi.med .label { color: var(--med); }
.kpi.feature { background: #0b3d2c; color: var(--hm-sand); box-shadow: 0 18px 40px -22px rgba(11, 61, 44, 0.8); }
:root[data-theme="dark"] .kpi.feature { background: var(--hm-sand); color: #0b3d2c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .kpi.feature { background: var(--hm-sand); color: #0b3d2c; } }
.kpi.feature .label, .kpi.feature .note { color: inherit; opacity: 0.75; }

/* chart */
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw-direct { background: var(--s-direct); }
.sw-split { background: var(--s-split); }
.chart { display: grid; gap: 6px; }
.bar-row {
  display: grid; grid-template-columns: minmax(120px, 220px) 1fr; gap: 14px; align-items: center;
  padding: 6px 8px; margin: 0 -8px; border-radius: 8px; cursor: pointer; border: 0; background: none; text-align: left; width: calc(100% + 16px);
  transition: background-color 150ms ease;
}
@media (hover: hover) and (pointer: fine) { .bar-row:hover { background: var(--surface-2); } }
.bar-label { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-label small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.bar-track { position: relative; display: flex; align-items: center; gap: 10px; min-width: 0; height: 30px; }
.bar-track::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; right: 56px; background-image: linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 25% 100%; pointer-events: none; }
.bar-track::after { content: ""; position: absolute; top: 0; bottom: 0; right: 56px; width: 1px; background: var(--grid); }
.bar-stack { display: flex; gap: 2px; height: 18px; transform-origin: left center; width: calc((100% - 56px) * var(--f)); }
.seg { height: 100%; min-width: 2px; flex: var(--g) 1 0; }
.seg:last-child { border-radius: 0 4px 4px 0; }
.seg.direct { background: var(--s-direct); }
.seg.split { background: var(--s-split); }
.bar-val { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
.chart-axis { display: grid; grid-template-columns: minmax(120px, 220px) 1fr; gap: 14px; font-size: 11px; color: var(--muted); padding: 4px 0 0; }
.chart-axis div { margin-right: 56px; display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
@media (max-width: 600px) {
  .bar-row, .chart-axis { grid-template-columns: 1fr; gap: 6px; }
  .chart-axis > span { display: none; }
}

/* chart reveal: bars grow once when the chart scrolls into view */
.chart.armed .bar-stack { transform: scaleX(0.001); }
.chart.armed .bar-val { opacity: 0; }
.chart.play .bar-stack { transform: scaleX(1); transition: transform 700ms var(--ease-out); transition-delay: var(--d, 0ms); }
.chart.play .bar-val { opacity: 1; transition: opacity 300ms ease; transition-delay: calc(var(--d, 0ms) + 350ms); }

/* tooltip */
.tip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 260px;
  background: var(--ink); color: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; line-height: 1.45;
  box-shadow: 0 12px 28px -12px rgba(0, 0, 0, 0.45);
  opacity: 1; transform: translateY(0); transition: opacity 125ms var(--ease-out), transform 125ms var(--ease-out);
}
.tip[hidden] { display: block; opacity: 0; transform: translateY(4px); visibility: hidden; }
.tip b { font-variant-numeric: tabular-nums; }
.tip .t-row { display: flex; align-items: center; gap: 8px; }
.tip .sw { width: 10px; height: 10px; }

/* tabs */
.table-panel { padding-top: 8px; }
.tabs { position: relative; display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; margin: 0 -4px; padding: 0 4px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: none; border: 0; padding: 14px 12px; cursor: pointer; color: var(--muted); font-weight: 700; font-size: 14px;
  white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; transition: color 150ms ease;
}
.tabs button.active { color: var(--ink); }
@media (hover: hover) and (pointer: fine) { .tabs button:hover { color: var(--ink); } }
.tab-ink {
  position: absolute; left: 0; bottom: -1px; height: 2px; width: 100px; background: var(--accent); border-radius: 2px;
  transform-origin: left; transition: transform 240ms var(--ease-in-out);
}
.pill { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); box-shadow: 0 0 0 1px var(--line) inset; font-size: 11.5px; text-align: center; font-variant-numeric: tabular-nums; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 16px 0 14px; }
.filters select { max-width: 100%; padding-right: 30px; }
.search { display: flex; align-items: center; gap: 8px; flex: 1 1 220px; }
.search svg { width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search input { border: 0; background: none; outline: none; width: 100%; height: 100%; font-size: 15px; }

/* table */
.table-wrap { border-radius: 12px; box-shadow: 0 0 0 1px var(--line); overflow: auto; max-height: 72vh; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; font-size: 14px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th {
  position: sticky; top: 0; z-index: 1; cursor: pointer; user-select: none;
  background: color-mix(in srgb, var(--surface-2) 92%, transparent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  font-size: 11.5px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 700;
}
th.num, td.num { text-align: right; }
th .arrow { color: var(--accent); }
tbody tr { transition: background-color 120ms ease; }
@media (hover: hover) and (pointer: fine) { tbody tr:hover { background: var(--surface-2); } }
tr.clickable { cursor: pointer; }
tr.open > td { background: var(--surface-2); }
td.wrap-cell { white-space: normal; min-width: 240px; }
td.strong { font-weight: 600; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.High { background: var(--high-bg); color: var(--high); }
.badge.Medium { background: var(--med-bg); color: var(--med); }
.badge.Low { background: var(--low-bg); color: var(--low); }
.badge.Clean { background: var(--ok-bg); color: var(--ok); }
.meter { display: inline-block; width: 56px; height: 6px; border-radius: 3px; background: var(--line); vertical-align: middle; margin-left: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meter.warn i { background: var(--s-split); }

tr.detail > td { background: var(--surface-2); padding: 4px 18px 20px; white-space: normal; }
tr.detail .detail-inner { opacity: 1; transform: none; transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out); }
@starting-style { tr.detail .detail-inner { opacity: 0; transform: translateY(-4px); } }
.detail-grid { display: flex; flex-wrap: wrap; gap: 8px 28px; margin-bottom: 12px; font-size: 13px; color: var(--ink-2); }
.detail-grid b { color: var(--ink); font-variant-numeric: tabular-nums; }
.why { margin: 0 0 14px; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 13.5px; }
.why li { display: flex; gap: 10px; align-items: baseline; }
.why .pts { flex-shrink: 0; min-width: 52px; text-align: center; font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--surface); box-shadow: 0 0 0 1px var(--line) inset; color: var(--accent); font-variant-numeric: tabular-nums; }
.inner { border-radius: 10px; overflow: auto; background: var(--surface); box-shadow: 0 0 0 1px var(--line); }
.inner th { position: static; cursor: default; background: var(--surface); }
.timeline { position: relative; height: 34px; margin: 6px 4px 4px; border-bottom: 1px solid var(--line-strong); max-width: 720px; }
.timeline span { position: absolute; bottom: 0; width: 4px; background: var(--s-split); border-radius: 2px 2px 0 0; }
.timeline-axis { display: flex; justify-content: space-between; max-width: 720px; margin: 0 4px 14px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.empty-row { color: var(--muted); text-align: center; padding: 40px 12px; }

/* ---------- landing ---------- */
.landing { padding-top: 24px; }
.section { padding: 48px 0; }
.section + .section { border-top: 1px solid var(--line); }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-top: 28px; }
.step { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 24px; }
.step-n { font-family: var(--font-display); font-size: 15px; color: var(--hm-gold); font-weight: 600; }
.step h3 { font-size: 18px; margin: 14px 0 8px; letter-spacing: -0.01em; }
.step p { color: var(--ink-2); font-size: 14.5px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; align-items: center; }
@media (max-width: 800px) { .split { grid-template-columns: 1fr; } }
.body-copy { margin-top: 14px; max-width: 56ch; }
.score-list { list-style: none; margin: 0; padding: 8px 20px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md); }
.score-list li { display: flex; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.score-list li:last-child { border-bottom: 0; }
.score-list b { font-variant-numeric: tabular-nums; }
.score-list .levels { justify-content: flex-start; flex-wrap: wrap; gap: 8px; }

/* ---------- footer ---------- */
.footer { border-top: 1px solid var(--line); padding: 24px 0 calc(24px + env(safe-area-inset-bottom)); font-size: 13px; }
.footer-inner { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }

/* ---------- dialog (modal: centered, 250ms in) ---------- */
dialog {
  border: 0; border-radius: 20px; background: var(--surface); color: var(--ink); max-width: 620px; width: calc(100% - 32px);
  max-height: calc(100dvh - 48px); padding: 28px; box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.45);
  opacity: 1; transform: scale(1);
  transition: opacity 250ms var(--ease-out), transform 250ms var(--ease-out), overlay 250ms allow-discrete, display 250ms allow-discrete;
}
@starting-style { dialog[open] { opacity: 0; transform: scale(0.96); } }
dialog:not([open]) { opacity: 0; transform: scale(0.98); transition-duration: 150ms; }
dialog::backdrop { background: rgba(8, 20, 15, 0.5); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); transition: opacity 250ms ease; }
@starting-style { dialog[open]::backdrop { opacity: 0; } }
dialog h3 { font-size: 15px; margin: 18px 0 6px; }
dialog p, dialog li { color: var(--ink-2); font-size: 14.5px; }
dialog ul { padding-left: 18px; margin: 0; display: grid; gap: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 22px; }

/* ---------- entrance + scroll reveal ---------- */
/* Hero: one entrance on first paint. Lead (headline) rises furthest; support follows with shrinking gaps. */
@keyframes rise { from { opacity: 0; transform: translateY(var(--rise, 12px)); } }
@keyframes fade { from { opacity: 0; } }
.e1 { animation: fade 500ms var(--ease-out) both; }
.e2 { --rise: 18px; animation: rise 700ms var(--ease-out) 60ms both; }
.e3 { --rise: 10px; animation: rise 600ms var(--ease-out) 160ms both; }
.e4 { --rise: 14px; animation: rise 700ms var(--ease-out) 220ms backwards; }
.e4 .m1 { animation: rise 600ms var(--ease-out) 380ms backwards; --rise: 8px; }
.e4 .m2 { animation: rise 600ms var(--ease-out) 330ms backwards; --rise: 12px; }
.e4 .m3 { animation: rise 600ms var(--ease-out) 420ms backwards; --rise: 8px; }

/* Sections reveal once as they scroll into view (JS adds .in). */
.js .reveal { opacity: 0; transform: translateY(18px); }
.js .reveal.in { opacity: 1; transform: none; transition: opacity 600ms var(--ease-out), transform 700ms var(--ease-out); transition-delay: var(--d, 0ms); }
.js .steps .step { opacity: 0; transform: translateY(14px); }
.js .reveal.in .step { opacity: 1; transform: none; transition: opacity 500ms var(--ease-out), transform 600ms var(--ease-out); }
.js .reveal.in .step:nth-child(1) { transition-delay: 120ms; }
.js .reveal.in .step:nth-child(2) { transition-delay: 190ms; }
.js .reveal.in .step:nth-child(3) { transition-delay: 240ms; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .e1, .e2, .e3, .e4, .e4 .mug { animation: fade 300ms ease both; }
  .js .reveal, .js .steps .step { transform: none; }
  .js .reveal.in, .js .reveal.in .step { transition: opacity 300ms ease; transition-delay: 0ms; }
  .chart.armed .bar-stack, .chart.play .bar-stack { transform: none; transition: none; }
  .tab-ink { transition: none; }
}


/* ==========================================================================
   v2: layout + atmosphere
   ========================================================================== */

/* ---------- ambient page background: slow drifting brand light ---------- */
.ambient { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.ambient::before { /* faint dot grid, faded toward the edges */
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(circle at 1px 1px, var(--line-strong) 1px, transparent 0);
  background-size: 28px 28px;
  -webkit-mask-image: radial-gradient(70% 60% at 50% 40%, #000 20%, transparent 75%);
          mask-image: radial-gradient(70% 60% at 50% 40%, #000 20%, transparent 75%);
  opacity: 0.55;
}
.ambient::after { /* paper grain */
  content: ""; position: absolute; inset: 0; opacity: 0.05; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.blob { position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%; will-change: transform; }
.b1 { left: -25vmax; top: 10vh;  background: radial-gradient(closest-side, rgba(10, 125, 85, 0.16), transparent); animation: drift1 38s ease-in-out infinite alternate; }
.b2 { right: -28vmax; top: 30vh; background: radial-gradient(closest-side, rgba(184, 134, 44, 0.16), transparent); animation: drift2 46s ease-in-out infinite alternate; }
.b3 { left: 20vw; bottom: -45vmax; background: radial-gradient(closest-side, rgba(217, 199, 163, 0.35), transparent); animation: drift3 52s ease-in-out infinite alternate; }
@keyframes drift1 { to { transform: translate3d(14vw, 18vh, 0) scale(1.1); } }
@keyframes drift2 { to { transform: translate3d(-16vw, -14vh, 0) scale(0.92); } }
@keyframes drift3 { to { transform: translate3d(-12vw, -10vh, 0) scale(1.08); } }
:root[data-theme="dark"] .ambient::after { mix-blend-mode: screen; opacity: 0.04; }
:root[data-theme="dark"] .b3 { background: radial-gradient(closest-side, rgba(47, 158, 116, 0.10), transparent); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ambient::after { mix-blend-mode: screen; opacity: 0.04; }
  :root:not([data-theme="light"]) .b3 { background: radial-gradient(closest-side, rgba(47, 158, 116, 0.10), transparent); }
}

/* ---------- hero: slow aurora + steaming mugs ---------- */
.aurora {
  position: absolute; left: -25%; top: -60%; width: 150%; height: 220%;
  background:
    radial-gradient(30% 25% at 30% 45%, rgba(47, 158, 116, 0.45), transparent 70%),
    radial-gradient(25% 22% at 70% 40%, rgba(184, 134, 44, 0.35), transparent 70%),
    radial-gradient(28% 24% at 55% 70%, rgba(233, 220, 192, 0.14), transparent 70%);
  animation: aurora 60s linear infinite; will-change: transform; opacity: 0.9;
}
@keyframes aurora { to { transform: rotate(360deg); } }
.hero::after { /* soft fade into the page */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(233, 220, 192, 0.35), transparent);
}
.mugs .mug { transform-box: fill-box; transform-origin: 50% 100%; }
.steam path { fill: none; stroke: rgba(233, 220, 192, 0.55); stroke-width: 3; stroke-linecap: round; opacity: 0; }
.steam .s1 { animation: steam 3.6s ease-out 1.1s infinite; }
.steam .s2 { animation: steam 3.6s ease-out 0.5s infinite; }
.steam .s3 { animation: steam 3.6s ease-out 1.8s infinite; }
@keyframes steam {
  0%   { opacity: 0;   transform: translateY(8px) scaleY(0.8); }
  25%  { opacity: 0.8; }
  100% { opacity: 0;   transform: translateY(-14px) scaleY(1.1); }
}
.steam path { transform-box: fill-box; transform-origin: 50% 100%; }
@media (hover: hover) and (pointer: fine) {
  .drop .mug { transition: transform 300ms var(--ease-out); }
  .drop:hover .m1 { transform: translateY(-3px) rotate(-4deg); }
  .drop:hover .m2 { transform: translateY(-5px); }
  .drop:hover .m3 { transform: translateY(-3px) rotate(4deg); }
}

/* report header: one entrance when a file loads */
body.has-data .hero-report > * { animation: rise 600ms var(--ease-out) both; --rise: 12px; }
body.has-data .hero-report > :nth-child(2) { animation-delay: 60ms; --rise: 16px; }
body.has-data .hero-report > :nth-child(3) { animation-delay: 120ms; --rise: 8px; }
body.has-data .drop-again, body.has-data .drop-clear { animation: rise 600ms var(--ease-out) 160ms both; --rise: 8px; }

/* ---------- KPI cards: numbers always fit, cards are shortcuts ---------- */
.kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 1180px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 600px)  { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { container-type: inline-size; position: relative; overflow: hidden; }
.kpi .value { font-size: clamp(24px, 17cqi, 40px); white-space: nowrap; }
.kpi .value .unit { font-family: var(--font-body); font-size: 0.4em; font-weight: 700; letter-spacing: 0.02em; color: var(--muted); margin-left: 4px; }
.kpi.feature .value .unit { color: inherit; opacity: 0.7; }
.kpi[data-go] { cursor: pointer; transition: transform 200ms var(--ease-out), box-shadow 200ms ease; }
.kpi[data-go]:active { transform: scale(0.98); }
.kpi .go { position: absolute; top: 16px; right: 16px; width: 16px; height: 16px; opacity: 0; transform: translate(-4px, 4px); transition: opacity 200ms ease, transform 200ms var(--ease-out); fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); }
.kpi.feature .go { color: inherit; }
@media (hover: hover) and (pointer: fine) {
  .kpi[data-go]:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
  .kpi[data-go]:hover .go { opacity: 0.8; transform: none; }
}
/* accent line that sweeps in across each card on entrance */
.kpi::after { content: ""; position: absolute; left: 18px; right: 18px; bottom: 0; height: 2px; border-radius: 2px; background: var(--kpi-accent, transparent); transform-origin: left; }
.kpi.high { --kpi-accent: var(--high); }
.kpi.med  { --kpi-accent: var(--s-split); }
.kpi.feature { --kpi-accent: var(--hm-gold); }
/* staggered entrance per file load (non-uniform gaps, lead card first) */
.kpis.enter .kpi { animation: rise 560ms var(--ease-out) both; --rise: 14px; }
.kpis.enter .kpi::after { animation: sweep 700ms var(--ease-out) both; }
.kpis.enter .kpi:nth-child(1), .kpis.enter .kpi:nth-child(1)::after { animation-delay: 0ms; }
.kpis.enter .kpi:nth-child(2), .kpis.enter .kpi:nth-child(2)::after { animation-delay: 45ms; }
.kpis.enter .kpi:nth-child(3), .kpis.enter .kpi:nth-child(3)::after { animation-delay: 85ms; }
.kpis.enter .kpi:nth-child(4), .kpis.enter .kpi:nth-child(4)::after { animation-delay: 115ms; }
.kpis.enter .kpi:nth-child(5), .kpis.enter .kpi:nth-child(5)::after { animation-delay: 140ms; }
.kpis.enter .kpi:nth-child(6), .kpis.enter .kpi:nth-child(6)::after { animation-delay: 160ms; }
@keyframes sweep { from { transform: scaleX(0); } }

/* ---------- chart + rules side by side on wide screens ---------- */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; margin-top: 20px; }
.dash-grid > .panel { margin-top: 0; }
.dash-grid .settings { position: sticky; top: 88px; }
.dash-grid .settings-grid { grid-template-columns: 1fr; gap: 14px; }
.dash-grid .settings-head { flex-direction: column; gap: 2px; align-items: flex-start; }
.rules-note { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
  .dash-grid .settings { position: static; order: -1; }
  .dash-grid .settings-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}
@media (max-width: 600px) { .dash-grid .settings-grid { grid-template-columns: 1fr 1fr; gap: 10px; } }

/* panels: a whisper of brand colour at the top edge */
.panel { position: relative; }
.panel::before { content: ""; position: absolute; left: 24px; right: 24px; top: 0; height: 1px; background: linear-gradient(90deg, transparent, rgba(184, 134, 44, 0.45), transparent); }

/* recalculation feedback: values blur briefly when rules change */
.kpis.recalc .value, .chart.recalc .bar-stack { animation: settle 360ms var(--ease-out); }
@keyframes settle { from { filter: blur(2px); opacity: 0.6; } }

@media (prefers-reduced-motion: reduce) {
  .blob, .aurora, .steam path { animation: none !important; }
  .steam path { opacity: 0.4; }
  .kpis.enter .kpi { animation: fade 300ms ease both; }
  .kpis.enter .kpi::after { animation: none; }
  body.has-data .hero-report > *, body.has-data .drop-again, body.has-data .drop-clear { animation: fade 300ms ease both; }
  .kpi[data-go]:hover { transform: none; }
}

/* export button while the workbook is being built */
.btn.busy { opacity: 0.75; cursor: progress; }
.btn.busy svg { animation: nudge 900ms var(--ease-in-out) infinite; }
@keyframes nudge { 50% { transform: translateY(2px); } }
@media (prefers-reduced-motion: reduce) { .btn.busy svg { animation: none; } }

/* ==========================================================================
   Cloud mode (Cloudflare deployment)
   ========================================================================== */
.cloud-only { display: none; }
body.cloud .cloud-only { display: block; }
body.cloud .drop-clear { display: none !important; }
body.has-data .drop-original:not([hidden]) { display: inline-flex; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; margin-right: 4px; background: rgba(233, 220, 192, 0.12); max-width: 240px; }
.user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav.scrolled .user-chip { background: var(--surface-2); box-shadow: 0 0 0 1px var(--line) inset; }
.dot-live { width: 7px; height: 7px; border-radius: 50%; background: #6fcf9f; box-shadow: 0 0 0 3px rgba(111, 207, 159, 0.25); flex-shrink: 0; }
@media (max-width: 760px) { .user-chip { display: none !important; } }

.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.danger { color: var(--high); }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { text-decoration: none; }
tr.current > td { background: color-mix(in srgb, var(--accent) 7%, transparent); }

/* review */
.rv { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--muted); box-shadow: 0 0 0 1px var(--line) inset; }
.rv-violation { background: var(--high-bg); color: var(--high); box-shadow: none; }
.rv-genuine { background: var(--ok-bg); color: var(--ok); box-shadow: none; }
.rv-false_positive { background: var(--low-bg); color: var(--low); box-shadow: none; }
.review-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; margin: 6px 0 14px; border-radius: 12px; background: var(--surface); box-shadow: 0 0 0 1px var(--line) inset; }
.review-bar .rv-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin-right: 4px; }
.review-bar select, .review-bar input { height: 34px; border-radius: 8px; border: 0; padding: 0 10px; font-size: 13.5px; background: var(--surface-2); color: var(--ink); box-shadow: 0 0 0 1px var(--line) inset; }
.review-bar input { flex: 1 1 220px; min-width: 0; }
.review-bar select:focus, .review-bar input:focus { outline: none; box-shadow: 0 0 0 1px var(--accent) inset, 0 0 0 3px var(--focus); }
.review-bar .rv-meta { flex-basis: 100%; font-size: 12px; color: var(--muted); }

/* repeat-offender heatmap */
.trend-tools { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.trend-tools select { height: 36px; border-radius: 10px; border: 0; padding: 0 10px; background: var(--surface-2); color: var(--ink); box-shadow: 0 0 0 1px var(--line) inset; }
.heat-wrap { max-height: 560px; }
table.heat th, table.heat td { padding: 6px 8px; }
table.heat th.day { padding: 6px 2px; text-align: center; font-size: 10.5px; letter-spacing: 0; text-transform: none; }
table.heat td.cell { padding: 4px 2px; text-align: center; }
.hc { display: inline-block; width: 16px; height: 16px; border-radius: 4px; vertical-align: middle; }
.legend .hc { width: 12px; height: 12px; border-radius: 3px; }
.hc-High { background: var(--high); }
.hc-Medium { background: var(--s-split); }
.hc-Low { background: color-mix(in srgb, var(--low) 55%, transparent); }
.hc-Clean { background: color-mix(in srgb, var(--ok) 30%, transparent); }
.hc-none { background: var(--surface-2); box-shadow: 0 0 0 1px var(--line) inset; }

/* status toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 60; max-width: min(560px, calc(100% - 32px));
  padding: 12px 18px; border-radius: 12px; background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 600;
  box-shadow: 0 16px 40px -16px rgba(0, 0, 0, 0.5);
  opacity: 0; transform: translate(-50%, 12px); pointer-events: none;
  transition: opacity 200ms var(--ease-out), transform 260ms var(--ease-out);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--high); color: #fff; }
.toast.busy::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 10px; vertical-align: -1px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .toast { transition: opacity 200ms ease; transform: translate(-50%, 0); } .toast.busy::before { animation: none; } }

/* ---------- view scope (area manager / ROM / city / zone) ---------- */
.scope-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; padding: 12px 16px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.scope-bar[hidden] { display: none; }
.scope-title { font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin-right: 2px; }
.scope-bar select { height: 38px; max-width: 220px; border-radius: 10px; border: 0; padding: 0 10px; font-size: 14px; background: var(--surface-2); color: var(--ink); box-shadow: 0 0 0 1px var(--line) inset; }
.scope-bar select:focus { outline: none; box-shadow: 0 0 0 1px var(--accent) inset, 0 0 0 3px var(--focus); }
@media (max-width: 600px) { .scope-bar select { flex: 1 1 140px; max-width: none; } }
.map-box { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.map-box .section-title { font-size: 14px; }
.map-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.user-chip[hidden] { display: none !important; }

.map-missing { display: grid; gap: 8px; }
.map-missing .strong-label { font-weight: 700; margin-top: 6px; }
.miss-row { display: grid; gap: 6px; padding: 10px; border-radius: 10px; background: var(--surface-2); box-shadow: 0 0 0 1px var(--line) inset; }
.miss-row.done { grid-template-columns: 1fr auto; align-items: center; background: var(--ok-bg); box-shadow: none; }
.miss-input { display: flex; gap: 6px; }
.miss-input input { flex: 1; min-width: 0; height: 32px; border-radius: 8px; border: 0; padding: 0 10px; font-size: 13px; background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line) inset; }
.miss-input input:focus { outline: none; box-shadow: 0 0 0 1px var(--accent) inset, 0 0 0 3px var(--focus); }

.miss-done { display: grid; gap: 8px; }
.miss-done summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-bottom: 6px; }
.miss-done[open] summary { margin-bottom: 8px; }
.miss-done .miss-row + .miss-row { margin-top: 8px; }

/* ==========================================================================
   Accounts & roles
   ========================================================================== */
.admin-only, .viewer-only { display: none !important; }
body.admin .admin-only { display: inline-flex !important; }
body.viewer .viewer-only { display: inline !important; }
body.viewer .admin-hide-viewer { display: none !important; }

/* sign-in screen */
body.auth-open { overflow: hidden; }
body.auth-open > header, body.auth-open > section, body.auth-open > main, body.auth-open > footer { visibility: hidden; }
.auth-screen { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px 16px; background: var(--hm-green-900); overflow: auto; }
.auth-screen[hidden] { display: none; }
.auth-bg { position: absolute; inset: 0; overflow: hidden; background: linear-gradient(180deg, var(--hm-green-800), var(--hm-green-900)); }
.auth-card {
  position: relative; width: min(440px, 100%); padding: 32px 28px; border-radius: 24px;
  background: var(--surface); color: var(--ink); box-shadow: 0 40px 80px -30px rgba(0, 0, 0, 0.6);
  animation: rise 500ms var(--ease-out) both; --rise: 14px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth-brand .monogram { background: #0b3d2c; color: var(--hm-sand); }
.auth-brand strong { display: block; font-size: 15px; }
.auth-brand small { color: var(--muted); font-size: 12px; }
.auth-card h1 { margin: 0 0 18px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); margin-bottom: 18px; }
.auth-tabs button { height: 38px; border: 0; border-radius: 9px; background: transparent; font-weight: 700; color: var(--muted); cursor: pointer; transition: background-color 160ms ease, color 160ms ease; }
.auth-tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.auth-form { display: grid; gap: 14px; }
.auth-form .btn { width: 100%; height: 44px; margin-top: 4px; }
.auth-form h3 { font-size: 15px; margin: 8px 0 0; }
.auth-msg { margin: 0 0 14px; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); }
.auth-msg.error { background: var(--high-bg); color: var(--high); }
.auth-msg.ok { background: var(--ok-bg); color: var(--ok); }
.auth-form .auth-msg { margin: 0; }

/* account chip + users button */
button.user-chip { border: 0; cursor: pointer; color: inherit; text-align: left; height: 40px; }
.uc-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.uc-text small { font-size: 10.5px; font-weight: 600; opacity: 0.7; }
.count-badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--high); color: #fff; font-size: 11px; font-weight: 700; margin-left: 4px; }
.count-badge[hidden] { display: none; }

/* dialogs */
dialog.wide { max-width: 1040px; }
.dlg-close { position: absolute; top: 14px; right: 14px; margin: 0; }
dialog { position: fixed; }
.users-wrap { margin-top: 14px; max-height: 60vh; }
table.users td { vertical-align: middle; }
table.users input, table.users select { height: 34px; border-radius: 8px; border: 0; padding: 0 10px; font-size: 13.5px; background: var(--surface-2); color: var(--ink); box-shadow: 0 0 0 1px var(--line) inset; min-width: 0; }
table.users input.u-name { width: 180px; }
table.users input.u-am { width: 200px; }
table.users tr.pending > td { background: color-mix(in srgb, var(--s-split) 9%, transparent); }

/* ---------- area manager (viewer) layout: focus on the two main checks ---------- */
body.viewer .drop, body.viewer #empty, body.viewer .settings, body.viewer #scopeBar { display: none !important; }
body.viewer .dash-grid { grid-template-columns: minmax(0, 1fr); }
body.viewer .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
body.viewer .kpi[data-k="sa"], body.viewer .kpi[data-k="zq"] { display: none; }
body.viewer .kpi[data-k="dv"] { order: 1; grid-column: span 2; }
body.viewer .kpi[data-k="sr"] { order: 2; grid-column: span 2; }
body.viewer .kpi[data-k="hi"] { order: 3; grid-column: span 2; }
body.viewer .kpi[data-k="mu"] { order: 4; grid-column: span 2; }
body.viewer .kpi[data-k="dv"], body.viewer .kpi[data-k="sr"] { padding: 24px; min-height: 168px; justify-content: center; }
body.viewer .kpi[data-k="dv"] .value, body.viewer .kpi[data-k="sr"] .value { font-size: clamp(40px, 14cqi, 64px); }
body.viewer .kpi[data-k="dv"] .label, body.viewer .kpi[data-k="sr"] .label { font-size: 13px; }
body.viewer .kpi[data-k="dv"] { background: linear-gradient(180deg, color-mix(in srgb, var(--high) 6%, var(--surface)), var(--surface)); }
body.viewer .kpi[data-k="sr"] { background: linear-gradient(180deg, color-mix(in srgb, var(--s-split) 8%, var(--surface)), var(--surface)); }
@media (min-width: 1000px) {
  body.viewer .kpi[data-k="hi"], body.viewer .kpi[data-k="mu"] { grid-column: span 1; }
  body.viewer .kpis { grid-template-columns: 1.5fr 1.5fr 1fr 1fr; }
  body.viewer .kpi[data-k="dv"], body.viewer .kpi[data-k="sr"] { grid-column: span 1; }
}
@media (max-width: 600px) { body.viewer .kpis { grid-template-columns: 1fr 1fr; } }
.viewer-empty { margin-top: 24px; text-align: center; padding: 48px 24px; }

/* ---------- admin leaderboard ---------- */
.group-pick { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.group-pick select { height: 36px; border-radius: 10px; border: 0; padding: 0 10px; background: var(--surface-2); color: var(--ink); box-shadow: 0 0 0 1px var(--line) inset; font-size: 14px; }
table.leader td.bar-cell { white-space: nowrap; }
table.leader td.bar-cell b { display: inline-block; min-width: 34px; }
.mini { display: inline-block; width: 70px; height: 8px; border-radius: 4px; background: var(--line); margin-right: 8px; vertical-align: middle; overflow: hidden; }
.mini i { display: block; height: 100%; border-radius: 4px; }
.mini i.d { background: var(--s-direct); }
.mini i.s { background: var(--s-split); }

/* ---------- day-by-day chart ---------- */
.daily-chart { display: flex; align-items: flex-end; gap: 6px; height: 220px; padding: 8px 4px 0; overflow-x: auto; border-bottom: 1px solid var(--line-strong); }
.day-col { flex: 1 0 28px; max-width: 64px; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; cursor: default; }
.day-bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.day-bars i { width: min(14px, 40%); min-height: 2px; border-radius: 4px 4px 0 0; transition: height 400ms var(--ease-out); }
.day-bars i.d { background: var(--s-direct); }
.day-bars i.s { background: var(--s-split); }
.day-lbl { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; padding-bottom: 6px; }
@media (hover: hover) and (pointer: fine) { .day-col:hover .day-bars i { filter: brightness(1.1); } }
@media (prefers-reduced-motion: reduce) { .auth-card { animation: fade 300ms ease both; } .day-bars i { transition: none; } }
.auth-form[hidden] { display: none; }
dialog.wide { max-width: 1180px; }
table.users input.u-name { width: 150px; }
table.users input.u-am { width: 180px; }
table.users td.actions { white-space: normal; min-width: 230px; }
table.users td.actions .btn { margin: 2px 0; }

/* ---------- first load: no upload-screen flash while the report loads ---------- */
.boot-loader { display: none; }
html.booting .boot-loader {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  grid-column: 1 / -1; min-height: calc(100vh - 230px); min-height: calc(100dvh - 230px); text-align: center; color: var(--hm-sand);
  animation: fade 400ms var(--ease-out) both;
}
html.booting .hero-intro, html.booting .hero-report, html.booting #drop, html.booting main, html.booting .footer { visibility: hidden; }
html.booting .hero-inner { grid-template-columns: 1fr; }
html.booting .hero { min-height: 100vh; min-height: 100dvh; }

.boot-mugs { width: min(260px, 70vw); height: auto; overflow: visible; }
.bm { transform-box: fill-box; transform-origin: 50% 100%; animation: bm-bob 2.4s var(--ease-in-out) infinite; }
.bm2 { animation-delay: 0.2s; }
.bm3 { animation-delay: 0.4s; }
.bm-body { fill: rgba(255, 253, 248, 0.06); stroke-width: 3; stroke-linejoin: round; }
.bm1 .bm-body { stroke: #d9c7a3; }
.bm2 .bm-body { stroke: #2f9e74; }
.bm3 .bm-body { stroke: #e9dcc0; }
.bm-handle { fill: none; stroke-width: 5; stroke-linecap: round; }
.bm1 .bm-handle { stroke: #d9c7a3; }
.bm2 .bm-handle { stroke: #2f9e74; }
.bm3 .bm-handle { stroke: #e9dcc0; }
/* coffee fills each mug in turn, with a gentle wave on top */
.bm-fill { fill: #b8862c; transform: translateY(100%); animation: bm-fill 2.4s var(--ease-in-out) infinite; }
.bm2 .bm-fill { animation-delay: 0.2s; }
.bm3 .bm-fill { animation-delay: 0.4s; }
.bm-steam { fill: none; stroke: rgba(233, 220, 192, 0.6); stroke-width: 3; stroke-linecap: round; opacity: 0; transform-box: fill-box; transform-origin: 50% 100%; animation: bm-steam 2.4s ease-out infinite; }
.bm2 .bm-steam { animation-delay: 0.2s; }
.bm3 .bm-steam { animation-delay: 0.4s; }
@keyframes bm-fill {
  0%   { transform: translate(0, 100%); }
  45%  { transform: translate(-16px, 8%); }
  70%  { transform: translate(-32px, 8%); }
  100% { transform: translate(-32px, 100%); }
}
@keyframes bm-steam {
  0%, 40% { opacity: 0; transform: translateY(6px) scaleY(0.8); }
  60%     { opacity: 0.9; }
  100%    { opacity: 0; transform: translateY(-14px) scaleY(1.1); }
}
@keyframes bm-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

.boot-text { display: grid; gap: 4px; }
.boot-text strong { font-family: var(--font-display); font-weight: 500; font-size: clamp(22px, 3vw, 30px); letter-spacing: -0.01em; color: #f6eedc; min-height: 1.3em; transition: opacity 200ms ease; }
.boot-text strong.swap { opacity: 0; }
.boot-sub { font-size: 12px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(233, 220, 192, 0.6); }
.boot-bar { position: relative; width: min(220px, 60vw); height: 3px; border-radius: 3px; background: rgba(233, 220, 192, 0.15); overflow: hidden; }
.boot-bar i { position: absolute; top: 0; bottom: 0; width: 40%; border-radius: 3px; background: linear-gradient(90deg, transparent, var(--hm-sand), transparent); animation: boot-bar 1.4s var(--ease-in-out) infinite; }
@keyframes boot-bar { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

@media (prefers-reduced-motion: reduce) {
  .bm, .bm-steam, .boot-bar i { animation: none; }
  .bm-fill { animation: none; transform: translateY(30%); }
  .bm-steam { opacity: 0.5; }
}
