/* ============================================================
   Export Docs — proforma invoice + packing list generator
   Single page. No external fonts, no frameworks, no network.
   ============================================================ */

:root {
  --ink: #101a26;
  --ink-2: #38485a;
  --muted: #5f6d7c;
  --line: #e2e7ee;
  --line-2: #cfd7e2;
  --bg: #f4f6f9;
  --card: #ffffff;
  --accent: #0b62d6;
  --accent-dk: #08489c;
  --accent-soft: #eaf1fd;
  --warn: #b3261e;
  --ok: #0d6b46;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px;
  min-width: 0;
}

/* ---------- header ---------- */
.site-head {
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.head-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}
.brand-mark {
  width: 20px; height: 20px;
  border-radius: 5px;
  background: var(--accent);
  position: relative;
  flex: none;
}
.brand-mark::after {
  content: "";
  position: absolute;
  left: 4px; right: 4px; top: 6px;
  height: 2px;
  background: #fff;
  box-shadow: 0 4px 0 #fff, 0 8px 0 rgba(255,255,255,.55);
}
.head-note {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- hero ---------- */
.hero { padding: 42px 20px 26px; }
.hero h1 {
  margin: 0 0 14px;
  font-size: clamp(26px, 3.4vw, 38px);
  line-height: 1.12;
  letter-spacing: -0.022em;
  max-width: 20ch;
}
.lede {
  margin: 0 0 18px;
  max-width: 72ch;
  font-size: 16px;
  color: var(--ink-2);
}
.lede strong { color: var(--ink); font-weight: 650; }
.trust {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.trust li {
  font-size: 12.5px;
  color: var(--ok);
  background: #eaf6f0;
  border: 1px solid #cbe7da;
  border-radius: 999px;
  padding: 4px 11px;
}
.hero-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}
.linkish {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.linkish:hover { color: var(--accent-dk); }

/* ---------- tool layout ---------- */
.tool {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
  padding-bottom: 34px;
}
.tool > * { min-width: 0; }

.form-pane {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px 18px 18px;
}

/* fieldset */
.fs {
  border: 0;
  border-bottom: 1px solid var(--line);
  margin: 0;
  padding: 16px 0 18px;
}
.fs:last-of-type { border-bottom: 0; }
.fs legend {
  padding: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .01em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}
.fs-n {
  display: inline-grid;
  place-items: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dk);
  font-size: 11px;
  font-weight: 700;
}
.legend-hint {
  font-style: normal;
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
  margin-left: 4px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}
.grid > * { min-width: 0; }
.span-2 { grid-column: span 2; }

.field { display: block; min-width: 0; }
.lab {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 5px;
}
.req, .opt, .hint {
  font-style: normal;
  font-weight: 500;
  font-size: 11px;
  letter-spacing: .01em;
  margin-left: 5px;
}
.req { color: var(--accent); }
.opt { color: #8a97a6; }
.hint { color: #8a97a6; font-weight: 400; }

input[type="text"],
input[type="date"],
textarea,
select {
  width: 100%;
  min-width: 0;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fcfdfe;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  padding: 8px 10px;
  line-height: 1.4;
  transition: border-color .12s, box-shadow .12s, background .12s;
}
textarea { resize: vertical; line-height: 1.45; }
select { appearance: none; background-image: none; cursor: pointer; }
input:focus, textarea:focus, select:focus {
  outline: 0;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(11, 98, 214, .13);
}
.invalid input, .invalid textarea, .invalid select,
input.invalid, textarea.invalid {
  border-color: var(--warn);
  background: #fff8f7;
}
.err {
  display: none;
  font-size: 11.5px;
  color: var(--warn);
  margin-top: 4px;
}
.err.on { display: block; }

/* ---------- line items ---------- */
.items { display: grid; gap: 10px; margin-top: 12px; }
.item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfe;
  padding: 10px 11px 11px;
  position: relative;
}
.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.item-idx {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.item-del {
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--muted);
  border-radius: 6px;
  font-size: 11.5px;
  padding: 3px 8px;
  cursor: pointer;
  font-family: inherit;
}
.item-del:hover { color: var(--warn); border-color: #e8c3bf; background: #fff8f7; }
.item-del:disabled { opacity: .4; cursor: not-allowed; }

.item-row {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.item-row > * { min-width: 0; }
.r-desc { grid-template-columns: minmax(0, 1fr) 118px; }
.r-money { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); }
.r-pack { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); }
.r-dims { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); }

.mini {
  display: block;
  min-width: 0;
}
.mini > span:first-child {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mini input { padding: 6px 8px; font-size: 13.5px; }
.ro {
  display: block;
  padding: 6px 8px;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  background: #f1f4f8;
  border: 1px dashed var(--line-2);
  border-radius: 7px;
  color: var(--ink-2);
  text-align: right;
  min-height: 32px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.add {
  margin-top: 10px;
  width: 100%;
}
.btn {
  font-family: inherit;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border: 1px solid transparent;
  transition: background .12s, border-color .12s, color .12s;
}
.btn-ghost {
  background: #fff;
  border-color: var(--line-2);
  color: var(--ink-2);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-dk); background: var(--accent-soft); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  padding: 13px 16px;
  font-size: 15px;
}
.btn-primary:hover { background: var(--accent-dk); }

/* ---------- totals ---------- */
.totals {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
  padding: 11px;
  background: #f1f5fb;
  border: 1px solid #dde6f3;
  border-radius: 9px;
}
.tot { min-width: 0; }
.tot-k {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tot-v {
  display: block;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- actions ---------- */
.actions {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.picker-lab {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}
.chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
}
.chk input { width: 15px; height: 15px; accent-color: var(--accent); }
.actions-note {
  margin: 9px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.warn-none {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--warn);
  background: #fff5f4;
  border: 1px solid #f0cfcb;
  border-radius: 7px;
  padding: 8px 10px;
}

/* ---------- preview ---------- */
.preview-pane {
  position: sticky;
  top: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: #fafbfd;
}
.tabs { display: flex; gap: 4px; min-width: 0; flex-wrap: wrap; }
.tab {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--accent-dk); }
.tab.is-on {
  background: #fff;
  color: var(--ink);
  border-color: var(--line-2);
  box-shadow: 0 1px 2px rgba(16,26,38,.06);
}
.zoom {
  font-size: 11px;
  color: #94a1b0;
  font-variant-numeric: tabular-nums;
  flex: none;
}
.preview-stage {
  --scale: 1;
  position: relative;
  padding: 12px;
  background: #eceff4;
  overflow: hidden;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
}

#docPrint { transform-origin: top left; }

/* ============================================================
   THE DOCUMENT SHEET  (shared by preview + print)
   210mm wide, A4 proportions. Everything below is print-true.
   ============================================================ */
.sheet {
  width: 210mm;
  min-height: 276mm;
  padding: 13mm 14mm 12mm;
  background: #fff;
  color: #101820;
  font-family: var(--font);
  font-size: 10pt;
  line-height: 1.38;
  box-shadow: 0 3px 14px rgba(16,26,38,.14);
  margin: 0 auto 12px;
  transform: scale(var(--scale));
  transform-origin: top left;
  display: flex;
  flex-direction: column;
}
.sheet:last-child { margin-bottom: 0; }
.sheet.screen-hidden { display: none; }

.sheet-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10mm;
  padding-bottom: 3mm;
  border-bottom: 1.6pt solid #101820;
}
.sheet-title {
  font-size: 17pt;
  font-weight: 800;
  letter-spacing: .06em;
  line-height: 1.05;
  text-transform: uppercase;
}
.sheet-sub {
  margin-top: 1.6mm;
  font-size: 7.6pt;
  color: #5a6773;
  letter-spacing: .02em;
}
.sheet-meta {
  text-align: right;
  font-size: 8.4pt;
  flex: none;
  min-width: 62mm;
}
.sheet-meta dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.2mm 3mm;
}
.sheet-meta dt { color: #5a6773; }
.sheet-meta dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }

.party-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4mm;
  margin-top: 4mm;
}
.party {
  border: 0.5pt solid #c9d2dc;
  border-radius: 1mm;
  padding: 2.4mm 2.8mm;
  min-height: 20mm;
  min-width: 0;
}
.party-role {
  font-size: 6.8pt;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: #6b7885;
  margin-bottom: 1.2mm;
}
.party-body {
  font-size: 8.6pt;
  line-height: 1.42;
  white-space: pre-line;
  word-break: break-word;
}
.party-body .empty { color: #a4aeb9; font-style: italic; }

.terms-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2.5mm 4mm;
  margin-top: 4mm;
  padding: 2.6mm 2.8mm;
  background: #f4f6f9;
  border-radius: 1mm;
}
.terms-row > div { min-width: 0; }
.terms-k {
  font-size: 6.8pt;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: #6b7885;
}
.terms-v {
  font-size: 8.6pt;
  font-weight: 600;
  word-break: break-word;
}
.terms-row .wide { grid-column: span 2; }

