/* ============================================================
   DeudaCero — estilos
   Mobile first, sin fuentes ni librerías externas.
   ============================================================ */

:root {
  --bg: #070b14;
  --bg-soft: #0b1120;
  --card: #101a2e;
  --card-2: #0d1526;
  --line: rgba(148, 163, 184, 0.14);
  --line-strong: rgba(148, 163, 184, 0.24);
  --text: #e9eefc;
  --muted: #94a3b8;
  --muted-2: #8b9bb4;
  --accent: #6366f1;
  --accent-2: #22d3ee;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #fb7185;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.8);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(99, 102, 241, 0.22), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(34, 211, 238, 0.14), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Estructura ---------- */

.app-shell {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 max(16px, var(--safe-r)) calc(96px + var(--safe-b)) max(16px, var(--safe-l));
}

@media (min-width: 600px) {
  .app-shell {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(255,255,255,0.015), transparent 30%);
    padding-left: 22px;
    padding-right: 22px;
  }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + var(--safe-t)) 2px 12px;
  background: linear-gradient(180deg, rgba(7, 11, 20, 0.96) 55%, rgba(7, 11, 20, 0));
  backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.logo {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #22d3ee);
  box-shadow: 0 8px 22px -8px rgba(99, 102, 241, 0.9);
}
.logo svg { width: 23px; height: 23px; }

.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: -0.02em;
  font-weight: 800;
}
.brand-text p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.ghost-btn {
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 15px;
  min-height: 40px;
  font-size: 12.5px;
  font-weight: 600;
}
.ghost-btn:active { transform: scale(0.97); }

.view {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 6px;
  animation: fade 0.22s ease;
}

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Tabbar ---------- */

.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(10px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 30;
  width: min(528px, calc(100% - 24px));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: rgba(13, 21, 38, 0.86);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 2px 6px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--muted-2);
  font-size: 10.5px;
  font-weight: 600;
  transition: color 0.18s, background 0.18s;
}
.tab svg { width: 21px; height: 21px; }
.tab.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(34, 211, 238, 0.16));
}
.tab:active { transform: scale(0.97); }

