/* =============================================================
   Finanzas · God's Plan — tema oscuro, acentos rojos
   ============================================================= */
:root {
  --bg: #0a0a0c;
  --bg-2: #101013;
  --card: #141418;
  --card-2: #1b1b20;
  --borde: rgba(255, 255, 255, 0.07);
  --borde-2: rgba(255, 255, 255, 0.13);
  --texto: #f5f5f6;
  --suave: #a1a1aa;
  --tenue: #6b6b74;
  --rojo: #ff5a5f;
  --rojo-2: #e02a33;
  --rojo-glow: rgba(255, 90, 95, 0.28);
  --ok: #4ade80;
  --warn: #fbbf24;
  --radio: 20px;
  --radio-s: 14px;
  --f-titulo: "Montserrat", system-ui, sans-serif;
  --f-texto: "Inter", system-ui, -apple-system, sans-serif;
  --f-num: "Martian Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --tabbar-h: 64px;
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(224, 42, 51, 0.16), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(255, 90, 95, 0.07), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--texto);
  font-family: var(--f-texto);
  font-size: 15px;
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: var(--f-titulo); margin: 0; letter-spacing: -0.01em; }
.mono { font-family: var(--f-num); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 16px) 10px calc(var(--safe-l) + 16px);
  background: rgba(10, 10, 12, 0.78);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid var(--borde);
}
.topbar__inner { max-width: 1480px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand__mark {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 11px;
  background: linear-gradient(145deg, var(--rojo), var(--rojo-2));
  font-family: var(--f-titulo); font-weight: 800; font-size: 14px; color: #fff;
  box-shadow: 0 6px 20px var(--rojo-glow);
}
.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__name { font-family: var(--f-titulo); font-weight: 700; font-size: 16px; }
.brand__date { color: var(--suave); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sync { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--suave); padding: 6px 10px; border: 1px solid var(--borde); border-radius: 999px; background: var(--bg-2); white-space: nowrap; }
.sync__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--tenue); }
.sync[data-estado="ok"] .sync__dot { background: var(--ok); box-shadow: 0 0 8px rgba(74, 222, 128, 0.6); }
.sync[data-estado="pendiente"] .sync__dot { background: var(--warn); }
.sync[data-estado="offline"] .sync__dot { background: var(--tenue); }
.sync[data-estado="error"] .sync__dot { background: var(--rojo); }

/* ---------- Layout ---------- */
.layout {
  max-width: 1480px;
  margin: 0 auto;
  padding: 14px calc(var(--safe-r) + 14px) calc(var(--tabbar-h) + var(--safe-b) + 24px) calc(var(--safe-l) + 14px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.col { display: contents; }

/* Orden en móvil */
#hero { order: 1; }
#registro { order: 2; }
#boveda { order: 3; }
#historial { order: 4; }
#ciclo { order: 5; }
#fijos { order: 6; }
#sync { order: 7; }

/* Tabs en móvil: solo se ven las secciones del tab activo */
@media (max-width: 1023.98px) {
  body[data-tab="hoy"] [data-tab]:not([data-tab="hoy"]),
  body[data-tab="historial"] [data-tab]:not([data-tab="historial"]),
  body[data-tab="ajustes"] [data-tab]:not([data-tab="ajustes"]) { display: none; }
}

/* ---------- Tarjetas ---------- */
.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 40%), var(--card);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 18px;
  min-width: 0;
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
#historial .card__head { flex-wrap: wrap; }
.card__head h2 { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.ico { color: var(--rojo); display: inline-flex; }
.eyebrow { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--suave); }
.mini-titulo { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--tenue); margin: 18px 0 6px; }
.nota { color: var(--tenue); font-size: 12.5px; margin: 8px 0 0; }

.pill { font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 999px; background: rgba(255, 90, 95, 0.12); color: var(--rojo); border: 1px solid rgba(255, 90, 95, 0.25); white-space: nowrap; }
.pill--suave { background: var(--card-2); color: var(--suave); border-color: var(--borde); }

