:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #16202b;
  --muted: #64707d;
  --line: #e3e8ee;
  --accent: #0f766e;
  --accent-soft: #d6efec;
  --ingreso: #15803d;
  --gasto: #c2410c;
  --neutro: #64748b;
  --alerta: #b45309;
  --alerta-soft: #fef3c7;
  --peligro: #b91c1c;
  --radio: 14px;
  --sombra: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --card: #161b22; --text: #e6edf3; --muted: #8b949e; --line: #262d36;
    --accent: #2dd4bf; --accent-soft: #123b37; --ingreso: #4ade80; --gasto: #fb923c; --neutro: #94a3b8;
    --alerta: #fbbf24; --alerta-soft: #3a2e0b; --peligro: #f87171; --sombra: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --card: #161b22; --text: #e6edf3; --muted: #8b949e; --line: #262d36;
  --accent: #2dd4bf; --accent-soft: #123b37; --ingreso: #4ade80; --gasto: #fb923c; --neutro: #94a3b8;
  --alerta: #fbbf24; --alerta-soft: #3a2e0b; --peligro: #f87171; --sombra: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 10px; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted, .nota { color: var(--muted); font-size: 13px; }
.error { color: var(--peligro); min-height: 1.2em; }

/* Ingreso */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-caja { width: 100%; max-width: 360px; text-align: center; display: grid; gap: 14px; justify-items: center; }
.login-caja h1 { font-size: 26px; }
.login-caja p { margin: 0; color: var(--muted); }
#dev-login { display: grid; gap: 8px; width: 100%; }

/* Barra y pestañas */
#app { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.barra {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: center; gap: 4px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.mes-titulo { background: none; border: 0; font-weight: 700; font-size: 17px; padding: 6px 10px; border-radius: 10px; min-width: 160px; cursor: pointer; }
.mes-flecha { background: none; border: 0; font-size: 26px; line-height: 1; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; color: var(--muted); }
.mes-flecha:hover, .mes-titulo:hover { background: var(--line); }
.sync { position: absolute; right: 16px; width: 8px; height: 8px; border-radius: 50%; background: var(--ingreso); transition: background .3s; }
.sync.cargando { background: var(--alerta); }
.sync.error { background: var(--peligro); }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs a { display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; padding: 4px 0; }
.tabs a.activa { color: var(--accent); font-weight: 600; }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab-agregar { justify-self: center; width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; cursor: pointer; display: grid; place-items: center; box-shadow: 0 4px 12px rgba(15, 118, 110, .35); margin-top: -18px; }
.tab-agregar svg { width: 26px; height: 26px; stroke-width: 2.4; }
:root[data-theme="dark"] .tab-agregar, .tab-agregar { color: var(--card); }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
.vista { display: none; gap: 14px; }
.vista.activa { display: grid; }

