/*
 * Argus UI — layout and components. Colours / spacing / type come from
 * tokens.css (linked first by base.html). Calm, dense, professional.
 */

/* ---- state icons: distinct silhouettes so colour is never the only cue ---- */
:root {
  --icon-online: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><circle cx='8' cy='8' r='6'/></svg>");
  --icon-degraded: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M8 1.5 15 14H1z'/></svg>");
  --icon-offline: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill-rule='evenodd' d='M2 2h12v12H2zM5.2 4.5 4.5 5.2 7.3 8l-2.8 2.8.7.7L8 8.7l2.8 2.8.7-.7L8.7 8l2.8-2.8-.7-.7L8 7.3z'/></svg>");
  --icon-maintenance: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M8 1 15 8 8 15 1 8z'/></svg>");
  --icon-unknown: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill-rule='evenodd' d='M8 1a7 7 0 1 0 0 14A7 7 0 0 0 8 1zm0 2.5a4.5 4.5 0 1 1 0 9 4.5 4.5 0 0 1 0-9z'/></svg>");
  --icon-flask: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M6 1h4v1H9.5v4.2L14 13.5c.4.7 0 1.5-.9 1.5H2.9c-.9 0-1.3-.8-.9-1.5l4.5-7.3V2H6z'/></svg>");
  --icon-good: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M6.3 11.3 3 8l1-1 2.3 2.3L12 3.6l1 1z'/></svg>");
  --icon-bad: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M7.2 2h1.6l-.3 7H7.5zM8 10.5a1 1 0 1 1 0 2 1 1 0 0 1 0-2z'/></svg>");
}

.state-online      { --st-fg: var(--state-online-fg);      --st-bg: var(--state-online-bg);      --st-solid: var(--state-online);      --st-icon: var(--icon-online); }
.state-degraded    { --st-fg: var(--state-degraded-fg);    --st-bg: var(--state-degraded-bg);    --st-solid: var(--state-degraded);    --st-icon: var(--icon-degraded); }
.state-offline     { --st-fg: var(--state-offline-fg);     --st-bg: var(--state-offline-bg);     --st-solid: var(--state-offline);     --st-icon: var(--icon-offline); }
.state-maintenance { --st-fg: var(--state-maintenance-fg); --st-bg: var(--state-maintenance-bg); --st-solid: var(--state-maintenance); --st-icon: var(--icon-maintenance); }
.state-unknown     { --st-fg: var(--state-unknown-fg);     --st-bg: var(--state-unknown-bg);     --st-solid: var(--state-unknown);     --st-icon: var(--icon-unknown); }

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + var(--s-4)); }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: var(--lh-tight); font-weight: var(--fw-semibold); letter-spacing: -0.01em; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-md); }
h3 { font-size: var(--fs-base); }
p { margin: 0 0 var(--s-2); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::selection { background: var(--accent-bg); color: var(--text); }

code, kbd, .mono { font-family: var(--mono); font-size: 0.92em; }
.mono { word-break: break-word; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.muted, .lede { color: var(--text-muted); }
.lede { margin: var(--s-1) 0 0; font-size: var(--fs-base); }
.eyebrow { margin: 0 0 var(--s-1); color: var(--text-muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; }
.dot { margin: 0 var(--s-1); color: var(--border-strong); }
.meta { margin: var(--s-1) 0; color: var(--text-muted); }

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

/* ---- skip link ----------------------------------------------------------- */
.skip-link {
  position: absolute;
  left: var(--s-4);
  top: -100px;
  z-index: 100;
  padding: var(--s-2) var(--s-4);
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius);
  font-weight: var(--fw-semibold);
}
.skip-link:focus { top: var(--s-2); text-decoration: none; }

/* ---- top bar ------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--s-1) var(--s-4);
  min-height: var(--topbar-h);
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "brand nav actions";
  align-items: center;
  column-gap: var(--s-6);
}

.brand {
  grid-area: brand;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--text);
  font-weight: var(--fw-semibold);
  font-size: var(--fs-md);
  letter-spacing: 0.02em;
}
.brand:hover { text-decoration: none; }
.brand svg { width: 22px; height: 22px; color: var(--accent); flex: none; }

.primary-nav { grid-area: nav; display: flex; gap: var(--s-1); min-width: 0; overflow-x: auto; scrollbar-width: none; }
.primary-nav::-webkit-scrollbar { display: none; }
.primary-nav a {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 var(--s-3);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-weight: var(--fw-medium);
  white-space: nowrap;
}
.primary-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.primary-nav a[aria-current="page"],
.primary-nav a.is-active {
  color: var(--text);
  font-weight: var(--fw-semibold);
  background: var(--surface-2);
}
/* active marker is a bar, not only a colour/weight change */
.primary-nav a[aria-current="page"]::after,
.primary-nav a.is-active::after {
  content: "";
  position: absolute;
  left: var(--s-3); right: var(--s-3); bottom: 0;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.topbar-actions { grid-area: actions; display: flex; align-items: center; gap: var(--s-1); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .glyph { font-weight: var(--fw-semibold); font-size: var(--fs-md); line-height: 1; }

:root[data-theme="dark"] .icon-moon,
:root[data-theme="light"] .icon-sun { display: none; }
:root:not([data-theme]) .icon-moon { display: none; }

/* ---- page frame ---------------------------------------------------------- */
.page {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--s-5) var(--s-4) var(--s-8);
}
.page:focus { outline: none; }

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--fs-xs);
}
.site-footer-inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--s-3) var(--s-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-4);
  justify-content: space-between;
}

