/* Дизайн — по макету варианта B (MINIAPP.md), цвета — фирменные vokshelp:
   всё выведено из зелёного #35453A и светлого #F2F2F1 (цвета логотипа, брендбук).
   Светлая тема: фон #F2F2F1, кнопки и активный пункт — #35453A. Тёмная: фон —
   очень тёмный зелёный, главные кнопки светлые #F2F2F1, как лого в тёмной теме.
   Контраст текста проверен (WCAG ≥ 4.5) — при смене цветов перепроверять.
   Шрифты — системные (SF на Mac): без Google Fonts, чтобы страница не ждала чужой
   сервер без VPN. Тема: в браузере — по системе, в окне Telegram — по теме Telegram
   (app.js ставит data-theme). */
:root {
  --ground: #F2F2F1;
  --surface: #FFFFFF;
  --line: #DBDEDB;
  --line-soft: #EBECEB;
  --chip: #F3F4F3;
  --text: #1C2620;
  --text-2: #3E4B42;
  --muted: #657068;
  --faint: #9AA29C;
  --accent: #35453A;          /* заливки: главные кнопки */
  --accent-hover: #2A372E;
  --accent-ink: #35453A;      /* акцент текстом: ссылки, активная вкладка */
  --on-accent: #FFFFFF;
  --nav-on: #35453A;
  --on-nav-on: #FFFFFF;
  --warn: #8A4210;
  --warn-bg: #FBF0E6;
  --brand: #35453A;           /* логотип vokshelp: зелёный на светлом */
  --good: #1E7A44;            /* лучшая цена (вкладка «Цены»); фирменный зелёный в тёмной теме — серый */
  --good-bg: #E3F2E8;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #131915; --surface: #1A221D; --line: #2C3830; --line-soft: #232C26;
    --chip: #212A24; --text: #F2F2F1; --text-2: #C8CDC9; --muted: #9AA39D; --faint: #6B756F;
    --accent: #F2F2F1; --accent-hover: #FFFFFF; --accent-ink: #F2F2F1; --on-accent: #131915;
    --nav-on: #F2F2F1; --on-nav-on: #131915; --warn: #F0A56B; --warn-bg: #2E2219;
    --brand: #F2F2F1; --good: #7FD8A0; --good-bg: rgba(127, 216, 160, .13);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #131915; --surface: #1A221D; --line: #2C3830; --line-soft: #232C26;
  --chip: #212A24; --text: #F2F2F1; --text-2: #C8CDC9; --muted: #9AA39D; --faint: #6B756F;
  --accent: #F2F2F1; --accent-hover: #FFFFFF; --accent-ink: #F2F2F1; --on-accent: #131915;
  --nav-on: #F2F2F1; --on-nav-on: #131915; --warn: #F0A56B; --warn-bg: #2E2219;
  --brand: #F2F2F1; --good: #7FD8A0; --good-bg: rgba(127, 216, 160, .13);
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* иначе display у .app/.center перебивает атрибут hidden и экран виден без входа */
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--ground); color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
h1 { margin: 0; font-size: 26px; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--accent-ink); }
code, .mono { font-family: var(--mono); font-size: 0.93em; }
code {
  background: var(--chip); border: 1px solid var(--line); border-radius: 6px;
  padding: 1px 6px; white-space: nowrap;
}

/* ── карточки, кнопки ── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-secondary:hover { background: var(--chip); }
.btn:focus-visible, .nav button:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }

/* ── логотип vokshelp ──
   Один файл logo.svg служит МАСКОЙ, цвет — фон под ней (--brand): зелёный в светлой
   теме, светло-серый в тёмной. Так не нужны две картинки под две темы. */
.logo-full {
  display: block; height: 26px; aspect-ratio: 1780 / 265; background: var(--brand);
  -webkit-mask: url(logo.svg) no-repeat center / contain;
  mask: url(logo.svg) no-repeat center / contain;
}
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.brand .logo-full { height: 30px; }
.brand small { font-size: 13px; color: var(--muted); }

