/* NEXUS products console: a calm operations-console look.
   One accent, neutral greys, four semantic tones; light and dark follow the system. */

:root {
  color-scheme: light dark;

  --font-sans: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", "Source Han Sans SC",
    "WenQuanYi Micro Hei", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Consolas, "Liberation Mono", Menlo, monospace;

  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #dde1e8;
  --border-strong: #c2c8d3;
  --text: #171a21;
  --text-2: #464d5c;
  --text-3: #626a7a;

  --accent: #2f4bd0;
  --accent-strong: #2339a8;
  --accent-soft: #e9edfc;
  --on-accent: #ffffff;

  --ok: #17784a;
  --ok-soft: #e2f4ea;
  --warn: #935400;
  --warn-soft: #fbefd9;
  --bad: #b42a2a;
  --bad-soft: #fbe6e6;
  --on-bad: #ffffff;
  --idle: #575f6f;
  --idle-soft: #eceef2;

  --radius: 8px;
  --shadow: 0 1px 2px rgb(20 24 34 / 0.06), 0 6px 20px rgb(20 24 34 / 0.08);
  --shadow-lg: 0 10px 40px rgb(20 24 34 / 0.22);
  --scrim: rgb(14 18 28 / 0.5);

  --gutter: 16px;
  --page-max: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a22;
    --surface-2: #1b2029;
    --border: #2a303c;
    --border-strong: #3c4453;
    --text: #e8eaf0;
    --text-2: #b3bac8;
    --text-3: #8f98a9;

    --accent: #8fa3ff;
    --accent-strong: #b3c0ff;
    --accent-soft: #1e2646;
    --on-accent: #0b1030;

    --ok: #5fd39b;
    --ok-soft: #12291f;
    --warn: #f0b35a;
    --warn-soft: #2e2412;
    --bad: #ff8f8f;
    --bad-soft: #341b1b;
    --on-bad: #2a0a0a;
    --idle: #a5adbd;
    --idle-soft: #232833;

    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 20px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 10px 40px rgb(0 0 0 / 0.6);
    --scrim: rgb(0 0 0 / 0.62);
  }
}

@media (min-width: 720px) {
  :root { --gutter: 24px; }
}

/* ------------------------------------------------------------------ base */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font-sans);
  font-variant-numeric: tabular-nums;
}

body:has(dialog[open]) { overflow: hidden; }

[hidden] { display: none !important; }

h1, h2, h3, p, dl, dd, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }

code {
  font: 0.92em var(--font-mono);
  overflow-wrap: anywhere;
}

a { color: var(--accent-strong); text-underline-offset: 3px; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

.skip-link {
  position: absolute;
  left: 8px;
  top: -60px;
  z-index: 100;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--on-accent);
}
.skip-link:focus { top: 8px; }

.muted { color: var(--text-3); }

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --------------------------------------------------------------- tones */

.tone-ok { --tone: var(--ok); --tone-soft: var(--ok-soft); }
.tone-warn { --tone: var(--warn); --tone-soft: var(--warn-soft); }
.tone-idle { --tone: var(--idle); --tone-soft: var(--idle-soft); }
.tone-danger { --tone: var(--bad); --tone-soft: var(--bad-soft); }

.badge, .tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 9px 1px 6px;
  border: 1px solid var(--tone);
  border-color: color-mix(in srgb, var(--tone) 40%, transparent);
  border-radius: 999px;
  background: var(--tone-soft);
  color: var(--tone);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}
.badge .icon, .tag .icon { width: 12px; height: 12px; }

.tag-idle { --tone: var(--idle); --tone-soft: var(--idle-soft); }
.tag-todo {
  --tone: var(--warn);
  --tone-soft: var(--warn-soft);
  border-style: dashed;
  border-color: var(--tone);
}

/* -------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: var(--on-bad); }
.btn-danger:hover:not(:disabled) { background: var(--bad); border-color: var(--bad); filter: brightness(0.92); }

.btn-sm { min-height: 30px; padding: 0 9px; font-size: 13px; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-quiet:hover:not(:disabled) { border-color: transparent; background: var(--accent-soft); color: var(--accent-strong); }
.btn-quiet.tone-danger { color: var(--tone); }
.btn-quiet.tone-danger:hover:not(:disabled) { background: var(--tone-soft); color: var(--tone); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); color: var(--text); }

/* -------------------------------------------------------------- top bar */

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }

