/* Layout: black section rail on the left, working surface on the right; on tablets the rail slides in from the edge.
   One committed look: black with signal yellow (as on workshop signage), in every OS theme. */
:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1a1a1a;
  --seg-on: #2b2b2b;
  --line: #262626;
  --line-strong: #383838;
  --ink: #f5f5f0;
  --ink-2: #d6d6cf;
  --muted: #9b9b92;
  --primary: #ffc800;
  --primary-hover: #ffd740;
  --primary-soft: #2b2306;
  --on-primary: #0a0a0a;
  --success: #4ade80;
  --success-btn: #16a34a;
  --success-soft: #0f2618;
  --danger: #ff5f5f;
  --danger-soft: #2f1414;
  --warning: #ff8a3d;
  --warning-soft: #2e1a0c;
  --return: #ecece6;
  --return-soft: #262626;
  --nav: #000000;
  --nav-2: #171717;
  --nav-ink: #e6e6e0;
  --nav-muted: #85857c;
  --nav-active: #ffc800;
  --toast-bg: #ffc800;
  --toast-ink: #0a0a0a;
  --backdrop: rgba(0, 0, 0, 0.72);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 14px 40px rgba(0, 0, 0, 0.55);
  --font: "Avenir Next", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, "Cascadia Mono", Consolas, "Roboto Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
}
body.no-scroll { overflow: hidden; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { text-wrap: balance; }
a { color: var(--primary); }
.i { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.mono { font-family: var(--font-mono); letter-spacing: 0.02em; }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.sidebar {
  background: var(--nav);
  color: var(--nav-ink);
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 12px calc(14px + env(safe-area-inset-bottom, 0px));
}
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 8px 14px; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: var(--nav-active); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 22px; height: 22px; stroke: var(--on-primary); stroke-width: 2; fill: none; stroke-linecap: round; }
.brand-name { display: block; font-weight: 800; letter-spacing: 0.16em; font-size: 17px; color: #fff; }
.brand-sub { display: block; font-size: 11.5px; color: var(--nav-muted); }
.nav-label { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--nav-muted); padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%; min-height: 42px; padding: 8px 10px;
  border: 0; background: none; border-radius: 9px; color: var(--nav-ink); font-weight: 600; font-size: 14.5px;
  text-align: left; cursor: pointer; text-decoration: none;
}
.nav-item:hover { background: var(--nav-2); }
.nav-item.active { background: var(--nav-active); color: var(--on-primary); }
.nav-item .i { opacity: 0.85; }
.nav-text { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--nav-muted); }
.nav-item.active .count { color: rgba(0, 0, 0, 0.65); }
.nav-add { color: var(--nav-muted); }
.badge { background: #ef4444; color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sidebar-foot { margin-top: auto; padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--nav-muted); padding: 0 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; flex: none; }
.dot.off { background: #ef4444; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; background: var(--nav-2); }
.me-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-weight: 700; flex: none; }
.me-text { min-width: 0; flex: 1; }
.me-name { display: block; color: #fff; font-weight: 650; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-role { display: block; color: var(--nav-muted); font-size: 12px; }
.me .icon-btn { background: transparent; border-color: #333; color: var(--nav-ink); width: 36px; height: 36px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  display: flex; align-items: center; gap: 16px;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 32px 14px;
}
.titles { min-width: 0; flex: 1; }
h1 { font-size: 26px; line-height: 1.15; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.sub { margin: 3px 0 0; color: var(--muted); font-size: 13.5px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.search {
  display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 11px; width: 320px; color: var(--muted);
}
.search input { border: 0; outline: 0; background: none; flex: 1; min-width: 0; height: 100%; color: var(--ink); font-size: 15px; }
.search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.topbar .menu-btn { display: none; }
.scrim { display: none; }
.view { padding: 6px 32px 56px; display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1px solid transparent; font-weight: 650; font-size: 14.5px; cursor: pointer;
  white-space: nowrap; text-decoration: none; transition: background-color 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success-btn); color: #fff; }
.btn-return { background: var(--return); color: var(--on-primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost-danger { background: transparent; color: var(--danger); border-color: var(--line-strong); }
.btn-ghost-danger:hover { background: var(--danger-soft); }
.btn-lg { height: 54px; font-size: 16px; padding: 0 22px; border-radius: 12px; }
.w-full { width: 100%; }
.icon-btn {
  width: 42px; height: 42px; display: inline-grid; place-items: center; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); cursor: pointer; flex: none;
}
.icon-btn.sm { width: 36px; height: 36px; }
.icon-btn.sm .i { width: 17px; height: 17px; }
.icon-btn.del { color: var(--muted); }
.icon-btn.del:hover { color: var(--danger); border-color: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.link { color: var(--primary); font-weight: 650; font-size: 13.5px; text-decoration: none; background: none; border: 0; cursor: pointer; padding: 0; }

/* ---------- Home ---------- */
.scanbar {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 20px;
  padding: 20px 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
}
.scanbar-art {
  width: 68px; height: 68px; border-radius: 14px; display: grid; place-items: center;
  background: repeating-linear-gradient(90deg, var(--primary) 0 3px, transparent 3px 5px, var(--primary) 5px 6px, transparent 6px 9px, var(--primary) 9px 13px, transparent 13px 15px);
  background-size: 100% 60%; background-position: center; background-repeat: no-repeat;
  border: 1px solid var(--line); background-color: var(--primary-soft);
}
.scanbar h2 { margin: 0; font-size: 19px; }
.scanbar p { margin: 4px 0 0; color: var(--muted); max-width: 62ch; }
.scanbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: -6px; }
.section-head h3 { margin: 0; font-size: 12.5px; letter-spacing: 0.11em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px;
  display: flex; flex-direction: column; gap: 4px; min-width: 0; text-align: left; color: inherit; text-decoration: none;
}
button.tile { cursor: pointer; font: inherit; }
button.tile:hover { border-color: var(--line-strong); }
.tile-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.tile-value { font-size: 26px; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-value .cur { font-size: 14px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.tile-sub { font-size: 12.5px; color: var(--muted); }
.tile.warn .tile-value { color: var(--warning); }
.tile.bad .tile-value { color: var(--danger); }
.tile.good .tile-value { color: var(--success); }
.split { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; }

/* ---------- Panels & lists ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; min-width: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-size: 15.5px; }
.panel-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.panel-note { padding: 18px; color: var(--muted); margin: 0; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row[data-id] { cursor: pointer; }
.row[data-id]:hover { background: var(--surface-2); }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-end { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rows.compact .row { padding: 10px 0; }

/* ---------- Toolbar, segmented ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 2px; max-width: 100%; overflow-x: auto; }
.seg button { border: 0; background: none; height: 36px; padding: 0 12px; border-radius: 8px; font-weight: 650; font-size: 13.5px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--seg-on); color: var(--ink); box-shadow: 0 1px 2px rgba(16, 24, 40, 0.14); }
.seg .n { font-variant-numeric: tabular-nums; opacity: 0.7; margin-left: 4px; }

/* ---------- Table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.tbl th {
  background: var(--surface-2); text-align: left; font-size: 11.5px; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr[data-id] { cursor: pointer; }
.tbl tbody tr[data-id]:hover { background: var(--surface-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr.is-zero td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.tbl tr.is-low td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
.pname { font-weight: 650; }
.pcode { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.loc {
  display: inline-block; font-family: var(--font-mono); font-size: 12px; font-weight: 600; padding: 3px 8px;
  border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface-2); white-space: nowrap;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2);
}
.loc.none { border-style: dashed; color: var(--muted); text-transform: none; letter-spacing: 0; font-family: var(--font); font-weight: 500; }
.qty { font-weight: 750; font-variant-numeric: tabular-nums; }
.qty.low { color: var(--warning); }
.qty.zero { color: var(--danger); }
.pill { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.pill.ok, .pill.in { background: var(--success-soft); color: var(--success); }
.pill.low { background: var(--warning-soft); color: var(--warning); }
.pill.zero { background: var(--danger-soft); color: var(--danger); }
.pill.out { background: var(--primary-soft); color: var(--primary); }
.pill.ret { background: var(--return-soft); color: var(--return); }
.pill.role { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line-strong); }
.pos { color: var(--success); }
.neg { color: var(--danger); }
.cards { display: none; flex-direction: column; gap: 10px; }
.pcard {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; cursor: pointer;
}
.pcard-foot { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); }
.pcard-foot strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.table-note { font-size: 13px; color: var(--muted); }

/* ---------- Empty ---------- */
.empty {
  background: var(--surface); border: 1px dashed var(--line-strong); border-radius: 14px; padding: 44px 20px;
  text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty > .i { width: 40px; height: 40px; color: var(--muted); }
.empty h3 { margin: 0; font-size: 17px; }
.empty p { margin: 0; color: var(--muted); max-width: 48ch; }
.empty .actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.skeleton { height: 92px; border-radius: 14px; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; border: 1px solid var(--line); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-size: 13px; font-weight: 650; color: var(--ink-2); }
.req { color: var(--danger); }
.field input, .field select, .input {
  height: 48px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface);
  padding: 0 12px; font-size: 16px; outline: 0; width: 100%; min-width: 0; color: var(--ink);
}
.field input:focus, .field select:focus, .input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field input[readonly] { background: var(--surface-2); color: var(--ink-2); }
.field.invalid input { border-color: var(--danger); }
.hint { font-size: 12.5px; color: var(--muted); }
.hint:empty { display: none; }
.hint.err { color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-group-title { font-size: 12px; letter-spacing: 0.11em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-bottom: -4px; }
.span-all { grid-column: 1 / -1; }
.input-group { position: relative; }
.input-group input { padding-right: 54px; }
.in-btn {
  position: absolute; right: 5px; top: 5px; height: 38px; width: 42px; border-radius: 8px; border: 0;
  background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; cursor: pointer;
}
.cat-row { display: flex; gap: 10px; }
.cat-row select, .cat-row input { flex: 1; }
.margin-box { justify-content: flex-end; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); gap: 2px; }
.margin-box strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.markup-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip { height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 650; font-size: 13.5px; cursor: pointer; color: var(--ink-2); }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.form-error { color: var(--danger); font-weight: 600; margin: 0; flex: 1; font-size: 14px; }
.form-error:empty { display: none; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14.5px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

/* ---------- Product sheet ---------- */
.sheet-layer { position: fixed; inset: 0; z-index: 40; display: flex; justify-content: flex-end; background: var(--backdrop); }
.sheet {
  width: min(500px, 100%); height: 100%; background: var(--surface); box-shadow: var(--shadow);
  display: flex; flex-direction: column; animation: slide-in 0.2s ease-out;
}
@keyframes slide-in { from { transform: translateX(32px); opacity: 0.4; } }
.sheet-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: calc(18px + env(safe-area-inset-top, 0px)) 22px 16px; border-bottom: 1px solid var(--line); }
.sheet-head > div { min-width: 0; }
.sheet-body { overflow-y: auto; padding: 18px 22px calc(28px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 18px; flex: 1; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--primary); }
.sheet h2 { margin: 4px 0 8px; font-size: 22px; line-height: 1.2; overflow-wrap: anywhere; }
.code-big {
  font-family: var(--font-mono); font-size: 15px; letter-spacing: 0.06em; padding: 5px 10px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 6px; display: inline-flex; align-items: center; gap: 8px; overflow-wrap: anywhere;
}
.code-big .i { width: 18px; height: 18px; color: var(--muted); }
.where {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: center;
  padding: 16px 18px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line);
}
.where-label { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.where-loc { font-family: var(--font-mono); font-size: 22px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; overflow-wrap: anywhere; }
.where-loc.none { font-family: var(--font); font-size: 16px; color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 600; }
.where-qty { text-align: right; }
.where-qty strong { display: block; font-size: 40px; line-height: 1; font-weight: 750; font-variant-numeric: tabular-nums; }
.where-qty strong.low { color: var(--warning); }
.where-qty strong.zero { color: var(--danger); }
.where-qty span { font-size: 13px; color: var(--muted); }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 0; }
.kv > div { background: var(--surface); padding: 11px 14px; min-width: 0; }
.kv > div:last-child:nth-child(odd) { grid-column: 1 / -1; }
.kv dt { font-size: 12px; color: var(--muted); font-weight: 650; }
.kv dd { margin: 2px 0 0; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stock-form { border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 12px; background: var(--surface-2); }
.stock-form .seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; background: var(--surface); }
.stock-form .seg button { height: 42px; font-size: 15px; }
.stock-form .seg button.on.in { color: var(--success); }
.stock-form .seg button.on.out { color: var(--primary); }
.stock-form .seg button.on.ret { color: var(--return); }
.stock-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.stepper { display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; height: 52px; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; background: var(--surface); }
.stepper button { border: 0; background: var(--surface-2); font-size: 24px; line-height: 1; cursor: pointer; color: var(--ink); }
.stepper input { border: 0; text-align: center; font-size: 21px; font-weight: 700; min-width: 0; background: transparent; outline: 0; height: 100%; font-variant-numeric: tabular-nums; color: var(--ink); }
.stock-msg { margin: 0; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.stock-msg.err { color: var(--danger); }
.stock-msg:empty { display: none; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }
.sheet-body > *, .modal-body > * { flex-shrink: 0; }
.history h3 { margin: 0 0 4px; font-size: 15px; }

/* ---------- Modal ---------- */
.modal-layer { position: fixed; inset: 0; z-index: 60; background: var(--backdrop); display: grid; place-items: center; padding: 24px; }
.modal {
  width: min(820px, 100%); max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); background: var(--surface); border-radius: 18px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; animation: pop 0.18s ease-out;
}
@keyframes pop { from { transform: translateY(10px) scale(0.98); opacity: 0.5; } }
.modal.sm { width: min(460px, 100%); }
.modal-inner { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.modal-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 20px 24px 14px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 21px; }
.modal-head p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.modal-body { padding: 18px 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 14px 24px calc(14px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--surface-2); flex-wrap: wrap; }
.center-body { text-align: center; align-items: center; padding-top: 28px; }
.center-body h2 { margin: 0; font-size: 20px; }
.center-body p { margin: 0; color: var(--muted); max-width: 40ch; }
.round-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--warning-soft); color: var(--warning); }
.round-icon .i { width: 28px; height: 28px; }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.settings-grid .wide { grid-column: 1 / -1; }
.connect { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 22px; align-items: start; }
.qr { background: #fff; padding: 12px; border-radius: 12px; border: 1px solid var(--line); width: 200px; max-width: 100%; aspect-ratio: 1; }
.qr svg { width: 100%; height: 100%; display: block; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; color: var(--ink-2); }
.url-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.url-text { font-family: var(--font-mono); font-size: 14px; font-weight: 600; overflow-wrap: anywhere; flex: 1; min-width: 0; user-select: all; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form .input { flex: 1; min-width: 140px; }
.inline-form select.input { flex: 0 0 auto; width: auto; }
.danger-row { display: flex; align-items: center; gap: 14px; justify-content: space-between; flex-wrap: wrap; }
.danger-row p { margin: 0; color: var(--muted); font-size: 13.5px; max-width: 52ch; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: var(--nav);
  background-image: repeating-linear-gradient(-45deg, rgba(255, 200, 0, 0.07) 0 22px, transparent 22px 44px);
}
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 18px; padding: 28px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4); display: flex; flex-direction: column; gap: 16px; }
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand .brand-name { color: var(--ink); }
.login-brand .brand-sub { color: var(--muted); }
.login-card h2 { margin: 6px 0 0; font-size: 22px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 52px; }
.pw-wrap .in-btn { background: transparent; color: var(--muted); }

/* ---------- Scanner (camera UI stays dark in both themes) ---------- */
.scanner { position: fixed; inset: 0; z-index: 80; background: #000; color: #f5f5f0; display: flex; flex-direction: column; }
.scanner-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(14px + env(safe-area-inset-top, 0px)) 18px 12px; }
.scanner-titles strong { display: block; font-size: 18px; }
.scanner-titles span { display: block; font-size: 13px; color: #9b9b92; }
.icon-btn.on-dark { background: #161616; border-color: #333; color: #f5f5f0; }
.scanner-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; display: grid; place-items: center; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: relative; width: min(80vw, 540px); aspect-ratio: 1.7; max-width: 100%; border-radius: 18px; border: 2px solid var(--primary); box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.45); transition: box-shadow 0.15s; }
.laser { position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: var(--primary); box-shadow: 0 0 14px var(--primary); animation: laser 1.8s ease-in-out infinite alternate; }
@keyframes laser { from { top: 22%; } to { top: 78%; } }
.scan-frame.hit { box-shadow: 0 0 0 200vmax rgba(22, 163, 74, 0.35); }
.no-live { position: relative; max-width: 440px; text-align: center; padding: 24px; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.no-live h3 { margin: 0; font-size: 20px; }
.no-live p { margin: 0; color: #b5b5ad; }
.no-live .i.big { width: 48px; height: 48px; color: var(--primary); }
.no-live .url-text { color: #fff; }
.scanner-foot { padding: 14px 18px calc(18px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 12px; background: #0a0a0a; border-top: 1px solid #222; }
.scan-status { text-align: center; font-size: 14.5px; color: #d6d6cf; min-height: 1.4em; margin: 0; }
.scan-status.err { color: #ff8a8a; }
.manual { display: flex; gap: 8px; max-width: 640px; width: 100%; margin: 0 auto; }
.manual input { flex: 1; min-width: 0; height: 50px; border-radius: 11px; border: 1px solid #383838; background: #161616; color: #fff; padding: 0 14px; font-size: 17px; outline: 0; }
.manual input:focus { border-color: var(--primary); }
.manual .btn { height: 50px; }
.btn-on-dark { background: #161616; color: #f5f5f0; border-color: #383838; max-width: 640px; width: 100%; margin: 0 auto; height: 50px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 520px); }
.toast { background: var(--toast-bg); color: var(--toast-ink); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 650; display: flex; gap: 10px; align-items: center; animation: pop 0.2s ease-out; }
.toast.err { background: var(--danger); color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 1240px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1100px) {
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 980px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 284px; z-index: 50; transform: translateX(-100%); transition: transform 0.22s ease; }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: var(--backdrop); z-index: 45; }
  .topbar .menu-btn { display: inline-grid; }
  .topbar { padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px; flex-wrap: wrap; gap: 10px 12px; }
  .top-actions { order: 3; width: 100%; }
  .search { flex: 1; width: auto; }
  .view { padding: 4px 16px 44px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .only-wide { display: none; }
  .cards { display: flex; }
  .scanbar { grid-template-columns: auto minmax(0, 1fr); }
  .scanbar-actions { grid-column: 1 / -1; }
  .scanbar-actions .btn { flex: 1; }
  .tiles.three { grid-template-columns: minmax(0, 1fr); }
  .connect { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 22px; }
}
@media (max-width: 640px) {
  .modal-layer { padding: 0; place-items: end stretch; }
  .modal, .modal.sm { width: 100%; max-height: 100vh; max-height: 100dvh; border-radius: 18px 18px 0 0; }
  .modal-foot .btn { flex: 1; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .stock-row { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: minmax(0, 1fr); }
  .scan-btn span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
