/* Nuestra economía — estilos. Mobile-first, modo claro/oscuro según el sistema. */

:root {
    --bg: #f2f3f7;
    --card: #ffffff;
    --card-2: #f7f8fb;
    --text: #15171c;
    --muted: #6b7180;
    --line: #e3e5ec;
    --primary: #2f6bff;
    --primary-ink: #ffffff;
    --primary-soft: #e6eeff;
    --ok: #1f9d55;
    --ok-soft: #e3f6ea;
    --warn: #b7791f;
    --warn-soft: #fff4dc;
    --err: #d93a3a;
    --err-soft: #fde8e8;
    --shadow: 0 1px 2px rgba(20, 25, 40, .06), 0 4px 16px rgba(20, 25, 40, .05);
    --radius: 16px;
    --tabbar-h: 64px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1115;
        --card: #1a1d24;
        --card-2: #22262f;
        --text: #eef0f5;
        --muted: #9aa1b2;
        --line: #2c313c;
        --primary: #5b8cff;
        --primary-soft: #1f2a45;
        --ok: #4ccb7f;
        --ok-soft: #173225;
        --warn: #f0b44c;
        --warn-soft: #3a2e14;
        --err: #ff6b6b;
        --err-soft: #3d1c1f;
        --shadow: none;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
[hidden] { display: none !important; }

/* ---------- Estructura */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 8px;
    padding: calc(var(--safe-top) + 10px) 16px 10px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
}
.topbar h1 { flex: 1; font-size: 22px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
    border: 0; background: var(--card); width: 40px; height: 40px; border-radius: 50%;
    font-size: 26px; line-height: 1; display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow);
}
.view {
    max-width: 720px; margin: 0 auto;
    padding: 4px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
    outline: none;
}
.loading { padding: 40px 0; text-align: center; color: var(--muted); }

.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: flex; justify-content: space-around; align-items: center;
    height: calc(var(--tabbar-h) + var(--safe-bottom));
    padding: 0 max(8px, var(--safe-left)) var(--safe-bottom) max(8px, var(--safe-right));
    background: color-mix(in srgb, var(--card) 92%, transparent);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--line);
}
.tabbar a {
    flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 11px; color: var(--muted); padding: 6px 0; -webkit-tap-highlight-color: transparent;
}
.tabbar a .ti { font-size: 21px; filter: grayscale(1); opacity: .7; }
.tabbar a.active { color: var(--primary); font-weight: 600; }
.tabbar a.active .ti { filter: none; opacity: 1; }
.tabbar .tab-add .plus {
    width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center;
    background: var(--primary); color: var(--primary-ink); font-size: 34px; font-weight: 300; line-height: 1;
    box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 45%, transparent);
    margin-top: -18px;
}

.offline {
    position: fixed; top: 0; left: 0; right: 0; z-index: 50;
    padding: calc(var(--safe-top) + 8px) 16px 8px; text-align: center; font-size: 14px; font-weight: 600;
    background: var(--err); color: #fff;
}

.toast {
    position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); z-index: 60;
    transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
    max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px;
    background: #1d2129; color: #fff; font-size: 15px; box-shadow: 0 8px 30px rgba(0,0,0,.25);
    transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--err); }
.toast.ok { background: var(--ok); }

