/* ============ Tokens ============ */
:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f0f1f8;
  --text: #171a2c;
  --muted: #6b7088;
  --line: #e7e8f1;
  --accent: #5b4cf0;
  --accent-2: #7c6cff;
  --accent-soft: #ecebff;
  --ef: #12a36d;
  --ef-soft: #e3f6ee;
  --bz: #0b93c9;
  --bz-soft: #e1f3fb;
  --neg: #e5484d;
  --neg-soft: #fdecec;
  --warn: #a16207;
  --warn-soft: #fdf6e3;
  --shadow: 0 1px 2px rgba(23, 26, 44, .04), 0 4px 16px rgba(23, 26, 44, .06);
  --shadow-lg: 0 12px 40px rgba(23, 26, 44, .18);
  --r: 18px;
  --r-sm: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1020;
    --surface: #181a2e;
    --surface-2: #20233a;
    --text: #eceefa;
    --muted: #9a9fbc;
    --line: #2a2d47;
    --accent: #8b7dff;
    --accent-2: #a69bff;
    --accent-soft: #2a2752;
    --ef: #3ccf91;
    --ef-soft: #16352b;
    --bz: #3cc0ef;
    --bz-soft: #13304060;
    --neg: #ff6b6f;
    --neg-soft: #3a1d24;
    --warn: #f3c66b;
    --warn-soft: #3a3020;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  }
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.6rem; letter-spacing: -.02em; margin: .25rem 0 1.1rem; }
h2 { font-size: 1.05rem; letter-spacing: -.01em; margin: 1.8rem 0 .7rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
code { background: var(--surface-2); padding: .1rem .4rem; border-radius: 6px; font-size: .95em; }
.big-code { font-size: 1.25rem; font-weight: 700; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.neg { color: var(--neg) !important; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
.ic { width: 20px; height: 20px; flex: none; }

.wrap { max-width: 980px; margin: 0 auto; padding: 1.1rem 1rem 2rem; }
body.has-nav .wrap { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
@media (min-width: 861px) { body.has-nav .wrap { padding-bottom: 3rem; padding-top: 1.8rem; } }

/* ============ Header ============ */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem 1rem; padding-top: calc(.7rem + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--text); font-weight: 800; letter-spacing: -.02em; font-size: 1.05rem; }
.brand img { width: 30px; height: 30px; border-radius: 9px; }
.desk-nav { display: none; gap: .25rem; margin-left: .5rem; }
.desk-nav a { color: var(--muted); padding: .45rem .8rem; border-radius: 999px; font-weight: 600; font-size: .93rem; }
.desk-nav a:hover { color: var(--text); background: var(--surface-2); }
.desk-nav a.active { color: var(--accent); background: var(--accent-soft); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.desk-only { display: none !important; }
@media (min-width: 861px) {
  .desk-nav { display: flex; }
  .desk-only { display: inline-flex !important; }
}

.avatar {
  width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; font-weight: 800; font-size: 1rem;
  color: #fff; background: linear-gradient(135deg, var(--accent), #c05cf0);
}
.avatar.big { width: 46px; height: 46px; font-size: 1.15rem; cursor: default; }
.avatar.soft { color: var(--accent); background: var(--accent-soft); cursor: default; }

/* ============ Tab bar (móvil) ============ */
.tabbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; align-items: center; justify-content: space-around;
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: var(--shadow-lg); padding: 6px 8px; height: 68px;
}
.tabbar a, .tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: .7rem; font-weight: 600; background: none; border: 0; cursor: pointer; font-family: inherit; padding: 6px 0;
}
.tabbar .ic { width: 23px; height: 23px; }
.tabbar .active { color: var(--accent); }
.tabbar .tab-plus {
  flex: none; width: 56px; height: 56px; border-radius: 18px; margin: 0 6px;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent);
  justify-content: center;
}
.tabbar .tab-plus .ic { width: 28px; height: 28px; stroke-width: 2.4; }
@media (min-width: 861px) { .tabbar { display: none; } }

/* ============ Sheet (menú "Más") ============ */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 12, 30, .4); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s; }
.sheet {
  position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-radius: 24px 24px 0 0; box-shadow: var(--shadow-lg);
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .25s ease;
}
@media (min-width: 861px) {
  .sheet { left: auto; right: 1rem; top: 64px; bottom: auto; width: 320px; border-radius: var(--r); transform: translateY(-8px); opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; }
}
body.sheet-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
body.sheet-open .sheet { transform: none; opacity: 1; pointer-events: auto; }
.sheet-head { display: flex; align-items: center; gap: .8rem; padding: .3rem .3rem 1rem; border-bottom: 1px solid var(--line); margin-bottom: .4rem; }
.sheet-head > div:nth-child(2) { display: flex; flex-direction: column; flex: 1; }
.sheet-head .muted { font-size: .85rem; }
.sheet form { margin: 0; }
.sheet-link {
  display: flex; align-items: center; gap: .85rem; width: 100%;
  padding: .85rem .5rem; border-radius: var(--r-sm); color: var(--text); font-weight: 600; font-size: 1rem;
  background: none; border: 0; cursor: pointer; font-family: inherit; text-align: left;
}
.sheet-link:hover { background: var(--surface-2); }
.sheet-link span { flex: 1; }
.sheet-link .ic { color: var(--muted); }
.sheet-link .chev { width: 16px; height: 16px; }
.danger-text, .danger-text .ic { color: var(--neg) !important; }

