/* Diseño: barra lateral + contenido con scroll propio, tarjetas con borde fino, números tabulares. */
:root {
  color-scheme: light;
  --bg: #f5f6f8; --card: #ffffff; --ink: #0f1419; --ink2: #4a5260; --muted: #6a7280;
  --line: #e4e7ec; --axis: #c9ced6; --hover: rgba(15, 20, 25, 0.05);
  --accent: #256abf; --accent-soft: rgba(37, 106, 191, 0.10);
  --inc: #2a78d6; --exp: #eb6834;
  --cat1: #d24c49; --cat2: #5d9300; --cat3: #008cd6; --cat4: #bf50a0; --cat5: #ae7400; --cat6: #009e97; --cat7: #8a66d9; --cat8: #d05320; --cat9: #279936; --cat10: #0083e0; --cat11: #ca4b85; --cat12: #998000; --cat13: #009ab0; --cat14: #9f5dcb; --cat15: #c95d00; --cat16: #009d5b; --cat17: #4d79e4; --cat18: #d04a69; --cat19: #7f8a00; --cat20: #0094c5; --cat21: #b156b7; --cat22: #be6800; --cat23: #009f7a; --cat24: #6f6fe2;
  --good-text: #006300; --good-bg: #e6f4e6; --bad-text: #b3261e; --bad-bg: #fdeceb;
  --warn-text: #8a5a00; --warn-bg: #fff3d6; --flat-text: #4a5260; --flat-bg: #eef0f3;
  --overlay: rgba(15, 20, 25, 0.45); --shadow: 0 8px 30px rgba(15, 20, 25, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d0d; --card: #1a1a19; --ink: #f0efec; --ink2: #c3c2b7; --muted: #9d9b93;
    --line: #2c2c2a; --axis: #383835; --hover: rgba(255, 255, 255, 0.06);
    --accent: #3987e5; --accent-soft: rgba(57, 135, 229, 0.18);
    --inc: #3987e5; --exp: #d95926;
    --cat1: #f87e77; --cat2: #88ba4c; --cat3: #1bb5f8; --cat4: #e57fc5; --cat5: #d39f00; --cat6: #00c4bc; --cat7: #af93fb; --cat8: #f5835b; --cat9: #64c06a; --cat10: #55adff; --cat11: #ef7cac; --cat12: #bea90b; --cat13: #00c1d4; --cat14: #c48bee; --cat15: #ee8b3e; --cat16: #34c486; --cat17: #79a4ff; --cat18: #f67c92; --cat19: #a5b22e; --cat20: #00bce8; --cat21: #d684db; --cat22: #e39420; --cat23: #00c5a2; --cat24: #969bff;
    --good-text: #4fcf5b; --good-bg: rgba(12, 163, 12, 0.16); --bad-text: #f2908b; --bad-bg: rgba(230, 103, 103, 0.16);
    --warn-text: #f0c05a; --warn-bg: rgba(240, 192, 90, 0.14); --flat-text: #c3c2b7; --flat-bg: #262625;
    --overlay: rgba(0, 0, 0, 0.6); --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0d0d; --card: #1a1a19; --ink: #f0efec; --ink2: #c3c2b7; --muted: #9d9b93;
  --line: #2c2c2a; --axis: #383835; --hover: rgba(255, 255, 255, 0.06);
  --accent: #3987e5; --accent-soft: rgba(57, 135, 229, 0.18);
  --inc: #3987e5; --exp: #d95926;
  --cat1: #f87e77; --cat2: #88ba4c; --cat3: #1bb5f8; --cat4: #e57fc5; --cat5: #d39f00; --cat6: #00c4bc; --cat7: #af93fb; --cat8: #f5835b; --cat9: #64c06a; --cat10: #55adff; --cat11: #ef7cac; --cat12: #bea90b; --cat13: #00c1d4; --cat14: #c48bee; --cat15: #ee8b3e; --cat16: #34c486; --cat17: #79a4ff; --cat18: #f67c92; --cat19: #a5b22e; --cat20: #00bce8; --cat21: #d684db; --cat22: #e39420; --cat23: #00c5a2; --cat24: #969bff;
  --good-text: #4fcf5b; --good-bg: rgba(12, 163, 12, 0.16); --bad-text: #f2908b; --bad-bg: rgba(230, 103, 103, 0.16);
  --warn-text: #f0c05a; --warn-bg: rgba(240, 192, 90, 0.14); --flat-text: #c3c2b7; --flat-bg: #262625;
  --overlay: rgba(0, 0, 0, 0.6); --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---- Estructura ---- */
.app { display: flex; height: 100%; }
.sidebar { width: 252px; flex: none; display: flex; flex-direction: column; background: var(--card); border-right: 1px solid var(--line); height: 100%; overflow: hidden; padding-top: env(safe-area-inset-top, 0px); z-index: 40; }
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 8px; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 8px 10px; }
.sidebar-foot { border-top: 1px solid var(--line); padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)); }
.main { flex: 1; min-width: 0; height: 100%; overflow-y: auto; padding: 24px max(28px, env(safe-area-inset-right, 0px)) calc(40px + env(safe-area-inset-bottom, 0px)) 28px; }
.main-inner { max-width: 1200px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.topbar { display: none; }
.scrim { display: none; }
@media (max-width: 900px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; transform: translateX(-102%); transition: transform .2s; box-shadow: var(--shadow); width: min(86vw, 300px); }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 35; }
  .app { flex-direction: column; }
  .topbar { display: flex; align-items: center; gap: 10px; flex: none; padding: calc(8px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px)); background: var(--card); border-bottom: 1px solid var(--line); }
  .main { padding: 16px max(16px, env(safe-area-inset-right, 0px)) calc(32px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 0 10px; border-radius: 10px; color: var(--ink2); font-weight: 500; text-align: left; }
.nav-item:hover { background: var(--hover); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--bad-bg); color: var(--bad-text); font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.sidebar-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 10px 10px 4px; }
.acc-select { width: 100%; height: 40px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 0 10px; font-weight: 600; }

