:root {
  --morado: #6c5ce7;
  --morado-osc: #5546c9;
  --verde: #00b894;
  --rojo: #ff6b6b;
  --azul: #0984e3;
  --fondo: #f5f3ff;
  --texto: #2d2a4a;
  --gris: #8a87a8;
  --borde: #e4e0f7;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  padding-bottom: calc(150px + env(safe-area-inset-bottom));
  font-size: 17px;
}
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(135deg, var(--morado), #a29bfe);
  color: #fff;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar h1 { font-size: 1.15rem; margin: 0; }
.quien {
  border: 2px solid #fff; border-radius: 999px; padding: 6px 14px;
  color: #fff; font-weight: 700; font-size: .95rem; cursor: pointer;
  background: rgba(255,255,255,.2);
}
main { max-width: 640px; margin: 0 auto; padding: 16px; }
h2 { font-size: 1.1rem; margin: 20px 0 8px; }
.ayuda { color: var(--gris); font-size: .9rem; margin: 0 0 10px; }
.vista { display: none; }
.vista.activa { display: block; }

.selector-mes { display: flex; align-items: center; justify-content: space-between; background: #fff; border-radius: 16px; padding: 8px; box-shadow: 0 2px 8px rgba(108,92,231,.1); }
.selector-mes button { width: 48px; height: 48px; font-size: 1.6rem; border: 0; background: var(--fondo); border-radius: 12px; color: var(--morado); cursor: pointer; }
.selector-mes strong { text-transform: capitalize; }

.tarjetas { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.tarjeta { border-radius: 18px; padding: 14px; color: #fff; display: flex; flex-direction: column; gap: 4px; }
.tarjeta span { font-size: .85rem; opacity: .9; }
.tarjeta b { font-size: 1.35rem; }
.tarjeta.ancha { grid-column: span 2; }
.verde { background: linear-gradient(135deg, #00b894, #55efc4); }
.rojo { background: linear-gradient(135deg, #ff6b6b, #ff9f7f); }
.azul { background: linear-gradient(135deg, #0984e3, #74b9ff); }

.torta-caja { background: #fff; border-radius: 18px; padding: 16px; box-shadow: 0 2px 8px rgba(108,92,231,.1); }
.torta-caja svg { display: block; margin: 0 auto 12px; max-width: 240px; width: 100%; }
.leyenda { list-style: none; margin: 0; padding: 0; }
.leyenda li { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: .95rem; }
.punto { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.leyenda .monto { margin-left: auto; font-weight: 700; }
.pres { padding: 8px 0; }
.pres + .pres { border-top: 1px solid var(--borde); }
.pres-cab { display: flex; justify-content: space-between; gap: 8px; font-size: .95rem; margin-bottom: 6px; }
.pres-cab small { color: var(--gris); white-space: nowrap; }
.barra { height: 14px; background: var(--fondo); border-radius: 999px; overflow: hidden; }
.barra i { display: block; height: 100%; border-radius: 999px; background: var(--verde); }
.barra i.amarillo { background: #fdcb6e; }
.barra i.rojo { background: var(--rojo); }
.pres-msg { font-size: .85rem; margin-top: 4px; font-weight: 700; }
.pres-msg.amarillo { color: #c98a00; }
.pres-msg.rojo { color: #d63031; }
.pres-msg.ok { color: #00846a; }
.filtros { background: #fff; border-radius: 18px; padding: 4px 16px 16px; box-shadow: 0 2px 8px rgba(108,92,231,.1); margin-bottom: 14px; }
.nav button { min-width: 0; }
.dictado { background: var(--fondo); border-radius: 16px; padding: 4px 12px 12px; margin-bottom: 8px; }
.dictado .ayuda { margin: 8px 0 0; }
.fila-dic { display: flex; gap: 8px; }
.fila-dic input { flex: 1; min-width: 0; }
.fila-dic .btn { flex: none; width: 56px; background: #fff; border: 2px solid var(--borde); font-size: 1.3rem; padding: 8px; }
.fila-dic .btn[hidden] { display: none; }
.dictado > .btn { width: 100%; margin-top: 8px; background: #fff; }
.tipo input:checked + span.v { background: var(--morado); border-color: var(--morado); color: #fff; }
.selector-vista { margin-top: 12px; }
.auth { position: fixed; inset: 0; z-index: 30; overflow-y: auto; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(135deg, var(--morado), #a29bfe); }
.auth[hidden] { display: none; }
.auth-caja { width: 100%; max-width: 420px; background: #fff; border-radius: 24px; padding: 22px 18px 20px; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.auth-caja h1 { font-size: 1.3rem; margin: 0 0 14px; text-align: center; }
.auth-tabs { margin-bottom: 4px; }
.auth-caja .btn.grande { margin-top: 16px; }
#authMsg { margin: 0 0 10px; }
.auth-sub { font-size: 1.05rem; margin: 4px 0 6px; text-align: center; }
.enlace { display: block; width: 100%; margin-top: 12px; padding: 10px; border: 0; background: none; color: var(--morado); font: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; }
.tarjeta-cuenta { background: #fff; border-radius: 18px; padding: 14px; box-shadow: 0 2px 8px rgba(108,92,231,.1); margin-bottom: 14px; }
.tarjeta-cuenta h3 { margin: 0 0 6px; font-size: 1rem; }
.tarjeta-cuenta .ayuda { margin: 0 0 10px; }
.tarjeta-cuenta .btn { width: 100%; margin-top: 8px; }
.interruptor { display: flex; align-items: center; gap: 12px; margin: 0; font-size: 1rem; color: var(--texto); cursor: pointer; }
.interruptor input { width: 26px; height: 26px; flex: none; accent-color: var(--morado); }
.etiqueta { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--fondo); color: var(--morado); margin-left: 6px; vertical-align: middle; }
.codigo { font-family: ui-monospace, Consolas, monospace; font-size: 1.8rem; font-weight: 800; letter-spacing: 3px; text-align: center; background: var(--fondo); border-radius: 14px; padding: 14px; user-select: all; }
.item.solo-lectura { cursor: default; }
.vacio { text-align: center; color: var(--gris); padding: 20px 0; }

.lista { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: #fff; border: 0; border-radius: 16px; padding: 12px;
  box-shadow: 0 2px 8px rgba(108,92,231,.1); text-align: left; cursor: pointer; color: inherit; font: inherit;
}
.icono { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 1.4rem; flex: none; }
.item .info { flex: 1; min-width: 0; }
.item .info b, .item .info small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item small { color: var(--gris); }
.item .valor { font-weight: 800; }
.valor.gasto { color: var(--rojo); }
.valor.ingreso { color: var(--verde); }

.btn { border: 0; border-radius: 14px; padding: 12px 18px; font-size: 1rem; font-weight: 700; cursor: pointer; background: var(--fondo); color: var(--morado); font-family: inherit; }
.btn.primario { background: var(--morado); color: #fff; }
.btn.peligro { background: #ffe3e3; color: #d63031; }
.btn.grande { width: 100%; margin-top: 14px; background: var(--morado); color: #fff; padding: 15px; }

.fab {
  position: fixed; right: 18px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 6;
  width: 62px; height: 62px; border-radius: 50%; border: 0; cursor: pointer;
  background: linear-gradient(135deg, #fd79a8, #e84393); color: #fff; font-size: 2rem;
  box-shadow: 0 6px 16px rgba(232,67,147,.45);
}
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: #fff;
  border-top: 1px solid var(--borde); padding-bottom: env(safe-area-inset-bottom);
}
.nav button { flex: 1; border: 0; background: none; padding: 10px 4px; font-size: .75rem; color: var(--gris); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; font-family: inherit; }
.nav button span { font-size: 1.4rem; }
.nav button.activo { color: var(--morado); font-weight: 700; }

.modal { position: fixed; inset: 0; z-index: 10; background: rgba(45,42,74,.55); display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-caja { background: #fff; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; border-radius: 24px 24px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); }
.modal-caja h3 { margin: 0 0 12px; }
label { display: block; font-size: .85rem; font-weight: 700; margin: 12px 0 4px; color: var(--gris); }
input, select { width: 100%; padding: 13px; font-size: 1rem; border: 2px solid var(--borde); border-radius: 12px; background: #fff; color: var(--texto); font-family: inherit; }
input[type=color] { padding: 4px; height: 50px; }
.fila { display: flex; gap: 10px; }
.fila > * { flex: 1; }
.tipo { display: flex; gap: 8px; }
.tipo label { flex: 1; margin: 0; }
.tipo input { display: none; }
.tipo span { display: block; text-align: center; padding: 12px; border-radius: 12px; border: 2px solid var(--borde); font-weight: 700; color: var(--texto); cursor: pointer; }
.tipo input:checked + span.g { background: var(--rojo); border-color: var(--rojo); color: #fff; }
.tipo input:checked + span.i { background: var(--verde); border-color: var(--verde); color: #fff; }
.acciones { display: flex; gap: 10px; margin-top: 18px; }
.acciones .btn { flex: 1; }
