@font-face { font-family: "Bricolage"; src: url(fonts/bricolage.woff2) format("woff2"); font-weight: 200 800; font-display: swap; }

:root {
  color-scheme: light;
  --bg: #e7ece4;
  --surface: #f6f8f3;
  --surface-2: #dde4d9;
  --line: #c9d3c5;
  --ink: #14231f;
  --ink-2: #44544e;
  --muted: #64736d;
  --accent: #14231f;
  --on-accent: #eef3ea;
  --in: #0f7a55;
  --warn-bg: #f3d46b;
  --warn-ink: #3b2e00;
  --danger: #b3261e;
  --s1: #2a78d6;           /* serie principal (este mes) */
  --s0: #9aa69f;           /* serie de contexto (mes anterior) */
  --h1: #cde2fb; --h2: #9ec5f4; --h3: #6da7ec; --h4: #3987e5; --h5: #256abf; --h6: #184f95; --h7: #0d366b;
  --radius: 14px;
  --nav-h: 64px;
  --font-d: "Bricolage", system-ui, sans-serif;
  --font-b: "Bricolage", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111b18; --surface: #18241f; --surface-2: #223029; --line: #2e3d37;
    --ink: #e4ece7; --ink-2: #b6c4bd; --muted: #8fa29a;
    --accent: #dfe9e2; --on-accent: #111b18; --in: #4cc392;
    --warn-bg: #e2bd3e; --warn-ink: #2a2000; --danger: #ff8a80;
    --s1: #3987e5; --s0: #5f6f68;
    --h1: #1a2d44; --h2: #184f95; --h3: #1c5cab; --h4: #2a78d6; --h5: #5598e7; --h6: #86b6ef; --h7: #cde2fb;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111b18; --surface: #18241f; --surface-2: #223029; --line: #2e3d37;
  --ink: #e4ece7; --ink-2: #b6c4bd; --muted: #8fa29a;
  --accent: #dfe9e2; --on-accent: #111b18; --in: #4cc392;
  --warn-bg: #e2bd3e; --warn-ink: #2a2000; --danger: #ff8a80;
  --s1: #3987e5; --s0: #5f6f68;
  --h1: #1a2d44; --h2: #184f95; --h3: #1c5cab; --h4: #2a78d6; --h5: #5598e7; --h6: #86b6ef; --h7: #cde2fb;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.45 var(--font-b); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--font-d); font-weight: 650; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 1.15rem; }
.num, .item .a, .calc td, .bar-row .v, .kv dd, .heat td, .tip, .chart svg text, .mp-card, .amount-input { font-family: var(--font-d); font-variant-numeric: tabular-nums; }
.item .t > span, .muted.small, p.small { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.in { color: var(--in); }
:focus-visible { outline: 2px solid var(--s1); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Estructura ---------- */
#app { min-height: 100dvh; }
main { padding: 12px 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); max-width: 1120px; margin: 0 auto; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0 6px; }
.top h1 { font-size: 1.5rem; }
.back { border: 0; background: none; padding: 6px 8px 6px 0; font-weight: 700; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }

nav.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 900; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
}
nav.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; font-size: .72rem; color: var(--muted); padding: 6px 0; }
nav.tabs a.on { color: var(--ink); font-weight: 700; }
nav.tabs svg { width: 24px; height: 24px; }
nav.tabs a.add span.plus {
  width: 52px; height: 52px; border-radius: 18px; background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; margin-top: -26px; box-shadow: 0 0 0 5px var(--bg);
}
nav.tabs a.add svg { width: 26px; height: 26px; }
nav.tabs .badge { position: absolute; transform: translate(12px, -6px); background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; font-size: .68rem; padding: 0 6px; font-weight: 700; }