.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 12px var(--gutter);
}

.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand h1 { display: flex; align-items: baseline; gap: 8px; font-size: 15px; font-weight: 600; }
.brand-name { font-weight: 800; letter-spacing: 0.18em; }
.brand-sep { color: var(--text-3); }

.brand-mark { width: 30px; height: 30px; flex: none; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { fill: none; stroke: var(--on-accent); stroke-width: 2; stroke-linecap: round; }
.brand-mark circle { fill: var(--on-accent); }

.state-badge {
  --tone: var(--idle);
  --tone-soft: var(--idle-soft);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 12px 2px 8px;
  border: 1px solid color-mix(in srgb, var(--tone) 45%, transparent);
  border-radius: 999px;
  background: var(--tone-soft);
  color: var(--tone);
  font-size: 13px;
  font-weight: 600;
}
.state-badge[data-state="online"] { --tone: var(--ok); --tone-soft: var(--ok-soft); }
.state-badge[data-state="degraded"] { --tone: var(--warn); --tone-soft: var(--warn-soft); }
.state-badge[data-state="offline"] { --tone: var(--bad); --tone-soft: var(--bad-soft); }

.sys-meta { display: flex; gap: 22px; }
.sys-meta dt { font-size: 12px; color: var(--text-3); }
.sys-meta dd { font-size: 13px; font-weight: 500; }

@media (max-width: 719px) {
  .sys-meta { order: 3; width: 100%; justify-content: space-between; gap: 12px; padding-top: 8px; border-top: 1px solid var(--border); }
  .sys-meta dd { font-size: 12px; }
}

.banner {
  padding: 8px var(--gutter);
  border-bottom: 1px solid color-mix(in srgb, var(--bad) 40%, transparent);
  background: var(--bad-soft);
  color: var(--bad);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}

/* ----------------------------------------------------------- page layout */

.page {
  display: grid;
  gap: 20px;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 20px var(--gutter) 56px;
}

/* Offline: keep the last data on screen but visibly stale. */
body[data-offline] .page,
body[data-offline] .sys-meta { opacity: 0.55; filter: saturate(0.5); }

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px var(--gutter) 0;
}
.panel-head h2, .roadmap h2 { font-size: 15px; font-weight: 600; }

/* ----------------------------------------------------------------- stats */

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.stats .stat:first-child { grid-column: 1 / -1; }

@media (min-width: 600px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats .stat:first-child { grid-column: auto; }
}
@media (min-width: 960px) {
  .stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

.stat {
  position: relative;
  display: grid;
  gap: 2px;
  padding: 14px 14px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}
.stat::before {
  content: "";
  position: absolute;
  inset: -1px -1px auto -1px;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--tone, var(--border-strong));
}
.stat:hover { border-color: var(--border-strong); }
.stat[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }

.stat-total { --tone: var(--accent); }
.stat-active { --tone: var(--ok); }
.stat-draft { --tone: var(--warn); }
.stat-inactive { --tone: var(--idle); }
.stat-archived { --tone: var(--text-3); }

.stat-head { display: flex; align-items: center; gap: 6px; color: var(--tone); font-weight: 600; }
.stat-label { color: var(--text-2); }
.stat-value { font-size: 30px; font-weight: 650; line-height: 1.15; letter-spacing: -0.01em; }
.stat-hint { font-size: 12px; color: var(--text-3); }
@media (max-width: 599px) {
  .stat { padding: 10px 14px; }
  .stat-hint { display: none; }
}

/* --------------------------------------------------------------- toolbar */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px var(--gutter);
}

.search { position: relative; flex: 1 1 260px; }
.search > .icon { position: absolute; left: 11px; top: 50%; margin-top: -8px; color: var(--text-3); pointer-events: none; }
.search input { padding-left: 34px; }

.family-wrap { flex: 0 1 170px; }
.select-wrap { flex: 0 0 auto; }
.select-wrap select { width: auto; min-width: 128px; }

