/* ============================================================
   SELBA FINCONTROL — tokens de identidad visual.
   Sustituir aquí la paleta y tipografía oficiales de SELBA I.D.E.A.
   (es el único sitio donde se definen colores y fuentes).
   ============================================================ */
:root {
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: "Inter", "Segoe UI", system-ui, sans-serif;

  --bg: #f4f3ef;          /* fondo general */
  --surface: #ffffff;     /* tarjetas */
  --surface-2: #faf9f6;   /* filas alternas, zonas secundarias */
  --line: #e3e1da;
  --line-strong: #cfccc2;
  --ink: #16212e;         /* texto principal */
  --ink-2: #4a5462;       /* texto secundario */
  --ink-3: #8a909a;       /* texto terciario */

  --brand: #13324f;       /* color principal de marca */
  --brand-ink: #ffffff;
  --accent: #1d6f6a;      /* acción principal */
  --accent-soft: #e2efed;

  --income: #1e7a4c;
  --income-soft: #e6f2ea;
  --expense: #b3412f;
  --expense-soft: #f7e8e4;
  --warn: #a8690c;
  --warn-soft: #fbf0dc;
  --pending: #6b5fb5;
  --pending-soft: #ecebf7;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgb(22 33 46 / 6%), 0 4px 16px rgb(22 33 46 / 5%);
  --shadow-lg: 0 12px 40px rgb(22 33 46 / 18%);

  --sidebar-w: 236px;
  --bottombar-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-sans); font-size: 15px; line-height: 1.45; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
a { color: var(--accent); }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.income { color: var(--income); }
.expense { color: var(--expense); }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.stack-sm > * + * { margin-top: 6px; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Layout ---------- */
.shell { min-height: 100%; display: flex; }
.sidebar {
  width: var(--sidebar-w); background: var(--brand); color: var(--brand-ink); position: fixed; inset: 0 auto 0 0;
  display: flex; flex-direction: column; padding: 18px 12px; overflow-y: auto; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: rgb(255 255 255 / 12%); display: grid; place-items: center; font-weight: 800; letter-spacing: .02em; font-size: 13px; }
.brand-name { font-weight: 750; letter-spacing: .06em; font-size: 13px; line-height: 1.1; }
.brand-sub { font-size: 11px; opacity: .65; letter-spacing: .04em; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .5; padding: 14px 10px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: inherit; text-decoration: none;
  opacity: .82; font-size: 14px;
}
.nav-link:hover { background: rgb(255 255 255 / 8%); opacity: 1; }
.nav-link.active { background: rgb(255 255 255 / 14%); opacity: 1; font-weight: 600; }
.nav-link svg { width: 18px; height: 18px; flex: none; }
.nav-badge { margin-left: auto; background: var(--warn); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.sidebar .add-btn { margin: 4px 4px 10px; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; font-size: 12px; opacity: .7; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); padding: 12px 28px; display: flex; align-items: center; gap: 12px; min-height: 60px;
}
.topbar h1 { font-size: 18px; }
.content { padding: 22px 28px 48px; max-width: 1500px; }
.offline-pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }

.bottombar { display: none; }
.fab { display: none; }

@media (max-width: 1100px) and (min-width: 721px) {
  :root { --sidebar-w: 76px; }
  .sidebar .nav-text, .sidebar .nav-group, .brand-txt, .sidebar-foot, .sidebar .add-btn .lbl { display: none; }
  .nav-link { justify-content: center; padding: 10px; position: relative; }
  .nav-badge { position: absolute; top: 2px; right: 2px; }
  .brand { justify-content: center; padding-inline: 0; }
}
@media (max-width: 720px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding-bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom)); }
  .topbar { padding: 10px 16px; min-height: 54px; }
  .content { padding: 14px 14px 32px; }
  .bottombar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; z-index: 30;
    height: calc(var(--bottombar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .bottombar a, .bottombar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px;
    color: var(--ink-2); text-decoration: none; background: none; border: 0; position: relative;
  }
  .bottombar .active { color: var(--brand); font-weight: 650; }
  .bottombar svg { width: 22px; height: 22px; }
  .bottombar .plus { width: 50px; height: 50px; border-radius: 16px; background: var(--accent); color: #fff; display: grid; place-items: center; margin-top: -18px; box-shadow: var(--shadow-lg); }
  .bottombar .plus svg { width: 26px; height: 26px; }
  .hide-mobile { display: none !important; }
}
@media (min-width: 721px) { .only-mobile { display: none !important; } }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.section-title { display: flex; align-items: center; gap: 10px; margin: 26px 0 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); padding: 8px 14px; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--expense); }
.btn.danger.solid { background: var(--expense); border-color: var(--expense); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgb(0 0 0 / 5%); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 7px; }
.btn.block { width: 100%; }
.add-btn { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 10px 12px; font-weight: 650; display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; }
.add-btn svg { width: 18px; height: 18px; }

