/* newFP — estilos mobile-first. Tema claro/oscuro: automático o elegido en Ajustes (data-theme en <html>). */

:root {
    --bg: #f4f5fa;
    --surface: #ffffff;
    --surface-2: #f0f1f7;
    --border: #e3e5ee;
    --text: #151827;
    --text-2: #5b6075;
    --text-3: #8a8fa3;
    --primary: #4f46e5;
    --primary-soft: #eceafe;
    --on-primary: #ffffff;
    --income: #0f9f6e;
    --income-soft: #e2f6ee;
    --expense: #e0344f;
    --expense-soft: #fde8ec;
    --warn: #b7791f;
    --hero-a: #4f46e5;
    --hero-b: #3a6fdc;
    --shadow: 0 1px 2px rgba(20, 22, 40, .05), 0 4px 16px rgba(20, 22, 40, .06);
    --radius: 16px;
    --radius-sm: 10px;
    --nav-h: 64px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    color-scheme: light;
}

/* Oscuro: automático según el sistema, salvo que se elija Claro; o forzado con data-theme="dark". */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0e1018;
        --surface: #171a25;
        --surface-2: #1f2331;
        --border: #2a2f40;
        --text: #eef0f7;
        --text-2: #a4a9bd;
        --text-3: #727892;
        --primary: #8b85ff;
        --primary-soft: #26244a;
        --on-primary: #0e1018;
        --income: #34d399;
        --income-soft: #15302a;
        --expense: #fb7185;
        --expense-soft: #3a1c25;
        --warn: #f6c453;
        --hero-a: #3a32b0;
        --hero-b: #1f5a9e;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #0e1018;
    --surface: #171a25;
    --surface-2: #1f2331;
    --border: #2a2f40;
    --text: #eef0f7;
    --text-2: #a4a9bd;
    --text-3: #727892;
    --primary: #8b85ff;
    --primary-soft: #26244a;
    --on-primary: #0e1018;
    --income: #34d399;
    --income-soft: #15302a;
    --expense: #fb7185;
    --expense-soft: #3a1c25;
    --warn: #f6c453;
    --hero-a: #3a32b0;
    --hero-b: #1f5a9e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.income { color: var(--income); }
.expense { color: var(--expense); }
.ms { font-family: 'Material Symbols Outlined'; font-weight: normal; font-style: normal; font-size: 22px; line-height: 1; display: inline-block; vertical-align: middle; -webkit-font-smoothing: antialiased; font-feature-settings: 'liga'; user-select: none; }

/* ---------- Layout ---------- */
.shell { min-height: 100vh; }
.main { padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 1080px; margin: 0 auto; min-width: 0; overflow-x: clip; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.topbar h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.topbar .sub { font-size: 13px; color: var(--text-2); }

.sidebar { display: none; }

.bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
}
.bottomnav a, .bottomnav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 11px; color: var(--text-3); background: none; border: 0; padding: 6px 0; cursor: pointer;
}
.bottomnav a.active { color: var(--primary); }
.bottomnav a.active .ms { font-variation-settings: 'FILL' 1; }
.bottomnav .fab {
    width: 52px; height: 52px; border-radius: 18px; margin: -18px auto 0;
    background: var(--primary); color: var(--on-primary); justify-content: center;
    box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 40%, transparent);
}
.bottomnav .fab .ms { font-size: 30px; }