/* ---- Componentes ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; }
.card-title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.icon-box { width: 28px; height: 28px; border-radius: 8px; background: var(--flat-bg); color: var(--ink2); display: grid; place-items: center; flex: none; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 10px; font-size: 14px; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; transition: background-color .15s; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--bad-text); border-color: var(--bad-text); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-danger-solid { background: var(--bad-text); border-color: var(--bad-text); color: var(--card); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; display: inline-grid; place-items: center; color: var(--ink2); }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn.danger:hover { background: var(--bad-bg); color: var(--bad-text); }
.field { width: 100%; height: 38px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 0 10px; font-size: 14px; }
.field::placeholder { color: var(--muted); }
textarea.field { height: auto; padding: 8px 10px; resize: vertical; }
.label { display: block; font-size: 12px; font-weight: 600; color: var(--ink2); margin-bottom: 6px; }
.err { color: var(--bad-text); font-size: 12px; margin-top: 4px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--flat-bg); }
.seg button { height: 30px; padding: 0 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink2); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.chip { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip-good { background: var(--good-bg); color: var(--good-text); }
.chip-bad { background: var(--bad-bg); color: var(--bad-text); }
.chip-warn { background: var(--warn-bg); color: var(--warn-text); }
.chip-flat { background: var(--flat-bg); color: var(--flat-text); }
.chip-accent { background: var(--accent-soft); color: var(--accent); }
.progress { height: 8px; border-radius: 999px; background: var(--flat-bg); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--cat1); }
.tip { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 12px; box-shadow: var(--shadow); min-width: 170px; }
.tip-title { font-weight: 600; margin-bottom: 6px; }
.tip-row { display: flex; justify-content: space-between; gap: 16px; color: var(--ink2); padding: 2px 0; }
.tip-row span { display: inline-flex; align-items: center; gap: 6px; }
.tip-row b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.tip-net { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }
.note { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--flat-bg); color: var(--ink2); font-size: 13px; }
.note-warn { background: var(--warn-bg); color: var(--warn-text); }
.note-bad { background: var(--bad-bg); color: var(--bad-text); }
.empty { text-align: center; padding: 40px 16px; color: var(--ink2); }
.empty .icon-box { width: 44px; height: 44px; border-radius: 14px; margin: 0 auto 12px; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 12px; letter-spacing: 0.02em; white-space: nowrap; }
.data-table td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
.data-table th.num, .data-table td.num { text-align: right; }
.data-table tr.sel td { background: var(--accent-soft); }
.th-sort { display: inline-flex; align-items: center; gap: 4px; font: inherit; color: inherit; letter-spacing: inherit; }
.th-sort:hover { color: var(--ink); }
@media (max-width: 640px) {
  .data-table.stack thead { display: none; }
  .data-table.stack tr { display: block; border-top: 1px solid var(--line); padding: 10px 4px; }
  .data-table.stack td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 0; padding: 3px 8px; text-align: right; }
  .data-table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: none; }
  .data-table.stack td.no-label::before { content: none; }
  .data-table.stack td.num { text-align: right; }
}

.switch { position: relative; width: 40px; height: 24px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--axis); transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

.sw-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.sw-pick button { width: 26px; height: 26px; border-radius: 8px; border: 2px solid transparent; }
.sw-pick button[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px var(--card) inset; }
.avatar { border-radius: 999px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.row-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.row-item:first-child { border-top: 0; }

.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.cal-head { background: var(--card); padding: 8px 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-align: center; }
.cal-cell { background: var(--card); min-height: 92px; padding: 6px; text-align: left; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-cell:hover { background: var(--hover); }
.cal-cell.out { opacity: .45; }
.cal-cell.today .cal-num { background: var(--accent); color: #fff; }
.cal-cell.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-num { width: 22px; height: 22px; border-radius: 999px; display: grid; place-items: center; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cal-tag { font-size: 11px; line-height: 1.2; padding: 1px 5px; border-radius: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.cal-dots { display: none; gap: 3px; flex-wrap: wrap; }
.cal-dots i { width: 6px; height: 6px; border-radius: 50%; display: block; }
@media (max-width: 640px) {
  .cal-cell { min-height: 54px; padding: 4px; align-items: center; }
  .cal-tags { display: none; }
  .cal-dots { display: flex; justify-content: center; }
}

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 80; background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 16px; font-size: 14px; font-weight: 500; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.bad { background: var(--bad-text); color: var(--card); }
.offline-bar { background: var(--warn-bg); color: var(--warn-text); padding: 8px 16px; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; padding: 28px; }
pre.sample { background: var(--flat-bg); color: var(--ink2); border-radius: 10px; padding: 10px 12px; font-size: 11.5px; overflow-x: auto; }
.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); background: var(--flat-bg); }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }

.att-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--flat-bg); font-size: 13px; min-width: 0; }
.att-row a { color: var(--accent); text-decoration: none; }
.att-row a:hover { text-decoration: underline; }
.drop { border: 1.5px dashed var(--axis); border-radius: 12px; padding: 18px; text-align: center; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink2); cursor: pointer; }
.check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.bulk { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); border: 1px solid var(--line); font-size: 14px; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.link-btn:hover { color: var(--accent); text-decoration: underline; }
.move-row { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; min-height: 42px; flex-wrap: wrap; }
.ok { color: var(--good-text); font-size: 13px; }
.data-table tr.sel td { background: var(--accent-soft); }
.auth-logo { width: 44px; height: 44px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 14px; }
select.field { appearance: auto; }

.md-hide { display: none; }
@media (max-width: 900px) {
  .md-hide { display: inline-grid; margin-left: auto; }
  .main { flex: 1; height: auto; min-height: 0; }
}
html, body, #root { height: 100%; }