.page-header, .hero-strip, .camera-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s-3) var(--s-4);
  margin-bottom: var(--s-4);
}
.hero-strip { display: block; }
.hero-strip h1, .camera-header h1, .page-header h1 { margin: 0; }
.page-header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }

/* ---- layout helpers ------------------------------------------------------ */
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: var(--s-4); }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: var(--s-4); }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: var(--s-4); }
.chart-grid > .panel { margin-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* ---- KPI ----------------------------------------------------------------- */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--s-3);
  margin: var(--s-4) 0;
}

.kpi {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  min-width: 0;
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
a.kpi:hover { border-color: var(--border-strong); background: var(--surface-2); text-decoration: none; }

.kpi-label {
  display: flex;
  align-items: center;
  gap: var(--s-1);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.kpi-value {
  display: inline-flex;
  align-items: baseline;
  gap: var(--s-1);
  font-size: var(--fs-2xl);
  line-height: var(--lh-tight);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.kpi-value[class*="state-"] { color: var(--st-fg); }
.kpi-value[class*="state-"]::before {
  content: "";
  align-self: center;
  width: 14px; height: 14px;
  flex: none;
  background: currentColor;
  -webkit-mask: var(--st-icon) center / contain no-repeat;
  mask: var(--st-icon) center / contain no-repeat;
}
.kpi-unit { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-muted); letter-spacing: 0; }

.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
}
.kpi-delta .delta-icon { width: 12px; height: 12px; flex: none; background: currentColor; }
.kpi-delta.delta-good { color: var(--good-fg); }
.kpi-delta.delta-bad { color: var(--bad-fg); }
.kpi-delta.delta-good .delta-icon { -webkit-mask: var(--icon-good) center / contain no-repeat; mask: var(--icon-good) center / contain no-repeat; }
.kpi-delta.delta-bad .delta-icon { -webkit-mask: var(--icon-bad) center / contain no-repeat; mask: var(--icon-bad) center / contain no-repeat; }
.kpi-state { font-weight: var(--fw-semibold); color: var(--st-fg); text-transform: capitalize; letter-spacing: 0; }

/* ---- panels / cards ------------------------------------------------------ */
.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-4);
  margin-bottom: var(--s-4);
  box-shadow: var(--shadow-1);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-1) var(--s-3);
  margin-bottom: var(--s-3);
}
.panel-head h2 { margin: 0; font-size: var(--fs-md); }
.panel-head p { margin: 0; font-size: var(--fs-sm); }

