/* Cerebro Familia — estilos, sin frameworks, sin CDNs */

:root {
  --bg: #0f1115;
  --bg-elevado: #171a21;
  --bg-tarjeta: #1b1f28;
  --borde: #262b36;
  --texto: #f1f2f5;
  --texto-tenue: #9aa0ac;
  --texto-muy-tenue: #5c6472;
  --acento: #e8935c;
  --acento-fuerte: #f3a56f;
  --verde: #5fbf8b;
  --rojo: #e0685f;
  --azul: #6ea8e0;
  --radio: 16px;
  --radio-chico: 10px;
  --sombra: 0 8px 24px rgba(0,0,0,0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--texto);
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

button {
  font-family: inherit;
  cursor: pointer;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* evita zoom automático en iOS */
}

.pantalla {
  min-height: 100vh;
  min-height: 100dvh;
}

/* ===== Login ===== */

#pantalla-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 24px) 20px calc(var(--safe-bottom) + 24px);
}

.login-wrap {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.login-logo {
  font-size: 48px;
  margin-bottom: 4px;
}

.login-titulo {
  font-size: 22px;
  font-weight: 600;
  margin: 0;
}

.login-sub {
  color: var(--texto-tenue);
  font-size: 14px;
  margin: 0 0 20px;
}

.pin-dots {
  display: flex;
  gap: 18px;
  margin-bottom: 14px;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--texto-muy-tenue);
  background: transparent;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.pin-dot.lleno {
  background: var(--acento);
  border-color: var(--acento);
  transform: scale(1.1);
}

.pin-dot.error {
  border-color: var(--rojo);
  background: var(--rojo);
}

.pin-error {
  color: var(--rojo);
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 12px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  gap: 14px;
  margin-top: 8px;
}

.tecla {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 1px solid var(--borde);
  background: var(--bg-elevado);
  color: var(--texto);
  font-size: 26px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .1s ease;
}

.tecla:active {
  background: #23283333;
  background: #262c38;
}

.tecla-vacia {
  border: none;
  background: transparent;
  cursor: default;
}

.tecla-borrar {
  font-size: 20px;
  color: var(--texto-tenue);
}

/* ===== App shell ===== */

#pantalla-app {
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 14px) 18px 14px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid var(--borde);
}

.app-header-saludo {
  font-size: 19px;
  font-weight: 600;
}

.app-header-acciones {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--borde);
  background: var(--bg-elevado);
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: #262c38;
}

.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(96px + var(--safe-bottom));
}

/* ===== Tarjetas / secciones ===== */

.seccion-titulo {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--texto-tenue);
  margin: 22px 0 10px;
}

.seccion-titulo:first-child {
  margin-top: 0;
}

.tarjeta {
  background: var(--bg-tarjeta);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 16px;
  margin-bottom: 12px;
}

.tarjeta-total {
  padding: 20px 18px;
}

.tarjeta-total-label {
  color: var(--texto-tenue);
  font-size: 13px;
  margin-bottom: 6px;
}

.tarjeta-total-monto {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.tarjeta-total-comparacion {
  margin-top: 8px;
  font-size: 13px;
  color: var(--texto-tenue);
}

.tarjeta-total-comparacion .up { color: var(--rojo); }
.tarjeta-total-comparacion .down { color: var(--verde); }

/* Barras por categoría */

.barra-fila {
  margin-bottom: 12px;
}

.barra-fila:last-child { margin-bottom: 0; }

.barra-cabecera {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 5px;
}

.barra-nombre { color: var(--texto); }
.barra-monto { color: var(--texto-tenue); }

.barra-track {
  height: 8px;
  border-radius: 5px;
  background: var(--bg-elevado);
  overflow: hidden;
}

.barra-fill {
  height: 100%;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--acento), var(--acento-fuerte));
}

/* Listas genéricas */

.lista-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--borde);
}

.lista-item:last-child { border-bottom: none; }

.lista-item-info { min-width: 0; flex: 1; }

.lista-item-titulo {
  font-size: 14.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lista-item-sub {
  font-size: 12.5px;
  color: var(--texto-tenue);
  margin-top: 2px;
}

.lista-item-monto {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

.lista-item-monto.ingreso { color: var(--verde); }

.chip {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--bg-elevado);
  color: var(--texto-tenue);
  margin-left: 6px;
}

/* Item accionable (recordatorio / decisión) con check */

.item-check {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--borde);
}

