/* ============================================================
   Finanzas del hogar
   Sobrio: grises neutros, morado como acento (botones, selección, pestaña
   activa) y el verde solo para la plata que entra. Íconos de línea (iconos.js), sin emojis.
   Contraste medido (WCAG) con scripts/contraste.py: si cambias un color,
   vuelve a medir.
   ============================================================ */
:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #ededea;
  --text: #18181b;
  --muted: #5f5f66;
  --line: #e6e6e2;
  --accent: #5b36b8;         /* fondo de botones principales */
  --accent-text: #5232a8;    /* acento como texto */
  --accent-soft: #ece7f8;
  --on-accent: #ffffff;
  --ingreso: #13693a;
  --ingreso-soft: #e3f1e8;
  --ahorro: #1f5b9e;
  --danger: #b42318;
  --on-danger: #ffffff;
  --shadow: 0 1px 2px rgba(24, 24, 27, 0.05);
  --shadow-lg: 0 -8px 32px rgba(24, 24, 27, 0.12);
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111113; --surface: #1b1b1e; --surface-2: #27272b;
    --text: #f4f4f5; --muted: #a8a8b0; --line: #2c2c31;
    --accent: #6e4ad0; --accent-text: #c3b1f5; --accent-soft: #2a2340; --on-accent: #ffffff;
    --ingreso: #5fd08b; --ingreso-soft: #173524; --ahorro: #8cbcf2; --danger: #f6a091; --on-danger: #111113;
    --shadow: none; --shadow-lg: 0 -8px 32px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111113; --surface: #1b1b1e; --surface-2: #27272b;
  --text: #f4f4f5; --muted: #a8a8b0; --line: #2c2c31;
  --accent: #6e4ad0; --accent-text: #c3b1f5; --accent-soft: #2a2340; --on-accent: #ffffff;
  --ingreso: #5fd08b; --ingreso-soft: #173524; --ahorro: #8cbcf2; --danger: #f6a091; --on-danger: #111113;
  --shadow: none; --shadow-lg: 0 -8px 32px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; margin: 0; padding: 0; }
