/* ============================================================
   Blanks Inventory — Compound Sportswear
   Operate-mode design system. One family, restrained colour,
   brand teal reserved for action + current state.
   ============================================================ */

/* ---------- Tokens: light is the base definition ---------- */
:root {
  color-scheme: light;

  --bg:        #F2F5F6;
  --surface:   #FFFFFF;
  --surface-2: #E9EEF0;
  --surface-3: #DFE6E9;
  --line:      #D3DCE1;
  --line-soft: #E4EAED;

  --text:      #0C1418;
  --text-2:    #53656F;
  --text-3:    #5C6E78;

  --accent:      #07707F;   /* teal, darkened for 4.5:1 on white */
  --accent-ink:  #05515C;
  --accent-fill: #07707F;
  --accent-on:   #FFFFFF;
  --accent-wash: #E2F2F5;
  --accent-edge: #A9D8DF;

  --danger:      #B3261E;
  --danger-fill: #C6342B;
  --danger-wash: #FCE9E7;
  --danger-edge: #F0BEB9;

  --warn:        #8A5300;
  --warn-fill:   #C98100;
  --warn-wash:   #FDF1DC;
  --warn-edge:   #EFD3A0;

  --ok:          #1C6B45;
  --ok-fill:     #228856;
  --ok-wash:     #E3F4EB;
  --ok-edge:     #B0DDC5;

  --idle:        #5A6B75;
  --idle-wash:   #E9EEF0;
  --idle-edge:   #CFD9DE;

  --shadow-1: 0 1px 2px rgba(12, 20, 24, .06), 0 2px 8px rgba(12, 20, 24, .05);
  --shadow-2: 0 2px 6px rgba(12, 20, 24, .08), 0 12px 32px rgba(12, 20, 24, .10);
  --shadow-3: 0 8px 20px rgba(12, 20, 24, .12), 0 32px 64px rgba(12, 20, 24, .18);

  --r-sm: 5px;
  --r:    8px;
  --r-lg: 12px;

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --nav-w: 232px;
  --bar-h: 60px;
  --ease: cubic-bezier(.22, 1, .36, 1);
}

/* ---------- Dark: system default, unless forced light ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
  :root:not([data-theme="light"]) {
    --bg:        #090D10;
    --surface:   #11171B;
    --surface-2: #171F24;
    --surface-3: #1E282E;
    --line:      #26333A;
    --line-soft: #1B242A;

    --text:      #E9F1F4;
    --text-2:    #98AAB4;
    --text-3:    #7E929D;

    --accent:      #45D3E8;
    --accent-ink:  #8AE6F3;
    --accent-fill: #24C1DB;
    --accent-on:   #04222A;
    --accent-wash: #0E2C33;
    --accent-edge: #1C4E59;

    --danger:      #FF8B82;
    --danger-fill: #E8483C;
    --danger-wash: #2E1512;
    --danger-edge: #5B2620;

    --warn:        #F5B94A;
    --warn-fill:   #D99413;
    --warn-wash:   #2C2110;
    --warn-edge:   #55401A;

    --ok:          #57D69A;
    --ok-fill:     #2CA96C;
    --ok-wash:     #10281D;
    --ok-edge:     #1F4B36;

    --idle:        #8496A0;
    --idle-wash:   #182025;
    --idle-edge:   #2A363D;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .35);
    --shadow-2: 0 2px 6px rgba(0, 0, 0, .5), 0 14px 34px rgba(0, 0, 0, .45);
    --shadow-3: 0 10px 24px rgba(0, 0, 0, .55), 0 36px 70px rgba(0, 0, 0, .6);
  }
}

/* ---------- Dark: explicit toggle ---------- */
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="dark"] {
  --bg:        #090D10;
  --surface:   #11171B;
  --surface-2: #171F24;
  --surface-3: #1E282E;
  --line:      #26333A;
  --line-soft: #1B242A;

  --text:      #E9F1F4;
  --text-2:    #98AAB4;
  --text-3:    #7E929D;

  --accent:      #45D3E8;
  --accent-ink:  #8AE6F3;
  --accent-fill: #24C1DB;
  --accent-on:   #04222A;
  --accent-wash: #0E2C33;
  --accent-edge: #1C4E59;

  --danger:      #FF8B82;
  --danger-fill: #E8483C;
  --danger-wash: #2E1512;
  --danger-edge: #5B2620;

  --warn:        #F5B94A;
  --warn-fill:   #D99413;
  --warn-wash:   #2C2110;
  --warn-edge:   #55401A;

  --ok:          #57D69A;
  --ok-fill:     #2CA96C;
  --ok-wash:     #10281D;
  --ok-edge:     #1F4B36;

  --idle:        #8496A0;
  --idle-wash:   #182025;
  --idle-edge:   #2A363D;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .35);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, .5), 0 14px 34px rgba(0, 0, 0, .45);
  --shadow-3: 0 10px 24px rgba(0, 0, 0, .55), 0 36px 70px rgba(0, 0, 0, .6);
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: "tnum" 1, "cv05" 1, "ss03" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Browser surfaces belong to the design system too. */
::selection { background: var(--accent-fill); color: var(--accent-on); }
:focus-visible {
  outline: 2px solid var(--accent-fill);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
* { scrollbar-color: var(--line) transparent; scrollbar-width: thin; }
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line);
  border: 3px solid transparent;
  border-radius: 99px;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

a { color: var(--accent); text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 2px; }
a:hover { color: var(--accent-ink); text-decoration-color: currentColor; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.015em; text-wrap: balance; }
h1 { font-size: 1.375rem; letter-spacing: -0.022em; }
h2 { font-size: 1.0625rem; }
h3 { font-size: .9375rem; }
p  { margin: 0; }

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

.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: .8125em; letter-spacing: -0.01em; }
.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ============================================================
   Shell
   ============================================================ */
