/* АвтоТочка — склад. Светлая тема по умолчанию, тёмная — по настройке системы. */
:root {
  --bg: #f1f3f5;
  --panel: #ffffff;
  --text: #1c2024;
  --muted: #64707d;
  --line: #dde1e6;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --ok: #1a7f37;      --ok-bg: #e6f4ea;
  --warn: #8a5a00;    --warn-bg: #fff4d6;
  --bad: #c62828;     --bad-bg: #fdecec;
  --gray: #6b7280;    --gray-bg: #eceef1;
  --radius: 8px;
  --side: 210px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c; --panel: #1e2227; --text: #e6e8eb; --muted: #9aa4ae; --line: #343a41;
    --accent: #4c8dff; --ok: #5fcf7a; --ok-bg: #18301f; --warn: #f0c050; --warn-bg: #3a2f12;
    --bad: #ff7b7b; --bad-bg: #3d1d1d; --gray: #a0a8b2; --gray-bg: #2a2f35;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 17px; margin: 22px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.art { font-weight: 600; user-select: all; }
.nowrap { white-space: nowrap; }

/* ---------- Каркас ---------- */
.layout { display: flex; min-height: 100vh; }
.side {
  width: var(--side); flex: none; background: var(--panel); border-right: 1px solid var(--line);
  padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { font-weight: 700; font-size: 17px; padding: 4px 10px 14px; }
.brand span { color: var(--muted); font-weight: 400; font-size: 13px; display: block; }
.side nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 6px;
  color: var(--text); text-decoration: none;
}
.side nav a:hover { background: var(--bg); }
.side nav a.active { background: var(--accent); color: var(--accent-text); }
.side .group { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  padding: 14px 10px 4px; }
.main { flex: 1; min-width: 0; }
.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.top .spacer { flex: 1; }
.exchange { font-size: 13px; color: var(--muted); }
.exchange .bad { color: var(--bad); font-weight: 600; }
.userbox { font-size: 13px; display: flex; gap: 8px; align-items: center; }
.userbox form { margin: 0; }
.content { padding: 18px 20px 40px; max-width: 1280px; }

.mode { padding: 7px 20px; font-size: 13px; font-weight: 600; }
.mode.shadow { background: var(--gray-bg); color: var(--muted); }
.mode.live { background: var(--bad-bg); color: var(--bad); }

.bottom-nav { display: none; }

/* ---------- Элементы ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel + .panel { margin-top: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.big { min-height: 52px; font-size: 18px; padding: 0 22px; }
.btn.wide { width: 100%; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; min-height: 38px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { min-width: 220px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); font-size: 13px; text-decoration: none;
}
.chip:hover { text-decoration: none; border-color: var(--muted); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* Статусы — всегда со значком и текстом */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.yellow, .badge.low { background: var(--warn-bg); color: var(--warn); }
.badge.red, .badge.zero, .badge.minus { background: var(--bad-bg); color: var(--bad); }
.badge.gray { background: var(--gray-bg); color: var(--gray); }
.t-bad { color: var(--bad); font-weight: 600; }
.t-warn { color: var(--warn); font-weight: 600; }
.t-ok { color: var(--ok); }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }

/* Таблицы */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel); position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }
tr.archived td { color: var(--muted); }
.table-foot { font-size: 13px; color: var(--muted); padding: 8px 2px; }