/* ── загрузка и экраны входа ── */
.center {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 40px 16px;
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent-ink);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.gate { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 20px; }
.gate-card { padding: 26px 24px; display: flex; flex-direction: column; gap: 14px; }
#gate-text { color: var(--text-2); }
#gate-body { display: flex; flex-direction: column; gap: 12px; }
#gate-body:empty { display: none; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions .btn { flex: 1 1 180px; }
.step { display: flex; gap: 12px; align-items: baseline; color: var(--text-2); font-size: 14.5px; }
.step-n {
  flex: none; width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--chip); border: 1px solid var(--line); font-size: 12px; font-weight: 600; color: var(--text);
}
.big-id { font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: .02em; }
.fine { font-size: 13px; line-height: 1.55; color: var(--muted); }

/* ── рабочее место ── */
.app { min-height: 100vh; display: flex; }
.side {
  width: 236px; flex: none; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 22px; padding: 20px 14px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.side-brand { padding: 6px 8px 2px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 10px; min-height: 44px; width: 100%;
  padding: 0 12px; border: 0; border-radius: 8px; background: transparent;
  color: var(--text-2); font: inherit; font-size: 14.5px; font-weight: 500; text-align: left; cursor: pointer;
}
.nav button:hover:not(:disabled) { background: var(--line-soft); color: var(--text); }
.nav button.on, .nav button.on:hover { background: var(--nav-on); color: var(--on-nav-on); }
.nav button:disabled { color: var(--faint); cursor: default; }
.nav button small { font-size: 12px; font-weight: 400; }
.nav svg {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.me {
  margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line-soft);
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: 13.5px; color: var(--text-2);
}
#me-name { overflow-wrap: anywhere; }
button.link {
  border: 0; background: none; padding: 6px 0; min-height: 32px; cursor: pointer;
  font: inherit; color: var(--accent-ink); text-decoration: underline; text-underline-offset: 3px;
}
button.link:hover { color: var(--text); }

.main {
  flex: 1; min-width: 0; padding: 28px clamp(16px, 4vw, 44px) 48px;
  display: flex; flex-direction: column;
}
.panel { max-width: 760px; display: flex; flex-direction: column; gap: 6px; }
.panel h1 { margin-bottom: 14px; }
.empty { padding: 22px 22px 20px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.empty p { color: var(--text-2); max-width: 62ch; }
.empty .muted { color: var(--muted); font-size: 14px; }
.badge {
  font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--warn);
  background: var(--warn-bg); border-radius: 999px; padding: 2px 10px;
}

.btn:disabled, .btn:disabled:hover { opacity: .45; cursor: default; background: var(--accent); }
.btn-secondary:disabled, .btn-secondary:disabled:hover { background: var(--surface); }
.muted { color: var(--muted); }

/* ── вкладка «Инвойс» (invoice.js). Цвета — только токены выше: контраст уже проверен. ── */
.inv { display: flex; flex-direction: column; gap: 14px; }
.inv-card { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.inv-card .actions .btn { flex: 0 1 220px; }
.inv-drop { border-style: dashed; border-width: 1.5px; }
.inv-drop.over { border-color: var(--accent-ink); background: var(--chip); }
.note {
  color: var(--warn); background: var(--warn-bg); border-radius: 10px;
  padding: 10px 14px; font-size: 14px;
}
.warn-text { color: var(--warn); }
.bar { height: 8px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent-ink); border-radius: inherit; transition: width .4s; }
/* размер выборки ещё не известен — бегущий кусок вместо процентов */
.bar.indet > span { width: 30% !important; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) { .bar.indet > span { animation-duration: 3.6s; } }
.stats { display: flex; flex-wrap: wrap; gap: 8px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 13.5px; color: var(--text-2);
}
.stat b { font-size: 18px; color: var(--text); margin-right: 6px; font-variant-numeric: tabular-nums; }
.sec { margin-top: 10px; }
.sec h2 { margin: 0 0 2px; font-size: 18px; line-height: 1.3; }
.sec .hint { color: var(--muted); font-size: 14px; }
.group { padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.group-head {
  display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap;
  gap: 4px 12px; padding: 2px 8px 6px;
}
.art { font-family: var(--mono); font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
/* артикул + «скопировать» в строке текста (инвойс): кнопка не раздувает строку */
.art-copy { display: inline-flex; align-items: center; gap: 2px; }
.art-copy .copy { margin: -6px 0; }
.pick {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 6px 8px;
  border-radius: 8px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.pick:hover { background: var(--chip); }
.pick input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: inherit; }
.pick.off { cursor: default; color: var(--muted); }
.pick.off:hover { background: transparent; }
.sum { padding: 6px 8px 0; font-size: 13.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sum.ok { color: var(--accent-ink); font-weight: 600; }
.sum.bad { color: var(--warn); font-weight: 600; }
.rows { list-style: none; margin: 0; padding: 0 16px; font-size: 14px; color: var(--text-2); }
.rows li { padding: 9px 0; border-top: 1px solid var(--line-soft); }
.rows li:first-child { border-top: 0; }
.rows .rows-head { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
ul.card.rows { padding: 4px 16px; }
.fold { padding: 0; }
.fold summary { padding: 12px 16px; cursor: pointer; font-weight: 600; font-size: 14.5px; }
.fold[open] summary { border-bottom: 1px solid var(--line-soft); }
.fold .rows { padding-bottom: 6px; }
/* Кнопка «Подтвердить» всегда под рукой: прилипает к низу экрана. */
.actbar {
  position: sticky; bottom: 12px; margin-top: 8px; padding: 12px 14px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .08);
}
.act-text { font-size: 14px; color: var(--text-2); }
.act-text.bad { color: var(--warn); font-weight: 600; }
.actbar .actions { flex: 1 1 auto; justify-content: flex-end; }
.actbar .actions .btn { flex: 0 1 auto; }

/* ── вкладка «Цены» (prices.js) ──
   Раскладка: уже 1600 — одна колонка (обёртки «растворены», порядок задан order); шире — вариант 4
   (Илья 24.10): слева управление липнет, справа таблица, пометки — её колонкой справа. */
.pr-layout { display: flex; flex-direction: column; gap: 14px; }
.pr-side, .pr-main { display: contents; }
#pq { order: 1; } #pq-out { order: 2; } #pf { order: 3; } #pf-main { order: 4; }
#pq-out:empty, #pf-main:empty { display: none; }
/* пометки лежат в двух местах (prices.js, prRow): узко — строкой под позицией, широко — колонкой */
.pr-table .notes { display: none; }
@media (min-width: 1600px) {
  .pr-table .notes { display: table-cell; }
  .pr-table tr.pr-sub { display: none; }
  .pr-table tr.has-sub td { padding-bottom: 9px; }
  .panel.pr-panel { max-width: none; }
  .pr-layout { display: grid; grid-template-columns: 400px minmax(0, 1fr); gap: 24px; align-items: start; }
  .pr-side, .pr-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
  .pr-side { position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow-y: auto; }
  .pr-side .chips { flex-direction: column; align-items: stretch; }
  .pr-side .btn.chip { justify-content: flex-start; }
  .pr-table .num { width: 1%; }           /* цены — по содержимому, остальное — пометкам */
  .pr-table td.notes { min-width: 320px; font-size: 13px; }
  .pr-table td.notes .pr-notes { position: static; max-width: none; }
}
.pr-text {
  width: 100%; min-height: 76px; resize: vertical; padding: 10px 12px;
  font: 15px/1.45 var(--mono); color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
}
.pr-text:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 1px; }
/* таблица цен — вариант A (как в Excel); узко — листается вбок, артикул прибит слева */
.pr-scroll { overflow-x: auto; }
.pr-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.pr-table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase;
  letter-spacing: .05em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.pr-table td { padding: 9px 12px; border-top: 1px solid var(--line-soft); vertical-align: top; }
.pr-table tr:first-child td { border-top: 0; }
.pr-table .num { text-align: right; white-space: nowrap; }
.pr-table .money { font-variant-numeric: tabular-nums; color: var(--text); }
.pr-table .t { display: block; font-size: 12.5px; color: var(--muted); }
.pr-table td.w { background: var(--good-bg); }
.pr-table td.w .money, .pr-table td.best .money { color: var(--good); }
.pr-table td.best .money { font-size: 15px; }
.pr-table td.dash { color: var(--faint); }
.pr-table th:first-child, .pr-art { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.pr-brand { font-size: 12.5px; color: var(--muted); min-height: 1em; white-space: nowrap; }
.pr-num { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.pr-num .art { font-size: 15px; }
.pr-tr.has-sub td { padding-bottom: 4px; }
.pr-sub td { border-top: 0; padding-top: 0; }
.pr-wide { color: var(--text-2); }
.pr-wide .actions { margin-top: 8px; }
.pr-wide .actions .btn { flex: 0 1 auto; min-height: 40px; }
/* пометки во всю ширину, но при прокрутке вбок стоят на месте и переносятся по видимой ширине */
.pr-notes {
  list-style: none; margin: 0; padding: 0; font-size: 13.5px; color: var(--text-2);
  position: sticky; left: 12px; max-width: calc(100vw - 80px);
}
.pr-notes li { display: flex; align-items: center; flex-wrap: wrap; gap: 0 4px; }
.pr-notes .o { color: var(--warn); }
.pr-notes .art { font-weight: 600; color: inherit; }
/* «скопировать»: значок — маска, цвет — текущий текст; скопировано — галочка */
.copy {
  flex: none; width: 30px; height: 30px; border: 0; border-radius: 6px; padding: 0;
  background: transparent; color: var(--muted); cursor: pointer; display: inline-grid; place-items: center;
}
.copy:hover { background: var(--chip); color: var(--text); }
.copy:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 1px; }
.copy::before {
  content: ""; width: 15px; height: 15px; background: currentColor;
  -webkit-mask: var(--icon) no-repeat center / contain; mask: var(--icon) no-repeat center / contain;
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='12' height='12' rx='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E");
}
.copy.done { color: var(--good); }
.copy.done::before {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
}
.copy.fail { color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.btn.chip { min-height: 36px; padding: 0 14px; font-size: 13.5px; font-weight: 500; border-radius: 999px;
  background: var(--surface); color: var(--text-2); border-color: var(--line); }
.btn.chip:hover { background: var(--chip); }
.btn.chip.on { background: var(--nav-on); color: var(--on-nav-on); border-color: var(--nav-on); }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; }
.pager .btn { min-height: 40px; }

/* Узко (телефон, окно Telegram на Mac): меню уезжает вниз вкладками с иконками. */
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .side {
    order: 2; position: sticky; bottom: 0; top: auto; width: auto; height: auto; z-index: 2;
    flex-direction: row; gap: 0; padding: 0 0 env(safe-area-inset-bottom);
    border-right: 0; border-top: 1px solid var(--line);
  }
  .side-brand, .me { display: none; }
  .nav { flex-direction: row; flex: 1; gap: 0; }
  .nav button {
    flex: 1; flex-direction: column; justify-content: center; gap: 3px; min-height: 58px;
    padding: 6px 4px; border-radius: 0; font-size: 11.5px; text-align: center; color: var(--muted);
  }
  .nav button small { display: none; }
  /* фирменный зелёный почти не отличим от тёмного текста — активную вкладку
     выделяем полоской сверху, а не только цветом */
  .nav button.on, .nav button.on:hover {
    background: transparent; color: var(--accent-ink); font-weight: 600;
    box-shadow: inset 0 2px 0 var(--accent-ink);
  }
  .nav svg { width: 22px; height: 22px; }
  .main { flex: 1; padding: 20px 16px 28px; }
  h1 { font-size: 23px; }
  /* «Цены»: пояснение и кнопки брендов — в видимой части, а не за правым краем прокрутки */
  .pr-wide > * { max-width: calc(100vw - 230px); }
  .pr-wide > span { display: block; }   /* строчному max-width не действует */
  /* над нижними вкладками, а не под ними */
  .actbar { bottom: calc(66px + env(safe-area-inset-bottom)); }
  .actbar .actions .btn { flex: 1 1 auto; }
}