.app { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100vh; }

/* --- Sidebar --- */
.nav {
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--bar-h); padding: 0 18px;
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
}
.brand-mark {
  width: 26px; height: 26px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--accent-fill); color: var(--accent-on);
  border-radius: var(--r-sm);
  font-weight: 700; font-size: 12px; letter-spacing: -0.04em;
}
.brand-name { font-weight: 650; font-size: .8125rem; letter-spacing: .01em; line-height: 1.15; }
.brand-sub { color: var(--text-3); font-size: .6875rem; letter-spacing: .05em; text-transform: uppercase; line-height: 1.15; }

.nav-scroll { flex: 1 1 auto; overflow-y: auto; padding: 14px 10px; }
.nav-label {
  padding: 12px 8px 6px;
  font-size: .625rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-3);
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px; margin-bottom: 1px;
  background: none; border: 0; border-radius: var(--r-sm);
  color: var(--text-2); font-weight: 500; text-align: left;
  cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.nav-item[aria-current="page"] .nav-ico { color: var(--accent); }
.nav-ico { width: 16px; height: 16px; flex: 0 0 auto; color: var(--text-3); }
.nav-count {
  margin-left: auto; padding: 1px 6px; border-radius: 99px;
  font-size: .6875rem; font-weight: 650;
  background: var(--surface-3); color: var(--text-2);
}
.nav-item[data-tone="danger"] .nav-count { background: var(--danger-wash); color: var(--danger); }
.nav-item[data-tone="warn"] .nav-count { background: var(--warn-wash); color: var(--warn); }

.nav-foot { flex: 0 0 auto; padding: 12px; border-top: 1px solid var(--line-soft); display: grid; gap: 8px; }

/* --- Topbar --- */
.main { min-width: 0; display: flex; flex-direction: column; }
.bar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: var(--bar-h); padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.bar-title { font-weight: 650; font-size: .9375rem; white-space: nowrap; }
.bar-spacer { flex: 1 1 auto; }