/* Tarjetas */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radio); padding: 16px; box-shadow: var(--sombra); min-width: 0; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { padding: 14px; }
.kpi .etq { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.ingreso .val { color: var(--ingreso); }
.kpi.gasto .val { color: var(--gasto); }
.kpi.ahorro { grid-column: span 2; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.barra-ahorro { flex: 1; max-width: 220px; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.barra-ahorro > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

.alerta { display: flex; gap: 10px; align-items: center; background: var(--alerta-soft); color: var(--text); border: 1px solid transparent; border-radius: var(--radio); padding: 12px 14px; text-decoration: none; }
.alerta b { color: var(--alerta); }
.alerta .flecha { margin-left: auto; color: var(--alerta); font-size: 20px; }

.grafico { position: relative; height: 220px; }
.grafico.alto { height: 260px; }
.dona { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: center; }
.dona .grafico { height: 150px; }
.card { container-type: inline-size; }
@container (max-width: 400px) { .dona { grid-template-columns: 1fr; } .dona .grafico { height: 170px; } }

.lista-barras { display: grid; gap: 10px; }
.lb { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 14px; }
.lb .nom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lb .nom span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .pista { grid-column: span 2; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.lb .pista > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.punto { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.vacio { text-align: center; color: var(--muted); padding: 28px 12px; }
.vacio p { margin: 6px 0 14px; }

/* Movimientos */
.filtros { display: flex; gap: 8px; flex-wrap: wrap; }
.filtros input[type=search] { flex: 1 1 200px; }
.filtros select { flex: 0 1 auto; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; }
.chip.activa { background: var(--accent); border-color: var(--accent); color: var(--card); font-weight: 600; }
.chip .n { opacity: .75; margin-left: 4px; }
.resumen-lista { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.dia { padding: 0; overflow: hidden; }
.dia-cab { display: flex; justify-content: space-between; padding: 10px 14px; font-size: 13px; font-weight: 600; color: var(--muted); background: var(--bg); border-bottom: 1px solid var(--line); text-transform: capitalize; }
.mov { display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; align-items: center; padding: 11px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; width: 100%; text-align: left; cursor: pointer; }
.mov:last-child { border-bottom: 0; }
.mov:hover { background: var(--bg); }
.mov .ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff; }
.mov .txt { min-width: 0; }
.mov .t1, .mov .t2 { display: block; }
.mov .t1 { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mov .t2 { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mov .m { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.mov .m small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }
.m.ingreso { color: var(--ingreso); }
.m.gasto { color: var(--text); }
.m.neutro { color: var(--neutro); }
.etiqueta { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--alerta-soft); color: var(--alerta); vertical-align: 1px; margin-left: 4px; text-transform: uppercase; letter-spacing: .03em; }

/* Formularios */
input, select { width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.btn { min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 600; cursor: pointer; }
.btn.primario { background: var(--accent); color: var(--card); border-color: var(--accent); }
.btn.peligro { color: var(--peligro); }
.btn.chico { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.campo { display: grid; gap: 4px; }
.campo > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.fila2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: 20px; min-height: 20px; }
.ayuda { font-size: 13px; color: var(--muted); margin: 0; }

.hoja { border: 0; padding: 0; background: var(--card); color: var(--text); width: 100%; max-width: 480px; border-radius: 18px; }
.hoja::backdrop { background: rgba(0, 0, 0, .45); }
@media (max-width: 560px) { .hoja { margin: auto 0 0; max-width: none; border-radius: 18px 18px 0 0; max-height: 92dvh; } }
.hoja form { display: grid; gap: 12px; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.hoja header, .hoja footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.hoja footer .primario { flex: 1; }
.cerrar { border: 0; background: var(--bg); width: 34px; height: 34px; border-radius: 50%; font-size: 22px; line-height: 1; cursor: pointer; }
.monto input { font-size: 28px; font-weight: 700; text-align: center; min-height: 58px; font-variant-numeric: tabular-nums; }
.segmento { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--bg); border-radius: 10px; padding: 3px; gap: 2px; }
.segmento label { position: relative; }
.segmento input { position: absolute; opacity: 0; pointer-events: none; }
.segmento span { display: block; text-align: center; padding: 8px 2px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmento input:checked + span { background: var(--card); color: var(--text); box-shadow: var(--sombra); }
.segmento input:focus-visible + span { outline: 2px solid var(--accent); }

/* Correo */
.pasos { counter-reset: paso; display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; }
.pasos > li { counter-increment: paso; display: grid; grid-template-columns: 28px 1fr; gap: 10px; }
.pasos > li::before { content: counter(paso); width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; font-size: 14px; }
.pasos p { margin: 2px 0 8px; }
.copiable { display: flex; gap: 8px; align-items: stretch; }
.copiable code { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); font-size: 13px; overflow-wrap: anywhere; }
.codigo-conf { font-size: 26px; font-weight: 800; letter-spacing: .1em; color: var(--accent); }
.estado-ok { color: var(--ingreso); font-weight: 600; }
.correo-fila { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.correo-fila:last-child { border-bottom: 0; }
.correo-fila .asunto { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.correo-fila .det { grid-column: span 2; font-size: 12px; color: var(--muted); }
.res { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; align-self: start; white-space: nowrap; }
.res.ok { background: var(--accent-soft); color: var(--accent); }
.res.no_reconocido { background: var(--alerta-soft); color: var(--alerta); }
.res.duplicado, .res.ignorado, .res.confirmacion { background: var(--bg); color: var(--muted); }

/* Ajustes */
.ajuste-lista { display: grid; gap: 0; }
.ajuste-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.ajuste-item:last-child { border-bottom: 0; }
.ajuste-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ajuste-item button.x { border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; width: 32px; height: 32px; border-radius: 50%; }
.ajuste-item button.x:hover { background: var(--bg); color: var(--peligro); }
.form-linea { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.form-linea input { flex: 1 1 140px; }
.form-linea select { flex: 0 1 120px; }
.form-linea input[type=color] { flex: 0 0 48px; padding: 4px; }
.botones { display: flex; gap: 8px; flex-wrap: wrap; }

.aviso { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; max-width: calc(100% - 32px); z-index: 20; }
.aviso.ver { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .kpi.ahorro { grid-column: span 1; display: block; }
  .barra-ahorro { margin-top: 8px; max-width: none; }
  .dos-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
