/* ---------- Heading font (self-hosted; SIL Open Font License, see /fonts/Sora-OFL-LICENSE.txt) ---------- */
@font-face {
  font-family: "Sora";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/sora-latin-600-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- App tokens ---------- */
:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --input-bg: #ffffff;
  --text: #16181d;
  --muted: #5b6560;
  --line: #dfe6e2;
  --primary: #137a47;        /* Bamboo Dark: buttons, links */
  --primary-hover: #0f6a3d;
  --primary-ink: #ffffff;
  --focus: rgba(23, 138, 80, 0.3);
  --danger: #c7362d;
  --preview-bg: #e3e9e5;
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.06), 0 8px 24px rgba(16, 24, 20, 0.08);
  --font-display: "Sora", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1210;
    --surface: #161b18;
    --input-bg: #1c221f;
    --text: #e7ece9;
    --muted: #98a39d;
    --line: #2a322e;
    --primary: #5fd394;      /* Leaf */
    --primary-hover: #7fe0ab;
    --primary-ink: #0b1a12;
    --focus: rgba(95, 211, 148, 0.35);
    --danger: #ff6b61;
    --preview-bg: #090c0a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1210; --surface: #161b18; --input-bg: #1c221f; --text: #e7ece9; --muted: #98a39d;
  --line: #2a322e; --primary: #5fd394; --primary-hover: #7fe0ab; --primary-ink: #0b1a12;
  --focus: rgba(95, 211, 148, 0.35); --danger: #ff6b61; --preview-bg: #090c0a; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; text-decoration: none; flex: 0 0 auto; }
