/*! invoice.css — the invoice generator: hero, editor, A4 sheet, print.
    Loaded only on /invoice-generator/ so other pages stay light. */

/* =============================== hero =============================== */
.hero { padding: 34px 0 26px; }
.hero-inner { display: grid; gap: 22px; align-items: start; }
@media (min-width: 1024px) {
  .hero-inner { grid-template-columns: minmax(0, 1.25fr) minmax(0, .75fr); gap: 40px; }
}
.hero h1 { margin-bottom: 12px; }
.hero-lead { font-size: 1.05rem; color: var(--ink-2); max-width: 60ch; margin-bottom: 18px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.trust-list {
  list-style: none; margin: 20px 0 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 6px 18px;
  font-size: .85rem; color: var(--muted);
}
.trust-list li { display: flex; align-items: center; gap: 7px; }
.trust-list li::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: var(--brand); flex: none;
}

.hero-note {
  padding: 16px 18px; background: var(--surface);
  border: 1px solid var(--line); border-left: 3px solid var(--brand);
  border-radius: var(--radius); font-size: .89rem; color: var(--ink-2);
}
.hero-note strong { display: block; margin-bottom: 4px; color: var(--ink); }
.hero-note p:last-child { margin-bottom: 0; }

/* =============================== tool =============================== */
.tool { padding-bottom: 20px; scroll-margin-top: 70px; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 12px; margin-bottom: 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  position: sticky; top: var(--header-h); z-index: 30;
}
.toolbar-status {
  display: flex; align-items: center; gap: 7px; margin-right: auto;
  font-family: var(--font-mono); font-size: .72rem; color: var(--muted);
  letter-spacing: .02em;
}
.toolbar-status::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--brand); flex: none;
}
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.count-badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px;
  padding: 0 5px; margin-left: 2px; border-radius: 9px;
  background: var(--brand-soft); color: var(--brand-ink);
  font-family: var(--font-mono); font-size: .68rem;
}

.view-toggle { display: none; gap: 4px; padding: 4px; background: var(--desk-deep); border-radius: var(--radius-sm); }
.view-toggle .btn { min-height: 34px; border: 0; background: transparent; font-size: .87rem; }
.view-toggle .btn.is-active { background: var(--surface); box-shadow: var(--shadow-sm); }
@media (max-width: 1023px) { .view-toggle { display: flex; } }

#tool-grid { display: grid; gap: var(--gap); align-items: start; }
@media (min-width: 1024px) {
  #tool-grid { grid-template-columns: minmax(0, 1.02fr) minmax(0, 1fr); }
}
@media (min-width: 1440px) {
  #tool-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); }
}

@media (max-width: 1023px) {
  #tool-grid.is-preview .editor-pane { display: none; }
  #tool-grid:not(.is-preview) .preview-pane { display: none; }
}

/* ============================== notices ============================= */
.notice {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 11px 14px; margin-bottom: 12px;
  border-radius: var(--radius); font-size: .88rem;
}
.notice--sample { background: var(--brand-soft); color: var(--brand-ink); }
.notice--warn { background: var(--warn-soft); color: var(--warn); }
.notice p { margin: 0; }
.notice .btn { margin-left: auto; }

/* ============================== editor ============================== */
.editor-pane { display: grid; gap: 12px; min-width: 0; }

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel > summary {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; cursor: pointer; list-style: none;
  font-weight: 650; letter-spacing: -.01em;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::after {
  content: ""; margin-left: auto; flex: none;
  width: 8px; height: 8px; border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted); transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .16s ease;
}
.panel[open] > summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
.panel > summary:hover { background: var(--surface-2); }
.panel-step {
  font-family: var(--font-mono); font-size: .7rem; color: var(--muted);
  background: var(--desk); border-radius: 4px; padding: 3px 6px; flex: none;
}
.panel-hint { font-weight: 400; font-size: .82rem; color: var(--muted); }
.panel-body { padding: 4px 16px 18px; border-top: 1px solid var(--line); }
.panel-body > * + * { margin-top: 14px; }

