:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --hover: #eef1f4;
  --ink: #14161a;
  --ink-2: #6b6e76;
  --ink-3: #999da6;
  --line: #e1e4ea;
  --accent: #007aff;
  --accent-fg: #ffffff;
  --accent-tint: #eaf2ff;
  --ok: #1f8a4c;
  --warn: #b8630b;
  --err: #c02626;
  --bar: rgba(245,246,248,.88);
  --bar-solid: rgba(255,255,255,.94);
  --code-bg: #f1f3f6;
  --btn-fg: #ffffff;
  --toast-bg: #14161a;
  --toast-fg: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20,22,26,.05), 0 8px 24px rgba(20,22,26,.06);
}

/* Тёмная тема — только для интерфейса. Счёт остаётся «бумажным»:
   это предпросмотр печатного документа, он белый в любой теме. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1c1e22;
    --hover: #262931;
    --ink: #eef0f3;
    --ink-2: #9ea2ab;
    --ink-3: #6b6f78;
    --line: #2c2f36;
    --accent: #0a84ff;
    --accent-fg: #ffffff;
    --accent-tint: rgba(10,132,255,.16);
    --ok: #5fbe83;
    --warn: #e0973f;
    --err: #ef7070;
    --bar: rgba(21,23,26,.88);
    --bar-solid: rgba(28,30,34,.94);
    --code-bg: #1a1c20;
    --btn-fg: #ffffff;
    --toast-bg: #eef0f3;
    --toast-fg: #15171a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}

:root[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1c1e22;
  --hover: #262931;
  --ink: #eef0f3;
  --ink-2: #9ea2ab;
  --ink-3: #6b6f78;
  --line: #2c2f36;
  --accent: #0a84ff;
  --accent-fg: #ffffff;
  --accent-tint: rgba(10,132,255,.16);
  --ok: #5fbe83;
  --warn: #e0973f;
  --err: #ef7070;
  --bar: rgba(21,23,26,.88);
  --bar-solid: rgba(28,30,34,.94);
  --code-bg: #1a1c20;
  --btn-fg: #ffffff;
  --toast-bg: #eef0f3;
  --toast-fg: #15171a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}

:root[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --hover: #eef1f4;
  --ink: #14161a;
  --ink-2: #6b6e76;
  --ink-3: #999da6;
  --line: #e1e4ea;
  --accent: #007aff;
  --accent-fg: #ffffff;
  --accent-tint: #eaf2ff;
  --ok: #1f8a4c;
  --warn: #b8630b;
  --err: #c02626;
  --bar: rgba(245,246,248,.88);
  --bar-solid: rgba(255,255,255,.94);
  --code-bg: #f1f3f6;
  --btn-fg: #ffffff;
  --toast-bg: #14161a;
  --toast-fg: #ffffff;
  --shadow: 0 1px 2px rgba(20,22,26,.05), 0 8px 24px rgba(20,22,26,.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- Каркас ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 24px;
  background: var(--bar);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.logo { font-weight: 700; letter-spacing: -.02em; font-size: 17px; }
.logo span { color: var(--ink-3); font-weight: 500; }
.topbar .spacer { flex: 1; }
.topbar .hint { color: var(--ink-2); font-size: 13px; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 28px 24px 160px; }
.wrap.narrow { max-width: 760px; }

h1 { font-size: 28px; letter-spacing: -.03em; margin: 0 0 6px; }
h2 { font-size: 18px; letter-spacing: -.02em; margin: 32px 0 12px; }
.sub { color: var(--ink-2); margin: 0 0 24px; }

/* ---------- Фильтры ---------- */

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 20px; }
.chip {
  border: 1px solid var(--line); background: var(--surface);
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  font-size: 13px; color: var(--ink-2); transition: .12s;
}
.chip:hover { border-color: var(--ink-3); }
.chip.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.search {
  flex: 1; min-width: 200px; padding: 9px 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 14px;
}
.search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- Карточки товаров ---------- */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 10px;
  transition: box-shadow .15s, border-color .15s;
}
.card:hover { box-shadow: var(--shadow); }
.card.in-cart { border-color: var(--accent); }
.card.out { opacity: .55; }

.card .group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); }
.card .name { font-size: 17px; font-weight: 650; letter-spacing: -.02em; }
.card .title { color: var(--ink-2); font-size: 13px; flex: 1; }
.card .sku { font-size: 11px; color: var(--ink-3); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.card .price { font-size: 18px; font-weight: 600; }
.card .price small { font-weight: 400; color: var(--ink-3); font-size: 12px; }
.card .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.badge-out { font-size: 12px; color: var(--warn); }

/* ---------- Счётчик ---------- */

.counter { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); }
.counter button {
  width: 34px; height: 34px; border: 0; background: transparent; cursor: pointer;
  font-size: 17px; line-height: 1; color: var(--ink); transition: background .12s;
}
.counter button:hover:not(:disabled) { background: var(--hover); }
.counter button:disabled { color: var(--ink-3); cursor: default; }
.counter input {
  width: 46px; height: 34px; border: 0; text-align: center; font: inherit; color: var(--ink);
  font-variant-numeric: tabular-nums; background: transparent;
}
.counter input:focus { outline: none; background: var(--hover); }

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 999px; border: 1px solid var(--ink);
  background: var(--ink); color: var(--btn-fg); font: inherit; font-weight: 550; font-size: 14px;
  cursor: pointer; text-decoration: none; transition: .12s;
}
.btn:hover { opacity: .88; }
.btn:disabled { background: var(--ink-3); border-color: var(--ink-3); cursor: not-allowed; opacity: 1; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--ink); opacity: 1; }
.btn.sm { padding: 7px 14px; font-size: 13px; }
.btn[hidden] { display: none; }

