/* Аналитика КМТ — интерфейс под ПК, на телефоне таблицы прокручиваются по горизонтали. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #18202b;
  --muted: #5d6877;
  --border: #e1e5ea;
  --accent: #1f5bd8;
  --accent-hover: #194bb3;
  --accent-text: #ffffff;
  --ok: #17663f;
  --ok-bg: #e6f4ec;
  --warn: #7f5200;
  --warn-bg: #fff3d6;
  --err: #a8231a;
  --err-bg: #fde9e7;
  --info: #2d5a86;
  --info-bg: #e8f0f8;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a2028;
    --surface-2: #222a34;
    --text: #e6eaf0;
    --muted: #9aa5b3;
    --border: #2d3642;
    --accent: #5b8dff;
    --accent-hover: #7aa3ff;
    --accent-text: #0b1220;
    --ok: #7dd3a5;
    --ok-bg: #173226;
    --warn: #f0c46b;
    --warn-bg: #3a2d10;
    --err: #ff9b91;
    --err-bg: #3d1a17;
    --info: #9cc2ea;
    --info-bg: #182a3d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0 0 12px; }
p { margin: 0 0 10px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar__inner { max-width: 1440px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 24px; height: 52px; }
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.userbox form { margin: 0; }
.userbox__name { color: var(--muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.devbar { background: var(--warn-bg); color: var(--warn); text-align: center; padding: 6px 16px; font-size: 13px; font-weight: 600; }
.login { max-width: 460px; margin: 48px auto; }
.login h1 { margin-bottom: 14px; }
.login form { margin: 14px 0; }
.login__code { font-size: 40px; font-weight: 700; letter-spacing: 0.25em; text-align: center; padding: 12px; margin: 14px 0;
  background: var(--surface-2); border-radius: var(--radius); font-variant-numeric: tabular-nums; }
.login .btn--wide { display: block; width: 100%; text-align: center; margin-bottom: 12px; }
.btn--wide:hover { text-decoration: none; }
.steps { padding-left: 20px; margin: 0 0 6px; }
.steps li { margin-bottom: 4px; }
.code { background: var(--surface-2); border-radius: 6px; padding: 10px 12px; overflow-x: auto; font-size: 13px; }
.section-title { font-size: 18px; margin: 24px 0 8px; }
@media (max-width: 600px) { .userbox__name { display: none; } .login { margin: 16px auto; } }
@media (max-width: 600px) { .topbar__inner { gap: 10px; } }
.nav { display: flex; gap: 4px; overflow-x: auto; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.is-active { color: var(--text); background: var(--surface-2); font-weight: 600; }

.page { max-width: 1440px; margin: 0 auto; padding: 20px 16px 48px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; min-width: 0; }
.card--action { display: flex; justify-content: space-between; align-items: center; gap: 16px; border-color: var(--accent); flex-wrap: wrap; }
.card--action h2 { margin-bottom: 4px; }
.grid { display: grid; gap: 16px; }
.grid > .card { margin-bottom: 0; }
.grid + .card, .grid + .grid { margin-top: 16px; }
.grid--upload { grid-template-columns: minmax(320px, 420px) 1fr; }
.grid--two { grid-template-columns: 1fr 1fr; margin-bottom: 16px; }
@media (max-width: 1100px) { .grid--upload { grid-template-columns: 1fr; } }
@media (max-width: 900px) { .grid--two { grid-template-columns: 1fr; } }

.lead { color: var(--muted); max-width: 820px; margin-bottom: 16px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 10px; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.req { color: var(--err); }

.form .field { display: block; border: 0; padding: 0; margin: 0 0 14px; }
.field__label { display: block; font-weight: 600; margin-bottom: 6px; padding: 0; }
input[type=text], input[type=date], select, input[type=file] {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; max-width: 100%;
}
input[type=text] { width: 100%; }
input[type=file] { width: 100%; padding: 6px; }
input:focus-visible, select:focus-visible, .btn:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.period { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.card--action .actions { margin-top: 0; }

.btn { font: inherit; font-weight: 600; border-radius: 6px; padding: 8px 16px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--small { padding: 4px 10px; font-size: 13px; }
.link { font: inherit; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline dotted; }

.flash { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; border: 1px solid transparent; }
.flash--ok { background: var(--ok-bg); color: var(--ok); }
.flash--error { background: var(--err-bg); color: var(--err); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table thead th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.table tbody tr:hover { background: var(--surface-2); }
.table--compact th, .table--compact td { padding: 4px 8px; font-size: 13px; }
.table--plain th { font-weight: 500; color: var(--muted); }
.table--plain tbody tr:hover { background: transparent; }
.table--form th { width: 55%; font-weight: 400; }
.table--form tbody tr:hover { background: transparent; }
.table .num, .num { text-align: right; white-space: nowrap; }
.table tfoot td { font-weight: 600; background: var(--surface-2); border-bottom: 0; }
.table .empty { text-align: center; color: var(--muted); padding: 24px; }
.row--warning td, .row--warning th { background: var(--warn-bg); }
.row--muted td { color: var(--muted); }

.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge--applied { background: var(--ok-bg); color: var(--ok); }
.badge--preview { background: var(--info-bg); color: var(--info); }
.badge--rejected, .badge--failed { background: var(--err-bg); color: var(--err); }
.badge--queued, .badge--parsing { background: var(--warn-bg); color: var(--warn); }

.pill { display: inline-block; border-radius: 4px; padding: 1px 6px; font-size: 12px; font-weight: 600; margin-right: 4px; white-space: nowrap; }
.pill--error { background: var(--err-bg); color: var(--err); }
.pill--warning { background: var(--warn-bg); color: var(--warn); }
.pill--info { background: var(--info-bg); color: var(--info); }

.crumbs { color: var(--muted); margin-bottom: 8px; }
.run-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.run-head h1 { margin: 0; max-width: 900px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.section-head h2 { margin: 0; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 24px; margin: 0; }
.facts dt { color: var(--muted); font-size: 12px; }
.facts dd { margin: 2px 0 0; font-weight: 600; }
.message { margin: 14px 0 0; padding: 10px 14px; border-radius: 6px; background: var(--surface-2); }
.message--rejected, .message--failed { background: var(--err-bg); color: var(--err); }
.loading { margin: 14px 0 0; color: var(--warn); }
.ok-line { color: var(--ok); margin-top: 10px; }

.changes { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 4px; }
.changes .num { display: inline-block; min-width: 64px; font-weight: 600; margin-right: 8px; }
.changes--warn { color: var(--warn); }

.issue { border: 1px solid var(--border); border-radius: 6px; margin-bottom: 8px; background: var(--surface); }
.issue > summary { cursor: pointer; padding: 8px 12px; display: flex; gap: 10px; align-items: baseline; list-style: none; }
.issue > summary::-webkit-details-marker { display: none; }
.issue > summary::before { content: "▸"; color: var(--muted); }
.issue[open] > summary::before { content: "▾"; }
.issue__text { flex: 1; }
.issue__count { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.issue .table-wrap, .issue > p { margin: 0 12px 10px; }
.issue--error { border-color: var(--err); }

.summary-title { cursor: pointer; font-weight: 600; }
.meta { display: grid; grid-template-columns: 220px 1fr; gap: 6px 16px; margin: 12px 0 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-word; }
@media (max-width: 700px) { .meta { grid-template-columns: 1fr; } .truncate { max-width: 180px; } }

/* --- клиенты --- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { margin-bottom: 4px; }
.page-head .actions { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 4px 12px; font-size: 13px; white-space: nowrap; }
.chip:hover { text-decoration: none; background: var(--surface-2); }
.chip.is-active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip--attention { border-color: var(--warn); }
.filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; padding: 12px 16px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.filters label.grow { flex: 1; min-width: 180px; }
.filters label.check { flex-direction: row; align-items: center; font-size: 14px; color: var(--text); }
.filters .summary-line { margin: 0 0 0 auto; }
.custom-period { display: flex; gap: 6px; }
.summary-line { margin: 0 0 12px; }
.status { display: inline-block; border-radius: 4px; padding: 1px 7px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.status--active { background: var(--ok-bg); color: var(--ok); }
.status--new { background: var(--info-bg); color: var(--info); }
.status--declining, .status--at_risk { background: var(--warn-bg); color: var(--warn); }
.status--lost { background: var(--err-bg); color: var(--err); }
.seg { display: inline-block; border: 1px solid var(--border); border-radius: 4px; padding: 0 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.seg--wholesale { color: var(--accent); border-color: var(--accent); }
.seg--none { border-style: dashed; }
.neg { color: var(--err); font-weight: 600; }
.pos { color: var(--ok); font-weight: 600; }
.small { font-size: 12px; }
.status-note { margin: 14px 0 0; padding: 10px 12px; background: var(--surface-2); border-radius: 6px; }
.inline-form { display: flex; gap: 8px; align-items: center; margin: 0; }
.inline-form input[type=text] { width: 260px; }
.found-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); margin: 0; }
h3 { font-size: 14px; margin: 18px 0 6px; }
textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; width: 100%; }
.events { list-style: none; padding: 0; margin: 0; font-size: 13px; display: grid; gap: 4px; }
.merge-pair__clients { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: start; }
.merge-pair__plus { font-size: 20px; color: var(--muted); padding-top: 2px; }
.merge-pair__why { margin-top: 8px; }
.table--clients td { vertical-align: middle; }
@media (max-width: 700px) { .merge-pair__clients { grid-template-columns: 1fr; } .merge-pair__plus { display: none; } .filters .summary-line { margin-left: 0; } }
.table--clients thead th { white-space: normal; vertical-align: bottom; }
.table--clients td:first-child { min-width: 220px; }
.table--clients th, .table--clients td { padding: 6px 8px; }
.input-short { width: 110px !important; }

/* --- товары --- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; color: var(--text); }
a.kpi:hover { text-decoration: none; border-color: var(--accent); }
.kpi__label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi__value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi__note { font-size: 12px; color: var(--muted); }
.kpi--err .kpi__value { color: var(--err); }
.kpi--warn .kpi__value { color: var(--warn); }
.pstatus--deficit { background: var(--err-bg); color: var(--err); }
.pstatus--running_out { background: var(--warn-bg); color: var(--warn); }
.pstatus--dead { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pstatus--slow { background: var(--info-bg); color: var(--info); }
.pstatus--ok { background: var(--ok-bg); color: var(--ok); }
.chip-sep { width: 1px; background: var(--border); margin: 0 4px; }
.run-head .seg { margin-left: 2px; }
.tg-message { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 12px; font-size: 14px; line-height: 1.45; max-width: 560px; overflow-wrap: anywhere; }
.check-line { display: block; margin: 2px 0; }
