/* ==========================================================================
   Liquid Glass — hoja base (estilo iOS 26)
   Extraída del sistema en producción de la app Gastos.
   Cópiala al proyecto y ajusta solo lo que necesite esta app.
   Orden: tokens · reset · fondo · cristal · tipografía · componentes ·
          animaciones · hover · accesibilidad · modo oscuro
   ========================================================================== */

:root {
  /* Tinta y acentos */
  --tinta: #1c1c2e;
  --tinta-suave: rgba(28, 28, 46, 0.68);   /* ≥4.5:1 sobre el cristal (WCAG AA) */
  --acento: #5b6cff;
  --acento-2: #8a5cf6;
  --peligro: #ff3b30;
  --exito: #34c759;

  /* Cristal */
  --vidrio-fondo: rgba(255, 255, 255, 0.55);
  --vidrio-borde: rgba(255, 255, 255, 0.65);
  --vidrio-filo: rgba(255, 255, 255, 0.7);  /* filo interior de luz */
  --vidrio-sheen: rgba(255, 255, 255, 0.35);

  /* Geometría */
  --radio-tarjeta: 22px;
  --radio-boton: 16px;
  --radio-campo: 14px;
  --radio-hoja: 26px;

  /* Sombra de color (nunca gris) */
  --sombra-suave: 0 12px 28px -14px rgba(91, 108, 255, 0.35);

  /* Curvas del sistema */
  --muelle: cubic-bezier(0.34, 1.56, 0.64, 1);   /* rebote sutil */
  --salida: cubic-bezier(0.16, 1, 0.3, 1);       /* deceleración elegante */
  --hoja:   cubic-bezier(0.32, 0.72, 0, 1);      /* sheet estilo iOS */
  --direccion: cubic-bezier(0.23, 1, 0.32, 1);   /* cambio de vista */

  --barra-tabs-alto: 76px;

  /* Fuente del sistema. En Windows antepón:
     "Segoe UI Variable Display", "Segoe UI Variable Text", "Segoe UI" */
  --fuente: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
            "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
}

/* ---------- Reset mínimo ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--fuente);
  color: var(--tinta);
  background: #eef2ff;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;      /* sin zoom por doble toque */
  -webkit-user-select: none;
  user-select: none;
}
input, textarea, select, code, .seleccionable { -webkit-user-select: text; user-select: text; }

