/* ===== Tokens (colores del sistema iOS, claro y oscuro) ===== */
:root {
  --fondo: #F2F2F7;
  --tarjeta: #FFFFFF;
  --tarjeta-2: #F2F2F7;
  --texto: #000000;
  --texto-2: rgba(60, 60, 67, .64);
  --texto-3: rgba(60, 60, 67, .36);
  --separador: rgba(60, 60, 67, .16);
  --verde: #248A3D;          /* verde accesible sobre blanco */
  --verde-vivo: #34C759;
  --rojo: #D70015;
  --rojo-vivo: #FF3B30;
  --azul: #007AFF;
  --gris-dia: rgba(120, 120, 128, .12);
  --vidrio: rgba(255, 255, 255, .62);
  --vidrio-borde: rgba(255, 255, 255, .7);
  --sombra: 0 8px 32px rgba(0, 0, 0, .12);
  --resorte: cubic-bezier(.34, 1.56, .64, 1);
  --suave: cubic-bezier(.32, .72, 0, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fondo: #000000;
    --tarjeta: #1C1C1E;
    --tarjeta-2: #2C2C2E;
    --texto: #FFFFFF;
    --texto-2: rgba(235, 235, 245, .62);
    --texto-3: rgba(235, 235, 245, .32);
    --separador: rgba(84, 84, 88, .55);
    --verde: #30D158;
    --verde-vivo: #30D158;
    --rojo: #FF453A;
    --rojo-vivo: #FF453A;
    --azul: #0A84FF;
    --gris-dia: rgba(120, 120, 128, .2);
    --vidrio: rgba(28, 28, 30, .55);
    --vidrio-borde: rgba(255, 255, 255, .12);
    --sombra: 0 8px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fondo: #000000; --tarjeta: #1C1C1E; --tarjeta-2: #2C2C2E; --texto: #FFFFFF;
  --texto-2: rgba(235, 235, 245, .62); --texto-3: rgba(235, 235, 245, .32); --separador: rgba(84, 84, 88, .55);
  --verde: #30D158; --verde-vivo: #30D158; --rojo: #FF453A; --rojo-vivo: #FF453A; --azul: #0A84FF;
  --gris-dia: rgba(120, 120, 128, .2); --vidrio: rgba(28, 28, 30, .55); --vidrio-borde: rgba(255, 255, 255, .12);
  --sombra: 0 8px 32px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 17px/1.3 -apple-system, "SF Pro Text", "SF Pro Display", "Helvetica Neue", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--azul); outline-offset: 2px; border-radius: 10px; }

/* ===== Barra flotante con vidrio ===== */
.barra {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 4px) max(8px, env(safe-area-inset-right)) 4px max(8px, env(safe-area-inset-left));
  background: transparent;
  transition: background .25s, box-shadow .25s;
}
.barra.con-fondo {
  background: var(--vidrio);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  box-shadow: inset 0 -0.5px 0 var(--separador);
}
.barra-centro { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.barra-titulo { font-weight: 600; font-size: 17px; opacity: 0; transform: translateY(4px); transition: opacity .2s, transform .2s; }
.barra.con-fondo .barra-titulo { opacity: 1; transform: none; }
.estado { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--texto-2); }
.estado i { width: 7px; height: 7px; border-radius: 50%; background: var(--texto-3); }
.estado.vivo i { background: var(--verde-vivo); box-shadow: 0 0 0 3px color-mix(in srgb, var(--verde-vivo) 25%, transparent); }
.estado.demo i { background: #FF9F0A; }
.estado.error i { background: var(--rojo-vivo); }
.estado b { font-weight: 500; }

.icono-btn {
  width: 44px; height: 44px; border-radius: 22px;
  display: grid; place-items: center; color: var(--azul);
  transition: transform .2s var(--resorte), background .2s;
}
.icono-btn:active { transform: scale(.9); background: var(--gris-dia); }
.icono-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.icono-btn.chico svg { width: 22px; height: 22px; }
.icono-btn.gris { width: 32px; height: 32px; margin: 6px; background: var(--gris-dia); color: var(--texto-2); }
.icono-btn.gris svg { width: 14px; height: 14px; stroke-width: 3; }
.icono-btn.girando svg { animation: girar .8s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }

/* ===== Contenido ===== */
.contenido {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 56px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 32px) max(16px, env(safe-area-inset-left));
}
.titulo-grande { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }
.acciones { display: flex; gap: 2px; }
.aviso-flotante {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); z-index: 40;
  transform: translateX(-50%); max-width: min(92vw, 420px);
  padding: 12px 18px; border-radius: 18px; font-size: 15px; text-align: center;
  background: var(--vidrio); color: var(--texto);
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
  box-shadow: var(--sombra), inset 0 0.5px 0 var(--vidrio-borde);
  animation: aparecer .3s var(--suave);
}
body.soltando .contenido { outline: 3px dashed var(--azul); outline-offset: -8px; border-radius: 24px; }
.titulo-grande h1 { font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: .01em; margin: 0; text-transform: capitalize; }