/* ---------- Tipografía y utilidades ---------- */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 0;
}
.section-head h2 {
  margin: 0;
  font-size: 21px;
  letter-spacing: -0.02em;
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; line-height: 1.55; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.spacer { height: 4px; }

.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.008));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 12px 30px -24px rgba(0,0,0,0.9);
}
.card h3 {
  margin: 0 0 8px;
  font-size: 15.5px;
  letter-spacing: -0.01em;
}
.card > .btn.block:first-of-type { margin-top: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
  transition: transform 0.12s, filter 0.18s, background 0.18s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn.block { width: 100%; margin-top: 8px; }
.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  box-shadow: 0 10px 24px -12px rgba(99, 102, 241, 0.95);
}
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.045);
  border-color: var(--line-strong);
}
.btn.danger {
  color: #fff;
  background: linear-gradient(135deg, #f43f5e, #e11d48);
  box-shadow: 0 10px 24px -12px rgba(244, 63, 94, 0.9);
}
.btn.danger.ghost {
  color: #fda4af;
  background: rgba(244, 63, 94, 0.08);
  border-color: rgba(244, 63, 94, 0.28);
  box-shadow: none;
}
.btn.small { padding: 10px 14px; font-size: 12.5px; border-radius: 11px; min-height: 40px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
}
.icon-btn:active { transform: scale(0.95); }

/* ---------- Hero ---------- */

.hero {
  position: relative;
  overflow: hidden;
  border-radius: 26px;
  padding: 20px 18px 17px;
  background:
    radial-gradient(600px 240px at 0% 0%, rgba(99, 102, 241, 0.55), transparent 62%),
    radial-gradient(500px 220px at 100% 100%, rgba(34, 211, 238, 0.28), transparent 60%),
    linear-gradient(160deg, #141f3a, #0c1425 70%);
  border: 1px solid rgba(129, 140, 248, 0.3);
  box-shadow: 0 24px 60px -30px rgba(79, 70, 229, 0.75);
}
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(300px 120px at 80% -20%, rgba(255,255,255,0.16), transparent 70%);
  pointer-events: none;
}

.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hero-label { font-size: 12.5px; color: #c7d2fe; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; }
.chip {
  font-size: 11px;
  font-weight: 700;
  color: #dbeafe;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 4px 9px;
  border-radius: 999px;
}

.hero-amount {
  margin: 6px 0 14px;
  font-size: clamp(34px, 11vw, 46px);
  font-weight: 850;
  letter-spacing: -0.035em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #22d3ee, #34d399);
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.hero-progress-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 7px;
  font-size: 11.5px;
  color: #bfdbfe;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.hero-stats > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hero-stats b { font-size: 15px; font-weight: 750; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hero-stats small { font-size: 10.5px; color: #a5b4fc; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- Plan ---------- */

.plan-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.plan-head h3 { margin: 0 0 2px; }
.plan-head p { margin: 0; }
.plan-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 13px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
}
.plan-grid > div { min-width: 0; }
.plan-grid span {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-2);
  font-weight: 600;
}
.plan-grid b {
  display: block;
  margin-top: 3px;
  font-size: 14.5px;
  font-weight: 750;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plan-grid b.good { color: var(--good); }

/* ---------- Avisos ---------- */

.alert {
  border-radius: 16px;
  padding: 13px 14px;
  border: 1px solid;
  font-size: 13px;
  line-height: 1.5;
}
.alert strong { display: block; margin-bottom: 3px; font-size: 13.5px; }
.alert p { margin: 0; color: var(--muted); }
.alert.warn { background: rgba(251, 191, 36, 0.08); border-color: rgba(251, 191, 36, 0.28); }
.alert.warn strong { color: #fcd34d; }
.alert.bad { background: rgba(251, 113, 133, 0.08); border-color: rgba(251, 113, 133, 0.28); }
.alert.bad strong { color: #fda4af; }
.alert.info { background: rgba(34, 211, 238, 0.07); border-color: rgba(34, 211, 238, 0.25); }
.alert.info strong { color: #67e8f9; }

/* ---------- Estadísticas ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat {
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 14px;
  min-width: 0;
}
.stat > span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.stat > b {
  display: block;
  margin: 4px 0 1px;
  font-size: clamp(19px, 5.6vw, 24px);
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat > small { font-size: 11px; color: var(--muted-2); }
.stat.good > b { color: var(--good); }
.stat.bad > b { color: var(--bad); }

/* ---------- Deudas ---------- */

.debt-list { display: flex; flex-direction: column; gap: 11px; }

.debt-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.012));
  border: 1px solid var(--line);
  border-left: 4px solid var(--debt-color, var(--line));
  border-radius: 19px;
  padding: 15px;
}
.debt-card.paid { opacity: 0.72; }
.debt-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.debt-title { min-width: 0; }
.debt-head h3 { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 15.5px; letter-spacing: -0.01em; }
.debt-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--debt-color, var(--accent));
}
.debt-tags { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.debt-bank {
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: #cbd5e1;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.22);
  padding: 2px 7px;
  border-radius: 999px;
}
.debt-head-actions { display: flex; flex: none; gap: 4px; }
.badge {
  display: inline-block;
  margin-top: 5px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #c7d2fe;
  background: rgba(99, 102, 241, 0.16);
  border: 1px solid rgba(99, 102, 241, 0.28);
  padding: 2px 7px;
  border-radius: 999px;
}
.badge.good { color: #a7f3d0; background: rgba(52, 211, 153, 0.14); border-color: rgba(52, 211, 153, 0.3); }
.badge.bad { color: #fda4af; background: rgba(251, 113, 133, 0.12); border-color: rgba(251, 113, 133, 0.3); }
.debt-tags .badge { margin-top: 0; }

/* Selector de color de la deuda */
.color-pick { display: flex; flex-wrap: wrap; gap: 9px; padding: 2px 0; }
.color-pick label { position: relative; width: 32px; height: 32px; cursor: pointer; }
.color-pick input { position: absolute; inset: 0; margin: 0; opacity: 0; }
.color-pick span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--swatch);
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.22);
}
.color-pick input:checked + span { border-color: #fff; box-shadow: 0 0 0 2px var(--swatch); }
.color-pick input:focus-visible + span { outline: 2px solid #fff; outline-offset: 2px; }

.debt-amount {
  margin: 9px 0 6px;
  font-size: 27px;
  font-weight: 820;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}
.debt-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 11px;
}
.debt-meta span { display: inline-flex; align-items: center; gap: 4px; }
.debt-meta b { color: #cbd5e1; font-weight: 650; }

.debt-card .progress { height: 6px; }
.debt-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
}
.debt-foot > span { font-size: 11.5px; color: var(--muted-2); }
.row-actions { display: flex; gap: 7px; }

/* ---------- Gastos e ingresos ---------- */

.segmented.three { grid-template-columns: repeat(3, 1fr); }
.sub-head { margin-top: 18px; }
.sub-head h3 { margin: 0; font-size: 15px; letter-spacing: -0.02em; }

.free-money {
  margin: 8px 0 12px;
  font-size: 30px;
  font-weight: 820;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}
.free-money.bad { color: var(--bad); }
.mini-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 14px; }
.mini-grid > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding: 7px 0;
  border-top: 1px solid var(--line);
}
.mini-grid b { color: var(--text); font-variant-numeric: tabular-nums; }

