:root {
    /* Paleta Draupnir: azul noche + dorado (anillo) + azul real de acción */
    --navy-900: #061426;
    --navy-800: #0A2342;
    --navy-700: #0F3A6B;
    --gold: #D4AF5A;
    --gold-soft: #F1D890;
    --primary: #1F4FE0;
    --primary-2: #2F6BFF;
    --primary-hover: #1A41BF;
    --ink: #0A1A33;
    --muted: #5B6B84;
    --line: #CBD6E6;
    --bg: #E6EDF9;
    --bg-glow-1: #C9DAFB;
    --bg-glow-2: #F6E7BE;
    --card: #FFFFFF;
    --danger: #B42318;
    --danger-bg: #FEF3F2;
    --danger-line: #FECDCA;
    --radius: 12px;
    --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    height: 48px; padding: 0 24px; border: 0; border-radius: 10px;
    font: 600 15px var(--font); cursor: pointer; text-decoration: none;
    transition: background .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid rgba(29, 78, 216, .35); outline-offset: 2px; }
.btn-primary {
    width: 100%; color: #fff;
    background: linear-gradient(180deg, var(--primary-2), var(--primary));
    box-shadow: 0 6px 16px rgba(31, 79, 224, .35);
}
.btn-primary:hover { background: linear-gradient(180deg, var(--primary), var(--primary-hover)); }
.btn-primary:disabled { opacity: .7; cursor: progress; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { background: #F8FAFC; }

/* ---------- Layout de autenticación ---------- */
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(380px, 5fr) 6fr; }

.auth-brand {
    position: relative; overflow: hidden;
    display: flex; flex-direction: column; justify-content: space-between;
    padding: 48px 56px; color: #fff;
    background:
        radial-gradient(900px 500px at 110% -10%, rgba(212, 175, 90, .18), transparent 60%),
        linear-gradient(160deg, var(--navy-700) 0%, var(--navy-800) 55%, var(--navy-900) 100%);
}
/* Anillos decorativos (alusión al anillo Draupnir) */
.auth-brand::before, .auth-brand::after {
    content: ""; position: absolute; border-radius: 50%;
    border: 1.5px solid rgba(212, 175, 90, .22); pointer-events: none;
}
.auth-brand::before { width: 520px; height: 520px; right: -200px; bottom: -180px; }
.auth-brand::after  { width: 340px; height: 340px; right: -110px; bottom: -90px; border-color: rgba(212, 175, 90, .14); }

.brand-top, .mobile-brand { display: flex; align-items: center; gap: 14px; }
.brand-name { font-size: 26px; font-weight: 700; letter-spacing: .4px; }

.brand-copy { position: relative; z-index: 1; max-width: 460px; }
.brand-copy h2 { font-size: 38px; line-height: 1.15; font-weight: 800; letter-spacing: -.6px; }
.brand-copy h2 .accent { color: var(--gold-soft); }
.brand-points { list-style: none; padding: 0; margin: 32px 0 0; display: grid; gap: 14px; color: #C8D4E6; font-size: 15.5px; }
.brand-points li { display: flex; align-items: center; gap: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); flex: none; }
.brand-foot { color: #8FA3BF; font-size: 13px; position: relative; z-index: 1; }

.auth-panel {
    display: flex; align-items: center; justify-content: center; padding: 32px 24px;
    background:
        radial-gradient(700px 520px at 100% 0%, var(--bg-glow-2), transparent 62%),
        radial-gradient(800px 600px at 0% 100%, var(--bg-glow-1), transparent 60%),
        linear-gradient(135deg, #EEF3FC 0%, var(--bg) 55%, #D3E0F7 100%);
}
.auth-card {
    width: 100%; max-width: 420px; background: var(--card);
    border: 1px solid rgba(255, 255, 255, .8); border-top: 4px solid var(--gold);
    border-radius: 16px; padding: 40px 36px 32px;
    box-shadow: 0 24px 60px rgba(10, 35, 66, .18), 0 2px 6px rgba(10, 35, 66, .08);
}
.mobile-brand { display: none; justify-content: center; margin-bottom: 24px; color: var(--navy-800); }
.mobile-brand .logo-mark { width: 38px; height: 38px; }

.auth-head { margin-bottom: 28px; }
.auth-head h1 {
    font-size: 36px; line-height: 1.1; font-weight: 800; letter-spacing: -.8px;
    color: var(--navy-800);
}
.auth-head h1::after {
    content: ""; display: block; width: 44px; height: 4px; border-radius: 4px; margin-top: 12px;
    background: linear-gradient(90deg, var(--gold), var(--gold-soft));
}
.subtitle { margin-top: 12px; color: var(--muted); font-size: 15px; font-weight: 500; }

/* ---------- Formulario ---------- */
.field { margin-bottom: 22px; }
.field > label { display: block; margin-bottom: 8px; font-size: 13.5px; font-weight: 600; color: #334155; }

.input-wrap { position: relative; }
.input-wrap .ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: #94A3B8; pointer-events: none; }
.input-wrap input {
    width: 100%; height: 48px; padding: 0 14px 0 42px;
    border: 1px solid var(--line); border-radius: 10px; background: #fff;
    font: 400 15px var(--font); color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
}
.input-wrap input::placeholder { color: #A3AEC0; }
.input-wrap input:focus, .pin-box:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(29, 78, 216, .12);
}

.pin-row { display: flex; gap: 12px; }
.pin-box {
    flex: 1; min-width: 0; height: 58px; text-align: center;
    border: 1px solid var(--line); border-radius: 10px; background: #fff;
    font: 600 24px var(--font); color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
}
.pin-box:not(:placeholder-shown), .pin-box.filled { border-color: #94A3B8; }

.field-error { display: block; margin-top: 6px; font-size: 13px; color: var(--danger); }
.field-error:empty { display: none; }
.field.invalid .input-wrap input, .field.invalid .pin-box { border-color: var(--danger); }

.alert {
    display: flex; align-items: flex-start; gap: 10px; margin-bottom: 22px; padding: 12px 14px;
    border: 1px solid var(--danger-line); background: var(--danger-bg); color: var(--danger);
    border-radius: 10px; font-size: 14px; line-height: 1.4;
}
.alert svg { flex: none; margin-top: 1px; }

/* Checkbox */
.check { display: flex; align-items: center; gap: 10px; margin: 0 0 24px; font-size: 14px; color: #475569; cursor: pointer; user-select: none; }
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check .box {
    width: 18px; height: 18px; border: 1.5px solid #94A3B8; border-radius: 5px; background: #fff;
    display: grid; place-items: center; transition: .15s; flex: none;
}
.check input:checked + .box { background: var(--primary); border-color: var(--primary); }
.check input:checked + .box::after {
    content: ""; width: 5px; height: 9px; margin-top: -2px;
    border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.check input:focus-visible + .box { box-shadow: 0 0 0 4px rgba(29, 78, 216, .2); }

.auth-note {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    margin-top: 22px; font-size: 12.5px; color: var(--muted);
}

/* ---------- Placeholder del inicio ---------- */
.placeholder { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px; text-align: center; padding: 24px; background: var(--navy-800); color: #fff; }
.placeholder p { color: #B8C6DB; max-width: 420px; }
.placeholder .btn-secondary { margin-top: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-brand { display: none; }
    .mobile-brand { display: flex; }
    .auth-panel { align-items: flex-start; padding: 32px 16px; }
}
@media (max-width: 420px) {
    .auth-card { padding: 28px 20px 24px; }
    .pin-row { gap: 8px; }
}

/* =====================================================================
   Área autenticada: barra superior, páginas, tablas, formularios
   ===================================================================== */
body.app {
    background:
        radial-gradient(900px 420px at 100% 0%, var(--bg-glow-2), transparent 65%),
        linear-gradient(180deg, #EEF3FC 0%, var(--bg) 100%) fixed;
    min-height: 100vh;
}

.topbar {
    position: sticky; top: 0; z-index: 50;
    background: linear-gradient(135deg, var(--navy-700), var(--navy-800) 60%, var(--navy-900));
    border-bottom: 3px solid var(--gold);
    box-shadow: 0 4px 18px rgba(6, 20, 38, .25);
}
.topbar-in { max-width: 1200px; margin: 0 auto; padding: 0 20px; min-height: 64px; display: flex; align-items: center; gap: 24px; }

.tb-brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-size: 21px; font-weight: 700; letter-spacing: .3px; }
.tb-brand .logo-mark { width: 30px; height: 30px; }

.tb-menu { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.tb-spacer { flex: 1; }
.tb-nav { display: flex; gap: 4px; }
.tb-nav a {
    color: #C8D4E6; text-decoration: none; font-weight: 600; font-size: 15px;
    padding: 10px 16px; border-radius: 8px; position: relative; transition: background .15s, color .15s;
}
.tb-nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.tb-nav a.active { color: #fff; background: rgba(255, 255, 255, .1); }
.tb-nav a.active::after { content: ""; position: absolute; left: 16px; right: 16px; bottom: 3px; height: 2px; background: var(--gold); border-radius: 2px; }

.tb-toggle { display: none; margin-left: auto; width: 46px; height: 46px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, .08); cursor: pointer; flex-direction: column; align-items: center; justify-content: center; gap: 5px; }
.tb-toggle span { width: 22px; height: 2px; background: #fff; border-radius: 2px; transition: .2s; }
.tb-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.tb-toggle.open span:nth-child(2) { opacity: 0; }
.tb-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Menú de usuario */
.user-menu { position: relative; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px 10px 6px 6px; border-radius: 40px; color: #fff; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: rgba(255, 255, 255, .08); }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--gold-soft), var(--gold)); color: var(--navy-900); font-weight: 800; font-size: 14px; }
.u-text { display: grid; line-height: 1.2; text-align: left; }
.u-text strong { font-size: 14px; }
.u-text small { color: #9FB2CE; font-size: 12px; }
.chev { color: #9FB2CE; transition: transform .15s; }
.user-menu[open] .chev { transform: rotate(180deg); }
.um-panel {
    position: absolute; right: 0; top: calc(100% + 8px); min-width: 210px; padding: 6px;
    background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px rgba(6, 20, 38, .25);
}
.um-panel a, .um-panel button {
    display: block; width: 100%; text-align: left; padding: 12px 14px; border: 0; background: none; border-radius: 8px;
    font: 500 14.5px var(--font); color: var(--ink); text-decoration: none; cursor: pointer;
}
.um-panel a:hover, .um-panel button:hover { background: #EEF3FC; }
.um-panel form { margin: 0; border-top: 1px solid #EDF1F7; margin-top: 4px; padding-top: 4px; }

/* Páginas */
.app-main { max-width: 1200px; margin: 0 auto; padding: 32px 20px 56px; }
.page-head { margin-bottom: 24px; }
.page-head.row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 32px; font-weight: 800; letter-spacing: -.6px; color: var(--navy-800); }
.page-head h1::after { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; margin-top: 10px; background: linear-gradient(90deg, var(--gold), var(--gold-soft)); }
.page-sub { margin-top: 10px; color: var(--muted); font-size: 15px; }
.back { display: inline-block; margin-bottom: 8px; color: var(--primary); font-weight: 600; font-size: 14px; text-decoration: none; }
.back:hover { text-decoration: underline; }
.page-head.denied .btn { margin-top: 16px; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: 0 10px 30px rgba(10, 35, 66, .08); }
.panel.narrow { max-width: 480px; }
.panel-title { font-size: 18px; font-weight: 700; color: var(--navy-800); margin-bottom: 18px; }
.two-col { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 24px; align-items: start; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }
.two-col > *, .stack > * { min-width: 0; }
.pin-box { width: 100%; }
.hint { color: var(--muted); font-size: 13.5px; margin: 0 0 18px; line-height: 1.45; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.card { display: block; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 24px; box-shadow: 0 10px 30px rgba(10, 35, 66, .08); color: inherit; text-decoration: none; }
.card h2 { font-size: 18px; font-weight: 700; color: var(--navy-800); }
.card p { margin: 8px 0 16px; color: var(--muted); font-size: 14.5px; line-height: 1.45; }
.card-link { border-top: 4px solid var(--gold); transition: transform .15s, box-shadow .15s; }
.card-link:hover { transform: translateY(-2px); box-shadow: 0 16px 36px rgba(10, 35, 66, .14); }
.card.soon { opacity: .85; }

/* Inputs genéricos */
.input {
    width: 100%; height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
    font: 400 15px var(--font); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
select.input { appearance: none; padding-right: 38px; cursor: pointer;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 20 20' fill='%2364748B'%3E%3Cpath d='M5.5 7.5 10 12l4.5-4.5z'/%3E%3C/svg%3E") no-repeat right 12px center; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(31, 79, 224, .14); }
.input:disabled { background: #F1F5FA; color: var(--muted); }
.field.invalid .input { border-color: var(--danger); }
.panel .btn-primary, .panel .btn-secondary { width: 100%; }
.btn-auto { width: auto !important; }
.btn-sm { height: 38px; padding: 0 16px; font-size: 14px; width: auto !important; text-decoration: none; }

/* Badges */
.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 12.5px; font-weight: 700; }
.badge-gold { background: #FBF1D3; color: #7A5A12; }
.badge-soft { background: #E6EDF9; color: #34507A; }
.badge-ok { background: #DDF5E8; color: #11643A; }
.badge-warn { background: #FDE9D2; color: #99500A; }
.badge-off { background: #E9ECF1; color: #5B6B84; }
.badge-info { background: #DCE8FF; color: #1A41BF; }

/* Tabla */
.table-wrap { padding: 8px 8px 12px; overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.tbl th { text-align: left; padding: 14px 16px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); border-bottom: 1px solid var(--line); }
.tbl td { padding: 14px 16px; border-bottom: 1px solid #EDF1F7; vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: #F7F9FD; }
.tbl .actions { text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }

/* Mensajes */
.flash { margin-bottom: 20px; padding: 13px 16px; border-radius: 10px; font-size: 14.5px; font-weight: 500; transition: opacity .4s; }
.flash.hide { opacity: 0; pointer-events: none; height: 0; margin: 0; padding: 0; overflow: hidden; }
.flash-ok { background: #DDF5E8; color: #11643A; border: 1px solid #B6E6CB; }
.flash-err { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-line); }
.flash-info { background: #E4EDFF; color: #1A41BF; border: 1px solid #C3D5FF; }

/* ---------- Responsive de la barra y páginas ---------- */
@media (max-width: 860px) {
    .topbar-in { gap: 12px; flex-wrap: wrap; padding: 8px 16px; }
    .tb-toggle { display: flex; }
    .tb-menu { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 8px; padding: 8px 0 14px; border-top: 1px solid rgba(255, 255, 255, .12); }
    .tb-menu.open { display: flex; }
    .tb-nav { flex-direction: column; }
    .tb-nav a { padding: 14px 12px; font-size: 16px; }
    .tb-nav a.active::after { left: 12px; right: auto; width: 28px; }
    .user-menu summary { padding: 10px 6px; border-radius: 10px; }
    .um-panel { position: static; margin-top: 6px; box-shadow: none; }
    .two-col { grid-template-columns: 1fr; }
    .app-main { padding: 24px 16px 48px; }
    .page-head h1 { font-size: 27px; }
    .panel { padding: 22px 18px; }
}

/* Tabla -> tarjetas en teléfono */
@media (max-width: 700px) {
    .table-wrap { padding: 0; background: none; border: 0; box-shadow: none; overflow: visible; }
    .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
    .tbl thead { display: none; }
    .tbl tr { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 8px 6px; margin-bottom: 14px; box-shadow: 0 6px 18px rgba(10, 35, 66, .07); }
    .tbl td { border: 0; display: flex; justify-content: space-between; gap: 12px; padding: 9px 14px; text-align: right; }
    .tbl td::before { content: attr(data-l); color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; text-align: left; }
    .tbl td.actions { display: block; padding-top: 12px; }
    .tbl td.actions::before { content: none; }
    .tbl td.actions .btn { width: 100% !important; height: 44px; }
    .tbl tbody tr:hover { background: #fff; }
}

/* =====================================================================
   Gastos, tablero y categorías
   ===================================================================== */
/* Botón principal "Registrar gasto" */
.cta {
    display: flex; align-items: center; gap: 18px; margin-bottom: 24px; padding: 22px 26px;
    border-radius: 18px; text-decoration: none; color: #fff;
    background: linear-gradient(135deg, var(--primary-2) 0%, var(--primary) 55%, #1738A8 100%);
    box-shadow: 0 14px 30px rgba(31, 79, 224, .38), inset 0 1px 0 rgba(255, 255, 255, .25);
    border-bottom: 4px solid var(--gold);
    transition: transform .12s, box-shadow .12s;
}
.cta:hover { transform: translateY(-2px); box-shadow: 0 18px 36px rgba(31, 79, 224, .45), inset 0 1px 0 rgba(255, 255, 255, .25); }
.cta:active { transform: translateY(1px); }
.cta:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.cta-ico { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .18); flex: none; }
.cta-text { display: grid; gap: 2px; }
.cta-text strong { font-size: 26px; font-weight: 800; letter-spacing: -.3px; }
.cta-text small { font-size: 15px; color: #D5E1FF; }

/* Selector de mes */
.mes-nav { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 4px; box-shadow: 0 4px 12px rgba(10, 35, 66, .06); }
.mes-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 9px; font-size: 22px; line-height: 1; color: var(--navy-800); text-decoration: none; font-weight: 700; }
a.mes-btn:hover { background: #EEF3FC; }
.mes-btn.disabled { color: #B7C2D4; }
.mes-label { min-width: 138px; text-align: center; font-weight: 700; color: var(--navy-800); font-size: 15px; }
.mes-hoy { margin: 0 6px 0 2px; padding: 6px 10px; border-radius: 8px; background: #FBF1D3; color: #7A5A12; font-size: 13px; font-weight: 700; text-decoration: none; }
.head-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Tarjetas KPI */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; box-shadow: 0 10px 30px rgba(10, 35, 66, .08); border-top: 4px solid var(--navy-700); }
.kpi h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); font-weight: 700; }
.kpi-v { margin: 8px 0 4px; font-size: 27px; font-weight: 800; letter-spacing: -.5px; color: var(--navy-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-v.muted-v { color: #94A3B8; }
.kpi-v.neg, .neg { color: var(--danger) !important; }
.kpi-s { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.4; }
.kpi-s a { color: var(--primary); font-weight: 600; }
.kpi-ok { border-top-color: #34A853; }
.kpi-warn { border-top-color: #FBBC04; }
.kpi-bad { border-top-color: var(--danger); }
.meter { height: 8px; border-radius: 8px; background: #E6EDF9; overflow: hidden; margin: 6px 0 8px; }
.meter span { display: block; height: 100%; border-radius: 8px; background: #34A853; }
.kpi-warn .meter span { background: #F5A400; }
.kpi-bad .meter span { background: var(--danger); }

/* Rejilla del tablero */
.dash { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px; }
.dash-main { grid-column: span 7; }
.dash-side { grid-column: span 5; }
.dash-full { grid-column: span 12; }
.dash .panel { padding: 22px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.panel-head .panel-title { margin: 0; }
.link { color: var(--primary); font-weight: 600; font-size: 14px; text-decoration: none; }
.link:hover { text-decoration: underline; }
.empty-note { color: var(--muted); font-size: 14.5px; margin: 4px 0; }

/* Lista de gastos recientes */
.gl { list-style: none; margin: 0; padding: 0; }
.gl li { display: flex; align-items: center; gap: 14px; padding: 13px 0; border-bottom: 1px solid #EDF1F7; }
.gl li:last-child { border-bottom: 0; }
.gl-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.gl-body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.gl-body strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gl-body small { color: var(--muted); font-size: 12.5px; }
.gl-amt { font-weight: 800; color: var(--navy-800); white-space: nowrap; }

/* Gráfico circular */
.donut-wrap { display: grid; place-items: center; margin: 4px 0 12px; }
.donut { width: 100%; max-width: 230px; height: auto; transform: rotate(0); }
.donut .seg { transition: stroke-width .15s; cursor: pointer; }
.donut a:hover .seg { stroke-width: 7; }
.d-top { font-size: 2.6px; fill: var(--muted); font-family: var(--font); text-transform: uppercase; letter-spacing: .2px; }
.d-val { font-size: 4.2px; font-weight: 800; fill: var(--navy-800); font-family: var(--font); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.legend a { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; color: var(--ink); text-decoration: none; font-size: 14px; }
.legend a:hover { background: #EEF3FC; }
.legend i { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.legend span { flex: 1; }
.legend b { color: var(--muted); font-weight: 700; }

/* Presupuesto por categoría */
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; }
.bars-top { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; margin-bottom: 6px; font-weight: 600; }
.bars-top i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; }
.bars-top small { color: var(--muted); font-weight: 500; }
.track { height: 10px; border-radius: 10px; background: #E6EDF9; overflow: hidden; }
.fill { display: block; height: 100%; border-radius: 10px; background: var(--c, var(--primary)); }
.fill.near { background: #F5A400; }
.fill.over { background: var(--danger); }

/* Gasto por día */
.daybars { display: flex; align-items: stretch; gap: 3px; height: 170px; }
.db { flex: 1; position: relative; min-width: 0; }
.db span { position: absolute; left: 10%; right: 10%; bottom: 18px; height: calc((100% - 18px) * var(--h, 0)); background: linear-gradient(180deg, var(--primary-2), var(--primary)); border-radius: 4px 4px 0 0; }
.db.today span { background: linear-gradient(180deg, var(--gold-soft), var(--gold)); }
.db em { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); font-style: normal; font-size: 11px; color: var(--muted); }
.db:hover span { filter: brightness(1.15); }
.chart-note { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); }

/* Últimos 6 meses */
.mbars { position: relative; height: 230px; display: flex; gap: 14px; padding: 0 4px; }
.mb { flex: 1; position: relative; height: 100%; text-decoration: none; color: var(--ink); }
.mb span { position: absolute; left: 18%; right: 18%; bottom: 28px; height: calc((100% - 52px) * var(--h, 0)); background: #9FB5DE; border-radius: 6px 6px 0 0; transition: filter .15s; }
.mb.sel span { background: linear-gradient(180deg, var(--primary-2), var(--primary)); }
.mb.over span { background: #E88E86; }
.mb.sel.over span { background: linear-gradient(180deg, #E5584B, var(--danger)); }
.mb:hover span { filter: brightness(1.08); }
.mb em { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-style: normal; font-size: 13px; font-weight: 600; color: var(--muted); }
.mb.sel em { color: var(--navy-800); }
.mb b { position: absolute; left: 0; right: 0; bottom: calc(28px + (100% - 52px) * var(--h, 0) + 4px); text-align: center; font-size: 12px; font-weight: 700; color: var(--navy-800); }
.mline { position: absolute; left: 0; right: 0; bottom: calc(28px + (100% - 52px) * var(--h, 0)); border-top: 2px dashed var(--gold); pointer-events: none; z-index: 2; }
.mline span { position: absolute; right: 0; top: -22px; font-size: 12px; font-weight: 700; color: #7A5A12; background: #FBF1D3; padding: 2px 8px; border-radius: 6px; }

/* Formulario de gasto */
.monto-field { margin-bottom: 26px; }
.monto-wrap { display: flex; align-items: center; gap: 8px; padding: 6px 18px; border: 2px solid var(--line); border-radius: 14px; background: #F8FAFE; transition: border-color .15s, box-shadow .15s; }
.monto-wrap:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(31, 79, 224, .14); background: #fff; }
.monto-sign { font-size: 34px; font-weight: 700; color: var(--muted); }
.monto-input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font: 800 44px var(--font); letter-spacing: -1px; color: var(--navy-800); padding: 8px 0; }
.monto-input::placeholder { color: #B7C2D4; }
.field.invalid .monto-wrap { border-color: var(--danger); }

.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip { cursor: pointer; }
.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip-body { display: inline-flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 16px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; font-size: 15px; font-weight: 600; color: #334155; transition: .12s; user-select: none; }
.chip-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; background: var(--c); flex: none; }
.chip:hover .chip-body { border-color: var(--c); }
.chip input:checked + .chip-body { background: var(--c); border-color: var(--c); color: #fff; box-shadow: 0 4px 12px rgba(10, 35, 66, .2); }
.chip input:checked + .chip-body .chip-dot { background: #fff; }
.chip input:focus-visible + .chip-body { outline: 3px solid rgba(31, 79, 224, .35); outline-offset: 2px; }

.form-actions { display: grid; gap: 12px; margin-top: 8px; }
.btn-lg { height: 56px; font-size: 17px; }
.btn-danger { background: #fff; color: var(--danger); border: 1px solid var(--danger-line); }
.btn-danger:hover { background: var(--danger-bg); }
.danger-zone { margin-top: 22px; padding-top: 22px; border-top: 1px solid #EDF1F7; }
.hint.tight { margin: 8px 0 0; }

.money-input { position: relative; }
.money-input > span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; z-index: 1; }
.money-input .input { padding-left: 30px; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { cursor: pointer; }
.swatch input { position: absolute; opacity: 0; width: 0; height: 0; }
.swatch span { display: block; width: 38px; height: 38px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1.5px var(--line); transition: .12s; }
.swatch:hover span { transform: scale(1.08); }
.swatch input:checked + span { box-shadow: 0 0 0 3px var(--navy-800); }
.swatch input:focus-visible + span { outline: 3px solid rgba(31, 79, 224, .4); outline-offset: 3px; }

/* Filtros y tablas de gastos */
.chip-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.fchip { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 20px; border: 1px solid var(--line); background: #fff; color: #334155; font-size: 14px; font-weight: 600; text-decoration: none; }
.fchip:hover { border-color: var(--primary); }
.fchip.on { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }
.cat-tag { display: inline-flex; align-items: center; gap: 8px; }
.num { text-align: right; }
.nowrap { white-space: nowrap; }
.panel.empty { text-align: center; padding: 40px 20px; }
.panel.empty p { color: var(--muted); margin-bottom: 18px; }

/* Botón flotante en móvil (acceso rápido a registrar gasto) */
.fab { display: none; }

@media (max-width: 1000px) {
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dash-main, .dash-side { grid-column: span 12; }
}
@media (max-width: 860px) {
    .cta { padding: 28px 24px; border-radius: 20px; flex-direction: column; text-align: center; gap: 12px; }
    .cta-ico { width: 78px; height: 78px; }
    .cta-ico svg { width: 42px; height: 42px; }
    .cta-text strong { font-size: 30px; }
    .fab {
        display: grid; place-items: center; position: fixed; right: 18px; bottom: 18px; z-index: 40;
        width: 62px; height: 62px; border-radius: 50%; color: #fff; text-decoration: none;
        background: linear-gradient(135deg, var(--primary-2), var(--primary)); border: 3px solid var(--gold);
        box-shadow: 0 10px 24px rgba(31, 79, 224, .45);
    }
    .app-main { padding-bottom: 104px; }
    .head-actions { width: 100%; justify-content: space-between; }
    .head-actions .btn-auto { flex: 1; }
    .mes-nav { width: 100%; justify-content: space-between; }
    .page-head.row > .mes-nav { margin-top: 4px; }
}
@media (max-width: 520px) {
    .kpi { padding: 14px; }
    .kpi-v { font-size: 21px; }
    .monto-input { font-size: 38px; }
    .daybars { gap: 2px; }
}

/* =====================================================================
   Gastos fijos
   ===================================================================== */
.kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpis.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis .kpi-v { font-size: 24px; }
a.kpi-link { color: inherit; text-decoration: none; transition: transform .12s, box-shadow .12s; }
a.kpi-link:hover { transform: translateY(-2px); box-shadow: 0 16px 36px rgba(10, 35, 66, .14); }
.badge-bad { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-line); }
.tag-fijo { margin-left: 8px; font-size: 11px; padding: 2px 8px; vertical-align: middle; }
.cat-tag.small { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.cat-tag.small .chip-dot { width: 9px; height: 9px; }
.block { display: block; }
.inline-form { display: inline; margin: 0; }
.tbl td small.muted { font-size: 12px; }
input[type="month"].input, input[type="number"].input { min-height: 48px; }

@media (max-width: 1100px) {
    .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .kpis.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1000px) {
    .kpis, .kpis.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpis > .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
    .kpis .kpi-v { font-size: 20px; }
}

@media (max-width: 700px) {
    .tbl td[data-l="Gasto fijo"] { justify-content: flex-start; text-align: left; font-size: 16px; padding-bottom: 4px; }
    .tbl td[data-l="Gasto fijo"]::before { content: none; }
}

/* Tablero con 4 tarjetas */
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .kpis:not(.three) { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1000px) { .kpis.three { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpis .kpi-v { font-size: 26px; }
@media (max-width: 520px) { .kpis .kpi-v { font-size: 20px; } }

/* =====================================================================
   Informes
   ===================================================================== */
.tabs { display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 20px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 4px 12px rgba(10, 35, 66, .06); }
.tab { padding: 10px 20px; border-radius: 9px; font-weight: 700; font-size: 14.5px; color: var(--muted); text-decoration: none; }
.tab:hover { color: var(--navy-800); background: #EEF3FC; }
.tab.on { background: var(--navy-800); color: #fff; }

.table-scroll { overflow-x: auto; }
.tbl.compact th, .tbl.compact td { padding: 11px 14px; }
.tbl tfoot td { padding: 13px 14px; font-weight: 800; color: var(--navy-800); border-top: 2px solid var(--line); background: #F7F9FD; }
.tbl.matrix { font-size: 13px; min-width: 980px; }
.tbl.matrix th, .tbl.matrix td { padding: 10px 8px; }
.tbl.matrix td:first-child, .tbl.matrix th:first-child { position: sticky; left: 0; background: #fff; z-index: 1; padding-left: 14px; }
.tbl.matrix tfoot td:first-child { background: #F7F9FD; }
.legend .lg { display: flex; align-items: center; gap: 10px; padding: 7px 8px; font-size: 14px; }
.legend .pct { color: var(--muted); min-width: 52px; text-align: right; }
.mbars.twelve { gap: 6px; }
.mbars.twelve .mb b { font-size: 10.5px; }
.year-split { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 28px; align-items: center; }
.foot-note { margin: 22px 0 0; font-size: 12.5px; color: var(--muted); }

@media (max-width: 860px) {
    .year-split { grid-template-columns: 1fr; }
    .tabs { display: flex; }
    .tab { flex: 1; text-align: center; }
    .head-actions .btn-auto { flex: 1 1 100%; }
    .mbars.twelve .mb b { display: none; }
}
@media (max-width: 700px) {
    /* En móvil las tablas del informe se desplazan en lugar de volverse tarjetas */
    .tbl.compact { display: table; width: 100%; }
    .tbl.compact thead { display: table-header-group; }
    .tbl.compact tbody { display: table-row-group; }
    .tbl.compact tfoot { display: table-footer-group; }
    .tbl.compact tr { display: table-row; background: none; border: 0; box-shadow: none; padding: 0; margin: 0; }
    .tbl.compact td, .tbl.compact th { display: table-cell; width: auto; padding: 10px 10px; text-align: left; }
    .tbl.compact td.num, .tbl.compact th.num { text-align: right; }
    .tbl.compact td::before { content: none; }
    .tbl.compact { min-width: 520px; }
    .tbl.matrix { min-width: 980px; }
}

/* ---------- Impresión / PDF ---------- */
@media print {
    @page { size: A4; margin: 14mm; }
    html, body, body.app { background: #fff !important; }
    .topbar, .fab, .no-print, .flash, .tabs { display: none !important; }
    .app-main { max-width: none; padding: 0; }
    .panel, .kpi { box-shadow: none !important; border: 1px solid #CBD6E6 !important; }
    .panel { padding: 14px !important; }
    .kpis { grid-template-columns: repeat(4, 1fr) !important; gap: 10px; }
    .dash { gap: 12px; }
    .avoid-break { break-inside: avoid; }
    .page-head h1 { font-size: 24px; }
    .table-scroll { overflow: visible; }
    .tbl.matrix { min-width: 0; font-size: 9.5px; }
    .tbl.matrix th, .tbl.matrix td { padding: 5px 3px; }
    a { color: inherit !important; text-decoration: none !important; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Marca de presupuesto en cada barra mensual */
.mb .tick { position: absolute; left: 6%; right: 6%; bottom: calc(28px + (100% - 52px) * var(--b, 0)); border-top: 2.5px solid var(--gold); border-radius: 2px; z-index: 2; pointer-events: none; }
.tick-key { display: inline-block; width: 18px; border-top: 2.5px solid var(--gold); vertical-align: middle; margin-right: 6px; }
.current-budget { display: grid; gap: 2px; margin-bottom: 22px; padding: 14px 16px; border-radius: 12px; background: #FBF1D3; color: #7A5A12; }
.current-budget span { font-size: 13px; font-weight: 600; }
.current-budget strong { font-size: 26px; letter-spacing: -.5px; color: var(--navy-800); }

.danger-title { margin: 0 0 8px; font-size: 16px; color: var(--danger); }
.danger-zone .field { margin-bottom: 14px; }

/* Instalación como app */
[hidden] { display: none !important; }
.install-hint { margin: 4px 8px 8px; padding: 10px 12px; border-radius: 8px; background: #E4EDFF; color: #1A41BF; font-size: 13px; line-height: 1.4; }
.um-panel #install-app { color: var(--primary); font-weight: 600; }
/* En la app instalada, las zonas seguras del teléfono (muesca) no tapan la barra */
@media (display-mode: standalone) { .topbar { padding-top: env(safe-area-inset-top); } }
