/* ── Local Invoice — private, in-browser invoice maker ─────────────── */
:root {
  --brand: #4338ca;
  --brand-dark: #3730a3;
  --brand-light: #818cf8;
  --brand-soft: #eef2ff;
  --brand-border: #c7d2fe;
  --ink: #1a1a2e;
  --muted: #6b7280;
  --line: #e7e8ee;
  --bg: #f7f7fb;
  --card: #ffffff;
  --ok: #0f766e;
  --danger: #b91c1c;
  --shadow: 0 1px 3px rgba(20,20,40,.06), 0 8px 24px rgba(20,20,40,.05);
  --shadow-lg: 0 20px 60px rgba(20,20,40,.14);
  /* Status chips (success / error). Tokenized so dark mode can override them;
     values below match the previous hard-coded light colors exactly. */
  --ok-bg: #ecfdf5;
  --err: #b91c1c;
  --err-bg: #fef2f2;
  /* Topbar glass + input fill + subtle hovers — tokenized for dark mode.
     Light values are identical to what was previously hard-coded inline. */
  --topbar-bg: rgba(255,255,255,.85);
  --pill-bg: #f0fdf9;
  --pill-border: #99f6e4;
  --input-bg: #fbfbfd;
  --input-bg-focus: #ffffff;
  --chip-neutral-bg: #f1f1f5;
  --danger-soft-bg: #fee2e2;
  --footer-ink: #9ca3bf;
  --preview-line-soft: #f2f2f6;
}

/* ── Dark mode ─────────────────────────────────────────────────────────
   Opt-in overlay: only the app CHROME goes dark. The invoice preview is
   "paper" (it represents the exported PDF) and is deliberately kept LIGHT
   below so what the user sees matches what exports. */
[data-theme="dark"] {
  --brand: #818cf8;        /* lightened so it stays vivid & AA on dark chrome */
  --brand-dark: #a5b4fc;   /* used for text on dark → lighter than base brand */
  --brand-light: #a5b4fc;
  --brand-soft: #262a3d;   /* deep indigo-tinted surface */
  --brand-border: #3b3f57;
  --ink: #e8e8ed;
  --muted: #9aa0b0;
  --line: #2c2e38;
  --bg: #15161a;
  --card: #1c1d22;
  --ok: #34d399;
  --danger: #f87171;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 20px 60px rgba(0,0,0,.55);
  --ok-bg: #10281f;
  --err: #fca5a5;
  --err-bg: #2a1416;
  --topbar-bg: rgba(21,22,26,.85);
  --pill-bg: #0f2820;
  --pill-border: #1e5045;
  --input-bg: #23252d;
  --input-bg-focus: #2a2c35;
  --chip-neutral-bg: #2a2c35;
  --danger-soft-bg: #3a1d1d;
  --footer-ink: #7a7f90;
  --preview-line-soft: #f2f2f6;
}