.expense-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.expense-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.012));
  border: 1px solid var(--line);
  border-left: 4px solid var(--debt-color, var(--line));
  border-radius: 17px;
  padding: 13px 14px;
}
.expense-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.expense-main { min-width: 0; }
.expense-main h3 { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 14.5px; letter-spacing: -0.01em; }
.expense-bottom { display: flex; align-items: baseline; gap: 8px; margin-top: 10px; }
.expense-amount { font-size: 21px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.expense-amount.good { color: var(--good); }
.expense-bottom span { font-size: 11.5px; color: var(--muted-2); }
.expense-note { margin: 8px 0 0; font-size: 11.5px; color: var(--muted-2); }
.fixed-actions { margin-top: 10px; }
.fixed-actions .btn { width: 100%; }
.expense-card.paid { opacity: 0.78; }
.empty-mini {
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  padding: 18px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 12px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  font-size: 13px;
  color: var(--muted);
}
.toggle-row input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.daily-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.daily-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.daily-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.daily-date { flex: 0 0 40px; text-align: center; }
.daily-date b { display: block; font-size: 15px; }
.daily-date small { font-size: 10px; color: var(--muted-2); text-transform: uppercase; }
.daily-body { flex: 1 1 auto; min-width: 0; }
.daily-body b { display: block; font-size: 13px; }
.daily-body small { font-size: 11px; color: var(--muted-2); }
.history-edit {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted-2);
  padding: 0;
  font-size: 14px;
  line-height: 1;
}
.history-edit:hover { color: var(--accent-2); }

/* ---------- Próximos pagos ---------- */

.pay-list { display: flex; flex-direction: column; }
.pay-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.pay-item:last-child { border-bottom: 0; padding-bottom: 0; }
.pay-item:first-child { padding-top: 4px; }
.pay-date {
  flex: 0 0 auto;
  width: 46px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(99, 102, 241, 0.14);
  border: 1px solid rgba(99, 102, 241, 0.24);
  line-height: 1.05;
}
.pay-date b { font-size: 17px; font-weight: 800; }
.pay-date small { font-size: 9.5px; text-transform: uppercase; color: #a5b4fc; letter-spacing: 0.04em; }
.pay-date.soon { background: rgba(251, 191, 36, 0.14); border-color: rgba(251, 191, 36, 0.3); }
.pay-date.soon small { color: #fcd34d; }
.pay-body { flex: 1 1 auto; min-width: 0; }
.pay-body b { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pay-body small { font-size: 11.5px; color: var(--muted); }
.pay-amount { flex: 0 0 auto; text-align: right; }
.pay-amount b { display: block; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.pay-amount small { font-size: 11px; color: var(--muted-2); }
.pay-amount small.soon { color: var(--warn); font-weight: 700; }

/* ---------- Gráficos ---------- */

.chart-card { padding-bottom: 12px; }
.chart { display: block; width: 100%; height: auto; margin: 4px 0 2px; overflow: visible; }
.chart-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted-2);
  padding: 0 2px;
}

.donut-wrap { display: flex; align-items: center; gap: 16px; }
.donut { flex: 0 0 auto; width: 118px; height: 118px; }
.donut-label { fill: var(--text); font-size: 22px; font-weight: 800; font-family: inherit; }
.donut-sub { fill: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: 1px; font-family: inherit; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.legend li { display: flex; align-items: center; gap: 7px; font-size: 12px; min-width: 0; }
.legend .dot { width: 8px; height: 8px; border-radius: 3px; flex: 0 0 auto; }
.legend-name { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.legend b { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Simulador ---------- */

.field-label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 2px 0 8px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: rgba(2, 6, 16, 0.55);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 9px 6px;
  font-size: 13px;
  font-weight: 650;
}
.segmented button.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.85), rgba(79, 70, 229, 0.85));
  box-shadow: 0 6px 16px -8px rgba(99, 102, 241, 0.9);
}

.money-input {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  background: rgba(2, 6, 16, 0.55);
  border: 1px solid var(--line-strong);
  border-radius: 15px;
  padding: 5px;
  margin-top: 2px;
}
.money-input button {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 21px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.money-input button:active { transform: scale(0.94); }
.money-input input {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: center;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  outline: none;
  -moz-appearance: textfield;
}
.money-input input::-webkit-outer-spin-button,
.money-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  margin-top: 10px;
  background: transparent;
}
.range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #6366f1, #22d3ee);
}
.range::-moz-range-track { height: 6px; border-radius: 999px; background: linear-gradient(90deg, #6366f1, #22d3ee); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #6366f1;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
}
.range::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #6366f1;
}
.range-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted-2); margin-top: 2px; }