.switch { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; cursor: pointer; user-select: none; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-track {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--border-strong);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.35);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
}
textarea { min-height: 78px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--accent); }
input::placeholder { color: var(--text-3); }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; }
input[readonly] { background: var(--surface-2); color: var(--text-2); }

@media (pointer: coarse) {
  .btn, .icon-btn, .switch, input, select { min-height: 44px; }
  .btn-sm { min-height: 40px; }
}

/* ----------------------------------------------------------------- table */

.list-region { overflow-x: auto; border-top: 1px solid var(--border); }
.list-region[aria-busy="true"] .products { opacity: 0.55; }

.products { width: 100%; border-collapse: collapse; }

.products th {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
.products td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.products :is(th, td):first-child { padding-left: var(--gutter); }
.products :is(th, td):last-child { padding-right: var(--gutter); }
.products tbody tr:hover { background: var(--surface-2); }
.products tr.is-archived .c-name,
.products tr.is-archived .c-brand { color: var(--text-2); }

.c-name { min-width: 11em; overflow-wrap: anywhere; }
.c-brand span, .c-name .sub { display: block; }
.c-platforms, .c-recv, .c-actions { white-space: nowrap; }
.sub { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.chip-row { display: flex; gap: 4px; }

.chip {
  padding: 0 7px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-2);
  font: 600 11.5px/1.7 var(--font-mono);
}

.c-status .badge { margin: 1px 4px 1px 0; }

.yn { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; }
.yn.yes { color: var(--ok); }
.yn.no { color: var(--text-3); }

.c-updated { white-space: nowrap; color: var(--text-2); }

.sku-link {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--accent-strong);
  font: 600 13px var(--font-mono);
  text-align: left;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 4px;
  white-space: nowrap;
  cursor: pointer;
}
.sku-link:hover { text-decoration-color: currentColor; }

.row-actions { display: flex; justify-content: flex-end; gap: 2px; }

.skeleton td { padding: 16px var(--gutter); }
.skel { display: block; width: 45%; height: 12px; margin: 6px 0; border-radius: 4px; background: var(--border); }
.skel-wide { width: 75%; }

.state { display: grid; justify-items: center; gap: 6px; padding: 44px var(--gutter); text-align: center; }
.state h3 { font-size: 15px; }
.state p { max-width: 42ch; color: var(--text-2); }
.state-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 6px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-3);
}
.state-icon .icon { width: 22px; height: 22px; }
.state-actions { margin-top: 10px; }

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  padding: 10px var(--gutter);
  border-top: 1px solid var(--border);
  color: var(--text-2);
  font-size: 13px;
}
.pager-buttons { display: flex; align-items: center; gap: 10px; }

/* Narrow screens: every row becomes a stacked card. */
@media (max-width: 1159px) {
  .products, .products tbody, .products tr, .products td { display: block; }
  .products thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

  .products tbody {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
    gap: 12px;
    padding: 12px;
  }
  .products tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px 10px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
  }
  .products tbody tr:hover { background: var(--surface); }
  .products td, .products td:first-child, .products td:last-child { padding: 0; border: 0; }

  .c-sku { grid-column: 1; grid-row: 1; min-width: 0; }
  .sku-link { white-space: normal; overflow-wrap: anywhere; }
  .c-status { grid-column: 2; grid-row: 1; justify-self: end; }
  .c-name { grid-column: 1 / -1; font-weight: 500; overflow-wrap: anywhere; }
  .products .c-brand span { min-width: 0; overflow-wrap: anywhere; }
  .sub { white-space: normal; }
  .products .c-brand, .products .c-platforms, .products .c-recv, .products .c-updated {
    grid-column: 1 / -1;
    display: flex;
    align-items: baseline;
    gap: 10px;
    font-size: 13px;
  }
  .c-brand::before, .c-platforms::before, .c-recv::before, .c-updated::before {
    content: attr(data-label);
    flex: none;
    width: 5.5em;
    color: var(--text-3);
    font-size: 12px;
  }
  .products .c-actions { grid-column: 1 / -1; margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--border); }
  .c-actions .row-actions { flex-wrap: wrap; justify-content: flex-start; }
  .chip-row { flex-wrap: wrap; }
  .skeleton td { grid-column: 1 / -1; }
  .skeleton { display: block; }
}