/* ---- charts -------------------------------------------------------------- */
.chart { width: 100%; height: 260px; min-width: 0; border-radius: var(--radius-sm); }
.chart-heatmap { height: 420px; }
.chart-ribbon { height: 72px; }

.chart[aria-busy="true"]:empty {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}
.chart[data-state="empty"]:empty {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
}
.chart[data-state="empty"]:empty::after { content: "Chart unavailable — no data loaded."; font-size: var(--fs-sm); }

/* ---- tables -------------------------------------------------------------- */
.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.data-table th, .data-table td {
  text-align: left;
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table th {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
  background: var(--surface-2);
}
.data-table th:first-child { border-top-left-radius: var(--radius-sm); }
.data-table th:last-child { border-top-right-radius: var(--radius-sm); }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table td.num, .data-table th.num { text-align: right; }
.data-table caption { text-align: left; padding: 0 0 var(--s-2); color: var(--text-muted); font-size: var(--fs-sm); }

/* ---- state badge / pill -------------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px var(--s-2) 1px 6px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1.5;
  text-transform: capitalize;
  white-space: nowrap;
}
.pill[class*="state-"] {
  color: var(--st-fg);
  background-color: var(--st-bg);
  border-color: color-mix(in srgb, var(--st-fg) 45%, transparent);
}
.pill[class*="state-"]::before {
  content: "";
  width: 10px; height: 10px;
  flex: none;
  background: currentColor;
  -webkit-mask: var(--st-icon) center / contain no-repeat;
  mask: var(--st-icon) center / contain no-repeat;
}
/* maintenance: own tone, dotted outline */
.pill.state-maintenance { border-style: dotted; border-width: 2px; padding-top: 0; padding-bottom: 0; }
/* unknown: hatched fill + dashed outline */
.pill.state-unknown {
  border-style: dashed;
  background-image: repeating-linear-gradient(135deg, transparent 0 3px, color-mix(in srgb, var(--st-fg) 22%, transparent) 3px 4px);
}
.hatch-unknown {
  background-color: var(--state-unknown-bg);
  background-image: repeating-linear-gradient(135deg, transparent 0 4px, color-mix(in srgb, var(--state-unknown-fg) 35%, transparent) 4px 5px);
}
.hatch-maintenance {
  background-color: var(--state-maintenance-bg);
  background-image: radial-gradient(color-mix(in srgb, var(--state-maintenance-fg) 45%, transparent) 1px, transparent 1.5px);
  background-size: 6px 6px;
}

/* ---- chips --------------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 1px var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1.5;
  white-space: nowrap;
}
a.chip:hover { background: var(--surface-2); text-decoration: none; }
.chip-active, a.chip-active:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: var(--fw-semibold);
}
.chip.tone-good { background: var(--good-bg); color: var(--good-fg); border-color: color-mix(in srgb, var(--good-fg) 45%, transparent); }
.chip.tone-bad { background: var(--bad-bg); color: var(--bad-fg); border-color: color-mix(in srgb, var(--bad-fg) 45%, transparent); }
.chip.tone-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: color-mix(in srgb, var(--warn-fg) 45%, transparent); }
.chip.tone-info { background: var(--info-bg); color: var(--info-fg); border-color: color-mix(in srgb, var(--info-fg) 45%, transparent); }
/* "sample data": dashed outline + flask icon, never colour alone */
.chip.tone-sample {
  background: var(--sample-bg);
  color: var(--sample-fg);
  border: 1px dashed var(--sample-fg);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.6875rem;
  font-weight: var(--fw-semibold);
}
.chip.tone-sample::before {
  content: "";
  width: 11px; height: 11px;
  background: currentColor;
  -webkit-mask: var(--icon-flask) center / contain no-repeat;
  mask: var(--icon-flask) center / contain no-repeat;
}

/* ---- range picker (segmented) -------------------------------------------- */
.range-picker {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1);
  padding: var(--s-1);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  height: fit-content;
}
.range-picker .chip { border-color: transparent; background: transparent; color: var(--text-muted); min-height: 26px; }
.range-picker a.chip:hover { background: var(--surface-3); color: var(--text); }
.range-picker .chip-active, .range-picker a.chip-active:hover { background: var(--accent); color: var(--accent-contrast); }

