:root {
  --jade: #03A2A0;
  --oscuro: #2F5D50;
  --fondo: #F3F7F6;
  --tarjeta: #FFFFFF;
  --texto: #17302A;
  --suave: #5D736D;
  --borde: #D6E2DF;
  --error: #C0392B;
  --error-fondo: #FDECEA;
  --radio: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fondo: #0F1A17;
    --tarjeta: #172622;
    --texto: #E6F2EF;
    --suave: #9DB5AE;
    --borde: #2A3D38;
    --error: #FF8A7A;
    --error-fondo: #3A1F1B;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }

/* Pantallas de acceso */
.acceso {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.acceso-cabecera {
  background: linear-gradient(135deg, var(--jade), var(--oscuro));
  color: #fff;
  padding: 40px 24px 64px;
  text-align: center;
}
.marca { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.logo-acceso {
  margin: 0 auto; width: 168px; padding: 14px 16px 10px;
  background: #fff; border-radius: 22px; box-shadow: 0 8px 24px rgba(10, 40, 34, .25);
}
.logo-acceso img { display: block; width: 100%; height: auto; }
.barra-marca { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo-barra {
  flex: none; width: 46px; height: 46px; border-radius: 12px; background: #fff;
  display: grid; place-items: center; padding: 4px;
}
.logo-barra img { display: block; width: 100%; height: auto; }
.marca span { font-weight: 400; opacity: .9; }
.lema { margin: 6px 0 0; opacity: .85; }
.acceso-cuerpo {
  flex: 1;
  margin: -40px 16px 24px;
  display: flex;
  justify-content: center;
}
.tarjeta {
  background: var(--tarjeta);
  border-radius: var(--radio);
  box-shadow: 0 8px 30px rgba(15, 50, 42, .12);
  padding: 24px 20px;
  width: 100%;
  max-width: 420px;
}
.tarjeta h2 { margin: 0 0 18px; font-size: 1.3rem; }
.campo { display: block; margin-bottom: 14px; }
.campo span { display: block; font-size: .9rem; color: var(--suave); margin-bottom: 6px; }
.campo input {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid var(--borde);
  border-radius: 10px;
  background: transparent;
  color: var(--texto);
  font-size: 1rem;
}
.campo input:focus { outline: none; border-color: var(--jade); box-shadow: 0 0 0 3px rgba(3, 162, 160, .18); }
.clave { position: relative; }
.clave input { padding-right: 70px; }
.clave button {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--jade); font-weight: 600; padding: 8px; cursor: pointer;
}
.boton {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 14px;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  background: linear-gradient(135deg, var(--jade), var(--oscuro));
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}
.boton:disabled { opacity: .6; cursor: wait; }
.boton.secundario { background: transparent; color: var(--jade); border: 1.5px solid var(--jade); }
.boton.peligro { background: transparent; color: var(--error); border: 1.5px solid var(--error); }
.boton .icono { width: 20px; height: 20px; }
.error {
  background: var(--error-fondo);
  color: var(--error);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: .92rem;
}
.cambiar { text-align: center; margin: 18px 0 0; color: var(--suave); font-size: .95rem; }
.cambiar a { color: var(--jade); font-weight: 600; text-decoration: none; }

/* ---------- App ---------- */
.icono { display: inline-flex; width: 22px; height: 22px; flex: none; }
.icono svg { width: 100%; height: 100%; }
.icono.redondo {
  width: 40px; height: 40px; padding: 9px; border-radius: 50%;
  background: rgba(3, 162, 160, .12); color: var(--jade);
}
.icono.grande { width: 56px; height: 56px; color: var(--jade); }

.marco { min-height: 100dvh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.barra {
  background: linear-gradient(135deg, var(--jade), var(--oscuro));
  color: #fff;
  padding: 14px 16px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.marca.chica { font-size: .85rem; font-weight: 700; opacity: .85; margin: 0; }
.titulo { margin: 2px 0 0; font-size: 1.35rem; }
.boton.secundario.claro { color: #fff; border-color: rgba(255, 255, 255, .7); width: auto; padding: 8px 14px; }
.contenido { padding: 16px; max-width: 720px; margin: 0 auto; }
.saludo { font-size: 1.15rem; font-weight: 700; margin: 4px 0 12px; }
.nota { color: var(--suave); margin: 12px 0; }
.nota.centro { text-align: center; padding: 32px 0; }
.ayuda { color: var(--suave); font-size: .88rem; margin: -6px 0 14px; }
.cargando { min-height: 100dvh; display: grid; place-items: center; color: var(--suave); }

/* Menú inferior */
.menu {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--tarjeta);
  border-top: 1px solid var(--borde);
  padding-bottom: env(safe-area-inset-bottom);
}
.menu a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 2px 8px; color: var(--suave); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.menu a.activo { color: var(--jade); }

/* Resumen */
.destacado {
  background: var(--tarjeta); border-radius: var(--radio); padding: 18px;
  box-shadow: 0 2px 10px rgba(15, 50, 42, .06); border-left: 5px solid var(--jade);
}
.destacado-etiqueta { margin: 0; color: var(--suave); font-size: .9rem; }
.destacado-monto { margin: 4px 0; font-size: 2.1rem; font-weight: 800; letter-spacing: -.02em; }
.destacado-detalle { margin: 0; color: var(--suave); font-size: .88rem; }
.mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.mini {
  background: var(--tarjeta); border-radius: var(--radio); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.mini span { color: var(--suave); font-size: .82rem; }
.mini strong { font-size: 1.15rem; }
.acciones { display: flex; gap: 10px; margin: 14px 0; }
.acciones .boton { flex: 1; width: auto; padding: 12px 10px; }

/* Listas */
.grupo { margin: 18px 0; }
.grupo-cabecera { display: flex; justify-content: space-between; align-items: baseline; margin: 0 4px 8px; }
.grupo-cabecera h2 { font-size: .95rem; margin: 0; color: var(--suave); font-weight: 700; }
.grupo-cabecera span { font-weight: 700; }
details.grupo summary { cursor: pointer; color: var(--suave); font-weight: 700; margin: 0 4px 8px; }
.lista { background: var(--tarjeta); border-radius: var(--radio); overflow: hidden; }
.fila {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; border: 0; background: none; color: inherit; text-align: left; cursor: pointer;
}
.fila + .fila { border-top: 1px solid var(--borde); }
.fila.estatica { cursor: default; }
.fila-nombre { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.fila-nombre small { display: block; color: var(--suave); font-weight: 400; font-size: .8rem; margin-top: 2px; }
.fila-monto { font-weight: 700; white-space: nowrap; }
.negativo { color: var(--error); }
.enlace { border: 0; background: none; color: var(--jade); font-weight: 600; cursor: pointer; padding: 6px; }
.enlace.peligro { color: var(--error); }

.vacio { text-align: center; padding: 48px 16px; color: var(--suave); }

/* Botón flotante */
.fab {
  position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 11;
  width: 56px; height: 56px; border-radius: 50%; border: 0; color: #fff; cursor: pointer;
  background: linear-gradient(135deg, var(--jade), var(--oscuro));
  box-shadow: 0 6px 18px rgba(15, 50, 42, .3);
  display: grid; place-items: center;
}
.fab .icono { width: 26px; height: 26px; }

/* Hoja inferior */
.sin-scroll { overflow: hidden; }
.hoja-fondo {
  position: fixed; inset: 0; z-index: 20; background: rgba(10, 25, 21, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.hoja {
  background: var(--tarjeta); width: 100%; max-width: 520px; max-height: 92dvh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  animation: subir .18s ease-out;
}
@keyframes subir { from { transform: translateY(30px); } }
@media (min-width: 600px) {
  .hoja-fondo { align-items: center; }
  .hoja { border-radius: 18px; }
}
.hoja-cabecera {
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: -16px; z-index: 1; background: var(--tarjeta);
  margin: -16px -16px 12px; padding: 16px 16px 8px;
}
.hoja-cabecera h2 { margin: 0; font-size: 1.2rem; }
.hoja-cerrar { border: 0; background: none; color: var(--suave); font-size: 1.2rem; padding: 6px 8px; cursor: pointer; }
.campo select {
  width: 100%; padding: 13px 12px; border: 1.5px solid var(--borde); border-radius: 10px;
  background: var(--tarjeta); color: var(--texto); font-size: 1rem;
}
.campo select:focus { outline: none; border-color: var(--jade); box-shadow: 0 0 0 3px rgba(3, 162, 160, .18); }
.pie-hoja { display: flex; gap: 10px; margin-top: 12px; }
.pie-hoja .boton { flex: 1; }

/* Aviso flotante */
.aviso {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(92px + env(safe-area-inset-bottom));
  background: var(--oscuro); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: .92rem; box-shadow: 0 6px 18px rgba(0, 0, 0, .2); max-width: calc(100% - 32px);
}

/* ---------- Movimientos ---------- */
:root { --verde: #0E8A5F; --rojo: #C0392B; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --verde: #4FD1A1; --rojo: #FF8A7A; }
}
.positivo { color: var(--verde); }
.negativo { color: var(--rojo); }
.suave { color: var(--suave); font-weight: 600; font-size: .9rem; }
.icono.redondo.verde { color: var(--verde); background: color-mix(in srgb, var(--verde) 14%, transparent); }
.icono.redondo.rojo { color: var(--rojo); background: color-mix(in srgb, var(--rojo) 14%, transparent); }
.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.trio .mini { padding: 10px 12px; min-width: 0; }
.trio .mini strong { font-size: 1rem; overflow-wrap: anywhere; }

.selector-mes {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--tarjeta); border-radius: var(--radio); padding: 4px; margin-bottom: 10px;
}
.selector-mes strong { font-size: 1.05rem; }
.flecha {
  width: 44px; height: 44px; border: 0; border-radius: 10px; background: none;
  color: var(--jade); font-size: 1.8rem; line-height: 1; cursor: pointer;
}
.flecha:disabled { color: var(--borde); cursor: default; }

.chips { display: flex; gap: 8px; margin: 14px 0 4px; }
.chip {
  border: 1.5px solid var(--borde); background: var(--tarjeta); color: var(--suave);
  border-radius: 999px; padding: 7px 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.activo { border-color: var(--jade); color: #fff; background: var(--jade); }

.segmento {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 14px;
  background: var(--fondo); border-radius: 12px;
}
.segmento button {
  border: 0; border-radius: 9px; padding: 10px; font-weight: 700; cursor: pointer;
  background: none; color: var(--suave);
}
.segmento .seg-egreso.activo { background: var(--rojo); color: #fff; }
.segmento .seg-ingreso.activo { background: var(--verde); color: #fff; }
.campo select:disabled { opacity: .6; }

.lista.barras { padding: 6px 14px; }
.barra-cat { padding: 8px 0; }
.barra-cat-texto { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-size: .92rem; }
.barra-cat-fondo { height: 8px; border-radius: 999px; background: var(--fondo); overflow: hidden; }
.barra-cat-relleno { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--jade), var(--oscuro)); }
.vacio .boton { width: auto; padding: 12px 28px; margin-top: 8px; }

/* ---------- Presupuesto ---------- */
:root { --ambar: #C98A06; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --ambar: #F2C14E; }
}
.progreso { height: 10px; border-radius: 999px; background: var(--fondo); overflow: hidden; margin: 10px 0 6px; }
.progreso > div { height: 100%; border-radius: 999px; background: var(--jade); transition: width .3s; }
.progreso.cerca > div { background: var(--ambar); }
.progreso.excedido > div { background: var(--rojo); }
.fila-resumen { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.fila-resumen .derecha { text-align: right; }
.monto-medio { margin: 4px 0 6px; font-weight: 700; }
.presupuesto-resumen .destacado-monto { margin-bottom: 0; }
.partida {
  display: block; width: 100%; text-align: left; border: 0; background: none; color: inherit;
  padding: 12px 14px; cursor: pointer;
}
.partida + .partida { border-top: 1px solid var(--borde); }
.partida-fila { display: flex; align-items: baseline; gap: 10px; }
.partida-montos { white-space: nowrap; color: var(--suave); font-size: .92rem; }
.partida-montos strong { color: var(--texto); font-size: 1rem; }
.partida .progreso { height: 8px; margin: 8px 0 4px; }
.partida-estado { font-size: .82rem; font-weight: 600; color: var(--suave); }
.partida-estado.cerca { color: var(--ambar); }
.partida-estado.excedido { color: var(--rojo); }
.pila { display: flex; flex-direction: column; gap: 10px; max-width: 320px; margin: 12px auto 0; }
.pila .boton { width: 100%; }
.centro { text-align: center; }