/* Главная */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; color: var(--text); text-decoration: none; border-left: 4px solid var(--line); }
.tile:hover { text-decoration: none; border-color: var(--muted); }
.tile .v { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .t { font-size: 13px; color: var(--muted); }
.tile.red { border-left-color: var(--bad); }
.tile.yellow { border-left-color: var(--warn); }
.tile.ok { border-left-color: var(--ok); }
.attention { list-style: none; margin: 0; padding: 0; }
.attention li { padding: 9px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; }
.attention li:last-child { border-bottom: none; }

/* ---------- Склад (телефон) ---------- */
.sklad { max-width: 640px; }
.search-big { display: flex; gap: 8px; margin-bottom: 14px; }
.search-big input { flex: 1; min-height: 52px; font-size: 19px; }
.results { list-style: none; margin: 0; padding: 0; }
.results a { display: flex; justify-content: space-between; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; color: var(--text); text-decoration: none; min-height: 56px; }
.results .art { font-size: 18px; }
.stock3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stock3 > div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; text-align: center; }
.stock3 .v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stock3 .t { font-size: 13px; color: var(--muted); }
.big-art { font-size: 26px; font-weight: 700; user-select: all; }
.op-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.op-line { display: grid; grid-template-columns: 1fr 110px 44px; gap: 8px; margin-bottom: 8px; }
.op-line input { min-height: 52px; font-size: 18px; width: 100%; }
.op-line .del { min-height: 52px; }
.confirm { background: var(--panel); border: 2px solid var(--accent); border-radius: var(--radius); padding: 16px; margin: 14px 0; }
.confirm .line { font-size: 20px; padding: 6px 0; }
.done { background: var(--ok-bg); color: var(--ok); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.done .line { font-size: 18px; font-weight: 600; }
.done form { margin-top: 10px; }
.menu-list a { display: flex; align-items: center; min-height: 56px; padding: 0 16px; font-size: 18px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; color: var(--text); }

/* Вход */
.login { max-width: 360px; margin: 12vh auto; padding: 0 16px; }
.login .panel { padding: 24px; }
.login input { width: 100%; min-height: 48px; font-size: 17px; }

/* ---------- Телефон ---------- */
@media (max-width: 800px) {
  .side { display: none; }
  .top { padding: 8px 12px; }
  .top .brand-mobile { font-weight: 700; }
  .userbox .name { display: none; }
  .content { padding: 12px 12px 90px; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0;
    background: var(--panel); border-top: 1px solid var(--line); z-index: 10;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 60px; font-size: 13px; color: var(--muted); text-decoration: none; gap: 2px; }
  .bottom-nav a .ic { font-size: 20px; line-height: 1; }
  .bottom-nav a.active { color: var(--accent); font-weight: 600; }
  .btn { min-height: 48px; }
  .btn.small { min-height: 32px; }
  .top { flex-wrap: nowrap; gap: 8px; }
  .exchange { font-size: 12px; }
  .mode { padding: 6px 12px; font-size: 12px; }
  input, select { min-height: 48px; }
  .filters input[type=search] { min-width: 0; flex: 1; }
  .hide-mobile { display: none; }
  h1 { font-size: 20px; }
}
@media (min-width: 801px) {
  .brand-mobile { display: none; }
}

/* Плашки инвентаризации и правки поверх Точки */
.badge.flag-recount { background: var(--warn-bg); color: var(--warn); }
.badge.flag-inv { background: var(--bad-bg); color: var(--bad); }
.badge.flag-care { background: var(--gray-bg); color: var(--text); border: 1px dashed var(--muted); }
.fix-note { font-size: 13px; color: var(--muted); }
.fix-note::before { content: "✎ "; }
.alert.info { background: var(--gray-bg); color: var(--text); }
.bom-narrow td { background: var(--warn-bg); }

/* Светофор (docs/06): цвет всегда вместе с текстом */
.badge.tl-red { background: var(--bad-bg); color: var(--bad); }
.badge.tl-orange { background: #ffe8d1; color: #9a4a00; }
.badge.tl-green { background: var(--ok-bg); color: var(--ok); }
.badge.tl-blue { background: #e1ecff; color: #1d4fa8; }
.badge.tl-gray { background: var(--gray-bg); color: var(--gray); }
@media (prefers-color-scheme: dark) {
  .badge.tl-orange { background: #3d2a14; color: #ffb066; }
  .badge.tl-blue { background: #172a4a; color: #8db8ff; }
}
.t-warn { color: var(--warn); }

/* Правка остатка в строке */
.quick input { width: 70px; min-height: 0; padding: 4px 6px; }
.quick-confirm { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.quick-confirm .btn { min-height: 0; padding: 3px 9px; font-size: 13px; }
.quick-err { color: var(--bad); font-size: 13px; }
tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--ok-bg); } to { background: transparent; } }
.cost input { width: 80px; min-height: 0; padding: 4px 6px; text-align: right; }
td.money, th.money { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.runout td { vertical-align: top; }

/* Кнопки в строке заказа (отмены) */
.inline-form { display: inline-block; margin: 2px 4px 0 0; }
.order-state { min-width: 210px; }
.order-state .badge { white-space: normal; margin: 1px 0; }

/* «Сверка»: расхождение повторилось после пересчёта */
tr.repeat td { background: var(--bad-bg); }