/* ---------- Tarjetas y listas */
.card {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px; margin: 12px 0;
}
.card.flush { padding: 0; overflow: hidden; }
.card h2, .section-title { font-size: 17px; font-weight: 700; margin-bottom: 10px; }
.section-title { margin: 22px 4px 6px; display: flex; justify-content: space-between; align-items: baseline; }
.section-title a, .section-title .muted { font-size: 14px; font-weight: 500; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.right { text-align: right; }
.pos { color: var(--ok); }
.neg { color: var(--err); }
.nowrap { white-space: nowrap; }
.mt { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 > * { min-width: 0; }
a.kpi { color: inherit; }
.sticky-save { position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 10px); z-index: 5; box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 35%, transparent); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li, .list > a, .item {
    display: flex; align-items: center; gap: 12px; padding: 12px 16px;
    border-bottom: 1px solid var(--line); color: inherit; min-height: 56px;
}
.list > li:last-child, .list > a:last-child { border-bottom: 0; }
.item .ico, .ico {
    width: 38px; height: 38px; flex: none; border-radius: 11px; display: grid; place-items: center; font-size: 20px;
    background: var(--card-2);
}
.item .main { flex: 1; min-width: 0; }
.item .t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .t2 { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .amt { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chev::after { content: '›'; color: var(--muted); font-size: 22px; margin-left: 4px; }

/* ---------- Inicio */
.hero { text-align: center; padding: 20px 16px; }
.hero .label { color: var(--muted); font-size: 14px; }
.hero .big { font-size: 38px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.kpi { background: var(--card-2); border-radius: 12px; padding: 10px 12px; text-align: left; }
.kpi .label { font-size: 12px; }
.kpis3 { grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpis3 .kpi { padding: 8px 10px; }
.kpis3 .val { font-size: 16px; }
.kpi .val { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sinrep { display: flex; align-items: center; gap: 12px; }
.sinrep .val { font-size: 22px; font-weight: 800; }

.bar { height: 8px; border-radius: 4px; background: var(--card-2); overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; border-radius: 4px; background: var(--primary); }
.bar.over > span { background: var(--err); }
.bar.full > span { background: var(--ok); }

.aviso { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; margin: 10px 0; font-size: 14px; }
.aviso.info { background: var(--primary-soft); }
.aviso.ok { background: var(--ok-soft); }
.aviso.error { background: var(--err-soft); }
.aviso.warn { background: var(--warn-soft); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--card-2); color: var(--muted); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.info { background: var(--primary-soft); color: var(--primary); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Botones y formularios */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 48px; padding: 0 18px; border-radius: 14px; border: 0; cursor: pointer;
    background: var(--card-2); color: var(--text); font-weight: 600; font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--err-soft); color: var(--err); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.btns .btn { flex: 1; }

.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px 4px; }
.input, select.input, textarea.input {
    width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 12px;
    border: 1px solid var(--line); background: var(--card); font-size: 16px; /* 16px evita el zoom de iOS */
    -webkit-appearance: none; appearance: none;
}
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
textarea.input { min-height: 90px; resize: vertical; }
.input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.field .error, .error-msg { color: var(--err); font-size: 13px; margin: 6px 4px 0; }
.field.has-error .input { border-color: var(--err); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }

.amount-input {
    width: 100%; max-width: 100%; field-sizing: content; min-width: 3ch; border: 0; background: transparent; text-align: center;
    font-size: 48px; font-weight: 800; letter-spacing: -.02em; padding: 8px 0; font-variant-numeric: tabular-nums;
}
.amount-input:focus { outline: none; }
.amount-wrap { display: flex; align-items: baseline; justify-content: center; }
.amount-wrap .cur { font-size: 32px; font-weight: 700; color: var(--muted); margin-left: 4px; }

.segmented { display: flex; background: var(--card-2); border-radius: 12px; padding: 3px; gap: 3px; }
.segmented button, .segmented a {
    flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 10px; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--text); text-align: center;
}
.segmented .on { background: var(--card); box-shadow: var(--shadow); color: var(--primary); }

.cats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 520px) { .cats { grid-template-columns: repeat(4, 1fr); } }
.cat {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    min-height: 78px; padding: 8px 4px; border-radius: 14px; border: 2px solid transparent;
    background: var(--card); box-shadow: var(--shadow); cursor: pointer; font-size: 12.5px; font-weight: 600; text-align: center; line-height: 1.15;
    -webkit-tap-highlight-color: transparent;
}
.cat .e { font-size: 26px; }
.cat.on { border-color: var(--primary); background: var(--primary-soft); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

/* ---------- Hojas modales */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
    width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
    background: var(--bg); border-radius: 20px 20px 0 0; padding: 10px 16px calc(var(--safe-bottom) + 20px);
    animation: up .2s ease-out;
}
.sheet .grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h2 { font-size: 19px; margin: 6px 0 10px; }
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Tablas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.t th, table.t td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ---------- Gráficas */
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 9.5px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Login */
.login { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.login img { width: 96px; height: 96px; border-radius: 22px; box-shadow: var(--shadow); }
.login h2 { font-size: 26px; margin: 16px 0 4px; }
.login form { text-align: left; margin-top: 24px; }

/* ---------- Calendario */
.mes-cal { margin: 18px 0 6px; }
.dia { width: 44px; flex: none; text-align: center; line-height: 1.1; }
.dia b { display: block; font-size: 18px; }
.dia small { color: var(--muted); font-size: 11px; text-transform: uppercase; }

/* ---------- Pasos del cierre */
.steps { display: flex; gap: 6px; margin: 4px 0 12px; }
.steps span { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.steps span.on { background: var(--primary); }

.desktop-only { display: none; }
@media (min-width: 900px) {
    .topbar h1 { font-size: 26px; }
    .view { max-width: 820px; }
    .desktop-only { display: initial; }
}

/* En pantallas anchas, la barra superior se alinea con el contenido centrado */
@media (min-width: 760px) {
    .topbar { padding-left: max(16px, calc((100% - 720px) / 2 + 16px)); padding-right: max(16px, calc((100% - 720px) / 2 + 16px)); }
}
@media (min-width: 900px) {
    .topbar { padding-left: max(16px, calc((100% - 820px) / 2 + 16px)); padding-right: max(16px, calc((100% - 820px) / 2 + 16px)); }
}

/* ---------- Inicio */
.fila-link { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.fila-link .grow { min-width: 0; }
.left { text-align: left; }
.partidas { margin-top: 6px; }
.partida { display: flex; align-items: center; gap: 12px; padding: 10px 0; color: inherit; border-bottom: 1px solid var(--line); }
.partida:last-child { border-bottom: 0; padding-bottom: 0; }
.partida .ico { width: 34px; height: 34px; font-size: 18px; }
.partida .bar { height: 6px; margin-top: 5px; }
span.bar { display: block; }
.partida .sub { display: block; margin-top: 3px; }
