:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --text: #1d2321;
  --muted: #6a736f;
  --border: #e1e4df;
  --primary: #1f5f4a;
  --primary-ink: #ffffff;
  --pos: #1c7a52;
  --neg: #b4432f;
  --pos-soft: #e3f2ea;
  --neg-soft: #f7e6e2;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131715; --surface: #1c2120; --text: #e8ebe9; --muted: #9aa3a0;
    --border: #2d3431; --primary: #5fb592; --primary-ink: #0f1412;
    --pos: #5fc49a; --neg: #ec8b77; --pos-soft: #1d3329; --neg-soft: #3a2420;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 1rem; }
small, .muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* Menú lateral */
body.con-menu { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1.25rem 1rem; }
.brand { font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--text); }
.sidebar-body { display: flex; flex-direction: column; flex: 1; padding: 0 .75rem 1rem; }
.sidebar nav { display: flex; flex-direction: column; gap: 1.25rem; flex: 1; }
.nav-group { display: flex; flex-direction: column; gap: .15rem; }
.nav-title { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 0 .75rem .35rem; }
.nav-group a {
  padding: .55rem .75rem; border-radius: 8px; text-decoration: none; color: var(--text);
  border-left: 3px solid transparent;
}
.nav-group a:hover { background: var(--bg); }
.nav-group a.active { background: var(--pos-soft); color: var(--primary); font-weight: 600; border-left-color: var(--primary); }
.logout { margin: 1rem 0 0; }
.btn-block { width: 100%; }
.menu-toggle { display: none; }
body.con-menu .container { width: 100%; max-width: 1200px; padding: 2rem 2rem 3rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem;
}
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + .card, .grid-2 + section { margin-top: 1.25rem; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.kpi span { display: block; color: var(--muted); font-size: .85rem; }
.kpi strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }

/* Formularios */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
input, select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; align-items: end; }
.span-2 { grid-column: span 2; }
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; margin-bottom: 1rem; }
.actions { display: flex; gap: .75rem; align-items: center; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: 0; }
.inline-form.grow { flex: 1; }
.inline-form.grow input { flex: 1; }

.btn {
  font: inherit; cursor: pointer; display: inline-block; text-decoration: none;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn-link { font: inherit; background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; text-decoration: underline; }
.danger { color: var(--neg); }

/* Alertas */
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-ok { background: var(--pos-soft); color: var(--pos); }
.alert-error { background: var(--neg-soft); color: var(--neg); }

/* Tablas y listas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-actions { display: flex; gap: .75rem; justify-content: flex-end; white-space: nowrap; }
.row-actions form { margin: 0; }
.tag { padding: .15rem .55rem; border-radius: 99px; font-size: .8rem; }
.tag-ingreso { background: var(--pos-soft); color: var(--pos); }
.tag-egreso { background: var(--neg-soft); color: var(--neg); }
.list { list-style: none; padding: 0; margin: 0 0 1rem; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.list li > div { display: flex; flex-direction: column; }
.summary { display: flex; flex-wrap: wrap; gap: 1.25rem; padding: .75rem 0; border-top: 1px solid var(--border); margin-bottom: .5rem; }
.pager { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: 1rem; }
.pager a { padding: .3rem .65rem; border: 1px solid var(--border); border-radius: 6px; text-decoration: none; }
.pager a.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

/* Chips de rango */
.chips { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip { padding: .35rem .8rem; border-radius: 99px; border: 1px solid var(--border); text-decoration: none; color: var(--text); font-size: .9rem; }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

/* Barras (progress, sin estilos inline para respetar la CSP) */
.bar-row { margin-bottom: .85rem; }
.bar-label { display: flex; justify-content: space-between; gap: 1rem; font-size: .9rem; margin-bottom: .25rem; }
progress.bar { appearance: none; -webkit-appearance: none; width: 100%; height: 10px; border: 0; border-radius: 99px; background: var(--bg); overflow: hidden; }
progress.bar::-webkit-progress-bar { background: var(--bg); border-radius: 99px; }
progress.bar.pos::-webkit-progress-value { background: var(--pos); border-radius: 99px; }
progress.bar.neg::-webkit-progress-value { background: var(--neg); border-radius: 99px; }
progress.bar.pos::-moz-progress-bar { background: var(--pos); border-radius: 99px; }
progress.bar.neg::-moz-progress-bar { background: var(--neg); border-radius: 99px; }
.mini-bars { min-width: 160px; }
.mini-bars progress { display: block; height: 7px; margin: 2px 0; }

.login { max-width: 380px; margin: 4rem auto; }
.login form { display: flex; flex-direction: column; gap: 1rem; }

@media (max-width: 860px) {
  body.con-menu { display: block; }
  body.con-menu .container { padding: 1.25rem 1rem 3rem; }
  .sidebar { position: sticky; height: auto; z-index: 10; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar-head { padding: .75rem 1rem; }
  .sidebar-body { display: none; padding: 0 .75rem 1rem; }
  .sidebar.open .sidebar-body { display: flex; max-height: calc(100vh - 56px); overflow-y: auto; }
  .menu-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); cursor: pointer;
  }
  .menu-icon, .menu-icon::before, .menu-icon::after {
    display: block; width: 18px; height: 2px; background: var(--text); border-radius: 2px; position: relative;
  }
  .menu-icon::before, .menu-icon::after { content: ""; position: absolute; left: 0; }
  .menu-icon::before { top: -6px; }
  .menu-icon::after { top: 6px; }
}
@media (max-width: 600px) {
  .span-2 { grid-column: auto; }
}