/* ============ Botones ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  background: var(--accent); color: #fff; border: 0; border-radius: 14px;
  padding: .75rem 1.15rem; font: inherit; font-weight: 700; font-size: .95rem; cursor: pointer;
  transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.98); }
.btn .ic { width: 18px; height: 18px; }
.btn.small { padding: .5rem .85rem; border-radius: 12px; font-size: .9rem; }
.btn.big { width: 100%; padding: 1rem 1.2rem; font-size: 1.05rem; border-radius: 16px; }
.btn.secondary, .btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--neg-soft); color: var(--neg); }
.btn:disabled { opacity: .6; cursor: wait; }
.icon-btn {
  width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 12px;
  background: var(--surface-2); color: var(--text); border: 0; cursor: pointer; flex: none;
}
.icon-btn .ic { width: 18px; height: 18px; }
.linklike { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-weight: 600; padding: 0; }
form.inline { display: inline; margin: 0; }
.danger-zone { margin-top: 1rem; text-align: center; }
.danger-zone .btn { background: none; color: var(--neg); }

/* ============ Tarjetas ============ */
.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 1.15rem; margin-bottom: 1rem; color: inherit; display: block; }
.card.narrow, .narrow { max-width: 540px; margin-left: auto; margin-right: auto; }
.card h1:first-child, .card h2:first-child { margin-top: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: .9rem; }
.cards .card { margin: 0; }
a.card { transition: transform .12s, box-shadow .12s; }
a.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.label { color: var(--muted); font-size: .82rem; font-weight: 600; }
.amount { font-size: 2rem; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.15; margin: .15rem 0 .1rem; }
.amount.xl { font-size: 2.6rem; }

.local-card { display: flex; flex-direction: column; gap: .55rem; }
.local-card .row-top { display: flex; align-items: center; justify-content: space-between; }
.local-card h3 { margin: 0; font-size: .98rem; }
.local-card .ic { color: var(--muted); width: 18px; height: 18px; }
.local-card .foot { display: flex; justify-content: space-between; font-size: .88rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: .6rem; }
.local-card .foot strong { color: var(--text); }

.pills { display: flex; gap: .4rem; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; font-weight: 700; padding: .3rem .65rem; border-radius: 999px; font-variant-numeric: tabular-nums; }
.pill .ic { width: 15px; height: 15px; }
.pill.ef { background: var(--ef-soft); color: var(--ef); }
.pill.bz { background: var(--bz-soft); color: var(--bz); }

.split-bar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--surface-2); margin: .7rem 0 .2rem; }
.split-bar .ef { background: var(--ef); }
.split-bar .bz { background: var(--bz); }

/* Tiles de resumen */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin-bottom: 1rem; }
.tiles.two { grid-template-columns: repeat(2, 1fr); }
.tile { background: var(--surface); border-radius: var(--r-sm); box-shadow: var(--shadow); padding: .75rem .85rem; min-width: 0; }
.tile span { display: block; color: var(--muted); font-size: .76rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile strong { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; letter-spacing: -.01em; white-space: nowrap; }
.tile.ef strong { color: var(--ef); }
.tile.bz strong { color: var(--bz); }
@media (min-width: 600px) { .tile strong { font-size: 1.25rem; } }

/* Hero (acción principal) */
.hero-action {
  display: flex; align-items: center; gap: 1rem; padding: 1.15rem 1.2rem; border-radius: var(--r); margin-bottom: 1.1rem;
  color: #fff; background: linear-gradient(135deg, var(--accent), #a35cf0);
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 35%, transparent);
}
.hero-action .plus { width: 46px; height: 46px; border-radius: 14px; background: rgba(255, 255, 255, .2); display: grid; place-items: center; }
.hero-action .plus .ic { width: 26px; height: 26px; stroke-width: 2.4; }
.hero-action strong { display: block; font-size: 1.1rem; }
.hero-action small { opacity: .85; }
.hero-action > .ic { margin-left: auto; opacity: .8; }
.quick { display: flex; gap: .6rem; margin: -.3rem 0 1.1rem; }
.quick .btn { flex: 1; }

