/* ============================================================
   App de Gastos — estilos
   Paleta validada para modo claro y oscuro.
   ============================================================ */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;      /* tarjetas y superficie de graficos */
  --plane: #f9f9f7;          /* fondo de la pagina */
  --surface-2: #f0efec;      /* relleno suave */

  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;

  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6;
  --series-1-suave: #cde2fb;

  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  --radio: 14px;
  --sombra: 0 1px 2px rgba(11, 11, 11, 0.06), 0 4px 14px rgba(11, 11, 11, 0.05);

  --seguro-arriba: env(safe-area-inset-top, 0px);
  --seguro-abajo: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --plane: #0d0d0d;
    --surface-2: #242422;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-1-suave: #184f95;
    --good-text: #0ca30c;
    --sombra: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --plane: #0d0d0d;
  --surface-2: #242422;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-1-suave: #184f95;
  --good-text: #0ca30c;
  --sombra: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(72px + var(--seguro-abajo)); }
body.sin-nav { padding-bottom: 0; }

.oculto { display: none !important; }

/* ------------------------------------------------------------ estructura */

.encabezado {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(12px + var(--seguro-arriba)) 20px 12px;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.encabezado h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

main { padding: 16px 16px 24px; max-width: 720px; margin: 0 auto; }

.pantalla { display: none; }
.pantalla.activa { display: block; animation: aparecer 0.18s ease-out; }

@keyframes aparecer {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------ navegacion */

.nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--seguro-abajo);
}

.nav button {
  appearance: none;
  border: 0;
  background: none;
  padding: 10px 4px 12px;
  cursor: pointer;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 550;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: color 0.15s;
}

.nav button svg { width: 23px; height: 23px; stroke-width: 1.7; }
.nav button.activa { color: var(--series-1); }

/* ------------------------------------------------------------ tarjetas */

.tarjeta {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radio);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--sombra);
}

.tarjeta h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.005em;
}

.tarjeta .subtitulo {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ------------------------------------------------------------ botones */

button, .boton {
  font-family: inherit;
  font-size: 16px;
}

.btn {
  appearance: none;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 15px 18px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  background: var(--series-1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  transition: transform 0.12s, opacity 0.12s;
  min-height: 52px;
}

.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 21px; height: 21px; stroke-width: 1.9; }

.btn.secundario {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn.peligro { background: transparent; color: var(--critical); border: 1px solid var(--critical); }
.btn.pequeno { min-height: 42px; padding: 10px 14px; font-size: 14px; width: auto; }

.fila-botones { display: flex; gap: 10px; }
.fila-botones .btn { flex: 1; }

/* ------------------------------------------------------------ formularios */

label {
  display: block;
  font-size: 13px;
  font-weight: 550;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: 16px; /* 16px evita que iPhone haga zoom al enfocar */
  padding: 12px 13px;
  border: 1px solid var(--axis);
  border-radius: 10px;
  background: var(--surface-1);
  color: var(--text-primary);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--series-1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--series-1) 18%, transparent);
}

textarea { resize: vertical; min-height: 72px; }
.campo { margin-bottom: 14px; }
.campos-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ------------------------------------------------------------ numeros */

.hero {
  font-size: 42px;
  font-weight: 680;
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin: 2px 0 6px;
}

