/* ============================================================
   FINANZAS HOGAR — Estilos
   Estética: limpia tipo dashboard (referencia), con acentos de color.
   ============================================================ */
:root {
  --bg: #EDECE8;
  --surface: #FFFFFF;
  --surface-2: #F7F6F3;
  --border: #E5E3DD;
  --text: #17171C;
  --text-2: #6B6B76;
  --text-3: #9C9CA6;
  --primary: #4F46E5;
  --primary-soft: #EEF0FE;
  --green: #16A34A;   --green-soft: #EAF7EF;
  --red: #DC2626;     --red-soft: #FDECEC;
  --amber: #D97706;   --amber-soft: #FCF3E3;
  --cyan: #0891B2;    --cyan-soft: #E5F6FA;
  --pink: #DB2777;    --pink-soft: #FBE9F2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20,20,30,.05), 0 4px 16px rgba(20,20,30,.05);
  --font: 'Inter', system-ui, sans-serif;
  --font-display: 'Space Grotesk', var(--font);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: .95rem; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 6px 8px 20px; }
.brand-icon { width: 38px; height: 38px; background: var(--text); color: #fff; border-radius: 11px; display: grid; place-items: center; font-size: 1.1rem; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1rem; }
.brand-sub { font-size: .72rem; color: var(--text-3); }
.nav-label { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin: 16px 10px 6px; }
.nav-item {
  display: block; padding: 9px 12px; border-radius: 10px; font-size: .92rem;
  color: var(--text-2); font-weight: 500; margin-bottom: 2px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--text); color: #fff; }
.sidebar-user { margin-top: auto; display: flex; gap: 10px; align-items: center; padding: 12px 8px 4px; border-top: 1px solid var(--border); }
.avatar { width: 34px; height: 34px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; }
.sidebar-user-info { font-size: .85rem; line-height: 1.3; }
.sidebar-user-info a { color: var(--text-3); font-size: .75rem; }
.sidebar-user-info a:hover { color: var(--red); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 16px 26px;
  position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px); z-index: 20;
}
.topbar-title { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; flex: 1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.menu-toggle { display: none; }
.content { padding: 6px 26px 40px; }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card-title { font-size: .72rem; letter-spacing: .09em; text-transform: uppercase; color: var(--text-3); font-weight: 600; margin-bottom: 10px; }
.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-2 { grid-template-columns: 1.6fr 1fr; }
.grid-2e { grid-template-columns: 1fr 1fr; }
@media (max-width: 1000px) { .grid-2, .grid-2e { grid-template-columns: 1fr; } }

.kpi-valor { font-family: var(--font-display); font-size: 1.65rem; font-weight: 700; letter-spacing: -.02em; }
.kpi-nota { font-size: .78rem; color: var(--text-3); margin-top: 4px; }
.kpi-nota .up { color: var(--green); } .kpi-nota .down { color: var(--red); }

.btn { border: none; border-radius: 10px; padding: 9px 16px; font-weight: 600; font-size: .9rem; transition: opacity .15s; }
.btn:hover { opacity: .88; }
.btn-primary { background: var(--text); color: #fff; }
.btn-accent { background: var(--primary); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-2); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: .8rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-icon { background: none; border: none; font-size: 1.2rem; }

.input-sm, input, select, textarea {
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;
  background: var(--surface); color: var(--text); outline: none; width: 100%;
}
.input-sm { width: auto; padding: 7px 10px; font-size: .85rem; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
label { display: block; font-size: .8rem; font-weight: 600; color: var(--text-2); margin: 12px 0 5px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-gray { background: var(--surface-2); color: var(--text-2); }
.badge-cyan { background: var(--cyan-soft); color: var(--cyan); }
.badge-pink { background: var(--pink-soft); color: var(--pink); }

/* Tablas */
.tabla { width: 100%; border-collapse: collapse; font-size: .89rem; }
.tabla th { text-align: left; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); padding: 10px 12px; border-bottom: 1px solid var(--border); }
.tabla td { padding: 11px 12px; border-bottom: 1px solid var(--surface-2); vertical-align: middle; }
.tabla tr:last-child td { border-bottom: none; }
.tabla tr:hover td { background: var(--surface-2); }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.cat-chip { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; }
.cat-dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* Barras de progreso */
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; border-radius: 99px; transition: width .4s; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,20,28,.45); z-index: 90; display: grid; place-items: center; padding: 18px; }
.modal-backdrop[hidden], .toast[hidden] { display: none; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h3 { font-family: var(--font-display); margin-bottom: 4px; }
.modal .modal-sub { color: var(--text-3); font-size: .82rem; margin-bottom: 10px; }
.modal-acciones { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }
.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 11px 20px; border-radius: 12px; font-size: .9rem; z-index: 99; box-shadow: var(--shadow); }
.toast.err { background: var(--red); }

/* Listas del dashboard */
.lista-item { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--surface-2); }
.lista-item:last-child { border-bottom: none; }
.lista-icono { width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-size: 1rem; flex-shrink: 0; }
.lista-main { flex: 1; min-width: 0; }
.lista-main strong { display: block; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lista-main small { color: var(--text-3); font-size: .76rem; }
.lista-monto { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lista-monto.gasto { color: var(--red); } .lista-monto.ingreso { color: var(--green); }

/* Informe IA */
.informe { line-height: 1.65; font-size: .95rem; }
.informe h1, .informe h2, .informe h3 { font-family: var(--font-display); margin: 18px 0 8px; }
.informe ul, .informe ol { margin: 8px 0 8px 22px; }
.informe strong { color: var(--text); }
.informe p { margin: 8px 0; }

.alert { padding: 10px 14px; border-radius: 10px; font-size: .87rem; margin-bottom: 12px; }
.alert-error { background: var(--red-soft); color: var(--red); }
.loading { text-align: center; color: var(--text-3); padding: 60px 0; }
.vacio { text-align: center; color: var(--text-3); padding: 34px 10px; font-size: .9rem; }
.mt { margin-top: 16px; }
.acciones-tabla { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow); padding: 38px 34px; width: 100%; max-width: 380px; text-align: center; }
.login-logo { font-size: 2.2rem; margin-bottom: 8px; }
.login-card h1 { font-family: var(--font-display); font-size: 1.4rem; }
.login-sub { color: var(--text-3); font-size: .85rem; margin-bottom: 20px; }
.login-card form { text-align: left; }
.login-card .btn { margin-top: 20px; }

/* ---------- Móvil ---------- */
.bottomnav { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(20,20,28,.45); z-index: 45; opacity: 0; pointer-events: none; transition: opacity .25s; }
.scrim.visible { opacity: 1; pointer-events: auto; }

@media (max-width: 820px) {
  html { font-size: 14px; }
  .sidebar { position: fixed; z-index: 50; transform: translateX(-105%); transition: transform .25s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: block; }
  .content { padding: 6px 14px 110px; }
  .topbar { padding: 12px 14px; flex-wrap: wrap; }
  .topbar-title { font-size: 1.05rem; }
  .topbar-actions .btn-primary { display: none; }   /* en móvil lo reemplaza el botón central */
  .grid-kpi { grid-template-columns: 1fr 1fr; }
  .kpi-valor { font-size: 1.3rem; }
  .card { padding: 14px 14px; }

  /* Barra de navegación inferior tipo app */
  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
    justify-content: space-around; align-items: center;
    box-shadow: 0 -4px 20px rgba(20,20,30,.06);
  }
  .bn-item {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: .62rem; font-weight: 600; color: var(--text-3);
    background: none; border: none; padding: 4px 8px; border-radius: 10px; min-width: 56px;
  }
  .bn-item .bn-ico { font-size: 1.25rem; line-height: 1; }
  .bn-item.active { color: var(--text); }
  .bn-fab {
    width: 54px; height: 54px; border-radius: 50%; background: var(--text); color: #fff;
    font-size: 1.7rem; border: none; display: grid; place-items: center;
    margin-top: -28px; box-shadow: 0 6px 18px rgba(0,0,0,.3); flex-shrink: 0;
  }
  .bn-fab:active { transform: scale(.94); }

  /* Modales como hoja inferior (bottom sheet) */
  .modal-backdrop { place-items: end center; padding: 0; }
  .modal { max-width: none; border-radius: 20px 20px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); max-height: 88vh; }
  .modal-acciones { position: sticky; bottom: 0; background: var(--surface); padding-top: 10px; }
  .modal-acciones .btn { flex: 1; padding: 12px; }

  /* Toast por encima de la barra inferior */
  .toast { bottom: calc(86px + env(safe-area-inset-bottom)); width: calc(100% - 40px); text-align: center; }
}
