/* Mi Economía — estilos. Colores como variables; el tema oscuro se elige a mano o sigue al sistema. */
:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --wash: rgba(11, 11, 11, 0.05);
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.20);
  --accent: #2a78d6;
  --accent-hover: #256abf;
  --accent-soft: rgba(42, 120, 214, 0.12);
  --link: #1c5cab;
  --good-ink: #006300;
  --good-bg: rgba(0, 99, 0, 0.09);
  --bad-ink: #c23030;
  --bad-bg: rgba(194, 48, 48, 0.09);
  --warn-ink: #8a5a00;
  --warn-bg: rgba(250, 178, 25, 0.22);
  --income: #1baf7a;
  --expense: #eb6834;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
  --series-other: #a9a89f;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #252523; --wash: rgba(255, 255, 255, 0.06);
    --ink: #f4f4f2; --ink-2: #c3c2b7; --ink-3: #898781;
    --grid: #2c2c2a; --axis: #3d3d3a; --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.20);
    --link: #6da7ec; --accent-soft: rgba(57, 135, 229, 0.18);
    --good-ink: #3fc26b; --good-bg: rgba(63, 194, 107, 0.13);
    --bad-ink: #ef7a7a; --bad-bg: rgba(239, 122, 122, 0.13);
    --warn-ink: #fab219; --warn-bg: rgba(250, 178, 25, 0.16);
    --income: #199e70; --expense: #d95926;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --series-other: #6b6a63;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #252523; --wash: rgba(255, 255, 255, 0.06);
  --ink: #f4f4f2; --ink-2: #c3c2b7; --ink-3: #898781;
  --grid: #2c2c2a; --axis: #3d3d3a; --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.20);
  --link: #6da7ec; --accent-soft: rgba(57, 135, 229, 0.18);
  --good-ink: #3fc26b; --good-bg: rgba(63, 194, 107, 0.13);
  --bad-ink: #ef7a7a; --bad-bg: rgba(239, 122, 122, 0.13);
  --warn-ink: #fab219; --warn-bg: rgba(250, 178, 25, 0.16);
  --income: #199e70; --expense: #d95926;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --series-other: #6b6a63;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--link); }
button { font: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ic { flex: none; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px; display: flex; flex-direction: column; gap: 22px;
  background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 10px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 17px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 18px; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-weight: 550; }
.nav a:hover { background: var(--wash); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--link); }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; }
.sidebar-foot p { font-size: 12px; color: var(--ink-2); padding: 0 4px; }
.theme-btn { display: flex; align-items: center; gap: 10px; background: none; border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; color: var(--ink-2); font-size: 13px; cursor: pointer; }
.theme-btn:hover { background: var(--wash); color: var(--ink); }
.main { padding: 30px 38px 64px; min-width: 0; }
#view { max-width: 1260px; margin: 0 auto; }
.fab {
  display: none; position: fixed; right: 16px; bottom: 82px; width: 56px; height: 56px; border-radius: 50%; border: 0; z-index: 60;
  background: var(--accent); color: #fff; place-items: center; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28); cursor: pointer;
}

