/* Plata · estilos. Colores y medidas del sistema de Apple; modo claro u oscuro según el dispositivo. */
:root {
  color-scheme: light dark;
  --fondo: #f2f2f7; --tarjeta: #fff; --texto: #1d1d1f; --texto-2: #6e6e73; --texto-3: #c7c7cc;
  --linea: rgba(60, 60, 67, 0.14); --relleno: rgba(118, 118, 128, 0.12); --relleno-solido: #ebebf0;
  --azul: #007aff; --verde: #34c759; --rojo: #ff3b30; --naranja: #ff9500;
  --radio: 14px; --sombra: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 20px rgba(0, 0, 0, 0.04);
  --vidrio: rgba(249, 249, 251, 0.82);
  --fuente: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #000; --tarjeta: #1c1c1e; --texto: #f5f5f7; --texto-2: #98989d; --texto-3: #48484a;
    --linea: rgba(84, 84, 88, 0.55); --relleno: rgba(118, 118, 128, 0.24); --relleno-solido: #2c2c2e;
    --azul: #0a84ff; --verde: #30d158; --rojo: #ff453a; --naranja: #ff9f0a;
    --sombra: none; --vidrio: rgba(22, 22, 24, 0.82);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fondo); color: var(--texto);
  font: 17px/1.35 var(--fuente); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--azul); }
h1, h2, h3 { letter-spacing: -0.01em; }
small { color: var(--texto-2); font-size: 13px; }
code { font-family: var(--mono); font-size: 0.88em; background: var(--relleno); padding: 1px 6px; border-radius: 6px; word-break: break-all; }
:focus-visible { outline: 2px solid var(--azul); outline-offset: 2px; }
.verde { color: var(--verde); }
.rojo { color: var(--rojo); }