.item-check:last-child { border-bottom: none; }

.check-btn {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid var(--texto-muy-tenue);
  background: transparent;
  color: var(--texto-tenue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.check-btn:active {
  border-color: var(--verde);
  color: var(--verde);
}

.item-check-info { min-width: 0; flex: 1; }

.item-check-titulo {
  font-size: 14.5px;
  font-weight: 500;
}

.item-check-sub {
  font-size: 12.5px;
  color: var(--texto-tenue);
  margin-top: 2px;
}

/* Inversiones */

.inversion-fila {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--borde);
}

.inversion-fila:last-child { border-bottom: none; }

.inversion-nombre { font-size: 14.5px; font-weight: 500; }
.inversion-valor { font-size: 15px; font-weight: 600; text-align: right; }
.inversion-diff { font-size: 12.5px; margin-top: 2px; text-align: right; }
.inversion-diff.pos { color: var(--verde); }
.inversion-diff.neg { color: var(--rojo); }

/* Notas */

.nota-tarjeta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.nota-cuerpo { min-width: 0; flex: 1; }

.nota-titulo {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}

.nota-contenido {
  font-size: 13.5px;
  color: var(--texto-tenue);
  white-space: pre-wrap;
  word-break: break-word;
}

.nota-borrar {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--texto-muy-tenue);
  font-size: 18px;
  padding: 4px;
}

.nota-borrar:active { color: var(--rojo); }

/* Estados: vacío / error / loading */

.estado-vacio, .estado-error {
  text-align: center;
  padding: 28px 16px;
  color: var(--texto-tenue);
  font-size: 14px;
}

.estado-error button {
  margin-top: 12px;
  display: inline-block;
}

.spinner-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--borde);
  border-top-color: var(--acento);
  animation: girar .8s linear infinite;
}

@keyframes girar {
  to { transform: rotate(360deg); }
}

/* Botones */

.btn {
  border: none;
  border-radius: var(--radio-chico);
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  background: var(--bg-elevado);
  color: var(--texto);
  border: 1px solid var(--borde);
}

.btn-primario {
  background: var(--acento);
  color: #201207;
  border: none;
}

.btn-primario:active { background: var(--acento-fuerte); }

.btn-full { width: 100%; }

/* FAB */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(78px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--acento);
  color: #201207;
  border: none;
  font-size: 28px;
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--sombra);
  z-index: 6;
}

.fab:active { background: var(--acento-fuerte); }

/* Tabbar */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--bg-elevado);
  border-top: 1px solid var(--borde);
  padding-bottom: var(--safe-bottom);
  z-index: 5;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0 8px;
  color: var(--texto-tenue);
  font-size: 11.5px;
  font-weight: 500;
}

.tab-icon { font-size: 20px; }

.tab-activo { color: var(--acento); }

/* Overlay / Modal */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}

.modal {
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-elevado);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(24px + var(--safe-bottom));
}

.modal-titulo {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 16px;
}

.modal-opciones {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 4px;
}

.modal-opcion {
  background: var(--bg-tarjeta);
  border: 1px solid var(--borde);
  border-radius: var(--radio-chico);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
}

.modal-opcion-icono { font-size: 22px; }

.modal-opcion:active { border-color: var(--acento); }

.campo {
  margin-bottom: 14px;
}

.campo label {
  display: block;
  font-size: 13px;
  color: var(--texto-tenue);
  margin-bottom: 6px;
}

.campo input, .campo select, .campo textarea {
  width: 100%;
  background: var(--bg-tarjeta);
  border: 1px solid var(--borde);
  border-radius: var(--radio-chico);
  padding: 12px 12px;
  color: var(--texto);
}

.campo textarea {
  resize: vertical;
  min-height: 70px;
}

.modal-acciones {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.modal-acciones .btn { flex: 1; }

.modal-cerrar {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  border: none;
  color: var(--texto-tenue);
  font-size: 20px;
}

/* Toast */

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(96px + var(--safe-bottom));
  background: #2a1414;
  border: 1px solid #4a2424;
  color: #f5b7b1;
  padding: 12px 16px;
  border-radius: var(--radio-chico);
  font-size: 13.5px;
  z-index: 30;
  box-shadow: var(--sombra);
}

.toast.toast-ok {
  background: #142a1c;
  border-color: #244a34;
  color: #a9e0bf;
}

[hidden] { display: none !important; }
