/* Phapur – editor + A4 sheet */
.editor-page { background: var(--paper-2); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.topbar { background: var(--white); border-bottom: 1px solid var(--line); padding: 12px 24px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 5; }
.topbar-left, .topbar-right { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; }
.logo-sm { font-size: 20px; gap: 8px; }
.divider { width: 1px; height: 24px; background: var(--line); }
.doc-title { font: 600 16px var(--body); letter-spacing: 0; }
.saved { font-size: 13px; color: var(--ink-2); }
.saved::before { content: "✓ "; color: #0F766E; font-weight: 700; }

.editor { display: flex; flex-wrap: wrap; align-items: flex-start; }
.panel { flex: 1 1 380px; max-width: 520px; min-width: 0; background: var(--white); border-right: 1px solid var(--line); padding: 24px; display: flex; flex-direction: column; gap: 28px; }
.panel fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel legend { font: 700 18px var(--head); margin-bottom: 12px; padding: 0; }
.panel label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; min-width: 0; }
.panel input:not([type=checkbox]):not([type=radio]):not([type=file]), .panel textarea, .panel select { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #A9A595; border-radius: 8px; font: 400 15px var(--body); color: var(--ink); background: var(--white); }
.panel textarea { resize: vertical; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1 1 0; }
.check { flex-direction: row !important; align-items: center; gap: 10px !important; font-size: 14px !important; font-weight: 500 !important; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); }

.swatches { display: flex; gap: 10px; }
.swatch { position: relative; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.swatch span { display: block; width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--white); box-shadow: 0 0 0 2px transparent; }
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--ink); }
.swatch input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 3px; }
.logo-row { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn { position: relative; overflow: hidden; flex-direction: row !important; font-size: 14px !important; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.item { display: grid; grid-template-columns: minmax(0, 1fr) 64px 96px 44px; gap: 8px; align-items: end; margin-bottom: 10px; }
.item input { padding-left: 8px !important; padding-right: 8px !important; }
.remove { width: 44px; height: 44px; border: 1px solid var(--line); background: var(--white); border-radius: 8px; cursor: pointer; font-size: 20px; line-height: 1; color: var(--ink-2); }
.remove:hover { border-color: var(--ink); color: var(--ink); }
.add { align-self: flex-start; border-style: dashed; }
.privacy-note { margin: 0; font-size: 13px; color: var(--ink-2); }

.preview { flex: 999 1 560px; min-width: 0; padding: 32px 24px 64px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.preview-label { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink-2); }

/* The A4 sheet. Sized in mm so print matches screen. */
.sheet { --doc: #2747D6; width: 210mm; min-height: 297mm; background: var(--white); box-shadow: 0 20px 50px -20px rgba(21,23,28,.4); padding: 18mm 16mm; display: flex; flex-direction: column; font-size: 10pt; line-height: 1.45; color: var(--ink); transform-origin: top center; }
.pre { white-space: pre-line; }
.inv-head { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 6mm; border-bottom: 1.2mm solid var(--doc); }
.inv-from img { max-height: 18mm; max-width: 60mm; object-fit: contain; margin-bottom: 3mm; }
.inv-biz { font: 700 16pt var(--head); }
.inv-muted { color: var(--ink-3); }
.inv-meta { text-align: right; }
.inv-word { font: 700 22pt var(--head); color: var(--doc); letter-spacing: .02em; }
.inv-meta dl { margin: 2mm 0 0; display: grid; grid-template-columns: auto auto; gap: 1mm 4mm; justify-content: end; color: var(--ink-3); }
.inv-meta dt { font-weight: 600; }
.inv-meta dd { margin: 0; color: var(--ink); }
.inv-to { margin: 8mm 0; }
.inv-label { font-size: 8pt; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.inv-client { font-weight: 600; font-size: 12pt; }
.inv-table { width: 100%; border-collapse: collapse; }
.inv-table th { text-align: left; font-weight: 600; padding: 2.5mm 0; border-bottom: .6mm solid var(--ink); }
.inv-table td { padding: 2.5mm 0; border-bottom: .2mm solid var(--line-2); vertical-align: top; }
.inv-table .num { text-align: right; padding-left: 4mm; white-space: nowrap; }
.inv-totals-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8mm; margin-top: 5mm; }
.paid-stamp { font: 700 22pt var(--head); letter-spacing: .12em; color: var(--doc); border: .8mm solid var(--doc); border-radius: 2mm; padding: 1.5mm 5mm; transform: rotate(-6deg); margin-top: 3mm; }
.inv-totals { margin: 0 0 0 auto; width: 70mm; display: flex; flex-direction: column; gap: 1.5mm; }
.inv-totals div { display: flex; justify-content: space-between; color: var(--ink-2); }
.inv-totals .grand { color: var(--ink); font-weight: 700; font-size: 13pt; padding-top: 2mm; border-top: .6mm solid var(--ink); }
.inv-foot { margin-top: auto; padding-top: 8mm; display: flex; flex-direction: column; gap: 2mm; color: var(--ink-2); }
.inv-foot > div:empty { display: none; }
#p-bank { padding: 3mm 4mm; background: #F3F2EE; color: var(--ink); }
.inv-reg { font-size: 8pt; color: var(--ink-3); }

.dialog-backdrop { position: fixed; inset: 0; background: rgba(21,23,28,.5); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 20; }
.dialog-backdrop[hidden] { display: none; }
.dialog { background: var(--white); border-radius: 14px; padding: 28px; max-width: 480px; display: flex; flex-direction: column; gap: 14px; }
.dialog h2 { font-size: 24px; }
.dialog p { margin: 0; color: var(--ink-2); }

/* Segmented control */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--paper-2); border-radius: 10px; }
.seg label { position: relative; flex-direction: row !important; font-size: 14px !important; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.seg input:checked + span { background: var(--white); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 1px; }
.hint { margin: 0; font-size: 13px; color: var(--ink-2); }
#letter-fields { display: flex; flex-direction: column; gap: 12px; }

/* Letterhead */
.lh { padding: 16mm 18mm 12mm; font-size: 10.5pt; }
.lh-head { display: flex; gap: 6mm; align-items: flex-start; padding-bottom: 6mm; border-bottom: .8mm solid var(--doc); }
.lh-logo { max-height: 18mm; max-width: 50mm; object-fit: contain; }
.lh-id { flex: 1; min-width: 0; }
.lh-biz { font: 700 17pt var(--head); color: var(--ink); }
.lh-addr { color: var(--ink-3); font-size: 9pt; margin-top: 1.5mm; }
.lh-contact { text-align: right; font-size: 9pt; color: var(--ink-2); line-height: 1.6; }
.lh-letter { margin-top: 14mm; display: flex; flex-direction: column; }
.lh-letter p { margin: 0 0 5mm; }
.lh-date { margin: 8mm 0 8mm; }
.lh-text { margin-bottom: 6mm; }
.lh-sig { margin-top: 14mm; display: flex; flex-direction: column; }
.lh-sig span { color: var(--ink-3); }
.lh-foot { margin-top: auto; padding-top: 4mm; border-top: .2mm solid var(--line); font-size: 7.5pt; color: var(--ink-3); text-align: center; }
.lh-foot:empty { border: 0; }
.lh[data-layout="centred"] .lh-head { flex-direction: column; align-items: center; text-align: center; gap: 3mm; }
.lh[data-layout="centred"] .lh-contact { text-align: center; display: flex; gap: 0 5mm; flex-wrap: wrap; justify-content: center; }
.lh[data-layout="band"] { padding-top: 0; }
.lh[data-layout="band"] .lh-head { margin: 0 -18mm; padding: 10mm 18mm 8mm; background: var(--doc); border: 0; color: #FFFFFF; }
.lh[data-layout="band"] .lh-biz { color: #FFFFFF; }
.lh[data-layout="band"] .lh-addr, .lh[data-layout="band"] .lh-contact { color: rgba(255,255,255,.85); }
.lh[data-layout="band"] .lh-logo { background: #FFFFFF; padding: 2mm; border-radius: 2mm; }

/* Business card */
.bc-stage { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 8px; }
.bc-wrap { width: calc(85mm * 1.5); height: calc(55mm * 1.5); }
.bc-wrap .bc { transform: scale(1.5); transform-origin: top left; box-shadow: 0 6px 18px rgba(21,23,28,.18); }
.bc { --doc: #2747D6; width: 85mm; height: 55mm; padding: 5mm; background: #FFFFFF; color: var(--ink); display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; font-size: 7pt; line-height: 1.4; border-radius: 0; }
.bc-top { display: flex; align-items: center; gap: 2.5mm; }
.bc-logo { max-height: 9mm; max-width: 28mm; object-fit: contain; }
.bc-biz { font: 700 9pt var(--head); }
.bc-name { font: 700 12pt var(--head); letter-spacing: -.01em; }
.bc-title { color: var(--doc); font-weight: 600; margin-bottom: 2mm; }
.bc-lines { color: var(--ink-2); }
.bc[data-style="dark"] { background: var(--ink); color: #FFFFFF; }
.bc[data-style="dark"] .bc-lines { color: #C9CBD1; }
.bc[data-style="dark"] .bc-title { color: #FFFFFF; opacity: .8; }
.bc[data-style="accent"] { background: var(--doc); color: #FFFFFF; }
.bc[data-style="accent"] .bc-lines { color: rgba(255,255,255,.88); }
.bc[data-style="accent"] .bc-title { color: #FFFFFF; opacity: .85; }
.bc-back { align-items: center; justify-content: center; text-align: center; gap: 2mm; background: var(--doc); color: #FFFFFF; }
.bc-back[data-style="accent"] { background: var(--ink); }
.bc-logo-back { max-height: 18mm; max-width: 50mm; object-fit: contain; background: #FFFFFF; padding: 2mm; border-radius: 1.5mm; }
.bc-back-biz { font: 700 14pt var(--head); }
.bc-tagline { font-size: 7.5pt; opacity: .9; }
#print-area { display: none; }
@media (max-width: 520px) { .bc-wrap { width: calc(85mm * 1.1); height: calc(55mm * 1.1); } .bc-wrap .bc { transform: scale(1.1); } }

@media print {
  body.print-cards .editor, body.print-cards .site-footer, body.print-cards .topbar { display: none !important; }
  body.print-cards #print-area { display: block; }
  #print-area .bc { box-shadow: none; transform: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .bc-page { width: 91mm; height: 61mm; padding: 3mm; break-after: page; background: #FFFFFF; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .bc-page[data-style="dark"][data-side="front"] { background: var(--ink); }
  .bc-page[data-style="accent"][data-side="front"] { background: var(--doc); }
  .bc-page[data-side="back"] { background: var(--doc); }
  .bc-page[data-style="accent"][data-side="back"] { background: var(--ink); }
  .bc-sheet { width: 210mm; height: 297mm; padding: 11mm 20mm; display: grid; grid-template-columns: repeat(2, 85mm); grid-auto-rows: 55mm; break-after: page; }
  .bc-sheet .bc { outline: .1mm solid #BDBAB0; outline-offset: 0; }
}

/* Price list */
.pl-sec-edit { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.pl-sec-head { display: flex; gap: 8px; align-items: flex-end; }
.pl-sec-head label { flex: 1; }
.pl-item-edit { display: grid; grid-template-columns: minmax(0, 1fr) 110px 44px; gap: 8px; align-items: end; padding-top: 10px; border-top: 1px dashed var(--line); }
.pl-item-edit .full { grid-column: 1 / -1; }
.pl { padding: 18mm 20mm; font-size: 10.5pt; }
.pl-head { text-align: center; padding-bottom: 7mm; margin-bottom: 7mm; border-bottom: .8mm solid var(--doc); display: flex; flex-direction: column; align-items: center; gap: 1.5mm; }
.pl-logo { max-height: 20mm; max-width: 60mm; object-fit: contain; margin-bottom: 2mm; }
.pl-biz { font-size: 9pt; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); }
.pl-title { font: 700 26pt var(--head); color: var(--doc); margin: 0; }
.pl-sub { color: var(--ink-2); }
.pl-sub:empty { display: none; }
.pl-body { flex: 1; }
.pl[data-layout="two"] .pl-body { columns: 2; column-gap: 10mm; }
.pl-sec { break-inside: avoid-column; margin-bottom: 7mm; }
.pl-sec-name { font: 700 13pt var(--head); margin: 0 0 3mm; padding-bottom: 1.5mm; border-bottom: .3mm solid var(--line); }
.pl-item { margin-bottom: 2.5mm; break-inside: avoid; }
.pl-line { display: flex; align-items: baseline; gap: 2mm; font-weight: 600; }
.pl-dots { flex: 1; border-bottom: .3mm dotted #A9A595; transform: translateY(-1mm); min-width: 6mm; }
.pl-price { white-space: nowrap; }
.pl-desc { color: var(--ink-3); font-size: 9pt; margin-top: .5mm; max-width: 85%; }
.pl-foot { margin-top: 8mm; padding-top: 4mm; border-top: .3mm solid var(--line); text-align: center; color: var(--ink-2); font-size: 9pt; display: flex; flex-direction: column; gap: 1.5mm; }
.pl-contact { font-weight: 600; color: var(--ink); }
@media print {
  body.print-flow .sheet { height: auto !important; min-height: 0; overflow: visible !important; padding-top: 4mm; padding-bottom: 4mm; }
}

/* QR on business card */
.bc { position: relative; }
.bc-qr { position: absolute; right: 5mm; bottom: 5mm; width: 17mm; height: 17mm; }
.bc-qr svg { width: 100%; height: 100%; display: block; }

/* Compliments slip */
.slip { --doc: #2747D6; position: relative; width: 210mm; height: 99mm; background: #FFFFFF; box-shadow: 0 20px 50px -20px rgba(21,23,28,.4); padding: 12mm 14mm 0; display: flex; flex-direction: column; transform-origin: top center; }
.slip-bar { position: absolute; left: 0; right: 0; top: 0; height: 2.5mm; background: var(--doc); }
.slip-head { display: flex; align-items: center; gap: 5mm; }
.slip-logo { max-height: 14mm; max-width: 45mm; object-fit: contain; }
.slip-biz { flex: 1; font: 700 13pt var(--head); }
.slip-contact { text-align: right; font-size: 8.5pt; color: var(--ink-2); line-height: 1.5; }
.slip-heading { margin-top: 8mm; font: 700 24pt var(--head); color: var(--doc); }
.slip-msg { margin-top: 2mm; font-size: 10pt; color: var(--ink-2); max-width: 120mm; white-space: pre-line; }
.slip-foot { margin-top: auto; padding: 2mm 0 3mm; border-top: .2mm solid var(--line); font-size: 8pt; color: var(--ink-3); display: flex; flex-direction: column; gap: .5mm; }
@media print { .slip { box-shadow: none; transform: none !important; margin: 0; -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

@media (max-width: 900px) {
  .topbar { position: static; }
  .panel { max-width: none; border-right: 0; border-bottom: 1px solid var(--line); }
}

@media print {
  @page { size: A4; margin: 0; }
  html, body { background: #FFFFFF !important; }
  .no-print { display: none !important; }
  .editor, .preview { display: block; padding: 0; margin: 0; }
  .sheet { box-shadow: none; transform: none !important; margin: 0; width: 210mm; height: 297mm; min-height: 0; overflow: hidden; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* My documents */
.docs-head { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-end; justify-content: space-between; margin-bottom: 28px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 28px; }
.stat { background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }
.stat span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.stat strong { font: 700 28px var(--head); }
.stat em { font-style: normal; font-size: 13px; color: var(--ink-2); }
.stat.alert { border-color: #B42318; }
.stat.alert strong { color: #B42318; }
.docs-tools { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.search input { min-height: 44px; width: 280px; max-width: 100%; padding: 0 14px; border: 1px solid #A9A595; border-radius: 10px; font: 400 15px var(--body); background: var(--white); }
.table-box { background: var(--white); border: 1px solid var(--line); border-radius: 14px; overflow-x: auto; }
.docs-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.docs-table th { text-align: left; font-size: 13px; color: var(--ink-2); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.docs-table td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.docs-table tr:last-child td { border-bottom: 0; }
.docs-table .num { text-align: right; white-space: nowrap; }
.docs-table small { display: block; color: var(--ink-2); font-size: 12px; }
.doc-link { font-weight: 600; text-decoration: underline; white-space: nowrap; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; align-items: center; }
.row-actions .btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-quiet { border-color: transparent; color: var(--ink-2); }
.btn-danger { background: #B42318; border-color: #B42318; color: #FFFFFF; }
.btn-danger:hover { background: #8F1C13; color: #FFFFFF; }
.sure { font-size: 13px; font-weight: 600; color: #B42318; }
.pill { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill-paid { background: #DCF2E8; color: #0B5D3B; }
.pill-open { background: #ECEAE3; color: var(--ink); }
.pill-overdue { background: #FDE4E1; color: #9A1C11; }
.empty { padding: 32px 20px; margin: 0; text-align: center; color: var(--ink-2); }
.empty a { text-decoration: underline; }
.backup { margin-top: 40px; padding: 24px; border: 1px dashed #A9A595; border-radius: 14px; }
.backup h2 { font-size: 22px; margin-bottom: 8px; }
.backup p { margin: 0 0 14px; color: var(--ink-2); }
@media (max-width: 760px) {
  .docs-table thead { display: none; }
  .docs-table tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
  .docs-table td { padding: 0; border: 0; }
  .docs-table .row-actions { grid-column: 1 / -1; justify-content: flex-start; margin-top: 8px; }
}
