:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #dfe3e8;
  --text: #15181c;
  --muted: #5d6670;
  --accent: #1f5fd1;
  --accent-soft: #e6eefc;
  --accent-ink: #ffffff;
  --ok: #17794a;
  --ok-soft: #e3f4ea;
  --warn: #a35f00;
  --warn-soft: #fdf1dc;
  --danger: #c22c2c;
  --danger-soft: #fbe6e6;
  --violet: #6a3fc1;
  --violet-soft: #efe8fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --nav-w: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1114;
    --surface: #171a1f;
    --surface-2: #1d2127;
    --border: #2b3038;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --accent: #5b8def;
    --accent-soft: #1d2a44;
    --accent-ink: #0b0d10;
    --ok: #4cc38a;
    --ok-soft: #15291f;
    --warn: #f0b04a;
    --warn-soft: #2e2413;
    --danger: #f07070;
    --danger-soft: #331a1a;
    --violet: #a98bf0;
    --violet-soft: #251d37;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* ---------- Каркас ---------- */
.layout { min-height: 100vh; display: grid; grid-template-columns: var(--nav-w) 1fr; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .title { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }
.nav {
  position: sticky; top: 0; height: 100vh; overflow: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 12px 10px 24px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; font-weight: 700; }
.brand img { width: 28px; height: 28px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .count { margin-left: auto; font-size: 12px; background: var(--danger); color: #fff; border-radius: 10px; padding: 0 7px; }
.nav .who { margin-top: 18px; padding: 12px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.main { min-width: 0; }
.content { padding: 18px 20px 80px; max-width: 1180px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { flex: 1 1 auto; }
.scrim { display: none; }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .nav {
    position: fixed; z-index: 40; left: 0; top: 0; bottom: 0; width: 280px;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .25);
  }
  body.nav-open .nav { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .35); }
  .menu-btn { display: inline-flex; }
  .content { padding: 14px 12px 80px; }
}

/* ---------- Кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 34px; padding: 0 10px; font-size: 13px; border-radius: 7px; }
.btn.lg { min-height: 54px; font-size: 16px; padding: 0 20px; }
.btn.block { width: 100%; }
.icon-btn { min-height: 40px; width: 40px; padding: 0; border-radius: 8px; border: 0; background: transparent; color: var(--text); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; position: relative; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.badge { position: absolute; top: 3px; right: 2px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 5px; }

label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-weight: 500; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }

/* поле сканирования */
.scan { display: flex; gap: 8px; }
.scan input { font-size: 20px; min-height: 56px; font-weight: 600; letter-spacing: .5px; }
.scan .btn { min-height: 56px; }

/* сегменты */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  flex: 1 1 auto; min-height: 48px; padding: 6px 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Карточки, списки ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel > .ph { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel > .ph h2 { flex: 1 1 auto; }
.panel > .pb { padding: 14px 16px; }
.panel + .panel { margin-top: 14px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.list > li.overdue { box-shadow: inset 4px 0 0 var(--danger); background: color-mix(in srgb, var(--danger-soft) 55%, transparent); }
.list > li.escalate { box-shadow: inset 4px 0 0 var(--violet); }
.list .t { font-weight: 600; }
.list .s { color: var(--muted); font-size: 13px; }
a.li-link { color: inherit; display: block; }
a.li-link:hover { text-decoration: none; }

.kpis { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); color: inherit; display: block; }
a.kpi:hover { text-decoration: none; border-color: var(--accent); }
.kpi .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 13px; color: var(--muted); }
.kpi.bad .v { color: var(--danger); }
.kpi.good .v { color: var(--ok); }

.banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 12px; }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.banner.bad { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.banner.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.banner.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.chip.st-new { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.st-okz { background: var(--violet-soft); color: var(--violet); border-color: transparent; }
.chip.st-accepting { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.st-discrepancy, .chip.bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip.st-awaiting_doc, .chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.st-in_section { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.good { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

/* таблицы */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); }
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t tr.total td { font-weight: 700; background: var(--surface-2); }
table.t tr.overdue td { background: color-mix(in srgb, var(--danger-soft) 60%, transparent); }
@media (max-width: 700px) {
  table.t.stack-sm thead { display: none; }
  table.t.stack-sm tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--border); }
  table.t.stack-sm td { display: flex; justify-content: space-between; gap: 10px; border: 0; padding: 3px 0; text-align: right; }
  table.t.stack-sm td::before { content: attr(data-l); color: var(--muted); text-align: left; font-size: 13px; }
  table.t.stack-sm td.num { text-align: right; }
}

/* ---------- Позиции (сверка) ---------- */
.items { list-style: none; margin: 0; padding: 0; }
.items li { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--border); }
.items li:first-child { border-top: 0; }
.items li.ok { background: color-mix(in srgb, var(--ok-soft) 70%, transparent); }
.items li.bad { background: color-mix(in srgb, var(--danger-soft) 70%, transparent); }
.items .nm { font-weight: 600; }
.items .meta { font-size: 13px; color: var(--muted); }
.qty { display: flex; align-items: center; gap: 6px; }
.qty .btn { min-width: 44px; padding: 0; font-size: 20px; }
.qty .val { min-width: 74px; text-align: center; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.qty .val small { font-weight: 500; color: var(--muted); font-size: 13px; }

/* шапка карточки */
.ret-head { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.ret-head .no { font-size: 26px; font-weight: 800; letter-spacing: .3px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 18px; margin-top: 12px; }
.facts div > span { display: block; font-size: 12px; color: var(--muted); }
.actions-bar { display: flex; flex-wrap: wrap; gap: 8px; }
@media (max-width: 700px) {
  .actions-bar .btn { flex: 1 1 calc(50% - 8px); }
  .actions-bar .btn.primary { flex-basis: 100%; }
}

/* история */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.timeline li::after { content: ""; position: absolute; left: 9px; top: 18px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .when { font-size: 12px; color: var(--muted); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photos a, .photos .add { aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); display: flex; align-items: center; justify-content: center; }
.photos img { width: 100%; height: 100%; object-fit: cover; }
.photos .add { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13px; text-align: center; padding: 6px; }

/* ---------- Модальные окна, уведомления ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(10, 12, 16, .45); }
dialog .dh { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
dialog .dh h2 { flex: 1 1 auto; }
dialog .db { padding: 16px 18px; overflow: auto; max-height: calc(100vh - 180px); }
dialog .df { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
dialog video { width: 100%; border-radius: 10px; background: #000; }
@media (max-width: 600px) {
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 14px 14px 0 0; }
  dialog .df .btn { flex: 1 1 auto; }
}

#toasts { position: fixed; z-index: 100; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; width: min(460px, calc(100vw - 24px)); pointer-events: none; }
.toast { padding: 12px 16px; border-radius: 10px; background: #1d2127; color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); font-weight: 500; pointer-events: auto; animation: tin .18s ease-out; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

.notif-panel { position: absolute; right: 12px; top: 52px; width: min(420px, calc(100vw - 24px)); max-height: 70vh; overflow: auto; z-index: 50; }
.notif-panel li { align-items: flex-start; }
.notif-panel li.unread { background: var(--accent-soft); }
.notif-panel li.escalate .t::before { content: "⚠ "; color: var(--violet); }

/* вход */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .panel { width: min(400px, 100%); }
.login .brand { justify-content: center; font-size: 20px; padding: 6px 0 4px; }

.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.progress-txt { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* редактор состава */
.item-row { display: grid; gap: 8px; grid-template-columns: 1fr 2fr 84px 120px 44px; align-items: end; }
@media (max-width: 640px) {
  .item-row { grid-template-columns: 1fr 1fr 44px; padding-bottom: 10px; border-bottom: 1px dashed var(--border); }
  .item-row > :nth-child(2) { grid-column: 1 / -1; grid-row: 1; }
  .item-row > :nth-child(5) { grid-column: 3; grid-row: 2 / 4; align-self: center; }
}

/* ИИ */
.chip.ai { background: var(--violet-soft); color: var(--violet); border-color: transparent; }
.ai-box { margin-top: 8px; padding: 10px 12px; border-radius: 9px; background: var(--violet-soft); border: 1px solid color-mix(in srgb, var(--violet) 25%, transparent); display: grid; gap: 4px; }
.ai-panel > .ph h2 { display: flex; align-items: center; gap: 8px; }
.ai-text { white-space: pre-wrap; }
.ai-wait { display: flex; align-items: center; gap: 10px; padding: 18px 0; color: var(--muted); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--violet); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.doc-text { min-height: 55vh; font: 14px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.ai-doc-list { display: grid; gap: 8px; }
.ai-doc-list .btn { justify-content: flex-start; }
.model-list { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.model-opt { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.model-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.model-opt input { margin-top: 2px; flex: none; }
.feature-card { padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; }
.feature-card:has(> .check input:checked) { border-color: color-mix(in srgb, var(--violet) 45%, var(--border)); }
.check.big { font-weight: 700; font-size: 16px; min-height: 36px; }

/* руководство */
.ui { display: inline-block; padding: 0 7px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; font-size: .92em; white-space: nowrap; }
.guide-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.guide-bar input { flex: 1 1 260px; width: auto; }
.guide-bar .seg { flex: 0 1 auto; }
.guide { display: grid; grid-template-columns: 230px 1fr; gap: 18px; align-items: start; }
.guide-toc { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; display: grid; gap: 2px; }
.guide-toc a { padding: 6px 10px; border-radius: 7px; color: var(--text); font-size: 14px; }
.guide-toc a:hover { background: var(--surface-2); text-decoration: none; }
.toc-group { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 12px 10px 4px; }
.guide-group { margin: 20px 0 10px; }
.guide-group:first-child { margin-top: 0; }
.guide-topic { scroll-margin-top: 70px; }
.guide-topic p { margin: 0 0 10px; }
.guide-topic .pb > :last-child { margin-bottom: 0; }
.steps, .bullets { margin: 0 0 10px; padding-left: 22px; display: grid; gap: 6px; }
.steps li::marker { font-weight: 700; color: var(--accent); }
.guide-tip { margin: 10px 0; }
.guide-table { margin: 6px 0 12px; }
.faq dt { font-weight: 700; margin-top: 12px; }
.faq dt:first-child { margin-top: 0; }
.faq dd { margin: 4px 0 0; color: var(--muted); }
@media (max-width: 960px) {
  .guide { grid-template-columns: 1fr; }
  .guide-toc { display: none; }
}
@media print {
  .nav, .topbar, .no-print, #toasts, .scrim { display: none !important; }
  .layout { display: block; }
  body { background: #fff; color: #000; }
  .guide { display: block; }
  .panel { box-shadow: none; break-inside: avoid; }
  .content { padding: 0; max-width: none; }
}