.compare {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin-top: 4px;
}
.compare th {
  text-align: right;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-2);
  font-weight: 700;
  padding: 0 6px 7px;
}
.compare th:first-child { text-align: left; }
.compare td {
  padding: 9px 6px;
  border-top: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.compare td:first-child { text-align: left; font-weight: 650; }
.compare tr.current td { color: #fff; }
.compare tr.current td:first-child::after {
  content: "actual";
  display: inline-block;
  margin-left: 6px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.18);
  border-radius: 999px;
  padding: 2px 6px;
  vertical-align: middle;
}
.compare .good { color: var(--good); font-weight: 700; }

.order-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; }
.order-list li {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.order-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.order-num {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 800;
  color: #c7d2fe;
  background: rgba(99, 102, 241, 0.16);
  border: 1px solid rgba(99, 102, 241, 0.3);
}
.order-body { flex: 1 1 auto; min-width: 0; }
.order-body b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-body small { font-size: 11px; color: var(--muted-2); }
.order-date { flex: 0 0 auto; text-align: right; font-size: 12px; font-weight: 650; }
.order-date small { display: block; font-size: 10.5px; color: var(--muted-2); font-weight: 400; }

/* ---------- Formularios ---------- */

.field { display: block; margin-bottom: 12px; }
.field > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: rgba(2, 6, 16, 0.55);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2394a3b8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 34px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: rgba(99, 102, 241, 0.75);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row .field { margin-bottom: 12px; }
.field-row .field > span { font-size: 11.5px; }

/* ---------- Modal ---------- */

body.modal-open { overflow: hidden; }

.overlay {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vvt, 0px);
  bottom: auto;
  height: var(--vvh, 100dvh);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  background: rgba(2, 6, 16, 0.66);
  backdrop-filter: blur(6px);
  animation: fade 0.18s ease;
}
@media (min-width: 600px) {
  .overlay { align-items: center; padding: 24px; }
}

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: min(92dvh, calc(var(--vvh, 100dvh) - 8px));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: linear-gradient(180deg, #111c33, #0b1322);
  border: 1px solid var(--line-strong);
  border-radius: 24px 24px 0 0;
  padding: 18px 18px calc(20px + var(--safe-b));
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.6);
  animation: sheetIn 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}
@media (min-width: 600px) {
  .sheet { border-radius: 24px; padding-bottom: 20px; }
}
@keyframes sheetIn {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.sheet-head h3 { margin: 0; font-size: 19px; letter-spacing: -0.02em; }
.sheet:has(.sheet-actions) { padding-bottom: 0; }
.sheet-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  gap: 9px;
  justify-content: flex-end;
  align-items: center;
  margin: 18px -18px 0 -18px;
  padding: 12px 18px calc(12px + var(--safe-b));
  background: #0b1322;
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 24px rgba(2, 6, 16, 0.55);
}
.sheet-actions .btn { flex: 0 0 auto; }
.sheet-actions .btn.danger { margin-right: auto; }

