/* ---------- Tokens ---------- */
:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #ecebe8;
  --text: #1c1917;
  --muted: #6f6a66;
  --border: #e2e0dc;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-ink: #ffffff;
  --accent-soft: rgba(15, 118, 110, .1);
  --danger: #b91c1c;
  --focus: rgba(15, 118, 110, .35);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0e0d; --surface: #1a1918; --surface-2: #121110; --text: #f2f1ef; --muted: #a29d98;
    --border: #2d2a28; --accent: #2dd4bf; --accent-hover: #5eead4; --accent-ink: #042f2e;
    --accent-soft: rgba(45, 212, 191, .12); --danger: #f87171; --focus: rgba(45, 212, 191, .35);
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0e0d; --surface: #1a1918; --surface-2: #121110; --text: #f2f1ef; --muted: #a29d98;
  --border: #2d2a28; --accent: #2dd4bf; --accent-hover: #5eead4; --accent-ink: #042f2e;
  --accent-soft: rgba(45, 212, 191, .12); --danger: #f87171; --focus: rgba(45, 212, 191, .35);
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; padding-bottom: env(safe-area-inset-bottom);
}
h2 { font-size: 17px; margin: 0; letter-spacing: -.01em; }
h3 { margin: 0 0 8px; font-size: 18px; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- App bar & tabs ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.appbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; min-width: 0; }
.appbar-brand span { white-space: nowrap; }
.appbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-switch select { max-width: 160px; padding: 6px 28px 6px 10px; font-size: 14px; }
.plan-pill {
  font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted);
}
button.plan-pill { border: 0; cursor: pointer; font-family: inherit; }
.plan-pill.pro { background: var(--accent-soft); color: var(--accent); }
.plan-pill.warn { background: rgba(180, 83, 9, .14); color: #b45309; }
.plan-pill.expired { background: rgba(185, 28, 28, .12); color: var(--danger); }
.trial-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; font-size: 14px;
}
.trial-banner.expired { border-color: var(--danger); }
.pay-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.pay-head .icon-btn { margin: -8px -8px 0 0; }
.price-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin-bottom: 14px; background: var(--surface-2); }
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
@media (max-width: 380px) { .plans { grid-template-columns: 1fr; } }
.plan-opt { position: relative; margin: 0; cursor: pointer; }
.plan-opt input { position: absolute; opacity: 0; pointer-events: none; }
.po-body {
  display: flex; flex-direction: column; gap: 2px; height: 100%; padding: 12px 14px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--surface); transition: border-color .15s, background .15s;
}
.plan-opt input:checked + .po-body { border-color: var(--accent); background: var(--accent-soft); }
.plan-opt input:focus-visible + .po-body { box-shadow: 0 0 0 3px var(--focus); }
.po-name { font-size: 13px; font-weight: 650; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.po-price { font-size: 13px; color: var(--muted); font-weight: 500; }
.po-price strong { font-size: 22px; color: var(--text); letter-spacing: -.02em; }
.po-body small { font-size: 12px; color: var(--muted); font-weight: 400; }
.po-badge { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); }
.price { display: flex; align-items: baseline; gap: 6px; margin-bottom: 8px; }
.price strong { font-size: 28px; letter-spacing: -.02em; }
.price span { color: var(--muted); }
.price-card .perks { margin: 0; }
.pay-status { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; background: var(--accent-soft); color: var(--text); }
.pay-status.err { background: rgba(185, 28, 28, .1); }
.btn-block { width: 100%; margin-bottom: 6px; }
.center { display: block; text-align: center; }
.restore { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.restore summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--accent); }
.restore .hint { display: block; margin: 8px 0 10px; }
.r-trial { margin-top: 14px; text-align: center; font-size: 11px; color: #9ca3af; border-top: 1px dashed #e5e7eb; padding-top: 8px; }

.tabs {
  display: flex; gap: 4px; padding: 8px 16px 0; max-width: 1240px; margin: 0 auto;
  overflow-x: auto; scrollbar-width: none;
}
.tabs button {
  appearance: none; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 550;
  padding: 10px 14px; border-radius: 10px 10px 0 0; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs button:hover { color: var(--text); }

main { max-width: 1240px; margin: 0 auto; padding: 12px 16px 48px; }

/* ---------- Panels & forms ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-variant-numeric: tabular-nums; }

fieldset { border: 0; padding: 0; margin: 0 0 18px; min-width: 0; }
legend { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; padding: 0; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 550; color: var(--text); margin-bottom: 10px; min-width: 0; }
.req { color: var(--danger); }
input, select, textarea {
  font: inherit; font-size: 15px; font-weight: 400; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; width: 100%; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
input.invalid { border-color: var(--danger); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
input[type="color"] { padding: 3px; width: 46px; height: 40px; flex: none; cursor: pointer; }
.color-row { display: flex; gap: 8px; }
.hex { font-family: ui-monospace, Consolas, monospace; text-transform: uppercase; }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.input-group { display: flex; }
.input-group > :first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group > :last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; width: auto; flex: none; }
form.panel { container-type: inline-size; }
.row2, .row3 { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
@container (min-width: 420px) { .row2 { grid-template-columns: 1fr 1fr; } }
@container (min-width: 560px) { .row3 { grid-template-columns: 1fr 1fr 1fr; } }
@container (min-width: 420px) and (max-width: 559px) { .row3 { grid-template-columns: 1fr 1fr; } }
.hint { color: var(--muted); font-size: 12px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 14px; line-height: 1; text-decoration: none;
  padding: 11px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; transition: background .15s, border-color .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-style: dashed; }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger-ghost:hover { background: rgba(185, 28, 28, .08); }
.btn:disabled { opacity: .55; cursor: progress; }
.file-btn { margin: 0; flex-direction: row; }
.icon-btn {
  appearance: none; border: 1px solid transparent; background: none; color: var(--muted); font-size: 20px; line-height: 1;
  width: 38px; height: 40px; border-radius: 9px; cursor: pointer;
}
.icon-btn:hover:not(:disabled) { color: var(--danger); background: var(--surface-2); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.pro-tag { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; background: var(--accent-soft); color: var(--accent); padding: 2px 6px; border-radius: 99px; }

/* ---------- Create ---------- */
.setup-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-size: 14px;
}
.create-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 1100px) { .create-grid { grid-template-columns: minmax(420px, 1fr) minmax(0, 620px); } .preview-col { position: sticky; top: 72px; } }