html, body {
  min-height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased;
}
body { overflow-x: hidden; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font: inherit; color: var(--text); }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.ico { width: 20px; height: 20px; flex: 0 0 auto; display: block; }
[data-ico] { display: inline-flex; align-items: center; justify-content: center; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ingreso { color: var(--ingreso); }
.ahorro { color: var(--ahorro); }

/* ---------- Botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; min-height: 50px; padding: 0.75rem 1.2rem; border-radius: var(--r-md); font-weight: 600; font-size: 1rem; }
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn-primario { background: var(--accent); color: var(--on-accent); }
.btn-secundario { background: var(--accent-soft); color: var(--accent-text); }
.btn-texto { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--accent-text); min-height: 44px; padding: 0.5rem 0.75rem; font-weight: 600; font-size: 0.95rem; }
.btn-texto .ico { width: 18px; height: 18px; }
.btn-eliminar { background: var(--danger); color: var(--on-danger); }
.btn-peligro { color: var(--danger); background: transparent; flex: 0 0 auto !important; padding-left: 0.5rem; padding-right: 0.75rem; }
.icono-btn { width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); flex: 0 0 auto; }
.icono-btn .ico { width: 22px; height: 22px; }
.icono-btn:active { background: var(--surface-2); }
.icono-btn[disabled] { opacity: 0.35; }

/* ---------- Campos ---------- */
.campo { display: flex; flex-direction: column; gap: 0.4rem; text-align: left; }
.campo > span { font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.campo input, .campo select, .campo textarea, .hoja-cuerpo > textarea {
  width: 100%; min-height: 50px; padding: 0.75rem 0.9rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-sm); outline: none; font-size: 1rem;
}
.campo input:focus, .campo select:focus, .campo textarea:focus, .hoja-cuerpo > textarea:focus { border-color: var(--accent-text); }
.hoja-cuerpo > textarea { resize: none; font-size: 1.05rem; }
.error { color: var(--danger); font-size: 0.95rem; }

/* ---------- Entrar ---------- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 1rem; text-align: center; }
.login-logo { align-self: center; border-radius: 16px; margin-bottom: 0.25rem; }
.login-card h1 { font-size: 1.5rem; letter-spacing: -0.02em; font-weight: 700; margin-bottom: 0.75rem; }
.login-card .campo input { background: var(--surface); }

/* ---------- App ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.cabecera { padding: max(18px, env(safe-area-inset-top)) 16px 10px; }
.saludo { font-size: 0.95rem; color: var(--muted); font-weight: 500; }
.cabecera h1 { font-size: 1.75rem; letter-spacing: -0.03em; font-weight: 700; }
.contenido { flex: 1; padding: 6px 16px calc(150px + env(safe-area-inset-bottom)); }
.vista { display: flex; flex-direction: column; gap: 22px; }
.tarjeta { background: var(--surface); border-radius: var(--r-lg); padding: 1.25rem; box-shadow: var(--shadow); border: 1px solid var(--line); }
.etiqueta { font-size: 0.8125rem; font-weight: 500; color: var(--muted); }

/* ---------- Inicio: resumen ---------- */
.resumen-queda { font-size: 2.5rem; font-weight: 700; letter-spacing: -0.035em; line-height: 1.1; margin: 0.2rem 0 1.25rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.resumen-queda.negativo { color: var(--danger); }
.resumen-fila { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.resumen-dato { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }
.dato-cab { display: flex; align-items: center; gap: 0.45rem; }
.dato-ico { flex: 0 0 24px; width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2); color: var(--text); }
.dato-ico.ingreso { background: var(--ingreso-soft); color: var(--ingreso); }
.dato-ico .ico { width: 14px; height: 14px; }
.resumen-num { font-size: 1.2rem; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.resumen-ahorro { display: flex; align-items: center; gap: 0.5rem; margin-top: 1rem; padding-top: 0.9rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.95rem; }
.resumen-ahorro .ico { color: var(--ahorro); width: 18px; height: 18px; }
.resumen-ahorro strong { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; }

.seccion { display: flex; flex-direction: column; gap: 10px; }
.seccion h2 { font-size: 1.05rem; font-weight: 650; }
.seccion-cab { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.seccion-cab .btn-texto { margin-right: -0.75rem; }

/* ---------- Filas ---------- */
.lista { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden; }
.lista:empty { display: none; }
.fila { display: flex; align-items: center; gap: 0.85rem; width: 100%; min-height: 64px; padding: 0.7rem 1rem; text-align: left; border-bottom: 1px solid var(--line); }
.fila:last-child { border-bottom: none; }
.fila:active { background: var(--surface-2); }
.fila-icono { flex: 0 0 40px; width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); color: var(--text); display: flex; align-items: center; justify-content: center; }
.fila-icono.es-ingreso { background: var(--ingreso-soft); color: var(--ingreso); }
.fila-texto { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.fila-titulo { font-weight: 550; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.fila-sub:empty { display: none; }
.fila-sub { font-size: 0.8125rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fila-monto { flex: 0 0 auto; font-weight: 650; font-variant-numeric: tabular-nums; }
.fila.inactiva .fila-titulo { color: var(--muted); }
.dia { display: flex; justify-content: space-between; font-size: 0.8125rem; font-weight: 600; color: var(--muted); margin: 1.25rem 0.25rem 0.5rem; }
.dia:first-child { margin-top: 0.25rem; }

.vacio { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r-lg); padding: 1.5rem 1.25rem; display: flex; flex-direction: column; gap: 0.35rem; align-items: center; text-align: center; }
.vacio-titulo { font-size: 1rem; font-weight: 600; }

/* ---------- Movimientos: filtros ---------- */
.mes-nav { display: flex; align-items: center; justify-content: space-between; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow); padding: 0.2rem; }
.mes-nombre { font-weight: 650; font-size: 1.05rem; }
.buscador { position: relative; display: block; }
.buscador > [data-ico] { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.buscador input { width: 100%; min-height: 48px; padding: 0.7rem 1rem 0.7rem 2.75rem; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface); outline: none; font-size: 1rem; }
.buscador input:focus { border-color: var(--accent-text); }
.filtros { display: flex; gap: 0.5rem; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; }
.filtros::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; min-height: 40px; padding: 0.45rem 1rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: 0.9rem; color: var(--muted); }
.chip.activo { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip-select { flex: 0 0 auto; min-height: 40px; padding: 0.45rem 0.9rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 0.9rem; color: var(--muted); max-width: 70vw; }
.totales { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.totales:empty { display: none; }
.total { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 0.7rem 0.9rem; font-size: 0.8125rem; }
.total strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* ---------- Segmentos ---------- */
.segmento { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface-2); border-radius: var(--r-md); padding: 4px; }
.seg { min-height: 42px; border-radius: 10px; font-weight: 600; font-size: 0.95rem; color: var(--muted); }
.seg.activo { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.seg.activo.es-ingreso { color: var(--ingreso); }

/* ---------- Botón Anotar + pestañas ---------- */
.anotar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 20;
  min-height: 54px; padding: 0 1.5rem 0 1.2rem; border-radius: 999px; background: var(--accent); color: var(--on-accent);
  font-size: 1.05rem; font-weight: 650; box-shadow: 0 8px 24px rgba(91, 54, 184, 0.35); display: inline-flex; align-items: center; gap: 0.5rem;
}
.anotar .ico { width: 22px; height: 22px; }
.anotar:active { transform: translateX(-50%) scale(0.97); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.tab .ico { width: 22px; height: 22px; }
.tab.activo { color: var(--accent-text); }

/* ---------- Hoja ---------- */
.velo { position: fixed; inset: 0; z-index: 40; background: rgba(10, 10, 12, 0.45); }
.hoja {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: var(--shadow-lg);
  animation: subir 0.22s ease-out;
}
@keyframes subir { from { transform: translateY(48px); } to { transform: none; } }
@media (min-width: 640px) { .hoja { left: 50%; right: auto; width: 560px; transform: translateX(-50%); animation: none; } }
.hoja-cab { display: flex; align-items: center; justify-content: space-between; padding: 14px 8px 6px 16px; }
.hoja-cab h2 { font-size: 1.15rem; font-weight: 700; }
.hoja-cuerpo { flex: 1; overflow-y: auto; padding: 4px 16px 16px; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
.hoja-pie { display: flex; gap: 10px; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.hoja-pie:empty { display: none; }
.hoja-pie .btn { flex: 1; }

/* Las tres formas de anotar */
.formas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding-top: 4px; }
.forma { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.6rem; min-height: 112px; padding: 1rem 0.5rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.forma:active { background: var(--surface-2); }
.forma-icono { width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center; }
.forma-icono .ico { width: 22px; height: 22px; }
.forma-titulo { font-weight: 600; font-size: 0.95rem; }
.a-mano { align-self: center; }

/* Grabando */
.grabando { display: flex; flex-direction: column; align-items: center; gap: 0.9rem; padding: 1.5rem 0 0.5rem; text-align: center; }
.punto { width: 104px; height: 104px; border-radius: 50%; background: var(--danger); color: #fff; display: flex; align-items: center; justify-content: center; animation: latido 1.2s ease-in-out infinite; }
.punto .ico { width: 40px; height: 40px; }
@keyframes latido { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.06); opacity: 0.85; } }
.reloj { font-size: 1.75rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* Pensando */
.pensando { display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 2.5rem 0; text-align: center; }
.rueda { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--accent-text); animation: girar 0.8s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .punto, .rueda, .hoja { animation: none; } }

/* Tarjeta de confirmación */
.aviso { display: flex; gap: 0.6rem; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 0.75rem 0.9rem; font-size: 0.9rem; }
.aviso .ico { width: 18px; height: 18px; margin-top: 1px; color: var(--muted); }
.miniatura { max-width: 100%; max-height: 180px; border-radius: var(--r-md); object-fit: contain; align-self: center; background: var(--surface-2); }
.prop { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1rem; display: flex; flex-direction: column; gap: 14px; }
.prop.revisar { border-color: var(--danger); }
.prop-cab { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.prop-cab .segmento { flex: 1; }
.revisar-txt { display: flex; align-items: center; gap: 0.4rem; font-size: 0.875rem; font-weight: 600; color: var(--danger); }
.revisar-txt .ico { width: 18px; height: 18px; }
.monto-campo input { font-size: 1.85rem; font-weight: 700; letter-spacing: -0.02em; min-height: 62px; font-variant-numeric: tabular-nums; }
.prop .campo input, .prop .campo select { background: var(--bg); }
.cats { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.cat { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 0.4rem; min-height: 42px; padding: 0.4rem 0.85rem 0.4rem 0.7rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-weight: 550; font-size: 0.9rem; white-space: nowrap; }
.cat .ico { width: 17px; height: 17px; }
.cat.activo { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.dos-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dos-col .campo { min-width: 0; }
@media (max-width: 419px) { .dos-col.apilar { grid-template-columns: 1fr; } }
.transcripcion { display: flex; gap: 0.5rem; align-items: flex-start; font-size: 0.9rem; color: var(--muted); }
.transcripcion .ico { width: 16px; height: 16px; margin-top: 2px; }
.adjunto { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.adjunto .btn-texto { margin-left: -0.75rem; }

/* Selector de íconos de categoría */
.iconos { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 8px; }
.icono-op { height: 48px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; color: var(--text); }
.icono-op.activo { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(146px + env(safe-area-inset-bottom)); z-index: 60; display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.8rem 1rem; border-radius: var(--r-md); background: var(--text); color: var(--bg); font-weight: 600; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; }
.toast.ver { opacity: 1; pointer-events: auto; transform: none; }
.toast button { color: var(--bg); text-decoration: underline; font-weight: 700; min-height: 40px; padding: 0 0.25rem; }
@media (min-width: 640px) { .toast { left: 50%; right: auto; width: 420px; transform: translateX(-50%); } .toast.ver { transform: translateX(-50%); } }
