/* Boyito Control · sistema visual
   Tinta azul para la estructura, papel frío para el contenido y un único verde "billete" para la acción.
   Jerarquía de radios: 22 cabecera del panel · 14 tarjetas · 10 controles · 4 marcas de datos. */
:root {
  color-scheme: light;
  --page: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f6f7fa;
  --ink: #16233b;
  --ink-2: #4a5670;
  --muted: #5d697f;
  --line: #e3e7ee;
  --axis: #c9d0dc;
  --brand: #0b7060;
  --brand-ink: #ffffff;
  --brand-soft: #e0f2ee;
  --good: #0a6b3d;
  --warn: #8f5d00;
  --critical: #c0302d;
  --track: #e8ebf1;
  --side-bg: #16233b;
  --side-ink: #eef1f6;
  --side-muted: #94a1b9;
  --side-hover: rgba(255, 255, 255, .07);
  --side-active: rgba(255, 255, 255, .13);
  --hero-bg: linear-gradient(120deg, #16233b 0%, #1b3a5c 55%, #134a5c 100%);
  --hero-ink: #ffffff;
  --hero-muted: #c6cfdf;
  --hero-accent: #5ad6c0;
  --s-ingresos: #2a78d6;
  --s-facturas: #eb6834;
  --s-gastos: #1baf7a;
  --s-ahorros: #eda100;
  --s-inversiones: #e87ba4;
  --s-deudas: #6250d6;
  --font-display: "Bricolage Grotesque", "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --side-w: 248px;
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0c111b;
    --surface: #151c2a;
    --surface-2: #1b2434;
    --ink: #eef1f6;
    --ink-2: #b9c2d3;
    --muted: #8591a8;
    --line: #253044;
    --axis: #33405a;
    --brand: #35bfa8;
    --brand-ink: #06201c;
    --brand-soft: #15332f;
    --good: #3ecf8e;
    --warn: #e0a22b;
    --critical: #f0706c;
    --track: #253044;
    --side-bg: #0a0f18;
    --hero-bg: #1c2942;
    --s-ingresos: #3987e5;
    --s-facturas: #d95926;
    --s-gastos: #199e70;
    --s-ahorros: #c98500;
    --s-inversiones: #d55181;
    --s-deudas: #9085e9;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.5 var(--font-body); font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
h1, h2 { font-family: var(--font-display); text-wrap: balance; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- acceso ---------- */
body.locked .shell, body.locked .fab { display: none; }
#gate {
  --g0: #35bfa8; --g1: #e9edf5; --g2: #eda100;
  position: fixed; inset: 0; z-index: 100; overflow-y: auto; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(120% 80% at 50% 110%, #12456a 0%, #16233b 48%, #0c1424 100%);
}
.gate-art { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.gate-bars { position: absolute; left: 0; right: 0; bottom: 0; height: 62%; display: flex; align-items: flex-end; gap: clamp(6px, 1.6vw, 22px); padding: 0 clamp(10px, 3vw, 48px); }
.gate-bars i { flex: 1; height: var(--h); background: var(--c); opacity: .5; border-radius: 8px 8px 0 0; transform-origin: bottom; }
.gate-line { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 70%; stroke-width: initial; overflow: visible; }
.gate-line path { fill: none; stroke: #fff; stroke-width: 3px; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; opacity: .85; }
.gate-card {
  position: relative; width: min(390px, 100%); background: var(--surface); border-radius: 24px;
  padding: 32px 28px 28px; display: grid; gap: 12px; box-shadow: 0 30px 80px rgba(3, 8, 18, .55);
}
.gate-logo { width: 62px; height: 62px; border-radius: 17px; background: #16233b; display: flex; align-items: flex-end; justify-content: center; gap: 5px; padding: 14px 0; }
.gate-logo i { width: 9px; border-radius: 3px; transform-origin: bottom; }
.gate-logo i:nth-child(1) { height: 45%; background: #35bfa8; }
.gate-logo i:nth-child(2) { height: 100%; background: #fff; }
.gate-logo i:nth-child(3) { height: 70%; background: #eda100; }
.gate-card h1 { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; }
.gate-card .sub { margin-bottom: 6px; }
#gateIn { position: relative; }
.gi-load { display: none; align-items: flex-end; gap: 4px; height: 18px; }
.gi-load i { width: 5px; height: 100%; border-radius: 2px; background: currentColor; transform-origin: bottom; transform: scaleY(.4); }
.gate-card.busy #gateIn .gi-t { display: none; }
.gate-card.busy #gateIn .gi-load { display: inline-flex; }
@media (prefers-reduced-motion: no-preference) {
  .gate-bars i { animation: gbar-in .9s cubic-bezier(.2, .8, .2, 1) var(--d) both, gbar-live 4.2s ease-in-out calc(var(--d) * 6 + 1s) infinite alternate; }
  .gate-line { animation: gline 1.9s cubic-bezier(.4, 0, .2, 1) .45s both; }
  .gate-card { animation: gcard .7s cubic-bezier(.2, .8, .2, 1) .15s both; }
  .gate-logo i { animation: gbar-in .7s cubic-bezier(.2, .9, .3, 1.2) both; }
  .gate-logo i:nth-child(1) { animation-delay: .55s; }
  .gate-logo i:nth-child(2) { animation-delay: .68s; }
  .gate-logo i:nth-child(3) { animation-delay: .81s; }
  .gi-load i { animation: gload .7s ease-in-out infinite alternate; }
  .gi-load i:nth-child(2) { animation-delay: .15s; }
  .gi-load i:nth-child(3) { animation-delay: .3s; }
  .gate-card.shake { animation: gshake .4s ease-in-out; }
  #gate.out { animation: gout .45s ease-in both; }
  #gate.out .gate-card { animation: gcard-out .4s ease-in both; }
}
@keyframes gbar-in { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes gbar-live { from { transform: scaleY(1); } to { transform: scaleY(.8); } }
@keyframes gline { from { clip-path: inset(-10% 100% -10% 0); } to { clip-path: inset(-10% 0 -10% 0); } }
@keyframes gcard { from { opacity: 0; transform: translateY(26px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes gcard-out { to { opacity: 0; transform: translateY(-18px) scale(.97); } }
@keyframes gout { to { opacity: 0; } }
@keyframes gload { from { transform: scaleY(.3); } to { transform: scaleY(1); } }
@keyframes gshake { 20% { transform: translateX(-9px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
.gate-card label, dialog label { display: grid; gap: 5px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.gate-card input, dialog input:not([type=file]), dialog select {
  min-height: 46px; border-radius: 10px; border: 1px solid var(--axis); background: var(--surface);
  padding: 6px 12px; font-size: 16px; font-weight: 400; color: var(--ink);
}
.gate-card input:focus, dialog input:focus, dialog select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.gate-card .btn { min-height: 46px; }
.gate-card .hint:empty { display: none; }

/* ---------- estructura: una sola pantalla ---------- */
.shell { min-height: 100dvh; }
.bar {
  position: sticky; top: 0; z-index: 10; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(20px, calc((100vw - 1240px) / 2 + 20px)) 10px;
  background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; font-family: var(--font-display); font-weight: 700; font-size: 19px; letter-spacing: -.01em; white-space: nowrap; min-width: 0; }
.brand img { border-radius: 9px; flex: none; }
.brand .lbl { overflow: hidden; text-overflow: ellipsis; max-width: 30ch; }
.gate-card h1 { overflow-wrap: anywhere; }
.bar-end { display: flex; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; }
.sync { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; margin-right: 8px; }
.sync i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.sync[data-state="ok"] i, .sync[data-state="idle"] i { background: var(--brand); }
.sync[data-state="sync"] i, .sync[data-state="offline"] i { background: var(--warn); }
.sync[data-state="error"] i { background: var(--critical); }
.sync[data-state="error"] { color: var(--critical); }
.icon-btn {
  width: 42px; height: 42px; display: grid; place-items: center; border: 0; border-radius: 10px;
  background: transparent; color: var(--ink-2); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--line); color: var(--ink); }
.month-nav { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 2px; }
.month-nav .icon-btn { width: 36px; height: 36px; }
.month-label { min-width: 132px; text-align: center; font-weight: 600; white-space: nowrap; }
.month-label::first-letter { text-transform: uppercase; }
main { max-width: 1240px; margin: 0 auto; padding: 22px 20px 110px; }

/* secciones que se expanden y se encogen */
.sec-tools { display: flex; justify-content: flex-end; margin: 4px 2px 2px; }
.sec { border-top: 1px solid var(--line); }
.sec:last-of-type { border-bottom: 1px solid var(--line); }
.sec.open { border-bottom: 0; }
.sec-h { margin: 0; }
.sec-h button {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 62px; padding: 10px 6px;
  border: 0; background: transparent; cursor: pointer; text-align: left; border-radius: 10px;
}
.sec-h button:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.sec-h .chev { color: var(--muted); }
.sec-i { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex: none; background: var(--brand-soft); color: var(--brand); }
.sec.open .sec-i { background: var(--brand); color: var(--brand-ink); }
.sec-s { padding-right: 2px; }

/* calendario y gastos fijos programados */
.cal-wrap { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 14px; margin-bottom: 14px; align-items: stretch; }
.cal-wrap > .card { margin-bottom: 0; display: flex; flex-direction: column; }
.cal { flex: 1; display: flex; flex-direction: column; }
.cal-dow { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); text-align: center; margin-bottom: 6px; }
.cal-grid { flex: 1; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: minmax(64px, 1fr); gap: 6px; }
.cal-day {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; padding: 6px 7px; text-align: left;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: inherit; cursor: pointer;
}
.cal-day.out { border-style: dashed; background: transparent; color: var(--muted); cursor: default; opacity: .55; }
.cal-day .n { font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.cal-day.has { background: var(--surface-2); }
.cal-day:not(.out):hover { border-color: var(--brand); }
.cal-day.today .n { background: var(--ink); color: var(--surface); border-radius: 6px; padding: 0 6px; }
.cal-day.sel { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.cal-dots { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.cal-dots i { width: 9px; height: 9px; border-radius: 3px; background: var(--c); border: 1.5px solid var(--c); }
.cal-dots i.done { background: transparent; }
.cal-dots em { font-style: normal; font-size: 11.5px; color: var(--muted); }
.cal-amt { margin-top: auto; font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.cal-day.late .cal-amt { color: var(--critical); }
.cal-key { margin-top: 12px; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.cal-key span { display: inline-flex; align-items: center; gap: 6px; }
.cal-k { width: 10px; height: 10px; border-radius: 3px; background: var(--ink-2); border: 1.5px solid var(--ink-2); display: inline-block; }
.cal-k.done { background: transparent; }
.ico-rep { width: 15px; height: 15px; color: var(--brand); stroke-width: 2; vertical-align: -2px; margin-left: 6px; }
.cal-key .ico-rep { margin-left: 0; }
.pay-t { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pay.done .pay-t, .fore-it.done .pay-t { color: var(--muted); }
.pay-name small.pos { color: var(--brand); font-weight: 600; }
.cal-badge { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--surface-2); border: 1px solid var(--line); font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.fx-tbl td { padding-top: 7px; padding-bottom: 7px; }
.fx-cat { display: block; font-size: 12.5px; color: var(--muted); margin-left: 18px; }
.fore { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 8px 24px; align-items: start; }
.fore-sum .facts { margin-bottom: 12px; }
.fore-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 24px; }
.fore-it { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cal-amt b { font-weight: 600; }
/* selector de apariencia */
.seg svg { width: 18px; height: 18px; vertical-align: -4px; margin-right: 6px; }
#themeBtn .i-sun, :root[data-theme="light"] #themeBtn .i-moon { display: none; }
:root[data-theme="light"] #themeBtn .i-sun { display: block; }
:root[data-theme="light"] .card, :root[data-theme="light"] .stats { box-shadow: 0 1px 2px rgba(22, 35, 59, .05), 0 6px 18px rgba(22, 35, 59, .04); }
/* selector gasto / ingreso */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.seg button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--ink-2); font: 600 15px var(--font-body); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
/* tick del diálogo */
dialog label.tick { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; font-size: 15px; font-weight: 600; color: var(--ink); }
dialog label.tick input { width: 22px; height: 22px; min-height: 0; padding: 0; accent-color: var(--brand); flex: none; }
dialog label.tick small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }
dialog label.tick:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.fixed-box { display: grid; gap: 8px; }
.fixed-box .hint { margin: 0; color: var(--ink-2); }
.sec.open .sec-h .chev { transform: rotate(90deg); }
.sec-t { font-family: var(--font-display); font-size: 21px; font-weight: 700; letter-spacing: -.015em; }
.sec-s { margin-left: auto; font: 500 14px var(--font-body); color: var(--muted); text-align: right; }
.sec-b { padding: 4px 0 22px; }
.masonry { columns: 2 440px; column-gap: 14px; }
.masonry > .card { break-inside: avoid; }
.masonry { margin-bottom: 0; }
.masonry + .card { margin-top: 0; }
/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--axis);
  background: var(--surface); cursor: pointer; font-weight: 600;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--critical); border-color: var(--critical); }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 13.5px; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-col { display: grid; gap: 8px; }
.link { margin-left: auto; border: 0; background: none; padding: 4px 0; color: var(--brand); font: 600 13.5px var(--font-body); cursor: pointer; }
.link:hover { text-decoration: underline; }
.fab {
  display: none; position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 9;
  width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer; place-items: center;
  background: var(--brand); color: var(--brand-ink); box-shadow: 0 8px 22px rgba(14, 60, 52, .35);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.2; }

/* ---------- panel: cabecera ---------- */
.hero {
  background: var(--hero-bg); color: var(--hero-ink); border-radius: 22px; padding: 30px 32px;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 420px); gap: 28px 44px; align-items: end; margin-bottom: 14px;
}
.hero-label { color: var(--hero-muted); font-weight: 500; }
.hero-figure {
  font-family: var(--font-display); font-weight: 700; font-size: clamp(42px, 7vw, 76px); line-height: 1.02;
  letter-spacing: -.035em; margin: 6px 0 10px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums;
}
.hero-figure.neg { color: #ff9a95; }
.hero-sub { color: var(--hero-muted); max-width: 46ch; }
.pace { min-width: 0; }
.pace-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; color: var(--hero-muted); font-size: 14px; }
.pace-head strong { color: var(--hero-ink); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pace-bar { position: relative; height: 14px; border-radius: 7px; background: rgba(255, 255, 255, .13); margin: 30px 0 10px; }
.pace-fill { height: 100%; border-radius: 7px; background: var(--hero-accent); min-width: 4px; }
.pace-fill.hot { background: #ffb347; }
.pace-today { position: absolute; top: -7px; bottom: -7px; width: 2px; background: #fff; border-radius: 1px; }
.pace-today span { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 600; padding-bottom: 2px; }
.pace-verdict { font-weight: 600; font-size: 14px; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 14px; }
/* indicador: el texto ocupa la izquierda y un mini-gráfico la derecha; nunca queda media tarjeta vacía */
.stat { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 16px 20px; min-width: 0; }
.kpi-txt { display: grid; gap: 1px; min-width: 0; }
.kpi-ring { position: relative; width: 76px; height: 76px; flex: none; }
.kpi-ring svg { width: 100%; height: 100%; stroke-width: initial; display: block; }
.kpi-ring b { position: absolute; inset: 0; display: grid; place-items: center; font: 600 14px var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi-spark { display: flex; align-items: flex-end; gap: 2px; width: clamp(84px, 9vw, 132px); height: 62px; }
.kpi-spark i { flex: 1; min-width: 1px; border-radius: 2px 2px 0 0; }
.kpi-spark i.on { outline: 1.5px solid var(--ink); outline-offset: 1px; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat .k, .tile .k { font-size: 13.5px; color: var(--ink-2); font-weight: 500; }
.stat .v { font-family: var(--font-display); font-size: 25px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .n, .tile .n { font-size: 13px; color: var(--muted); }


/* ---------- piezas comunes ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; margin-bottom: 14px; min-width: 0; }
.card > h2 { font-size: 17px; font-weight: 600; letter-spacing: -.01em; margin-bottom: 12px; display: flex; align-items: center; gap: 9px; }
.card > h2 .count { margin-left: auto; font: 600 15px var(--font-body); font-variant-numeric: tabular-nums; color: var(--ink-2); }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
.sub { color: var(--ink-2); font-size: 14px; }
.sub.more { margin-top: 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 2px 0 8px; }
.neg, .over { color: var(--critical); }
.over { font-weight: 600; }
.pos { color: var(--good); }

.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 18px; min-width: 0; }
.tile .v { font-family: var(--font-display); font-size: 25px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 430px), 1fr)); gap: 14px; align-items: start; margin-bottom: 14px; }
.grid-2 > .card { margin-bottom: 0; }
/* tarjetas emparejadas: misma altura en cada fila, sin huecos debajo de la más corta */
.grid-2.even { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
.grid-2.even > .card { display: flex; flex-direction: column; }
.grid-2.even > .card > .donut-wrap, .grid-2.even > .card > .chart { flex: 1; }
.grid-2.even > .card > .facts:last-child { margin-top: auto; }
.grid-2.even > .card > .chart + .facts { margin-top: 16px; }
.grid-2.even > .card:last-child:nth-child(odd) { grid-column: 1 / -1; }
.nobudget { color: var(--warn); font-weight: 600; }

/* gráfico de línea */
.chart-cap { font-size: 13.5px; font-weight: 600; color: var(--ink-2); margin: 16px 0 -4px; }
.chart-cap:first-of-type { margin-top: 2px; }
.chart-cap + .key { margin-top: 10px; }
.lineplot { display: block; }
.lineplot svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; stroke-width: initial; }
.lineplot .ln { fill: none; stroke: var(--brand); stroke-width: 2.5px; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.lineplot .area { fill: var(--brand); fill-opacity: .13; stroke: none; }
.lineplot .zero { position: absolute; left: 0; right: 0; border-top: 1.5px solid var(--axis); pointer-events: none; }
.pt {
  position: absolute; width: 11px; height: 11px; margin: 0 0 -5.5px -5.5px; padding: 0; border-radius: 50%;
  border: 2px solid var(--surface); background: var(--brand); cursor: pointer;
}
.pt::before { content: ""; position: absolute; inset: -12px -8px; }
.pt:hover, .pt:focus-visible { transform: scale(1.5); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 30%, transparent); }
.lineplot.dense .pt { width: 7px; height: 7px; margin: 0 0 -3.5px -3.5px; border-width: 1.5px; }
.lineplot.dense .pt::before { inset: -14px -3px; }
.lineplot.drawing .pt { opacity: 0; }
.lineplot .pt { transition: opacity .25s ease-out; }

/* pagos pendientes */
.pay-list { display: grid; }
.pay { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.pay:first-child { border-top: 0; padding-top: 2px; }
.pay input { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.pay-name { flex: 1; min-width: 0; font-weight: 500; display: grid; }
.pay-name small { font-size: 13px; font-weight: 400; color: var(--muted); }
.pay-name small.over { color: var(--critical); font-weight: 600; }
.pay-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- tablas de presupuesto ---------- */
.tbl-wrap { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 13px; font-weight: 500; color: var(--muted); padding: 4px 6px 6px; white-space: nowrap; }
td { padding: 3px 6px; border-top: 1px solid var(--line); vertical-align: middle; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 700; border-top: 2px solid var(--axis); padding-top: 9px; padding-bottom: 4px; }
td.ck { width: 34px; }
td.ck input { width: 20px; height: 20px; accent-color: var(--brand); display: block; }
td.nm { width: 55%; }
th.due, td.due { width: 60px; text-align: center; }
td.acts { width: 80px; white-space: nowrap; text-align: right; }
.cell { width: 100%; min-height: 36px; border: 1px solid transparent; border-radius: 8px; background: transparent; padding: 4px 6px; }
.cell:hover { border-color: var(--line); }
.cell:focus { border-color: var(--brand); background: var(--surface); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.cell.name { min-width: 172px; font-weight: 500; text-overflow: ellipsis; }
.cell.amt { text-align: right; width: 98px; font-variant-numeric: tabular-nums; }
.cell.day { width: 52px; text-align: center; }
.mini { width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; }
.mini:hover { background: var(--surface-2); color: var(--ink); }
.row-done .cell.name { color: var(--muted); text-decoration: line-through; }
.card-foot { margin-top: 10px; }

/* ---------- movimientos ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.filters select { min-height: 42px; border-radius: 10px; border: 1px solid var(--axis); background: var(--surface); padding: 4px 12px; font-weight: 500; }
.day-head { font-size: 13px; font-weight: 600; color: var(--muted); margin: 16px 0 2px; }
.day-head::first-letter { text-transform: uppercase; }
.day-head:first-child { margin-top: 0; }
.tx { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
h2 + .tx { border-top: 0; padding-top: 2px; }
.tx .info { flex: 1; min-width: 0; }
.tx .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.empty { text-align: center; padding: 44px 16px; color: var(--ink-2); }
.empty h2 { justify-content: center; font-size: 20px; }
.empty .btn { margin: 14px 4px 0; }

/* ---------- gráficos ---------- */
.meter-row { display: grid; grid-template-columns: minmax(90px, 150px) 1fr; gap: 4px 14px; align-items: center; padding: 8px 0; }
.meter-row .lbl { font-weight: 500; display: flex; align-items: center; gap: 9px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter-row .vals { grid-column: 2; display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.track { height: 10px; background: var(--track); border-radius: 4px; overflow: hidden; }
.fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.stack { display: flex; gap: 2px; height: 26px; border-radius: 6px; overflow: hidden; margin: 6px 0 14px; }
.stack > div { min-width: 3px; }
.legend { display: grid; gap: 7px; }
.legend .li { display: grid; grid-template-columns: 14px 1fr auto auto; gap: 8px; align-items: center; }
.legend .li .pct { color: var(--muted); min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
.legend .li .val { font-variant-numeric: tabular-nums; font-weight: 500; }
.rank { display: grid; grid-template-columns: 22px minmax(90px, 1fr) minmax(60px, 1.2fr) auto; gap: 10px; align-items: center; padding: 6px 0; }
.rank .i { color: var(--muted); font-variant-numeric: tabular-nums; }
.rank .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .val { font-variant-numeric: tabular-nums; text-align: right; font-weight: 500; }
.rank .val small { color: var(--muted); margin-left: 8px; font-weight: 400; }
.cols { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 190px; border-bottom: 1px solid var(--axis); margin-top: 12px; }
.col { display: flex; gap: 2px; align-items: flex-end; height: 100%; justify-content: center; cursor: pointer; border-radius: 6px 6px 0 0; }
.col:hover { background: var(--surface-2); }
.col i { display: block; width: 42%; max-width: 18px; border-radius: 4px 4px 0 0; }
.col-labels { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; font-size: 12px; color: var(--muted); text-align: center; margin-top: 6px; text-transform: capitalize; }
.key { display: flex; gap: 18px; font-size: 13.5px; color: var(--ink-2); }
.key span { display: inline-flex; align-items: center; gap: 7px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.clickable td { padding-top: 8px; padding-bottom: 8px; }
tr.current td { font-weight: 700; }

/* ---------- economía ---------- */
.stats.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.donut-wrap { display: grid; grid-template-columns: minmax(150px, 210px) minmax(0, 1fr); gap: 22px 26px; align-items: center; }
.donut { position: relative; aspect-ratio: 1; width: 100%; max-width: 230px; margin: 0 auto; }
.donut svg { width: 100%; height: 100%; stroke-width: initial; stroke-linecap: initial; display: block; overflow: visible; }
.donut circle[data-act] { cursor: pointer; outline: none; }
.donut circle[data-act]:focus-visible { stroke-opacity: .7; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; padding: 26%; }
.donut-center strong { font-family: var(--font-display); font-size: clamp(15px, 2.1vw, 21px); font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.donut-center span { font-size: 12.5px; color: var(--muted); }
.legend button.li { width: 100%; border: 1px solid transparent; background: none; border-radius: 9px; padding: 7px 8px; margin: -3px 0; text-align: left; cursor: pointer; }
.legend button.li:hover { background: var(--surface-2); }
.legend button.li[aria-pressed="true"] { background: var(--surface-2); border-color: var(--line); font-weight: 600; }
.legend .li .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 2px 0 14px; }
.chart + .facts { margin: 16px 0 0; }
.facts > div { background: var(--surface); padding: 9px 12px; display: grid; gap: 1px; min-width: 0; }
.facts span { font-size: 12.5px; color: var(--muted); display: block; }
.facts span::first-letter { text-transform: uppercase; }
.facts strong { font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.facts small { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.rank.no-i { grid-template-columns: minmax(90px, 1fr) minmax(60px, 1.2fr) auto; }
.fill[style*="width:0%"] { min-width: 0; }
.card:has(> .donut-wrap) { container-type: inline-size; }
@container (max-width: 520px) {
  .donut-wrap { grid-template-columns: minmax(0, 1fr); }
  .donut { max-width: 210px; }
}
table.detail { min-width: 440px; }
table.detail td:first-child { white-space: nowrap; }

.chart { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 10px; margin-top: 14px; }
.chart-y { display: flex; flex-direction: column; justify-content: space-between; height: 200px; font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; line-height: 1; }
.chart-y span:first-child { transform: translateY(-4px); }
.chart-y span:last-child { transform: translateY(4px); }
.chart-plot { position: relative; height: 200px; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 0 6px; align-items: end; border-bottom: 1px solid var(--axis); }
.grid-lines { position: absolute; inset: 0; pointer-events: none; }
.grid-lines i { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.grid-lines i:first-child { top: 0; }
.grid-lines i:last-child { top: 50%; }
.cgroup { position: relative; height: 100%; display: flex; gap: 2px; align-items: flex-end; justify-content: center; border-radius: 6px 6px 0 0; }
.cgroup:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.cgroup i { display: block; width: 38%; max-width: 34px; border-radius: 4px 4px 0 0; }
.cgroup.thin i { width: 72%; max-width: 16px; border-radius: 3px 3px 0 0; }
.cgroup.mark::after { content: ""; position: absolute; left: 50%; bottom: -7px; width: 5px; height: 5px; border-radius: 50%; background: var(--ink); transform: translateX(-50%); }
.chart-plot:has(.thin) { gap: 0 2px; }
.chart-x { grid-column: 2; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 0 6px; margin-top: 8px; font-size: 12.5px; color: var(--muted); text-align: center; }
.chart-x span { white-space: nowrap; overflow: visible; }
.chart-x span::first-letter { text-transform: uppercase; }
.chart-plot:has(.thin) + .chart-x { gap: 0 2px; }
.avg { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--ink-2); pointer-events: none; }
.avg span { position: absolute; right: 0; bottom: 3px; font-size: 12px; font-weight: 600; color: var(--ink-2); background: color-mix(in srgb, var(--surface) 85%, transparent); padding: 0 4px; border-radius: 4px; }
.swatch-multi { background: linear-gradient(90deg, var(--s-facturas) 0 33%, var(--s-gastos) 33% 66%, var(--s-deudas) 66%); }
table.detail { margin-top: 18px; }
table.detail td { padding-top: 8px; padding-bottom: 8px; }

.rule { padding: 12px 0; border-top: 1px solid var(--line); }
.rule:first-of-type { border-top: 0; }
.rule-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-end; }
.rule-head strong { font-weight: 600; display: block; }
.rule-head small { font-size: 13px; color: var(--muted); display: block; }
.rule-val { font-family: var(--font-display); font-size: 20px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rule-val small { font-family: var(--font-body); font-weight: 400; }
.rule-bar { position: relative; margin: 26px 0 8px; }
.rule-target { position: absolute; top: -6px; bottom: -6px; width: 2px; background: var(--ink); border-radius: 1px; }
.rule-target span { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 600; color: var(--ink-2); padding-bottom: 1px; white-space: nowrap; }
.rule-note { font-size: 13.5px; font-weight: 600; }

/* ---------- diálogos y avisos ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px); overflow-y: auto; background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 60px rgba(10, 18, 34, .35);
}
dialog::backdrop { background: rgba(12, 19, 33, .55); }
dialog form, .dlg-body { padding: 22px; display: grid; gap: 13px; }
dialog h2 { font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
dialog h3 { font: 600 14px var(--font-body); color: var(--ink); margin-top: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.cloud { display: grid; gap: 10px; }
.warn-box { margin: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--surface)); color: var(--ink); font-size: 13.5px; line-height: 1.45; }
#pwMsg:empty { display: none; }
#pwForm.busy input { opacity: .6; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.facts strong.wrap { overflow-wrap: anywhere; font-size: 15px; }
.hist-wrap { max-height: 460px; overflow-y: auto; }
.hist td { padding-top: 8px; padding-bottom: 8px; font-size: 14px; }
.hist thead th { position: sticky; top: 0; background: var(--surface); }
.nowrap { white-space: nowrap; font-variant-numeric: tabular-nums; }
.ev { font-weight: 600; }
.ev.ok { color: var(--good); }
.ev.bad { color: var(--critical); }
#askDlg { width: min(400px, calc(100vw - 32px)); }
.ask-msg { color: var(--ink-2); font-size: 15px; line-height: 1.5; }
.btn.danger-solid { background: var(--critical); border-color: var(--critical); color: var(--surface); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
#tip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: var(--surface);
  padding: 7px 10px; border-radius: 8px; font-size: 12.5px; max-width: 250px; white-space: pre-line;
}
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--ink); color: var(--surface); padding: 11px 18px; border-radius: 12px; font-size: 14px; font-weight: 500;
  max-width: calc(100vw - 32px); box-shadow: 0 10px 28px rgba(10, 18, 34, .3);
}

/* ---------- tableta vertical y móvil ---------- */
@media (max-width: 900px) {
  .bar { grid-template-columns: auto 1fr auto; padding-left: 14px; padding-right: 10px; }
  .brand .lbl, .sync .lbl { display: none; }
  .sync { margin-right: 2px; }
  .month-nav { justify-self: center; }
  main { padding: 16px 16px 110px; }
  .add-top { display: none; }
  .fab { display: grid; }
  .hero { grid-template-columns: minmax(0, 1fr); padding: 26px 24px; align-items: start; }
  .stats.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats.four .stat:nth-child(3) { border-left: 0; }
  .stats.four .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .grid-2.even { grid-template-columns: minmax(0, 1fr); }
  .cal-wrap, .fore { grid-template-columns: minmax(0, 1fr); }
  .cal-grid { grid-auto-rows: minmax(56px, auto); gap: 4px; }
  .cal-dow { gap: 4px; }
  .cal-day { padding: 5px 4px; }
  .cal-amt { font-size: 11.5px; }
  .sec-i { width: 34px; height: 34px; border-radius: 10px; }
}
@media (max-width: 560px) {
  #themeBtn { display: none; }
  .bar h1 { font-size: 19px; }
  .month-label { min-width: 0; padding: 0 2px; font-size: 14px; }
  .month-nav .icon-btn { width: 32px; }
  .bar { gap: 4px; }
  td.num, tfoot td, .cell.amt { font-size: 14px; }
  td.nm { width: auto; }
  main { padding: 12px 10px 110px; }
  .hero { padding: 22px 18px; border-radius: 18px; }
  .card { padding: 14px 12px; }
  .grid-2.even { grid-template-columns: minmax(0, 1fr); }
  .sec-t { font-size: 18px; }
  .sec-s { font-size: 13px; }
  .sec-h button { gap: 8px; padding-left: 2px; padding-right: 2px; }
  .kpi-ring { width: 64px; height: 64px; }
  .stats, .stats.four { grid-template-columns: minmax(0, 1fr); }
  .stats.four .stat:nth-child(n+2) { border-top: 1px solid var(--line); }
  .donut-wrap { grid-template-columns: minmax(0, 1fr); }
  .donut { max-width: 200px; }
  .donut-center strong { font-size: 18px; }
  .chart-plot, .chart-y { height: 170px; }
  .chart-plot, .chart-x { gap: 0 3px; }
  .rank.no-i { grid-template-columns: minmax(70px, 1fr) minmax(40px, .8fr) auto; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .facts > div:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .stat { padding: 12px 16px; }
  .stat + .stat { border-left: 0; border-top: 1px solid var(--line); }
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tiles .tile:first-child { grid-column: 1 / -1; }
  .tile .v { font-size: 21px; }
  td, th { padding-left: 2px; padding-right: 2px; }
  td.acts { width: 36px; }
  .mini.del, th.due, td.due { display: none; }
  .cell.name { min-width: 78px; padding-left: 2px; padding-right: 2px; }
  .cell.amt { width: 64px; padding-left: 2px; padding-right: 2px; }
  td.ck { width: 30px; }
  .rank { grid-template-columns: 18px minmax(70px, 1fr) minmax(40px, .8fr) auto; }
  .rank .val small { display: none; }
  .meter-row { grid-template-columns: minmax(80px, 110px) 1fr; }
}
/* Pantallas táctiles (iPad, iPhone): campos de 16px para que Safari no haga zoom al escribir */
@media (pointer: coarse) {
  .cell, .filters select { font-size: 16px; }
  .cell { min-height: 42px; }
  .mini { width: 40px; height: 40px; }
  td.ck input { width: 24px; height: 24px; }
  .pay { padding: 12px 0; }
  .pay input { width: 24px; height: 24px; }
}
@media (prefers-reduced-motion: no-preference) {
  .sec-h .chev { transition: transform .2s ease-out; }
}

.add-top { white-space: nowrap; }