.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--brand); color: #fff; }
.seg.income-expense button.on.inc { background: var(--income); }
.seg.income-expense button.on.exp { background: var(--expense); }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label, .label { font-size: 12px; font-weight: 650; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); padding: 9px 11px; min-height: 40px;
}
.input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; border-color: var(--accent); }
textarea.input { min-height: 70px; resize: vertical; }
.amount-input { font-size: 28px; font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 900px) { .cols2 { grid-template-columns: 1fr; } }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 720px) { .grid3 { grid-template-columns: 1fr; } }
.hint { font-size: 12px; color: var(--ink-3); }
.error-box { background: var(--expense-soft); color: var(--expense); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.warn-box { background: var(--warn-soft); color: #6d4506; border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.info-box { background: var(--accent-soft); color: #134a46; border-radius: 8px; padding: 10px 12px; font-size: 14px; }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 650; border-radius: 99px; padding: 2px 9px; white-space: nowrap; }
.chip.pending { background: var(--pending-soft); color: var(--pending); }
.chip.collected, .chip.paid { background: var(--income-soft); color: var(--income); }
.chip.void { background: var(--surface-2); color: var(--ink-3); text-decoration: line-through; }
.chip.premium { background: #f3ead2; color: #7a5a12; }
.chip.neutral { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }

.empty { text-align: center; padding: 40px 16px; color: var(--ink-2); }
.empty svg { width: 36px; height: 36px; opacity: .4; }

/* ---------- KPIs ---------- */
/* El saldo disponible va primero y destacado; el resto, más compacto. */
.kpis { display: grid; grid-template-columns: minmax(240px, 1.5fr) repeat(4, minmax(0, 1fr)); gap: 12px; align-items: stretch; }
.kpi { padding: 12px 14px; }
.kpi .k-label { font-size: 11px; font-weight: 650; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: 6px; }
.kpi .k-label svg { width: 14px; height: 14px; }
.kpi .k-value { font-size: 18px; font-weight: 700; margin-top: 5px; letter-spacing: -0.01em; }
.kpi .k-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.kpi .k-accounts { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; }
.kpi .k-accounts div { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); gap: 8px; }
.kpi .dot { width: 8px; height: 8px; border-radius: 50%; }
.kpi-main { padding: 16px 18px; border-color: color-mix(in srgb, var(--brand) 25%, var(--line)); box-shadow: inset 3px 0 0 var(--brand), var(--shadow); }
.kpi-main .k-label { font-size: 12px; color: var(--brand); }
.kpi-main .k-value { font-size: 30px; margin-top: 6px; }
.kpi-main .k-sub { font-size: 12px; }
@media (max-width: 1250px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpi-main { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi .k-value { font-size: 16px; }
  .kpi-main { padding: 14px 16px; }
  .kpi-main .k-value { font-size: 26px; }
}

/* ---------- Matriz ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.matrix-wrap { overflow: auto; max-height: calc(100vh - 180px); border-radius: var(--radius); }
table.matrix { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; }
.matrix th, .matrix td { padding: 7px 7px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.matrix thead th { position: sticky; top: 0; background: var(--surface); z-index: 3; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); font-weight: 650; }
.matrix .sticky { position: sticky; left: 0; background: inherit; z-index: 2; text-align: left; min-width: 170px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--line); }
.matrix thead .sticky { z-index: 4; background: var(--surface); }
.matrix tr { background: var(--surface); }
.matrix .total-col { background: var(--surface-2); font-weight: 650; border-left: 1px solid var(--line); position: sticky; right: 0; z-index: 2; }
.matrix thead .total-col { z-index: 4; }
.matrix .block-head td { background: var(--surface-2); font-weight: 750; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; padding-top: 12px; }
.matrix .block-head.inc td:first-child { box-shadow: inset 3px 0 0 var(--income); color: var(--income); }
.matrix .block-head.exp td:first-child { box-shadow: inset 3px 0 0 var(--expense); color: var(--expense); }
.matrix .cat-row td { font-weight: 600; cursor: pointer; }
.matrix .cat-row:hover td { background: var(--surface-2); }
.matrix .cat-row .chev { display: inline-block; width: 14px; height: 14px; vertical-align: -2px; margin-right: 4px; transition: transform .15s; color: var(--ink-3); }
.matrix .cat-row .chev svg { width: 14px; height: 14px; display: block; }
.matrix .cat-row.open .chev { transform: rotate(90deg); }
.matrix .con-row td { color: var(--ink-2); }
.matrix .con-row td.sticky { padding-left: 32px; font-weight: 400; }
.matrix .con-row td.cell { cursor: pointer; }
.matrix .con-row td.cell:hover { background: var(--accent-soft); color: var(--ink); }
.matrix .zero { color: var(--line-strong); }
.matrix .sum-row td { font-weight: 700; background: var(--surface-2); border-bottom: 2px solid var(--line-strong); }
.matrix .bal-row td { font-weight: 750; background: #eef1f4; font-size: 14px; border-bottom: 0; }
.matrix td.current-month { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.matrix th.current-month { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.matrix .forecast-mark { color: var(--pending); }
.matrix td.neg { color: var(--expense); }
.matrix td.pos { color: var(--income); }

/* ---------- Listas ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--line); cursor: pointer; background: var(--surface); }
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); }
.mv-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.mv-icon.inc { background: var(--income-soft); color: var(--income); }
.mv-icon.exp { background: var(--expense-soft); color: var(--expense); }
.mv-icon.trf { background: var(--accent-soft); color: var(--accent); }
.mv-icon svg { width: 18px; height: 18px; }
.mv-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-meta { font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-amount { font-weight: 700; text-align: right; }
.group-label { padding: 8px 16px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); background: var(--surface-2); border-bottom: 1px solid var(--line); }

.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; }
.progress.near > div { background: var(--warn); }
.progress.over > div { background: var(--expense); }

/* ---------- Hojas modales ---------- */
.overlay { position: fixed; inset: 0; background: rgb(15 22 31 / 45%); z-index: 50; display: flex; justify-content: flex-end; animation: fade .15s; }
.sheet { background: var(--surface); width: min(520px, 100%); height: 100%; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slidein .2s ease-out; }
.sheet-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.sheet-body { padding: 18px; overflow-y: auto; flex: 1; }
.sheet-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; background: var(--surface-2); padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.overlay.center { justify-content: center; align-items: center; padding: 16px; }
.dialog { background: var(--surface); border-radius: 14px; width: min(440px, 100%); box-shadow: var(--shadow-lg); animation: pop .15s; }
@media (max-width: 720px) {
  .overlay { align-items: flex-end; }
  .sheet { height: auto; max-height: 94vh; border-radius: 16px 16px 0 0; animation: slideup .2s ease-out; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }

.toast-wrap { position: fixed; z-index: 80; left: 50%; transform: translateX(-50%); bottom: 24px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
@media (max-width: 720px) { .toast-wrap { bottom: calc(var(--bottombar-h) + 16px); } }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow-lg); max-width: 90vw; }
.toast.err { background: var(--expense); }

.detail-grid { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; font-size: 14px; }
.detail-grid dt { color: var(--ink-3); }
.detail-grid dd { margin: 0; }

/* Categorías */
.cat-card { margin-bottom: 10px; }
.cat-line { display: flex; align-items: center; gap: 8px; padding: 9px 12px; }
.cat-line.cat { font-weight: 650; border-bottom: 1px solid var(--line); }
.cat-line.con { padding-left: 34px; border-bottom: 1px dashed var(--line); font-size: 14px; }
.cat-line.con:last-child { border-bottom: 0; }
.drag { cursor: grab; color: var(--ink-3); display: grid; place-items: center; }
.drag svg { width: 16px; height: 16px; }
.dragging { opacity: .4; }
.drop-target { box-shadow: inset 0 2px 0 var(--accent); }
.inline-edit { border: 1px solid transparent; background: transparent; padding: 3px 6px; border-radius: 6px; min-width: 0; flex: 1; font-weight: inherit; }
.inline-edit:hover { border-color: var(--line); }
.inline-edit:focus { border-color: var(--accent); outline: none; background: #fff; }

/* Onboarding */
.onb { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; background: linear-gradient(160deg, var(--brand) 0 38%, var(--bg) 38%); }
.onb-card { width: min(560px, 100%); padding: 28px; }
.onb-steps { display: flex; gap: 6px; margin: 14px 0 22px; }
.onb-steps span { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.onb-steps span.on { background: var(--accent); }
.choice { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.choice button { text-align: left; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 10px; padding: 12px; cursor: pointer; font-weight: 600; }
.choice button.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }

/* Gráficos */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--ink-3); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

details.faq { border-bottom: 1px solid var(--line); padding: 12px 18px; }
details.faq summary { cursor: pointer; font-weight: 600; }
details.faq p { color: var(--ink-2); margin: 8px 0 0; }

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th, table.simple td { padding: 9px 14px; border-bottom: 1px solid var(--line); text-align: right; }
table.simple th:first-child, table.simple td:first-child { text-align: left; }
table.simple thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); background: var(--surface-2); }
table.simple tfoot td { font-weight: 700; background: var(--surface-2); }

@media print {
  .sidebar, .bottombar, .topbar .btn, .no-print, .toolbar { display: none !important; }
  .main { margin: 0; }
  .card { box-shadow: none; }
  body { background: #fff; }
}

.boot { min-height: 100vh; display: grid; place-items: center; padding: 24px; color: var(--ink-2); }
.linklike { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font-size: 12px; margin-top: 4px; opacity: .9; }
.legal h3 { margin: 18px 0 6px; }
.legal p { margin: 0; color: var(--ink-2); font-size: 14px; }

.app-footer { display: flex; justify-content: center; padding: 8px 16px 28px; }
.onb .app-footer { padding-top: 18px; }
@media print { .app-footer { display: none; } }

.sync-pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); font-weight: 600; text-decoration: none; white-space: nowrap; border: 1px solid var(--line); }
.sync-pill.ok { color: var(--income); background: var(--income-soft); border-color: transparent; }
.sync-pill.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.sync-pill.err { color: var(--expense); background: var(--expense-soft); border-color: transparent; }
@media (max-width: 720px) { .sync-pill { font-size: 11px; padding: 2px 8px; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; } }
