:root {
    --bg: #0b0c10;
    --surface: #16181f;
    --surface-2: #1e212b;
    --surface-3: #262a35;
    --border: #262a35;
    --text: #f2f3f5;
    --text-muted: #9096a3;
    --accent: #7c6cff;
    --accent-2: #4a9eff;
    --accent-grad: linear-gradient(135deg, #7c6cff, #4a9eff);
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;
    --radius: 16px;
    --radius-sm: 10px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
    overscroll-behavior-y: none;
}

.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }

/* ── App shell ─────────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.sidebar-nav { display: none; } /* se activa en desktop, ver media query abajo */

.app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    flex: 1;
}

.app-header {
    position: sticky; top: 0; z-index: 20;
    padding: calc(1rem + var(--safe-top)) 1.1rem .9rem;
    background: linear-gradient(180deg, var(--bg) 60%, rgba(11,12,16,0));
    display: flex; align-items: center; justify-content: space-between;
}
.app-header h1 { font-size: 1.25rem; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.app-header .subtitle { color: var(--text-muted); font-size: .8rem; margin-top: .1rem; }
.avatar-btn {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--accent-grad); color: #fff; border: none;
    font-weight: 700; font-size: .95rem; display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}

.app-content { flex: 1; padding: 0 1.1rem calc(6.5rem + var(--safe-bottom)); }

section[id^="tab-"] h2 {
    font-size: .78rem; color: var(--text-muted); margin: 1.6rem 0 .6rem;
    text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
}
section[id^="tab-"] h2:first-child { margin-top: .4rem; }

.overview-grid { display: block; }
.overview-col:first-child h2:first-child { margin-top: .4rem; }
.overview-col:last-child h2:first-child { margin-top: 1.6rem; }

.filters-row { display: block; }

/* Desglose "por categoría este mes" */
.cat-breakdown-row { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; }
.cat-breakdown-row .name { flex: 1; font-size: .88rem; }
.cat-breakdown-row .bar-track { flex: 2; background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; }
.cat-breakdown-row .bar-fill { height: 100%; border-radius: 999px; }
.cat-breakdown-row .amount { font-size: .85rem; font-weight: 700; width: 70px; text-align: right; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    margin-bottom: .65rem;
}
.card-flat { background: transparent; border: none; padding: 0; }
.row { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.muted { color: var(--text-muted); font-size: .88em; }

/* Balance hero */
.balance-hero {
    background: var(--accent-grad);
    border-radius: 20px;
    padding: 1.3rem 1.3rem 1.5rem;
    color: #fff;
    margin-bottom: 1.1rem;
    box-shadow: 0 8px 28px rgba(124,108,255,.28);
}
.balance-hero .label { font-size: .8rem; opacity: .85; }
.balance-hero .amount { font-size: 2.1rem; font-weight: 800; letter-spacing: -.02em; margin-top: .15rem; }
.balance-hero .split { display: flex; gap: 1.5rem; margin-top: 1rem; }
.balance-hero .split div { font-size: .82rem; opacity: .9; }
.balance-hero .split strong { display: block; font-size: 1rem; font-weight: 700; }

/* Category progress rows */
.cat-row { display: flex; align-items: center; gap: .75rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.cat-row:last-child { border-bottom: none; }
.cat-icon {
    width: 40px; height: 40px; border-radius: 12px; flex: none;
    background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 1.15rem;
}
.cat-body { flex: 1; min-width: 0; }
.cat-body .row { margin-bottom: .35rem; }
.cat-body .name { font-weight: 600; font-size: .93rem; }
.cat-body .amounts { font-size: .82rem; color: var(--text-muted); white-space: nowrap; }
.progress-bar { background: var(--surface-2); border-radius: 999px; height: 7px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--ok); transition: width .3s; }
.progress-fill.warn { background: var(--warn); }
.progress-fill.over { background: var(--danger); }
.pct-badge { font-size: .72rem; font-weight: 700; padding: .1rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--text-muted); }
.pct-badge.warn { color: var(--warn); background: rgba(251,191,36,.12); }
.pct-badge.over { color: var(--danger); background: rgba(248,113,113,.12); }

/* Per-person avatars */
.person-list { display: flex; gap: .75rem; }
.person-chip { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .8rem; text-align: center; }
.person-chip .initial {
    width: 34px; height: 34px; border-radius: 50%; margin: 0 auto .4rem;
    background: var(--surface-3); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem;
}
.person-chip .amount { font-weight: 700; font-size: 1.05rem; margin-top: .1rem; }
.person-chip .name { font-size: .78rem; color: var(--text-muted); }