.search { position: relative; flex: 0 1 340px; min-width: 140px; }
.search svg { position: absolute; left: 10px; top: 50%; translate: 0 -50%; width: 15px; height: 15px; color: var(--text-3); pointer-events: none; }
.search input {
  width: 100%; height: 34px; padding: 0 30px 0 32px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.search input::placeholder { color: var(--text-3); }
.search input:focus { outline: none; border-color: var(--accent-fill); box-shadow: 0 0 0 3px var(--accent-wash); }
.search kbd {
  position: absolute; right: 8px; top: 50%; translate: 0 -50%;
  font-family: var(--sans); font-size: .625rem; font-weight: 600;
  padding: 2px 5px; border-radius: 4px;
  background: var(--surface-2); color: var(--text-3); border: 1px solid var(--line-soft);
}
.search input:focus + kbd { opacity: 0; }

.content { padding: 22px 20px 72px; max-width: 1560px; width: 100%; }

/* ============================================================
   Primitives
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 13px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  font-size: .8125rem; font-weight: 550; white-space: nowrap;
  cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease), transform .1s var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:active { transform: translateY(.5px); }
.btn svg { width: 15px; height: 15px; flex: 0 0 auto; }
.btn[disabled] { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--accent-on); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent-fill) 88%, var(--text)); border-color: transparent; }
.btn.danger { background: var(--danger-fill); border-color: var(--danger-fill); color: #fff; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger-fill) 88%, #000); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 28px; padding: 0 9px; font-size: .75rem; }
.btn.sm svg { width: 13px; height: 13px; }
.btn.icon { width: 34px; padding: 0; }
.btn.icon.sm { width: 28px; }
.btn.block { width: 100%; }
.btn.loading { color: transparent; position: relative; pointer-events: none; }
.btn.loading::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 20%, transparent);
  border-top-color: var(--text);
  animation: spin .7s linear infinite;
}
.btn.primary.loading::after { border-top-color: var(--accent-on); }
@keyframes spin { to { rotate: 360deg; } }

.field { display: grid; gap: 5px; min-width: 0; }
.field > label { font-size: .6875rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); }
.input, select.input, textarea.input {
  width: 100%; height: 34px; padding: 0 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
textarea.input { height: auto; min-height: 66px; padding: 8px 10px; resize: vertical; }
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--accent-fill); box-shadow: 0 0 0 3px var(--accent-wash); }
.input:disabled { background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }
select.input {
  appearance: none; padding-right: 28px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.hint { font-size: .75rem; color: var(--text-3); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--line-soft);
}
.card-head h2, .card-head h3 { min-width: 0; }
.card-head .sub { color: var(--text-3); font-size: .75rem; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 99px;
  font-size: .6875rem; font-weight: 650; letter-spacing: .02em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.pill.out      { background: var(--danger-wash); color: var(--danger); border-color: var(--danger-edge); }
.pill.critical { background: var(--warn-wash);   color: var(--warn);   border-color: var(--warn-edge); }
.pill.low      { background: var(--accent-wash); color: var(--accent); border-color: var(--accent-edge); }
.pill.ok       { background: var(--ok-wash);     color: var(--ok);     border-color: var(--ok-edge); }
.pill.unknown, .pill.retired { background: var(--idle-wash); color: var(--idle); border-color: var(--idle-edge); }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 7px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line-soft);
  color: var(--text-2); font-size: .6875rem; font-weight: 550;
}
.swatch { width: 9px; height: 9px; border-radius: 2px; border: 1px solid rgba(128,128,128,.45); flex: 0 0 auto; }

/* ============================================================
   Dashboard
   ============================================================ */
.stack { display: grid; gap: 18px; min-width: 0; }
.stack > * { min-width: 0; }
.row-2 { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.row-2 > * { min-width: 0; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 12px; }
.kpi {
  position: relative; overflow: hidden;
  padding: 14px 15px 15px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-1);
}
.kpi::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--tone, var(--line));
}
.kpi-k { font-size: .6875rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--text-3); }
.kpi-v { margin-top: 7px; font-size: 1.875rem; font-weight: 620; letter-spacing: -0.035em; line-height: 1; color: var(--tone-text, var(--text)); }
.kpi-s { margin-top: 6px; font-size: .75rem; color: var(--text-3); }
.kpi.is-danger { --tone: var(--danger-fill); --tone-text: var(--danger); }
.kpi.is-warn   { --tone: var(--warn-fill);   --tone-text: var(--warn); }
.kpi.is-ok     { --tone: var(--ok-fill);     --tone-text: var(--ok); }
.kpi.is-accent { --tone: var(--accent-fill); }