.grid-2 { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 560px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.grid-3 { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 560px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.span-2 { grid-column: 1 / -1; }

/* logo control */
.logo-control { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.logo-drop {
  width: 96px; height: 72px; flex: none;
  display: grid; place-items: center; text-align: center;
  border: 1px dashed var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--muted);
  font-family: var(--font-mono); font-size: .64rem; letter-spacing: .06em;
  text-transform: uppercase; padding: 6px;
}
#logo-preview { width: 96px; height: 72px; flex: none; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px; background: var(--surface); }
#logo-preview img { max-height: 60px; max-width: 84px; object-fit: contain; }
.logo-meta { min-width: 0; }
.logo-meta p { margin: 6px 0 0; font-size: .8rem; color: var(--muted); }
.file-btn { position: relative; overflow: hidden; }
.file-btn:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }
.file-btn input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0;
}

/* item rows */
.items { display: grid; gap: 10px; }
.item-row {
  display: grid; gap: 8px 10px; align-items: end;
  padding: 12px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "idx    actions"
    "desc   desc"
    "qty    rate"
    "amount amount";
}
.items--with-tax .item-row {
  grid-template-areas:
    "idx    actions"
    "desc   desc"
    "qty    rate"
    "tax    amount";
}
.item-row-index {
  grid-area: idx; font-family: var(--font-mono); font-size: .7rem;
  color: var(--muted); letter-spacing: .08em;
}
.item-row-index::before { content: "ITEM "; }
.field--desc { grid-area: desc; }
.field--qty { grid-area: qty; }
.field--rate { grid-area: rate; }
.field--tax { grid-area: tax; }
.field--amount { grid-area: amount; align-items: flex-end; text-align: right; }
.item-actions { grid-area: actions; display: flex; gap: 2px; justify-content: flex-end; }

.item-amount {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 1rem; font-weight: 600; padding: 8px 0 0;
}

@media (min-width: 700px) {
  .item-row {
    grid-template-columns: 22px minmax(0, 1fr) 84px 110px minmax(96px, auto) 76px;
    grid-template-areas: "idx desc qty rate amount actions";
    align-items: end; gap: 8px;
  }
  .items--with-tax .item-row {
    grid-template-columns: 22px minmax(0, 1fr) 72px 100px 74px minmax(90px, auto) 76px;
    grid-template-areas: "idx desc qty rate tax amount actions";
  }
  .item-row-index { padding-bottom: 11px; }
  .item-row-index::before { content: ""; }
  .item-actions { padding-bottom: 4px; }
  .field--amount { padding-bottom: 0; }
  .item-amount { padding-top: 0; padding-bottom: 8px; }
  /* Only the first row needs visible column headings. */
  .item-row:not(:first-child) .field-label:not(.sr-only) { display: none; }
  .item-row:not(:first-child) .field--amount .field-label { display: none; }
}

.charge-row {
  display: grid; gap: 8px; align-items: end;
  grid-template-columns: minmax(0, 1fr) 130px 32px;
  margin-bottom: 8px;
}

/* totals recap inside the editor */
.recap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; background: var(--ink); color: #fff;
  border-radius: var(--radius);
}
.recap-label {
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .1em;
  text-transform: uppercase; opacity: .7;
}
.recap-total {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em;
}
.recap-meta { font-family: var(--font-mono); font-size: .72rem; opacity: .65; }

/* template + colour pickers */
.template-picker { display: grid; gap: 8px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.template-option {
  display: grid; gap: 4px; padding: 10px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); font: inherit; color: var(--ink);
}
.template-option:hover { border-color: #a9b7c4; }
.template-option.is-active { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(11, 107, 91, .16); }
.template-option-name { font-weight: 600; font-size: .9rem; }
.template-option-hint { font-size: .74rem; color: var(--muted); line-height: 1.35; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  background: var(--swatch); border: 2px solid transparent;
  box-shadow: 0 0 0 1px var(--line-strong) inset;
}
.swatch.is-active { border-color: var(--surface); box-shadow: 0 0 0 2px var(--ink); }
.color-custom { display: flex; align-items: center; gap: 8px; }
.color-custom input[type="color"] {
  width: 40px; height: 32px; padding: 2px; cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface);
}

