/* Инвентарь — tokens, layout, components. No hex colours outside the token blocks.
   Dark is the base; light via [data-theme="light"] (theme.js) or the system preference when no attribute is set. */
:root {
  color-scheme: dark;
  --bg: #16181d; --surface: #1e2127; --surface-2: #262a31; --border: #343941; --border-strong: #4a515b;
  --text: #e6e8eb; --muted: #9aa1ab; --faint: #6c737d;
  --accent: #6ea8fe; --accent-ink: #0b1220; --accent-soft: #6ea8fe26;
  --ok: #4cc38a; --ok-soft: #4cc38a22; --warn: #f0b429; --warn-soft: #f0b42922; --err: #f26d6d; --err-soft: #f26d6d22;
  --info: #5aa9e6; --info-soft: #5aa9e622; --violet: #b18cff; --violet-soft: #b18cff22; --teal: #3cc7c1; --teal-soft: #3cc7c122;
  --orange: #f59e57; --orange-soft: #f59e5722; --graphite: #8b95a1; --graphite-soft: #8b95a122;
  --focus: #8ab4ff; --shadow: 0 8px 28px #0008; --scrim: #000a;
  --radius: 8px; --row: 30px; --rail: 188px; --tabbar: 58px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #eef0f3; --border: #d5d9df; --border-strong: #b7bec8;
  --text: #1b1e23; --muted: #5d6571; --faint: #8a919b;
  --accent: #2563c9; --accent-ink: #ffffff; --accent-soft: #2563c91a;
  --ok: #1f8a57; --ok-soft: #1f8a571a; --warn: #9a6200; --warn-soft: #d9960021; --err: #c83737; --err-soft: #c837371a;
  --info: #1f6fb5; --info-soft: #1f6fb51a; --violet: #7a4fd6; --violet-soft: #7a4fd61a; --teal: #0f8f89; --teal-soft: #0f8f891a;
  --orange: #c05f0e; --orange-soft: #c05f0e1a; --graphite: #5b6572; --graphite-soft: #5b65721a;
  --focus: #2563c9; --shadow: 0 8px 28px #0002; --scrim: #0006;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #f5f6f8; --surface: #ffffff; --surface-2: #eef0f3; --border: #d5d9df; --border-strong: #b7bec8;
    --text: #1b1e23; --muted: #5d6571; --faint: #8a919b; --accent: #2563c9; --accent-ink: #ffffff; --accent-soft: #2563c91a;
    --ok: #1f8a57; --warn: #9a6200; --err: #c83737; --info: #1f6fb5; --violet: #7a4fd6; --teal: #0f8f89; --orange: #c05f0e;
    --graphite: #5b6572; --focus: #2563c9; --shadow: 0 8px 28px #0002; --scrim: #0006;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 14px/1.45 var(--font); font-variant-numeric: tabular-nums;
  display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); grid-template-rows: auto auto 1fr;
  grid-template-areas: "top top" "nav banner" "nav main";
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 12px; line-height: 1.25; }
h2 { font-size: 15px; margin: 0; }
h3.sub { font-size: 13px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
h4, h5 { margin: 12px 0 4px; }
p { margin: 6px 0; }
code, kbd, output.secret { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; overflow-wrap: anywhere; }
kbd { border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface-2); }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -40px; z-index: 50; background: var(--accent); color: var(--accent-ink); padding: 6px 10px; border-radius: var(--radius); }
.skip:focus { top: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.struck { text-decoration: line-through; color: var(--muted); }
.noscript { padding: 16px; }

/* ---- shell ---- */
.top {
  grid-area: top; position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: calc(8px + var(--safe-t)) calc(16px + var(--safe-r)) 8px calc(16px + var(--safe-l));
  background: var(--surface); border-bottom: 1px solid var(--border); min-height: 52px;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 600; flex: 0 0 auto; }
.brand img { display: block; border-radius: 6px; }
.search { position: relative; flex: 1 1 auto; max-width: 640px; margin: 0; }
.search input { width: 100%; height: 36px; padding: 0 34px 0 12px; }
.search-kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.top-settings { margin-left: auto; }
.nav {
  grid-area: nav; position: sticky; top: 52px; align-self: start; display: flex; flex-direction: column; gap: 2px;
  padding: 12px 8px calc(12px + var(--safe-b)) calc(8px + var(--safe-l)); height: calc(100dvh - 52px); overflow-y: auto;
  border-right: 1px solid var(--border); background: var(--surface);
}
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius); color: var(--text); min-height: 36px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-i { width: 20px; text-align: center; font-size: 16px; line-height: 1; }
.badge { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; text-align: center; font-weight: 600; }
.banner { grid-area: banner; padding: 8px 16px; background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--warn); font-weight: 600; }
main { grid-area: main; min-width: 0; padding: 16px calc(20px + var(--safe-r)) 48px 20px; outline: none; }
.view { max-width: 1280px; }
.loading { min-height: 120px; padding: 24px 0; color: var(--muted); }