/* ---- tabs ---------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--s-1);
  margin-bottom: var(--s-4);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab {
  position: relative;
  padding: var(--s-2) var(--s-3);
  color: var(--text-muted);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  border-radius: var(--radius) var(--radius) 0 0;
}
.tab:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.tab-active, .tab-active:hover { color: var(--text); font-weight: var(--fw-semibold); }
.tab-active::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--accent);
}

/* ---- empty state & skeleton ---------------------------------------------- */
.empty {
  margin: var(--s-2) 0;
  padding: var(--s-4);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  background: var(--surface);
}
.empty p { margin: 0; }
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--s-1);
  padding: var(--s-8) var(--s-4);
}
.empty-state .empty-icon { width: 28px; height: 28px; color: var(--text-muted); margin-bottom: var(--s-1); }
.empty-state strong { color: var(--text); font-size: var(--fs-md); }
.empty-state .btn { margin-top: var(--s-2); }

.skeleton {
  width: 100%;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---- buttons & form controls --------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 32px;
  padding: 0 var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: var(--fw-medium);
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

select, input[type="text"], input[type="search"], input[type="date"], input[type="number"] {
  min-height: 32px;
  padding: 0 var(--s-2);
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
input::placeholder { color: var(--text-muted); }

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-xs);
  text-align: center;
}

/* ---- help dialog --------------------------------------------------------- */
.help-dialog {
  width: min(480px, calc(100vw - var(--s-8)));
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
}
.help-dialog::backdrop { background: var(--overlay); }
.help-dialog-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border); }
.help-dialog-body { padding: var(--s-3) var(--s-4) var(--s-4); }
.shortcut-list { display: grid; grid-template-columns: auto 1fr; gap: var(--s-2) var(--s-4); margin: 0; align-items: center; }
.shortcut-list dt { display: flex; gap: var(--s-1); align-items: center; }
.shortcut-list dd { margin: 0; color: var(--text-muted); }

/* ---- styleguide ---------------------------------------------------------- */
.swatch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s-3); }
.swatch { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.swatch-chip { height: 40px; border-bottom: 1px solid var(--border); }
.swatch-meta { padding: var(--s-2); font-size: var(--fs-xs); }
.swatch-meta code { display: block; color: var(--text-muted); word-break: break-all; }
.type-row { display: flex; align-items: baseline; gap: var(--s-4); padding: var(--s-1) 0; border-bottom: 1px solid var(--border); }
.type-row code { flex: 0 0 150px; color: var(--text-muted); white-space: nowrap; }
.space-row { display: flex; align-items: center; gap: var(--s-3); padding: 2px 0; }
.space-row code { flex: 0 0 110px; color: var(--text-muted); white-space: nowrap; }
.space-bar { height: 12px; background: var(--accent); border-radius: 2px; }
.sg-section { margin-bottom: var(--s-8); }
.sg-section > h2 { font-size: var(--fs-lg); margin-bottom: var(--s-3); padding-bottom: var(--s-2); border-bottom: 1px solid var(--border); }
.sg-demo { padding: var(--s-4); border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--bg); }

/* ---- responsive ---------------------------------------------------------- */
@media (max-width: 760px) {
  .topbar-inner {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand actions" "nav nav";
    row-gap: var(--s-1);
    column-gap: var(--s-3);
    padding-bottom: var(--s-2);
  }
  .topbar { position: static; }
  html { scroll-padding-top: var(--s-4); }
  .page { padding: var(--s-4) var(--s-3) var(--s-6); }
  .kpi-value { font-size: var(--fs-xl); }
  .chart-heatmap { height: 320px; }
  .panel { padding: var(--s-3); }
  .data-table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ---- reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .skeleton, .chart[aria-busy="true"]:empty { animation: none; background: var(--surface-2); }
}

/* ---- auth / guest landing ------------------------------------------------ */
.topbar-guest .topbar-inner { justify-content: space-between; }
.page-guest {
  flex: 1;
  display: flex;
  align-items: stretch;
  max-width: none;
  width: 100%;
  padding: 0;
}