/* ---------- Botones y campos ---------- */
button, .boton {
  font: inherit; font-size: 16px; font-weight: 500; color: var(--azul); background: var(--relleno);
  border: 0; border-radius: 12px; padding: 11px 18px; min-height: 44px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
button:disabled { opacity: 0.5; cursor: progress; }
.primario { background: var(--azul); color: #fff; font-weight: 600; }
.grande { width: 100%; max-width: 380px; padding: 15px 24px; font-size: 18px; }
.texto { background: none; padding: 8px 10px; min-height: 0; }
.texto.rojo { color: var(--rojo); }
.fuerte { font-weight: 600; }
.peligro { color: var(--rojo); width: 100%; background: var(--tarjeta); }
.ancho-boton { width: 100%; margin-top: 12px; }

input, select, textarea {
  font: inherit; font-size: 17px; color: inherit; background: var(--relleno);
  border: 0; border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px; min-width: 0;
}
textarea { resize: vertical; font-family: var(--mono); font-size: 14px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--texto-2) 50%), linear-gradient(135deg, var(--texto-2) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; accent-color: var(--azul); }
input[type="checkbox"] { width: 20px; height: 20px; flex: none; }
input[type="color"] { padding: 4px; height: 44px; max-width: 80px; }
input[type="file"] { padding: 8px; font-size: 15px; }

.campos { display: grid; overflow: hidden; }
.campo { display: grid; gap: 6px; padding: 10px 16px; }
.campo > span { font-size: 13px; color: var(--texto-2); }
.campo + .campo, .campo + .campo-check, .campo-check + .campo { border-top: 0.5px solid var(--linea); }
.campo.linea { grid-template-columns: 110px minmax(0, 1fr); align-items: center; gap: 12px; }
.campo.linea > span { font-size: 16px; color: var(--texto); }
.campo.linea input, .campo.linea select { background-color: transparent; text-align: right; padding: 6px 0; min-height: 36px; }
.campo.linea select { text-align-last: right; padding-right: 22px; background-position: calc(100% - 9px) 50%, calc(100% - 4px) 50%; }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.campo-check { padding: 12px 16px; }
.campo[data-si] { display: none; }
form:has(option[value="credito"]:checked) .campo[data-si="credito"] { display: grid; }

/* ---------- Tarjetas y listas ---------- */
.tarjeta { background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); }
.lista { overflow: hidden; }
.fila {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 52px; width: 100%;
  background: none; border-radius: 0; color: inherit; font-weight: 400; text-align: left; text-decoration: none; position: relative;
  justify-content: flex-start;
}
.fila + .fila::before, .fila + form.fila::before { content: ""; position: absolute; top: 0; left: 60px; right: 0; border-top: 0.5px solid var(--linea); }
button.fila:active, a.fila:active { background: var(--relleno); }
.ico {
  width: 34px; height: 34px; border-radius: 9px; flex: none; display: grid; place-items: center; font-size: 18px;
  background: color-mix(in srgb, var(--c, #8e8e93) 18%, transparent);
}
.punto { width: 12px; height: 12px; border-radius: 50%; display: block; }
.txt { flex: 1; min-width: 0; display: grid; gap: 1px; }
.txt b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txt small { overflow: hidden; text-overflow: ellipsis; }
.monto { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.monto.ingreso { color: var(--verde); }
.pendiente { width: 8px; height: 8px; border-radius: 50%; background: var(--naranja); display: inline-block; }
.flecha { color: var(--texto-3); font-size: 24px; line-height: 1; margin-left: auto; }
.chip-mini { font-size: 12px; font-weight: 600; color: var(--texto-2); background: var(--relleno); padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.agregar b { color: var(--azul); font-weight: 500; }
.agregar .ico { color: var(--azul); --c: var(--azul); }
.medidor { display: block; height: 6px; border-radius: 3px; background: var(--relleno); margin-top: 6px; overflow: hidden; }
.medidor > i { display: block; height: 100%; border-radius: 3px; transition: width 0.4s; }
.vacio { color: var(--texto-2); text-align: center; padding: 22px 16px; margin: 0; font-size: 15px; }
.explica { color: var(--texto-2); font-size: 15px; margin: -6px 4px 16px; max-width: 720px; }
.pie { color: var(--texto-2); font-size: 13px; padding: 8px 16px 0; margin: 0; }

.seccion > header { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 8px; }
.seccion h2 { font-size: 20px; font-weight: 600; margin: 0; }
.seccion h2 small { font-weight: 400; margin-left: 6px; }
.seccion header a { text-decoration: none; font-size: 15px; }
.botones { gap: 8px; flex-wrap: wrap; }
.formulario-linea { gap: 8px; flex-wrap: wrap; }
.formulario-linea input { flex: 2 1 160px; }
.formulario-linea select { flex: 1 1 140px; }

/* ---------- Estructura: barra inferior (iPhone) o lateral (PC) ---------- */
.barra {
  position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; align-items: center;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: var(--vidrio); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--linea);
}
.barra a { display: grid; justify-items: center; gap: 2px; min-width: 64px; font-size: 10px; font-weight: 500; color: var(--texto-2); text-decoration: none; }
.barra a.activo { color: var(--azul); }
.barra svg { width: 26px; height: 26px; }
.barra .marca { display: none; }
.nuevo { width: 50px; height: 50px; padding: 0; border-radius: 50%; background: var(--azul); color: #fff; box-shadow: 0 4px 14px color-mix(in srgb, var(--azul) 40%, transparent); }
.nuevo span { display: none; }
.nuevo svg { width: 26px; height: 26px; }
.vista { max-width: 1180px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 8px) 16px calc(100px + env(safe-area-inset-bottom)); }

@media (min-width: 900px) {
  .barra {
    top: 0; right: auto; width: 232px; flex-direction: column; justify-content: flex-start; align-items: stretch; gap: 2px;
    padding: 22px 12px; border-top: 0; border-right: 0.5px solid var(--linea);
  }
  .barra .marca { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; padding: 0 8px 18px; order: -2; }
  .barra a { grid-auto-flow: column; justify-content: start; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; font-size: 15px; color: var(--texto); }
  .barra a.activo { background: var(--relleno); }
  .barra svg { width: 20px; height: 20px; }
  .nuevo { order: -1; width: auto; height: 40px; border-radius: 10px; margin-bottom: 14px; font-size: 15px; font-weight: 600; box-shadow: none; }
  .nuevo span { display: inline; }
  .nuevo svg { width: 18px; height: 18px; }
  .vista { margin-left: 232px; padding: 36px 40px 56px; }
}

.titulo h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; margin: 6px 0 18px; }
.eyebrow { margin: 10px 0 0; color: var(--texto-2); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.eyebrow a { text-decoration: none; }

/* ---------- Inicio ---------- */
.rejilla { display: grid; gap: 22px; }
@media (min-width: 900px) { .rejilla { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } .rejilla > .ancho { grid-column: 1 / -1; } }
.resumen { padding: 20px; }
.enorme { display: block; font-size: 46px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; margin: 2px 0 14px; line-height: 1.1; }
.pares { display: flex; gap: 28px; }
.pares span { display: grid; font-size: 13px; color: var(--texto-2); }
.pares b { font-size: 18px; font-weight: 600; color: var(--texto); font-variant-numeric: tabular-nums; }
.pares b.rojo { color: var(--rojo); } .pares b.verde { color: var(--verde); }
a.enlace { display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: inherit; text-decoration: none; }
.destacado { outline: 1.5px solid color-mix(in srgb, var(--naranja) 60%, transparent); }

/* ---------- Movimientos ---------- */
.filtros { display: grid; gap: 8px; padding: 12px; margin-bottom: 14px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.filtros input[type="search"] { grid-column: 1 / -1; }
.filtros label:not(.check) { display: grid; gap: 2px; font-size: 12px; color: var(--texto-2); }
.filtros .check { padding: 0 4px; }
.totales { display: flex; gap: 18px; padding: 0 4px 6px; font-size: 15px; color: var(--texto-2); }
.totales b { color: var(--texto); font-variant-numeric: tabular-nums; }
.dia h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--texto-2); margin: 18px 4px 6px; }

/* ---------- Hoja (ventana que sube desde abajo) ---------- */
dialog#hoja {
  border: 0; padding: 0; color: inherit; background: var(--fondo); width: 100%; max-width: 560px; max-height: 94dvh;
  margin: auto auto 0; border-radius: 16px 16px 0 0; overflow: auto; overscroll-behavior: contain;
}
dialog#hoja::backdrop { background: rgba(0, 0, 0, 0.38); }
dialog#hoja[open] { animation: subir 0.28s cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes subir { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) { dialog#hoja { margin: auto; border-radius: 18px; max-height: 88vh; } }
#hoja > form, #hoja > div { display: grid; gap: 16px; padding: 0 16px calc(20px + env(safe-area-inset-bottom)); }
#hoja p { margin: 0; }
.hoja-cabeza {
  position: sticky; top: 0; z-index: 1; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  margin: 0 -16px; padding: 8px 6px; background: var(--vidrio); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.hoja-cabeza h2 { font-size: 17px; font-weight: 600; margin: 0; }
.hoja-cabeza > :first-child { justify-self: start; }
.hoja-cabeza > :last-child { justify-self: end; }

.segmentos { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--relleno); border-radius: 10px; padding: 2px; }
.segmentos input, .chip input { position: absolute; opacity: 0; pointer-events: none; }
.segmentos span { display: block; text-align: center; padding: 7px 4px; border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; }
.segmentos input:checked + span { background: var(--tarjeta); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14); }
.segmentos input:focus-visible + span, .chip input:focus-visible + span { outline: 2px solid var(--azul); outline-offset: 1px; }
.monto-grande { display: flex; align-items: baseline; justify-content: center; gap: 4px; font-size: 52px; font-weight: 700; letter-spacing: -0.03em; }
.monto-grande span { color: var(--texto-2); font-weight: 600; }
.monto-grande input { font: inherit; letter-spacing: inherit; background: none; padding: 0; width: 1.3ch; max-width: 80%; font-variant-numeric: tabular-nums; }
.monto-grande input:focus-visible { outline: none; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--texto-2); padding: 0 4px 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip span { display: inline-block; padding: 8px 13px; border-radius: 999px; background: var(--tarjeta); box-shadow: inset 0 0 0 1px var(--linea); font-size: 15px; cursor: pointer; }
.chip input:checked + span { background: var(--azul); color: #fff; box-shadow: none; }
/* El formulario muestra solo lo que corresponde al tipo elegido (gasto, ingreso o transferencia). */
.hoja-mov:has([name="tipo"][value="gasto"]:checked) [data-solo]:not([data-solo="gasto"]),
.hoja-mov:has([name="tipo"][value="ingreso"]:checked) [data-solo]:not([data-solo="ingreso"]),
.hoja-mov:has([name="tipo"][value="transferencia"]:checked) [data-solo]:not([data-solo="transferencia"]) { display: none; }

/* ---------- Avisos breves ---------- */
#toast {
  position: fixed; inset: auto auto calc(104px + env(safe-area-inset-bottom)) 50%; transform: translateX(-50%); margin: 0;
  border: 0; padding: 12px 18px; border-radius: 14px; max-width: min(92vw, 440px); text-align: center; font-size: 15px;
  background: rgba(28, 28, 30, 0.94); color: #fff; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}
#toast:not([popover]) { opacity: 0; pointer-events: none; transition: opacity 0.25s; }
#toast:not([popover]).visible { opacity: 1; }
#toast:popover-open { animation: aparecer 0.25s ease-out; }
@keyframes aparecer { from { opacity: 0; transform: translate(-50%, 12px); } }
#toast.error { background: var(--rojo); }
@media (min-width: 900px) { #toast { bottom: 32px; } }

/* ---------- Acceso (entrar, instalar, bienvenida) ---------- */
.acceso {
  min-height: 100dvh; max-width: 480px; margin: 0 auto; display: grid; align-content: center; justify-items: center; gap: 16px;
  padding: calc(env(safe-area-inset-top) + 32px) 20px calc(env(safe-area-inset-bottom) + 32px); text-align: center;
}
.acceso h1 { font-size: 32px; letter-spacing: -0.02em; margin: 6px 0 0; }
.acceso > p { color: var(--texto-2); margin: 0; }
.acceso .nota { font-size: 13px; }
.formulario { width: 100%; display: grid; gap: 12px; text-align: left; }
.acceso .formulario .texto { justify-self: center; }
.icono-app {
  width: 88px; height: 88px; border-radius: 20px; display: grid; place-items: center; color: #fff; font-size: 50px; font-weight: 700;
  background: linear-gradient(160deg, #3ddc84 0%, #0d9b5f 55%, #07633e 100%); box-shadow: 0 12px 34px rgba(13, 155, 95, 0.32);
}
.icono-app.mini { width: 30px; height: 30px; border-radius: 8px; font-size: 17px; box-shadow: none; }
.opcion { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); cursor: pointer; text-align: left; }
.opcion .txt b { white-space: normal; }
.opcion input { width: 24px; height: 24px; }
.lista-opciones { display: grid; gap: 8px; }
.codigos { font-family: var(--mono); font-size: 17px; columns: 2; column-gap: 28px; padding: 16px 16px 16px 44px; margin: 0; width: 100%; text-align: left; }
.codigos li { padding: 3px 0; }
.recuperar { width: 100%; max-width: 380px; text-align: left; }
.recuperar summary { text-align: center; color: var(--azul); cursor: pointer; font-size: 15px; padding: 8px; }
.token { font-family: var(--mono); font-size: 15px; padding: 14px 16px; word-break: break-all; user-select: all; }

/* ---------- Ajustes ---------- */
.grupos { display: grid; gap: 28px; max-width: 760px; }
.guia { margin-top: 10px; padding: 4px 16px 12px; }
.guia summary { cursor: pointer; color: var(--azul); padding: 10px 0; font-weight: 500; }
.guia h3 { font-size: 16px; margin: 14px 0 4px; }
.guia ol { padding-left: 20px; margin: 6px 0; }
.guia li { margin: 7px 0; font-size: 15px; }

/* ---------- Panel ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi b { display: block; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.graficas { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); }
.grafica { padding: 16px 16px 8px; min-width: 0; }
.grafica.ancha { grid-column: 1 / -1; }
.grafica h3 { margin: 0; font-size: 17px; font-weight: 600; }
.grafica > p { margin: 2px 0 8px; color: var(--texto-2); font-size: 14px; }
.lienzo { height: 290px; }
#g-calendario { height: 210px; }

/* ---------- Importar ---------- */
.tabla-scroll { overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th, .tabla td { padding: 8px 10px; border-bottom: 0.5px solid var(--linea); text-align: left; vertical-align: middle; }
.tabla th { font-size: 12px; color: var(--texto-2); font-weight: 600; text-transform: uppercase; }
.tabla td.monto { display: table-cell; text-align: right; }
.tabla select { min-width: 150px; min-height: 36px; padding: 6px 28px 6px 8px; font-size: 14px; }
.duplicado { opacity: 0.55; }
#columnas, #revision { margin-top: 24px; }

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