.confirm-msg { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.confirm-msg b { color: var(--text); }

.pay-debt-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.22);
  margin-bottom: 15px;
  font-size: 13.5px;
}
.pay-debt-info b { font-size: 17px; font-variant-numeric: tabular-nums; }

.split-preview {
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(2, 6, 16, 0.4);
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.split-preview .split-row { display: flex; justify-content: space-between; gap: 10px; }
.split-preview .split-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.split-preview .split-row.interest b { color: var(--warn); }
.split-preview .split-row.principal b { color: var(--good); }
.split-preview .split-row.total { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; }

/* ---------- Historial ---------- */

.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.history li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.history li:last-child { border-bottom: 0; padding-bottom: 0; }
.history-body { flex: 1 1 auto; min-width: 0; }
.history-body b { display: block; font-size: 13px; }
.history-body small { font-size: 11px; color: var(--muted-2); }
.history-amount { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.history-del {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted-2);
  padding: 0;
  font-size: 15px;
  line-height: 1;
}
.history-del:hover { color: var(--bad); }

/* ---------- Vacío ---------- */

.empty {
  text-align: center;
  padding: 46px 18px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.empty-icon {
  width: 82px;
  height: 82px;
  border-radius: 26px;
  display: grid;
  place-items: center;
  color: #c7d2fe;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.22), rgba(34, 211, 238, 0.12));
  border: 1px solid rgba(99, 102, 241, 0.3);
  margin-bottom: 6px;
}
.empty h2 { margin: 0; font-size: 22px; letter-spacing: -0.025em; }
.empty p { margin: 0 0 8px; color: var(--muted); font-size: 14px; line-height: 1.6; max-width: 330px; }
.empty .btn { min-width: 210px; }

/* ---------- FAB ---------- */

.fab {
  position: fixed;
  right: max(18px, calc(50% - 262px));
  bottom: calc(92px + var(--safe-b));
  z-index: 25;
  width: 54px;
  height: 54px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  font-size: 27px;
  font-weight: 300;
  line-height: 1;
  display: grid;
  place-items: center;
  box-shadow: 0 16px 34px -12px rgba(79, 70, 229, 0.95);
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.93); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(104px + var(--safe-b));
  transform: translate(-50%, 14px);
  z-index: 200;
  max-width: min(460px, calc(100% - 32px));
  padding: 11px 16px;
  border-radius: 14px;
  background: #16233d;
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast.err { border-color: rgba(251, 113, 133, 0.4); color: #fecdd3; }
.toast { display: flex; align-items: center; justify-content: center; gap: 10px; }
.toast-action {
  flex: none;
  border: 1px solid rgba(165, 180, 252, 0.55);
  background: rgba(99, 102, 241, 0.2);
  color: #e0e7ff;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 700;
}

/* ---------- Detalles ---------- */

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.25); border-radius: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- Explicación del simulador ---------- */

.explain-list {
  margin: 10px 0 12px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}
.explain-list b { color: var(--text); }

/* ---------- Comprobantes ---------- */

.receipt-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: -2px 0 12px;
}
.receipt-preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(2, 6, 16, 0.55);
}
.schedule-scroll {
  max-height: 55vh;
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.schedule-scroll .compare { margin: 0; }
.schedule-scroll .compare th { position: sticky; top: 0; background: var(--card); z-index: 1; }
.receipt-img {
  display: block;
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #05080f;
}
.history-receipt {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--accent-2);
  padding: 0;
  font-size: 16px;
  line-height: 1;
}
.field { scroll-margin-bottom: 96px; }


/* ============================================================
   Tema claro
   ============================================================ */

:root[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-soft: #eef2f9;
  --card: #ffffff;
  --card-2: #f7f9fd;
  --line: rgba(15, 23, 42, 0.1);
  --line-strong: rgba(15, 23, 42, 0.18);
  --text: #0f172a;
  --muted: #475569;
  --muted-2: #64748b;
  --good: #047857;
  --warn: #b45309;
  --bad: #be123c;
  --shadow: 0 20px 50px -24px rgba(15, 23, 42, 0.28);
  color-scheme: light;
}

