/* Визуальный язык — из макетов v2 (Golos Text, тёплый серый фон, синий акцент). */
:root {
  --page: #e6e4dd;
  --bg: #f3f2ee;
  --card: #ffffff;
  --line: #e3e1da;
  --text: #1b1b1a;
  --muted: #5f5e59;
  --accent: #1b4f9e;
  --accent-hover: #153d7a;
  --accent-tint: #e8eef8;
  --dark: #1b1b1a;
  --dark-muted: #c9c7bf;
  --ok: #1f7a4d; --ok-bg: #e4f2ea;
  --warn: #8a5a00; --warn-bg: #fbf0d9;
  --bad: #a8322d; --bad-bg: #f9e3e1;
  --radius: 14px;
  --app-w: 440px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0f0f0e; --bg: #171716; --card: #222220; --line: #34332f; --text: #f1efe8; --muted: #a5a39b;
    --accent: #7fa8e8; --accent-hover: #a3c0ef; --accent-tint: #1f2a3d; --dark: #f1efe8; --dark-muted: #4b4a45;
    --ok: #6cc596; --ok-bg: #18301f; --warn: #e3b55c; --warn-bg: #352a12; --bad: #ef8a84; --bad-bg: #3a1c1a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #0f0f0e; --bg: #171716; --card: #222220; --line: #34332f; --text: #f1efe8; --muted: #a5a39b;
  --accent: #7fa8e8; --accent-hover: #a3c0ef; --accent-tint: #1f2a3d; --dark: #f1efe8; --dark-muted: #4b4a45;
  --ok: #6cc596; --ok-bg: #18301f; --warn: #e3b55c; --warn-bg: #352a12; --bad: #ef8a84; --bad-bg: #3a1c1a; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--text); font-family: 'Golos Text', system-ui, -apple-system, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.app { max-width: var(--app-w); margin: 0 auto; min-height: 100vh; background: var(--bg); padding-bottom: 168px; position: relative; }
@media (min-width: 520px) { .app { box-shadow: 0 8px 30px rgba(0,0,0,.12); } }

/* Шапка */
.head { background: var(--card); border-bottom: 1px solid var(--line); padding: 20px 16px 12px; display: flex; flex-direction: column; gap: 12px; }
.head-row { display: flex; align-items: center; gap: 12px; }
.back { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 12px; display: flex; align-items: center; justify-content: center; color: var(--text); flex-shrink: 0; background: var(--card); }
.titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.eyebrow { font-size: 12px; color: var(--muted); }
h1 { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.2; }
.meta { font-size: 13px; color: var(--muted); line-height: 1.4; }
.note { font-size: 12px; color: var(--muted); line-height: 1.45; }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 13px; white-space: nowrap; flex-shrink: 0; }
a.chip { display: inline-flex; align-items: center; color: var(--text); }
a.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.on, a.chip.on { background: var(--dark); color: var(--bg); border-color: var(--dark); font-weight: 500; }

.search { position: relative; }
.search input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 12px; padding: 0 40px 0 40px; background: var(--card); font-size: 15px; }
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search svg { position: absolute; left: 12px; top: 11px; color: var(--muted); }
.search .clear { position: absolute; right: 6px; top: 6px; width: 32px; height: 32px; border: 0; background: none; color: var(--muted); font-size: 18px; }

.body { padding: 12px 16px 0; display: flex; flex-direction: column; gap: 10px; }
.section-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 10px 0 0; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); padding: 0 14px; font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--text); flex: none; text-align: center; }
.btn-row .btn { flex: 1; }
.btn.primary { background: var(--dark); color: var(--bg); border-color: var(--dark); }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { height: 36px; font-size: 13px; flex: 0 0 auto; }
.btn[disabled] { opacity: .45; cursor: default; }