/* Subtle theme transition on the root chrome; suppressed for reduced motion. */
@media (prefers-reduced-motion: no-preference) {
  body, .topbar, .panel, .invoice-row, .modal, .preview,
  .field input, .field textarea, select {
    transition: background-color .2s ease, border-color .2s ease, color .2s ease;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; }
.hidden { display: none !important; }

/* ── Top bar ───────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px max(28px, env(safe-area-inset-right)) 14px max(28px, env(safe-area-inset-left));
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--topbar-bg);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.logo svg { width: 30px; height: 30px; }
.logo b { font-size: 17px; font-weight: 800; letter-spacing: -.3px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.privacy-pill {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 600; color: var(--ok);
  background: var(--pill-bg); border: 1px solid var(--pill-border);
  padding: 5px 12px; border-radius: 999px;
}
.privacy-pill svg { width: 14px; height: 14px; }

/* Theme toggle (sun/moon) — icon-only; swaps which glyph shows by theme. */
.theme-toggle {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; flex-shrink: 0;
  background: transparent; border: 1px solid var(--line); border-radius: 10px;
  color: var(--muted); transition: color .12s ease, border-color .12s ease, background-color .12s ease;
}
.theme-toggle:hover { color: var(--brand); border-color: var(--brand-border); background: var(--brand-soft); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .theme-icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .theme-icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .theme-icon-moon { display: block; }

/* ── Hero ──────────────────────────────────────────────────────────── */
.hero { text-align: center; padding: 52px 24px 26px; }
.hero h1 { font-size: 40px; font-weight: 800; letter-spacing: -1px; line-height: 1.15; max-width: 720px; margin: 0 auto 14px; }
.hero .accent { color: var(--brand); }
.hero p { color: var(--muted); font-size: 16.5px; max-width: 540px; margin: 0 auto 14px; }
.hero .reassure { display: inline-block; background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; font-size: 13.5px; padding: 8px 16px; border-radius: 999px; margin-bottom: 22px; }

.btn {
  border: none; border-radius: 12px; padding: 11px 20px; font-weight: 700; font-size: 14.5px;
  background: var(--brand); color: #fff; box-shadow: 0 6px 18px rgba(67,56,202,.25);
  transition: transform .1s ease, box-shadow .1s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(67,56,202,.3); }
.btn:active { transform: translateY(0); }
.btn.big { font-size: 15.5px; padding: 13px 26px; }
.btn.ghost { background: transparent; color: var(--brand); border: 1.5px solid var(--brand-border); box-shadow: none; }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.sm { padding: 8px 14px; font-size: 13px; }
.btn.danger { background: var(--danger); box-shadow: 0 6px 18px rgba(185,28,28,.2); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── Wrap / hub list ───────────────────────────────────────────────── */
.wrap { max-width: 900px; margin: 0 auto; padding: 8px 24px 40px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-head h2 { font-size: 18px; font-weight: 800; }

.invoice-list { display: flex; flex-direction: column; gap: 10px; }
.invoice-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 18px; box-shadow: var(--shadow); cursor: pointer;
  transition: border-color .12s ease;
}
.invoice-row:hover { border-color: var(--brand-border); }
.invoice-row .left { display: flex; flex-direction: column; gap: 2px; }
.invoice-row .num { font-weight: 700; font-size: 14.5px; }
.invoice-row .client { color: var(--muted); font-size: 13px; }
.invoice-row .right { display: flex; align-items: center; gap: 14px; }
.invoice-row .amount { font-weight: 800; font-size: 15px; }
.invoice-row .status { font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 999px; text-transform: uppercase; letter-spacing: .3px; }
.invoice-row .status.draft { background: var(--chip-neutral-bg); color: var(--muted); }
.invoice-row .status.sent { background: var(--brand-soft); color: var(--brand-dark); }
.invoice-row .status.paid { background: var(--ok-bg); color: var(--ok); }
.invoice-row .del { color: var(--muted); background: none; border: none; padding: 4px; border-radius: 6px; display: flex; }
.invoice-row .del:hover { background: var(--danger-soft-bg); color: var(--danger); }
.invoice-row .del svg { width: 16px; height: 16px; }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty p:first-child { font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.muted { color: var(--muted); font-size: 13.5px; }

.strip {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 28px;
  padding: 26px 24px; border-top: 1px solid var(--line); margin-top: 20px;
  color: var(--muted); font-size: 13px;
}
.strip .item { display: flex; align-items: center; gap: 7px; }
.strip svg { width: 16px; height: 16px; color: var(--ok); flex-shrink: 0; }

footer { text-align: center; color: var(--footer-ink); font-size: 12.5px; padding: 30px 24px max(40px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); margin-top: 30px; }
footer a { color: var(--muted); }

/* ── Editor ────────────────────────────────────────────────────────── */
.editor { max-width: 1080px; margin: 0 auto; padding: 24px; }
.editor-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.back { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 16px; font-weight: 600; font-size: 13.5px; color: var(--ink); box-shadow: var(--shadow); }
.editor-head .spacer { flex: 1; }
.status-badge { font-size: 11.5px; font-weight: 700; padding: 5px 12px; border-radius: 999px; text-transform: uppercase; letter-spacing: .3px; }
.status-badge.draft { background: var(--chip-neutral-bg); color: var(--muted); }
.status-badge.sent { background: var(--brand-soft); color: var(--brand-dark); }
.status-badge.paid { background: var(--ok-bg); color: var(--ok); }

.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 24px; align-items: flex-start; }
@media (max-width: 860px) { .editor-grid { grid-template-columns: 1fr; } }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.field-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; display: block; }
.field { margin-bottom: 14px; }
.field input, .field textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 9px; padding: 9px 11px;
  color: var(--ink); background: var(--input-bg); transition: border-color .12s ease;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--brand-light); background: var(--input-bg-focus); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field textarea { resize: vertical; min-height: 60px; }

.panel h3 { font-size: 14.5px; font-weight: 800; margin-bottom: 14px; }

.lineitems { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.lineitem-row { display: grid; grid-template-columns: 1fr 56px 84px 28px; gap: 8px; align-items: center; }
.lineitem-row input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 9px; padding: 9px 11px;
  color: var(--ink); background: var(--input-bg); transition: border-color .12s ease;
}
.lineitem-row input:focus { outline: none; border-color: var(--brand-light); background: var(--input-bg-focus); }
.lineitem-row .qty, .lineitem-row .rate { text-align: right; }
.lineitem-row .rm { background: none; border: none; color: var(--muted); display: flex; align-items: center; justify-content: center; border-radius: 6px; padding: 4px; }
.lineitem-row .rm:hover { background: var(--danger-soft-bg); color: var(--danger); }

/* Selects (currency/status/discount/client picker) get their fill inline in JS
   via var(--input-bg); make sure text + option colors read in dark too. */
select { color: var(--ink); }
select option { color: var(--ink); background: var(--card); }
.lineitem-row .rm svg { width: 15px; height: 15px; }

/* ── Live preview (looks like the exported PDF) ───────────────────── */
/* PAPER STAYS LIGHT: the preview represents the printed PDF, so it keeps a
   white paper surface with dark text even in dark mode. We re-pin every color
   token it consumes back to the light palette (scoped to this subtree only),
   so the paper matches what actually exports regardless of app theme. */
.preview {
  --ink: #1a1a2e;
  --muted: #6b7280;
  --line: #e7e8ee;
  --brand-dark: #3730a3;
  --preview-line-soft: #f2f2f6;
  color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 40px;
}
.preview-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 26px; }
.preview-head h2 { font-size: 22px; font-weight: 800; }
.preview-head .meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.preview-head .amount { font-size: 26px; font-weight: 800; color: var(--brand-dark); }
.preview-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.preview-parties .label { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 4px; }
.preview-parties .name { font-size: 13.5px; font-weight: 700; }
.preview-parties .sub { font-size: 12.5px; color: var(--muted); white-space: pre-line; }
.preview table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 16px; }
.preview thead td { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; padding-bottom: 8px; }
.preview tbody td { padding: 6px 0; border-top: 1px solid var(--preview-line-soft); }
.preview td.num { text-align: right; }
.preview td.qty { text-align: center; }
.preview-totals { display: flex; justify-content: flex-end; }
.preview-totals table { width: 240px; }
.preview-totals td { padding: 4px 0; font-size: 13px; }
.preview-totals td.num { text-align: right; }
.preview-totals .grand td { font-weight: 800; font-size: 15px; border-top: 1px solid var(--line); padding-top: 8px; }
.preview-footer { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); white-space: pre-line; }
.preview-due { display: flex; justify-content: space-between; margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.preview-logo { display: block; max-width: 160px; max-height: 44px; object-fit: contain; margin-bottom: 16px; }

/* ── Logo upload (Pro) ─────────────────────────────────────────────── */
.logo-row { display: flex; align-items: center; gap: 12px; }
.logo-thumb { width: 44px; height: 44px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: #fff; }
[data-theme="dark"] .logo-thumb { background: var(--input-bg); }

/* ── Pro paywall modal ────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,20,40,.45); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--card); border-radius: 18px; padding: 28px; max-width: 380px; width: 100%;
  box-shadow: var(--shadow-lg);
}
.pro-modal h3 { font-size: 20px; font-weight: 800; margin-bottom: 8px; }
.pro-price { margin-bottom: 16px; }
.pro-price-amt { font-size: 28px; font-weight: 800; color: var(--brand-dark); }
.pro-price-note { font-size: 13.5px; color: var(--muted); }
.pro-features { padding-left: 20px; margin-bottom: 20px; color: var(--ink); font-size: 14px; }
.pro-features li { margin-bottom: 6px; }
.pro-actions { display: flex; gap: 10px; }
.pro-actions .btn { flex: 1; }
.pro-msg:empty { margin: 0; }
.pro-modal .hint { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; }

/* ── Restore-by-code ──────────────────────────────────────────────── */
.restore-code-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--brand-soft); border: 1.5px dashed var(--brand-border); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 18px;
}
.restore-code-value { font-size: 15px; font-weight: 700; letter-spacing: .3px; color: var(--brand-dark); word-break: break-all; }
.restore-code-input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 9px; padding: 10px 12px;
  font-size: 15px; letter-spacing: .5px; margin-bottom: 14px; text-transform: uppercase;
  color: var(--ink); background: var(--input-bg); transition: border-color .12s ease;
}
.restore-code-input:focus { outline: none; border-color: var(--brand-light); background: var(--input-bg-focus); }
.restore-link {
  display: block; width: 100%; text-align: center; background: none; border: none;
  color: var(--muted); font-size: 12.5px; margin-top: 12px; padding: 4px; text-decoration: underline;
}
.restore-link:hover { color: var(--brand-dark); }


