:root {
  --paper: #F6F4EF; --card: #FFFFFF; --navy: #1F3A5F; --navy-2: #2B4C78; --gold: #D9A441;
  --ink: #16202E; --sub: #5E6878; --line: #E3E0D8; --bad: #C0392B; --bad-bg: #FBEDEB; --ok: #1E7A4C; --ok-bg: #E9F5EE;
  --radius: 16px; --shadow: 0 1px 2px rgba(31,58,95,.06), 0 8px 24px rgba(31,58,95,.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--font); }
a { color: var(--navy); }
img { max-width: 100%; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; background: #fff; padding: 8px 12px; z-index: 10; }
.muted { color: var(--sub); }
.small { font-size: 13px; }

/* Header */
.top { position: sticky; top: 0; z-index: 20; background: rgba(246,244,239,.9); backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--line); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 64px; }
.brand { flex: none; }
.top nav { min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; }
.brand img { border-radius: 8px; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--sub); line-height: 1; }
.brand span { line-height: 1.15; }
.top nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.top nav a { text-decoration: none; color: var(--sub); padding: 8px 12px; border-radius: 999px; white-space: nowrap; font-size: 15px; }
.top nav a:hover, .top nav a[aria-current] { color: var(--navy); background: #fff; }

/* Hero */
.hero { padding: 40px 20px 20px; }
.hero h1 { font-size: clamp(30px, 4.4vw, 48px); line-height: 1.08; letter-spacing: -.02em; margin: 12px 0 14px; color: var(--navy); max-width: 900px; }
.lead { font-size: clamp(17px, 1.6vw, 20px); color: #3A4658; max-width: 780px; margin: 0; }
.badge { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 6px 12px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-size: 13px; color: var(--navy); font-weight: 600; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.hero-pts { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 16px; color: var(--sub); font-size: 15px; }

/* Generator layout */
.gen { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 24px; align-items: start; padding: 16px 0 40px; }
.gen-form { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.side-sticky { position: sticky; top: 80px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card-h { font-size: 18px; font-weight: 700; margin: 0 0 4px; color: var(--navy); cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary.card-h::after { content: "–"; float: right; color: var(--sub); }
details:not([open]) > summary.card-h::after { content: "+"; }
details[open] > summary { margin-bottom: 14px; }

.kinds { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin-top: 12px; }
.kind { display: flex; gap: 10px; align-items: flex-start; text-align: left; border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 12px; cursor: pointer; font: inherit; color: var(--ink); transition: border-color .15s, background .15s; }
.kind b { display: block; font-size: 15px; }
.kind small { color: var(--sub); font-size: 12.5px; }
.kind-dot { flex: none; width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--k); margin-top: 1px; position: relative; }
.kind.on { border-color: var(--k); background: color-mix(in srgb, var(--k) 7%, #fff); }
.kind.on .kind-dot { background: var(--k); }
.kind.on .kind-dot::after { content: ""; position: absolute; left: 5px; top: 1px; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.span2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; margin: 0; }
.field > span { font-size: 13px; color: var(--sub); font-weight: 600; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--ink); background: #FBFAF7; border: 1px solid #D9D5CB; border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0; }
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--navy) 35%, transparent); border-color: var(--navy); background: #fff; }
.field.bad input, .field.bad select { border-color: var(--bad); background: var(--bad-bg); }
.hint { color: var(--bad); font-size: 12.5px; min-height: 0; display: block; }
.hint:empty { display: none; }
.hint::before { content: "↳ "; }
.check { display: flex; gap: 10px; align-items: center; font-size: 15px; cursor: pointer; margin: 6px 0; }
.check input { width: 20px; height: 20px; accent-color: var(--navy); }
.inline { display: flex; gap: 8px; }
.clause { background: #F1EFEA; border-radius: 10px; padding: 12px 14px; font-size: 13.5px; color: #3A4658; margin: 4px 0 10px; }
.row-btns { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 14px; }
.row-btns.end { justify-content: flex-end; }
.thumb img { height: 34px; border-radius: 6px; border: 1px solid var(--line); background: #fff; vertical-align: middle; }
.thumb.sig img { height: 30px; }
.thumb:empty + .link { display: none; }

/* Items */
.items-head, .item { display: grid; grid-template-columns: minmax(0, 1fr) 80px 70px 100px 70px 104px 30px; gap: 8px; align-items: center; }
body:not(.vat) .items-head, body:not(.vat) .item { grid-template-columns: minmax(0, 1fr) 80px 70px 110px 104px 30px; }
body:not(.vat) .vat-only { display: none; }
.items-head { font-size: 12px; color: var(--sub); font-weight: 600; padding: 0 2px 6px; }
.item { margin-bottom: 8px; }
.i-sum { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px; }
.i-del { border: 0; background: none; font-size: 22px; color: #9AA2AE; cursor: pointer; }
.i-del:hover { color: var(--bad); }
.sum-box { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 6px 20px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.sum-box strong { font-size: 22px; color: var(--navy); margin-left: 10px; }

/* Conditional sections by selected kinds */
.export-only, .waybill-only, .invoice-only, .period-only, .act-only { display: none; }
body[data-kinds~="export"] .export-only { display: grid; margin-top: 14px; }
body[data-kinds~="waybill"] .waybill-only { display: grid; margin-top: 14px; }
body[data-kinds~="invoice"] .invoice-only { display: block; margin-top: 14px; }
body[data-kinds~="act"] .period-only, body[data-kinds~="act"] .act-only { display: grid; margin-top: 14px; }
.invoice-only .clause, .invoice-only .exc { display: none; }
body.replaces .invoice-only .clause, body.replaces .invoice-only .exc { display: block; }
body.replaces[data-kinds~="invoice"] .period-only { display: grid; margin-top: 14px; }
body:not([data-kinds~="act"]) .act-only { display: none !important; }

/* Side */
.banner { border-radius: 14px; padding: 12px 14px; font-size: 14px; }
.banner.bad { background: var(--bad-bg); color: #7A2217; border: 1px solid #F1C9C3; }
.banner.ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #C6E6D3; }
.banner.warn { background: #FFF6E5; color: #7A5A12; border: 1px solid #F0DDB3; }
.banner ul { margin: 8px 0 0; padding-left: 18px; }
.banner li { margin: 3px 0; }
.banner li a { color: inherit; }
.banner li span { color: #A0615A; font-size: 12px; }
.preview-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.preview-tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); align-items: center; flex-wrap: wrap; }
.preview-tabs button { border: 0; background: #F1EFEA; border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; color: var(--sub); }
.preview-tabs button.on { background: var(--navy); color: #fff; }
.preview-tabs a { margin-left: auto; }
#hb-preview { width: 100%; height: 520px; border: 0; display: block; background: #EDEBE6; }
.actions { display: flex; flex-direction: column; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 700; font-size: 16px; border-radius: 12px; padding: 13px 18px; cursor: pointer; text-decoration: none; border: 1.5px solid transparent; }
.btn.primary { background: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.ghost { background: #fff; color: var(--navy); border-color: #CFD6E0; }
.btn.sm { font-size: 14px; padding: 8px 12px; font-weight: 600; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--navy); font: inherit; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.link.sm { font-size: 13.5px; }
.data-tools { padding: 0 4px; }

/* Content */
.article { padding: 24px 20px 48px; max-width: 860px; }
.article h2 { color: var(--navy); font-size: 24px; margin: 28px 0 10px; }
.article li { margin: 4px 0; }
.steps { padding-left: 20px; }
.ticks { list-style: none; padding: 0; }
.ticks li { padding-left: 26px; position: relative; }
.ticks li::before { content: "✓"; position: absolute; left: 0; color: var(--gold); font-weight: 800; }
.qa { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; margin: 8px 0; }
.qa summary { font-weight: 600; cursor: pointer; }
.strip { padding: 20px 20px 8px; }
.strip h2 { color: var(--navy); margin: 0 0 4px; }
.sample-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-top: 14px; }
.sample { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; background: #fff; border: 1px solid var(--line); border-radius: 14px; text-decoration: none; color: var(--ink); transition: transform .15s, box-shadow .15s; }
.sample:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.sample b { color: var(--navy); }
.sample small { color: var(--gold); font-weight: 700; font-size: 12.5px; }
.sample span { color: var(--sub); font-size: 14px; }
.sample-grid.big { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); padding-bottom: 32px; }
.tool { max-width: 720px; display: flex; flex-direction: column; gap: 12px; }
.tool-out { font-size: 16px; padding: 12px 14px; border-radius: 10px; background: #F7F5F0; margin: 0; }
.tool-out.big { font-size: 20px; font-weight: 600; color: var(--navy); }
.tool-out.ok { background: var(--ok-bg); color: var(--ok); }
.tool-out.bad { background: var(--bad-bg); color: var(--bad); }
.tool-out.warn { background: #FFF6E5; color: #7A5A12; }
.tool-out:empty { display: none; }
.qr-out svg { width: 220px; height: 220px; background: #fff; border-radius: 12px; }

/* Footer */
.foot { border-top: 1px solid var(--line); padding: 32px 0 24px; background: #F1EFEA; }
.foot-in { display: grid; grid-template-columns: 1.2fr 2fr; gap: 32px; margin-bottom: 16px; }
.foot-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.foot-cols div { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.foot-cols a { color: var(--sub); text-decoration: none; }
.foot-cols a:hover { color: var(--navy); }

/* Dialogs & toast */
.dlg { border: 0; border-radius: 20px; padding: 22px; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(22,32,46,.45); }
.dlg h3 { margin: 0 0 4px; color: var(--navy); }
#hb-sign-canvas { width: 100%; height: auto; aspect-ratio: 5 / 2; background: #FBFAF7; border: 1.5px dashed #CFC9BC; border-radius: 12px; touch-action: none; }
.upsell { text-align: left; }
.upsell img { border-radius: 14px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 220%); visibility: hidden; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; max-width: min(520px, calc(100vw - 32px)); font-size: 14.5px; transition: transform .25s; z-index: 50; }
.toast.show { transform: translate(-50%, 0); visibility: visible; }

@media (max-width: 980px) {
  .gen { grid-template-columns: 1fr; }
  .side-sticky { position: static; }
  #hb-preview { height: 420px; }
  .actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; border-radius: 18px 18px 0 0; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1.45fr 1fr; gap: 8px; box-shadow: 0 -8px 30px rgba(31,58,95,.14); }
  .actions > .muted.small:first-child { grid-column: 1 / -1; text-align: center; }
  .actions > p { display: none; }
  .actions .btn { font-size: 13.5px; padding: 12px 6px; white-space: nowrap; }
  body:has(#hb-app) { padding-bottom: 130px; }
  .toast { bottom: 140px; }
  .foot-in { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .wrap { padding: 0 14px; }
  .hero { padding: 24px 14px 8px; }
  .top nav a { padding: 6px 9px; font-size: 14px; }
  .brand small { display: none; }
  .brand span { display: none; }
  .top-in { gap: 10px; }
  .grid2 { grid-template-columns: 1fr; }
  .card { padding: 14px; }
  .items-head { display: none; }
  .item, body:not(.vat) .item { grid-template-columns: 1fr 1fr 1fr 30px; background: #FBFAF7; border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
  .i-name { grid-column: 1 / -1; }
  .i-sum { grid-column: 1 / -2; text-align: left; }
  .foot-cols { grid-template-columns: 1fr 1fr; }
  #hb-preview { height: 360px; }
}

@media (max-width: 640px) { .hide-sm { display: none; } }