.item-head, .item-row { display: grid; grid-template-columns: minmax(0, 1fr) 70px 120px 38px; gap: 8px; align-items: center; }
.item-head { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 6px; }
.item-row { margin-bottom: 8px; }
@container (max-width: 519px) {
  .item-head { display: none; }
  .item-row { grid-template-columns: 70px minmax(0, 1fr) 38px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
  .item-row .it-desc { grid-column: 1 / -1; }
}
.totals-mini { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
.totals-mini div { display: flex; justify-content: space-between; padding: 2px 0; font-variant-numeric: tabular-nums; }
.totals-mini .grand { font-weight: 700; font-size: 16px; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 6px; }

.preview-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tpl-select { margin: 0; }
.tpl-select select { padding: 7px 30px 7px 10px; font-size: 13px; }
.preview-scroll { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; overflow-x: auto; }
@media (max-width: 559px) { .preview-scroll { padding: 8px; } }

/* ---------- History ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.stat span { display: block; font-size: 12px; color: var(--muted); }
.stat strong { font-size: 19px; font-variant-numeric: tabular-nums; }
.search { margin-bottom: 12px; }
.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center;
  padding: 12px 4px; border-top: 1px solid var(--border);
}
.h-main { min-width: 0; }
.h-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-sub { font-size: 13px; color: var(--muted); }
.h-amount { font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; }
.h-actions { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
.status-dot { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; margin-left: 6px; vertical-align: 1px; }
.status-dot.paid { background: rgba(21,128,61,.12); color: #15803d; }
.status-dot.part { background: rgba(180,83,9,.12); color: #b45309; }
.status-dot.unpaid { background: rgba(185,28,28,.12); color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }

/* ---------- Brand ---------- */
.brand-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 900px) { .brand-grid { grid-template-columns: 280px minmax(0, 1fr); } }
.brand-list { list-style: none; padding: 0; margin: 0 0 12px; }
.brand-list button {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; font: inherit; color: var(--text);
  background: none; border: 1px solid transparent; border-radius: 10px; padding: 8px; cursor: pointer;
}
.brand-list button:hover { background: var(--surface-2); }
.brand-list button.on { border-color: var(--accent); background: var(--accent-soft); }
.b-swatch { width: 34px; height: 34px; border-radius: 8px; flex: none; display: grid; place-items: center; overflow: hidden; color: #fff; font-weight: 700; background: #fff; }
.b-swatch img { width: 100%; height: 100%; object-fit: contain; }
.b-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo-row { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.logo-box {
  width: 96px; height: 96px; border-radius: 12px; border: 1px dashed var(--border); display: grid; place-items: center;
  background: repeating-conic-gradient(#f3f3f3 0 25%, #fff 0 50%) 0 0 / 16px 16px; overflow: hidden; color: #8a8580; font-size: 12px;
}
.logo-box img { max-width: 88%; max-height: 88%; object-fit: contain; }
.logo-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.logo-actions .hint { flex-basis: 100%; }

/* ---------- Dialog & toast ---------- */
.dialog { border: 1px solid var(--border); border-radius: 16px; padding: 22px; max-width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog p { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.perks { padding-left: 18px; margin: 0 0 16px; font-size: 14px; }
.perks li { margin-bottom: 4px; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #1c1917; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100vw - 32px);
  transition: opacity .2s, transform .2s; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* =========================================================
   RECEIPT DOCUMENT — always rendered on white paper
   (avoid color-mix / filters so image export renders faithfully)
   ========================================================= */
.rcpt {
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: rgba(15,118,110,.08);
  position: relative; background: #ffffff; color: #1f2328; width: 100%; max-width: 620px; margin: 0 auto;
  padding: 34px 34px 28px; font: 13.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 8px 24px rgba(0,0,0,.06); border-radius: 4px; overflow: hidden;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.r-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 16px; border-bottom: 3px solid var(--brand); }
.r-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.r-logo { max-height: 58px; max-width: 150px; object-fit: contain; display: block; }
.r-name { font-size: 19px; font-weight: 750; line-height: 1.2; color: #111418; word-break: break-word; }
.r-tag { font-size: 12px; color: #6b7280; }
.r-title { text-align: right; flex: none; }
.r-label { font-size: 12px; font-weight: 750; letter-spacing: .18em; color: var(--brand); }
.r-no { font-size: 15px; font-weight: 650; color: #111418; font-variant-numeric: tabular-nums; }
.r-contact { font-size: 11.5px; color: #6b7280; margin: 10px 0 20px; }
.r-contact span { white-space: nowrap; display: inline-block; }
.r-contact span + span::before { content: "·"; margin: 0 6px; color: #c0c4ca; }
.r-meta { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.r-meta span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #8a9099; margin-bottom: 2px; }
.r-meta strong { display: block; font-weight: 650; color: #111418; word-break: break-word; }
.r-meta small { display: block; color: #6b7280; font-size: 12px; word-break: break-word; }
.r-items { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.r-items th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6b7280; font-weight: 650; text-align: left; padding: 8px 6px; border-bottom: 1px solid #d9dce1; }
.r-items td { padding: 10px 6px; border-bottom: 1px solid #eef0f2; vertical-align: top; }
.r-items .n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.r-items th.n { text-align: right; }
.r-sub { display: none; font-size: 11.5px; color: #6b7280; }
.r-summary { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.r-left { flex: 1; min-width: 0; padding-top: 6px; }
.r-totals { width: 260px; max-width: 55%; flex: none; }
.r-totals div { display: flex; justify-content: space-between; gap: 10px; padding: 4px 6px; font-variant-numeric: tabular-nums; }
.r-totals .muted { color: #6b7280; }
.r-totals .grand { margin-top: 4px; padding: 9px 8px; font-size: 16px; font-weight: 750; background: var(--brand); color: var(--brand-ink); border-radius: 4px; }
.r-totals .bal { font-weight: 650; color: #b45309; }
.r-stamp {
  display: inline-block; border: 2px solid currentColor; border-radius: 6px; padding: 4px 12px; font-weight: 800;
  letter-spacing: .14em; text-transform: uppercase; font-size: 15px; transform: rotate(-6deg); margin: 4px 0 12px;
}
.r-stamp.paid { color: #15803d; } .r-stamp.part { color: #b45309; } .r-stamp.unpaid { color: #b91c1c; }
.r-words { font-size: 12px; color: #374151; font-style: italic; margin-bottom: 8px; }
.r-notes { font-size: 12px; color: #374151; background: #f6f7f8; border-radius: 4px; padding: 8px 10px; margin-top: 6px; white-space: pre-wrap; word-break: break-word; }
.r-bank { font-size: 12px; color: #374151; margin-top: 8px; }
.r-bank b { font-weight: 650; }
.r-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-top: 34px; }
.r-sign { font-size: 12px; color: #6b7280; min-width: 170px; }
.r-sign .line { border-top: 1px solid #9ca3af; margin-bottom: 4px; height: 0; }
.r-sign b { display: block; color: #111418; font-weight: 600; }
.r-thanks { color: var(--brand); font-weight: 650; font-size: 13px; text-align: right; }
.r-mark { margin-top: 18px; text-align: center; font-size: 10px; color: #b0b5bc; letter-spacing: .04em; }

/* Modern template */
.tpl-modern .r-head { background: var(--brand); color: var(--brand-ink); margin: -34px -34px 0; padding: 28px 34px 24px; border-bottom: 0; }
.tpl-modern .r-name, .tpl-modern .r-no { color: var(--brand-ink); }
.tpl-modern .r-tag, .tpl-modern .r-label { color: var(--brand-ink); opacity: .82; }
.tpl-modern .r-logo-wrap { background: #fff; border-radius: 8px; padding: 6px; }
.tpl-modern .r-contact { background: var(--brand-soft); margin: 0 -34px 22px; padding: 9px 34px; color: #4b5563; }
.tpl-modern .r-items th { background: var(--brand-soft); border-bottom: 0; color: #374151; }
.tpl-modern .r-items th:first-child { border-radius: 4px 0 0 4px; } .tpl-modern .r-items th:last-child { border-radius: 0 4px 4px 0; }
.tpl-modern .r-foot { border-top: 1px solid #eef0f2; padding-top: 16px; }

/* Minimal template */
.tpl-minimal { font-size: 13px; }
.tpl-minimal .r-head { border-bottom: 1px solid #e5e7eb; flex-direction: column; align-items: center; text-align: center; gap: 10px; }
.tpl-minimal .r-brand { flex-direction: column; gap: 8px; }
.tpl-minimal .r-title { text-align: center; }
.tpl-minimal .r-contact { text-align: center; }
.tpl-minimal .r-totals .grand { background: none; color: #111418; border-top: 2px solid var(--brand); border-radius: 0; }

/* Narrow screens: reflow the on-screen preview (export always uses full width) */
@media (max-width: 559px) {
  .preview-scroll .rcpt { padding: 22px 18px 20px; font-size: 12.5px; }
  .preview-scroll .tpl-modern .r-head { margin: -22px -18px 0; padding: 20px 18px; }
  .preview-scroll .tpl-modern .r-contact { margin: 0 -18px 18px; padding: 8px 18px; }
  .preview-scroll .r-meta { grid-template-columns: 1fr 1fr; }
  .preview-scroll .r-meta > :first-child { grid-column: 1 / -1; }
  .preview-scroll .r-items .c-rate { display: none; }
  .preview-scroll .r-sub { display: block; }
  .preview-scroll .r-summary { flex-direction: column-reverse; }
  .preview-scroll .r-totals { width: 100%; max-width: none; }
  .preview-scroll .r-logo { max-height: 44px; max-width: 110px; }
}

/* Offscreen stage used for image export (fixed width) */
#renderStage { position: fixed; left: -10000px; top: 0; width: 640px; pointer-events: none; }
#renderStage .rcpt { width: 620px; max-width: none; box-shadow: none; border-radius: 0; }
#printArea { display: none; }

/* ---------- Print ---------- */
@media print {
  body { background: #fff !important; padding: 0; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  #printArea .rcpt { box-shadow: none; max-width: none; padding: 0; border-radius: 0; }
  #printArea .tpl-modern .r-head { margin: 0; padding: 22px 24px; }
  #printArea .tpl-modern .r-contact { margin: 0 0 22px; padding: 8px 24px; }
}