/* ------------------------------------------------------- interfaces panel */

.fold > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px var(--gutter);
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary .chev { transform: rotate(-90deg); color: var(--text-3); }
.fold[open] > summary .chev { transform: none; }
.fold-note { margin-left: auto; color: var(--text-3); font-size: 12px; font-weight: 400; }

.fold-body { padding: 4px var(--gutter) var(--gutter); }
.fold-cols { display: grid; gap: 22px; }
@media (min-width: 860px) {
  .fold-cols { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 32px; }
}
.fold-body h3 { margin: 0 0 8px; color: var(--text-3); font-size: 12px; font-weight: 600; letter-spacing: 0.04em; }
.fold-body h3:not(:first-child) { margin-top: 18px; }
.row-between { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.row-between h3 { margin: 0; }
.fold-body .hint { margin-top: 6px; }

.endpoints li { display: flex; align-items: baseline; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.method { flex: none; min-width: 3.6em; color: var(--accent-strong); font: 700 11px var(--font-mono); letter-spacing: 0.04em; }
.method-get { color: var(--ok); }
.link-row { margin-top: 10px; }
.link-row a { display: inline-flex; align-items: center; gap: 5px; }
.link-row .icon { width: 14px; height: 14px; }

.stream-id { display: block; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); user-select: all; }

.events li {
  display: grid;
  grid-template-columns: 4.4em 5.2em minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 4px 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.ev-seq { color: var(--text-3); font: 12px var(--font-mono); }
.ev-type { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; }
.ev-type .icon { width: 13px; height: 13px; }
.ev-sku { font-weight: 600; }
.ev-ver, .ev-time { color: var(--text-2); font-size: 12.5px; white-space: nowrap; }
@media (max-width: 559px) {
  .events li { grid-template-columns: 4em minmax(0, 1fr) auto; grid-template-areas: "seq type ver" "sku sku time"; }
  .ev-seq { grid-area: seq; }
  .ev-type { grid-area: type; }
  .ev-ver { grid-area: ver; }
  .ev-sku { grid-area: sku; }
  .ev-time { grid-area: time; }
}

.inline-error { display: flex; align-items: center; gap: 6px; color: var(--bad); font-weight: 500; }

/* --------------------------------------------------------------- roadmap */

.roadmap { display: grid; gap: 10px; }
.roadmap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 12px; }

.road-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 50%, transparent);
  color: var(--text-2);
}
.road-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.road-head h3 { font-size: 14px; font-weight: 600; }
.road-consumes { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; }
.road-label { color: var(--text-3); }
.road-consumes code { padding: 0 6px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-2); }

/* ---------------------------------------------------------------- drawer */

.drawer {
  width: min(560px, 100vw);
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.drawer[open] { display: flex; }
.drawer::backdrop, .modal::backdrop { background: var(--scrim); }
.drawer > form { display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; }

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 { font-size: 16px; }
.drawer-sub { margin-top: 2px; color: var(--text-3); font: 13px var(--font-mono); }
.drawer-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 18px 20px 24px; }
.drawer-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 20px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.bare { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { padding: 0; }

.notice {
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  border-radius: 6px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
}

.group { margin-bottom: 24px; }
.group > h3 { margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); color: var(--text-3); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; }
.group-note { margin: -4px 0 12px; color: var(--text-3); font-size: 12px; }

.field { min-width: 0; margin-bottom: 14px; }
.field > label, .field > legend { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 600; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 479px) {
  .field-row.wide { grid-template-columns: 1fr; }
}

.req { margin-left: 4px; padding: 0 5px; border: 1px solid var(--border-strong); border-radius: 3px; color: var(--text-3); font-size: 11px; font-weight: 500; }

.hint { margin-top: 5px; color: var(--text-3); font-size: 12px; }
.hint .icon { width: 13px; height: 13px; margin-right: 4px; vertical-align: -2px; }

