:root {
  --bg: #EEF4F0;
  --surface: #FFFFFF;
  --ink: #12261D;
  --muted: #55695D;
  --line: #D6E2DA;
  --green: #0E4B36;
  --on-green: #FFFFFF;
  --gold: #C79A1E;
  --on-gold: #241900;
  --gold-text: #6F5300;
  --gold-soft: #FBF1D3;
  --red: #B3322B;
  --red-soft: #FBE4E1;
  --ok-soft: #DDF0E5;
  --shadow: 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B1812;
    --surface: #13261D;
    --ink: #E7F1EB;
    --muted: #A3B9AC;
    --line: #2B4A3B;
    --green: #3FBF8A;
    --on-green: #06150E;
    --gold: #E3B73B;
    --on-gold: #241900;
    --gold-text: #F0CC66;
    --gold-soft: #3A2F10;
    --red: #FF9A90;
    --red-soft: #3B1A17;
    --ok-soft: #17382A;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 17px; margin: 24px 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0; }

.wrap { max-width: 720px; margin: 0 auto; padding: 12px 16px 120px; }

/* Barra superior */
.top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.tabs { display: flex; gap: 8px; margin: 12px 0 0; }
.tabs a {
  flex: 1; display: flex; align-items: center; justify-content: center; min-height: 44px;
  border-radius: 12px; background: var(--surface); border: 1px solid var(--line);
  color: var(--ink); font-weight: 700; font-size: 15px; text-decoration: none;
}
.tabs a[aria-current="page"] { background: var(--green); border-color: var(--green); color: var(--on-green); }

/* Botones */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 700 15px system-ui, sans-serif; border: 0; border-radius: 12px;
  padding: 10px 16px; min-height: 44px; min-width: 44px; cursor: pointer;
  background: var(--green); color: var(--on-green); text-decoration: none;
}
button:disabled { opacity: .55; cursor: progress; }
.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
.danger-solid { background: var(--red); color: var(--surface); }
.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  background: var(--gold); color: var(--on-gold); border-radius: 99px;
  padding: 14px 22px; font-size: 16px; box-shadow: var(--shadow); z-index: 5;
}
.rate-chip {
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  font-weight: 400; font-size: 13px; text-align: right; display: block; padding: 6px 12px; line-height: 1.3;
}
.rate-chip b { font-size: 14px; }
.rate-chip span { display: block; color: var(--muted); font-size: 12px; }

.link-btn {
  background: none; color: var(--ink); padding: 8px 4px; text-decoration: underline;
  font-weight: 600;
}

/* Tarjetas */
.hero { margin-top: 14px; background: var(--green); color: var(--on-green); border-radius: 20px; padding: 18px 20px; }
.hero small { opacity: .9; font-size: 13px; }
.big { font-size: 32px; font-weight: 800; line-height: 1.15; overflow-wrap: anywhere; }
.hero-ves { font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.hero-grid { display: grid; gap: 12px; }
.hero-part + .hero-part { padding-top: 12px; border-top: 1px solid currentColor; }

.banner {
  margin-top: 12px; background: var(--gold-soft); color: var(--ink); border: 1px solid var(--gold);
  border-radius: 14px; padding: 12px 14px; font-weight: 600;
}
.banner.alert { background: var(--red-soft); border-color: var(--red); }
.banner .actions { margin-top: 8px; }
.banner.subscription p { margin: 4px 0 0; }
.lock h2 { margin-top: 0; }
.lock h3 { margin: 18px 0 6px; font-size: 16px; }
.lock .payment-info { white-space: pre-line; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0; }
.sub-payments { list-style: none; padding: 0; margin: 0; }
.sub-payments li { display: flex; align-items: center; gap: 6px 10px; flex-wrap: wrap; padding: 8px 0; border-top: 1px solid var(--line); }
.sub-payments li span:first-child { flex: 1 1 180px; }
.sub-payments small { flex-basis: 100%; }
.dialog-body h3 { margin: 16px 0 6px; font-size: 16px; }
.dialog-body .payment-info { white-space: pre-line; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0; }
.downloads { list-style: none; padding: 0; margin: 0; }
.downloads li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 0; border-top: 1px solid var(--line); }
.downloads li span { flex: 1 1 140px; }