@media (min-width: 900px) {
  nav.tabs { inset: 0 auto 0 0; width: 96px; height: auto; grid-template-columns: 1fr; grid-auto-rows: 76px; align-content: start; padding-top: 18px; border-top: 0; border-right: 1px solid var(--line); }
  nav.tabs a.add span.plus { margin-top: 0; box-shadow: none; }
  main { padding: 16px 32px 48px 128px; max-width: 1240px; }
}

/* ---------- Bloques ---------- */
.panel { background: var(--surface); border-radius: var(--radius); padding: 16px; }
.panel + .panel, .stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 12px; }
.grid > *, .bar-row > * { min-width: 0; }
@media (min-width: 900px) {
  .grid.two { grid-template-columns: 1.25fr 1fr; align-items: start; }
  .grid.two > .panel + .panel { margin-top: 0; }
}
.panel h2 { margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

/* Hero del mes */
.hero { padding: 6px 0 14px; }
.month-switch { display: flex; align-items: center; gap: 4px; }
.month-switch button { border: 0; background: var(--surface); width: 36px; height: 36px; border-radius: 12px; cursor: pointer; font-size: 1.1rem; }
.month-switch strong { font-family: var(--font-d); font-size: 1.05rem; min-width: 118px; text-align: center; }
.hero .big { font-family: var(--font-d); font-weight: 700; font-size: clamp(3rem, 15vw, 5.6rem); line-height: .95; letter-spacing: -0.035em; font-stretch: 85%; margin: 14px 0 6px; font-variant-numeric: tabular-nums; }
.hero .big small { font-size: .42em; letter-spacing: 0; vertical-align: .9em; margin-right: .08em; font-weight: 600; }
.hero .sub { color: var(--ink-2); }

.pending {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; text-decoration: none;
  background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius); padding: 12px 16px; font-weight: 700; margin-bottom: 12px;
}

.hora-mini { display: flex; justify-content: space-between; align-items: end; text-decoration: none; }
.hora-mini .v { font-family: var(--font-d); font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; }

/* ---------- Gráficos ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.legend { display: flex; gap: 14px; font-size: .82rem; color: var(--ink-2); margin-bottom: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); padding: 6px 9px; border-radius: 8px;
  font-size: .8rem; white-space: nowrap; transform: translate(-50%, -110%); z-index: 5;
}

.bars { display: grid; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(96px, 34%) 1fr auto; gap: 10px; align-items: center; text-decoration: none; }
.bar-row .lbl { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-row .lbl span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.bar-track { height: 12px; position: relative; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: var(--s1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .v { font-size: .9rem; text-align: right; font-variant-numeric: tabular-nums; }
.bar-row .v small { color: var(--muted); margin-left: 6px; }

.heat { overflow-x: auto; }
.heat table { border-collapse: separate; border-spacing: 2px; width: 100%; font-size: .8rem; }
.heat th { font-weight: 400; color: var(--muted); text-align: left; padding: 2px 6px 2px 0; white-space: nowrap; }
.heat thead th { text-align: center; text-transform: capitalize; }
.heat td { height: 30px; min-width: 44px; border-radius: 4px; text-align: center; font-variant-numeric: tabular-nums; cursor: default; }
.heat td.dark { color: #fff; }
.heat td.light { color: #0d1f33; }
.heat .scale { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: .75rem; color: var(--muted); }
.heat .scale i { width: 18px; height: 10px; border-radius: 2px; display: inline-block; }

/* ---------- Listas ---------- */
.day { margin-top: 14px; }
.day h3 { font-family: var(--font-d); font-weight: 600; font-size: .9rem; color: var(--muted); margin: 0 0 6px 4px; }
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.item { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; text-decoration: none; border-top: 1px solid var(--line); cursor: pointer; }
.item:first-child { border-top: 0; }
.item .ic { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-family: var(--font-d); background: var(--surface-2); }
.item .t { min-width: 0; }
.item .t > b, .item .t > span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .t > span { font-size: .84rem; color: var(--muted); }
.item .a { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.item .a span { display: block; font-weight: 400; font-size: .78rem; color: var(--muted); }
.flag { display: inline-block; background: var(--warn-bg); color: var(--warn-ink); border-radius: 6px; padding: 0 6px; font-size: .72rem; font-weight: 700; margin-left: 6px; vertical-align: 1px; }

.search { display: flex; gap: 8px; margin: 6px 0 4px; }
.search input { flex: 1; }

/* ---------- Formularios ---------- */
label.f { display: block; margin-top: 14px; }
label.f > span { display: block; font-size: .85rem; color: var(--ink-2); margin-bottom: 6px; font-weight: 700; }
input[type=text], input[type=search], input[type=number], input[type=password], input[type=datetime-local], input[type=date], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 13px; min-height: 48px;
}
textarea { min-height: 70px; }
.amount-input { font-family: var(--font-d); font-size: 2.6rem; font-weight: 700; border: 0 !important; background: none !important; padding: 0 !important; letter-spacing: -0.02em; }
.btn { border: 0; border-radius: 12px; min-height: 48px; padding: 0 18px; font-weight: 700; cursor: pointer; background: var(--surface-2); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: .88rem; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 13px 8px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; font-size: .92rem; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.seg { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 12px; }
.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 700; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); }
.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 14px; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--ink); }
.sticky-save { position: sticky; bottom: calc(var(--nav-h) + 10px + env(safe-area-inset-bottom)); margin-top: 18px; }
@media (min-width: 900px) { .sticky-save { bottom: 16px; } }

