:root {
  --bg: #f3f5f4;
  --card: #ffffff;
  --text: #17201c;
  --muted: #5d6b65;
  --line: #d9e0dc;
  --accent: #1f6f54;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --wa: #1fa855;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614;
    --card: #1a201d;
    --text: #e6ece9;
    --muted: #9aa8a1;
    --line: #2d3632;
    --accent: #3aa57f;
    --danger: #f97066;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
.screen { max-width: 980px; margin: 0 auto; padding: 16px; }

.hero h1 { font-size: 28px; margin: 8px 0; }
.hero p { color: var(--muted); margin: 0 0 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}
.card h2 { font-size: 18px; margin: 0 0 12px; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
.opt { font-size: 12px; }

input {
  font: inherit;
  font-size: 16px; /* без автозума на iOS */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
  min-width: 0;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input.short { width: 80px; }
.hint { color: var(--danger); min-height: 0; }
.note { color: var(--muted); font-size: 13px; margin: 12px 0 0; }
.note.center { text-align: center; }

.vat-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; margin-top: 12px; }
.switch { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 16px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

.more { margin-top: 12px; }
.more summary { cursor: pointer; color: var(--accent); padding: 4px 0; }
.more .grid { margin-top: 12px; }

button {
  font: inherit;
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
  border: 1px solid transparent;
}
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.secondary { background: transparent; color: var(--accent); border-color: var(--accent); }

/* Таблица товаров на экране */
.items-head, .item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 72px 84px 110px 110px 36px;
  gap: 8px;
  align-items: center;
}
.items-head { font-size: 12px; color: var(--muted); padding: 0 0 6px; }
.item { padding: 6px 0; border-top: 1px solid var(--line); }
.item .num { color: var(--muted); text-align: center; }
.item .i-qty, .item .i-price { text-align: right; }
.item .i-sum { text-align: right; font-variant-numeric: tabular-nums; }
.item.bad .i-sum { color: var(--danger); }
.del { background: transparent; color: var(--muted); padding: 8px; }
.del:hover { color: var(--danger); }
#add-row { margin-top: 10px; }

.totals .total-line { display: flex; justify-content: space-between; padding: 4px 0; }
.totals strong { font-variant-numeric: tabular-nums; font-size: 18px; }
.words { margin: 8px 0 0; }
.words span { color: var(--muted); }
.words em { font-style: normal; }

.actions { display: flex; gap: 12px; flex-wrap: wrap; }
.actions .primary { flex: 1 1 240px; font-size: 18px; }

.promo {
  margin: 32px 0 16px;
  padding: 24px 16px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.promo h2 { margin: 0 0 8px; font-size: 20px; }
.promo p { margin: 0 0 16px; color: var(--muted); }
.wa {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--wa);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 999px;
}
.promo .company { margin: 12px 0 0; font-size: 13px; }
.foot { color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .items-head { display: none; }
  /* На телефоне строка товара — карточка в две-три строки */
  .item {
    grid-template-columns: 28px 1fr 1fr 36px;
    grid-template-areas:
      "num name name del"
      ".   qty  price ."
      ".   unit sum   .";
    row-gap: 6px;
    padding: 10px 0;
  }
  .item .num { grid-area: num; }
  .item .i-name { grid-area: name; }
  .item .i-unit { grid-area: unit; }
  .item .i-qty { grid-area: qty; }
  .item .i-price { grid-area: price; }
  .item .i-sum { grid-area: sum; align-self: center; font-weight: 600; }
  .item .del { grid-area: del; }
  .hero h1 { font-size: 24px; }
}

/* ---------- Печатная форма З-2 ---------- */
#print-area { display: none; }

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

@media print {
  html, body { background: #fff; color: #000; }
  .screen { display: none !important; }
  #print-area { display: block; }
}

.p-page {
  font-family: "Times New Roman", Times, serif;
  font-size: 10pt;
  color: #000;
  line-height: 1.25;
}
.p-page table { border-collapse: collapse; }
.p-appendix { text-align: right; font-size: 8pt; margin-left: auto; width: 60mm; }
.p-formname { text-align: right; font-size: 9pt; margin: 2mm 0 3mm; }

.p-top { display: flex; align-items: flex-end; gap: 6mm; }
.p-org { flex: 1; display: flex; gap: 3mm; align-items: flex-end; }
.p-org > span:first-child { white-space: nowrap; }
.p-line {
  display: inline-block;
  flex: 1;
  min-width: 40mm;
  border-bottom: 1px solid #000;
  padding: 0 2mm;
  font-weight: 600;
}
.p-line.p-short { min-width: 25mm; flex: 0; }
.p-bin td { border: 1px solid #000; padding: 1mm 2mm; }
.p-bin .p-bin-label { border: 0; }
.p-bin .p-bin-val { min-width: 40mm; letter-spacing: 1px; font-weight: 600; }

.p-titlerow { display: flex; justify-content: flex-end; align-items: flex-end; gap: 8mm; margin: 4mm 0; }
.p-title { font-weight: 700; font-size: 11pt; }
.p-docnum th, .p-docnum td { border: 1px solid #000; padding: 1mm 3mm; text-align: center; font-size: 8pt; }
.p-docnum td { font-size: 10pt; font-weight: 600; }

.p-parties { width: 100%; margin-bottom: 4mm; }
.p-parties th, .p-parties td { border: 1px solid #000; padding: 1mm 2mm; width: 20%; vertical-align: top; }
.p-parties th { font-weight: 400; font-size: 8pt; text-align: center; }

.p-items { width: 100%; }
.p-items th, .p-items td { border: 1px solid #000; padding: 1mm 1.5mm; vertical-align: top; }
.p-items th { font-weight: 400; font-size: 8pt; text-align: center; vertical-align: middle; }
.p-items .p-colnums td { text-align: center; font-size: 8pt; padding: 0.5mm; }
.p-items .w-num { width: 12mm; }
.p-items .w-nom { width: 22mm; }
.p-items .w-unit { width: 18mm; }
.p-items .w-qty { width: 20mm; }
.p-items .w-money { width: 27mm; }
.p-items .c { text-align: center; }
.p-items .r { text-align: right; white-space: nowrap; }
.p-items .p-x { text-align: center; }
.p-items tr { page-break-inside: avoid; }
.p-items thead { display: table-header-group; }

.p-words { margin: 4mm 0; display: grid; gap: 2mm; }
.p-words > div { display: flex; gap: 3mm; align-items: flex-end; }
.p-words > div > :first-child { white-space: nowrap; }

.p-signs { display: grid; grid-template-columns: 1fr 1fr; gap: 10mm; page-break-inside: avoid; }
.p-col { display: grid; gap: 4mm; align-content: start; }
.p-sign { display: flex; align-items: flex-start; gap: 2mm; }
.p-sign-label { white-space: nowrap; width: 32mm; padding-top: 1mm; }
.p-cell { flex: 1; display: flex; flex-direction: column; }
.p-cell.p-short { flex: 0 0 25mm; }
.p-val { border-bottom: 1px solid #000; min-height: 5mm; padding: 0 1mm; font-weight: 600; }
.p-cap { font-size: 7pt; text-align: center; }
.p-mp { padding-left: 34mm; }
.p-poa { display: flex; gap: 2mm; align-items: flex-end; white-space: nowrap; }