[data-theme="light"] body {
  background:
    radial-gradient(1100px 520px at 5% -10%, rgba(99, 102, 241, 0.14), transparent 60%),
    radial-gradient(800px 460px at 105% 5%, rgba(34, 211, 238, 0.12), transparent 55%),
    var(--bg);
}

[data-theme="light"] .app-shell {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.02), transparent 30%);
}

[data-theme="light"] .topbar {
  background: linear-gradient(180deg, rgba(244, 246, 251, 0.96) 55%, rgba(244, 246, 251, 0));
}

[data-theme="light"] .tabbar {
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 18px 40px -24px rgba(15, 23, 42, 0.4);
}

[data-theme="light"] .tab.active {
  color: #3730a3;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(34, 211, 238, 0.12));
}

[data-theme="light"] .ghost-btn,
[data-theme="light"] .btn.ghost {
  background: rgba(15, 23, 42, 0.045);
}

[data-theme="light"] .card,
[data-theme="light"] .stat,
[data-theme="light"] .debt-card,
[data-theme="light"] .expense-card {
  background: #fff;
  box-shadow: 0 12px 30px -26px rgba(15, 23, 42, 0.35);
}

[data-theme="light"] .field input,
[data-theme="light"] .field select,
[data-theme="light"] .field textarea,
[data-theme="light"] .segmented,
[data-theme="light"] .money-input,
[data-theme="light"] .split-preview {
  background: #f8fafc;
}

[data-theme="light"] .money-input button {
  background: rgba(15, 23, 42, 0.05);
}

[data-theme="light"] .overlay {
  background: rgba(15, 23, 42, 0.34);
}

[data-theme="light"] .sheet {
  background: #fff;
  box-shadow: 0 -20px 60px rgba(15, 23, 42, 0.18);
}

[data-theme="light"] .sheet-actions {
  background: #fff;
  box-shadow: 0 -10px 24px rgba(15, 23, 42, 0.08);
}

[data-theme="light"] .toast {
  background: #fff;
  box-shadow: 0 18px 40px -18px rgba(15, 23, 42, 0.3);
}

[data-theme="light"] .toast-action {
  color: #3730a3;
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.35);
}

[data-theme="light"] .schedule-scroll {
  background: #fff;
}

[data-theme="light"] .receipt-img {
  background: #f1f5f9;
}

[data-theme="light"] .badge.good {
  color: #047857;
}

[data-theme="light"] .alert.info strong {
  color: #0e7490;
}

[data-theme="light"] .alert.bad strong {
  color: #be123c;
}

[data-theme="light"] .alert.warn strong {
  color: #b45309;
}

[data-theme="light"] .btn.danger.ghost {
  color: #be123c;
}

[data-theme="light"] .toast.err {
  color: #be123c;
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.2);
}

[data-theme="light"] .debt-bank {
  color: #475569;
  background: rgba(15, 23, 42, 0.06);
  border-color: rgba(15, 23, 42, 0.12);
}

[data-theme="light"] .hero-amount,
[data-theme="light"] .hero-stats b {
  color: #f8fafc;
}

/* Contraste de etiquetas y tablas en tema claro */
[data-theme="light"] .badge {
  color: #3730a3;
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.22);
}

[data-theme="light"] .badge.good {
  color: #047857;
  background: rgba(5, 150, 105, 0.1);
  border-color: rgba(5, 150, 105, 0.22);
}

[data-theme="light"] .badge.bad {
  color: #be123c;
  background: rgba(190, 18, 60, 0.08);
  border-color: rgba(190, 18, 60, 0.22);
}

[data-theme="light"] .debt-meta b {
  color: var(--text);
}

[data-theme="light"] .pay-date small {
  color: #4338ca;
}

[data-theme="light"] .pay-date.soon small {
  color: #92400e;
}

[data-theme="light"] .compare tr.current td {
  color: var(--text);
  background: rgba(99, 102, 241, 0.08);
}

[data-theme="light"] .compare tr.current td:first-child::after {
  color: #3730a3;
  background: rgba(99, 102, 241, 0.14);
}

[data-theme="light"] .order-num {
  color: #3730a3;
}
