:root {
  --bg: #0f1420;
  --bg2: #171e2e;
  --card: #1c2536;
  --card2: #232e44;
  --line: #2c3852;
  --text: #e8edf6;
  --muted: #8b98b3;
  --accent: #4f8cff;
  --green: #34d399;
  --red: #f87171;
  --yellow: #fbbf24;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100vh;
}
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; background: var(--bg2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; width: 100%; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
label { font-size: 13px; color: var(--muted); display: block; margin: 10px 0 4px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 40px; width: min(360px, 90vw); text-align: center;
}
.login-logo { font-size: 48px; }
.login-card h1 { margin: 8px 0 4px; }
.login-card form { margin-top: 24px; display: flex; flex-direction: column; gap: 12px; }
.login-err { color: var(--red); font-size: 14px; min-height: 18px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px; flex-shrink: 0; background: var(--bg2);
  border-right: 1px solid var(--line); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 19px; font-weight: 700; padding: 4px 10px 16px; }
.nav-btn {
  background: none; border: none; color: var(--muted); text-align: left;
  padding: 10px 12px; border-radius: 8px; font-size: 15px;
}
.nav-btn:hover { background: var(--card); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; }
.quick-add { margin-top: 14px; }
.side-footer { margin-top: auto; padding: 10px; }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; }
.main { flex: 1; padding: 24px 28px; max-width: 1200px; }

/* ---------- cards / grid ---------- */
h2.view-title { font-size: 22px; margin-bottom: 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.kpi .k-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi .k-value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.pos { color: var(--green); } .neg { color: var(--red); }
.grid-2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; align-items: start; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.panel h3 { font-size: 15px; margin-bottom: 12px; color: var(--text); }
.panel .head-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel .head-row h3 { margin: 0; }

/* ---------- alerts ---------- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-size: 14px; }
.alert.warn { background: rgba(251,191,36,.12); border: 1px solid rgba(251,191,36,.4); color: var(--yellow); }
.alert.danger { background: rgba(248,113,113,.12); border: 1px solid rgba(248,113,113,.4); color: var(--red); }

/* ---------- charts ---------- */
.bar-row { display: grid; grid-template-columns: 110px 1fr 90px; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.bar-track { background: var(--bg2); border-radius: 6px; height: 16px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; min-width: 2px; }
.bar-amt { text-align: right; color: var(--muted); }
.trend-chart { display: flex; align-items: flex-end; gap: 14px; height: 140px; padding-top: 10px; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.trend-bar { width: 60%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.trend-bar.inc { background: var(--green); opacity: .85; }
.trend-pair { display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; flex: 1; }
.trend-label { font-size: 11px; color: var(--muted); }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tx-table .amount-pos { color: var(--green); }
.tx-table .amount-neg { color: var(--text); }
.empty { text-align: center; color: var(--muted); padding: 30px 0; font-size: 14px; }

/* ---------- pills / tags ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; margin: 1px 2px 1px 0; white-space: nowrap; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--muted); font-size: 13px; user-select: none;
}
.chip.selected { border-color: var(--accent); background: rgba(79,140,255,.15); color: var(--text); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.type-badge { font-size: 11px; padding: 2px 8px; border-radius: 6px; text-transform: uppercase; letter-spacing: .3px; }
.type-gasto { background: rgba(248,113,113,.15); color: var(--red); }
.type-ingreso { background: rgba(52,211,153,.15); color: var(--green); }
.type-retiro { background: rgba(251,191,36,.15); color: var(--yellow); }
.type-pago { background: rgba(79,140,255,.15); color: var(--accent); }
.type-ajuste { background: rgba(139,152,179,.15); color: var(--muted); }

/* ---------- accounts ---------- */
.acct-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.acct-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; position: relative; }
.acct-card h4 { font-size: 16px; margin-bottom: 2px; }
.acct-type { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.acct-bal { font-size: 26px; font-weight: 700; margin: 12px 0 4px; }
.acct-meta { font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.util-track { background: var(--bg2); height: 8px; border-radius: 4px; margin-top: 10px; overflow: hidden; }
.util-fill { height: 100%; border-radius: 4px; }
.acct-actions { position: absolute; top: 14px; right: 14px; display: flex; gap: 6px; }
.icon-btn { background: var(--bg2); border: 1px solid var(--line); color: var(--muted); border-radius: 6px; width: 28px; height: 28px; font-size: 13px; }
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--bg2); color: var(--text);
  padding: 9px 16px; border-radius: 8px; font-size: 14px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { background: rgba(248,113,113,.15); border-color: rgba(248,113,113,.4); color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,8,15,.7); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 24px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin-bottom: 6px; font-size: 18px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 22px; border-radius: 10px; z-index: 100; font-size: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

/* ---------- filters ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters select, .filters input { width: auto; min-width: 130px; }

/* ---------- plans ---------- */
.plan-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; }
.plan-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.plan-top h4 { font-size: 15px; }
.plan-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.plan-progress { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.progress-track { flex: 1; background: var(--bg2); height: 8px; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.progress-label { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- statement cards ---------- */
.stmt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.stmt-card { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; border-left-width: 4px; }
.stmt-card.st-open { border-left-color: var(--accent); }
.stmt-card.st-late { border-left-color: var(--red); }
.stmt-card.st-paid, .stmt-card.st-none { border-left-color: var(--green); }
.st-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; gap: 8px; }
.st-badge { font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.st-badge.st-open { background: rgba(79,140,255,.15); color: var(--accent); }
.st-badge.st-late { background: rgba(248,113,113,.18); color: var(--red); }
.st-badge.st-paid, .st-badge.st-none { background: rgba(52,211,153,.15); color: var(--green); }
.st-line { display: flex; justify-content: space-between; font-size: 13.5px; padding: 3px 0; }
.st-line .num { font-variant-numeric: tabular-nums; }
.st-total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 7px; font-weight: 700; }
.st-sub { font-size: 12px; color: var(--muted); margin: 0 0 4px 16px; }
.st-sub summary { cursor: pointer; font-size: 11px; color: var(--accent); }
.st-note { font-size: 11.5px; color: var(--muted); margin-top: 6px; font-style: italic; }
.st-next { font-size: 11.5px; color: var(--muted); margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.st-actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; }

/* ---------- upcoming ---------- */
.up-item { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; align-items: center; }
.up-item:last-child { border-bottom: none; }
.up-date { color: var(--muted); font-size: 12.5px; width: 76px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.up-amount { margin-left: auto; font-variant-numeric: tabular-nums; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { padding: 6px 10px; }
  nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .quick-add { margin: 0 0 0 auto; }
  .side-footer { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .main { padding: 16px; }
}