body.auth-guest {
  background:
    radial-gradient(ellipse 90% 60% at 15% 10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 85%, color-mix(in srgb, var(--state-online) 12%, transparent), transparent 50%),
    var(--bg);
}

.auth-landing {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-8) var(--s-5);
  width: 100%;
}

.auth-landing-inner {
  width: min(100%, 52rem);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: var(--s-10);
  align-items: center;
}

.auth-brand { max-width: 28rem; }
.auth-mark {
  width: 2.75rem;
  height: 2.75rem;
  color: var(--accent);
  margin-bottom: var(--s-4);
}
.auth-product {
  margin: 0 0 var(--s-3);
  font-size: var(--fs-2xl);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: var(--lh-tight);
}
.auth-headline {
  margin: 0 0 var(--s-3);
  font-size: clamp(1.5rem, 2.4vw, 2rem);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.02em;
  color: var(--text);
}
.auth-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--fs-md);
  max-width: 28ch;
  line-height: 1.45;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: var(--s-6);
}
.auth-card-title {
  margin: 0 0 var(--s-4);
  font-size: var(--fs-lg);
}
.auth-form {
  display: grid;
  gap: var(--s-3);
}
.auth-form label {
  display: grid;
  gap: var(--s-1);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.auth-form input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--s-3);
}
.auth-form input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--accent);
}
.btn-primary,
.auth-submit {
  margin-top: var(--s-2);
  width: 100%;
  background: var(--accent);
  color: var(--accent-contrast);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: var(--s-3) var(--s-4);
  font: inherit;
  font-weight: var(--fw-semibold);
  cursor: pointer;
}
.btn-primary:hover,
.auth-submit:hover { filter: brightness(1.06); text-decoration: none; }
.auth-hint {
  margin: var(--s-4) 0 0;
  font-size: var(--fs-xs);
}
.auth-hint code {
  font-size: 0.95em;
  padding: 0 0.2em;
  background: var(--surface-2);
  border-radius: 3px;
}

.flash-error {
  color: var(--state-offline-fg);
  background: var(--state-offline-bg);
  border: 1px solid color-mix(in srgb, var(--state-offline) 40%, var(--border));
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-sm);
  margin-bottom: var(--s-3);
  font-size: var(--fs-sm);
}
.inline-form { display: inline; margin: 0; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: var(--s-1) var(--s-2);
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
}
.nav-user {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.break-all { word-break: break-all; }

@media (max-width: 800px) {
  .auth-landing-inner {
    grid-template-columns: 1fr;
    gap: var(--s-6);
    max-width: 24rem;
  }
  .auth-brand { text-align: center; max-width: none; }
  .auth-mark { margin-left: auto; margin-right: auto; }
  .auth-sub { max-width: none; margin-inline: auto; }
  .auth-landing { padding: var(--s-6) var(--s-4); }
}

@media (prefers-reduced-motion: no-preference) {
  .auth-card {
    animation: auth-rise 420ms ease-out both;
  }
  .auth-brand {
    animation: auth-rise 480ms ease-out both;
  }
  @keyframes auth-rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }
}

/* ---- print --------------------------------------------------------------- */
@media print {
  body { background: #fff; color: #000; font-size: 11pt; display: block; }
  .skip-link, .topbar, .site-footer, .help-dialog, .range-picker, .tabs, .btn, .icon-btn { display: none !important; }
  .page { max-width: none; padding: 0; }
  .panel, .kpi { box-shadow: none; break-inside: avoid; page-break-inside: avoid; border-color: #999; }
  .chart { break-inside: avoid; }
  .kpi-strip { grid-template-columns: repeat(4, 1fr); }
  .chart-grid, .grid-2, .grid-3 { display: block; }
  .chart-grid > .panel, .grid-2 > .panel, .grid-3 > .panel { margin-bottom: var(--s-3); }
  a { color: inherit; text-decoration: none; }
  .data-table { display: table; white-space: normal; }
  .data-table tr { break-inside: avoid; }
  .skeleton { display: none; }
}