/* ============ Listas ============ */
.list { list-style: none; margin: 0 0 1rem; padding: 0; background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.item { display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; color: inherit; }
a.item:hover { background: var(--surface-2); }
.item-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--muted); font-weight: 800; }
.item-icon.ef { background: var(--ef-soft); color: var(--ef); }
.item-icon.bz { background: var(--bz-soft); color: var(--bz); }
.item-icon.mix { background: var(--accent-soft); color: var(--accent); }
.item-icon.extra { background: var(--warn-soft); color: var(--warn); }
.item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item-main strong { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-main span { color: var(--muted); font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-end { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; flex: none; }
.item-end strong { font-variant-numeric: tabular-nums; font-weight: 750; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; margin: 1.3rem .25rem .45rem; font-size: .85rem; font-weight: 700; color: var(--muted); }
.day-head:first-of-type { margin-top: .3rem; }

.tag { font-size: .7rem; font-weight: 700; padding: .12rem .5rem; border-radius: 999px; }
.tag.ef { background: var(--ef-soft); color: var(--ef); }
.tag.bz { background: var(--bz-soft); color: var(--bz); }
.tag.mix { background: var(--accent-soft); color: var(--accent); }
.tag.grey { background: var(--surface-2); color: var(--muted); }

.empty { text-align: center; padding: 2.2rem 1rem; color: var(--muted); background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); }

/* ============ Formularios ============ */
.form { display: flex; flex-direction: column; gap: 1rem; }
.form label, .filters label { display: flex; flex-direction: column; gap: .35rem; font-weight: 650; font-size: .88rem; color: var(--muted); }
label.check { flex-direction: row !important; align-items: center; gap: .55rem; font-weight: 600; color: var(--text) !important; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 420px) { .row { grid-template-columns: 1fr; } }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); width: 100%;
  padding: .75rem .85rem; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
select { appearance: none; -webkit-appearance: none; padding-right: 2.2rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7088' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; background-size: 18px; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
input.money { font-size: 1.7rem; font-weight: 800; text-align: center; letter-spacing: -.02em; padding: .8rem; }
.row input.money { font-size: 1.3rem; }
input.pct { max-width: 6rem; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 650; font-size: .88rem; color: var(--muted); margin-bottom: .4rem; padding: 0; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: .5rem; }
.segmented legend { grid-column: 1 / -1; }
.segmented label { margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; flex-direction: column; align-items: center; gap: .3rem; text-align: center;
  padding: .8rem .4rem; border: 1.5px solid var(--line); border-radius: 14px; cursor: pointer;
  font-weight: 700; color: var(--text); background: var(--surface); font-size: .92rem;
  transition: all .12s;
}
.segmented span .ic { width: 22px; height: 22px; color: var(--muted); }
.segmented input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.segmented input:checked + span .ic { color: var(--accent); }
.segmented input:focus-visible + span { box-shadow: 0 0 0 4px var(--accent-soft); }

.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters select { width: auto; flex: 1; min-width: 12rem; font-weight: 650; }
.month-switch { display: flex; align-items: center; gap: .4rem; background: var(--surface); border-radius: 14px; padding: 4px; box-shadow: var(--shadow); }
.month-switch span { min-width: 9.5rem; text-align: center; font-weight: 700; font-size: .95rem; }
.month-switch .icon-btn { width: 34px; height: 34px; background: none; }
.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .5rem; }
.inline-form input:not([type=checkbox]) { width: auto; flex: 1; min-width: 11rem; }
.title-input { font-weight: 800; font-size: 1.05rem; }

details.more { margin-top: .6rem; }
details.more summary { cursor: pointer; color: var(--accent); font-weight: 650; font-size: .88rem; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more[open] summary { margin-bottom: .5rem; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: .25rem 1rem; font-size: .9rem; }
.kv span { color: var(--muted); }
.kv strong { text-align: right; font-variant-numeric: tabular-nums; }

/* ============ Tablas ============ */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); margin-bottom: 1rem; }
.card .table-wrap { box-shadow: none; border-radius: 0; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .7rem .9rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; font-weight: 700; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot th { border-top: 1.5px solid var(--line); border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table.compact td, .table.compact th { padding: .45rem .5rem; }
.table tr.inactive { opacity: .5; }
.notes { max-width: 22rem; font-size: .85rem; }

.head-row { display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.head-row h1, .head-row h2 { margin: 0; }
.head-row > div { display: flex; gap: .5rem; flex-wrap: wrap; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.back { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); font-weight: 600; font-size: .9rem; margin-bottom: .4rem; }
.back .ic { width: 16px; height: 16px; }

/* ============ Avisos ============ */
.flash { padding: .8rem 1rem; border-radius: var(--r-sm); margin: 0 0 1rem; font-weight: 600; font-size: .93rem; }
.flash-ok { background: var(--ef-soft); color: var(--ef); }
.flash-warn { background: var(--warn-soft); color: var(--warn); }
.flash-error { background: var(--neg-soft); color: var(--neg); }

/* ============ Login ============ */
.login { min-height: 88vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.2rem; }
.login .logo { width: 64px; height: 64px; border-radius: 18px; box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 35%, transparent); }
.login .card { width: 100%; max-width: 380px; padding: 1.5rem; }
.login h1 { text-align: center; margin: 0; }
.login p { text-align: center; margin: -.6rem 0 0; }