/* ---------- Нижняя панель заказа ---------- */

.orderbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--bar-solid); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 24px rgba(17,17,16,.06);
}
.orderbar .inner { max-width: 1080px; margin: 0 auto; padding: 14px 24px; display: flex; align-items: center; gap: 20px; }
.orderbar .stats { flex: 1; min-width: 0; }
.orderbar .total { font-size: 22px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.orderbar .meta { font-size: 13px; color: var(--ink-2); }
.orderbar .meta b { color: var(--warn); font-weight: 600; }
.orderbar .meta b.ok { color: var(--ok); }

.progress { height: 4px; background: var(--line); border-radius: 99px; margin-top: 8px; overflow: hidden; max-width: 420px; }
.progress i { display: block; height: 100%; background: var(--warn); transition: width .25s ease; }
.progress i.ok { background: var(--ok); }

/* ---------- Формы ---------- */

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.panel + .panel { margin-top: 14px; }
.panel h3 { margin: 0 0 4px; font-size: 16px; letter-spacing: -.02em; }
.panel .note { color: var(--ink-2); font-size: 13px; margin: 0 0 18px; }
.panel.accent { background: var(--accent-tint); border-color: transparent; }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 13px; color: var(--ink-2); }
.field label .req { color: var(--err); }
.field input, .field textarea {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field .err { font-size: 12px; color: var(--err); display: none; }
.field.invalid input, .field.invalid textarea { border-color: var(--err); }
.field.invalid .err { display: block; }
.field .tip { font-size: 12px; color: var(--ink-3); }

/* ---------- Сводка заказа ---------- */

.summary { list-style: none; margin: 0; padding: 0; }
.summary li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.summary li:last-child { border-bottom: 0; }
.summary .n { flex: 1; }
.summary .n small { display: block; color: var(--ink-3); font-size: 12px; }
.summary .q { color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.summary .s { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.totals { display: flex; justify-content: space-between; padding-top: 14px; font-size: 16px; font-weight: 600; }
.totals.sub { padding-top: 6px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.totals.sub + .totals:not(.sub) { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 14px; }

.empty { text-align: center; padding: 60px 20px; color: var(--ink-2); }

/* ---------- Сообщения о состоянии ---------- */

.banner {
  border: 1px solid var(--line); border-left: 3px solid var(--warn);
  background: var(--surface); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 18px; font-size: 14px; color: var(--ink-2);
}
.banner.err { border-left-color: var(--err); color: var(--ink); }
.banner a { color: inherit; }

/* ---------- Счёт ---------- */

.invoice-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; }

.invoice {
  background: #fff; color: #000; padding: 40px 44px; border-radius: var(--radius);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  font-family: "Times New Roman", Georgia, serif; font-size: 13px; line-height: 1.35;
}
.invoice table { width: 100%; border-collapse: collapse; }
.inv-bank td { border: 1px solid #000; padding: 4px 6px; vertical-align: top; }
.inv-bank .lbl { font-size: 10px; color: #444; font-family: inherit; }
.inv-title { margin: 18px 0 6px; font-size: 20px; font-weight: bold; border-bottom: 2px solid #000; padding-bottom: 8px; }
.inv-parties { margin: 12px 0; }
.inv-parties td { padding: 3px 0; vertical-align: top; }
.inv-parties td:first-child { width: 130px; color: #444; }
.inv-items { margin-top: 14px; }
.inv-items th, .inv-items td { border: 1px solid #000; padding: 5px 6px; }
.inv-items th { background: #f0efec; font-weight: bold; font-size: 12px; }
.inv-items td.num, .inv-items th.num { text-align: right; white-space: nowrap; }
.inv-items td.c { text-align: center; }
.inv-totals { margin-top: 8px; text-align: right; }
.inv-totals div { padding: 2px 0; }
.inv-totals .grand { font-size: 15px; font-weight: bold; }
.inv-words { margin-top: 10px; padding-top: 8px; border-top: 1px solid #000; }
.inv-sign { margin-top: 40px; display: flex; gap: 60px; }
.inv-sign div { flex: 1; }
.inv-sign .line { border-bottom: 1px solid #000; height: 26px; margin-bottom: 4px; }
.inv-sign small { color: #444; }
.demo-stamp {
  margin-top: 18px; padding: 6px 10px; border: 1px dashed #999; color: #666;
  font-size: 11px; font-family: -apple-system, sans-serif; border-radius: 6px;
}


.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--toast-bg); color: var(--toast-fg); padding: 11px 20px; border-radius: 999px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  .fields { grid-template-columns: 1fr; }
  .wrap { padding: 20px 16px 170px; }
  .orderbar .inner { padding: 12px 16px; flex-wrap: wrap; }
  .invoice { padding: 20px; }
}

/* ---------- Печать / сохранение в PDF ---------- */

@page { size: A4; margin: 12mm; }

@media print {
  body { background: #fff; }
  .no-print, .topbar, .orderbar, .toast { display: none !important; }
  .wrap { padding: 0; max-width: none; }
  .invoice { border: 0; box-shadow: none; padding: 0; border-radius: 0; font-size: 11.5px; }
  .inv-items { page-break-inside: auto; }
  .inv-items tr { page-break-inside: avoid; }
}