/* ---------- Fondo: gradiente + orbes (nunca color plano) ---------- */
.fondo {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: linear-gradient(160deg, #eef2ff 0%, #fdeef7 45%, #e8f7ff 100%);
}
.orbe { position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.55; }
.orbe-1 { width: 340px; height: 340px; top: -90px;    left: -80px;   background: #a5b4ff; }
.orbe-2 { width: 300px; height: 300px; top: 35%;      right: -120px; background: #f3b0e0; }
.orbe-3 { width: 360px; height: 360px; bottom: -120px; left: 10%;    background: #a0e6ff; }

/* ---------- Superficies de cristal ---------- */
.vidrio {
  position: relative;
  background: var(--vidrio-fondo);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--vidrio-borde);
  border-radius: var(--radio-tarjeta);
  box-shadow: var(--sombra-suave), inset 0 1px 0 var(--vidrio-filo);
}
.vidrio::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(135deg, var(--vidrio-sheen) 0%, transparent 45%);
}
/* Barras fijas: más blur y más cuerpo, porque debajo pasa contenido en movimiento */
.vidrio-barra {
  background: rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.55);
}

/* ---------- Tipografía ---------- */
.titulo-hero    { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.titulo-vista   { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.titulo-hoja    { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.seccion-titulo { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; margin: 22px 4px 10px; }
.texto-secundario { font-size: 15px; color: var(--tinta-suave); }
.texto-ayuda      { font-size: 13px; color: var(--tinta-suave); }
.cifra-grande   { font-size: 52px; font-weight: 700; letter-spacing: -0.02em; }
.texto-vacio    { text-align: center; color: var(--tinta-suave); font-size: 15px; padding: 24px 12px; }

/* ---------- Tarjeta ---------- */
.tarjeta { padding: 20px; margin-bottom: 18px; }   /* combínala con .vidrio */
.tarjeta.compacta { padding: 14px 20px; }

/* ---------- Botones ---------- */
.boton-primario, .boton-secundario, .boton-peligro {
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  width: 100%;
  min-height: 50px;
  border: none;
  border-radius: var(--radio-boton);
  cursor: pointer;
  transition: transform 0.3s var(--muelle), filter 0.3s, background 0.3s;
}
.boton-primario {
  color: #fff;
  background: linear-gradient(135deg, var(--acento), var(--acento-2));
  box-shadow: 0 10px 22px -10px rgba(91, 108, 255, 0.6);
}
.boton-secundario { color: var(--acento);  background: rgba(91, 108, 255, 0.12); }
.boton-peligro    { color: var(--peligro); background: rgba(255, 59, 48, 0.1); }
.boton-primario:active, .boton-secundario:active, .boton-peligro:active { transform: scale(0.97); }

.boton-circulo {
  font: inherit;
  font-size: 24px;
  font-weight: 600;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.6);
  color: var(--acento);
  cursor: pointer;
  transition: transform 0.3s var(--muelle), background 0.3s;
}
.boton-circulo:active { transform: scale(0.92); }

/* Acción textual pequeña junto a un título (estilo iOS) */
.boton-titulo {
  font: inherit; font-size: 14px; font-weight: 600;
  color: var(--acento); background: none; border: 0;
  padding: 4px 8px; cursor: pointer;
}

/* ---------- Campos ---------- */
.campo { display: grid; gap: 6px; margin-bottom: 14px; min-width: 0; }
.campo > span, .campo-etiqueta {
  font-size: 13px; font-weight: 600;
  color: var(--tinta-suave);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.campo input, .campo select, .campo textarea {
  font: inherit;
  font-size: 17px;                 /* <16px provoca zoom automático en iOS */
  color: var(--tinta);
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: var(--radio-campo);
  padding: 13px 14px;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: box-shadow 0.38s var(--salida), border-color 0.38s;
}
.campo input:focus, .campo select:focus, .campo textarea:focus {
  border-color: rgba(91, 108, 255, 0.5);
  box-shadow: 0 0 0 4px rgba(91, 108, 255, 0.15);
}
/* Autocompletado sin el amarillo del navegador */
.campo input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px #f6f7ff inset;
  -webkit-text-fill-color: var(--tinta);
  caret-color: var(--tinta);
}
.fila-doble { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.error-texto { color: var(--peligro); font-size: 14px; margin-bottom: 10px; }

/* ---------- Chips / píldoras ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 6px;
  font: inherit; font-size: 15px; font-weight: 600;
  padding: 10px 14px;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.55);
  color: var(--tinta);
  cursor: pointer;
  transition: transform 0.3s var(--muelle), background 0.3s, color 0.3s, box-shadow 0.3s;
}
.chip:active { transform: scale(0.94); }
.chip.activo {
  background: var(--chip-color, var(--acento));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px -8px var(--chip-color, var(--acento));
}

/* ---------- Conmutador ---------- */
.conmutador { position: relative; flex: 0 0 auto; }
.conmutador input { position: absolute; opacity: 0; width: 100%; height: 100%; z-index: 1; margin: 0; }
.conmutador-pista {
  display: block;
  width: 52px; height: 32px;
  border-radius: 999px;
  background: rgba(28, 28, 46, 0.15);
  transition: background 0.38s;
  position: relative;
}
.conmutador-pista::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.38s var(--muelle);
}
.conmutador input:checked + .conmutador-pista { background: var(--exito); }
.conmutador input:checked + .conmutador-pista::after { transform: translateX(20px); }
.fila-conmutador {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 44px; padding: 4px 2px; margin-bottom: 16px;
}
.fila-conmutador > span:first-child { display: grid; gap: 2px; }
.fila-conmutador strong { font-size: 16px; font-weight: 600; }
.fila-conmutador small  { font-size: 13px; color: var(--tinta-suave); }

/* ---------- Cabecera y contenido ---------- */
.cabecera {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 20px 12px;
  border-radius: 0 0 24px 24px;
  border-top: none;
}
.cabecera h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }

#contenido {
  padding: calc(env(safe-area-inset-top) + 78px) 16px
           calc(var(--barra-tabs-alto) + env(safe-area-inset-bottom) + 20px);
  max-width: 560px;
  margin: 0 auto;
}

/* ---------- Barra de pestañas (móvil: flotante abajo) ---------- */
.barra-tabs {
  position: fixed; left: 16px; right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  z-index: 30;
  display: flex;
  border-radius: var(--radio-hoja);
  padding: 8px;
  box-shadow: 0 16px 36px -16px rgba(28, 28, 46, 0.35);
}
.tab-boton {
  flex: 1; min-width: 0;
  display: grid; justify-items: center; gap: 3px;
  font: inherit; font-size: 11px; font-weight: 600;
  color: var(--tinta-suave);
  background: transparent; border: none;
  border-radius: 18px;
  padding: 8px 4px;
  min-height: 56px;
  cursor: pointer;
  transition: color 0.38s, background 0.38s, transform 0.3s var(--muelle);
}
.tab-boton svg { width: 26px; height: 26px; }
.tab-boton:active { transform: scale(0.93); }
.tab-boton.activo { color: var(--acento); background: rgba(91, 108, 255, 0.12); }
.tab-boton.activo svg { animation: pop-icono 0.45s var(--muelle); }

/* ---------- Hoja modal / diálogo ---------- */
.hoja-fondo {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(28, 28, 46, 0.3);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fundido 0.38s var(--salida);
}
.hoja {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-height: 86dvh;
  overflow-y: auto;
  border-radius: var(--radio-hoja) var(--radio-hoja) 0 0;
  padding: 10px 22px calc(env(safe-area-inset-bottom) + 24px);
  max-width: 560px; margin: 0 auto;
  animation: subir 0.75s var(--hoja);
}
.hoja-asa { width: 40px; height: 5px; border-radius: 999px; background: rgba(28, 28, 46, 0.2); margin: 6px auto 14px; }
.hoja h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 16px; }