.error { margin-top: 5px; color: var(--bad); font-size: 12.5px; font-weight: 500; }
.error::before {
  content: "!";
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--bad);
  color: var(--on-bad);
  font-size: 10px;
  font-weight: 800;
  vertical-align: 1px;
}
.field.has-error :is(input, select, textarea) { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }

.chips, .segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-toggle input, .seg input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.chip-toggle, .seg { position: relative; cursor: pointer; }

.chip-toggle span, .seg-face {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-2);
  font-weight: 600;
}
.chip-toggle span { border-radius: 999px; font-family: var(--font-mono); font-size: 13px; }
.chip-toggle .icon { display: none; width: 14px; height: 14px; }
.chip-toggle input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
.chip-toggle input:checked + span .icon { display: block; }
.seg-face .icon { color: var(--tone); }
.seg input:checked + .seg-face { border-color: var(--tone); background: var(--tone-soft); color: var(--tone); box-shadow: 0 0 0 1px var(--tone); }
.chip-toggle input:focus-visible + span, .seg input:focus-visible + .seg-face { outline: 2px solid var(--accent); outline-offset: 2px; }
.bare:disabled .chip-toggle, .bare:disabled .seg { cursor: default; }
.bare:disabled :is(input, select, textarea) { opacity: 1; color: var(--text-2); background: var(--surface-2); }

.meta-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.meta-strip dt { color: var(--text-3); font-size: 12px; }
.meta-strip dd { font-size: 13px; }
.meta-strip:empty { display: none; }

/* ------------------------------------------------------- confirm + toasts */

.modal {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.modal-inner { padding: 20px; }
.modal h2 { margin-bottom: 10px; font-size: 16px; }
.modal-body { display: grid; gap: 8px; color: var(--text-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.toasts {
  position: fixed;
  right: var(--gutter);
  bottom: var(--gutter);
  z-index: 60;
  display: grid;
  gap: 10px;
  width: min(420px, calc(100vw - 2 * var(--gutter)));
  pointer-events: none;
}
/* A page-level toast would sit under an open modal drawer, so the drawer hosts its own. */
.drawer > .toasts { position: absolute; right: 16px; bottom: 76px; left: 16px; width: auto; }

.toast {
  --tone: var(--accent);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  padding: 12px 8px 12px 12px;
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--tone);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  pointer-events: auto;
}
.toast > .icon { margin-top: 2px; color: var(--tone); }
.toast .icon-btn { width: 28px; height: 28px; }
.toast-success { --tone: var(--ok); }
.toast-error { --tone: var(--bad); }
.toast-msg { font-weight: 600; overflow-wrap: anywhere; }
.toast-detail { margin-top: 2px; color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; }
.toast-code { display: inline-block; margin-top: 4px; color: var(--text-3); font-size: 11.5px; }

/* ---------------------------------------------------------------- motion */

@media (prefers-reduced-motion: no-preference) {
  .btn, .icon-btn, .stat, .switch-track, .switch-track::after { transition: background-color 0.15s, border-color 0.15s, transform 0.15s, color 0.15s; }
  .fold > summary .chev { transition: transform 0.15s; }
  .products, .page { transition: opacity 0.2s; }
  .drawer[open] { animation: drawer-in 0.2s ease-out; }
  .modal[open] { animation: fade-up 0.16s ease-out; }
  .toast { animation: fade-up 0.18s ease-out; }
  .skel {
    background: linear-gradient(90deg, var(--border) 25%, var(--surface-2) 50%, var(--border) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s linear infinite;
  }
}

@keyframes drawer-in { from { transform: translateX(28px); opacity: 0; } }
@keyframes fade-up { from { transform: translateY(8px); opacity: 0; } }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 479px) {
  .toasts { right: 12px; bottom: 12px; width: calc(100vw - 24px); }
  .drawer-head, .drawer-foot { padding-left: 16px; padding-right: 16px; }
  .drawer-body { padding-left: 16px; padding-right: 16px; }
}

/* ------------------------------------------------------------------ tabs */

.tabs { display: flex; gap: 4px; width: 100%; max-width: var(--page-max); margin: 0 auto; padding: 0 var(--gutter); }
.tab {
  padding: 9px 16px 10px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-2);
  font-weight: 600;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.is-active { border-bottom-color: var(--accent); color: var(--accent-strong); }

/* --------------------------------------------------------- warehouse page */

.wh-select-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.wh-select-row select { min-width: 200px; width: auto; }
#wh-empty { padding: 0 var(--gutter) 14px; }
#wh-stats .stat { cursor: default; }
#wh-stats .stat:hover { border-color: var(--border); }

#wh-stock-region, #wh-docs-region { overflow-x: auto; border-top: 1px solid var(--border); }
#wh-stock-region[aria-busy="true"], #wh-docs-region[aria-busy="true"] { opacity: 0.55; }
#wh-stock-region > .muted, #wh-docs-region > .muted, #wh-stock-region > .inline-error, #wh-docs-region > .inline-error { display: block; padding: 20px var(--gutter); }

.wh-stock-group { border-bottom: 1px solid var(--border); }
.wh-stock-group:last-child { border-bottom: 0; }
.wh-stock-group > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--gutter);
  list-style: none;
  cursor: pointer;
}
.wh-stock-group > summary::-webkit-details-marker { display: none; }
.wh-stock-group > summary:hover { background: var(--surface-2); }
.wh-stock-group > summary code { font: 700 13px var(--font-mono); }
.wh-stock-total { margin-left: auto; color: var(--text-2); font-weight: 600; white-space: nowrap; }