@media (min-width: 900px) {
    .shell { display: grid; grid-template-columns: 232px 1fr; }
    .bottomnav { display: none; }
    .main { padding: 28px 32px 48px; width: 100%; }
    .sidebar {
        display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
        padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--border);
    }
    .sidebar .brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 19px; padding: 4px 10px 18px; }
    .sidebar .brand .ms { color: var(--primary); }
    .sidebar a.nav { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--text-2); font-weight: 500; }
    .sidebar a.nav:hover { background: var(--surface-2); }
    .sidebar a.nav.active { background: var(--primary-soft); color: var(--primary); }
    .sidebar .btn { margin: 14px 0; }
    .settings-shortcut { display: none; }
    .sidebar .foot { margin-top: auto; font-size: 12px; color: var(--text-3); padding: 0 10px; }
}

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card, .card + .section, .section + .card, .section + .section { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.card h2, .section-title { font-size: 15px; font-weight: 650; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card h2 a, .section-title a { font-size: 13px; font-weight: 500; color: var(--primary); }
.grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (min-width: 900px) {
    .grid-md-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-md-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .grid-md-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.hero { background: linear-gradient(135deg, var(--hero-a), var(--hero-b)); color: #fff; border: 0; }
.hero .label { font-size: 13px; opacity: .85; }
.hero .big { font-size: 32px; font-weight: 750; letter-spacing: -.02em; margin: 2px 0 14px; }
.hero .split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero .pill { background: rgba(255, 255, 255, .16); border-radius: 12px; padding: 10px 12px; }
.hero .pill small { display: flex; align-items: center; gap: 4px; font-size: 12px; opacity: .9; }
.hero .pill strong { font-size: 17px; }

.stat { padding: 12px 14px; }
.stat .label { font-size: 12px; color: var(--text-2); }
.stat .value { font-size: 18px; font-weight: 700; margin-top: 2px; }
.stat .hint { font-size: 12px; color: var(--text-3); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
    font-weight: 600; cursor: pointer; background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-income { background: var(--income); color: #fff; }
.btn-expense { background: var(--expense); color: #fff; }
.btn-danger { background: var(--expense-soft); color: var(--expense); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-block { width: 100%; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-2); border: 0; cursor: pointer; }

/* Lista de movimientos */
.tx-day { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; padding: 14px 4px 6px; }
.tx-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tx { display: flex; align-items: center; gap: 12px; padding: 11px 14px; }
.tx + .tx { border-top: 1px solid var(--border); }
a.tx:active { background: var(--surface-2); }
.tx .ico { flex: none; width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
.tx .ico .ms { font-size: 21px; }
.tx .body { flex: 1; min-width: 0; }
.tx .title, .tx .meta { display: block; }
.tx .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .meta { font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { flex: none; text-align: right; font-weight: 650; white-space: nowrap; }
.tx .amt small { display: block; font-size: 11.5px; font-weight: 400; color: var(--text-3); }
.empty { text-align: center; padding: 36px 16px; color: var(--text-2); }
.empty .ms { font-size: 40px; color: var(--text-3); display: block; margin-bottom: 8px; }

/* Barras simples de categorías */
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; }
.bar-row .ms { font-size: 20px; }
.bar-row .name { font-size: 14px; display: flex; justify-content: space-between; gap: 8px; }
.bar-row .name span:last-child { color: var(--text-3); font-size: 12px; }
.bar-track { height: 7px; background: var(--surface-2); border-radius: 99px; margin-top: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; }
.bar-row .val { font-weight: 600; font-size: 14px; text-align: right; }

/* Formularios */
.field { margin-bottom: 14px; }
.field > label, .label-sm { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.input, select.input, textarea.input {
    width: 100%; height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--surface); font-size: 16px; outline: none; appearance: none; -webkit-appearance: none;
}
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 18px) 20px, calc(100% - 13px) 20px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.row { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.amount-input { display: flex; align-items: center; gap: 6px; border-bottom: 2px solid var(--border); padding: 4px 0 8px; margin-bottom: 16px; }
.amount-input:focus-within { border-color: var(--primary); }
.amount-input select { border: 0; background: var(--surface-2); border-radius: 10px; height: 38px; padding: 0 10px; font-weight: 600; font-size: 15px; }
.amount-input input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 34px; font-weight: 750; letter-spacing: -.02em; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; margin-bottom: 16px; }
.segmented button, .segmented a { height: 38px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; color: var(--text-2); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.segmented .on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented .on.t-expense { color: var(--expense); }
.segmented .on.t-income { color: var(--income); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips-scroll { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 4px; }
.chips-scroll::-webkit-scrollbar { display: none; }
.chip {
    display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: 99px;
    border: 1px solid var(--border); background: var(--surface); font-size: 13.5px; font-weight: 500; cursor: pointer; white-space: nowrap; flex: none;
}
.chip .ms { font-size: 18px; }
.chip.on, .chip:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.chip input { display: none; }

.cat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; max-height: 236px; overflow-y: auto; padding: 2px; }
.cat-opt { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 2px; border-radius: 12px; border: 1px solid transparent; cursor: pointer; text-align: center; font-size: 11.5px; line-height: 1.2; color: var(--text-2); }
.cat-opt .ico { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
.cat-opt input { display: none; }
.cat-opt:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--text); font-weight: 600; }
.cat-opt.hidden { display: none; }

/* Hoja inferior (modal) */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(8, 10, 20, .45); z-index: 60; opacity: 0; pointer-events: none; transition: opacity .2s; }
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; background: var(--surface);
    border-radius: 22px 22px 0 0; max-height: 92vh; overflow-y: auto; padding: 8px 16px calc(16px + var(--safe-b));
    transform: translateY(105%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 99px; background: var(--border); margin: 4px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h3 { font-size: 18px; }
body.sheet-open { overflow: hidden; }
body.sheet-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
body.sheet-open .sheet.open { transform: none; }
@media (min-width: 700px) {
    .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 520px; border-radius: 22px; transform: translate(-50%, -45%); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
    body.sheet-open .sheet.open { transform: translate(-50%, -50%); opacity: 1; pointer-events: auto; }
    .sheet .grab { display: none; }
}

/* Avisos */
.flash { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-size: 14px; }
.flash.ok { background: var(--income-soft); color: var(--income); }
.flash.err { background: var(--expense-soft); color: var(--expense); }

/* Tablas simples */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 8px 6px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px 6px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; }
.scroll-x { overflow-x: auto; }

.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 320px; }

.pager { display: flex; justify-content: center; gap: 8px; margin-top: 16px; }
details.filters summary { list-style: none; cursor: pointer; }
details.filters summary::-webkit-details-marker { display: none; }

/* Login */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; padding: 28px 22px; }
.auth .brand { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 26px; font-weight: 800; margin-bottom: 4px; }
.auth .brand .ms { color: var(--primary); font-size: 30px; }
