/* ============================================================
   Finanzas Personales — Design System (light + dark)
   ============================================================ */
:root {
  --bg:          #f4f6fa;
  --surface:     #ffffff;
  --surface-2:   #f8fafc;
  --text:        #1e2937;
  --text-muted:  #6b7280;
  --border:      #e5e9f0;
  --primary:     #2563eb;
  --primary-d:   #1d4ed8;
  --primary-light:#e8f0fe;
  --accent:      #0ea5e9;
  --success:     #16a34a;
  --warning:     #d97706;
  --danger:      #dc2626;
  --sidebar-bg:  #0f172a;
  --sidebar-text:#cbd5e1;
  --sidebar-muted:#64748b;
  --shadow:      0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg:   0 12px 32px rgba(16,24,40,.12);
  --radius:      14px;
}
:root[data-theme="dark"] {
  --bg:          #0b1120;
  --surface:     #131c30;
  --surface-2:   #0f1830;
  --text:        #e6eaf2;
  --text-muted:  #93a1b5;
  --border:      #25304a;
  --primary:     #3b82f6;
  --primary-d:   #2563eb;
  --primary-light:#1c2c4d;
  --sidebar-bg:  #070d18;
  --sidebar-text:#aeb9cc;
  --sidebar-muted:#5a6b86;
  --shadow:      0 1px 3px rgba(0,0,0,.4);
  --shadow-lg:   0 12px 32px rgba(0,0,0,.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Source Sans 3', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4 { font-family: 'Outfit', sans-serif; font-weight: 700; line-height: 1.2; }
a { color: var(--primary); text-decoration: none; }

/* ── Layout ── */
.app-layout { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: 252px; flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 40;
}
.sidebar-brand { padding: 1.25rem 1.25rem .75rem; display: flex; align-items: center; gap: .65rem; }
.brand-icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  font-size: 1.2rem;
}
.sidebar-brand h2 { color: #fff; font-size: 1.05rem; }
.sidebar-brand p  { color: var(--sidebar-muted); font-size: .7rem; margin-top: -2px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .5rem .75rem 1rem; }
.nav-section {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--sidebar-muted); font-weight: 700;
  padding: 1rem .75rem .35rem;
}
.nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .75rem; border-radius: 9px;
  color: var(--sidebar-text); font-size: .9rem; font-weight: 500;
  margin-bottom: 2px; transition: background .15s, color .15s;
}
.nav-item .ic { width: 18px; text-align: center; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item.disabled { color: var(--sidebar-muted); cursor: default; }
.nav-item.disabled:hover { background: transparent; color: var(--sidebar-muted); }
.nav-item .soon {
  margin-left: auto; font-size: .6rem; text-transform: uppercase;
  background: rgba(255,255,255,.08); color: var(--sidebar-muted);
  padding: .1rem .35rem; border-radius: 20px; letter-spacing: .03em;
}

.sidebar-user {
  display: flex; align-items: center; gap: .6rem;
  padding: .75rem 1rem; margin: 0 .75rem; border-radius: 10px;
  background: rgba(255,255,255,.04);
}
.sidebar-footer { padding: .75rem; border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-footer a {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .75rem; border-radius: 8px;
  color: var(--sidebar-muted); font-size: .85rem;
}
.sidebar-footer a:hover { background: rgba(255,255,255,.06); color: #fff; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .8rem;
}
.user-info strong { color: #fff; font-size: .85rem; display: block; }
.user-info span   { color: var(--sidebar-muted); font-size: .72rem; text-transform: capitalize; }

/* ── Main ── */
.main-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 1rem;
  padding: .85rem 1.5rem;
  background: var(--surface); /* fallback */
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.15rem; }
.topbar .subtitle { font-size: .8rem; color: var(--text-muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 1.05rem;
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }
#menuBtn { display: none; }

.page-body { padding: 1.5rem; flex: 1; }

/* ── Cards & grid ── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.25rem;
}
.grid { display: grid; gap: 1rem; }
.kpi-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.kpi { display: flex; flex-direction: column; gap: .35rem; }
.kpi .kpi-label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi .kpi-value { font-family: 'Outfit', sans-serif; font-size: 1.6rem; font-weight: 800; }
.kpi .kpi-foot  { font-size: .78rem; color: var(--text-muted); }
.kpi-value.pos { color: var(--success); }
.kpi-value.neg { color: var(--danger); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .6rem 1.1rem; border-radius: 9px; border: none; cursor: pointer;
  font-family: 'Outfit', sans-serif; font-weight: 600; font-size: .9rem;
  transition: all .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); }
.btn-sm { padding: .4rem .75rem; font-size: .82rem; }

/* ── Badges (semaforo) ── */
.badge { font-size: .72rem; font-weight: 700; padding: .15rem .55rem; border-radius: 20px; }
.badge.info     { background: var(--primary-light); color: var(--primary-d); }
.badge.atencion { background: #fef3c7; color: #92400e; }
.badge.critico  { background: #fee2e2; color: #991b1b; }

/* ── Empty state ── */
.empty {
  text-align: center; padding: 3rem 1rem; color: var(--text-muted);
  border: 1.5px dashed var(--border); border-radius: var(--radius);
}
.empty .em-icon { font-size: 2.5rem; margin-bottom: .5rem; }

/* ── Mobile sidebar ── */
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 39;
}
@media (max-width: 880px) {
  .sidebar {
    position: fixed; left: 0; top: 0; transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  #menuBtn { display: flex; }
}

/* ── Login ── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg);
  padding: 2.25rem 2rem;
}
.login-card .brand-icon { width: 52px; height: 52px; font-size: 1.6rem; margin: 0 auto 1rem; }
.login-card h1 { text-align: center; font-size: 1.4rem; margin-bottom: .25rem; }
.login-card .sub { text-align: center; color: var(--text-muted); font-size: .88rem; margin-bottom: 1.5rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .83rem; font-weight: 600; margin-bottom: .35rem; }
.input {
  width: 100%; padding: .7rem .9rem; border: 1.5px solid var(--border);
  border-radius: 9px; font-size: .95rem; background: var(--surface-2); color: var(--text);
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.alert { padding: .75rem 1rem; border-radius: 9px; font-size: .87rem; margin-bottom: 1rem; }
.alert-err  { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.alert-ok   { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
:root[data-theme="dark"] .alert-err { background: #2a1414; border-color: #5b2020; color: #fca5a5; }
:root[data-theme="dark"] .alert-ok  { background: #11251a; border-color: #1f5132; color: #86efac; }

/* ── Page heading row ── */
.page-head { display:flex; align-items:center; gap:1rem; margin-bottom:1.25rem; flex-wrap:wrap; }
.page-head h2 { font-size:1.15rem; }
.page-head .spacer { flex:1; }
.section-title { font-family:'Outfit',sans-serif; font-weight:700; font-size:1rem; margin:1.5rem 0 .75rem; }

/* ── Tables ── */
.table-wrap { overflow-x:auto; }
table.tbl { width:100%; border-collapse:collapse; font-size:.9rem; }
table.tbl th, table.tbl td { padding:.6rem .7rem; text-align:left; border-bottom:1px solid var(--border); white-space:nowrap; }
table.tbl th { font-size:.72rem; text-transform:uppercase; letter-spacing:.04em; color:var(--text-muted); font-weight:700; }
table.tbl tbody tr:hover { background:var(--surface-2); }
table.tbl td.num, table.tbl th.num { text-align:right; font-variant-numeric:tabular-nums; }
.pos { color:var(--success); } .neg { color:var(--danger); }
.muted { color:var(--text-muted); }

/* ── Forms ── */
.form-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:.9rem; }
.field { display:flex; flex-direction:column; gap:.3rem; }
.field label { font-size:.8rem; font-weight:600; }
.field .hint { font-size:.72rem; color:var(--text-muted); }
select.input, textarea.input { width:100%; padding:.6rem .85rem; border:1.5px solid var(--border); border-radius:9px; background:var(--surface-2); color:var(--text); font-size:.92rem; font-family:inherit; }
select.input:focus, textarea.input:focus { outline:none; border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-light); }
.form-actions { display:flex; gap:.6rem; margin-top:1rem; }

/* ── Modal (form colapsable) ── */
.collapse { display:none; }
.collapse.open { display:block; }

/* ── Progress ── */
.progress { background:var(--surface-2); border:1px solid var(--border); border-radius:20px; height:10px; overflow:hidden; }
.progress > span { display:block; height:100%; background:linear-gradient(90deg,var(--primary),var(--accent)); border-radius:20px; }
.progress.ok > span   { background:linear-gradient(90deg,var(--success),#34d399); }
.progress.warn > span { background:linear-gradient(90deg,var(--warning),#fbbf24); }
.progress.danger > span{ background:linear-gradient(90deg,var(--danger),#f87171); }

/* ── Pills / chips ── */
.pill { display:inline-block; font-size:.72rem; font-weight:700; padding:.12rem .55rem; border-radius:20px; background:var(--surface-2); border:1px solid var(--border); color:var(--text-muted); }
.pill.green { background:#dcfce7; color:#166534; border-color:#bbf7d0; }
.pill.red   { background:#fee2e2; color:#991b1b; border-color:#fecaca; }
.pill.blue  { background:var(--primary-light); color:var(--primary-d); border-color:transparent; }
:root[data-theme="dark"] .pill.green { background:#10241a; color:#86efac; border-color:#1f5132; }
:root[data-theme="dark"] .pill.red   { background:#2a1414; color:#fca5a5; border-color:#5b2020; }

/* ── Cards grid genérico ── */
.cards { display:grid; grid-template-columns:repeat(auto-fill,minmax(260px,1fr)); gap:1rem; }
.row-actions { display:flex; gap:.5rem; }
.row-actions a, .row-actions button { font-size:.8rem; padding:.25rem .5rem; }
.link-danger { color:var(--danger); background:none; border:none; cursor:pointer; font:inherit; }

/* ── Chat (asistente) ── */
.chat { display:flex; flex-direction:column; gap:.75rem; }
.chat .msg { max-width:75%; padding:.7rem .9rem; border-radius:12px; font-size:.9rem; line-height:1.5; white-space:pre-wrap; }
.chat .msg.user { align-self:flex-end; background:var(--primary); color:#fff; border-bottom-right-radius:3px; }
.chat .msg.ai   { align-self:flex-start; background:var(--surface-2); border:1px solid var(--border); border-bottom-left-radius:3px; }