/* ---------- Escritorio: mismo sistema, otro chasis ---------- */
@media (min-width: 700px) and (min-height: 600px) {
  .cabecera { align-items: center; min-height: 64px; padding: 12px 28px; border-radius: 0; }
  .cabecera h1 { font-size: 22px; }

  /* Las pestañas suben al centro de la cabecera, horizontales */
  .barra-tabs {
    top: 8px; bottom: auto; left: 50%; right: auto;
    transform: translateX(-50%);
    width: auto;
    padding: 5px;
    border-radius: var(--radio-boton);
    box-shadow: 0 10px 24px -14px rgba(28, 28, 46, 0.35);
  }
  .tab-boton {
    display: flex; align-items: center; gap: 8px;
    font-size: 15px; padding: 8px 16px; min-height: 44px;
    border-radius: 12px;
  }
  .tab-boton svg { width: 20px; height: 20px; }

  #contenido { padding: 92px 24px 32px; }
  .toast { bottom: 28px; }

  /* Pantallas anchas: contenido a dos columnas */
  @media (min-width: 1020px) { #contenido { max-width: 1060px; } }
}

/* La hoja pasa a diálogo centrado con el mismo material */
@media (min-width: 700px) and (min-height: 600px) {
  .hoja {
    left: 50%; top: 50%; bottom: auto; right: auto;
    translate: -50% -50%;
    width: min(92vw, 560px);
    border-radius: var(--radio-hoja);
    padding-bottom: 24px;
    animation: dialogo-entrada 0.45s var(--direccion);
  }
  .hoja-asa { display: none; }
}

.dialogo {
  position: fixed; left: 50%; top: 50%; translate: -50% -50%; z-index: 60;
  width: min(86vw, 320px);
  padding: 26px 22px 18px;
  text-align: center;
  animation: dialogo-entrada 0.38s var(--direccion);
}
.dialogo-icono {
  width: 56px; height: 56px; margin: 0 auto 10px;
  display: grid; place-items: center;
  font-size: 26px; border-radius: 50%;
  background: rgba(255, 59, 48, 0.12);
}
.dialogo h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 6px; }
.dialogo p { font-size: 15px; color: var(--tinta-suave); line-height: 1.4; margin-bottom: 18px; }
.dialogo-botones { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialogo-botones > * { margin: 0; min-height: 46px; }

/* Los modales necesitan más cuerpo que una tarjeta: sobre una pantalla con
   contenido, el cristal al 55 % deja leer el texto de detrás a través del
   diálogo. Se sube la opacidad y el blur, y se mantiene el material. */
.hoja, .dialogo {
  background: rgba(255, 255, 255, 0.88);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  backdrop-filter: blur(30px) saturate(180%);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(var(--barra-tabs-alto) + env(safe-area-inset-bottom) + 24px);
  left: 50%; transform: translateX(-50%); z-index: 70;
  font-size: 15px; font-weight: 600; color: #fff;
  background: rgba(28, 28, 46, 0.88);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  padding: 12px 20px;
  border-radius: 999px;
  max-width: 86vw; text-align: center;
  animation: subirToast 0.53s var(--muelle);
}

/* ---------- Animaciones ---------- */
@keyframes fundido   { from { opacity: 0; } to { opacity: 1; } }
@keyframes aparecer  { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes subir     { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes subirToast { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes dialogo-entrada { from { opacity: 0; scale: 0.92; } to { opacity: 1; scale: 1; } }
@keyframes pop-icono { 0% { scale: 1; } 50% { scale: 1.18; } 100% { scale: 1; } }

/* Cambio de vista con dirección (clases puestas por JS).
   `translate` en vez de `transform` para no pisar otros transforms. */
@keyframes entrar-derecha   { from { opacity: 0; translate: 32px 0; }  to { opacity: 1; translate: 0 0; } }
@keyframes entrar-izquierda { from { opacity: 0; translate: -32px 0; } to { opacity: 1; translate: 0 0; } }
.entra-derecha   { animation: entrar-derecha 0.45s var(--direccion); }
.entra-izquierda { animation: entrar-izquierda 0.45s var(--direccion); }

/* Entrada orquestada al abrir la app (clase .app-entrada en el contenedor raíz) */
@keyframes bajar-cabecera    { from { opacity: 0; translate: 0 -110%; } to { opacity: 1; translate: 0 0; } }
@keyframes entrada-contenido { from { opacity: 0; translate: 0 22px; }  to { opacity: 1; translate: 0 0; } }
@keyframes subir-barra       { from { opacity: 0; translate: 0 130%; }  to { opacity: 1; translate: 0 0; } }
.app-entrada .cabecera   { animation: bajar-cabecera 0.68s var(--salida) backwards; }
.app-entrada #contenido  { animation: entrada-contenido 0.68s var(--salida) 0.09s backwards; }
.app-entrada .barra-tabs { animation: subir-barra 0.75s var(--salida) 0.18s backwards; }

/* ---------- Ratón: hover (no afecta al táctil) ---------- */
@media (hover: hover) and (pointer: fine) {
  .boton-primario:hover   { filter: brightness(1.07); }
  .boton-secundario:hover { background: rgba(91, 108, 255, 0.2); }
  .boton-peligro:hover    { background: rgba(255, 59, 48, 0.18); }
  .boton-circulo:hover    { background: rgba(255, 255, 255, 0.95); }
  .chip:not(.activo):hover { background: rgba(255, 255, 255, 0.9); }
  .tab-boton:not(.activo):hover { color: var(--acento); background: rgba(91, 108, 255, 0.1); }

  /* Scrollbars finas y discretas */
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: rgba(28, 28, 46, 0.18); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
  ::-webkit-scrollbar-thumb:hover { background: rgba(28, 28, 46, 0.3); background-clip: content-box; }
}

/* ---------- Accesibilidad ---------- */
:focus-visible {
  outline: none;
  border-color: rgba(91, 108, 255, 0.5);
  box-shadow: 0 0 0 4px rgba(91, 108, 255, 0.15);
}

/* Se sustituye el movimiento por un fundido breve en vez de eliminarlo:
   quitar la animación dejaría invisible lo que arranca en opacity 0. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; }
  .entra-derecha, .entra-izquierda, .hoja, .dialogo, .toast,
  .app-entrada .cabecera, .app-entrada #contenido, .app-entrada .barra-tabs {
    animation: fundido 0.15s ease-out !important;
  }
  .tab-boton.activo svg { animation: none !important; }
}

/* ---------- Modo oscuro ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="claro"]) {
    --tinta: #f2f3ff;
    --tinta-suave: rgba(242, 243, 255, 0.7);
    --vidrio-fondo: rgba(28, 28, 46, 0.5);
    --vidrio-borde: rgba(255, 255, 255, 0.14);
    --vidrio-filo: rgba(255, 255, 255, 0.12);
    --vidrio-sheen: rgba(255, 255, 255, 0.08);
    --sombra-suave: 0 12px 28px -14px rgba(0, 0, 0, 0.55);
  }
  :root:not([data-tema="claro"]) body { background: #101226; }
  :root:not([data-tema="claro"]) .fondo { background: linear-gradient(160deg, #101226 0%, #1b1030 45%, #0d1b2e 100%); }
  :root:not([data-tema="claro"]) .orbe { opacity: 0.35; }
  :root:not([data-tema="claro"]) .vidrio-barra { background: rgba(28, 28, 46, 0.6); border-color: rgba(255, 255, 255, 0.12); }
  :root:not([data-tema="claro"]) .campo input,
  :root:not([data-tema="claro"]) .campo select,
  :root:not([data-tema="claro"]) .campo textarea { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.14); color: var(--tinta); }
  :root:not([data-tema="claro"]) .chip:not(.activo) { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.14); color: var(--tinta); }
  :root:not([data-tema="claro"]) .conmutador-pista { background: rgba(255, 255, 255, 0.18); }
  :root:not([data-tema="claro"]) .boton-circulo { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.16); }
}
/* Mismo bloque forzado por el selector de tema de la app */
:root[data-tema="oscuro"] {
  --tinta: #f2f3ff;
  --tinta-suave: rgba(242, 243, 255, 0.7);
  --vidrio-fondo: rgba(28, 28, 46, 0.5);
  --vidrio-borde: rgba(255, 255, 255, 0.14);
  --vidrio-filo: rgba(255, 255, 255, 0.12);
  --vidrio-sheen: rgba(255, 255, 255, 0.08);
  --sombra-suave: 0 12px 28px -14px rgba(0, 0, 0, 0.55);
}
:root[data-tema="oscuro"] body { background: #101226; }
:root[data-tema="oscuro"] .fondo { background: linear-gradient(160deg, #101226 0%, #1b1030 45%, #0d1b2e 100%); }
:root[data-tema="oscuro"] .orbe { opacity: 0.35; }
:root[data-tema="oscuro"] .vidrio-barra { background: rgba(28, 28, 46, 0.6); border-color: rgba(255, 255, 255, 0.12); }
:root[data-tema="oscuro"] .campo input,
:root[data-tema="oscuro"] .campo select,
:root[data-tema="oscuro"] .campo textarea { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.14); color: var(--tinta); }
:root[data-tema="oscuro"] .chip:not(.activo) { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.14); color: var(--tinta); }
:root[data-tema="oscuro"] .conmutador-pista { background: rgba(255, 255, 255, 0.18); }
:root[data-tema="oscuro"] .boton-circulo { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.16); }
