:root {
  --bg: #f4f6f9; --panel: #ffffff; --text: #1b2430; --muted: #6b7686; --line: #e2e7ee; --accent: #1f3a5f; --accent-2: #f2b632;
  --pos: #1a7f37; --neg: #c62828; --warn: #b26a00; --hover: #f0f4f9; --test: #8a63d2;
  --st-working: #1a7f37; --st-lunch: #c98a00; --st-idle: #6b7686; --st-repair: #c62828; --st-sold: #4b5563; --st-written_off: #4b5563;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a; --panel: #18202a; --text: #e6ebf1; --muted: #9aa6b5; --line: #2a3542; --accent: #7fb0ea; --hover: #1f2935;
    --pos: #4cc06a; --neg: #ff6b6b; --warn: #f0b04a; --test: #b39ae8;
    --st-working: #4cc06a; --st-lunch: #f0b04a; --st-idle: #9aa6b5; --st-repair: #ff6b6b; --st-sold: #9aa6b5; --st-written_off: #9aa6b5;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.muted { color: var(--muted); } .small { font-size: 12px; } .pad { padding: 12px 0; } .grow { flex: 1; }
.err { color: var(--neg); } .neg { color: var(--neg); } .pos { color: var(--pos); } .warn { color: var(--warn); } .b { font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px; min-height: 40px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0f141a; } }
.btn.danger { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, var(--line)); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.left { margin-right: auto; }
.icon-btn { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; }

/* Разметка */
.layout { display: grid; grid-template-columns: 210px 1fr; grid-template-rows: auto 1fr; min-height: 100vh; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; color: var(--text); }
.brand img { width: 30px; height: 30px; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 12px 8px; border-right: 1px solid var(--line); background: var(--panel); }
.nav a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 8px; text-decoration: none; color: var(--text); }
.nav a:hover { background: var(--hover); }
.nav a.on { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .nav a.on { color: #0f141a; } }
.nav .ic { width: 22px; text-align: center; }
.main { padding: 20px 24px 80px; min-width: 0; max-width: 1400px; }
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .user { display: none; }
  .nav { flex-direction: row; overflow-x: auto; position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; border-right: 0; border-top: 1px solid var(--line);
         padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); gap: 0; scrollbar-width: none; }
  .nav a { flex-direction: column; gap: 0; font-size: 11px; padding: 6px 8px; min-width: 68px; text-align: center; }
  .nav .ic { font-size: 18px; }
  .main { padding: 14px 16px 96px; }
  .brand span { font-size: 15px; }
}

/* Карточки, вкладки */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
details.card summary { cursor: pointer; list-style: none; }
details.card summary h2 { display: inline; }
details.card summary::before { content: '▸ '; color: var(--muted); }
details.card[open] summary::before { content: '▾ '; }
details.card[open] summary { margin-bottom: 10px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 14px; scrollbar-width: thin; }
.tab { border: 0; background: none; padding: 10px 14px; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; color: var(--muted); }
.tab.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar select { width: auto; max-width: 240px; }
.toolbar input[type=date] { width: auto; }
.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 14px; }
.cols > * { min-width: 0; }
@media (max-width: 980px) { .cols { grid-template-columns: 1fr; } }
.kvs { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px 16px; margin-bottom: 10px; }
.kvs h3 { grid-column: 1 / -1; margin: 6px 0 0; }
.kv { display: flex; flex-direction: column; } .kv .muted { font-size: 12px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* Таблицы */
.tbl-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.tbl { border-collapse: collapse; width: 100%; font-size: 14px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); position: sticky; top: 0; white-space: nowrap; }
.tbl td.num, .tbl th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: var(--hover); }
.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--hover); color: var(--muted); }
.tag.test { color: var(--test); border: 1px solid var(--test); background: transparent; }
.tag.np { background: var(--accent-2); color: #1b2430; font-weight: 600; }

/* Статусы */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; }
.badge.st-working { background: var(--st-working); } .badge.st-lunch { background: var(--st-lunch); } .badge.st-idle { background: var(--st-idle); }
.badge.st-repair { background: var(--st-repair); } .badge.st-sold, .badge.st-written_off { background: var(--st-sold); }
@media (prefers-color-scheme: dark) { .badge { color: #0f141a; } }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; box-shadow: var(--shadow); }
.chip.st-working b { color: var(--st-working); } .chip.st-lunch b { color: var(--st-lunch); } .chip.st-idle b { color: var(--st-idle); } .chip.st-repair b { color: var(--st-repair); }
.grp { margin-top: 18px; }
.eq-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.eq { text-align: left; background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--st-idle); border-radius: var(--radius);
      padding: 10px 12px; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 3px; }
.eq:hover { background: var(--hover); }
.eq.st-working { border-left-color: var(--st-working); } .eq.st-lunch { border-left-color: var(--st-lunch); } .eq.st-repair { border-left-color: var(--st-repair); }
.eq-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 16px; }
.eq-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.notif ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.notif li { padding: 6px 10px; border-radius: 6px; border-left: 4px solid var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.notif li.lvl-danger { border-left-color: var(--neg); background: color-mix(in srgb, var(--neg) 10%, transparent); }
.count { display: inline-block; background: var(--neg); color: #fff; border-radius: 999px; font-size: 12px; padding: 0 8px; vertical-align: middle; }
.st-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
@media (max-width: 480px) { .st-btns { grid-template-columns: repeat(2, 1fr); } }
.st-btn { padding: 14px 6px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 600; }
.st-btn.on { color: #fff; } .st-btn.st-working.on { background: var(--st-working); border-color: var(--st-working); }
.st-btn.st-lunch.on { background: var(--st-lunch); border-color: var(--st-lunch); } .st-btn.st-idle.on { background: var(--st-idle); border-color: var(--st-idle); }
.st-btn.st-repair.on { background: var(--st-repair); border-color: var(--st-repair); }

/* Формы и модальные окна */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
@media (max-width: 560px) { .form { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 4px; } .field.wide { grid-column: 1 / -1; }
.field[hidden] { display: none; }
.field .lab { font-size: 12px; color: var(--muted); }
.field.check { flex-direction: row; align-items: center; gap: 8px; min-height: 40px; }
.units { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.unit { display: grid; grid-template-columns: 1fr 100px; gap: 6px; align-items: center; }
.unit label { display: flex; align-items: center; gap: 6px; } .unit input[type=text] { min-height: 32px; padding: 4px 8px; }
.modal-wrap { position: fixed; inset: 0; background: rgba(10,15,25,.45); display: flex; align-items: flex-start; justify-content: center; z-index: 20; padding: 5vh 12px; overflow: auto; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 680px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; color: var(--text); text-transform: none; letter-spacing: 0; }
.modal-body { padding: 16px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 30; max-width: 90vw; }
.toast.err { background: var(--neg); color: #fff; }

/* Вход */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { background: var(--panel); padding: 28px; border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login .field { text-align: left; } .login .logo { width: 64px; height: 64px; margin: 0 auto; } .login h1 { font-size: 20px; margin: 0 0 6px; }
