/* ============================================================
   MI FINANZAS · Estilos
   Paleta: fondo gris claro · paneles blancos · navy navegación
   turquesa positivo · naranja advertencia · rojo exceso
   ============================================================ */
:root{
  --bg:#f3f5f9;
  --panel:#ffffff;
  --navy:#0f172a;
  --navy-2:#1e293b;
  --ink:#1e293b;
  --muted:#64748b;
  --line:#e7ebf1;
  --brand:#2563eb;
  --pos:#0ea5a4;
  --neg:#ef4444;
  --warn:#f59e0b;
  --high:#f97316;
  --exc:#ef4444;
  --radius:16px;
  --shadow:0 1px 2px rgba(16,24,40,.04),0 4px 16px rgba(16,24,40,.06);
  --font:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
}
*{box-sizing:border-box;margin:0;padding:0}
html,body{background:var(--bg);color:var(--ink);font-family:var(--font);-webkit-font-smoothing:antialiased;font-size:15px;line-height:1.5}
a{color:inherit;text-decoration:none}
.muted{color:var(--muted)}
.small{font-size:.82rem}
.pos{color:var(--pos)}
.neg{color:var(--neg)}
.link{color:var(--brand);font-weight:600;font-size:.9rem}

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

.sidebar{
  width:248px;flex-shrink:0;background:var(--navy);color:#cbd5e1;
  display:flex;flex-direction:column;position:sticky;top:0;height:100vh;padding:22px 16px;
}
.sidebar-brand{font-size:1.15rem;font-weight:700;color:#fff;padding:6px 10px 20px;display:flex;gap:8px;align-items:center}
.sidebar-nav{display:flex;flex-direction:column;gap:4px;flex:1}
.sidebar-nav a{display:flex;align-items:center;gap:12px;padding:11px 14px;border-radius:11px;color:#cbd5e1;font-weight:500;transition:.15s}
.sidebar-nav a:hover{background:var(--navy-2);color:#fff}
.sidebar-nav a.is-active{background:var(--brand);color:#fff}
.nav-ico{font-size:1.05rem;width:22px;text-align:center}
.sidebar-foot{border-top:1px solid #334155;padding-top:14px;display:flex;align-items:center;justify-content:space-between}
.user-chip{font-size:.85rem;color:#e2e8f0;font-weight:600}
.logout{font-size:.82rem;color:#94a3b8}
.logout:hover{color:#fff}

.content{flex:1;min-width:0;padding:24px 28px 40px;max-width:1120px;margin:0 auto;width:100%}
.topbar{display:flex;align-items:center;justify-content:space-between;margin-bottom:18px}
.topbar h1{font-size:1.5rem;font-weight:700}
.period-label{color:var(--muted);font-weight:600;margin:-6px 0 14px;text-transform:capitalize}

/* ---------- Cards ---------- */
.card{background:var(--panel);border:1px solid var(--line);border-radius:var(--radius);box-shadow:var(--shadow);padding:20px;margin-bottom:18px}
.card-title{font-size:1rem;font-weight:700;margin-bottom:14px}
.card-title-row{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px}
.card-title-row .card-title{margin-bottom:0}
.two-col{display:grid;grid-template-columns:1.3fr 1fr;gap:18px}

/* ---------- KPIs ---------- */
.kpi-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:14px;margin-bottom:18px}
.kpi{background:var(--panel);border:1px solid var(--line);border-radius:var(--radius);box-shadow:var(--shadow);padding:16px 18px;display:flex;flex-direction:column;gap:6px}
.kpi-label{font-size:.8rem;color:var(--muted);font-weight:600}
.kpi-value{font-size:1.5rem;font-weight:700;letter-spacing:-.02em}
.kpi-sub{font-size:.76rem;margin-top:2px}
.acc-bal small{display:block;font-weight:500;font-size:.74rem;margin-top:1px}

/* ---------- Alerts ---------- */
.alert{border-radius:12px;padding:12px 14px;font-size:.9rem}
.alert-ok{background:#ecfdf5;color:#065f46;border:1px solid #a7f3d0}
.alert-preventivo{background:#fffbeb;color:#92400e;border:1px solid #fde68a}
.alert-alto{background:#fff7ed;color:#9a3412;border:1px solid #fed7aa}
.alert-excedido{background:#fef2f2;color:#991b1b;border:1px solid #fecaca}
.alert-list{display:flex;flex-direction:column;gap:10px}
.alert-head{display:flex;justify-content:space-between;font-weight:700;margin-bottom:2px}
.alert-msg{font-size:.86rem;opacity:.9}
.empty-inline{color:var(--muted);text-align:center;padding:18px;font-size:.92rem}

/* ---------- Stat list ---------- */
.stat-list{list-style:none;display:flex;flex-direction:column;gap:12px;margin-bottom:10px}
.stat-list li{display:flex;justify-content:space-between;align-items:center;font-size:.92rem}
.stat-list strong{font-weight:700}

/* ---------- Budgets / bars ---------- */
.budget-list{display:flex;flex-direction:column;gap:16px}
.budget-row{display:flex;flex-direction:column;gap:7px}
.budget-info{display:flex;align-items:center;gap:8px;font-size:.9rem}
.budget-name{font-weight:600;flex:1}
.budget-nums{color:var(--muted);font-size:.84rem}
.dot{width:10px;height:10px;border-radius:50%;flex-shrink:0}
.bar{background:#eef1f6;border-radius:999px;height:9px;overflow:hidden}
.bar-lg{height:13px}
.bar-fill{height:100%;border-radius:999px;transition:width .4s ease}
.bar-fill.level-ok{background:var(--pos)}
.bar-fill.level-preventivo{background:var(--warn)}
.bar-fill.level-alto{background:var(--high)}
.bar-fill.level-excedido{background:var(--exc)}
.budget-row-lg{gap:9px}
.budget-detail{display:flex;justify-content:space-between;font-size:.84rem}
.badge{font-size:.72rem;font-weight:700;padding:2px 9px;border-radius:999px;text-transform:uppercase;letter-spacing:.02em}
.badge-ok{background:#d1fae5;color:#065f46}
.badge-preventivo{background:#fef3c7;color:#92400e}
.badge-alto{background:#ffedd5;color:#9a3412}
.badge-excedido{background:#fee2e2;color:#991b1b}
.budget-global{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}
.budget-global-pct{font-size:1.6rem;font-weight:800}
.level-ok{color:var(--pos)}.level-preventivo{color:var(--warn)}.level-alto{color:var(--high)}.level-excedido{color:var(--exc)}

/* ---------- Transactions ---------- */
.tx-list{display:flex;flex-direction:column}
.tx-row{display:flex;align-items:center;gap:12px;padding:11px 0;border-bottom:1px solid var(--line)}
.tx-row:last-child{border-bottom:0}
.tx-ico{width:34px;height:34px;border-radius:10px;display:flex;align-items:center;justify-content:center;font-size:1rem;flex-shrink:0}
.tx-ingreso{background:#ecfdf5;color:var(--pos)}
.tx-gasto{background:#fef2f2;color:var(--neg)}
.tx-transferencia{background:#eef2ff;color:var(--brand)}
.tx-main{flex:1;min-width:0;display:flex;flex-direction:column}
.tx-desc{font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.tx-meta{font-size:.78rem;color:var(--muted)}
.tx-amount{font-weight:700;white-space:nowrap}
.tx-actions{display:flex;gap:4px;align-items:center}
.tx-row-actions{gap:10px}
.icon-btn{background:none;border:0;cursor:pointer;font-size:.95rem;color:var(--muted);padding:6px;border-radius:8px;line-height:1}
.icon-btn:hover{background:#f1f5f9;color:var(--ink)}
.icon-btn.danger:hover{background:#fef2f2;color:var(--neg)}
.tx-actions form{display:inline}

/* ---------- Accounts / categories rows ---------- */
.acc-list,.cat-list{display:flex;flex-direction:column}
.acc-row,.cat-row{display:flex;align-items:center;gap:12px;padding:12px 0;border-bottom:1px solid var(--line)}
.acc-row:last-child,.cat-row:last-child{border-bottom:0}
.acc-info{flex:1;display:flex;flex-direction:column}
.acc-name,.cat-name{font-weight:600}
.acc-type{font-size:.78rem;color:var(--muted)}
.acc-bal{font-weight:700}
.cat-name{flex:1}
.cat-budget{color:var(--muted);font-size:.84rem}
.is-inactive{opacity:.45}

/* ---------- Forms ---------- */
.form{display:flex;flex-direction:column;gap:14px}
.form label{display:flex;flex-direction:column;gap:6px;font-size:.85rem;font-weight:600;color:#334155}
.form input,.form select{font:inherit;padding:11px 12px;border:1px solid #d7dde7;border-radius:10px;background:#fff;color:var(--ink);width:100%}
.form input:focus,.form select:focus{outline:none;border-color:var(--brand);box-shadow:0 0 0 3px rgba(37,99,235,.12)}
.form input[type=color]{height:44px;padding:4px;cursor:pointer}
.form-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px}
.form-grid .full{grid-column:1/-1}
.form-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:4px}
.form-card{max-width:620px}
.filter-row{display:flex;align-items:center;gap:16px;flex-wrap:wrap}
.filter-row label{flex-direction:row;align-items:center;gap:8px}
.filter-row input{width:auto}

/* type switch */
.type-switch{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.type-opt{cursor:pointer;border:1.5px solid #d7dde7;border-radius:11px;padding:11px;text-align:center;font-weight:600;font-size:.88rem;transition:.15s;flex-direction:row!important;justify-content:center}
.type-opt input{display:none}
.type-opt span{display:block}
.type-opt:has(input:checked).type-gasto{border-color:var(--neg);background:#fef2f2;color:var(--neg)}
.type-opt:has(input:checked).type-ingreso{border-color:var(--pos);background:#ecfdf5;color:var(--pos)}
.type-opt:has(input:checked).type-transferencia{border-color:var(--brand);background:#eef2ff;color:var(--brand)}

/* ---------- Buttons ---------- */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;font:inherit;font-weight:600;padding:11px 18px;border-radius:11px;border:0;cursor:pointer;transition:.15s}
.btn-primary{background:var(--brand);color:#fff}
.btn-primary:hover{background:#1d4ed8}
.btn-ghost{background:#f1f5f9;color:#475569}
.btn-ghost:hover{background:#e2e8f0}
.btn-block{width:100%}
.btn-sm{padding:8px 14px;font-size:.88rem}

/* ---------- Auth ---------- */
.auth-body{display:flex;align-items:center;justify-content:center;min-height:100vh;padding:20px;background:linear-gradient(160deg,#0f172a,#1e293b)}
.auth-card{background:#fff;border-radius:20px;padding:32px;width:100%;max-width:400px;box-shadow:0 20px 50px rgba(0,0,0,.3)}
.auth-brand{font-size:1.2rem;font-weight:700;margin-bottom:18px}
.auth-card h1{font-size:1.5rem;margin-bottom:4px}
.auth-card .muted{margin-bottom:18px}
.auth-card .alert{margin-bottom:14px}
.auth-card code{background:#f1f5f9;padding:2px 6px;border-radius:5px;font-size:.85em}

/* ---------- Mobile nav / FAB ---------- */
.mobile-nav{display:none}
.fab{display:none}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media(max-width:860px){
  .two-col{grid-template-columns:1fr}
  .kpi-grid{grid-template-columns:1fr 1fr}
}
@media(max-width:720px){
  .sidebar{display:none}
  .content{padding:16px 14px 90px;max-width:100%}
  .topbar h1{font-size:1.3rem}
  .topbar-add{display:none}
  .form-grid{grid-template-columns:1fr}
  .type-switch{grid-template-columns:1fr}
  .type-opt{flex-direction:row!important}

  /* barra inferior */
  .mobile-nav{
    display:flex;position:fixed;bottom:0;left:0;right:0;z-index:50;
    background:#fff;border-top:1px solid var(--line);
    padding:6px 4px calc(6px + env(safe-area-inset-bottom));
    justify-content:space-around;box-shadow:0 -2px 12px rgba(16,24,40,.06);
  }
  .mobile-nav a{display:flex;flex-direction:column;align-items:center;gap:2px;font-size:.66rem;color:var(--muted);padding:4px 6px;flex:1;font-weight:600}
  .mobile-nav a .nav-ico{font-size:1.2rem}
  .mobile-nav a.is-active{color:var(--brand)}

  /* botón flotante */
  .fab{
    display:flex;align-items:center;justify-content:center;
    position:fixed;right:18px;bottom:76px;z-index:51;
    width:56px;height:56px;border-radius:50%;background:var(--brand);color:#fff;
    font-size:1.8rem;font-weight:300;box-shadow:0 6px 18px rgba(37,99,235,.45);
  }
}
@media(max-width:420px){
  .kpi-value{font-size:1.3rem}
}
