:root {
  --bg: #0d0f12;
  --panel: #15181d;
  --panel-2: #1b1f25;
  --line: #262b33;
  --text: #e9ebef;
  --muted: #8d95a3;
  --faint: #5d6573;
  --accent: #ff7a1a;
  --accent-2: #ff9a4d;
  --accent-soft: rgba(255, 122, 26, .14);
  --good: #3ecf8e;
  --warn: #f5b942;
  --bad: #ff5d5d;
  --info: #5aa9ff;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- раскладка */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; background: #0f1215; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: -.02em; padding: 4px 10px 18px; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; background: var(--panel-2); display: grid; place-items: center; }
.brand .logo svg { width: 18px; height: 18px; }
.brand small { color: var(--accent); font-weight: 700; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; color: var(--muted); font-weight: 600; transition: background .15s, color .15s; }
.nav-link svg { width: 20px; height: 20px; flex: none; }
.nav-link:hover { background: var(--panel); color: var(--text); }
.nav-link.on { background: var(--accent-soft); color: var(--accent); }
.side .spacer { flex: 1; }
.side .who { color: var(--faint); font-size: 13px; padding: 8px 12px; }

.main { min-width: 0; padding: 26px 32px 60px; max-width: 1280px; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.top h1 { margin: 0; font-size: 26px; letter-spacing: -.03em; font-weight: 800; flex: 1; min-width: 0; }
.top h1 .sub { color: var(--muted); font-weight: 600; font-size: 15px; margin-left: 8px; letter-spacing: 0; }
.back { color: var(--muted); font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.back:hover { color: var(--text); }
.back svg { width: 16px; height: 16px; }

.bottom-nav { display: none; }

/* ---------- кнопки */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); font-weight: 650; cursor: pointer; white-space: nowrap; transition: border-color .15s, background .15s, transform .05s; }
.btn:hover { border-color: #3a414c; }
.btn:active { transform: scale(.98); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a0d02; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.icon { width: 40px; padding: 0; }
.btn.sm.icon { width: 32px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- панели */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 750; display: flex; align-items: center; gap: 8px; }
.card h3 .grow { flex: 1; }
.card h3 .count { color: var(--muted); font-weight: 600; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h3 { padding: 16px 18px 0; }

.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; display: block; }
a.kpi:hover { border-color: #3a414c; }
.kpi .lbl { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi .val { font-size: 26px; font-weight: 800; letter-spacing: -.03em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .hint { color: var(--faint); font-size: 12.5px; margin-top: 2px; }
.kpi.accent .val { color: var(--accent); }
.neg { color: var(--bad) !important; }
.pos { color: var(--good); }

/* ---------- списки */
.list { display: flex; flex-direction: column; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; align-items: center; padding: 12px 18px; border-top: 1px solid var(--line); cursor: pointer; transition: background .12s; }
.row:first-child { border-top: 0; }
.row:hover { background: var(--panel-2); }
.row .t { font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { color: var(--muted); font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r { text-align: right; font-weight: 700; white-space: nowrap; }
.row .rs { text-align: right; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.empty { color: var(--faint); padding: 22px 18px; text-align: center; font-size: 14px; }
.card .list .row { margin: 0 -18px; }
.card.flush .list .row { margin: 0; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12.5px; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--panel-2); }
.tbl .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl .muted, .muted { color: var(--muted); }
.tbl-wrap { overflow-x: auto; }

/* ---------- метки */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.plain::before { display: none; }
.st-new { color: #5aa9ff; background: rgba(90,169,255,.1); border-color: rgba(90,169,255,.25); }
.st-agreed { color: #a98bff; background: rgba(169,139,255,.1); border-color: rgba(169,139,255,.25); }
.st-waiting { color: #f5b942; background: rgba(245,185,66,.1); border-color: rgba(245,185,66,.25); }
.st-building { color: #ff7a1a; background: rgba(255,122,26,.12); border-color: rgba(255,122,26,.3); }
.st-testing { color: #ff9ad5; background: rgba(255,154,213,.1); border-color: rgba(255,154,213,.25); }
.st-ready { color: #3ecf8e; background: rgba(62,207,142,.12); border-color: rgba(62,207,142,.3); }
.st-done { color: #8d95a3; }
.st-cancelled { color: #5d6573; text-decoration: line-through; }
.tag { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); vertical-align: 1px; }
.tag.used { color: var(--warn); border-color: rgba(245,185,66,.3); }
.tag.ok { color: var(--good); border-color: rgba(62,207,142,.3); }
.tag.bad { color: var(--bad); border-color: rgba(255,93,93,.3); }

/* ---------- фильтры */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 420px; }
.search input { width: 100%; height: 40px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); padding: 0 16px 0 40px; outline: none; }
.search input:focus { border-color: var(--accent); }
.search svg { position: absolute; left: 14px; top: 11px; width: 18px; height: 18px; color: var(--faint); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-weight: 650; font-size: 13.5px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: rgba(255,122,26,.35); }
.chip .n { opacity: .7; margin-left: 4px; }
select.inline, input.inline { height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); padding: 0 10px; outline: none; }

/* ---------- детали заказа */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.kv dd.big { font-size: 18px; font-weight: 800; }
.kv .sep { grid-column: 1 / -1; border-top: 1px solid var(--line); margin: 2px 0; }
.status-line { display: flex; gap: 6px; flex-wrap: wrap; }
.status-btn { height: 32px; padding: 0 12px; border-radius: 999px; font-size: 13px; font-weight: 650; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); cursor: pointer; }
.status-btn.on { color: #1a0d02; background: var(--accent); border-color: var(--accent); }
.notes { white-space: pre-wrap; color: var(--text); font-size: 14px; }
.item-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.item-row:first-child { border-top: 0; }
.item-row .nm { font-weight: 600; min-width: 0; }
.item-row .meta { color: var(--muted); font-size: 12.5px; }
.item-row .cost { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.progress { height: 8px; border-radius: 99px; background: var(--panel-2); overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; background: var(--good); border-radius: 99px; }

/* ---------- график */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .bar { fill: var(--accent); cursor: pointer; }
.chart .bar.neg { fill: #6b7280; }
.chart .bar.sel { fill: var(--accent-2); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar { opacity: .8; }
.chart .grid-l { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: #3a414c; stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart text.sel { fill: var(--text); font-weight: 700; }
.tip { position: absolute; pointer-events: none; background: #23272e; border: 1px solid #333a44; border-radius: 10px; padding: 8px 10px; font-size: 12.5px; white-space: nowrap; box-shadow: 0 8px 24px rgba(0,0,0,.4); transform: translate(-50%, -100%); display: none; z-index: 2; }
.tip b { display: block; margin-bottom: 2px; }
.bars-h .bh { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 7px 0; font-size: 14px; }
.bars-h .bh .track { grid-column: 1 / -1; height: 6px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.bars-h .bh .track i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bars-h .bh .v { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- модальные окна */
.overlay { position: fixed; inset: 0; background: rgba(5,6,8,.66); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 50; padding: 20px; animation: fade .15s; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 40px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 22px; animation: pop .18s; }
.modal.wide { max-width: 720px; }
.modal h2 { margin: 0 0 16px; font-size: 20px; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; }
.modal h2 span { flex: 1; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 12px; }
.field { display: flex; flex-direction: column; gap: 6px; grid-column: span 2; min-width: 0; }
.field.half { grid-column: span 1; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea { width: 100%; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 10px 12px; outline: none; font-size: 16px; }
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field .help { color: var(--faint); font-size: 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.form-actions { grid-column: span 2; display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }
.form-actions .left { margin-right: auto; }
.form-err { grid-column: span 2; color: var(--bad); font-size: 14px; min-height: 0; }
.pick-list { max-height: 50vh; overflow: auto; margin: 10px -22px 0; border-top: 1px solid var(--line); }
.pick-list .row { padding: 12px 22px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80; pointer-events: none; }
#toast .t { background: #23272e; border: 1px solid #333a44; padding: 10px 16px; border-radius: 12px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.45); animation: pop .18s; }
#toast .t.err { border-color: rgba(255,93,93,.5); color: #ffb4b4; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.login .brand { padding: 0 0 8px; justify-content: center; font-size: 22px; }
.login input { height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 0 14px; outline: none; font-size: 16px; }
.login input:focus { border-color: var(--accent); }
.login .btn { height: 48px; }
.login .err { color: var(--bad); font-size: 14px; min-height: 20px; text-align: center; }

/* ---------- адаптив */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: calc(14px + env(safe-area-inset-top)) 14px calc(var(--nav-h) + 30px + env(safe-area-inset-bottom)); }
  .top h1 { font-size: 22px; }
  .top h1 .sub { display: block; margin: 2px 0 0; }
  .top .btn .lbl { display: none; }
  .top .btn.primary .lbl { display: inline; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .span2 { grid-column: auto; }
  .card { padding: 16px; border-radius: 14px; }
  .kpi { padding: 13px 14px; border-radius: 14px; }
  .kpi .val { font-size: 21px; }
  .card .list .row { margin: 0 -16px; padding: 12px 16px; }
  .search { max-width: none; min-width: 0; flex-basis: 100%; }
  .bottom-nav { display: grid; grid-template-columns: repeat(6, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: rgba(13,15,18,.94); backdrop-filter: blur(12px); border-top: 1px solid var(--line); }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; font-weight: 650; color: var(--faint); }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a.on { color: var(--accent); }
  .overlay { place-items: end center; padding: 0; }
  .modal { max-width: none; border-radius: 22px 22px 0 0; max-height: 92vh; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .22s; }
  .form { grid-template-columns: 1fr; }
  .field, .field.half, .form-actions, .form-err { grid-column: span 1; }
  .form-actions .btn { flex: 1; }
  .form-actions .left { flex: 0 0 auto; }
  .pick-list { margin: 10px -16px 0; }
  .pick-list .row { padding: 12px 16px; }
  .hide-m { display: none !important; }
  #toast { bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); }
}
@media (min-width: 821px) { .show-m { display: none !important; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

/* ---------- слоты комплектующих */
.slots { display: flex; flex-direction: column; }
.slot { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); align-items: start; }
.slot:first-child { border-top: 0; }
.slot-cat { color: var(--faint); font-weight: 650; font-size: 13.5px; padding-top: 9px; }
.slot.filled .slot-cat { color: var(--text); }
.slot-item { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 3px 0 8px; }
.slot-item .nm { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.slot-item .meta { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.slot-item .cost { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.slot-body { min-width: 0; }
.slot-add { display: flex; gap: 8px; align-items: center; min-width: 0; }
.slot-add select { flex: 1 1 0; width: 100%; min-width: 0; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 0 10px; font-size: 14px; outline: none; }
.slot-add select:focus { border-color: var(--accent); }
.slot-none { font-size: 13px; flex: 1; padding: 9px 0; color: var(--faint); }
.build-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); border: 1px solid rgba(255,122,26,.3); margin-bottom: 10px; font-size: 14px; }
.build-banner svg { width: 18px; height: 18px; color: var(--accent); }
.build-banner a { color: var(--accent); font-weight: 700; }
.build-banner .grow { flex: 1; min-width: 0; }
@media (max-width: 820px) {
  .slot { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .slot-cat { padding-top: 0; }
  .slot-add select { font-size: 16px; height: 42px; }
}
.chips.wrap { flex-wrap: wrap; overflow: visible; }

/* ---------- выбор со склада и обращения */
.stock-btn { flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-radius: 10px; border: 1px dashed #3a414c; background: var(--bg); color: var(--muted); font-weight: 600; font-size: 14px; cursor: pointer; text-align: left; }
.stock-btn:hover { border-color: var(--accent); color: var(--text); }
.stock-btn svg { width: 16px; height: 16px; flex: none; }
.stock-btn span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stock-btn b { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 8px; font-size: 12.5px; }
.slot-acts { display: inline-flex; gap: 2px; }
.modal .search { margin-bottom: 2px; }
.cs-open { color: #5aa9ff; background: rgba(90,169,255,.1); border-color: rgba(90,169,255,.25); }
.cs-repair { color: #ff7a1a; background: rgba(255,122,26,.12); border-color: rgba(255,122,26,.3); }
.cs-done { color: #3ecf8e; background: rgba(62,207,142,.12); border-color: rgba(62,207,142,.3); }
.cs-rejected { color: #8d95a3; }
@media (max-width: 820px) { .stock-btn { height: 42px; font-size: 15px; } }