/* ============================== preview ============================= */
.preview-pane { min-width: 0; }
@media (min-width: 1024px) {
  .preview-pane { position: sticky; top: calc(var(--header-h) + 76px); }
}

.preview-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.preview-title {
  font-family: var(--font-mono); font-size: .7rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted);
}
.preview-actions { margin-left: auto; display: flex; gap: 8px; }

#sheet-viewport { overflow: hidden; }
#sheet-scaler { width: 794px; transform-origin: top left; }

.sheet {
  width: 794px; min-height: 1123px; /* A4 at 96dpi */
  padding: 46px 52px 56px;
  background: #fff; color: #141A21;
  font-size: 13px; line-height: 1.55;
  box-shadow: var(--shadow-lg); border-radius: 2px;
}

/* --------------------------- sheet shared -------------------------- */
.sheet-placeholder { color: #b3bcc6; }
.sheet-lines { color: #4a5561; font-size: 12.5px; }
.sheet-lines div { margin-bottom: 1px; }

.sheet-block-title {
  font-family: var(--font-mono); font-size: 9.5px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase; color: #6d7885;
  margin: 0 0 6px;
}
.sheet-biz-name { font-size: 17px; font-weight: 700; letter-spacing: -.01em; margin-bottom: 6px; }
.sheet-party-name { font-size: 14px; font-weight: 650; margin-bottom: 3px; }
.sheet-logo { margin-bottom: 12px; }
.sheet-logo img { max-height: 62px; max-width: 210px; object-fit: contain; }

.sheet-doctype {
  font-size: 30px; font-weight: 700; letter-spacing: -.03em;
  text-transform: uppercase; color: var(--accent); line-height: 1; margin-bottom: 14px;
}

.sheet-meta { margin: 0; display: grid; gap: 4px; }
.sheet-meta > div { display: flex; justify-content: space-between; gap: 18px; }
.sheet-meta dt { color: #6d7885; font-size: 11.5px; }
.sheet-meta dd {
  margin: 0; font-family: var(--font-mono); font-size: 11.5px;
  font-variant-numeric: tabular-nums; text-align: right;
}
.sheet-meta--stack > div { justify-content: flex-start; gap: 8px; }
.sheet-meta--stack dd { text-align: left; }

.sheet-head { display: flex; gap: 30px; justify-content: space-between; align-items: flex-start; }
.sheet-head-left { max-width: 58%; }
.sheet-head-right { min-width: 210px; text-align: right; }
.sheet-head-right .sheet-doctype { text-align: right; }

.sheet-rule { height: 2px; background: var(--accent); margin: 22px 0 20px; }

.sheet-parties { display: flex; gap: 26px; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.sheet-party { min-width: 0; max-width: 62%; }

.sheet-amount-due {
  min-width: 190px; text-align: right; padding: 12px 14px;
  background: #f6f8f9; border-left: 3px solid var(--accent); border-radius: 2px;
}
.sheet-amount-due-label {
  font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .12em;
  text-transform: uppercase; color: #6d7885;
}
.sheet-amount-due-value {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 21px; font-weight: 700; letter-spacing: -.02em; margin: 3px 0 2px;
  color: var(--accent);
}
.sheet-amount-due-date { font-size: 11px; color: #6d7885; }

/* items table */
.sheet-items { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.sheet-items th {
  font-family: var(--font-mono); font-size: 9.5px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: #6d7885;
  text-align: left; padding: 8px 8px; border-bottom: 1.5px solid #d7dee5;
}
.sheet-items td {
  padding: 9px 8px; border-bottom: 1px solid #edf1f4; vertical-align: top;
  font-size: 12.5px;
}
.sheet-items .col-idx { width: 26px; color: #97a2ad; font-family: var(--font-mono); font-size: 10.5px; }
.sheet-items .col-num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.sheet-items th.col-num { text-align: right; }
.sheet-items .col-amount { font-weight: 600; }
.sheet-items .col-desc { word-break: break-word; }
.w-idx { width: 30px; } .w-qty { width: 62px; } .w-rate { width: 92px; }
.w-tax { width: 62px; } .w-amount { width: 106px; }

/* totals */
.sheet-summary { display: flex; justify-content: flex-end; margin-bottom: 26px; }
.sheet-summary-inner { width: 300px; max-width: 100%; }
.sheet-total-row {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 5px 0; font-size: 12.5px; color: #4a5561;
}
.sheet-total-row span:last-child {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: #141A21;
}
.sheet-total-row.is-negative span:last-child { color: #7c6a2a; }

.sheet-grand {
  display: flex; justify-content: space-between; gap: 16px; align-items: baseline;
  margin-top: 8px; padding-top: 10px; border-top: 1.5px solid var(--accent);
  font-weight: 700;
}
.sheet-grand span:first-child { font-size: 12.5px; letter-spacing: -.01em; }
.sheet-grand span:last-child {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 19px; letter-spacing: -.02em; color: var(--accent);
}

/* blocks */
.sheet-block { margin-bottom: 18px; max-width: 480px; }
.sheet-para { margin: 0; font-size: 12px; color: #4a5561; line-height: 1.55; }
.sheet-para--muted { color: #6d7885; font-size: 11.5px; }
.sheet-pay-list { margin: 0 0 8px; display: grid; gap: 3px; }
.sheet-pay-list > div { display: flex; gap: 10px; font-size: 12px; }
.sheet-pay-list dt { color: #6d7885; min-width: 108px; }
.sheet-pay-list dd { margin: 0; font-family: var(--font-mono); font-size: 11.5px; word-break: break-word; }

/* ----------------------------- modern ----------------------------- */
.sheet--modern { padding-top: 0; }
.sheet-band {
  display: flex; gap: 30px; justify-content: space-between; align-items: flex-start;
  margin: 0 -52px 26px; padding: 40px 52px 34px;
  background: var(--accent); color: #fff;
}
.sheet-band .sheet-biz-name { color: #fff; }
.sheet-band-left { max-width: 58%; }
.sheet-lines--band { color: rgba(255, 255, 255, .82); }
.sheet-band-right { text-align: right; min-width: 200px; }
.sheet-doctype--band { color: rgba(255, 255, 255, .78); font-size: 15px; letter-spacing: .16em; margin-bottom: 6px; }
.sheet-band-number { font-family: var(--font-mono); font-size: 12px; color: rgba(255, 255, 255, .82); margin-bottom: 14px; }
.sheet-band-total {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 26px; font-weight: 700; letter-spacing: -.02em;
}
.sheet-band-due { font-size: 11px; color: rgba(255, 255, 255, .82); margin-top: 2px; }
.sheet-parties--modern { gap: 40px; }
.sheet-parties--modern .sheet-party { flex: 1; max-width: none; }
.sheet--modern .sheet-items th { background: #f4f7f8; border-bottom: 1px solid #e2e8ed; padding: 9px 8px; }
.sheet--modern .sheet-items th:first-child { border-radius: 3px 0 0 3px; }
.sheet--modern .sheet-items th:last-child { border-radius: 0 3px 3px 0; }
.sheet-summary-inner--card {
  padding: 14px 16px; background: #f6f8f9; border-radius: 6px;
}
.sheet-grand--filled {
  margin: 10px -16px -14px; padding: 12px 16px;
  background: var(--accent); color: #fff; border-top: 0;
  border-radius: 0 0 6px 6px;
}
.sheet-grand--filled span:last-child { color: #fff; }

/* ----------------------------- minimal ---------------------------- */
.sheet--minimal { padding: 60px 58px; font-size: 12.5px; }
.sheet-min-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 24px; padding-bottom: 18px; border-bottom: 1px solid #e6ebef;
}
.sheet--minimal .sheet-biz-name { font-size: 15px; font-weight: 600; margin: 0; }
.sheet-min-doc { text-align: right; }
.sheet-eyebrow {
  display: block; font-family: var(--font-mono); font-size: 9.5px;
  letter-spacing: .2em; text-transform: uppercase; color: var(--accent);
}
.sheet-min-number { font-family: var(--font-mono); font-size: 12px; color: #6d7885; }
.sheet-min-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px; margin: 24px 0 30px;
}
.sheet--minimal .sheet-items th { border-bottom: 1px solid #d7dee5; color: #8a95a1; }
.sheet--minimal .sheet-items td { border-bottom: 1px solid #f1f4f6; }
.sheet-summary--min .sheet-summary-inner { width: 260px; }
.sheet--minimal .sheet-grand { border-top: 1px solid #141A21; }
.sheet--minimal .sheet-grand span:last-child { color: #141A21; font-size: 17px; }
.sheet--minimal .sheet-logo img { max-height: 46px; }

/* ========================= saved invoices ========================== */
.saved-grid { display: grid; gap: 8px; }
.saved-row {
  display: grid; gap: 8px 12px; align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.saved-row:hover { border-color: var(--line-strong); background: var(--surface-2); }
.saved-main { display: grid; gap: 2px; min-width: 0; }
.saved-number { font-family: var(--font-mono); font-size: .82rem; color: var(--brand-ink); }
.saved-customer { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-dates { font-size: .78rem; color: var(--muted); }
.saved-total {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-weight: 700; text-align: right;
}
.saved-actions { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
@media (min-width: 620px) {
  .saved-row { grid-template-columns: minmax(0, 1fr) 120px auto; }
  .saved-actions { grid-column: auto; }
}

/* ========================== mobile action bar ====================== */
.mobile-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: none; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(8px); border-top: 1px solid var(--line);
}
.mobile-bar .btn { flex: 1; }
@media (max-width: 1023px) {
  .mobile-bar { display: flex; }
  body { padding-bottom: 68px; }
}

/* =============================== print ============================= */
@media print {
  @page { size: A4; margin: 12mm; }

  html, body { background: #fff !important; padding: 0 !important; margin: 0 !important; }

  /* Everything that is not the invoice is removed from the page. */
  .site-header, .site-footer, .hero, .toolbar, .editor-pane, .mobile-bar,
  .ad-slot, .content-section, .breadcrumbs, .toasts, .modal, .preview-head,
  .notice, .skip-link, #tool-grid > .editor-pane {
    display: none !important;
  }

  /* Belt and braces: hide anything left, then reveal only the sheet. */
  body * { visibility: hidden !important; }
  #invoice-sheet, #invoice-sheet * { visibility: visible !important; }

  .wrap { padding: 0 !important; max-width: none !important; }
  .tool { padding: 0 !important; }
  #tool-grid { display: block !important; }
  .preview-pane { position: static !important; display: block !important; width: 100% !important; }
  #sheet-viewport { overflow: visible !important; height: auto !important; }
  /* Stay in normal flow — absolutely positioned content does not paginate
     reliably, and a long invoice must be able to break across pages. */
  #sheet-scaler { transform: none !important; width: 100% !important; margin: 0 !important; }
  #invoice-sheet { position: static !important; width: 100% !important; }

  .sheet {
    width: 100% !important; min-height: 0 !important;
    padding: 0 !important; box-shadow: none !important; border-radius: 0 !important;
    font-size: 11pt; color: #000;
  }
  .sheet--minimal { padding: 0 !important; }
  .sheet-band { margin: 0 0 8mm !important; padding: 8mm !important; }
  .sheet--modern { padding-top: 0 !important; }

  /* Multi-page behaviour */
  .sheet-items thead { display: table-header-group; }
  .sheet-items tr { break-inside: avoid; page-break-inside: avoid; }
  .sheet-summary, .sheet-block, .sheet-amount-due { break-inside: avoid; page-break-inside: avoid; }
  .sheet-grand { break-inside: avoid; }

  /* Keep accent fills in the PDF where the browser allows it. */
  .sheet-band, .sheet-grand--filled, .sheet-rule, .sheet-amount-due,
  .sheet--modern .sheet-items th, .sheet-summary-inner--card {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}