.wh-stock-detail { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.wh-stock-detail th {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-3);
  font-size: 11.5px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
.wh-stock-detail td { padding: 6px 12px; border-bottom: 1px solid var(--border); font-size: 13px; white-space: nowrap; }
.wh-stock-detail :is(th, td):first-child { padding-left: calc(var(--gutter) + 18px); }
.wh-stock-detail :is(th, td):last-child { padding-right: var(--gutter); }
.wh-row-actions { display: flex; justify-content: flex-end; gap: 4px; }

.wh-forms { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 860px) {
  .wh-forms { grid-template-columns: 1fr 1fr; }
}
.wh-form { padding: 14px var(--gutter) var(--gutter); }
.wh-form .field:last-of-type { margin-bottom: 10px; }
.wh-form-foot { display: flex; justify-content: flex-end; padding-top: 4px; }

.wh-pack-intro { padding: 0 var(--gutter) 10px; }
.wh-pack-cols { display: grid; gap: 16px; grid-template-columns: 1fr; margin-bottom: 10px; }
@media (min-width: 860px) {
  .wh-pack-cols { grid-template-columns: 1fr 1fr; }
}
.wh-pack-balance {
  margin: 4px 0 0;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-2);
  font-weight: 600;
  font-size: 13px;
}
.wh-pack-balance.tone-ok { background: var(--ok-soft); color: var(--ok); }
.wh-pack-balance.tone-danger { background: var(--bad-soft); color: var(--bad); }

.stocktake-delta { font-weight: 600; }
.stocktake-delta.tone-ok { color: var(--ok); }
.stocktake-delta.tone-danger { color: var(--bad); }
.stocktake-status.tone-ok { color: var(--ok); }
.stocktake-status.tone-danger { color: var(--bad); font-weight: 600; }
.stocktake-skipped { margin-top: 10px; color: var(--text-2); font-size: 13px; }
.stocktake-skipped summary { cursor: pointer; }
.stocktake-skipped ul { margin: 6px 0 0; padding-left: 20px; }
#stocktake-result { margin-top: 14px; }
#stocktake-result > table { width: 100%; }