/* ---------- Hero ---------- */
.hero {
  position: relative;
  overflow: hidden;
  padding: 20px 18px;
  background:
    radial-gradient(500px 220px at 100% 0%, rgba(255, 90, 95, 0.22), transparent 70%),
    linear-gradient(160deg, #1a0d0f 0%, #141418 55%);
  border-color: rgba(255, 90, 95, 0.2);
}
.hero__top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hero__monto {
  font-size: clamp(40px, 13vw, 64px);
  font-weight: 700;
  line-height: 1.05;
  margin: 12px 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hero__monto.negativo { color: var(--rojo); }
.hero__sub { color: var(--suave); margin: 0 0 16px; font-size: 14px; }
.hero__proyeccion { margin: 14px 0 0; font-size: 13.5px; color: var(--suave); }
.hero__proyeccion b { color: var(--texto); font-family: var(--f-num); font-weight: 500; }

.barra { position: relative; display: flex; height: 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.barra__gasto { height: 100%; width: 0; background: linear-gradient(90deg, var(--rojo-2), var(--rojo)); box-shadow: 0 0 16px var(--rojo-glow); transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1); }
.barra__boveda { height: 100%; width: 0; background: repeating-linear-gradient(45deg, rgba(255,255,255,.75) 0 4px, rgba(255,255,255,.45) 4px 8px); transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1); }
.barra.excedida .barra__gasto { background: var(--rojo); animation: pulso 1.6s ease-in-out infinite; }
@keyframes pulso { 50% { opacity: 0.65; } }
.barra__leyenda { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12.5px; color: var(--suave); }
.barra__leyenda b { color: var(--texto); font-weight: 500; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot--rojo { background: var(--rojo); }
.dot--blanco { background: rgba(255, 255, 255, 0.7); }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 18px; }
.stat { background: rgba(0, 0, 0, 0.28); border: 1px solid var(--borde); border-radius: var(--radio-s); padding: 10px 10px; min-width: 0; }
.stat__label { display: block; font-size: 10.5px; color: var(--tenue); text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat__valor { display: block; font-size: 13px; font-weight: 500; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat__valor.negativo { color: var(--rojo); }

.aviso { margin-top: 14px; padding: 11px 13px; border-radius: var(--radio-s); font-size: 13.5px; background: rgba(255, 90, 95, 0.1); border: 1px solid rgba(255, 90, 95, 0.3); color: #ffc9cb; }
.aviso--warn { background: rgba(251, 191, 36, 0.08); border-color: rgba(251, 191, 36, 0.3); color: #fde4a1; }
#btnConfigurar { margin-top: 16px; }

/* ---------- Bóveda ---------- */
.boveda__monto { font-size: 32px; font-weight: 700; margin: 2px 0 6px; letter-spacing: 0.02em; }
.boveda__monto.oculto { color: var(--suave); }
.boveda__detalle { display: grid; gap: 6px; margin: 6px 0 4px; padding: 10px 12px; background: var(--bg-2); border: 1px solid var(--borde); border-radius: var(--radio-s); font-size: 13px; }
.boveda__detalle div { display: flex; justify-content: space-between; gap: 8px; color: var(--suave); }
.boveda__detalle b { color: var(--texto); font-weight: 500; }
.boveda .campo { margin-top: 14px; }
.acciones { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 16px; }

.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--borde-2); background: var(--card-2); display: grid; place-items: center; color: var(--suave); }
.icon-btn:hover { color: var(--texto); }
.icon-btn .ojo-cerrado { display: none; }
.icon-btn[aria-pressed="true"] .ojo-abierto { display: none; }
.icon-btn[aria-pressed="true"] .ojo-cerrado { display: block; }

/* ---------- Botones ---------- */
.btn {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.12s ease, background 0.2s ease, opacity 0.2s;
  touch-action: manipulation;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn--primario { background: linear-gradient(180deg, var(--rojo), var(--rojo-2)); color: #fff; box-shadow: 0 8px 22px var(--rojo-glow), inset 0 1px 0 rgba(255,255,255,.25); }
.btn--primario:hover:not(:disabled) { filter: brightness(1.06); }
.btn--sec { background: var(--card-2); border-color: var(--borde-2); color: var(--texto); }
.btn--sec:hover { background: #24242a; }
.btn--fantasma { background: transparent; border-color: var(--borde-2); color: var(--suave); }
.btn--peligro { background: transparent; border-color: rgba(255, 90, 95, 0.4); color: var(--rojo); }
.btn--bloque { width: 100%; }
.btn--grande { min-height: 56px; font-size: 16px; }
#btnNuevoCiclo { margin-top: 10px; }

/* ---------- Inputs ---------- */
.form { display: grid; gap: 14px; }
.campo { display: grid; gap: 7px; }
.campo__label { font-size: 12.5px; color: var(--suave); font-weight: 500; }
.input { display: flex; align-items: center; background: var(--bg-2); border: 1px solid var(--borde-2); border-radius: 14px; min-height: 50px; padding: 0 14px; transition: border-color 0.2s, box-shadow 0.2s; min-width: 0; }
.input:focus-within { border-color: var(--rojo); box-shadow: 0 0 0 3px rgba(255, 90, 95, 0.18); }
.input input {
  flex: 1; min-width: 0; width: 100%;
  background: transparent; border: 0; outline: 0; color: var(--texto);
  font-size: 16px; /* ≥16px: evita el zoom automático de Safari iOS */
  font-family: inherit; padding: 12px 0;
}
.input input.mono { font-family: var(--f-num); }
.input input::placeholder { color: var(--tenue); }
.input input[type="date"] { color-scheme: dark; min-height: 24px; }
.input--prefijo > span, .input--sufijo > span { color: var(--tenue); font-size: 16px; }
.input--prefijo > span { margin-right: 8px; }
.input--sufijo > span { margin-left: 8px; }
.fila { display: flex; gap: 10px; margin-top: 10px; }
.fila .input { flex: 1; }

.monto-input { display: flex; align-items: center; gap: 6px; padding: 6px 16px; min-height: 76px; background: var(--bg-2); border: 1px solid var(--borde-2); border-radius: 18px; transition: border-color 0.2s, box-shadow 0.2s; }
.monto-input:focus-within { border-color: var(--rojo); box-shadow: 0 0 0 3px rgba(255, 90, 95, 0.18); }
.monto-input__signo { font-size: 30px; color: var(--tenue); }
.monto-input input { flex: 1; min-width: 0; width: 100%; background: transparent; border: 0; outline: 0; color: var(--texto); font-size: 36px; font-weight: 700; padding: 6px 0; }
.monto-input input::placeholder { color: #3a3a42; }
#formGasto { display: grid; gap: 12px; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips--scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 2px 18px; scroll-padding: 18px; }
.chips--scroll::-webkit-scrollbar { display: none; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--borde-2); background: var(--card-2); color: var(--suave); font-size: 14px; font-weight: 500; white-space: nowrap; flex-shrink: 0; touch-action: manipulation; }
.chip:hover { color: var(--texto); }
.chip.activo { background: rgba(255, 90, 95, 0.14); border-color: var(--rojo); color: #fff; }
.chips--mini .chip { min-height: 34px; padding: 0 12px; font-size: 13px; }

/* Switch */
.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__ui { flex-shrink: 0; width: 48px; height: 28px; border-radius: 999px; background: #2a2a31; border: 1px solid var(--borde-2); position: relative; transition: background 0.2s; margin-top: 2px; }
.switch__ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch input:checked + .switch__ui { background: var(--rojo-2); border-color: var(--rojo); }
.switch input:checked + .switch__ui::after { transform: translateX(20px); }
.switch input:focus-visible + .switch__ui { box-shadow: 0 0 0 3px rgba(255, 90, 95, 0.3); }
.switch__txt { display: grid; gap: 2px; font-size: 14px; }
.switch__txt small { color: var(--tenue); font-size: 12.5px; }

/* ---------- Listas ---------- */
.lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.mov { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--borde); }
.mov:last-child { border-bottom: 0; }
.mov__ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--card-2); font-size: 18px; }
.mov__ico--boveda { background: rgba(255, 255, 255, 0.08); }
.mov__info { min-width: 0; }
.mov__titulo { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mov__sub { display: block; font-size: 12px; color: var(--tenue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mov__monto { font-size: 14px; font-weight: 500; white-space: nowrap; }
.mov__monto--gasto { color: var(--texto); }
.mov__monto--boveda { color: var(--suave); }
.mov__monto--mas { color: var(--ok); }
.borrar { width: 36px; height: 36px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--tenue); display: grid; place-items: center; font-size: 13px; font-weight: 600; transition: all 0.2s; }
.borrar:hover { color: var(--rojo); background: rgba(255, 90, 95, 0.08); }
.borrar.confirmar { width: auto; padding: 0 10px; color: #fff; background: var(--rojo-2); }
.borrar--vacio { visibility: hidden; }

.dia { margin-top: 14px; }
.dia:first-child { margin-top: 0; }
.dia__head { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 4px; font-size: 12px; color: var(--tenue); text-transform: uppercase; letter-spacing: 0.07em; border-bottom: 1px solid var(--borde-2); }
.dia__head b { font-family: var(--f-num); font-weight: 500; color: var(--suave); letter-spacing: 0; text-transform: none; }
.vacio { text-align: center; color: var(--tenue); padding: 28px 10px; font-size: 14px; }

/* Fijos */
.fijo { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 8px 2px; border-bottom: 1px solid var(--borde); }
.fijo__check { width: 30px; height: 30px; border-radius: 9px; border: 1.5px solid var(--borde-2); background: var(--bg-2); display: grid; place-items: center; color: transparent; }
.fijo.pagado .fijo__check { background: var(--rojo-2); border-color: var(--rojo); color: #fff; }
.fijo__nombre { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fijo.pagado .fijo__nombre { color: var(--tenue); text-decoration: line-through; }
.fijo__monto { font-size: 14px; }
.fijo.pagado .fijo__monto { color: var(--tenue); }
.fijo-form { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) auto; gap: 8px; margin-top: 12px; }

/* Código sync */
.codigo { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.codigo code { flex: 1; min-width: 0; padding: 13px 14px; border-radius: 14px; background: var(--bg-2); border: 1px dashed var(--borde-2); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--rojo); }

/* ---------- Tab bar (móvil) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px calc(var(--safe-r) + 10px) calc(var(--safe-b) + 6px) calc(var(--safe-l) + 10px);
  background: rgba(12, 12, 14, 0.86);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-top: 1px solid var(--borde);
}
.tab { min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; background: none; border: 0; color: var(--tenue); font-size: 11px; font-weight: 600; border-radius: 12px; touch-action: manipulation; }
.tab.activo { color: var(--rojo); }

/* ---------- Modal / hoja inferior ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal__fondo { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fade 0.2s ease; }
.modal__hoja {
  position: relative; width: 100%; max-width: 520px;
  background: var(--card); border: 1px solid var(--borde-2); border-bottom: 0;
  border-radius: 24px 24px 0 0;
  padding: 10px calc(var(--safe-r) + 18px) calc(var(--safe-b) + 18px) calc(var(--safe-l) + 18px);
  max-height: 90dvh; overflow-y: auto;
  animation: subir 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal__asa { width: 40px; height: 5px; border-radius: 999px; background: var(--borde-2); margin: 0 auto 14px; }
.modal__hoja h2 { font-size: 19px; margin-bottom: 6px; }
#modalForm { display: grid; gap: 14px; margin-top: 12px; }
.modal__botones { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 4px; }
@keyframes subir { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: #222228; border: 1px solid var(--borde-2); border-radius: 14px; padding: 12px 14px; font-size: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.5); animation: subir 0.25s ease; pointer-events: auto; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.toast--error { border-color: rgba(255, 90, 95, 0.5); }
.toast button { background: none; border: 0; color: var(--rojo); font-weight: 600; padding: 4px; }

/* ---------- Tablet / escritorio ---------- */
@media (min-width: 1024px) {
  body { font-size: 15px; }
  .tabbar { display: none; }
  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    grid-template-areas: "a b" "c b";
    align-items: start;
    gap: 20px;
    padding: 24px calc(var(--safe-r) + 28px) 40px calc(var(--safe-l) + 28px);
  }
  .col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
  .col-a { grid-area: a; }
  .col-b { grid-area: b; position: sticky; top: 84px; }
  .col-c { grid-area: c; }
  .card { padding: 22px; }
  .hero { padding: 26px 24px; }
  .hero__monto { font-size: 68px; }
  .stat__valor { font-size: 16px; }
  .chips--scroll { flex-wrap: wrap; margin: 0; padding: 0; }
  .recientes { display: none; }
  #historialLista { max-height: calc(100dvh - 520px); min-height: 260px; overflow-y: auto; padding-right: 4px; }
  .modal { align-items: center; }
  .modal__hoja { border-radius: 24px; border-bottom: 1px solid var(--borde-2); padding-bottom: 22px; }
  .modal__asa { display: none; }
  .toasts { bottom: 28px; }
}

@media (min-width: 1360px) {
  .layout {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 0.85fr);
    grid-template-areas: "a b c";
  }
  .col-c { position: sticky; top: 84px; }
}

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