:root {
  color-scheme: light;
  --surface-0: #f3f2ef;
  --surface-1: #fcfcfb;
  --surface-2: #ecebe7;
  --border: #dddcd6;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7973;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0a7d3c;
  --bad: #c43d3c;
  --grid: #e6e5e0;
  /* categorías (paleta categórica validada, orden fijo) */
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --series-otro: #a3a29b;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-0: #111110;
    --surface-1: #1a1a19;
    --surface-2: #262624;
    --border: #34332f;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #3987e5;
    --good: #4cc47e;
    --bad: #ef7474;
    --grid: #2c2c29;
    --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-otro: #6e6d67;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--surface-0); color: var(--text-primary);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-card h1 { margin: 8px 0 24px; font-size: 28px; }
.logo { width: 72px; height: 72px; margin: 0 auto; border-radius: 20px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 38px; font-weight: 700; }
.login-card form { display: grid; gap: 12px; }
.error { color: var(--bad); min-height: 1.4em; margin: 0; }

/* ---------- layout ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--surface-0) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.topbar h1 { font-size: 24px; margin: 0; letter-spacing: -0.01em; flex: 1; }
.icon-btn.gear { font-size: 16px; }
.mes-nav { display: flex; align-items: center; gap: 2px; font-weight: 600; font-size: 15px; }
.mes-nav span { min-width: 112px; text-align: center; }
.icon-btn { border: 0; background: var(--surface-2); width: 32px; height: 32px; border-radius: 50%; font-size: 20px; line-height: 1; cursor: pointer; }
main { padding: 4px 16px calc(env(safe-area-inset-bottom) + 96px); max-width: 720px; margin: 0 auto; }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(6, 1fr);
  background: color-mix(in srgb, var(--surface-1) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { border: 0; background: none; padding: 7px 0 6px; font-size: 10.5px; color: var(--text-muted); display: grid; justify-items: center; gap: 1px; cursor: pointer; }
.tabbar button .ti { font-size: 20px; filter: grayscale(1); opacity: .6; }
.tabbar button.active { color: var(--accent); font-weight: 600; }
.tabbar button.active .ti { filter: none; opacity: 1; }

.fab { position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom) + 72px); z-index: 25; width: 58px; height: 58px; border-radius: 50%;
  border: 0; background: var(--accent); color: #fff; font-size: 32px; line-height: 1; box-shadow: 0 6px 18px rgba(0,0,0,.22); cursor: pointer; }

/* ---------- tarjetas ---------- */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; margin: 12px 0; }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--text-secondary); font-weight: 600; }
.card h3 { font-size: 17px; margin: 0; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; }
.tile .lbl { font-size: 12.5px; color: var(--text-secondary); }
.tile .val { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.tile.wide { grid-column: span 2; }
.pos { color: var(--good); } .neg { color: var(--bad); }

.hero { text-align: center; padding: 18px 16px; }
.hero .lbl { color: var(--text-secondary); font-size: 14px; }
.hero .val { font-size: 30px; font-weight: 700; margin: 4px 0 10px; }

.chart-box { position: relative; height: 220px; }
.chart-box.tall { height: 240px; }
.pie-wrap { display: grid; gap: 14px; }
.pie-wrap .chart-box { height: 180px; }
@media (min-width: 520px) { .pie-wrap { grid-template-columns: 200px 1fr; align-items: center; } .pie-wrap .chart-box { height: 200px; } }
.legend { display: grid; gap: 6px; font-size: 14px; }
.legend .row { display: flex; align-items: center; gap: 8px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .name { flex: 1; text-transform: capitalize; color: var(--text-primary); }
.legend .pct { color: var(--text-muted); font-size: 13px; min-width: 40px; text-align: right; }
.vacio { color: var(--text-muted); text-align: center; padding: 18px 0; font-size: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 12.5px; padding: 6px 4px; border-bottom: 1px solid var(--border); }
td { padding: 8px 4px; border-bottom: 1px solid var(--grid); }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 650; border-bottom: 0; }
td.cap { text-transform: capitalize; }
td.cap, .mes-cell { white-space: nowrap; }

/* ---------- listas ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.list li:last-child { border-bottom: 0; }
.list .ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; font-size: 17px; background: var(--surface-2); }
.list .main { flex: 1; min-width: 0; }
.list .t { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .s { font-size: 12.5px; color: var(--text-muted); }
.list .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list li.click { cursor: pointer; }

.chip { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--text-secondary); margin-left: 4px; vertical-align: 1px; }

/* ---------- botones / formularios ---------- */
.btn { border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row-btns .btn { flex: 1; }

input, select, textarea { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-1); font-size: 16px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.f { display: grid; gap: 5px; font-size: 13px; color: var(--text-secondary); margin: 10px 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.check { display: flex; align-items: center; gap: 10px; margin: 12px 0; font-size: 15px; }
.check input { width: 22px; height: 22px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; margin: 8px 0; }
.seg button { border: 0; background: none; padding: 8px 4px; border-radius: 9px; font-weight: 600; font-size: 14.5px; color: var(--text-secondary); cursor: pointer; }
.seg button.on { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.big-amount { font-size: 38px; font-weight: 700; text-align: center; border: 0; background: none; padding: 8px 0; }
.big-amount:focus { outline: none; }
.cats { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.cats button { border: 1px solid var(--border); background: var(--surface-1); border-radius: 99px; padding: 7px 13px; font-size: 14.5px; text-transform: capitalize; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.cats button .sw { width: 9px; height: 9px; border-radius: 3px; }
.cats button.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface-1)); font-weight: 600; }

/* ---------- hoja modal ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.38); z-index: 40; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--surface-0); border-radius: 20px 20px 0 0;
  max-height: 92vh; overflow-y: auto; padding: 8px 18px calc(env(safe-area-inset-bottom) + 18px); max-width: 720px; margin: 0 auto;
  animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 10px; }
.sheet h2 { margin: 4px 0 8px; font-size: 20px; }

.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 4px; }
.kv { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; }
.kv span:first-child { color: var(--text-secondary); }
.kv span:last-child { font-variant-numeric: tabular-nums; font-weight: 550; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 140px); z-index: 60;
  background: var(--text-primary); color: var(--surface-1); padding: 10px 16px; border-radius: 12px; font-size: 14.5px; max-width: 90vw; text-align: center; white-space: pre-line; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; word-break: break-all; background: var(--surface-2); padding: 10px; border-radius: 10px; user-select: all; }
.muted { color: var(--text-muted); font-size: 13.5px; }

/* ---------- agenda ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal .dow { text-align: center; font-size: 11.5px; color: var(--text-muted); padding: 2px 0 6px; font-weight: 600; }
.cal .d { min-height: 52px; border-radius: 10px; padding: 4px 2px 3px; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; border: 0; background: none; }
.cal .d .n { font-size: 14.5px; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; font-variant-numeric: tabular-nums; }
.cal .d.fuera .n { color: var(--text-muted); opacity: .45; }
.cal .d.hoy .n { background: var(--accent); color: #fff; font-weight: 700; }
.cal .d.sel { background: var(--surface-2); }
.cal .marks { display: flex; gap: 3px; height: 6px; align-items: center; }
.cal .mk { width: 6px; height: 6px; border-radius: 50%; }
.cal .bar { width: 100%; height: 4px; border-radius: 2px; background: var(--series-3); }
.mk.ev { background: var(--accent); }
.mk.fijo { background: var(--series-2); border-radius: 1px; transform: rotate(45deg); width: 5px; height: 5px; }
.cal-leyenda { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-secondary); margin-top: 10px; }
.cal-leyenda span { display: inline-flex; align-items: center; gap: 5px; }
.cal-leyenda .bar { display: inline-block; width: 14px; height: 4px; border-radius: 2px; background: var(--series-3); }
.hora-col { width: 46px; flex: none; font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; text-align: center; line-height: 1.2; }
.avisos-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.avisos-chips button { border: 1px solid var(--border); background: var(--surface-1); border-radius: 99px; padding: 6px 11px; font-size: 14px; cursor: pointer; }
.avisos-chips button.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface-1)); font-weight: 600; }
textarea { min-height: 70px; resize: vertical; }
.form-grid > * { min-width: 0; }

/* ---------- sin conexión ---------- */
.offline { position: sticky; top: calc(env(safe-area-inset-top) + 54px); z-index: 9; margin: 0 16px; padding: 8px 12px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 13.5px; color: var(--text-secondary); display: block; line-height: 1.45; }
.offline b { color: var(--text-primary); font-weight: 600; }