.card {
  display: block; width: 100%; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; margin-bottom: 10px; color: var(--ink);
}
.card.overdue { border: 2px solid var(--red); background: var(--red-soft); }
.card.overdue .due-date { color: var(--red); font-weight: 700; }

.row { display: flex; justify-content: space-between; gap: 12px; }
.grow { min-width: 0; flex: 1; }
.name { font-weight: 700; overflow-wrap: anywhere; color: inherit; text-decoration: none; }
a.name { text-decoration: underline; text-underline-offset: 3px; }
.muted { color: var(--muted); font-size: 14px; }
.muted a { color: inherit; display: inline-block; padding: 4px 0; }
.back { margin-top: 12px; }
.amount { text-align: right; font-weight: 700; white-space: nowrap; }
.amount span { display: block; font-size: 13px; color: var(--muted); font-weight: 400; }
.card.overdue .muted, .card.overdue .amount span { color: var(--ink); }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 700;
  background: var(--ok-soft); color: var(--ink);
}
.badge.soon, .badge.today { background: var(--gold-soft); color: var(--gold-text); border: 1px solid var(--gold); }
.badge.late { background: var(--red); color: var(--surface); }
.badge.closed { background: var(--line); }
.badge.void { background: var(--line); color: var(--ink); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.actions > * { flex: 1 1 auto; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin: 12px 0; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--muted); }
.stat b { display: block; color: var(--ink); font-size: 16px; overflow-wrap: anywhere; }
.stat.key { background: var(--ok-soft); }

.empty { text-align: center; color: var(--muted); padding: 24px; border: 1px dashed var(--line); border-radius: 14px; }

/* Historial */
.history { list-style: none; margin: 0; padding: 0; }
.history li { padding: 10px 0; border-top: 1px solid var(--line); font-size: 15px; }
.history li:first-child { border-top: 0; }
.history .voided .history-main { text-decoration: line-through; color: var(--muted); }

/* Formularios */
dialog {
  border: 0; border-radius: 20px; padding: 20px; width: min(480px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgba(5, 15, 10, .6); }
dialog h2 { margin-top: 0; }
label { display: block; font-size: 14px; font-weight: 600; margin: 12px 0 4px; color: var(--muted); }
label.check { display: flex; gap: 10px; align-items: center; min-height: 44px; font-weight: 400; color: var(--ink); margin-top: 10px; }
label.check input { width: 22px; height: 22px; flex: none; }
input, select {
  width: 100%; min-height: 44px; font: 16px system-ui, sans-serif; padding: 10px 12px;
  border: 1px solid var(--muted); border-radius: 10px; background: var(--bg); color: var(--ink);
}
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.error { color: var(--red); min-height: 20px; font-size: 15px; margin-top: 8px; font-weight: 600; }
.hint { font-size: 14px; color: var(--muted); margin-top: 4px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.shortcuts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.shortcuts button { flex: 1 1 auto; }
.preview { background: var(--bg); border-radius: 10px; padding: 10px 12px; margin-top: 12px; font-size: 15px; }
.preview b { font-weight: 700; }

.login { max-width: 400px; margin: 32px auto 0; }
.brand { text-align: center; margin-bottom: 8px; }
.brand img { display: block; margin: 0 auto 8px; border-radius: 16px; }
.search { margin-top: 12px; }

/* Avisos */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; background: var(--ink); color: var(--bg);
  padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); z-index: 10; font-weight: 600;
}

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

@media (min-width: 560px) {
  .hero-grid { grid-template-columns: 1fr 1fr; }
  .hero-part + .hero-part { padding: 0 0 0 16px; border-top: 0; border-left: 1px solid currentColor; }
}

/* Tablet y computadora: 2 columnas desde 900 px */
@media (min-width: 900px) {
  .wrap { max-width: 1080px; padding-top: 16px; }
  .big { font-size: 40px; }
  .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
  .cols .card { margin: 0; }
  .cols .empty { grid-column: 1 / -1; }
  .detail { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
}

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .18s ease-out; }
  @keyframes rise { from { transform: translateY(8px); opacity: 0; } }
}