.mp-card { background: var(--surface-2); border-radius: var(--radius); padding: 14px 16px; }
.mp-card .amt { font-family: var(--font-d); font-size: 2.4rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.05; }

/* ---------- Mi hora ---------- */
.hora-hero { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hora-hero .panel { margin: 0; }
.hora-hero .v { font-family: var(--font-d); font-size: clamp(2rem, 9vw, 3.4rem); font-weight: 700; letter-spacing: -0.03em; line-height: 1; margin: 6px 0; font-variant-numeric: tabular-nums; }
.calc { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.calc td, .calc th { padding: 9px 4px; border-top: 1px solid var(--line); text-align: right; }
.calc th { font-weight: 400; color: var(--muted); font-size: .82rem; border-top: 0; }
.calc td:first-child, .calc th:first-child { text-align: left; }
.calc tr.tot td { font-weight: 700; }
.calc tr.grp td { border-top: 0; padding-top: 18px; font-family: var(--font-d); font-weight: 650; font-size: 1.02rem; }
.calc .share { font-size: .78rem; color: var(--muted); display: block; }
.calc button.edit { border: 0; background: none; padding: 0; text-align: left; cursor: pointer; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }

/* ---------- Mapa ---------- */
#map { height: calc(100dvh - 210px); min-height: 340px; border-radius: var(--radius); z-index: 1; }
.pick-map { height: 260px; border-radius: 12px; margin-top: 8px; z-index: 1; }
.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-popup-content { margin: 12px 14px; }
.leaflet-popup-content b { font-family: var(--font-d); font-size: 1.05rem; }
.place-pin { background: var(--s1); border: 2px solid var(--surface); border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.3); }

/* ---------- Login / toasts / hoja ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(360px, 100%); }
.login h1 { font-size: 3.4rem; letter-spacing: -0.04em; margin-bottom: 4px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 22px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; z-index: 2000; font-weight: 700; max-width: calc(100% - 32px); }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
details summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.ac { position: relative; }
.ac ul { position: absolute; left: 0; right: 0; top: 100%; z-index: 50; margin: 4px 0 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; max-height: 240px; overflow: auto; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.ac li { padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.ac li:hover, .ac li.sel { background: var(--surface-2); }

@media (prefers-reduced-motion: no-preference) {
  .hero .big { animation: rise .5s cubic-bezier(.2,.8,.2,1); }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
}
.search .ac { flex: 1; }