.hero-etiqueta {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.delta { font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.delta.sube { color: var(--critical); }
.delta.baja { color: var(--good-text); }

.tabular { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ lista */

.gasto {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 0;
  border-bottom: 1px solid var(--grid);
  cursor: pointer;
}

.gasto:last-child { border-bottom: 0; }

.gasto-icono {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 11px;
  background: var(--series-1-suave);
  color: var(--series-1);
  display: grid;
  place-items: center;
  font-size: 17px;
}

.gasto-info { flex: 1; min-width: 0; }
.gasto-comercio {
  font-weight: 570;
  font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gasto-meta { font-size: 12.5px; color: var(--text-muted); }

.gasto-montos { text-align: right; flex-shrink: 0; }
.gasto-usd { font-weight: 630; font-size: 15.5px; font-variant-numeric: tabular-nums; }
.gasto-bs { font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ graficos */

.grafico { width: 100%; display: block; overflow: visible; }
.grafico text { font-family: inherit; font-size: 11px; fill: var(--text-muted); }
.grafico .rejilla { stroke: var(--grid); stroke-width: 1; }
.grafico .base { stroke: var(--axis); stroke-width: 1; }
.grafico .barra { fill: var(--series-1); transition: opacity 0.12s; }
.grafico .barra:hover { opacity: 0.78; }
.grafico .valor { fill: var(--text-secondary); font-weight: 600; font-variant-numeric: tabular-nums; }

.barra-cat { margin-bottom: 13px; }
.barra-cat-fila { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 5px; }
.barra-cat-nombre { color: var(--text-primary); font-weight: 520; }
.barra-cat-valor { color: var(--text-secondary); font-weight: 600; font-variant-numeric: tabular-nums; }
.barra-cat-pista { height: 9px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.barra-cat-relleno { height: 100%; background: var(--series-1); border-radius: 5px; transition: width 0.35s ease-out; }

/* ------------------------------------------------------------ avisos */

.aviso {
  border-radius: 11px;
  padding: 13px 15px;
  font-size: 14px;
  margin-bottom: 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  line-height: 1.45;
}

.aviso strong { display: block; margin-bottom: 2px; }
.aviso.info { background: var(--series-1-suave); color: var(--text-primary); }
.aviso.ojo { background: color-mix(in srgb, var(--warning) 18%, var(--surface-1)); border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent); }
.aviso.malo { background: color-mix(in srgb, var(--critical) 12%, var(--surface-1)); border: 1px solid color-mix(in srgb, var(--critical) 40%, transparent); }
.aviso .icono { flex-shrink: 0; font-size: 17px; line-height: 1.3; }

/* ------------------------------------------------------------ varios */

.vacio { text-align: center; padding: 44px 20px; color: var(--text-muted); }
.vacio .emoji { font-size: 40px; display: block; margin-bottom: 12px; opacity: 0.75; }

.cargando { display: inline-block; width: 19px; height: 19px; border: 2.5px solid rgba(255,255,255,0.32); border-top-color: #fff; border-radius: 50%; animation: girar 0.7s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }

.previsualizacion { width: 100%; border-radius: 12px; border: 1px solid var(--border); display: block; margin-bottom: 14px; max-height: 320px; object-fit: contain; background: var(--surface-2); }

.chip-fila { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; -webkit-overflow-scrolling: touch; }
.chip {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 540;
  cursor: pointer;
  white-space: nowrap;
}
.chip.activo { background: var(--series-1); color: #fff; border-color: var(--series-1); }

.hoja {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: aparecer 0.15s;
}
.hoja-contenido {
  background: var(--plane);
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(24px + var(--seguro-abajo));
  animation: subir 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes subir { from { transform: translateY(24px); } to { transform: none; } }

.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th, .tabla td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--grid); }
.tabla th { color: var(--text-secondary); font-weight: 600; font-size: 12.5px; }
.tabla td.num, .tabla th.num { text-align: right; font-variant-numeric: tabular-nums; }

.enlace-boton { background: none; border: 0; color: var(--series-1); font-size: 13.5px; font-weight: 570; cursor: pointer; padding: 4px 0; font-family: inherit; }

.login-caja { max-width: 400px; margin: 0 auto; padding: 40px 20px calc(40px + var(--seguro-abajo)); }
.login-logo { text-align: center; margin-bottom: 26px; }
.login-logo .emoji { font-size: 48px; display: block; margin-bottom: 8px; }
.login-logo h1 { margin: 0 0 4px; font-size: 25px; font-weight: 660; letter-spacing: -0.02em; }
.login-logo p { margin: 0; color: var(--text-secondary); font-size: 14.5px; }

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