/* Alert rows */
.alerts { display: grid; }
.alert {
  display: grid;
  grid-template-columns: 4px minmax(0, 1fr) auto auto;
  align-items: center; gap: 12px;
  padding: 10px 16px 10px 0;
  border-bottom: 1px solid var(--line-soft);
  background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%; text-align: left; cursor: pointer;
  transition: background .13s var(--ease);
}
.alert:last-child { border-bottom: 0; }
.alert:hover { background: var(--surface-2); }
.alert-rail { align-self: stretch; background: var(--rail, var(--line)); }
.alert[data-status="out"]      { --rail: var(--danger-fill); }
.alert[data-status="critical"] { --rail: var(--warn-fill); }
.alert[data-status="low"]      { --rail: var(--accent-fill); }
.alert[data-status="unknown"]  { --rail: var(--idle-edge); }
.alert-main { min-width: 0; }
.alert-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-meta { margin-top: 2px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--text-3); font-size: .75rem; }
.alert-qty { text-align: right; }
.alert-qty b { display: block; font-size: 1.0625rem; font-weight: 620; letter-spacing: -0.02em; line-height: 1.1; }
.alert-qty span { font-size: .6875rem; color: var(--text-3); }

/* Bars */
.bars { display: grid; gap: 12px; }
.bar-row { display: grid; gap: 5px; }
.bar-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: .8125rem; }
.bar-top b { font-weight: 600; }
.bar-top span { color: var(--text-3); font-size: .75rem; }
.bar-track { height: 7px; border-radius: 99px; background: var(--surface-3); display: flex; overflow: hidden; }
.bar-seg { height: 100%; }
.bar-seg.out { background: var(--danger-fill); }
.bar-seg.critical { background: var(--warn-fill); }
.bar-seg.low { background: var(--accent-fill); }
.bar-seg.ok { background: var(--ok-fill); }
.bar-seg.unknown, .bar-seg.retired { background: var(--idle-edge); }

.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .75rem; color: var(--text-2); }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

/* ============================================================
   Tables
   ============================================================ */
.tablewrap { overflow-x: auto; overscroll-behavior-x: contain; }
.tablewrap.tall { max-height: min(calc(100dvh - 232px), 780px); overflow: auto; overscroll-behavior: contain; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .8125rem; }
table.data.fixed { table-layout: fixed; }
table.data.fixed td, table.data.fixed th { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.data th, table.data td { padding: 9px 12px; text-align: left; vertical-align: middle; }
table.data thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: .625rem; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3);
  white-space: nowrap;
}
table.data thead th.sortable { cursor: pointer; user-select: none; }
table.data thead th.sortable:hover { color: var(--text); }
table.data thead th .arrow { opacity: 0; margin-left: 3px; }
table.data thead th[aria-sort] { color: var(--accent); }
table.data thead th[aria-sort] .arrow { opacity: 1; }
table.data tbody tr { cursor: pointer; transition: background .12s var(--ease); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody td { border-bottom: 1px solid var(--line-soft); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.r, table.data th.r { text-align: right; }
table.data td.qty { font-weight: 620; font-size: .875rem; letter-spacing: -0.01em; }
table.data td.dim { color: var(--text-3); }
.cellwrap { display: flex; align-items: center; gap: 7px; min-width: 0; }
.cellwrap > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.toolbar .grow { flex: 1 1 auto; }
.chipset { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  padding: 4px 10px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text-2);
  font-size: .75rem; font-weight: 550; cursor: pointer;
  transition: background .14s var(--ease), color .14s var(--ease), border-color .14s var(--ease);
}
.chip:hover { border-color: var(--text-3); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent-wash); border-color: var(--accent-edge); color: var(--accent); font-weight: 620; }

/* ============================================================
   Size grid (colour x size matrix)
   ============================================================ */
.gridblock + .gridblock { margin-top: 18px; }
.matrix { border-collapse: separate; border-spacing: 0; font-size: .8125rem; }
.matrix th, .matrix td { padding: 0; }
.matrix thead th {
  padding: 8px 6px; font-size: .625rem; font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-3); text-align: center; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.matrix thead th:first-child, .matrix tbody th { text-align: left; padding-left: 16px; padding-right: 14px; }
