:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #15181d;
  --muted: #5d6573;
  --border: #e2e5ea;
  --accent: #1557d6;
  --accent-ink: #ffffff;
  --accent-soft: #e8effc;
  --ok: #0f7b52;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --text: #e8eaee;
    --muted: #9aa3b2;
    --border: #2a2f39;
    --accent: #6d9cff;
    --accent-ink: #0b1220;
    --accent-soft: #1a2540;
    --ok: #4cc79a;
    --danger: #ff8a80;
    --danger-soft: #3a1d1b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
p { margin: 0; }
.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }

/* Header */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.header-link { font-size: 14px; font-weight: 600; text-decoration: none; white-space: nowrap; }

/* Hero */
.hero { padding: 40px 0 24px; text-align: center; }
.hero h1 { font-size: clamp(26px, 5vw, 40px); letter-spacing: -.02em; }
.hero .lead { color: var(--muted); font-size: 18px; margin: 12px auto 0; max-width: 620px; }
.badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; margin-top: 16px; font-size: 14px; color: var(--muted); }
.badges span::before { content: "✓ "; color: var(--ok); font-weight: 700; }

/* Dropzone */
.dropzone {
  display: block;
  margin: 28px auto 0;
  max-width: 640px;
  padding: 36px 20px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag, .dropzone:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dz-icon { width: 44px; height: 44px; margin: 0 auto 12px; color: var(--accent); }
.dz-title { font-size: 18px; font-weight: 700; }
.dz-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.btn-fake { display: inline-block; margin-top: 16px; }
.dropzone.loading { opacity: .6; pointer-events: none; }
.dropzone.loading .dz-title::after { content: " · Leyendo…"; }
.demo-link { margin-top: 14px; font-size: 14px; color: var(--muted); }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }

.error {
  max-width: 640px; margin: 16px auto 0; padding: 12px 16px;
  background: var(--danger-soft); color: var(--danger);
  border-radius: 10px; font-size: 15px; text-align: left;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 15px; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn[hidden] { display: none; }

/* Result */
.result { padding: 8px 0 32px; scroll-margin-top: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.toolbar .btn { flex: 1 1 auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.invoice { padding: 24px; }
.invoice section { margin-top: 24px; }
.invoice h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }

.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.inv-type { font-size: 14px; font-weight: 600; color: var(--accent); }
.inv-number { font-size: 26px; margin: 2px 0 4px; word-break: break-all; }
.inv-total { text-align: right; }
.inv-total span { display: block; font-size: 13px; }
.inv-total strong { font-size: 26px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.party { margin-top: 20px !important; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.party .party-name { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.meta { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-top: 16px; font-size: 14px; color: var(--muted); }
.meta b { color: var(--text); }

.lines { list-style: none; margin: 0; padding: 0; }
.lines li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.lines li:last-child { border-bottom: 0; }
.line-main { display: flex; justify-content: space-between; gap: 16px; }
.line-desc { font-weight: 500; overflow-wrap: anywhere; }
.line-amount { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.line-sub { font-size: 13px; margin-top: 2px; }
.tag { display: inline-block; padding: 0 8px; margin-left: 4px; border-radius: 999px; background: var(--surface-2); font-size: 12px; }

.totals .row { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; font-variant-numeric: tabular-nums; }
.totals .row.grand { margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 18px; font-weight: 700; }
.totals .row.muted { font-size: 14px; }
.note { font-size: 14px; color: var(--muted); white-space: pre-line; margin-bottom: 6px; }
.cufe code { display: block; font-size: 12px; color: var(--muted); word-break: break-all; background: var(--surface-2); padding: 10px; border-radius: 8px; }

/* App promo */
.promo { display: flex; align-items: center; gap: 20px; margin-top: 16px; padding: 20px 24px; }
.promo img { width: 56px; height: 56px; border-radius: 12px; flex: none; }
.promo h2 { font-size: 18px; }
.promo p { color: var(--muted); font-size: 15px; margin-top: 4px; }
.promo .btn { margin-left: auto; flex: none; }
.android-only { display: none; }
.is-android .android-only { display: block; }

/* Content */
.content { padding: 40px 0; border-top: 1px solid var(--border); }
.content h2 { font-size: 24px; margin-bottom: 16px; }
.content h3 { font-size: 18px; margin: 20px 0 6px; }
.content p, .content li { color: var(--muted); }
.content p + p { margin-top: 10px; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.steps li { counter-increment: s; position: relative; padding: 16px 16px 16px 60px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.steps li::before { content: counter(s); position: absolute; left: 16px; top: 14px; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; }
.steps strong { color: var(--text); }
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; margin-bottom: 10px; }
.faq summary { font-weight: 600; cursor: pointer; }
.faq details p { margin-top: 8px; }
.article { padding: 32px 0 8px; }
.article h1 { font-size: clamp(26px, 5vw, 36px); margin-bottom: 14px; letter-spacing: -.02em; }
.article .lead { font-size: 18px; color: var(--muted); }
.article ul, .article ol { padding-left: 22px; }
.cta-box { margin: 28px 0; padding: 22px; text-align: center; }
.cta-box p { margin: 6px 0 14px; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding: 28px 0 40px; font-size: 14px; color: var(--muted); }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-bottom: 10px; }

/* When an invoice is open, keep the focus on it */
.has-invoice .hero { padding-bottom: 8px; }

@media (max-width: 640px) {
  .hero { padding-top: 28px; }
  .invoice { padding: 18px 16px; }
  .inv-head { flex-direction: column; }
  .inv-total { text-align: left; }
  .parties { grid-template-columns: 1fr; gap: 0; }
  .promo { flex-wrap: wrap; }
  .promo .btn { margin-left: 0; width: 100%; }
  .header-link .long { display: none; }
}

@media print {
  :root { --text: #000; --muted: #444; --border: #ccc; --surface: #fff; --surface-2: #f1f3f6; --accent: #1557d6; }
  body { background: #fff; color: #000; }
  .site-header, .hero, .toolbar, .promo, .content, .site-footer, .error { display: none !important; }
  .card { border: 0; box-shadow: none; }
  .invoice { padding: 0; }
}
