:root {
  --bg: #f6f7f9; --surface: #fff; --border: #e3e6eb; --text: #1d2330; --muted: #677085;
  --accent: #2f6fde; --accent-soft: #e8f0fd; --income: #1e9a5b; --expense: #d2463c;
  --warn-bg: #fff6e0; --warn: #8a5a00; --ok-bg: #e6f6ed; --err-bg: #fdeceb;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --surface: #1b2029; --border: #2b323f; --text: #e6e9ef; --muted: #98a1b3;
    --accent: #6c9cf0; --accent-soft: #1f2b42; --income: #4cc788; --expense: #f07a70;
    --warn-bg: #3a2f14; --warn: #f2c66b; --ok-bg: #173226; --err-bg: #3b1d1b;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.top { background: var(--surface); border-bottom: 1px solid var(--border); }
header.top .inner { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center;
                    gap: 24px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); }
nav.main { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav.main a { padding: 6px 10px; border-radius: 6px; color: var(--muted); }
nav.main a.active, nav.main a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.user { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; }

main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.two { grid-template-columns: 2fr 1fr; }
.half { grid-template-columns: 1fr 1fr; }
@media (max-width: 860px) { .two, .half { grid-template-columns: 1fr; } }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 12px; color: var(--muted); }
.stack > * + * { margin-top: 16px; }

.pos { color: var(--income); }
.neg { color: var(--expense); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--accent-soft); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; border: 1px solid var(--border); color: var(--muted); }
.badge.pendiente { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.revisado, .badge.enlazada { background: var(--ok-bg); color: var(--income); border-color: transparent; }

input, select, textarea, button {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px;
}
textarea { width: 100%; min-height: 70px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field input, .field select { width: 100%; }
button, .btn { cursor: pointer; display: inline-block; padding: 6px 14px; border-radius: 6px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); text-decoration: none; }
.btn-danger { color: var(--expense); }
.btn-link { border: 0; background: none; color: var(--accent); padding: 0; }
form.inline { display: inline; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash.ok { background: var(--ok-bg); }
.flash.error { background: var(--err-bg); }
.alert { background: var(--warn-bg); color: var(--warn); padding: 10px 14px; border-radius: 8px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.bulk { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border);
        padding: 10px 0; margin-top: 8px; }
.bar { height: 6px; background: var(--accent-soft); border-radius: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--expense); }
.chart-box { position: relative; height: 280px; }

.login { max-width: 360px; margin: 10vh auto; }
pre.raw { white-space: pre-wrap; font-size: 12px; max-height: 260px; overflow: auto; background: var(--bg);
          padding: 10px; border-radius: 6px; }