/* History list */
.tx-list .tx { display: flex; align-items: center; gap: .75rem; padding: .65rem 0; border-bottom: 1px solid var(--border); }
.tx-list .tx:last-child { border-bottom: none; }
.tx-body { flex: 1; min-width: 0; }
.tx-body .desc { font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-body .meta { font-size: .78rem; color: var(--text-muted); margin-top: .1rem; }
.tx-amount { font-weight: 700; font-size: .95rem; white-space: nowrap; }
.tx-del { background: none; border: none; color: var(--text-muted); font-size: 1.1rem; padding: .3rem .4rem; cursor: pointer; }
.tx-del:active { color: var(--danger); }

/* ── Forms / inputs ────────────────────────────────────────────────────── */
button, input, select { font-family: inherit; font-size: .95rem; }
input, select {
    width: 100%;
    background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: .65rem .8rem;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.field { margin-bottom: .8rem; }
.field label { display: block; font-size: .78rem; color: var(--text-muted); margin-bottom: .3rem; font-weight: 600; }
.btn {
    cursor: pointer; border: none; border-radius: var(--radius-sm);
    background: var(--accent-grad); color: #fff; font-weight: 700; padding: .8rem 1rem; width: 100%;
}
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.small { width: auto; padding: .45rem .9rem; font-size: .85rem; }
.btn.danger { background: var(--danger); color: #200; }
.icon-btn {
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
    border-radius: 50%; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; cursor: pointer;
}

.chip-picker { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip-option {
    padding: .5rem .85rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
    font-size: .85rem; cursor: pointer; white-space: nowrap;
}
.chip-option.selected { background: var(--accent-grad); border-color: transparent; color: #fff; font-weight: 700; }

/* ── Bottom nav ────────────────────────────────────────────────────────── */
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    max-width: 480px; margin: 0 auto;
    background: rgba(22,24,31,.92); backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    display: flex; padding: .4rem .5rem calc(.5rem + var(--safe-bottom));
}
.nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: .2rem;
    padding: .4rem 0; color: var(--text-muted); cursor: pointer; border-radius: var(--radius-sm);
}
.nav-item .ic { font-size: 1.25rem; }
.nav-item .lbl { font-size: .68rem; font-weight: 600; }
.nav-item.active { color: var(--accent-2); }

/* FAB */
.fab {
    position: fixed; right: calc(50% - 240px + 1.1rem); bottom: calc(4.7rem + var(--safe-bottom)); z-index: 25;
    width: 58px; height: 58px; border-radius: 50%; border: none;
    background: var(--accent-grad); color: #fff; font-size: 1.6rem; font-weight: 400;
    box-shadow: 0 10px 26px rgba(124,108,255,.4); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
@media (max-width: 480px) { .fab { right: 1.1rem; } }

/* ── Bottom sheet ──────────────────────────────────────────────────────── */
.sheet-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40;
    opacity: 0; pointer-events: none; transition: opacity .25s;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
    max-width: 480px; margin: 0 auto;
    background: var(--surface); border-radius: 22px 22px 0 0;
    border: 1px solid var(--border); border-bottom: none;
    padding: .7rem 1.2rem calc(1.4rem + var(--safe-bottom));
    transform: translateY(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
    max-height: 86vh; overflow-y: auto;
}
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 38px; height: 4px; background: var(--surface-3); border-radius: 999px; margin: 0 auto .9rem; }
.sheet h3 { margin: 0 0 1rem; font-size: 1.05rem; }

.hidden { display: none !important; }
.empty-hint { color: var(--text-muted); font-size: .88rem; text-align: center; padding: 1.5rem 0; }

/* ═══════════════════════════════════════════════════════════════════════
   DESKTOP — sidebar en vez de barra inferior, más ancho, grillas de a 2.
   ═══════════════════════════════════════════════════════════════════════ */
@media (min-width: 900px) {
    body { display: flex; justify-content: center; }
    .shell { max-width: 1180px; width: 100%; }

    .sidebar-nav {
        display: flex; flex-direction: column; gap: .2rem;
        width: 240px; flex: none; padding: 1.5rem 1rem;
        border-right: 1px solid var(--border);
        position: sticky; top: 0; height: 100vh;
    }
    .sidebar-brand { font-size: 1.15rem; font-weight: 800; margin-bottom: 1.2rem; display: flex; gap: .5rem; align-items: center; }
    .sidebar-nav .nav-item { flex-direction: row; justify-content: flex-start; gap: .7rem; padding: .65rem .8rem; }
    .sidebar-nav .nav-item .ic { font-size: 1.1rem; }
    .sidebar-nav .nav-item .lbl { font-size: .88rem; }
    .sidebar-nav .nav-item.active { background: var(--surface); }
    .sidebar-nav #whoamiDesktop { text-align: left; }

    .bottom-nav, .fab { display: none; }

    .app { max-width: 100%; margin: 0; }
    .app-header { padding: 1.8rem 2rem 1rem; }
    .app-header h1 { font-size: 1.5rem; }
    .app-content { padding: 0 2rem 3rem; max-width: 1000px; }

    .overview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; align-items: start; }

    .filters-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; align-items: end; }
    .filters-row .field { margin-bottom: 0; }

    .tx-list .tx:hover { background: var(--surface-2); cursor: pointer; border-radius: var(--radius-sm); }

    /* El panel deja de deslizarse desde abajo y pasa a ser un modal centrado */
    .sheet {
        left: 50%; right: auto; bottom: auto; top: 50%;
        transform: translate(-50%, -46%); width: 420px;
        border-radius: 20px; border-bottom: 1px solid var(--border);
        opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
    }
    .sheet.open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%); }
    .sheet-handle { display: none; }
}
