/* MAT-SA Storage Intelligence
   Black, white and grey. Colour is reserved for bin status, where it carries meaning. */
:root {
  --bg: #000000;
  --panel: #0a0a0a;
  --raise: #141414;
  --line: #262626;
  --line-strong: #3a3a3a;
  --text: #ededed;
  --muted: #8f8f8f;
  --faint: #5c5c5c;
  --invert-bg: #ededed;
  --invert-text: #000000;

  --s-empty: #2fa36b;
  --s-occupied: #3b82f6;
  --s-amber: #e5a00d;
  --s-red: #e5484d;
  --s-grey: #4b4b52;

  --radius-s: 6px;
  --radius-m: 10px;
  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --rail: 232px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff; --panel: #fafafa; --raise: #f2f2f2; --line: #e6e6e6; --line-strong: #cfcfcf;
    --text: #000000; --muted: #666666; --faint: #9a9a9a; --invert-bg: #000000; --invert-text: #ffffff;
    --s-grey: #a1a1aa; color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #ffffff; --panel: #fafafa; --raise: #f2f2f2; --line: #e6e6e6; --line-strong: #cfcfcf;
  --text: #000000; --muted: #666666; --faint: #9a9a9a; --invert-bg: #000000; --invert-text: #ffffff;
  --s-grey: #a1a1aa; color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.02em; }
h1 { font-size: 24px; line-height: 1.2; }
h2 { font-size: 16px; line-height: 1.3; }
h3 { font-size: 14px; }
p { margin: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono, code { font-family: var(--mono); font-size: 12.5px; letter-spacing: -0.01em; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- shell */
.shell { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 4px; background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border: 1.5px solid var(--text); border-radius: 5px; position: relative; flex: none;
}
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; left: 4px; right: 4px; height: 1.5px; background: var(--text); }
.brand-mark::before { top: 8px; } .brand-mark::after { top: 14px; }
.brand-name { font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.brand-name small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; letter-spacing: 0; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-s);
  color: var(--muted); text-decoration: none; font-size: 14px;
}
.nav a:hover { color: var(--text); background: var(--raise); }
.nav a[aria-current="page"] { color: var(--text); background: var(--raise); }
.nav svg { width: 16px; height: 16px; flex: none; }
.nav-group { margin-top: 14px; padding: 0 10px 4px; color: var(--faint); font-size: 12px; }
.rail-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.who { padding: 0 10px; font-size: 13px; }
.who span { display: block; color: var(--muted); font-size: 12px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.page { padding: 28px 32px 48px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { margin-top: 6px; max-width: 64ch; }

/* ---------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 12px;
  border-radius: var(--radius-s); border: 1px solid var(--line-strong); background: var(--bg); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--raise); }
.btn-primary { background: var(--invert-bg); color: var(--invert-text); border-color: var(--invert-bg); }
.btn-primary:hover { background: var(--invert-bg); opacity: 0.88; }
.btn-ghost { border-color: transparent; }
.btn-danger { color: var(--s-red); }
.btn-sm { height: 28px; padding: 0 9px; font-size: 13px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
label > span.hint { font-size: 12px; color: var(--faint); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line-strong);
  border-radius: var(--radius-s); height: 36px; padding: 0 10px; width: 100%; min-width: 0;
}
textarea { height: auto; padding: 8px 10px; min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--text); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--text); }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.field-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.with-action { display: flex; gap: 6px; }
.with-action input { flex: 1; }
.form-grid { display: grid; gap: 16px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-s); padding: 2px; gap: 2px; background: var(--bg); }
.seg button, .seg a {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; padding: 4px 10px;
  border-radius: 4px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.seg [aria-pressed="true"], .seg [aria-current="page"] { background: var(--raise); color: var(--text); }

/* ---------- surfaces */
.section { border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--bg); }
.section + .section { margin-top: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.section-body { padding: 18px; }
.split { display: grid; gap: 20px; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 500; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; font-size: 12.5px; }
td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: var(--panel); }
.empty-state { padding: 40px 18px; text-align: center; color: var(--muted); display: grid; gap: 12px; justify-items: center; }

.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 2px; flex: none; background: var(--s-grey); }
.dot.empty { background: var(--s-empty); } .dot.occupied { background: var(--s-occupied); }
.dot.reserved, .dot.near_full, .dot.warning { background: var(--s-amber); }
.dot.exception, .dot.critical { background: var(--s-red); } .dot.blocked, .dot.info { background: var(--s-grey); }
.tag { display: inline-block; font-size: 12px; padding: 1px 7px; border: 1px solid var(--line-strong); border-radius: 99px; color: var(--muted); }

.flash { margin: 16px 32px 0; padding: 10px 14px; border-radius: var(--radius-s); border: 1px solid var(--line-strong); font-size: 14px; }
.flash.error { border-color: var(--s-red); }
.flash.ok { border-color: var(--line-strong); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(12px); opacity: 0;
  background: var(--invert-bg); color: var(--invert-text); padding: 10px 16px; border-radius: var(--radius-s);
  font-weight: 500; z-index: 60; transition: opacity .18s, transform .18s; max-width: min(560px, calc(100vw - 32px));
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--s-red); color: #fff; }

.stat-line { display: flex; flex-wrap: wrap; gap: 28px; }
.stat b { display: block; font-size: 22px; font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 12.5px; }

.bar { height: 6px; background: var(--raise); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--text); border-radius: 3px; }
.bar.warn > i { background: var(--s-amber); } .bar.crit > i { background: var(--s-red); }