.brand img { display: block; }
.brand .brand-full img { height: 36px; width: auto; }
.brand .brand-icon { display: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 14px;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .tabs button:focus-visible {
  outline: none; box-shadow: 0 0 0 3px var(--focus); border-color: var(--primary);
}
.icon-btn {
  width: 32px; height: 36px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { color: var(--danger); background: var(--bg); }

/* ---------- Editor layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(360px, 460px) minmax(0, 1fr);
  gap: 20px;
  max-width: 1500px; margin: 0 auto; padding: 20px;
  align-items: start;
}
.tabs { display: none; }
.preview-wrap {
  position: sticky; top: 79px;
  max-height: calc(100vh - 99px); overflow: auto;
  background: var(--preview-bg);
  border-radius: 14px; padding: 28px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 16px 18px;
  margin: 0 0 16px;
}
.card h2, .dlg h2, .viewer-heading strong { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
.card h2 { margin: 0 0 14px; font-size: 15px; }
.card h2 small { font-weight: 400; color: var(--muted); margin-left: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); min-width: 0; }
.card > .field + .field { margin-top: 12px; }
.field em { font-style: normal; opacity: .75; }

input, select, textarea {
  width: 100%; min-width: 0;
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px;
}
textarea { resize: vertical; line-height: 1.4; }
input[type="color"] { padding: 3px; height: 40px; cursor: pointer; }
input[type="date"] { min-height: 40px; }
.combo { display: flex; gap: 6px; }
.combo select { width: auto; flex: 0 0 auto; }

/* Searchable country picker */
.cbx { position: relative; }
.cbx input {
  padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.cbx-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 264px; overflow-y: auto; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.cbx-list li { padding: 8px 10px; border-radius: 7px; color: var(--text); font-size: 14px; cursor: pointer; }
.cbx-list li[aria-selected="true"] { background: var(--focus); }
.cbx-list li.cbx-current { font-weight: 600; }
.cbx-list .cbx-empty { color: var(--muted); cursor: default; }
.cbx-list .cbx-code { display: inline-block; min-width: 40px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cbx-list .cbx-sep { height: 1px; margin: 4px 6px; padding: 0; background: var(--line); cursor: default; }

/* Office-style colour palette */
.swatch-picker { position: relative; }
.swatch-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 5px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--input-bg); color: var(--text);
  font: inherit; font-size: 14px; cursor: pointer; text-align: left;
}
.swatch-current { width: 26px; height: 26px; border-radius: 6px; flex: 0 0 auto; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.swatch-hex { font-variant-numeric: tabular-nums; }
.swatch-pop {
  position: absolute; z-index: 30; right: 0; top: calc(100% + 4px); width: 292px; padding: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.swatch-title { font-size: 12px; font-weight: 600; color: var(--muted); margin: 0 0 8px; }
.swatch-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.swatch {
  aspect-ratio: 1; border: 0; border-radius: 4px; padding: 0; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); transition: transform .1s;
}
.swatch:hover { transform: scale(1.15); }
.swatch[aria-pressed="true"] { outline: 2px solid var(--text); outline-offset: 2px; }
.swatch-more {
  display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 8px 10px; border-radius: 8px;
  font-size: 14px; color: var(--text); cursor: pointer; border: 1px solid var(--line);
}
.swatch-more:hover { border-color: var(--muted); }
.swatch-more input { width: 26px; height: 26px; padding: 0; border: 0; border-radius: 6px; background: none; cursor: pointer; }

/* Logo */
.logo-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.logo-thumb {
  width: 96px; height: 48px; border-radius: 8px; flex: 0 0 auto;
  border: 1px dashed var(--line);
  background: var(--bg) center / contain no-repeat;
}
.logo-thumb.has { border-style: solid; background-color: #fff; }
.logo-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.mt { margin-top: 14px; }
.row-end { display: flex; justify-content: flex-end; margin-top: -4px; }

/* Inline notices (number already used, tax suggestion) */
.notice {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: 10px; font-size: 13px; color: var(--text);
  background: rgba(230, 160, 0, .12); border: 1px solid rgba(230, 160, 0, .35);
}
#taxHint { background: rgba(23, 138, 80, .08); border-color: rgba(23, 138, 80, .3); }
.notice-actions { display: flex; align-items: center; gap: 4px; }

/* Template picker */
.tpl-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; --accent: #178a50; }
.tpl { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; color: var(--text); font-size: 12px; }
.tpl input { position: absolute; top: 0; left: 0; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.tpl-thumb {
  position: relative; display: block; width: 100%; aspect-ratio: 3 / 4; overflow: hidden;
  background: #fff; border: 2px solid var(--line); border-radius: 8px; padding: 22% 14% 0;
}
.tpl input:checked + .tpl-thumb { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.tpl input:focus-visible + .tpl-thumb { box-shadow: 0 0 0 3px var(--focus); }
.tpl-thumb b { display: block; height: 3px; border-radius: 2px; background: #d6dbe1; margin-bottom: 7%; }
.tpl-thumb b.s { width: 45%; margin-left: auto; background: #1a1d24; }
.tpl-thumb b.h { position: absolute; left: 0; right: 0; top: 0; height: auto; margin: 0; border-radius: 0; }
.tpl-classic b.h { height: 5%; background: var(--accent); }
.tpl-modern b.h { height: 17%; background: var(--accent); }
.tpl-minimal b.h { left: auto; right: 14%; top: 8%; width: 22%; height: 3px; background: var(--accent); }
.tpl-pro b.h { top: 12%; left: 14%; right: 14%; height: 3px; background: var(--accent); }
.tpl-pro b.l:first-of-type { height: 7px; background: #1f2430; }
.tpl input:checked ~ .tpl-name { font-weight: 700; }

/* Items */
.items { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 72px minmax(0, 1fr) 32px;
  gap: 8px; align-items: end;
  padding: 10px; border: 1px solid var(--line); border-radius: 10px;
}
.item .item-desc { grid-column: 1 / -1; resize: none; overflow: hidden; min-height: 38px; }
.item .cell { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.item .lbl { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item input { text-align: right; }
.item .amt {
  display: flex; align-items: center; justify-content: flex-end; min-height: 38px;
  font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 600; overflow: hidden; white-space: nowrap;
}
.item .amt-cell .lbl { text-align: right; }
.item .amt-vat { font-size: 11px; color: var(--muted); text-align: right; white-space: nowrap; margin-top: -6px; }
.items-mode { margin-bottom: 12px; }
.item .del { align-self: end; }

.sum-line { display: flex; justify-content: space-between; align-items: baseline; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.sum-line strong { font-size: 20px; font-variant-numeric: tabular-nums; }

.privacy { font-size: 13px; color: var(--muted); margin: 4px 4px 24px; }

/* ---------- Viewer ---------- */
.viewer { max-width: 900px; margin: 0 auto; padding: 20px 16px 40px; }
.viewer-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.viewer-heading { display: flex; flex-direction: column; }
.viewer-heading span { color: var(--muted); font-size: 14px; }
.viewer .invoice { box-shadow: var(--shadow); border-radius: 4px; }
.viewer-foot { text-align: center; color: var(--muted); font-size: 14px; margin-top: 24px; }
.viewer-foot .dot { margin: 0 6px; }

/* ---------- Dialog ---------- */
dialog {
  width: min(520px, calc(100vw - 32px));
  border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); color: var(--text);
  padding: 0; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 12, 18, .5); }
.dlg { padding: 20px; }
.dlg h2 { margin: 0 0 6px; font-size: 18px; }
.muted { color: var(--muted); font-size: 14px; }
.copyrow { display: flex; gap: 8px; margin: 16px 0 10px; }
.copyrow input { font-size: 13px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 14px; }
.check input { width: auto; }
.share-row { display: flex; gap: 8px; flex-wrap: wrap; }
.warn { margin: 14px 0 0; padding: 10px 12px; border-radius: 8px; font-size: 13px; background: rgba(230, 160, 0, .14); color: var(--text); }
.dlg-foot { display: flex; justify-content: flex-end; margin-top: 18px; }

/* ---------- Page heading above the tool ---------- */
.hero { max-width: 1500px; margin: 0 auto; padding: 22px 20px 4px; }
.hero h1 { margin: 0 0 6px; font-family: var(--font-display); font-weight: 600; font-size: clamp(22px, 3vw, 30px); line-height: 1.2; letter-spacing: -0.01em; }
.hero-lead { margin: 0 0 12px; color: var(--muted); font-size: 16px; max-width: 760px; }
.hero-points { display: flex; flex-wrap: wrap; gap: 6px 8px; margin: 0; padding: 0; list-style: none; }
.hero-points li {
  padding: 4px 10px 4px 26px; border-radius: 99px; font-size: 13px; font-weight: 600; color: var(--text);
  background: var(--surface) no-repeat 9px 50% / 11px 11px; border: 1px solid var(--line);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 6.5l2.6 2.5L10 3.5' fill='none' stroke='%23178a50' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ---------- Guide content below the tool ---------- */
.seo { max-width: 900px; margin: 24px auto 0; padding: 8px 20px 40px; color: var(--text); font-size: 16px; line-height: 1.65; }
.seo section { margin-top: 40px; }
.seo h2 { margin: 0 0 12px; font-family: var(--font-display); font-weight: 600; font-size: 24px; line-height: 1.25; letter-spacing: -0.01em; }
.seo h3 { margin: 0 0 6px; font-size: 16px; }
.seo p { margin: 0 0 12px; }
.seo a { color: var(--primary); }
.steps { counter-reset: step; list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.steps li { counter-increment: step; position: relative; padding: 14px 16px 14px 56px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.steps li::before {
  content: counter(step); position: absolute; left: 16px; top: 14px; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--primary); color: var(--primary-ink); font-weight: 700; font-size: 14px;
}
.feature-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.feature { padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.feature p { margin: 0; color: var(--muted); font-size: 15px; }
.checklist { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.checklist li { position: relative; padding-left: 28px; }
.checklist li::before {
  content: ""; position: absolute; left: 0; top: 5px; width: 18px; height: 18px; border-radius: 50%; background: var(--primary);
}
.checklist li::after {
  content: ""; position: absolute; left: 5px; top: 9px; width: 8px; height: 5px;
  border-left: 2px solid var(--primary-ink); border-bottom: 2px solid var(--primary-ink); transform: rotate(-45deg);
}
.faq details { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); margin-bottom: 8px; }
.faq summary { cursor: pointer; padding: 14px 44px 14px 16px; font-weight: 600; list-style: none; position: relative; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; position: absolute; right: 16px; top: 10px; font-size: 22px; color: var(--muted); }
.faq details[open] summary::after { content: "−"; }
.faq details p { margin: 0; padding: 0 16px 14px; color: var(--muted); }

/* ---------- Footer ---------- */
.site-foot { border-top: 1px solid var(--line); background: var(--surface); margin-top: 24px; }
.foot-inner { max-width: 1100px; margin: 0 auto; padding: 28px 20px 8px; display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 24px; }
.foot-brand { display: flex; gap: 12px; align-items: flex-start; }
.foot-brand strong { font-family: var(--font-display); font-weight: 600; font-size: 17px; }
.foot-brand p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.foot-links { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.foot-links h2 { margin: 0 0 4px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.foot-links a { color: var(--text); text-decoration: none; }
.foot-links a:hover { color: var(--primary); text-decoration: underline; }
.foot-note { max-width: 1100px; margin: 0 auto; padding: 12px 20px 24px; color: var(--muted); font-size: 13px; }

/* ---------- Legal and other simple pages ---------- */
.doc-main { max-width: 780px; margin: 0 auto; padding: 32px 20px 24px; }
.doc { line-height: 1.7; font-size: 16px; }
.doc h1 { font-family: var(--font-display); font-weight: 600; font-size: clamp(26px, 4vw, 34px); margin: 0 0 4px; }
.doc h2 { font-size: 19px; margin: 28px 0 8px; }
.doc ul { padding-left: 22px; }
.doc li { margin-bottom: 6px; }
.doc-meta { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.doc-center { text-align: center; padding: 40px 0; }
.doc-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #16181d; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 14px; max-width: calc(100vw - 32px); text-align: center;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 920px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 24px; gap: 12px; }
  .tabs {
    display: flex; position: sticky; top: 59px; z-index: 15;
    background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 4px;
  }
  .tabs button {
    flex: 1; min-height: 36px; border: 0; border-radius: 7px; background: transparent;
    color: var(--muted); font: inherit; font-weight: 600; cursor: pointer;
  }
  .tabs button[aria-selected="true"] { background: var(--primary); color: var(--primary-ink); }
  .layout[data-tab="form"] .preview-wrap { display: none; }
  .layout[data-tab="preview"] .form { display: none; }
  .preview-wrap { position: static; max-height: none; padding: 0; background: transparent; }
  .preview-wrap .invoice { box-shadow: var(--shadow); }
}
@media (max-width: 760px) {
  .feature-grid { grid-template-columns: minmax(0, 1fr); }
  .foot-inner { grid-template-columns: 1fr 1fr; }
  .foot-brand { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 16px; }
  .hero { padding: 14px 16px 0; }
  .hero-lead { font-size: 14px; margin-bottom: 10px; }
  .hero-points li { font-size: 12px; }
  .seo { font-size: 15px; padding: 0 16px 32px; }
  .seo h2 { font-size: 21px; }
  .hide-sm { display: none; }
  .brand .brand-full { display: none; }
  .brand .brand-icon { display: block; }
  .grid2 { grid-template-columns: 1fr; }
  .item { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, 1fr) 32px; }
  .item .amt-cell { grid-column: 1 / 4; flex-direction: row; align-items: center; gap: 8px; }
  .item .amt-cell .lbl { flex: 1 1 auto; text-align: left; }
  .item .amt-vat { margin-top: 0; order: 3; }
  .item .del { grid-row: 2; grid-column: 4; }
  .tpl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tpl-thumb { aspect-ratio: 4 / 3; padding: 16% 12% 0; }
}

/* ===================================================================
   Invoice paper — always light, used by preview, viewer, PDF and print.
   Plain hex/rgba only (the PDF renderer does not understand newer colour syntax).
   =================================================================== */
.paper-host { container-type: inline-size; }
.invoice {
  --ink: #1a1d24;
  --ink2: #5b6270;
  --rule: #e4e7ed;
  --pad-top: 52px;
  --pad-x: 56px;
  width: 100%; max-width: 794px; margin: 0 auto;
  background: #ffffff; color: var(--ink);
  font: 13px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  padding: var(--pad-top) var(--pad-x) 56px;
  min-height: 600px;
}
.invoice * { box-sizing: border-box; }
/* Header: business on the left, QR code in the centre, title on the right */
.inv-top { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 24px; align-items: start; }
.inv-brand { grid-column: 1; min-width: 0; }
.inv-logo { display: block; max-width: 180px; max-height: 72px; margin-bottom: 12px; }
.inv-biz { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.inv-addr { color: var(--ink2); word-wrap: break-word; }
.inv-titlebox { grid-column: 3; justify-self: end; align-self: center; text-align: right; }
.inv-title { margin: 0; font-size: 30px; line-height: 1.1; font-weight: 800; letter-spacing: .02em; text-transform: uppercase; color: var(--accent); }

/* QR code linking to the online copy */
/* Centred, and always sitting at the bottom of the header, just above its divider line */
.inv-qr { grid-column: 2; align-self: end; margin: 0; width: 96px; text-align: center; }
.inv-qr img, .inv-qr .qr-ph { display: block; width: 96px; height: 96px; margin: 0 auto; }
.inv-qr img { image-rendering: pixelated; }
.inv-qr .qr-ph { background: #f1f3f5; border-radius: 4px; }
.inv-qr figcaption { margin-top: 5px; font-size: 9px; line-height: 1.3; color: var(--ink2); }

/* Invoice number and dates, next to Bill to */
.inv-meta { margin: 0; display: grid; gap: 3px; }
.inv-meta div { display: flex; justify-content: space-between; gap: 16px; }
.inv-meta dt { color: var(--ink2); }
.inv-meta dd { margin: 0; font-weight: 600; color: var(--ink); text-align: right; }

.inv-mid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; margin: 32px 0 28px; }
.inv-details { min-width: 0; }
.inv-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink2); margin-bottom: 6px; }
.inv-billto { min-width: 0; color: var(--ink2); word-wrap: break-word; }
.inv-billto .p-name { color: var(--ink); font-weight: 700; font-size: 14px; }

.inv-items { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.inv-items th {
  text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink2); padding: 10px 8px; border-bottom: 2px solid var(--ink);
}
.inv-items td { padding: 11px 8px; border-bottom: 1px solid var(--rule); vertical-align: top; word-wrap: break-word; }
.inv-items th:first-child, .inv-items td:first-child { padding-left: 0; }
.inv-items th:last-child, .inv-items td:last-child { padding-right: 0; }
.inv-items .c-num { text-align: right; white-space: nowrap; width: 1%; }
.inv-items .c-amt { font-weight: 600; }
.inv-items tr { page-break-inside: avoid; break-inside: avoid; }
.inv-empty { color: #a0a6b1; font-style: italic; }
.inv-table-wrap { overflow-x: auto; }
.inv-items.has-tax { font-size: 12.5px; }
.inv-items.has-tax th, .inv-items.has-tax td { padding-left: 6px; padding-right: 6px; }
.inv-items .disc-row td { color: var(--ink2); }
.inv-items tfoot td {
  padding-top: 10px; padding-bottom: 10px; border-top: 2px solid var(--ink); border-bottom: 0;
  font-weight: 700; text-align: right; white-space: nowrap;
}
.inv-items tfoot td:first-child { text-align: left; }

/* Payment details sit in the space to the left of the totals */
.inv-summary {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 32px;
  margin-top: 20px; page-break-inside: avoid; break-inside: avoid;
}
.inv-pay { flex: 1 1 auto; min-width: 0; max-width: 48%; color: var(--ink2); word-wrap: break-word; }
.inv-totals { flex: 0 0 auto; }
.inv-totals table { border-collapse: collapse; min-width: 280px; font-variant-numeric: tabular-nums; }
.inv-totals td { padding: 5px 0; }
.inv-totals td:last-child { text-align: right; padding-left: 32px; white-space: nowrap; }
.inv-totals .t-muted td:first-child { color: var(--ink2); }
.inv-totals .t-total td { border-top: 1px solid var(--rule); padding-top: 10px; font-weight: 700; }
.inv-totals .t-due td { border-top: 2px solid var(--ink); padding-top: 10px; font-weight: 800; font-size: 16px; }

.inv-notes { display: grid; grid-template-columns: 1fr 1fr; gap: 20px 32px; margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--rule); }
.inv-note { color: var(--ink2); word-wrap: break-word; page-break-inside: avoid; break-inside: avoid; }
.inv-note.wide { grid-column: 1 / -1; }

/* ----- Template: Classic (accent bar on top, coloured title) ----- */
.t-classic { border-top: 6px solid var(--accent); }

/* ----- Template: Modern (full-width coloured header) ----- */
.t-modern .inv-top {
  margin: calc(var(--pad-top) * -1) calc(var(--pad-x) * -1) 0;
  padding: 36px var(--pad-x) 32px;
  background: var(--accent); color: #ffffff;
}
.t-modern .inv-title { color: #ffffff; }
.t-modern .inv-addr { color: rgba(255, 255, 255, .82); }
.t-modern .inv-logo { background: #ffffff; padding: 8px; border-radius: 8px; }
.t-modern .inv-qr img, .t-modern .inv-qr .qr-ph { box-sizing: content-box; padding: 5px; background: #ffffff; border-radius: 6px; }
.t-modern .inv-qr figcaption { color: rgba(255, 255, 255, .85); }
.t-modern .inv-items th { background: var(--accent-soft); border-bottom: 0; color: var(--ink); }
.t-modern .inv-items th:first-child, .t-modern .inv-items td:first-child { padding-left: 10px; }
.t-modern .inv-items th:last-child, .t-modern .inv-items td:last-child { padding-right: 10px; }
.t-modern .t-due td { border-top-color: var(--accent); color: var(--accent); }

/* ----- Template: Minimal (black & white, one small accent) ----- */
.t-minimal .inv-title { color: var(--ink); font-weight: 300; font-size: 32px; letter-spacing: .14em; }
.t-minimal .inv-title::after { content: ""; display: block; width: 36px; height: 3px; margin: 12px 0 0 auto; background: var(--accent); }
.t-minimal .inv-biz { font-weight: 600; }
.t-minimal .inv-label { font-weight: 600; }
.t-minimal .inv-items th { font-weight: 600; border-bottom: 1px solid var(--ink); }
.t-minimal .inv-items td { border-bottom-color: #eef0f3; }
.t-minimal .inv-items .c-amt { font-weight: 500; }
.t-minimal .t-due td { border-top: 1px solid var(--ink); font-weight: 600; }
.t-minimal .t-due td:last-child { color: var(--accent); }
.t-minimal .inv-notes { border-top-color: #eef0f3; }

/* ----- Template: Professional (boxed details, dark table header) ----- */
.t-pro .inv-top { padding-bottom: 22px; border-bottom: 3px solid var(--accent); }
.t-pro .inv-title { color: var(--ink); font-size: 26px; }
.t-pro .inv-mid { margin-top: 28px; align-items: stretch; }
.t-pro .inv-billto, .t-pro .inv-details { background: #f5f6f8; border-radius: 6px; padding: 14px 16px; }
.t-pro .inv-items th { background: #1f2430; color: #ffffff; border-bottom: 0; }
.t-pro .inv-items th, .t-pro .inv-items td { padding-left: 10px; padding-right: 10px; }
.t-pro .inv-items th:first-child, .t-pro .inv-items td:first-child { padding-left: 12px; }
.t-pro .inv-items th:last-child, .t-pro .inv-items td:last-child { padding-right: 12px; }
.t-pro .inv-items tbody tr:nth-child(even) td { background: #f7f8fa; }
.t-pro .inv-items td { border-bottom: 0; }
.t-pro .inv-items tfoot td { background: #e9ecf0; border-top: 0; color: var(--ink); }
.t-pro .inv-pay:not(.inv-pay-empty) { background: #f5f6f8; border-radius: 6px; padding: 14px 16px; }
.t-pro .t-due td { border-top: 0; background: var(--accent); color: #ffffff; padding: 10px 12px; }
.t-pro .t-due td:last-child { padding-left: 32px; }

/* Narrow screens: stack the invoice so it's readable on a phone */
@container (max-width: 560px) {
  .invoice { --pad-top: 28px; --pad-x: 20px; padding-bottom: 32px; min-height: 0; font-size: 13px; }
  .inv-top { grid-template-columns: minmax(0, 1fr) auto; gap: 16px 20px; }
  .inv-brand { grid-column: 1 / -1; }
  .inv-titlebox { grid-column: 1; grid-row: 2; justify-self: start; text-align: left; }
  .inv-qr { grid-column: 2; grid-row: 2; }
  .inv-mid { grid-template-columns: minmax(0, 1fr); gap: 16px; margin: 24px 0 20px; }
  .t-modern .inv-top { padding-top: 28px; padding-bottom: 24px; }
  .t-minimal .inv-title::after { margin-left: 0; }
  .inv-items th, .inv-items td { padding-left: 4px; padding-right: 4px; }
  .inv-items.has-tax { min-width: 620px; }
  .inv-summary { flex-direction: column-reverse; gap: 20px; }
  .inv-pay { max-width: none; width: 100%; }
  .inv-pay-empty { display: none; }
  .inv-totals { width: 100%; }
  .inv-totals table { min-width: 0; width: 100%; }
  .inv-notes { grid-template-columns: 1fr; }
}

/* Offscreen holder for PDF rendering */
.pdf-holder { position: fixed; left: -10000px; top: 0; }
.invoice.for-pdf { --pad-top: 36px; max-width: none; min-height: 0; padding-bottom: 40px; }

/* ---------- Print ---------- */
#printRoot { display: none; }
@media print {
  html, body { background: #fff !important; }
  body > *:not(#printRoot) { display: none !important; }
  #printRoot { display: block !important; }
  #printRoot .invoice {
    --pad-top: 48px; max-width: none; min-height: 0; padding-bottom: 48px;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}