/* Карточки */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
a.card { color: var(--text); }
a.card:hover { border-color: var(--accent); color: var(--text); }
.card.sel { border-color: var(--accent); }
.card-title { font-size: 15px; font-weight: 600; line-height: 1.35; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.big { font-size: 17px; font-weight: 700; white-space: nowrap; }
.unit { font-size: 12px; font-weight: 400; color: var(--muted); }
.in-cart { font-size: 12px; color: var(--accent); font-weight: 500; }
.seller-tag { font-size: 12px; font-weight: 600; color: var(--muted); }

.badge { display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--accent-tint); color: var(--accent); }
.badge.muted { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

/* Группы и категории */
.group { padding: 0; gap: 0; overflow: hidden; }
.group-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px; border: 0; background: none; width: 100%; text-align: left; }
.group-head .chev { transition: transform .15s; color: var(--muted); flex-shrink: 0; }
.group.open .chev { transform: rotate(90deg); }
.cat-list { border-top: 1px solid var(--line); }
.cat { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); color: var(--text); }
.cat:last-child { border-bottom: 0; }
.cat:hover { background: var(--bg); color: var(--text); }
.cat-name { font-size: 14px; font-weight: 500; }

/* Степпер количества */
.stepper { display: flex; align-items: center; border: 1px solid var(--accent); border-radius: 10px; overflow: hidden; flex-shrink: 0; background: var(--card); }
.stepper button { width: 40px; height: 40px; border: 0; background: transparent; color: var(--accent); font-size: 20px; }
.stepper input { width: 72px; height: 40px; border: 0; text-align: center; font-size: 15px; font-weight: 600; background: transparent; }
.stepper input:focus { outline: none; background: var(--accent-tint); }
.add { height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--accent); background: var(--card); color: var(--accent); font-weight: 600; font-size: 14px; flex-shrink: 0; }

.more { height: 44px; border: 1px dashed var(--line); background: transparent; border-radius: 12px; color: var(--accent); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; font-size: 14px; line-height: 1.5; }

/* Нижняя панель заявки и навигация */
.dock { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: var(--app-w); z-index: 10; }
.cartbar { margin: 0 16px 10px; display: flex; justify-content: space-between; align-items: center; background: var(--dark); color: var(--bg); border-radius: 14px; padding: 10px 16px; min-height: 56px; gap: 10px; }
.cartbar:hover { color: var(--bg); }
.cartbar .t1 { font-size: 14px; font-weight: 600; }
.cartbar .t2 { font-size: 12px; color: var(--dark-muted); }
.cartbar .go { font-size: 14px; font-weight: 600; white-space: nowrap; }
.nav { height: 72px; background: var(--card); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: center; padding: 0 8px; }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); height: 56px; justify-content: center; position: relative; }
.nav a.on { color: var(--accent); font-weight: 600; }
.nav .dot { position: absolute; top: 4px; left: calc(50% + 8px); min-width: 18px; height: 18px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 4px; }