/* ── Pro license card ─────────────────────────────────────────────── */
.license-modal { max-width: 560px; }
.license-card-canvas {
  display: block; width: 100%; max-width: 100%; height: auto;
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 16px;
}
.pro-actions + .pro-actions { margin-top: 10px; }

/* Save-your-card nag banner (boot-time, dismissible) */
.license-nag {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  background: var(--brand-soft); color: var(--brand-dark);
  border-bottom: 1px solid var(--brand-border);
  font-size: 13px; font-weight: 600; padding: 7px 14px;
}
.license-nag-view {
  background: none; border: none; color: var(--brand); font-size: 13px;
  font-weight: 700; text-decoration: underline; padding: 2px 4px;
}
.license-nag-view:hover { color: var(--brand-dark); }
.license-nag-x {
  background: none; border: none; color: var(--brand-dark);
  font-size: 17px; line-height: 1; padding: 2px 8px; border-radius: 6px;
}
.license-nag-x:hover { background: rgba(67,56,202,.1); }

/* ── Data vault (back up & restore row + feedback toast) ──────────── */
.footer-tools { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 4px; }
.footer-tools .restore-link { display: inline-block; width: auto; margin-top: 0; }
.vault-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ok-bg); color: var(--ok); border: 1px solid var(--pill-border);
  padding: 10px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-lg); z-index: 200; max-width: min(92vw, 480px); text-align: center;
}

/* ── Keyboard focus visibility (WCAG 2.4.7) — added from experience audit ── */
:focus-visible { outline: 2px solid var(--brand, currentColor); outline-offset: 2px; border-radius: 3px; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible, .restore-code-input:focus-visible { outline: 2px solid var(--brand, currentColor); outline-offset: 1px; }