.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4.5mm;
  font-size: 8.4pt;
  table-layout: fixed;
}
.doc-table th {
  background: #eef1f5;
  border-top: 0.9pt solid #101820;
  border-bottom: 0.5pt solid #101820;
  padding: 1.8mm 1.4mm;
  font-size: 7pt;
  letter-spacing: .05em;
  text-transform: uppercase;
  text-align: left;
  color: #26313d;
  font-weight: 700;
}
.doc-table td {
  border-bottom: 0.4pt solid #d8dee6;
  padding: 1.7mm 1.4mm;
  vertical-align: top;
  word-break: break-word;
}
.doc-table tr { break-inside: avoid; }
.doc-table .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-table .c { text-align: center; }
.doc-table .idx { width: 7mm; color: #6b7885; }
.doc-table tfoot td {
  border-top: 0.9pt solid #101820;
  border-bottom: 0.9pt solid #101820;
  font-weight: 700;
  padding: 2mm 1.4mm;
}
.doc-table tfoot .lbl {
  text-align: right;
  font-size: 7.4pt;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.words {
  margin-top: 3.5mm;
  font-size: 8.4pt;
  border: 0.5pt solid #c9d2dc;
  border-radius: 1mm;
  padding: 2.2mm 2.8mm;
  background: #fafbfd;
}
.words b { letter-spacing: .02em; }

.remarks-block {
  margin-top: 4mm;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3mm;
}
.rbox {
  border: 0.5pt solid #c9d2dc;
  border-radius: 1mm;
  padding: 2.4mm 2.8mm;
  min-height: 15mm;
  min-width: 0;
}
.rbox .party-role { margin-bottom: 1mm; }
.rbox-body { font-size: 8.2pt; white-space: pre-line; word-break: break-word; line-height: 1.42; }

.sheet-foot {
  margin-top: auto;
  padding-top: 6mm;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8mm;
}
.sign {
  width: 62mm;
  text-align: center;
  font-size: 8pt;
}
.sign-line {
  border-bottom: 0.6pt solid #101820;
  height: 12mm;
}
.sign-cap {
  padding-top: 1.4mm;
  color: #4a5764;
  line-height: 1.4;
}
.sign-cap b { display: block; color: #101820; }
.doc-note {
  font-size: 7pt;
  color: #6b7885;
  max-width: 78mm;
  line-height: 1.45;
  text-align: left;
}

/* ---------- content bands ---------- */
.band {
  padding: 30px 20px 6px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
}
.band h2 {
  margin: 0 0 14px;
  font-size: 21px;
  letter-spacing: -0.015em;
}
.band-lede {
  margin: 0 0 16px;
  max-width: 76ch;
  color: var(--ink-2);
  font-size: 14.5px;
}
.band-note {
  margin: 14px 0 0;
  max-width: 76ch;
  font-size: 13.5px;
  color: var(--muted);
}

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.steps > li {
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 16px 17px 18px;
}
.step-n {
  display: inline-grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  margin-bottom: 9px;
}
.steps h3 { margin: 0 0 5px; font-size: 14.5px; }
.steps p { margin: 0; font-size: 13.5px; color: var(--muted); }

.tablewrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  -webkit-overflow-scrolling: touch;
}
.cmp {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 620px;
}
.cmp th, .cmp td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.cmp thead th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  background: #f7f9fc;
  font-weight: 700;
}
.cmp tbody th {
  font-weight: 600;
  color: var(--ink-2);
  background: #fbfcfe;
}
.cmp tbody tr:last-child th, .cmp tbody tr:last-child td { border-bottom: 0; }
.cmp .hi { background: #f2f7ff; color: var(--accent-dk); font-weight: 650; }
.cmp thead .hi { background: #e6effd; }

.faq-item {
  border-top: 1px solid var(--line);
  padding: 16px 0;
  max-width: 82ch;
}
.faq-item:first-of-type { border-top: 0; padding-top: 0; }
.faq-item h3 { margin: 0 0 7px; font-size: 15.5px; letter-spacing: -0.005em; }
.faq-item p { margin: 0; font-size: 14px; color: var(--ink-2); }
.faq-item strong { color: var(--ink); }

/* ---------- footer ---------- */
.site-foot {
  margin-top: 26px;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 22px 0 30px;
}
.site-foot p { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.site-foot .fine { font-size: 11.5px; line-height: 1.6; max-width: 88ch; color: #7b8794; }

/* ---------- mobile action bar ---------- */
.mobile-bar { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .tool { grid-template-columns: minmax(0, 1fr); }
  .preview-pane { position: static; }
  .preview-stage { max-height: none; }
}
@media (max-width: 760px) {
  body { font-size: 14.5px; padding-bottom: 76px; }
  .wrap { padding: 0 14px; }
  .hero { padding: 28px 14px 20px; }
  .hero h1 { max-width: none; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .form-pane { padding: 4px 13px 14px; }
  .fs legend { flex-wrap: wrap; row-gap: 3px; }
  .legend-hint { flex: 1 1 100%; margin-left: 0; }
  .item-row { grid-template-columns: minmax(0, 1fr); }
  .r-desc { grid-template-columns: minmax(0, 1fr); }
  .r-money, .r-pack { grid-template-columns: 1fr 1fr; }
  .r-dims { grid-template-columns: 1fr 1fr; }
  .totals { grid-template-columns: 1fr 1fr; }
  .steps { grid-template-columns: minmax(0, 1fr); }
  .tab { font-size: 12px; padding: 5px 7px; }
  .preview-stage { padding: 8px; }
  .head-note { display: none; }
  .mobile-bar {
    display: grid;
    grid-template-columns: minmax(0, 0.42fr) minmax(0, 1fr);
    gap: 8px;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    padding: 9px 14px calc(9px + env(safe-area-inset-bottom, 0px));
    background: rgba(255,255,255,.97);
    border-top: 1px solid var(--line);
    box-shadow: 0 -2px 14px rgba(16,26,38,.09);
    z-index: 60;
  }
  .mobile-bar .btn { width: 100%; padding: 11px 10px; font-size: 14px; }
}

/* ============================================================
   PRINT — the only thing that matters for output fidelity
   ============================================================ */
@page {
  size: A4;
  margin: 0;
}

@media print {
  html, body {
    background: #fff !important;
    font-size: 10pt;
  }
  .no-print { display: none !important; }

  .wrap { padding: 0 !important; max-width: none !important; }
  .tool { display: block !important; padding: 0 !important; gap: 0 !important; margin: 0 !important; }
  main, .band { margin: 0 !important; padding: 0 !important; border: 0 !important; }

  .preview-pane {
    position: static !important;
    border: 0 !important;
    border-radius: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }
  .preview-stage {
    padding: 0 !important;
    background: #fff !important;
    overflow: visible !important;
    max-height: none !important;
    height: auto !important;
  }
  #docPrint { transform: none !important; height: auto !important; }

  .sheet {
    transform: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    width: 210mm !important;
    min-height: 276mm !important;
    padding: 13mm 14mm 12mm !important;
    break-before: page;
    page-break-before: always;
  }
  .sheet:first-child { break-before: auto; page-break-before: auto; }
  .sheet.screen-hidden { display: flex !important; }
  .sheet.print-skip { display: none !important; }

  .doc-table { break-inside: auto; }
  .doc-table thead { display: table-header-group; }
  .doc-table tr, .party, .rbox, .words, .terms-row { break-inside: avoid; }

  a[href]::after { content: ""; }
}