.wh-docs { width: 100%; border-collapse: collapse; }
.wh-docs th {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
.wh-docs td { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: top; white-space: nowrap; }
.wh-docs :is(th, td):first-child { padding-left: var(--gutter); }
.wh-docs :is(th, td):last-child { padding-right: var(--gutter); }

.sum-row { cursor: pointer; }
.sum-toggle { display: inline-block; width: 1em; color: var(--text-3); }
.sum-detail td { padding-top: 0; padding-bottom: 10px; background: var(--surface-2); }
.sum-reason-list { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; padding: 0; list-style: none; color: var(--text-2); font-size: 13px; }
#sum-table-wrap { overflow-x: auto; border-top: 1px solid var(--border); }
#sum-empty { padding: 14px var(--gutter); }

/* ------------------------------------------------ sign-in + security tab (security.js) */

/* Until /auth/me answers, and while signed out, only the sign-in screen is on the page. */
body.auth-pending :is(.skip-link, .topbar, #offline-banner, #main),
body.auth-mode :is(.skip-link, .topbar, #offline-banner, #main) { display: none !important; }
body.auth-pending .auth-screen { display: none; }

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 32px var(--gutter);
  background: radial-gradient(900px 480px at 50% -8%, var(--accent-soft), transparent 70%), var(--bg);
}
.auth-screen[hidden] { display: none; }
.auth-card {
  width: min(100%, 400px);
  padding: 28px 28px 22px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-brand .brand-name { font-size: 15px; }
.auth-title { font-size: 21px; font-weight: 650; letter-spacing: -0.01em; }
.auth-sub { margin: 4px 0 20px; color: var(--text-2); font-size: 14px; }
.auth-form[hidden], .auth-loading[hidden] { display: none; }
.auth-foot { margin-top: 16px; color: var(--text-3); font-size: 12.5px; text-align: center; }
.auth-foot a { color: var(--accent); }
.auth-loading { padding: 18px 0 8px; color: var(--text-3); text-align: center; }

.auth-error, .form-error {
  margin: 0 0 14px;
  padding: 9px 12px;
  border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent);
  border-radius: var(--radius);
  background: var(--bad-soft);
  color: var(--bad);
  font-size: 13px;
}
.auth-error[hidden], .form-error[hidden] { display: none; }

.btn-block { width: 100%; min-height: 40px; justify-content: center; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 44px; }
.pw-toggle { position: absolute; top: 50%; right: 4px; transform: translateY(-50%); }
.pw-toggle[aria-pressed="true"] { color: var(--accent); }

.user-menu { display: flex; align-items: center; gap: 6px; }
.user-menu[hidden] { display: none; }
.user-who { display: inline-flex; align-items: center; gap: 8px; margin-right: 4px; }
.user-name { font-weight: 600; }
.role-chip {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

#page-security { display: grid; gap: 16px; }
#page-security[hidden] { display: none; }
.sec-stats .stat { cursor: default; }
.sec-stats .stat:hover { border-color: var(--border); }
.sec-stats .stat-value { font-size: 26px; }
.sec-grid { display: grid; gap: 16px; }
@media (min-width: 960px) {
  .sec-grid { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; }
}
.panel-note { margin: 0; padding: 4px var(--gutter) 0; }
.table-scroll { overflow-x: auto; margin-top: 10px; }
/* A plain table at every width (the products table turns into cards below 1160px; these scroll instead). */
.sec-table { width: 100%; border-collapse: collapse; }
.sec-table th {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
.sec-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 13.5px; }
.sec-table :is(th, td):first-child { padding-left: var(--gutter); }
.sec-table :is(th, td):last-child { padding-right: var(--gutter); }
.sec-table tbody tr:last-child td { border-bottom: 0; }
.sec-table tbody tr:hover { background: var(--surface-2); }
.sec-table .nowrap, .sec-table td:first-child { white-space: nowrap; }
.sec-table .mono, .sec-table .sub { font-family: var(--font-mono); }
.sec-table .mono { font-size: 12.5px; }
.sec-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.sec-table .small { font-size: 12.5px; }
.sec-table .sub { display: block; color: var(--text-3); font-size: 11.5px; overflow-wrap: anywhere; }
.sec-table td .badge + .badge { margin-left: 4px; }
.sec-table tr.is-alert td { background: var(--bad-soft); }
.sec-actions { display: flex; flex-wrap: wrap; gap: 2px; }
.sec-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.empty-note { padding: 14px var(--gutter) 16px; }
.load-more { display: flex; justify-content: center; padding: 8px 0 12px; }
.load-more:not(:has(button:not([hidden]))) { display: none; }
.link-box { display: flex; gap: 8px; margin: 12px 0 6px; }
.link-box input { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 12.5px; }