/* ---------- Cabecera de página y controles ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px 20px; flex-wrap: wrap; margin-bottom: 22px; }
h1 { font-size: 26px; line-height: 1.2; letter-spacing: -0.01em; font-weight: 700; }
.page-sub { color: var(--ink-2); margin-top: 2px; font-size: 14px; }
.head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink); font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--wash); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: #c23030; border-color: transparent; color: #fff; }
.btn.danger:hover { background: #a82727; }
.btn.danger.ghost { background: transparent; color: var(--bad-ink); border-color: var(--border-strong); }
.btn.danger.ghost:hover { background: var(--bad-bg); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--link); }
.btn.ghost:hover { background: var(--wash); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; background: none; border-radius: 8px; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--wash); color: var(--ink); }

input:not([type=radio]):not([type=checkbox]):not([type=file]), select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 10px; height: 38px; padding: 0 12px; min-width: 0;
}
input::placeholder { color: var(--ink-3); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.period { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.period-range { font-size: 13px; color: var(--ink-2); }
.period-sep { color: var(--ink-2); }

.seg-ctl { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg-ctl button { border: 0; background: none; font-size: 13px; padding: 5px 12px; border-radius: 8px; color: var(--ink-2); cursor: pointer; }
.seg-ctl button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14); }
.tabs { display: flex; gap: 6px; margin: 0 0 16px; border-bottom: 1px solid var(--border); }
.tabs button, .tabs a { border: 0; background: none; padding: 10px 14px; color: var(--ink-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.tabs button:hover, .tabs a:hover { color: var(--ink); }
.tabs button.on, .tabs a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.count { font-size: 12px; font-weight: 500; background: var(--surface-2); border-radius: 999px; padding: 1px 8px; color: var(--ink-2); }

.banner { display: flex; align-items: center; gap: 12px; padding: 11px 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 16px; font-size: 14px; }
.banner span { flex: 1; }
.banner.bad { border-color: var(--bad-ink); }
.banner.warn { background: var(--warn-bg); border-color: transparent; }
.banner.warn .ic { color: var(--warn-ink); }

/* ---------- Tarjetas e indicadores ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.card-head h3, .card > h3 { font-size: 15px; font-weight: 650; }
.sub { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.card-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.top-row { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 2fr); gap: 16px; margin-bottom: 16px; }
.top-row.single { grid-template-columns: 1fr; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.tiles.four { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tile-label { font-size: 13px; font-weight: 550; color: var(--ink-2); }
.tile-value { font-size: 26px; line-height: 1.15; font-weight: 650; letter-spacing: -0.015em; }
.tile-sub { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; min-height: 22px; }
.hero { padding: 24px; display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.hero-value { font-size: clamp(40px, 5vw, 56px); line-height: 1.05; font-weight: 650; letter-spacing: -0.03em; margin: 6px 0 8px; }
.neg { color: var(--bad-ink); }
.pos { color: var(--good-ink); }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; font-size: 12.5px; padding: 2px 8px 2px 6px; border-radius: 999px; }
.delta.good { color: var(--good-ink); background: var(--good-bg); }
.delta.bad { color: var(--bad-ink); background: var(--bad-bg); }
.delta.flat { color: var(--ink-2); background: var(--surface-2); padding-left: 8px; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; margin-bottom: 16px; align-items: stretch; }
.grid-2 > .stack { align-content: start; }
.grid-2.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.stack { display: grid; gap: 16px; }

/* ---------- Gráficos ---------- */
.chart { width: 100%; min-width: 0; }
.chart svg { display: block; max-width: 100%; height: auto; overflow: visible; }
.chart-donut { display: flex; justify-content: center; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; list-style: none; margin: 0 0 8px; padding: 0; font-size: 13px; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.key.inc { background: var(--income); } .key.exp { background: var(--expense); }
.key.net { background: var(--ink-3); } .key.line { background: var(--series-1); height: 3px; width: 12px; border-radius: 2px; }
.chart-card .table-view { display: none; }
.chart-card.show-table .table-view { display: block; }
.chart-card.show-table .chart-view, .chart-card.show-table .legend { display: none; }

svg .grid { stroke: var(--grid); stroke-width: 1; }
svg .axis { stroke: var(--axis); stroke-width: 1; }
svg .tick { fill: var(--ink-3); font-size: 11px; }
svg .bar { pointer-events: none; }
svg .bar.inc { fill: var(--income); } svg .bar.exp { fill: var(--expense); }
svg .hit { fill: transparent; }
svg .hit:hover { fill: var(--wash); }
svg .seg { transition: opacity 0.12s; }
svg .seg:hover { opacity: 0.8; }
svg .donut-track { stroke: var(--surface-2); }
svg .donut-label { fill: var(--ink-2); font-size: 12px; }
svg .donut-value { fill: var(--ink); font-size: 19px; font-weight: 650; }
svg .area { fill: var(--series-1); opacity: 0.1; pointer-events: none; }
svg .ln { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
svg .spark-ln { fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .pt .xhair { stroke: var(--axis); stroke-width: 1; opacity: 0; pointer-events: none; }
svg .pt .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; opacity: 0; pointer-events: none; }
svg .pt:hover .xhair, svg .pt:hover .dot { opacity: 1; }
svg .end-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; pointer-events: none; }
svg .end-label { fill: var(--ink); font-size: 12px; font-weight: 650; pointer-events: none; }

.tooltip {
  position: fixed; left: 0; top: 0; z-index: 300; pointer-events: none; min-width: 170px; max-width: 280px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18); padding: 10px 12px; font-size: 13px;
}
.tooltip b { display: block; font-weight: 600; margin-bottom: 4px; }
.tooltip b::first-letter { text-transform: uppercase; }
.tip-row { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.tip-row span { flex: 1; color: var(--ink-2); }
.tip-row strong { font-weight: 650; font-variant-numeric: tabular-nums; }
.tip-sep { height: 1px; background: var(--border); margin: 6px 0 2px; }

.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.hb-top { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; margin-bottom: 6px; }
.hb-val { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.hb-val em { font-style: normal; font-weight: 400; color: var(--ink-2); margin-left: 6px; font-size: 13px; }
.hb-track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.hb-fill { height: 100%; border-radius: 4px; }
.hb-fill.exp { background: var(--expense); } .hb-fill.inc { background: var(--income); } .hb-fill.sav { background: var(--series-1); }

.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.dlegend { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; gap: 2px; }
.dlegend li > a, .dlegend li > span { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; color: inherit; text-decoration: none; font-size: 14px; }
.dlegend li > a:hover { background: var(--wash); }
.dl-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.dlegend em { font-style: normal; color: var(--ink-2); width: 44px; text-align: right; font-size: 13px; }

/* ---------- Tablas y listas ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--ink-2); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--wash); }
.tbl tr.click { cursor: pointer; }
.tbl tfoot td { font-weight: 650; border-top: 1px solid var(--axis); border-bottom: 0; }
.tbl.compact td, .tbl.compact th { padding: 8px 10px; }
.tbl .num, .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl a { color: var(--ink); text-decoration: none; font-weight: 550; }
.tbl a:hover { text-decoration: underline; }
.flush .tbl th:first-child, .flush .tbl td:first-child { padding-left: 18px; }
.flush .tbl th:last-child, .flush .tbl td:last-child { padding-right: 14px; }
.c-date { white-space: nowrap; color: var(--ink-2); }
.c-item { white-space: nowrap; }
.c-note { color: var(--ink-2); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-act { text-align: right; white-space: nowrap; }
.amt { font-weight: 600; }
.amt.inc { color: var(--good-ink); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; flex: none; }
.kind-tag { margin-left: 8px; font-size: 13px; opacity: 0.8; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); vertical-align: middle; }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); }
.chip.bad { background: var(--bad-bg); color: var(--bad-ink); }
.chip.ok { background: var(--good-bg); color: var(--good-ink); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; padding: 16px 18px 12px; }
.filters input[type=search] { flex: 1 1 200px; }
.summary { display: flex; gap: 22px; flex-wrap: wrap; padding: 0 18px 14px; font-size: 14px; color: var(--ink-2); border-bottom: 1px solid var(--border); }
.summary b { color: var(--ink); font-weight: 650; }
.summary b.pos { color: var(--good-ink); } .summary b.neg { color: var(--bad-ink); }
.more { text-align: center; padding: 14px; }
.fine { font-size: 12.5px; color: var(--ink-2); }
.fine.pad { padding: 14px 4px 0; }
.empty { text-align: center; padding: 26px 12px; color: var(--ink-2); }
.empty p { max-width: 48ch; margin: 0 auto 14px; }
.recent { list-style: none; margin: 0; padding: 0; }
.recent li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.recent li:first-child { border-top: 0; padding-top: 0; }
.recent-main { flex: 1; min-width: 0; }
.recent-main strong { display: block; font-weight: 600; font-size: 14px; }
.recent .amt { font-variant-numeric: tabular-nums; }
.facts { margin: 0; display: grid; gap: 12px; }
.facts div { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.facts div:last-child { border-bottom: 0; padding-bottom: 0; }
.facts dt { color: var(--ink-2); font-size: 14px; }
.facts dd { margin: 0; text-align: right; font-weight: 600; font-size: 14px; }

/* ---------- Elementos ---------- */
.group-title { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 650; margin: 26px 0 12px; }
.group:first-of-type .group-title { margin-top: 4px; }
.group-sum { margin-left: auto; font-size: 13px; color: var(--ink-2); font-weight: 400; }
.group-sum b { font-weight: 650; color: var(--ink); } .group-sum b.neg { color: var(--bad-ink); } .group-sum b.pos { color: var(--good-ink); }
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.item-card { display: block; position: relative; overflow: hidden; color: inherit; text-decoration: none; transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; }
.item-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c); }
.item-card:hover { border-color: var(--axis); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.07); transform: translateY(-1px); }
.item-top { display: flex; align-items: center; gap: 12px; }
.item-top h3 { font-size: 16px; font-weight: 650; }
.item-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; flex: none; background: color-mix(in srgb, var(--c) 15%, var(--surface)); }
.item-ico.lg { width: 52px; height: 52px; font-size: 26px; border-radius: 14px; }
.item-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0 8px; }
.item-nums span { display: block; font-size: 12px; color: var(--ink-2); }
.item-nums strong { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.spark-cap { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.item-head { display: flex; flex-direction: column; gap: 12px; }
.item-title { display: flex; align-items: center; gap: 14px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); text-decoration: none; font-size: 14px; width: fit-content; }
.back:hover { color: var(--ink); }

/* ---------- Stock ---------- */
.card-head.pad { padding: 18px 18px 6px; margin-bottom: 0; }
.orders-card { margin-top: 16px; }
.stock-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 13px; color: var(--ink-2); }
.tbl.stock .sub, .tbl.orders .sub { display: block; font-weight: 400; margin-top: 1px; }
.tbl.stock .c-prod strong, .tbl.orders .c-prod strong { font-weight: 600; }
.c-ref { white-space: nowrap; color: var(--ink-2); font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.tbl.stock td.num .sub { text-align: right; }
.qty { display: inline-flex; align-items: center; gap: 4px; }
.qty strong { min-width: 34px; text-align: center; font-size: 15px; font-variant-numeric: tabular-nums; }
.icon-btn.sm { width: 26px; height: 26px; border: 1px solid var(--border-strong); border-radius: 50%; }
.icon-btn:disabled { opacity: 0.35; cursor: default; background: none; }
.c-pend { min-width: 112px; }
.tbl.stock th, .tbl.stock td { padding-left: 10px; padding-right: 10px; }
.tbl.stock .c-prod { min-width: 170px; }
.tbl.stock .sub.late, .tbl.orders .sub.late { color: var(--bad-ink); font-weight: 550; }
.c-state .chip { white-space: nowrap; }
.order-box { border: 1px solid var(--border-strong); border-radius: 12px; padding: 4px 14px 2px; margin: 4px 0 8px; min-width: 0; }
.order-box legend { font-size: 13px; font-weight: 600; color: var(--ink-2); padding: 0 6px; }
.check { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

/* ---------- Bienvenida ---------- */
.welcome { max-width: 760px; margin: 5vh auto; text-align: center; padding: 44px 34px; }
.welcome-ico { width: 64px; height: 64px; border-radius: 18px; background: var(--accent); color: #fff; font-size: 34px; font-weight: 700; display: grid; place-items: center; margin: 0 auto 18px; }
.lead { color: var(--ink-2); font-size: 16px; max-width: 52ch; margin: 8px auto 0; }
.steps { list-style: none; padding: 0; margin: 30px 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; text-align: left; counter-reset: s; }
.steps li { background: var(--surface-2); border-radius: 12px; padding: 16px; counter-increment: s; }
.steps li::before { content: counter(s); display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.steps b { display: block; margin-bottom: 4px; }
.steps span { font-size: 13px; color: var(--ink-2); }
.welcome-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }

/* ---------- Ahorros ---------- */
.acc-list { display: grid; gap: 16px; }
.group-total { font-size: 16px; font-variant-numeric: tabular-nums; }
.acc-group { padding-bottom: 8px; }
.acc-group .card-head { margin-bottom: 4px; align-items: center; }
.acc-row { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(100px, 0.8fr) 130px auto; gap: 16px; align-items: center; padding: 12px 0; border-top: 1px solid var(--border); }
.acc-main strong { display: block; font-weight: 600; }
.acc-share { display: flex; align-items: center; gap: 8px; }
.acc-share .hb-track { flex: 1; }
.acc-share em { font-style: normal; font-size: 12.5px; color: var(--ink-2); width: 36px; text-align: right; }
.acc-bal { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.acc-act { display: flex; align-items: center; gap: 2px; justify-content: flex-end; }

/* ---------- Ajustes ---------- */
.settings { display: grid; gap: 16px; max-width: 720px; }
.settings .card > .sub { margin-bottom: 14px; }
.settings .card > h3 { margin-bottom: 2px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.danger-zone { border-color: color-mix(in srgb, var(--bad-ink) 45%, transparent); }

/* ---------- Modal, formularios, avisos ---------- */
dialog { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--ink); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35); overflow: hidden; }
dialog::backdrop { background: rgba(10, 10, 10, 0.5); backdrop-filter: blur(2px); }
.modal { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.modal > header { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 6px; }
.modal h2 { font-size: 18px; font-weight: 650; }
.modal-body { padding: 10px 20px 12px; overflow: auto; }
.modal > footer { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.form-err { flex: 1; color: var(--bad-ink); font-size: 13px; font-weight: 550; }
.field { display: grid; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.opt { font-weight: 400; color: var(--ink-3); }
.field input:not([type=radio]), .field select { width: 100%; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.input-suffix span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-2); pointer-events: none; }
.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type-toggle label { position: relative; }
.type-toggle input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.type-toggle span { display: block; text-align: center; padding: 9px; border-radius: 10px; border: 1px solid var(--border-strong); font-weight: 550; color: var(--ink-2); }
.type-toggle input:checked + .t-exp { background: color-mix(in srgb, var(--expense) 16%, var(--surface)); border-color: var(--expense); color: var(--ink); font-weight: 650; }
.type-toggle input:checked + .t-inc { background: color-mix(in srgb, var(--income) 16%, var(--surface)); border-color: var(--income); color: var(--ink); font-weight: 650; }
.type-toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 14px; }
.chip-btn { font-size: 13px; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 3px 11px; cursor: pointer; color: var(--ink-2); }
.chip-btn:hover { background: var(--wash); }
.chip-btn.on { background: var(--accent); color: #fff; border-color: transparent; }
.hint { font-size: 13px; color: var(--ink-2); background: var(--surface-2); padding: 10px 12px; border-radius: 10px; margin: 0 0 12px; }
.confirm-msg { margin: 4px 0 14px; line-height: 1.55; }
.swatches { display: flex; gap: 12px; flex-wrap: wrap; }
.swatch { position: relative; }
.swatch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.swatch span { display: block; width: 28px; height: 28px; border-radius: 50%; }
.swatch input:checked + span { outline: 2px solid var(--ink); outline-offset: 3px; }
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }
.del-row { margin-top: 6px; }

.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 400; width: max-content; max-width: calc(100vw - 24px); }
.toast { display: flex; align-items: center; gap: 16px; background: var(--ink); color: var(--surface); padding: 11px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3); animation: pop 0.18s ease-out; }
.toast-btn { background: none; border: 0; color: inherit; text-decoration: underline; font-weight: 650; cursor: pointer; padding: 0; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Pantallas medianas ---------- */
@media (max-width: 1100px) {
  .main { padding: 26px 24px 64px; }
  .top-row, .grid-2, .grid-2.even { grid-template-columns: minmax(0, 1fr); }
  .tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .acc-row { grid-template-columns: minmax(0, 1.5fr) 120px auto; }
  .acc-share { display: none; }
}

/* ---------- Móvil: barra de navegación inferior ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; height: auto; z-index: 50; flex-direction: row; gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border);
  }
  .brand, .sidebar-foot { display: none; }
  .nav { grid-template-columns: repeat(5, 1fr); width: 100%; }
  .nav a { flex-direction: column; gap: 3px; font-size: 11px; padding: 6px 2px; text-align: center; }
  .main { padding: 18px 14px 120px; }
  .fab { display: grid; }
  .toasts { bottom: 92px; }
  h1 { font-size: 22px; }
  .head-actions [data-act="new-tx"]:not([data-repeat]) { display: none; } /* ya está el botón flotante */
  .c-note { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tiles:not(.four) .tile:last-child { grid-column: 1 / -1; }
  .steps { grid-template-columns: 1fr; }
  .welcome { padding: 28px 18px; margin: 2vh auto; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .acc-row { grid-template-columns: minmax(0, 1fr) auto; }
  .acc-bal { text-align: right; }
  .acc-act { grid-column: 1 / -1; justify-content: flex-start; margin-top: -4px; }
  .item-grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .tbl th, .tbl td { padding: 10px 8px; }
  .filters > * { flex: 1 1 100%; }
  /* La tabla de movimientos pasa a lista compacta: categoría + importe, y debajo fecha y elemento */
  .tbl.tx thead { display: none; }
  .tbl.tx, .tbl.tx tbody { display: block; }
  .tbl.tx tr {
    display: grid; grid-template-columns: 88px minmax(0, 1fr) auto auto; align-items: center; column-gap: 10px; row-gap: 2px;
    grid-template-areas: "cat cat amt act" "date item item act" "note note note note"; padding: 11px 14px; border-bottom: 1px solid var(--border);
  }
  .tbl.tx .c-note { grid-area: note; max-width: none; white-space: normal; font-size: 12.5px; margin-top: 2px; }
  .tbl.tx .c-note:empty { display: none; }
  .tbl.tx tbody tr:last-child { border-bottom: 0; }
  .tbl.tx td, .tbl.tx td:first-child, .tbl.tx td:last-child { display: block; padding: 0; border: 0; }
  .tbl.tx .c-cat { grid-area: cat; font-weight: 600; }
  .tbl.tx .c-date { grid-area: date; font-size: 12.5px; }
  .tbl.tx .c-item { grid-area: item; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
  .tbl.tx .dot { width: 8px; height: 8px; margin-right: 6px; }
  .tbl.tx .amt { grid-area: amt; }
  .tbl.tx .c-act { grid-area: act; }
  .flush .tbl th:first-child, .flush .tbl td:first-child { padding-left: 0; }
  /* Stock y pedidos: tarjetas compactas */
  .tbl.stock thead, .tbl.orders thead { display: none; }
  .tbl.stock, .tbl.stock tbody, .tbl.orders, .tbl.orders tbody { display: block; }
  .tbl.stock tr, .tbl.orders tr { display: grid; align-items: center; column-gap: 12px; row-gap: 4px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .tbl.stock tbody tr:last-child, .tbl.orders tbody tr:last-child { border-bottom: 0; }
  .tbl.stock td, .tbl.orders td, .tbl.stock td:first-child, .tbl.orders td:first-child, .tbl.stock td:last-child, .tbl.orders td:last-child { display: block; padding: 0; border: 0; }
  .tbl.stock tr { grid-template-columns: auto auto minmax(0, 1fr) auto; grid-template-areas: "prod prod prod qty" "ref price pend pend" "state state state act"; }
  .tbl.stock .c-prod { grid-area: prod; } .tbl.stock .c-ref { grid-area: ref; } .tbl.stock .c-price { grid-area: price; text-align: left; }
  .tbl.stock .c-price .sub { text-align: left; }
  .tbl.stock .c-qty { grid-area: qty; } .tbl.stock .c-pend { grid-area: pend; } .tbl.stock .c-state { grid-area: state; } .tbl.stock .c-act { grid-area: act; }
  .tbl.orders tr { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "prod qty" "exp exp" "sup sup" "act act"; }
  .tbl.orders .c-prod { grid-area: prod; } .tbl.orders .c-oqty { grid-area: qty; } .tbl.orders .c-exp { grid-area: exp; font-size: 13px; }
  .tbl.orders .c-sup { grid-area: sup; font-size: 13px; } .tbl.orders .c-ordered { display: none; } .tbl.orders .c-act { grid-area: act; text-align: left; margin-top: 4px; }
  .card-head.pad { padding: 14px 14px 4px; }
}
@media print {
  .sidebar, .fab, .head-actions, .toasts { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
}
