body.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); flex: none; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.btn-wa { background: #25d366; color: #073b1c; }
.btn-wa:hover { background: #1fbe5a; }
.count { background: var(--brand-soft); color: var(--brand-ink); border-radius: 99px; padding: 1px 7px; font-size: 12px; }
.count:empty { display: none; }

.seg { display: inline-flex; background: #efede7; border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; font: 600 14px var(--font); padding: 7px 14px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.seg-full { display: flex; margin: 16px 0 10px; }
.seg-full button { flex: 1; }

.mobile-tabs, .mobile-actions { display: none; }

.workspace { flex: 1; display: grid; grid-template-columns: minmax(380px, 500px) 1fr; min-height: 0; }
.editor { overflow-y: auto; padding: 18px; border-right: 1px solid var(--line); display: grid; gap: 14px; align-content: start; }
.preview-pane { overflow: auto; padding: 28px 24px 60px; background: #e9e7e0; }
.paper-scaler { width: 794px; transform-origin: top left; margin: 0 auto; }

/* ── Editor ── */
.panel { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 14px 16px 16px; margin: 0; display: grid; gap: 10px; min-width: 0; }
.panel legend { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 0 6px; margin-left: -6px; }
.editor label { display: grid; gap: 4px; font-size: 13px; font-weight: 500; color: var(--muted); min-width: 0; }
.editor label em { font-style: normal; opacity: .7; }
.editor input:not([type=checkbox]):not([type=file]), .editor select, .editor textarea {
  font: 15px var(--font); color: var(--ink); background: #fbfaf7; border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; width: 100%; min-width: 0;
}
.editor input[type=color] { padding: 3px; height: 40px; cursor: pointer; }
.editor textarea { resize: vertical; }
.editor ::placeholder { color: #b3b0a7; }
.editor input:focus, .editor select:focus, .editor textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; background: #fff; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 10px; }
[hidden] { display: none !important; }

.toggles { display: flex; gap: 18px; flex-wrap: wrap; }
.switch { display: inline-flex !important; grid-template-columns: none; align-items: center; gap: 9px !important; cursor: pointer; color: var(--ink) !important; font-size: 14px !important; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 36px; height: 21px; border-radius: 99px; background: #d7d4cb; position: relative; transition: background .15s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(15px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

.logo-row { display: flex; align-items: center; gap: 14px; }
.logo-drop { position: relative; width: 120px; height: 64px; border: 1.5px dashed #cbc7bb; border-radius: 10px; display: grid; place-items: center; font-size: 13px; color: var(--muted); overflow: hidden; background: #fbfaf7; }
.logo-drop:hover { border-color: var(--brand); color: var(--brand); }
.logo-drop img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.linkish { background: none; border: 0; color: var(--danger); cursor: pointer; font: 13px var(--font); padding: 0; }

.item { display: grid; grid-template-columns: 76px 1fr 1fr 30px; grid-template-areas: "d d d rm" "q p a a"; gap: 6px; align-items: center; background: #fbfaf7; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.item .desc { grid-area: d; } .item .qty { grid-area: q; } .item .price { grid-area: p; } .item .amt { grid-area: a; } .item .rm { grid-area: rm; }
#items { display: grid; gap: 8px; }
.item .amt { text-align: right; font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 4px; }
.item input { padding: 8px !important; background: #fff !important; }
.item input[type=number] { text-align: right; }
.item .rm { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; border-radius: 6px; height: 32px; }
.item .rm:hover { color: var(--danger); background: #fbeae6; }
.add-item { justify-self: start; }
.editor-totals { display: grid; gap: 3px; border-top: 1px solid var(--line); padding-top: 10px; font-size: 14px; }
.editor-totals div { display: flex; justify-content: space-between; color: var(--muted); }
.editor-totals .grand { color: var(--ink); font-weight: 700; font-size: 17px; }

.convert-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--brand-soft); border: 1px solid #bfe0d2; border-radius: 12px; padding: 10px 14px; font-size: 14px; font-weight: 500; }
.privacy { font-size: 13px; color: var(--muted); margin: 4px 2px 30px; }

/* ── The invoice paper ── */
.paper { --accent: #0b7a5c; width: 794px; min-height: 1123px; background: #fff; box-shadow: 0 10px 40px rgba(20,22,26,.12); padding: 56px 60px 48px; font-size: 13px; line-height: 1.5; color: #1d1f23; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.p-bar { position: absolute; left: 0; right: 0; top: 0; height: 8px; background: var(--accent); }
.p-head { display: flex; justify-content: space-between; gap: 30px; align-items: flex-start; }
.p-logo { max-width: 200px; max-height: 80px; object-fit: contain; display: block; margin-bottom: 12px; }
.p-biz { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.p-small { color: #5d6168; white-space: pre-line; }
.p-title { text-align: right; }
.p-title h1 { font: 700 28px var(--font); letter-spacing: .08em; color: var(--accent); margin: 0 0 10px; }
.p-meta { border-collapse: collapse; margin-left: auto; }
.p-meta td { padding: 2px 0 2px 16px; text-align: right; }
.p-meta td:first-child { color: #8a8d93; }
.p-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin: 40px 0 28px; }
.p-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: #8a8d93; font-weight: 700; margin-bottom: 6px; }
.p-client { font-size: 15px; font-weight: 600; }
.p-items { width: 100%; border-collapse: collapse; }
.p-items th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: #8a8d93; padding: 0 0 8px; border-bottom: 2px solid var(--accent); }
.p-items td { padding: 11px 0; border-bottom: 1px solid #eceae4; vertical-align: top; }
.p-items .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 14px; }
.p-items .d { white-space: pre-line; }
.p-empty { color: #b0b2b6; font-style: italic; }
.p-sum { display: flex; justify-content: flex-end; margin-top: 18px; }
.p-sum table { border-collapse: collapse; min-width: 290px; }
.p-sum td { padding: 5px 0; font-variant-numeric: tabular-nums; }
.p-sum td:last-child { text-align: right; padding-left: 30px; }
.p-sum .muted { color: #6f7278; }
.p-sum .total td { background: var(--accent); color: #fff; font-weight: 700; font-size: 17px; padding: 11px 14px; }
.p-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 40px; }
.p-box { background: #f7f6f2; border-radius: 8px; padding: 14px 16px; }
.p-box table { border-collapse: collapse; }
.p-box td { padding: 1px 0; }
.p-box td:first-child { color: #8a8d93; padding-right: 14px; }
.p-notes { white-space: pre-line; color: #4a4d53; }
.p-foot { margin-top: auto; padding-top: 30px; text-align: center; font-size: 11px; color: #a3a5a9; }
.p-foot b { color: #6f7278; }
.p-stamp { position: absolute; top: 150px; right: 70px; border: 4px solid #1f9d55; color: #1f9d55; font: 800 38px var(--font); letter-spacing: .12em; padding: 4px 18px; border-radius: 8px; transform: rotate(-14deg); opacity: .8; }

/* ── Drawer ── */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(20,22,26,.35); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100%); background: var(--bg); z-index: 21; padding: 20px; overflow-y: auto; box-shadow: -10px 0 40px rgba(0,0,0,.15); display: flex; flex-direction: column; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.drawer-head h2 { font-size: 26px; margin: 0; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.kpi b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi.warn b { color: var(--danger); }
.doc-list { display: grid; gap: 8px; flex: 1; align-content: start; }
.doc { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 8px; }
.doc.current { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.doc-top { display: flex; justify-content: space-between; gap: 10px; cursor: pointer; }
.doc-top b { display: block; }
.doc-top small { color: var(--muted); }
.doc-amt { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.doc-actions button { font: 500 12.5px var(--font); border: 1px solid var(--line); background: #fbfaf7; border-radius: 7px; padding: 5px 9px; cursor: pointer; color: var(--ink); }
.doc-actions button:hover { border-color: var(--ink); }
.doc-actions .del:hover { border-color: var(--danger); color: var(--danger); }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; text-transform: uppercase; letter-spacing: .04em; }
.pill.paid { background: #dff3e7; color: #17744a; }
.pill.unpaid { background: #fff2d9; color: #8a5a00; }
.pill.overdue { background: #fbe3de; color: var(--danger); }
.pill.quote { background: #e6eaf5; color: #3b4f86; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.upsell { display: block; margin-top: 18px; background: var(--ink); color: #d8d6cf; text-decoration: none; border-radius: 14px; padding: 16px 18px; font-size: 14px; }
.upsell b { display: block; color: var(--sun); font-size: 16px; margin-bottom: 2px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; z-index: 30; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast a { color: var(--sun); }

@media (max-width: 1080px) { .hide-md { display: none; } }
@media (max-width: 900px) {
  .hide-sm { display: none; }
  .topbar { gap: 10px; padding: 10px 12px; }
  .mobile-tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--line); }
  .mobile-tabs button { flex: 1; border: 0; background: none; padding: 11px; font: 600 14px var(--font); color: var(--muted); border-bottom: 2px solid transparent; }
  .mobile-tabs button.on { color: var(--brand-ink); border-bottom-color: var(--brand); }
  .workspace { grid-template-columns: 1fr; }
  .workspace[data-view=edit] .preview-pane, .workspace[data-view=preview] .editor { display: none; }
  .editor { border-right: 0; padding: 14px 14px 90px; }
  .topbar #btn-wa, .topbar #btn-pdf, .topbar #btn-email { display: none; }
  .mobile-actions { display: grid; grid-template-columns: auto 1fr 1fr; gap: 8px; position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.94); backdrop-filter: blur(8px); border-top: 1px solid var(--line); z-index: 10; }
  .preview-pane { padding-bottom: 90px !important; }
  .preview-pane { padding: 16px; }
}
@media (max-width: 520px) {
  .hide-xs { display: none; }
  .seg button { padding: 7px 10px; }
  .row-3 { grid-template-columns: 1fr 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
}

/* ── Print: only the paper, true A4 ── */
@page { size: A4; margin: 0; }
@media print {
  html, body.app { height: auto; overflow: visible; background: #fff; display: block; }
  .topbar, .mobile-tabs, .mobile-actions, .editor, .drawer, .drawer-backdrop, .toast { display: none !important; }
  .workspace { display: block; }
  .preview-pane { display: block !important; padding: 0; background: #fff; overflow: visible; }
  .paper-scaler { transform: none !important; width: auto; height: auto !important; margin: 0; }
  .paper { box-shadow: none; width: 210mm; min-height: 296mm; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