/* Загрузка и проверка */
textarea.list { width: 100%; min-height: 140px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 14px; line-height: 1.45; background: var(--card); resize: vertical; }
.drop { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 18px 14px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; background: var(--card); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-tint); }
.drop input { display: none; }
.steps { display: flex; flex-direction: column; gap: 8px; }
.step { display: flex; gap: 10px; font-size: 13px; line-height: 1.45; color: var(--muted); }
.step b { width: 22px; height: 22px; border-radius: 11px; background: var(--accent-tint); color: var(--accent); font-size: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.src { font-size: 12px; color: var(--muted); }
.src q { color: var(--text); }
.cand { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.cand input { margin-top: 3px; accent-color: var(--accent); }
.cand.on { border-color: var(--accent); background: var(--accent-tint); }
.cand .cn { font-size: 13px; font-weight: 600; line-height: 1.35; }
.cand .cm { font-size: 12px; color: var(--muted); margin-top: 2px; }
.alert { font-size: 12px; line-height: 1.45; padding: 8px 10px; border-radius: 10px; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.info { background: var(--accent-tint); color: var(--accent); }

.lines { display: flex; flex-direction: column; }
.line { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.line:last-child { border-bottom: 0; }
.line .ln { font-weight: 500; line-height: 1.35; }
.line .lm { color: var(--muted); margin-top: 2px; font-size: 12px; }
.line .lt { font-weight: 600; white-space: nowrap; }
.total { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; font-size: 16px; }
.link-btn { border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 600; padding: 0; }
.link-btn.bad { color: var(--bad); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); top: 16px; background: var(--dark); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: calc(100% - 32px); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Переключатель режима ---------- */
.seg { display: inline-flex; align-self: flex-start; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg a { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 9px; color: var(--muted); font-size: 13px; font-weight: 600; }
.seg a:hover { color: var(--text); }
.seg a.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- Табличный режим ---------- */
body.wide .app { max-width: none; padding-bottom: 0; box-shadow: none; min-height: 0; }
body.wide .dock { max-width: none; }
/* Внизу на широком экране: навигация слева, плашка заявки справа — в одну строку, чтобы оставить место таблице. */
body.wide .dock { display: flex; flex-direction: row-reverse; align-items: center; gap: 16px; padding: 6px 16px; background: var(--card); border-top: 1px solid var(--line); }
body.wide .cartbar { flex: 0 1 560px; margin: 0; min-height: 52px; }
body.wide .nav { flex: 0 0 420px; height: 60px; border-top: 0; background: transparent; padding: 0; margin-right: auto; }
.tf-toggle { display: none; }

.tbar { background: var(--card); border-bottom: 1px solid var(--line); padding: 16px 20px 10px; display: flex; flex-direction: column; gap: 12px; }
.tbar-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.tfilters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tsearch { flex: 1 1 260px; max-width: 420px; }
.tsearch input { height: 40px; }
.tsearch svg { top: 10px; }
.tsel { height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 0 10px; font-size: 14px; max-width: 230px; }
.tsel:focus, .tsearch input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.tcheck { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; height: 40px; padding: 0 4px; cursor: pointer; white-space: nowrap; }
.tcheck input { width: 16px; height: 16px; accent-color: var(--accent); }
.tspacer { flex: 1 1 0; }
.tfilters .btn.small { height: 40px; }
.tstatus { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.thint { font-size: 12px; }
.tpage.collapsed .tbar-top, .tpage.collapsed .tstatus { display: none; }
.tpage.collapsed .tbar { padding-top: 8px; padding-bottom: 8px; }

.twrap { overflow: auto; background: var(--card); scroll-padding-top: 44px; height: 60vh; }
table.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13px; }
.grid th { position: sticky; top: 0; z-index: 2; background: var(--bg); text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 0 10px; height: 40px; border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none; }
.grid th.sortable { cursor: pointer; }
.grid th.sortable:hover, .grid th.sorted { color: var(--text); }
.grid th:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid th .arr { margin-left: 4px; font-size: 10px; }
.grid td { height: 56px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--card); vertical-align: middle; }
.grid tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--bg) 45%, var(--card)); }
.grid tbody tr:hover td { background: color-mix(in srgb, var(--accent-tint) 45%, var(--card)); }
.grid tbody tr.sel td { background: var(--accent-tint); }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid th.num { text-align: right; }
.grid .c-name { position: sticky; left: 0; z-index: 1; min-width: 380px; max-width: 380px; border-right: 1px solid var(--line); }
.grid th.c-name { z-index: 3; }
.grid .c-seller { min-width: 110px; font-weight: 600; white-space: nowrap; }
.grid .c-cat { min-width: 180px; max-width: 220px; }
.grid .c-stock { min-width: 90px; }
.grid .c-price { min-width: 100px; }
.grid .c-sum { min-width: 110px; color: var(--muted); }
.grid .c-qty { min-width: 104px; }
.grid .c-total { min-width: 110px; font-weight: 600; }
.grid.one-seller .c-seller { display: none; }
.grid .nm { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.3; font-weight: 500; }
.grid .nm1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid .tid { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tq { width: 88px; height: 34px; border: 1px solid var(--line); border-radius: 8px; text-align: right; padding: 0 8px; font-size: 14px; font-weight: 600;
  background: var(--card); font-variant-numeric: tabular-nums; }
.tq:hover { border-color: var(--accent); }
.tq:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.tq::placeholder { color: var(--line); }
tr.sel .tq { border-color: var(--accent); color: var(--accent); }
.grid td.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0%, 40% { background: var(--warn-bg); } }
.grid .tid .mob { display: none; }
.tempty { text-align: center; color: var(--muted); height: 120px !important; }

@media (max-width: 640px) {
  body.wide .dock { flex-direction: column; align-items: stretch; gap: 0; padding: 8px 0 0; }
  body.wide .cartbar { flex: none; margin: 0 12px 6px; }
  body.wide .nav { flex: none; width: 100%; height: 64px; }
  .tf-toggle { display: inline-flex; }
  .tfilters > :not(.tsearch):not(.tf-toggle) { display: none; }
  .tfilters.open > :not(.tspacer) { display: inline-flex; }
  .tfilters.open > .tsel { display: block; }
  .tsearch { flex: 1 1 0; }
  .tbar-top h1 { font-size: 20px; }
  .tbar { padding: 12px 12px 8px; gap: 10px; }
  .tbar-top { gap: 8px; }
  .tbar-top .titles { width: 100%; }
  .tbar .meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .thint { display: none; }
  .tsel { flex: 1 1 140px; }
  .tspacer { display: none; }
  .grid .c-name { min-width: 180px; max-width: 180px; }
  .grid .c-cat, .grid .c-unit, .grid .c-sum, .grid .c-stock, .grid .c-price { display: none; }
  .grid .tid .mob { display: inline; }
  .grid .c-name .tid { white-space: normal; }
  .grid .c-qty { min-width: 96px; }
  .grid td { height: 64px; }
  .grid .nm { -webkit-line-clamp: 3; font-size: 12px; }
}

/* ---------- Сделка: этапы, компании, пульт менеджера ---------- */
.stages { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.stage { display: flex; flex-direction: column; gap: 5px; font-size: 11px; color: var(--muted); font-weight: 500; min-width: 0; }
.stage i { display: block; height: 6px; border-radius: 3px; background: var(--line); }
.stage.done i { background: var(--ok); }
.stage.done { color: var(--ok); }
.stage.current i { background: var(--accent); }
.stage.current { color: var(--accent); font-weight: 600; }
.stage.failed i { background: var(--bad); }
.stage.failed { color: var(--bad); font-weight: 600; }
.stage span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.approw { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.approw:last-of-type { border-bottom: 0; }
.approw .cn { font-size: 14px; font-weight: 600; }
.approw .cm { font-size: 12px; color: var(--muted); margin-top: 2px; }
.approw-r { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }

.reqform { gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.field input, .minput { height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font-size: 15px; background: var(--card); color: var(--text); width: 100%; }
.field input:focus, .minput:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field input[readonly] { background: var(--bg); color: var(--muted); }
.mfield { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); width: 92px; flex-shrink: 0; }
.mfield .minput { height: 36px; font-size: 14px; padding: 0 8px; text-align: right; }

.head.mgr { background: var(--dark); color: var(--bg); border-bottom: 0; }
.head.mgr .meta, .head.mgr .eyebrow, .head.mgr .note { color: var(--dark-muted); }
.head.mgr .back { background: transparent; color: var(--bg); border-color: var(--dark-muted); }
.lm s, .ln s, .lt s { color: var(--muted); }
.clamp3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.field select { height: 42px; flex: none; }
.checks { display: flex; flex-wrap: wrap; gap: 2px 14px; }
.checks .tcheck { height: 32px; font-size: 13px; color: var(--text); }

/* Только просмотр (BROWSE_ONLY в app.js): без кнопок заказа и выбора */
body.browse .add, body.browse .stepper, body.browse .cartbar, body.browse .c-qty,
body.browse a[href^="#/upload"], body.browse [data-act="t-export"], body.browse .in-cart, body.browse .grid .c-total { display: none !important; }
/* на телефоне вместо колонок заказа — сумма партии */
@media (max-width: 720px) { body.browse .grid .c-sum { display: table-cell; } }