/* ---------- space view */
.space { display: grid; grid-template-columns: minmax(0, 1fr) 380px; height: 100vh; }
.space-stage { position: relative; min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.space-top {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line);
  flex-wrap: wrap; background: var(--bg); z-index: 2;
}
.space-top .title { display: flex; align-items: center; gap: 8px; margin-right: auto; min-width: 0; }
.space-top select { width: auto; height: 32px; }
.space-top input[type="search"] { width: 200px; height: 32px; }
#scene { position: relative; flex: 1; min-height: 320px; overflow: hidden; cursor: grab; touch-action: none; }
#scene:active { cursor: grabbing; }
#scene canvas { display: block; }
.scene-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.legend {
  position: absolute; left: 14px; bottom: 14px; display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 8px 12px;
  background: color-mix(in srgb, var(--bg) 84%, transparent); border: 1px solid var(--line); border-radius: var(--radius-s);
  max-width: calc(100% - 28px); backdrop-filter: blur(6px);
}
.legend .chip { color: var(--text); }
.cam { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 6px; }
.cam .btn { background: color-mix(in srgb, var(--bg) 84%, transparent); backdrop-filter: blur(6px); }
.truth {
  position: absolute; left: 14px; top: 12px; font-size: 12.5px; color: var(--muted); max-width: 60ch;
  background: color-mix(in srgb, var(--bg) 78%, transparent); padding: 4px 8px; border-radius: 4px;
}
.hover-tip {
  position: absolute; pointer-events: none; background: var(--invert-bg); color: var(--invert-text);
  font-family: var(--mono); font-size: 12px; padding: 3px 7px; border-radius: 4px; transform: translate(10px, -130%);
  white-space: nowrap; display: none; z-index: 3;
}
.space-strip { display: flex; gap: 26px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.space-strip .stat b { font-size: 18px; }

.panel { overflow-y: auto; height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.panel-pad { padding: 18px 20px; }
.panel-pad + .panel-pad { border-top: 1px solid var(--line); }
.loc-code { font-family: var(--mono); font-size: 15px; font-weight: 500; letter-spacing: -0.01em; word-break: break-all; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.lines { display: grid; gap: 10px; }
.line { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-s); }
.line .q { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.line .sub { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; }
.line.bad { border-color: var(--s-red); }
.line.warn { border-color: var(--s-amber); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.feed { display: grid; gap: 8px; font-size: 13px; }
.feed div { display: grid; grid-template-columns: 74px 1fr; gap: 10px; }
.alert-item { display: grid; grid-template-columns: 10px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.alert-item:last-child { border-bottom: 0; }
.alert-item .dot { margin-top: 6px; }
.alert-item p { font-size: 13px; }

/* ---------- insights */
.alerts { display: grid; }
.alert { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 4px 14px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.alert:last-child { border-bottom: 0; }
.alert .dot { margin-top: 6px; }
.alert h3 { font-weight: 600; }
.alert .detail { color: var(--muted); grid-column: 2; }
.alert .do { grid-column: 2; margin-top: 4px; }
.alert .do b { font-weight: 500; }
.alert .right { grid-row: 1 / span 3; grid-column: 3; text-align: right; display: grid; gap: 6px; justify-items: end; align-content: start; }
.chat { display: grid; gap: 12px; }
.chat-log { display: grid; gap: 12px; max-height: 420px; overflow-y: auto; }
.msg { padding: 10px 12px; border-radius: var(--radius-s); white-space: pre-wrap; font-size: 13.5px; }
.msg.me { background: var(--raise); justify-self: end; max-width: 90%; }
.msg.bot { border: 1px solid var(--line); }
.msg small { display: block; color: var(--faint); margin-top: 6px; font-size: 11.5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { font: inherit; font-size: 12.5px; color: var(--muted); background: transparent; border: 1px solid var(--line-strong); border-radius: 99px; padding: 3px 10px; cursor: pointer; }
.chips button:hover { color: var(--text); }
.util-row { display: grid; grid-template-columns: 70px 1fr 64px; gap: 12px; align-items: center; padding: 8px 0; font-size: 13px; }

/* ---------- ops */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs button {
  border: 0; background: none; color: var(--muted); font: inherit; padding: 10px 14px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); }
.tab-panel[hidden] { display: none; }
.op { max-width: 640px; display: grid; gap: 16px; }
.suggest { display: grid; gap: 8px; }
.suggest button {
  text-align: left; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line-strong);
  border-radius: var(--radius-s); padding: 10px 12px; cursor: pointer; display: grid; gap: 2px;
}
.suggest button[aria-pressed="true"] { border-color: var(--text); background: var(--raise); }
.suggest small { color: var(--muted); }
.result { padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-s); font-size: 13.5px; }
.result.err { border-color: var(--s-red); }

/* ---------- auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; display: grid; gap: 20px; }
.auth-card .brand { padding: 0; }

/* ---------- scanner */
.scanner { position: fixed; inset: 0; background: rgba(0,0,0,.86); z-index: 70; display: grid; place-items: center; padding: 16px; }
.scanner[hidden] { display: none; }
.scanner-box { width: min(440px, 100%); display: grid; gap: 12px; color: #ededed; }
.scanner video { width: 100%; border-radius: var(--radius-m); background: #000; aspect-ratio: 4 / 3; object-fit: cover; border: 1px solid #3a3a3a; }

/* ---------- labels (print) */
.label-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.label { border: 1px solid var(--line-strong); border-radius: var(--radius-s); padding: 12px; display: grid; grid-template-columns: 84px 1fr; gap: 12px; align-items: center; break-inside: avoid; }
.label .qr { width: 84px; height: 84px; background: #fff; border-radius: 4px; padding: 4px; }
.label .qr svg { width: 100%; height: 100%; display: block; }
.label b { font-family: var(--mono); font-size: 13px; word-break: break-all; font-weight: 600; }
@media print {
  .rail, .mobile-nav, .no-print, .flash { display: none !important; }
  .shell { display: block; } body { background: #fff; color: #000; } .page { padding: 0; }
  .label { border-color: #000; }
}

/* ---------- mobile */
.mobile-nav { display: none; }
.mobile-top { display: none; }
@media (max-width: 1100px) {
  .space { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { display: none; }
  .mobile-top {
    display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; background: var(--bg); z-index: 20;
  }
  .page { padding: 20px 16px 96px; }
  .flash { margin: 12px 16px 0; }
  .split { grid-template-columns: 1fr; }
  .mobile-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--bg); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .mobile-nav a { display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; padding: 4px 0; }
  .mobile-nav a[aria-current="page"] { color: var(--text); }
  .mobile-nav svg { width: 20px; height: 20px; }
  .space { display: block; height: auto; }
  .space-stage { border-right: 0; }
  #scene { height: 58vh; flex: none; }
  .space-top input[type="search"] { width: 100%; order: 5; }
  .space-top .seg { order: 4; overflow-x: auto; max-width: 100%; }
  .panel { height: auto; overflow: visible; border-top: 1px solid var(--line); padding-bottom: 80px; }
  .legend { left: 8px; bottom: 8px; padding: 6px 8px; gap: 4px 10px; }
  .legend .chip { font-size: 11.5px; }
  .cam { right: 8px; top: 8px; bottom: auto; }
  .truth { display: none; }
  .alert { grid-template-columns: 10px minmax(0, 1fr); }
  .alert .right { grid-row: auto; grid-column: 2; justify-items: start; text-align: left; }
  th, td { padding: 9px 10px; }
  .hide-sm { display: none; }
}
.alert[hidden] { display: none; }
.plan { width: 100%; height: auto; display: block; background: var(--panel); border-radius: var(--radius-s); border: 1px solid var(--line); }
.plan .fac { fill: none; stroke: var(--line-strong); stroke-width: 0.08; }
.plan .grid { stroke: var(--line); stroke-width: 0.02; }
.plan .old { fill: var(--raise); stroke: var(--muted); stroke-width: 0.05; }
.plan .new { fill: color-mix(in srgb, var(--text) 18%, transparent); stroke: var(--text); stroke-width: 0.08; }
.plan .new.bad { fill: color-mix(in srgb, var(--s-red) 25%, transparent); stroke: var(--s-red); }
.plan text { fill: var(--muted); font-family: var(--font); }
.plan .dock { fill: var(--text); opacity: .35; }
.field-row { align-items: end; }
.sel-fill { pointer-events: none; }
@media (max-width: 860px) {
  .with-action:has(select) { flex-wrap: wrap; }
  .with-action select { flex: 1 1 100%; }
  .with-action input[data-product-lookup] { max-width: none !important; flex: 1; }
  .tabs button { padding: 10px 10px; }
}
@media (min-width: 861px) { .with-action input[data-product-lookup] { flex: 0 0 160px; } }