.matrix tbody th {
  font-weight: 600; white-space: nowrap; color: var(--text);
  min-width: 130px;
  border-bottom: 1px solid var(--line-soft);
  position: sticky; left: 0; background: var(--surface); z-index: 1;
}
.matrix tbody td { border-bottom: 1px solid var(--line-soft); text-align: center; }
.matrix tbody tr:last-child th, .matrix tbody tr:last-child td { border-bottom: 0; }
.cellbtn {
  display: block; width: 100%; min-width: 54px; padding: 9px 6px;
  background: none; border: 0; cursor: pointer;
  font-weight: 620; font-size: .875rem; letter-spacing: -0.01em;
  color: var(--text);
  position: relative;
  transition: background .12s var(--ease);
}
.cellbtn::after {
  content: ""; position: absolute; left: 6px; right: 6px; bottom: 4px; height: 2px;
  border-radius: 2px; background: var(--cell, transparent);
}
.cellbtn:hover { background: var(--surface-2); }
.cellbtn[data-status="out"]      { --cell: var(--danger-fill); color: var(--danger); }
.cellbtn[data-status="critical"] { --cell: var(--warn-fill); color: var(--warn); }
.cellbtn[data-status="low"]      { --cell: var(--accent-fill); }
.cellbtn[data-status="ok"]       { --cell: color-mix(in srgb, var(--ok-fill) 45%, transparent); }
.cellbtn[data-status="unknown"], .cellbtn[data-status="retired"] { color: var(--text-3); --cell: var(--idle-edge); }
.cellbtn.blank { color: var(--text-3); opacity: .38; cursor: default; pointer-events: none; }

/* ============================================================
   Drawer / dialogs
   ============================================================ */
dialog.drawer {
  position: fixed; inset: 0 0 0 auto; margin: 0;
  width: min(460px, 100%); max-width: 100%; height: 100dvh; max-height: 100dvh;
  padding: 0; border: 0; border-left: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-3);
  overflow: visible;
}
dialog.sheet {
  margin: auto; width: min(620px, calc(100% - 32px)); max-height: min(86dvh, 900px);
  padding: 0; border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-3);
}
dialog::backdrop { background: rgba(6, 10, 12, .55); backdrop-filter: blur(2px); }
dialog[open] { animation: dlg-in .24s var(--ease); }
dialog.drawer[open] { animation: drw-in .28s var(--ease); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.985); } }
@keyframes drw-in { from { transform: translateX(18px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  dialog[open], dialog.drawer[open] { animation: none; }
  * { scroll-behavior: auto !important; }
}

.dlg { display: flex; flex-direction: column; max-height: inherit; height: 100%; }
.dlg-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 16px 14px; border-bottom: 1px solid var(--line-soft); flex: 0 0 auto;
}
.dlg-head .grow { min-width: 0; }
.dlg-body { padding: 16px; overflow-y: auto; flex: 1 1 auto; }
.dlg-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--line-soft);
  background: var(--surface-2); flex: 0 0 auto;
}
.dlg-foot .grow { flex: 1 1 auto; }

.kv { display: grid; grid-template-columns: minmax(96px, auto) minmax(0, 1fr); gap: 7px 14px; font-size: .8125rem; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }

.section { border-top: 1px solid var(--line-soft); margin-top: 16px; padding-top: 16px; }
.section:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.section-t { font-size: .6875rem; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin-bottom: 10px; }

.sizegrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); gap: 8px; }
.sizecell { display: grid; gap: 4px; }
.sizecell label { font-size: .6875rem; font-weight: 650; color: var(--text-2); display: flex; justify-content: space-between; gap: 4px; }
.sizecell label em { font-style: normal; color: var(--text-3); font-weight: 500; }
.sizecell input { height: 32px; text-align: center; padding: 0 4px; }
.sizecell.is-over input { border-color: var(--warn-fill); box-shadow: 0 0 0 3px var(--warn-wash); }

/* ============================================================
   Status strip / toasts / misc
   ============================================================ */
.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 13px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface);
  font-size: .8125rem;
}
.banner.warn { background: var(--warn-wash); border-color: var(--warn-edge); color: var(--warn); }
.banner.info { background: var(--accent-wash); border-color: var(--accent-edge); color: var(--accent); }
.banner.danger { background: var(--danger-wash); border-color: var(--danger-edge); color: var(--danger); }
.banner .grow { flex: 1 1 auto; }
.banner svg { width: 16px; height: 16px; flex: 0 0 auto; }

.conn { display: flex; align-items: center; gap: 7px; font-size: .75rem; color: var(--text-2); }
.conn .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--idle); flex: 0 0 auto; }
.conn[data-state="live"] .dot { background: var(--ok-fill); box-shadow: 0 0 0 3px var(--ok-wash); }
.conn[data-state="local"] .dot { background: var(--warn-fill); box-shadow: 0 0 0 3px var(--warn-wash); }
.conn[data-state="error"] .dot { background: var(--danger-fill); box-shadow: 0 0 0 3px var(--danger-wash); }

