*, *::before, *::after { box-sizing: border-box; }
.inv-page { max-width: 900px; margin: 1.5rem auto 3rem; padding: 0 16px; }
.inv-page img, .inv-page table { max-width: 100%; }
.tool-banner { background: var(--surface, #fff); border: 1.5px solid var(--ink-2, #555); border-radius: 12px; padding: 1.1rem; margin-bottom: 1.25rem; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; }
.tool-banner h1 { margin: .25rem 0; font-size: clamp(1.25rem, 5vw, 1.75rem); line-height: 1.2; }
.tool-banner p { margin: 0; color: var(--ink-2, #555); font-size: .95rem; }
.banner-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.banner-actions .btn { min-height: 46px; padding: 0 18px; flex: 1 1 150px; text-align: center; }
.panel { background: var(--surface, #fff); border: 1px solid var(--line, #ddd); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }
.panel h2 { margin: 0 0 .5rem; font-size: 1.05rem; }
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem 1rem; align-items: end; }
.opts label { display: block; font-size: .85rem; font-weight: 600; }
.opts select, .opts input[type=text], .opts input[type=number] { width: 100%; min-height: 44px; margin-top: .25rem; font: inherit; padding: .4rem .5rem; border-radius: 6px; border: 1px solid var(--line, #bbb); background: var(--bg, #fff); color: var(--ink, #111); }
.check-row { display: flex; align-items: center; gap: .6rem; min-height: 44px; font-weight: 600; font-size: .95rem; }
.check-row input { width: 22px; height: 22px; flex: none; }
.hint { font-size: .8rem; color: var(--ink-2, #555); margin: .35rem 0 0; }
.missing { margin: 0; padding-left: 1.1rem; font-size: .9rem; }
.missing.ok { list-style: none; padding: 0; color: var(--ok, #15803d); font-weight: 600; }
.msg { color: #b91c1c; font-size: .85rem; font-weight: 600; margin: .25rem 0 0; min-height: 0; }
.msg:empty { margin: 0; }
.msg.plain { color: inherit; }
.check-label { margin: 0; font-size: inherit; }
.crumbs-wrap { margin-top: 1.5rem; }
.c-amt-head { text-align: right; }
.hint.tight { margin: 0; }
.pv { display: none; }
.print-warning { display: none; }
html[data-theme="dark"] .panel .msg { color: #fca5a5; }

/* the paper stays white so it prints the same in light and dark mode */
.invoice-paper { background: #fff; color: #0f172a; border-radius: 12px; padding: clamp(1rem, 4vw, 2.25rem); box-shadow: 0 4px 20px rgba(0,0,0,.08); border: 1px solid #e2e8f0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.invoice-paper input, .invoice-paper textarea { width: 100%; font: inherit; font-size: .95rem; color: #0f172a; background: #fff; border: 1px solid #cbd5e1; border-radius: 4px; padding: .45rem .5rem; min-height: 40px; }
.invoice-paper textarea { resize: vertical; display: block; }
.invoice-paper input::placeholder, .invoice-paper textarea::placeholder { color: #5f6f85; opacity: 1; }
.invoice-paper input:focus-visible, .invoice-paper textarea:focus-visible, .invoice-paper .btn-small:focus-visible { outline: 3px solid #1d4ed8; outline-offset: 1px; }
.invoice-paper input[aria-invalid="true"] { border-color: #b91c1c; box-shadow: 0 0 0 1px #b91c1c; }
.invoice-paper label { display: block; font-size: .85rem; color: #475569; margin: 0 0 .15rem; }
.field { margin-bottom: .6rem; }
.inv-top { display: grid; grid-template-columns: 1fr; gap: 1.25rem; border-bottom: 2px solid #e2e8f0; padding-bottom: 1.25rem; margin-bottom: 1.25rem; }
.inv-title { font-size: 1.8rem; margin: 0 0 .5rem; color: #1d4ed8; letter-spacing: .02em; }
.meta-grid { display: grid; grid-template-columns: 1fr; gap: .5rem; }
.parties { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-bottom: 1rem; }
.parties h3, .pay h3 { font-size: .8rem; text-transform: uppercase; color: #64748b; margin: 0 0 .4rem; letter-spacing: .5px; }
.lines-head { display: none; }
.line { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; padding: .75rem 0; border-bottom: 1px solid #e2e8f0; align-items: end; }
.line .c-desc { grid-column: 1 / -1; }
.line .c-total { text-align: right; font-weight: 700; align-self: center; }
.line .c-total .lbl { display: inline; font-size: .78rem; color: #64748b; font-weight: 400; margin-right: .4rem; }
.line .c-del { grid-column: 1 / -1; }
.line .msg { grid-column: 1 / -1; margin: 0; }
.btn-small { font: inherit; font-size: .85rem; min-height: 40px; padding: 0 .9rem; border-radius: 999px; border: 1.5px solid #94a3b8; background: #fff; color: #0f172a; cursor: pointer; }
.btn-small { white-space: nowrap; transition: background-color .15s, border-color .15s; }
.btn-small:hover:not([disabled]) { background: #f1f5f9; border-color: #475569; }
.btn-small:active:not([disabled]) { background: #e2e8f0; }
.btn-small[disabled] { color: #64748b; border-color: #cbd5e1; border-style: dashed; cursor: not-allowed; }
.btn-add { margin-top: .75rem; }
.totals { display: grid; grid-template-columns: 1fr; gap: 1.25rem; margin-top: 1.5rem; }
.totals > div:last-child { order: -1; }
.sum-row { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; font-size: .95rem; }
.sum-row.grand { border-top: 2px solid #0f172a; margin-top: .4rem; padding-top: .5rem; font-weight: 800; font-size: 1.2rem; color: #1d4ed8; }
.pay-terms-note { margin-top: .5rem; }
.cross-sell { margin-top: 2rem; background: var(--surface, #fff); border: 2px solid var(--accent, #2563eb); border-radius: 12px; padding: 1.1rem; }
.cross-sell h2 { margin: 0 0 .4rem; font-size: 1.15rem; }
.cross-sell .cs-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-top: .75rem; }
.cs-item { border: 1px solid var(--line, #ddd); border-radius: 10px; padding: .85rem; display: flex; flex-direction: column; gap: .5rem; min-width: 0; }
.cs-item h3 { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.cs-item p { margin: 0; font-size: .88rem; color: var(--ink-2, #555); overflow-wrap: anywhere; }
.cs-item .btn { min-height: 44px; padding: 0 16px; font-size: .92rem; text-align: center; margin-top: auto; }
.disclaimer { font-size: .85rem; color: var(--ink-2, #555); margin-top: 1rem; }
.print-only { display: none; }
@media (min-width: 640px) {
  .inv-top { grid-template-columns: 1fr minmax(220px, 300px); }
  .parties { grid-template-columns: 1fr 1fr; }
  .totals > div:last-child { order: 0; }
  .line label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; margin: 0; }
  .line .c-desc, .line .c-qty, .line .c-price { position: relative; }
  .lines-head { display: grid; grid-template-columns: 5fr 1.2fr 1.8fr 1.8fr 112px; gap: .5rem; padding: .6rem 0; border-bottom: 1px solid #e2e8f0; font-size: .78rem; text-transform: uppercase; color: #475569; }
  .line { grid-template-columns: 5fr 1.2fr 1.8fr 1.8fr 112px; align-items: center; }
  .line .c-desc { grid-column: auto; }
  .line .c-del { grid-column: auto; }
  .line .c-total .lbl { display: none; }
  .totals { grid-template-columns: 1fr minmax(240px, 320px); }
  .cross-sell .cs-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 380px) {
  .invoice-paper { padding: .75rem; }
  .line { grid-template-columns: 1fr 2fr; }
  .line .c-total { text-align: left; }
}
@media print {
  @page { size: A4; margin: 14mm; }
  html, body { background: #fff !important; }
  .site-header, .site-footer, .skip, .crumbs-wrap, .tool-banner, .panel, .cross-sell, .disclaimer.screen, .btn-small, .btn-add, .msg, .lines-head .c-act { display: none !important; }
  .inv-page { max-width: 100%; margin: 0; padding: 0; }
  .invoice-paper { box-shadow: none; border: none; padding: 0; border-radius: 0; }
  .invoice-paper input, .invoice-paper textarea { display: none !important; }
  .pv { display: block; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; font-size: .95rem; padding: .1rem 0; min-width: 0; }
  .line label, .line .c-total .lbl { display: none; }
  .line > div { min-width: 0; }
  .line { align-items: start; }
  body.has-errors .print-warning { display: block; border: 2px solid #b91c1c; color: #b91c1c; padding: .5rem .75rem; margin-bottom: 1rem; font-weight: 600; }
  .field.is-empty, .print-hide-empty.is-empty { display: none !important; }
  .line .c-del { display: none !important; }
  .lines-head { display: grid; grid-template-columns: 5fr 1.2fr 1.8fr 1.8fr; }
  .lines-head .c-act { display: none !important; }
  .line { grid-template-columns: 5fr 1.2fr 1.8fr 1.8fr; break-inside: avoid; }
  .line .c-desc { grid-column: auto; }
  .line .c-total .lbl { display: none; }
  .inv-top { grid-template-columns: 1fr 260px; }
  .parties { grid-template-columns: 1fr 1fr; }
  .totals { grid-template-columns: 1fr 280px; }
  .print-only { display: block; }
}
