/* ---------- Tema ---------- */
:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --border: #e2e5e0;
  --text: #17201b;
  --muted: #66716a;
  --accent: #2f9e6e;
  --accent-ink: #ffffff;
  --accent-soft: #e3f4ec;
  --danger: #d93d42;
  --warn-bg: #fff4d6;
  --warn-ink: #7a5600;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .05);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tabbar-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1512;
    --surface: #171f1b;
    --surface-2: #1e2823;
    --border: #2a3530;
    --text: #e8eeea;
    --muted: #93a19a;
    --accent: #3fbf86;
    --accent-ink: #062014;
    --accent-soft: #173327;
    --danger: #ff6b70;
    --warn-bg: #3a2f10;
    --warn-ink: #ffd773;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.error { color: var(--danger); min-height: 1.2em; font-size: 14px; margin: 4px 0 8px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-top: 14px; }

/* ---------- Formularios y botones ---------- */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 11px 12px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
input[type=range] { padding: 0; border: 0; accent-color: var(--accent); background: transparent; box-shadow: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px;
  font: inherit; font-weight: 600; font-size: 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; padding: 13px; font-size: 15px; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; color: var(--text); padding: 8px; border-radius: 10px; cursor: pointer; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- Acceso ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px 24px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 24px; margin: 18px 0 6px; }
.auth-card .muted { margin-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 16px; }

/* ---------- Estructura ---------- */
#app { display: grid; grid-template-columns: 240px 1fr; min-height: 100%; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 14px; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 22px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 500; cursor: pointer; border: 0; background: none; font: inherit; text-align: left; }
.nav-item svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.side-foot { margin-top: auto; padding: 0 12px; font-size: 13px; }
main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: 18px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.topbar h1 { font-size: 24px; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.sync { font-size: 12px; color: var(--muted); }
.sync.err { color: var(--danger); }
.view { padding: 4px 28px 40px; max-width: 1100px; display: grid; gap: 16px; }
.tabbar { display: none; }
.mobile-only { display: none; }

/* ---------- Tarjetas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.kpi .label { font-size: 13px; color: var(--muted); }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.kpi .value.good { color: var(--accent); }

.hero { background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 70%, #0b3d28) 100%); color: #fff; border: 0; }
.hero .label { opacity: .85; font-size: 14px; }
.hero .big { font-size: 38px; font-weight: 800; letter-spacing: -.5px; margin: 4px 0 2px; }
.hero .sub { opacity: .9; }
.progress { height: 10px; background: rgba(255,255,255,.25); border-radius: 99px; overflow: hidden; margin: 16px 0 6px; }
.progress > div { height: 100%; background: #fff; border-radius: 99px; transition: width .6s ease; }
.progress.light { background: var(--surface-2); }
.progress.light > div { background: var(--accent); }
.hero .progress-label { display: flex; justify-content: space-between; font-size: 13px; opacity: .9; }

/* Lista de pagos del mes */
.pay-list { display: grid; gap: 8px; }
.pay-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.pay-item .name { font-weight: 600; }
.pay-item .amount { margin-left: auto; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.pay-item .amount small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.green { background: var(--accent-soft); color: var(--accent); }
.badge.red { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* Fases */
.timeline { display: grid; gap: 0; }
.tl-item { display: grid; grid-template-columns: 22px 1fr auto; gap: 12px; align-items: start; padding-bottom: 16px; position: relative; }
.tl-item:not(:last-child)::before { content: ""; position: absolute; left: 10px; top: 20px; bottom: 0; width: 2px; background: var(--border); }
.tl-dot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700; }
.tl-item .when { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Deudas */
.debt-card { border-left: 5px solid var(--c, var(--accent)); }
.debt-card .bal { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 6px 0 10px; }
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; font-size: 13px; }
.facts div span { color: var(--muted); display: block; font-size: 12px; }
.facts div b { font-variant-numeric: tabular-nums; }

/* Tablas */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
tr.current td { background: var(--accent-soft); }
tr.done td:first-child::after { content: " ✓"; color: var(--accent); }
td .ex { display: block; font-size: 11px; color: var(--accent); }
td.zero { color: var(--muted); }

/* Gráfico */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid line { stroke: var(--border); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* Simulador */
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.compare .box { padding: 14px; border-radius: 12px; background: var(--surface-2); }
.compare .box.hl { background: var(--accent-soft); }
.compare .box .t { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.compare .box .v { font-size: 22px; font-weight: 700; margin-top: 4px; }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row output { min-width: 70px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Glosario */
details { border-bottom: 1px solid var(--border); padding: 10px 0; }
details:last-child { border-bottom: 0; }
summary { cursor: pointer; font-weight: 600; }
details p { margin-top: 8px; color: var(--muted); }

/* Modal y toast */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5, 10, 8, .55); display: grid; place-items: center; padding: 16px; }
.modal-card { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border-radius: 20px; padding: 22px; border: 1px solid var(--border); }
.modal-card h2 { font-size: 20px; margin-bottom: 6px; }
.modal-card > p.muted { margin-bottom: 16px; font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 140%); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-size: 14px; font-weight: 500; transition: transform .25s ease, opacity .25s; z-index: 60; opacity: 0; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
@media (max-width: 760px) { .toast { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); } }
.empty { text-align: center; color: var(--muted); padding: 24px 10px; }

/* ---------- Móvil ---------- */
@media (max-width: 860px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-3 > .kpi:first-child { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-only { display: inline-flex; }
  .topbar { padding: calc(env(safe-area-inset-top) + 12px) 16px 10px; }
  .topbar h1 { font-size: 22px; }
  .view { padding: 4px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); gap: 12px; }
  .card { padding: 16px; border-radius: 14px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .hero .big { font-size: 32px; }
  .kpi .value { font-size: 21px; }
  .form-grid { grid-template-columns: 1fr; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
  }
  .tabbar .nav-item { flex-direction: column; justify-content: center; gap: 3px; padding: 6px 0; font-size: 11px; border-radius: 0; text-align: center; }
  .tabbar .nav-item.active { background: none; }
  .tabbar .nav-item svg { width: 23px; height: 23px; }
  .modal { align-items: end; padding: 0; }
  .modal-card { max-width: none; border-radius: 20px 20px 0 0; padding-bottom: calc(22px + env(safe-area-inset-bottom)); max-height: 92vh; }
}
@media (max-width: 380px) {
  .grid-3 { grid-template-columns: 1fr; }
  .compare { grid-template-columns: 1fr; }
}

/* ---------- Acceso y bienvenida ---------- */
.link { color: var(--accent); text-decoration: none; font-weight: 600; }
.link:hover { text-decoration: underline; }
a.brand { color: var(--text); text-decoration: none; }
.auth-alt { text-align: center; margin-top: 18px; font-size: 14px; color: var(--muted); }
.auth-card .muted { margin-bottom: 20px; }
.auth-card label.check span { color: var(--text); }
.hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.warn a { color: inherit; font-weight: 600; }
.ob { display: grid; gap: 20px; }
.ob-step { display: flex; gap: 14px; align-items: flex-start; }
.ob-step h3 { margin-bottom: 4px; }
.ob-num { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.ob-step.done .ob-num { background: var(--accent); color: var(--accent-ink); }