/* ---- controls ---- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="search"], input[type="date"], input:not([type]), select, textarea {
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 6px; padding: 5px 8px; min-height: 32px; max-width: 100%;
}
textarea { width: 100%; resize: vertical; }
input:disabled, select:disabled { opacity: .55; }
input::placeholder, textarea::placeholder { color: var(--faint); }
.num-input { width: 8em; text-align: right; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 5px 14px;
  border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  cursor: pointer; white-space: nowrap; text-decoration: none; font-weight: 500;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { border-color: var(--err); color: var(--err); background: var(--err-soft); }
.btn-sm { min-height: 28px; padding: 2px 10px; font-size: 13px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; min-height: 32px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.actions, .btns, .quick, .row-gap { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.actions { margin-top: 10px; }
.quick { margin-bottom: 12px; }
.row-end { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 12px; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field > label, .field > .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.hint { color: var(--muted); font-size: 12px; }
.form { display: flex; flex-direction: column; gap: 10px; }
.inline { display: flex; gap: 6px; align-items: center; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.seg-opt { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; cursor: pointer; border-right: 1px solid var(--border); }
.seg-opt:last-child { border-right: 0; }
.seg-opt:has(input:checked) { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg-opt input { margin: 0; accent-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 4px; margin-right: 14px; min-height: 30px; }
.checks { border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px 8px; margin: 0; }
.checks legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }

/* ---- cards, lists, key/value ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 12px; }
.card-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; }
.card-err { border-color: var(--err); background: var(--err-soft); }
.card-accent { border-color: var(--accent); }
.err-title { color: var(--err); font-weight: 600; }
.head h1 { margin-bottom: 4px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.crumbs { color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 8px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.row-link { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: baseline; padding: 7px 6px; color: var(--text); border-radius: 6px; }
.row-link:hover, .row-link:focus-visible { background: var(--surface-2); text-decoration: none; }
.row-t { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.row-n { text-align: right; white-space: nowrap; }
.row-s { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.row-w { grid-column: 1 / -1; color: var(--warn); font-size: 12.5px; font-weight: 600; }
.empty { color: var(--muted); padding: 6px 0; }
.warn { color: var(--warn); }
.err { color: var(--err); }
.ok { color: var(--ok); }
.note { color: var(--info); }
.err-details { margin: 4px 0; padding-left: 18px; color: var(--muted); }
.plan { margin-top: 4px; }
.plan-lines { margin: 4px 0; padding-left: 18px; }
.plan-lines li { margin: 2px 0; }
.mono-row { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
output.secret { display: inline-block; padding: 6px 8px; background: var(--surface-2); border: 1px dashed var(--accent); border-radius: 6px; overflow-wrap: anywhere; user-select: all; }
output.secret.big { font-size: 22px; letter-spacing: .12em; }

/* ---- dense tables (desktop) → cards (phone) ---- */
.table-wrap { overflow-x: auto; margin: 4px 0; }
.grid { width: 100%; border-collapse: collapse; }
.grid th { position: sticky; top: 0; background: var(--surface); text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 4px 8px; border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
.grid td { padding: 3px 8px; height: var(--row); border-bottom: 1px solid var(--border); vertical-align: middle; }
.grid tbody tr:hover { background: var(--surface-2); }
.grid .num { text-align: right; white-space: nowrap; }
.grid tr.reversed td, .grid tr.closed td { color: var(--muted); }
.grid tr.reversed td:not(:last-child) { text-decoration: line-through; }
.grid tr.reversal td { font-style: italic; }
.moves { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }

/* ---- chips: statuses, costs, allocations (colour + text, never colour alone) ---- */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 18px; border: 1px solid transparent; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
a.chip:hover { text-decoration: none; border-color: currentColor; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-muted { color: var(--muted); }
.st-planned { border: 1px dashed var(--graphite); color: var(--graphite); background: transparent; }
.st-in_transit { background: var(--info-soft); color: var(--info); }
.st-in_stock { background: var(--graphite-soft); color: var(--text); }
.st-reserve { background: var(--teal-soft); color: var(--teal); }
.st-in_service { background: var(--ok-soft); color: var(--ok); }
.st-on_bench { background: var(--violet-soft); color: var(--violet); }
.st-repair { background: var(--warn-soft); color: var(--warn); }
.st-defective { background: var(--err-soft); color: var(--err); }
.st-scrapped { background: var(--graphite-soft); color: var(--faint); text-decoration: line-through; }
.st-dismantled, .st-transferred { background: var(--graphite-soft); color: var(--graphite); }
.st-lost { background: var(--err-soft); color: var(--err); border: 1px dashed var(--err); }
.st-voided { color: var(--faint); text-decoration: line-through; }
.zone-person { background: var(--orange-soft); color: var(--orange); }
.zone-site { background: var(--teal-soft); color: var(--teal); }
.zone-repair { background: var(--warn-soft); color: var(--warn); }
.zone-virtual { color: var(--faint); }
.cost-ok { color: var(--text); background: transparent; }
.cost-est { font-style: italic; color: var(--info); background: transparent; }
.cost-warn { color: var(--warn); background: var(--warn-soft); }
.cost-unknown { color: var(--warn); background: var(--warn-soft); border: 1px dashed var(--warn); }
.al-proposed { border: 1px dashed var(--accent); color: var(--accent); background: transparent; }
.al-allocated { background: var(--accent); color: var(--accent-ink); }
.al-locked { background: var(--violet-soft); color: var(--violet); border: 1px solid var(--violet); }
.al-reserve { border: 1px solid var(--teal); color: var(--teal); background: transparent; }
.lvl-plenty { color: var(--ok); }
.lvl-low { color: var(--warn); }
.lvl-out { color: var(--err); }
.sev-error .row-t, tr.sev-error td { color: var(--err); }
.sev-warning .row-t, tr.sev-warning td { color: var(--warn); }

/* ---- drawer, modal, toasts ---- */
dialog { color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); padding: 0; box-shadow: var(--shadow); }
dialog::backdrop { background: var(--scrim); }
.sheet { margin: 0 0 0 auto; width: min(440px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border-width: 0 0 0 1px; }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(10px + var(--safe-t)) 14px 10px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 1; }
.sheet-title { font-size: 16px; }
.sheet-body { padding: 12px 14px calc(16px + var(--safe-b)); }
.modal { width: min(520px, calc(100vw - 24px)); border-radius: 12px; }
.modal-form { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.modal-title { font-size: 16px; }
.toasts { position: fixed; right: calc(16px + var(--safe-r)); bottom: calc(16px + var(--safe-b)); z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(460px, calc(100vw - 32px)); }
.toast { display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border-strong); box-shadow: var(--shadow); }
.toast span { flex: 1 1 auto; overflow-wrap: anywhere; }
.toast-ok { border-left: 4px solid var(--ok); }
.toast-err { border-left: 4px solid var(--err); }
.toast-info { border-left: 4px solid var(--accent); }
.toast-x { border: 0; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; min-width: 28px; min-height: 28px; }

/* iOS zooms into inputs below 16px: any touch device, whatever its width (large phones in landscape, tablets) */
@media (pointer: coarse), (hover: none) {
  input, select, textarea, .search input { font-size: 16px; }
}

/* ---- phone ---- */
@media (max-width: 640px) {
  body { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "banner" "main"; font-size: 15px; }
  input, select, textarea, .search input { font-size: 16px; } /* iOS zooms into inputs below 16px */
  .brand-t, .search-kbd { display: none; }
  .top { gap: 8px; padding-left: calc(10px + var(--safe-l)); padding-right: calc(6px + var(--safe-r)); }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; height: auto; z-index: 30; flex-direction: row; justify-content: space-around;
    padding: 4px calc(4px + var(--safe-r)) calc(4px + var(--safe-b)) calc(4px + var(--safe-l)); border-right: 0; border-top: 1px solid var(--border);
    overflow: visible;
  }
  .nav a { flex: 1 1 0; flex-direction: column; gap: 2px; padding: 4px 2px; min-height: 48px; font-size: 11px; justify-content: center; position: relative; }
  .nav a[data-nav="tokens"] { display: none; }
  .nav .badge { position: absolute; top: 2px; right: 50%; margin-right: -22px; min-width: 16px; font-size: 10.5px; }
  main { padding: 12px calc(12px + var(--safe-r)) calc(var(--tabbar) + 24px + var(--safe-b)) calc(12px + var(--safe-l)); }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .icon-btn { min-width: 44px; min-height: 44px; }
  .row-link { padding: 10px 6px; }
  .kv { gap: 4px 12px; }
  .grid thead { display: none; }
  .grid, .grid tbody, .grid tr, .grid td { display: block; width: 100%; }
  .grid tr { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; padding: 6px 10px; background: var(--surface); }
  .grid td { height: auto; border: 0; padding: 3px 0; display: flex; gap: 10px; justify-content: space-between; align-items: center; text-align: right; }
  .grid td::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; text-align: left; flex: 0 0 auto; }
  .grid td[data-label=""]::before { content: none; }
  .grid td.num { text-align: right; }
  .sheet { inset: auto 0 0 0; margin: 0; width: 100vw; height: auto; max-height: 92dvh; border-radius: 14px 14px 0 0; border-width: 1px 0 0; }
  .sheet-head { padding-top: 10px; }
  .toasts { left: 12px; right: 12px; bottom: calc(var(--tabbar) + 12px + var(--safe-b)); max-width: none; }
  .num-input { width: 100%; }
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in .16s ease-out; }
  @keyframes toast-in { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
}
@media print {
  .top, .nav, .toasts, .actions, .banner { display: none !important; }
  body { display: block; background: white; color: black; }
}
