/* Tallyleaf — site + editor + document templates */
:root {
  --brand: #1f6f54;
  --brand-ink: #134a37;
  --brand-soft: #e3efe9;
  --gold: #d69e2e;
  --ink: #17201b;
  --muted: #5d6a63;
  --line: #dfe4df;
  --bg: #f6f7f3;
  --card: #ffffff;
  --field: #ffffff;
  --danger: #b42318;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 32, 24, .06), 0 8px 24px rgba(16, 32, 24, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #3fa47f; --brand-ink: #8fd8bb; --brand-soft: #18332a; --ink: #e8eee9; --muted: #9fb0a7;
    --line: #2b3732; --bg: #101614; --card: #161e1b; --field: #1b2521;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 var(--font); color: var(--ink); background: var(--bg); }
body.locked { overflow: hidden; }
a { color: var(--brand); }
img { max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 760px; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }

/* header / footer */
.site-header { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.site-header .wrap { display: flex; align-items: center; gap: 16px; min-height: 60px; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 750; font-size: 20px; letter-spacing: -.02em; }
.logo img { width: 32px; height: 32px; }
.nav { display: flex; gap: 4px; margin-left: auto; align-items: center; flex-wrap: wrap; }
.nav a { color: var(--ink); text-decoration: none; padding: 8px 10px; border-radius: 8px; font-size: 15px; }
.nav a:hover { background: var(--brand-soft); }
.nav .pro-link { color: var(--brand-ink); font-weight: 650; }
.is-pro .pro-link::after { content: " ✓"; }
@media (max-width: 720px) { .nav a.hide-sm { display: none; } }
.site-footer { margin-top: 64px; border-top: 1px solid var(--line); background: var(--card); padding: 32px 0; font-size: 14px; color: var(--muted); }
.foot-grid { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 24px; }
.foot-grid h4 { margin: 0 0 8px; color: var(--ink); font-size: 14px; }
.foot-grid ul { list-style: none; margin: 0; padding: 0; }
.foot-grid li { margin: 4px 0; }
.foot-grid a { color: var(--muted); text-decoration: none; }
.foot-grid a:hover { color: var(--brand); }
@media (max-width: 720px) { .foot-grid { grid-template-columns: 1fr 1fr; } .foot-grid > :first-child { grid-column: 1 / -1; } }

/* hero */
.hero { padding: 28px 0 12px; }
.hero h1 { font-size: clamp(26px, 4vw, 38px); line-height: 1.15; margin: 0 0 8px; letter-spacing: -.02em; }
.hero p { margin: 0; color: var(--muted); max-width: 760px; }
.trust { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 12px 0 0; padding: 0; list-style: none; font-size: 14px; color: var(--muted); }
.trust li::before { content: "✓ "; color: var(--brand); font-weight: 700; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--brand); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #06140e; } .btn-primary:hover { color: #06140e; } }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #1d1503; }
.btn-lg { min-height: 48px; padding: 10px 22px; font-size: 17px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.icon-btn:hover { color: var(--danger); border-color: var(--line); }
.linkish { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; font-size: 14px; cursor: pointer; text-decoration: underline; }

/* tool */
.tool { margin-top: 12px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow); }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font: inherit; font-size: 15px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.toolbar .spacer { flex: 1; }
.toolbar select { min-height: 40px; }
.mobile-tabs { display: none; }
.workspace { display: grid; grid-template-columns: minmax(340px, 440px) minmax(0, 1fr); gap: 18px; margin-top: 14px; align-items: start; }
.editor { display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h2 { font-size: 15px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field + .field, .grid2 + .field, .field + .grid2, .grid2 + .grid2 { margin-top: 10px; }
input, select, textarea { width: 100%; font: inherit; font-size: 15px; color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; min-height: 40px; }
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
input[type="color"] { padding: 3px; width: 56px; cursor: pointer; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > select { width: auto; }
.logo-row { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.logo-box { width: 84px; height: 64px; border: 1.5px dashed var(--line); border-radius: 10px; display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 13px; cursor: pointer; background: var(--bg); }
.logo-box img { max-height: 100%; max-width: 100%; object-fit: contain; }
.logo-row label:hover .logo-box { border-color: var(--brand); }
.items { display: grid; gap: 10px; }
.item-row { display: grid; grid-template-columns: 64px 1fr 1fr 32px; grid-template-areas: "desc desc desc del" "qty rate amt amt"; gap: 6px 8px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.item-row .it-desc { grid-area: desc; }
.item-row textarea { min-height: 40px; }
.item-row .it-qty { grid-area: qty; }
.item-row .it-rate { grid-area: rate; }
.item-row .it-amount { grid-area: amt; align-self: end; text-align: right; font-weight: 650; padding-bottom: 9px; font-variant-numeric: tabular-nums; }
.item-row .icon-btn { grid-area: del; justify-self: end; }
.item-row label { display: grid; gap: 2px; }
.mini { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.add-item { margin-top: 10px; width: 100%; border-style: dashed; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; font-weight: 400; }
.pro-tag { font-size: 11px; font-weight: 700; color: #1d1503; background: var(--gold); border-radius: 999px; padding: 2px 8px; letter-spacing: .04em; text-transform: uppercase; }
.is-pro .pro-tag { display: none; }

.preview-col { position: sticky; top: 76px; min-width: 0; }
.preview-wrap { position: relative; overflow: hidden; }
.after-download { margin-top: 12px; background: var(--brand-soft); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; }
.after-download p { margin: 4px 0; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .preview-col { position: static; }
  .mobile-tabs { display: flex; gap: 6px; margin-top: 12px; }
  .mobile-tabs button { flex: 1; min-height: 42px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; font: inherit; font-weight: 650; color: var(--muted); }
  .mobile-tabs button[aria-selected="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }
  .tool:not([data-view="preview"]) .preview-col { display: none; }
  .tool[data-view="preview"] .editor { display: none; }
  .toolbar .spacer { display: none; }
}

/* ---------------- the document (paper) ---------------- */
.paper {
  --accent: #1f6f54;
  width: 210mm; min-height: 297mm; padding: 16mm 15mm 22mm; position: relative; transform-origin: top left;
  background: #fff; color: #1d2320; font: 10.5pt/1.45 var(--font); box-shadow: 0 2px 10px rgba(0,0,0,.12), 0 20px 40px rgba(0,0,0,.08);
  border-radius: 4px; overflow: hidden; color-scheme: light;
}
.paper.paper-letter { width: 215.9mm; min-height: 279.4mm; }
.paper .ph { color: #a6aeaa; font-weight: 500; }
.p-head { display: flex; justify-content: space-between; gap: 10mm; align-items: flex-start; }
.p-brand { display: flex; flex-direction: column; gap: 4mm; max-width: 55%; }
.p-logo { max-width: 48mm; max-height: 22mm; object-fit: contain; align-self: flex-start; }
.p-from { color: #4c5652; font-size: 9.5pt; }
.p-name { display: block; font-size: 12.5pt; color: #1d2320; margin-bottom: 1mm; }
.p-title { text-align: right; }
.p-title h2 { margin: 0 0 4mm; font-size: 26pt; letter-spacing: .02em; color: var(--accent); text-transform: uppercase; font-weight: 800; line-height: 1; }
.p-meta { margin: 0; display: grid; gap: 1mm; font-size: 9.5pt; }
.p-meta div { display: flex; justify-content: flex-end; gap: 4mm; }
.p-meta dt { color: #6a746f; }
.p-meta dd { margin: 0; font-weight: 650; min-width: 26mm; }
.p-label { font-size: 8pt; text-transform: uppercase; letter-spacing: .1em; color: #6a746f; font-weight: 700; margin-bottom: 1.5mm; }
.p-to { margin: 11mm 0 7mm; font-size: 10pt; }
.p-to strong { font-size: 11.5pt; }
.p-items { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.p-items th { font-size: 8.5pt; text-transform: uppercase; letter-spacing: .08em; text-align: left; padding: 2.5mm 2mm; border-bottom: 2px solid var(--accent); color: #39423e; }
.p-items td { padding: 2.6mm 2mm; border-bottom: 1px solid #e6e9e7; vertical-align: top; }
.p-items .n { text-align: right; white-space: nowrap; width: 1%; padding-left: 6mm; }
.p-items tr { break-inside: avoid; }
.p-items .empty td { color: #a6aeaa; text-align: center; padding: 8mm; font-style: italic; }
.p-sum { margin: 5mm 0 0 auto; width: 78mm; font-variant-numeric: tabular-nums; break-inside: avoid; }
.sum-row { display: flex; justify-content: space-between; padding: 1.6mm 2mm; }
.sum-row.grand { margin-top: 2mm; padding: 3mm; background: var(--accent); color: #fff; font-weight: 800; font-size: 12.5pt; border-radius: 2mm; }
.p-notes { margin-top: 8mm; font-size: 9.5pt; color: #3b4440; break-inside: avoid; }
.p-footer { position: absolute; left: 15mm; right: 15mm; bottom: 8mm; text-align: center; font-size: 8pt; color: #8b948f; border-top: 1px solid #eef0ee; padding-top: 2.5mm; }
.stamp { position: absolute; top: 58mm; right: 22mm; transform: rotate(-14deg); border: 3px solid #1f8a5b; color: #1f8a5b; font-weight: 900; font-size: 22pt;
  letter-spacing: .15em; padding: 1mm 5mm; border-radius: 3mm; opacity: .75; }
.pro-ribbon { position: absolute; top: 9mm; right: -16mm; transform: rotate(35deg); background: var(--gold); color: #1d1503; font-weight: 800; font-size: 8pt;
  padding: 1.5mm 18mm; letter-spacing: .08em; text-transform: uppercase; z-index: 2; }

/* template: minimal */
.t-minimal .p-title h2 { color: #1d2320; font-weight: 300; font-size: 24pt; letter-spacing: .2em; }
.t-minimal .p-items th { border-bottom: 1px solid #1d2320; }
.t-minimal .sum-row.grand { background: none; color: #1d2320; border-top: 1.5px solid #1d2320; border-radius: 0; }
/* template: bold (Pro) */
.t-bold { padding-top: 0; }
.t-bold .p-head { background: var(--accent); color: #fff; margin: 0 -15mm; padding: 14mm 15mm 10mm; }
.t-bold .p-head .p-from, .t-bold .p-head .p-name, .t-bold .p-meta dt, .t-bold .p-head .ph { color: rgba(255,255,255,.88); }
.t-bold .p-title h2 { color: #fff; }
.t-bold .p-items th { background: color-mix(in srgb, var(--accent) 10%, white); border-bottom: 0; }
/* template: split (Pro) */
.t-split::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6mm; background: var(--accent); }
.t-split .p-to { background: color-mix(in srgb, var(--accent) 7%, white); padding: 5mm; border-radius: 2mm; }
.t-split .p-items th { color: var(--accent); }
.t-split .sum-row.grand { border-radius: 0; }
/* template: elegant (Pro) */
.t-elegant { font-family: Georgia, "Times New Roman", serif; }
.t-elegant .p-head { flex-direction: column; align-items: center; text-align: center; border-bottom: 1px solid var(--accent); padding-bottom: 6mm; }
.t-elegant .p-brand { align-items: center; max-width: none; }
.t-elegant .p-logo { align-self: center; }
.t-elegant .p-title { text-align: center; }
.t-elegant .p-title h2 { font-weight: 400; font-style: italic; text-transform: none; letter-spacing: .04em; }
.t-elegant .p-meta div { justify-content: center; }
.t-elegant .p-meta dd { min-width: 0; }
.t-elegant .p-items th { border-bottom: 1px solid var(--accent); color: var(--accent); }
.t-elegant .sum-row.grand { background: none; color: var(--accent); border-top: 1px solid var(--accent); border-bottom: 1px solid var(--accent); border-radius: 0; }
/* template: mono (Pro) */
.t-mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 9.5pt; }
.t-mono .p-title h2 { font-size: 20pt; letter-spacing: .3em; }
.t-mono .p-items th { border-bottom: 1px dashed #1d2320; border-top: 1px dashed #1d2320; }
.t-mono .p-items td { border-bottom: 1px dashed #d5d9d7; }
.t-mono .sum-row.grand { background: #1d2320; border-radius: 0; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(10, 18, 14, .5); display: flex; }
.modal { align-items: center; justify-content: center; padding: 16px; }
.modal-panel { background: var(--card); border-radius: 16px; max-width: 520px; width: 100%; padding: 24px; box-shadow: var(--shadow); position: relative; max-height: calc(100vh - 32px); overflow: auto; }
.modal-panel h2 { margin: 0 0 4px; font-size: 24px; }
.close-x { position: absolute; top: 12px; right: 12px; }
.price { font-size: 40px; font-weight: 800; letter-spacing: -.02em; }
.price small { font-size: 15px; color: var(--muted); font-weight: 500; }
.checks { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 6px; }
.checks li::before { content: "✓"; color: var(--brand); font-weight: 800; margin-right: 8px; }
.reason { background: #fff6e0; color: #5b4300; border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }
@media (prefers-color-scheme: dark) { .reason { background: #3a2f12; color: #f5dc9f; } }
.license-form { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.license-msg { font-size: 14px; color: var(--danger); min-height: 1em; margin: 6px 0 0; }
.ok { color: var(--brand); font-weight: 650; }
.drawer { justify-content: flex-end; }
.drawer-panel { width: min(460px, 100%); background: var(--card); height: 100%; overflow: auto; padding: 20px; position: relative; }
.drawer-panel h2 { margin: 0 0 12px; }
.drawer-panel h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpis div { background: var(--bg); border-radius: 10px; padding: 10px; }
.kpis .wide { grid-column: 1 / -1; }
.kpis span { display: block; font-size: 12px; color: var(--muted); }
.kpis strong { font-size: 20px; }
.hist, .clients { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.hist li { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.hist-open { all: unset; cursor: pointer; display: grid; gap: 2px; }
.hist-open:hover .hist-num { color: var(--brand); text-decoration: underline; }
.hist-num { font-weight: 700; }
.hist-client, .muted { color: var(--muted); font-size: 14px; }
.hist-total { font-variant-numeric: tabular-nums; }
.hist-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.hist-actions button, .clients button { font: inherit; font-size: 13px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; padding: 4px 8px; cursor: pointer; }
.hist-actions .danger, .clients .danger { color: var(--danger); }
.clients li { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); padding: 6px 0; }
.pill { align-self: start; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 2px 8px; text-transform: capitalize; background: var(--bg); color: var(--muted); }
.st-paid { background: #dcf3e6; color: #11633d; }
.st-sent { background: #e0ebff; color: #1e429f; }
.st-overdue { background: #fde3e1; color: #9b1c12; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #17201b; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: var(--shadow); font-size: 15px; max-width: calc(100% - 32px); }

/* content pages */
.content { padding-top: 8px; padding-bottom: 8px; }
.content h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.15; letter-spacing: -.02em; margin: 28px 0 10px; }
.content h2 { font-size: 24px; margin: 36px 0 10px; letter-spacing: -.01em; }
.content h3 { font-size: 18px; margin: 24px 0 6px; }
.content p, .content li { color: color-mix(in srgb, var(--ink) 88%, var(--muted)); }
.content .lede { font-size: 18px; color: var(--muted); }
.content table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 15px; }
.content th, .content td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.content th { background: var(--brand-soft); }
.content pre { white-space: pre-wrap; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; font: 14px/1.5 ui-monospace, Menlo, Consolas, monospace; }
.crumbs { font-size: 14px; color: var(--muted); margin-top: 16px; }
.crumbs a { color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 16px 0; }
.tile { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.tile:hover { border-color: var(--brand); }
.tile strong { display: block; margin-bottom: 4px; }
.tile span { color: var(--muted); font-size: 14px; }
.faq details { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 8px 0; }
.faq summary { cursor: pointer; font-weight: 650; }
.cta-box { background: var(--brand-soft); border-radius: 16px; padding: 20px; margin: 28px 0; }
.cta-box h2 { margin-top: 0; }
.pricing { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 20px 0; }
.plan { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 22px; box-shadow: var(--shadow); }
.plan.featured { border: 2px solid var(--gold); }
.plan h2 { margin: 0; }
@media (max-width: 720px) { .pricing { grid-template-columns: 1fr; } }
.ad-slot { margin: 24px 0; min-height: 90px; }

/* print: only the document */
@media print {
  body { background: #fff; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  #print-root .paper { box-shadow: none; border-radius: 0; transform: none !important; width: auto; min-height: 0; margin: 0; padding: 2mm 15mm 0; overflow: visible; }
  #print-root .t-bold .p-head { margin-top: -2mm; }
  #print-root .pro-ribbon { display: none; }
  #print-root .p-footer { position: static; margin-top: 12mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