#toasts {
  position: fixed; z-index: 100; right: 16px; bottom: 16px;
  display: grid; gap: 8px; width: min(360px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 11px 13px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-2); font-size: .8125rem;
  animation: toast-in .26s var(--ease);
}
.toast svg { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 1px; }
.toast.ok svg { color: var(--ok); }
.toast.err { border-color: var(--danger-edge); }
.toast.err svg { color: var(--danger); }
.toast .grow { flex: 1 1 auto; min-width: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }

.emptystate { padding: 44px 20px; text-align: center; color: var(--text-3); display: grid; gap: 8px; justify-items: center; }
.emptystate svg { width: 26px; height: 26px; opacity: .7; }
.emptystate b { color: var(--text); font-weight: 600; font-size: .9375rem; }
.emptystate p { max-width: 42ch; margin: 0; }

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shim 1.3s ease-in-out infinite; border-radius: var(--r-sm); }
@keyframes shim { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1080px) {
  .row-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .nav {
    position: fixed; inset: 0 auto 0 0; z-index: 60;
    width: 262px; height: 100dvh;
    translate: -100% 0;
    transition: translate .26s var(--ease);
    box-shadow: var(--shadow-3);
  }
  body[data-nav="open"] .nav { translate: 0 0; }
  body[data-nav="open"]::after {
    content: ""; position: fixed; inset: 0; z-index: 55;
    background: rgba(6, 10, 12, .5);
  }
  .navtoggle { display: inline-flex !important; }
  .content { padding: 16px 14px 72px; }
  .bar { padding: 0 14px; gap: 8px; }
  .bar-title { display: none; }
  dialog.drawer { width: 100%; border-left: 0; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-v { font-size: 1.5rem; }
  .alert { grid-template-columns: 4px minmax(0, 1fr) auto; }
  .alert .alert-act { display: none; }
}
.navtoggle { display: none; }

@media print {
  .nav, .bar, .toolbar, #toasts { display: none !important; }
  .app { display: block; }
  .content { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}

/* ============================================================
   Sign-in gate
   ============================================================ */
#gate[hidden] { display: none; }
#gate {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  padding: 24px;
  background: var(--bg);
  overflow-y: auto;
}
#gate.overlay { background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px); }
.gate-card {
  width: min(400px, 100%);
  padding: 30px 28px 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  text-align: center;
  animation: gate-in .32s var(--ease);
}
@keyframes gate-in { from { opacity: 0; transform: translateY(10px) scale(.98); filter: blur(3px); } }
@media (prefers-reduced-motion: reduce) { .gate-card { animation: none; } }
.gate-mark {
  width: 42px; height: 42px; margin: 0 auto 16px;
  display: grid; place-items: center;
  background: var(--accent-fill); color: var(--accent-on);
  border-radius: 10px; font-weight: 700; font-size: 18px; letter-spacing: -0.04em;
}
.gate-card h1 { font-size: 1.1875rem; }
.gate-card p { margin-top: 8px; color: var(--text-2); font-size: .8125rem; line-height: 1.55; }
.gate-btn { margin-top: 22px; display: flex; justify-content: center; min-height: 44px; }
.gate-note {
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line-soft);
  font-size: .75rem; color: var(--text-3);
}
.gate-err {
  margin-top: 16px; padding: 9px 12px; text-align: left;
  background: var(--danger-wash); border: 1px solid var(--danger-edge);
  color: var(--danger); border-radius: var(--r); font-size: .8125rem;
}

/* Signed-in identity chip */
.me { display: flex; align-items: center; gap: 9px; min-width: 0; }
.me-av {
  width: 26px; height: 26px; flex: 0 0 auto; border-radius: 50%;
  background: var(--surface-3); color: var(--text-2);
  display: grid; place-items: center;
  font-size: .6875rem; font-weight: 650; letter-spacing: .02em;
  object-fit: cover; overflow: hidden;
}
.me-txt { min-width: 0; line-height: 1.25; }
.me-name { font-size: .75rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-role { font-size: .6875rem; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-role[data-role="admin"] { color: var(--accent); }