.aviso-demo {
  margin: 0 0 12px; padding: 10px 14px; border-radius: 14px;
  background: color-mix(in srgb, #FF9F0A 16%, transparent); color: var(--texto);
  font-size: 13px; line-height: 1.35;
}

.etiqueta { font-size: 13px; color: var(--texto-2); font-weight: 500; }
.etiqueta.centro { text-align: center; }
.sub { font-size: 15px; color: var(--texto-2); margin: 0; }
.monto-grande { display: block; font-size: 40px; line-height: 1.1; font-weight: 700; letter-spacing: -.02em; }
.pos { color: var(--verde); }
.neg { color: var(--rojo); }
.cero { color: var(--texto-2); }

/* Hero */
.hero {
  display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center;
  background: var(--tarjeta); border-radius: 22px; padding: 18px 18px 16px;
}
.hero-total { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.hero-total .monto-grande { font-size: clamp(30px, 9vw, 40px); white-space: nowrap; }
.hero-dias { position: relative; display: grid; justify-items: center; gap: 4px; width: 92px; }
.anillo { width: 76px; height: 76px; transform: rotate(-90deg); }
.anillo circle { fill: none; stroke-width: 7; }
.anillo-fondo { stroke: color-mix(in srgb, var(--rojo-vivo) 30%, var(--gris-dia)); }
.anillo-valor { stroke: var(--verde-vivo); stroke-linecap: round; stroke-dasharray: 169.65; stroke-dashoffset: 169.65; transition: stroke-dashoffset .8s var(--suave); }
.anillo-texto { position: absolute; top: 0; height: 76px; display: grid; place-items: center; }
.anillo-texto strong { font-size: 19px; font-weight: 700; }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 12px -16px 16px; padding: 0 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; background: var(--tarjeta); border-radius: 14px; padding: 8px 12px; display: flex; flex-direction: column; gap: 1px; min-width: 96px; }
.chip span { font-size: 12px; color: var(--texto-2); }
.chip strong { font-size: 17px; font-weight: 600; }

/* ===== Calendario ===== */
.tarjeta { background: var(--tarjeta); border-radius: 22px; padding: 12px; }
.cal-semana, .cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-semana span { text-align: center; font-size: 12px; font-weight: 600; color: var(--texto-3); padding-bottom: 6px; }
.dia {
  position: relative; aspect-ratio: 1 / 1.12; min-height: 44px; border-radius: 12px;
  display: flex; flex-direction: column; justify-content: space-between; align-items: stretch;
  padding: 5px 4px 6px; background: var(--gris-dia); text-align: left;
  transition: transform .25s var(--resorte);
  animation: aparecer .4s var(--suave) both;
  animation-delay: calc(var(--i, 0) * 12ms);
}
@keyframes aparecer { from { opacity: 0; transform: scale(.92); } }
.dia:active { transform: scale(.92); }
.dia .num { font-size: 12px; font-weight: 600; color: var(--texto-2); line-height: 1; }
.dia .pl { font-size: 11px; font-weight: 700; text-align: center; letter-spacing: -.02em; white-space: nowrap; line-height: 1; }
.dia.vacio { background: none; animation: none; }
.dia.futuro { background: none; box-shadow: inset 0 0 0 1px var(--separador); }
.dia.futuro .num { color: var(--texto-3); }
.dia.gana { background: color-mix(in srgb, var(--verde-vivo) calc(16% + var(--fuerza, 0) * 30%), var(--tarjeta)); }
.dia.pierde { background: color-mix(in srgb, var(--rojo-vivo) calc(16% + var(--fuerza, 0) * 30%), var(--tarjeta)); }
.dia.gana .pl { color: var(--verde); }
.dia.pierde .pl { color: var(--rojo); }
.dia.gana .num, .dia.pierde .num { color: var(--texto); }
.dia.hoy::after { content: ""; position: absolute; inset: -2px; border-radius: 14px; box-shadow: 0 0 0 2px var(--azul); pointer-events: none; }
.leyenda { display: flex; gap: 14px; justify-content: center; margin-top: 12px; font-size: 12px; color: var(--texto-2); }
.leyenda span { display: inline-flex; align-items: center; gap: 5px; }
.leyenda i { width: 10px; height: 10px; border-radius: 3px; }
.leyenda .p { background: var(--verde-vivo); }
.leyenda .n { background: var(--rojo-vivo); }
.leyenda .s { background: var(--gris-dia); box-shadow: inset 0 0 0 1px var(--separador); }
.cal.sale-izq { animation: salir-izq .18s ease-in forwards; }
.cal.sale-der { animation: salir-der .18s ease-in forwards; }
@keyframes salir-izq { to { opacity: 0; transform: translateX(-24px); } }
@keyframes salir-der { to { opacity: 0; transform: translateX(24px); } }

/* ===== Grupos y listas (estilo Ajustes de iOS) ===== */
.grupo { margin-top: 28px; }
.grupo-titulo { font-size: 22px; font-weight: 700; margin: 0 4px 10px; }
.lista { padding: 0 0 0 16px; }
.fila { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 16px 10px 0; box-shadow: inset 0 -0.5px 0 var(--separador); }
.fila:last-child { box-shadow: none; }
.fila-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.fila-txt strong { font-weight: 500; }
.fila-txt span { font-size: 13px; color: var(--texto-2); }
.fila-valor { font-weight: 600; text-align: right; white-space: nowrap; }

/* Barras de reglas */
.regla { display: block; }
.regla-tit { display: block; font-weight: 500; }
.regla .fila-sup { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: 3px; }
.regla-sub { font-size: 13px; color: var(--texto-2); min-width: 0; }
.regla .fila-valor { font-size: 15px; }
.barra-prog { height: 6px; border-radius: 3px; background: var(--gris-dia); margin-top: 8px; overflow: hidden; }
.barra-prog i { display: block; height: 100%; border-radius: 3px; width: 0; transition: width .8s var(--suave); }
.barra-prog .ok { background: var(--verde-vivo); }
.barra-prog .alerta { background: #FF9F0A; }
.barra-prog .peligro { background: var(--rojo-vivo); }

/* Curva */
.curva-tarjeta { padding: 14px 12px 10px; }
.curva { width: 100%; height: 150px; display: block; overflow: visible; }
.curva .linea { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.curva .cero-linea { stroke: var(--separador); stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
.curva .punto { stroke: var(--tarjeta); stroke-width: 2; vector-effect: non-scaling-stroke; }

/* Estadísticas */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--tarjeta); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.stat span { font-size: 13px; color: var(--texto-2); }
.stat strong { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.stat small { font-size: 12px; color: var(--texto-3); }

.pie { text-align: center; font-size: 12px; color: var(--texto-3); margin: 28px 0 0; }

/* ===== Hoja inferior (vidrio, flota sobre el contenido) ===== */
.velo { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .32); opacity: 0; transition: opacity .3s; }
.velo.abierto { opacity: 1; }
.hoja {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-width: 560px; margin: 0 auto; max-height: 86vh; max-height: 86dvh;
  display: flex; flex-direction: column;
  border-radius: 28px 28px 0 0;
  background: var(--vidrio);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  backdrop-filter: blur(28px) saturate(180%);
  box-shadow: var(--sombra), inset 0 0.5px 0 var(--vidrio-borde);
  padding: 0 16px calc(env(safe-area-inset-bottom) + 16px);
  transform: translateY(100%);
  transition: transform .45s var(--suave);
}
.hoja.abierta { transform: translateY(0); }
.hoja[hidden], .velo[hidden] { display: none; }
.hoja-asa { display: grid; place-items: center; height: 22px; cursor: grab; touch-action: none; }
.hoja-asa span { width: 36px; height: 5px; border-radius: 3px; background: var(--texto-3); }
.hoja-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; touch-action: none; }
.hoja-cab h2 { font-size: 22px; font-weight: 700; margin: 4px 0 2px; }
.hoja-cab h2::first-letter { text-transform: uppercase; }
.hoja-monto { margin: 6px 0 12px; }
.hoja-lista { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 8px; padding-bottom: 4px; }
.op { background: var(--tarjeta); border-radius: 16px; padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.op-sim { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.op-tipo { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--gris-dia); color: var(--texto-2); text-transform: uppercase; letter-spacing: .03em; }
.op-pl { font-weight: 700; text-align: right; align-self: center; grid-row: span 2; font-size: 17px; }
.op-det { font-size: 13px; color: var(--texto-2); grid-column: 1 / 2; }
.op-det b { font-weight: 500; color: var(--texto); }
.vacio-msg { text-align: center; color: var(--texto-2); padding: 24px 0 12px; }

/* ===== Accesibilidad ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .barra.con-fondo, .hoja { background: var(--tarjeta); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  .dia { box-shadow: inset 0 0 0 1px var(--texto-3); }
  .hoja { background: var(--tarjeta); }
}
@media (max-width: 360px) {
  .dia .pl { font-size: 10px; }
  .cal, .cal-semana { gap: 4px; }
}
