:root {
  color-scheme: light;
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f8fafc; --border: #e4e7ec; --border-strong: #cfd5de;
  --text: #0f172a; --text-2: #475569; --muted: #64748b;
  --side: #0f172a; --side-2: #1e293b; --side-text: #cbd5e1; --side-active: #ffffff;
  --brand: #2563eb; --brand-ink: #ffffff; --brand-soft: #e8f0fe;
  --series-income: #2a78d6; --series-exp: #eb6834; --bar: #2a78d6; --bar-soft: #cde2fb;
  --good: #15803d; --good-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fdf3e2; --bad: #b91c1c; --bad-soft: #fdecec;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 1px rgba(15,23,42,.04);
  --radius: 12px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0f17; --surface: #131a24; --surface-2: #18212d; --border: #243042; --border-strong: #33425a;
    --text: #eef2f7; --text-2: #b8c2d0; --muted: #8a96a8;
    --side: #080c13; --side-2: #141c28; --side-text: #aab6c6;
    --brand: #3b82f6; --brand-soft: #172a4a;
    --series-income: #3987e5; --series-exp: #d95926; --bar: #3987e5; --bar-soft: #1c3557;
    --good: #4ade80; --good-soft: #10291a; --warn: #fbbf24; --warn-soft: #2d230d; --bad: #f87171; --bad-soft: #2e1414;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f17; --surface: #131a24; --surface-2: #18212d; --border: #243042; --border-strong: #33425a;
  --text: #eef2f7; --text-2: #b8c2d0; --muted: #8a96a8;
  --side: #080c13; --side-2: #141c28; --side-text: #aab6c6;
  --brand: #3b82f6; --brand-soft: #172a4a;
  --series-income: #3987e5; --series-exp: #d95926; --bar: #3987e5; --bar-soft: #1c3557;
  --good: #4ade80; --good-soft: #10291a; --warn: #fbbf24; --warn-soft: #2d230d; --bad: #f87171; --bad-soft: #2e1414;
  --shadow: none;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.num { font-variant-numeric: tabular-nums; }

/* íconos */
svg.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.btn svg.ico, .link svg.ico { width: 16px; height: 16px; }

/* login */
#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-brand { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.login-brand b { display: block; font-size: 18px; }
.login-brand small { color: var(--muted); }
.logo-dot { width: 34px; height: 34px; border-radius: 9px; background: var(--brand) url("favicon.svg") center/cover; flex: none; }

/* layout con menú lateral */
#layout { display: flex; min-height: 100vh; }
aside#side { width: 230px; flex: none; background: var(--side); color: var(--side-text); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.06); }
.brand b { color: #fff; display: block; font-size: 15px; }
.brand small { font-size: 11.5px; color: var(--side-text); opacity: .8; }
#menutoggle { display: none; margin-left: auto; color: #fff; }
nav#nav { display: flex; flex-direction: column; padding: 10px 8px; gap: 2px; flex: 1; overflow: auto; }
nav#nav button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; border-left: 3px solid transparent; color: var(--side-text); padding: 9px 10px; border-radius: 6px; cursor: pointer; font-weight: 500; }
nav#nav button:hover { background: var(--side-2); color: #fff; }
nav#nav button.active { background: var(--side-2); color: var(--side-active); border-left-color: var(--brand); }
nav#nav i { display: contents; }
.count { margin-left: auto; background: var(--series-exp); color: #fff; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; }
.count.muted { background: rgba(255,255,255,.12); color: var(--side-text); }
.side-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.06); display: grid; gap: 8px; font-size: 13px; }
.side-foot a, .side-foot .link { color: var(--side-text); text-decoration: none; display: flex; gap: 8px; align-items: center; background: none; border: 0; padding: 0; cursor: pointer; }
.side-foot a:hover, .side-foot .link:hover { color: #fff; }
.who { color: #fff; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { display: block; color: var(--side-text); font-weight: 400; white-space: normal; overflow-wrap: anywhere; }
main#main { flex: 1; min-width: 0; padding: 28px 32px 48px; max-width: 1280px; }
.footer-credit { margin-top: 40px; color: var(--muted); font-size: 12.5px; text-align: center; }
.footer-credit a { color: inherit; }

@media (max-width: 860px) {
  #layout { flex-direction: column; }
  aside#side { width: 100%; height: auto; position: sticky; z-index: 20; }
  #menutoggle { display: inline-flex; }
  nav#nav, .side-foot { display: none; }
  aside#side.open nav#nav, aside#side.open .side-foot { display: flex; }
  aside#side.open .side-foot { display: grid; }
  main#main { padding: 20px 16px 40px; }
}

/* encabezado de página */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; justify-content: space-between; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* controles */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 6px; cursor: pointer; color: var(--text-2); display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--bad); }
label { display: grid; gap: 5px; font-weight: 500; font-size: 13px; color: var(--text-2); }
input, select, textarea { background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: auto; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text); }
.err { color: var(--bad); margin: 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.month-nav { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 2px; }
.month-nav span { min-width: 130px; text-align: center; font-weight: 600; text-transform: capitalize; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters > * { width: auto; }
.filters input[type=search] { min-width: 220px; }

/* tarjetas */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.stat .label { color: var(--text-2); font-size: 13px; font-weight: 500; display: flex; gap: 6px; align-items: center; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.stat .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.delta { font-weight: 600; }
.delta.up { color: var(--bad); } .delta.down { color: var(--good); }
.profit.pos { color: var(--good); } .profit.neg { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; margin-bottom: 14px; }
.grid2 > .card { min-width: 0; }
@media (max-width: 1060px) { .grid2 { grid-template-columns: 1fr; } }
.card h2 { font-size: 15px; margin: 0 0 2px; }
.card .card-sub { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }
.banner { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; background: var(--warn-soft); color: var(--warn); font-weight: 500; }
.banner .btn { margin-left: auto; }
.banner.info { background: var(--brand-soft); color: var(--brand); }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }
.empty b { color: var(--text); display: block; margin-bottom: 4px; font-size: 15px; }

/* barras por categoría */
.catbars { display: grid; gap: 12px; }
.catbar .top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.catbar .top b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catbar .track { position: relative; height: 10px; background: var(--surface-2); border-radius: 4px; margin-top: 5px; }
.catbar .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.catbar .fill.over { background: var(--series-exp); }
.catbar .budget { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); opacity: .55; }
.catbar .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }

/* gráfica de tendencia */
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid line { stroke: var(--border); }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover { fill: var(--text); fill-opacity: .05; }
.tip { position: fixed; z-index: 100; pointer-events: none; background: var(--text); color: var(--surface); padding: 8px 10px; border-radius: 8px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(0,0,0,.18); max-width: 260px; }
.tip b { display: block; margin-bottom: 2px; text-transform: capitalize; }
.tip .row { display: flex; gap: 14px; justify-content: space-between; }

/* listas / tablas */
.list { display: grid; }
.list .item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list .item:last-child { border-bottom: 0; }
.list .when { width: 46px; text-align: center; flex: none; line-height: 1.1; }
.list .when b { display: block; font-size: 17px; }
.list .when small { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.list .what { flex: 1; min-width: 0; }
.list .what b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .what small { color: var(--muted); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.amt, th.amt { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td .sub { display: block; color: var(--muted); font-size: 12px; }
td.act { white-space: nowrap; text-align: right; width: 1%; }
tfoot td { font-weight: 600; background: var(--surface-2); }
tr.inactive td { opacity: .5; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill.pagado { background: var(--good-soft); color: var(--good); }
.pill.pendiente { background: var(--warn-soft); color: var(--warn); }
.pill.vencido { background: var(--bad-soft); color: var(--bad); }
.pill.estimado, .pill.programado { background: var(--brand-soft); color: var(--brand); }
.pill.src { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.pill svg.ico { width: 12px; height: 12px; }

/* formularios en modal */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-card h2 { margin: 0 0 16px; font-size: 18px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
@media (max-width: 560px) { .form { grid-template-columns: 1fr; } }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; z-index: 60; font-weight: 500; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--bad); color: #fff; }

.steps { display: grid; gap: 14px; }
.mapgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 12px 0; }
.sample td { font-size: 12.5px; color: var(--text-2); white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.preview td select { min-width: 160px; padding: 5px 8px; }
.preview td input[type=text] { min-width: 130px; padding: 5px 8px; }
tr.skip td { opacity: .5; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.settings-grid .card { display: grid; gap: 12px; align-content: start; }
.status-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--good); } .dot.no { background: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; padding: 3px 4px 3px 10px; font-size: 13px; }
.chip .icon-btn { padding: 2px; }
