/* =========================================================
   Control de Gastos — tema visual
   ========================================================= */

:root {
    --app-primary: #6d5dfc;
    --app-primary-2: #8b5cf6;
    --app-primary-dark: #5444e6;
    --app-primary-soft: #efedff;
    --app-bg: #f4f5fb;
    --app-surface: #ffffff;
    --app-border: #e9eaf3;
    --app-text: #1f2140;
    --app-muted: #7a7d9c;
    --app-success: #16a34a;
    --app-success-soft: #e7f8ee;
    --app-danger: #e5484d;
    --app-danger-soft: #fdecec;
    --app-warning: #d97706;
    --app-warning-soft: #fef3e2;
    --app-radius: 1.1rem;
    --app-radius-sm: .75rem;
    --app-shadow: 0 1px 2px rgba(31, 33, 64, .04), 0 6px 20px rgba(31, 33, 64, .06);
    --app-shadow-lg: 0 10px 30px rgba(109, 93, 252, .30);
    --app-gradient: linear-gradient(135deg, #6d5dfc 0%, #8b5cf6 55%, #c06cf0 100%);

    --bs-body-font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --bs-body-color: var(--app-text);
    --bs-body-bg: var(--app-bg);
    --bs-primary: var(--app-primary);
    --bs-primary-rgb: 109, 93, 252;
    --bs-link-color: var(--app-primary);
    --bs-link-color-rgb: 109, 93, 252;
    --bs-link-hover-color: var(--app-primary-dark);
    --bs-border-color: var(--app-border);
    --bs-secondary-color: var(--app-muted);
    --bs-border-radius: .7rem;
    --bs-border-radius-sm: .55rem;
    --bs-border-radius-lg: 1rem;
}

[data-bs-theme="dark"] {
    --app-primary: #8b7dff;
    --app-primary-dark: #a99fff;
    --app-primary-soft: rgba(139, 125, 255, .16);
    --app-bg: #0f1020;
    --app-surface: #191a2e;
    --app-border: #2a2c45;
    --app-text: #e8e9f6;
    --app-muted: #9a9cbb;
    --app-success-soft: rgba(22, 163, 74, .16);
    --app-danger-soft: rgba(229, 72, 77, .16);
    --app-warning-soft: rgba(217, 119, 6, .18);
    --app-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);

    --bs-body-color: var(--app-text);
    --bs-body-bg: var(--app-bg);
    --bs-link-color: var(--app-primary);
    --bs-link-hover-color: var(--app-primary-dark);
    --bs-border-color: var(--app-border);
    --bs-secondary-color: var(--app-muted);
    --bs-tertiary-bg: #22243b;
    --bs-secondary-bg: #22243b;
}

html { font-size: 15px; }
@media (min-width: 768px) { html { font-size: 16px; } }

body {
    background: var(--app-bg);
    color: var(--app-text);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

h1, h2, h3, h4, h5, .h1, .h2, .h3, .h4, .h5 { font-weight: 700; letter-spacing: -.01em; }

.text-muted, .text-body-secondary { color: var(--app-muted) !important; }

/* ---------- Botones ---------- */
.btn { font-weight: 600; border-radius: .7rem; }
.btn-sm { border-radius: .6rem; }
.btn-primary {
    --bs-btn-bg: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary-dark);
    --bs-btn-hover-border-color: var(--app-primary-dark);
    --bs-btn-active-bg: var(--app-primary-dark);
    --bs-btn-active-border-color: var(--app-primary-dark);
    --bs-btn-disabled-bg: var(--app-primary);
    --bs-btn-disabled-border-color: var(--app-primary);
    box-shadow: 0 4px 14px rgba(109, 93, 252, .28);
}
.btn-outline-primary {
    --bs-btn-color: var(--app-primary);
    --bs-btn-border-color: transparent;
    --bs-btn-bg: var(--app-primary-soft);
    --bs-btn-hover-bg: var(--app-primary);
    --bs-btn-hover-border-color: var(--app-primary);
    --bs-btn-hover-color: #fff;
    --bs-btn-active-bg: var(--app-primary-dark);
    --bs-btn-active-border-color: var(--app-primary-dark);
}
.btn-outline-secondary {
    --bs-btn-color: var(--app-text);
    --bs-btn-border-color: var(--app-border);
    --bs-btn-bg: var(--app-surface);
    --bs-btn-hover-bg: var(--app-primary-soft);
    --bs-btn-hover-border-color: var(--app-primary-soft);
    --bs-btn-hover-color: var(--app-primary);
    --bs-btn-active-bg: var(--app-primary-soft);
    --bs-btn-active-color: var(--app-primary);
}
.btn-outline-success {
    --bs-btn-color: var(--app-success);
    --bs-btn-border-color: transparent;
    --bs-btn-bg: var(--app-success-soft);
    --bs-btn-hover-bg: var(--app-success);
    --bs-btn-hover-border-color: var(--app-success);
}
.btn-outline-danger {
    --bs-btn-color: var(--app-danger);
    --bs-btn-border-color: transparent;
    --bs-btn-bg: var(--app-danger-soft);
    --bs-btn-hover-bg: var(--app-danger);
    --bs-btn-hover-border-color: var(--app-danger);
}
.btn-success { --bs-btn-bg: var(--app-success); --bs-btn-border-color: var(--app-success); }

/* ---------- Formularios ---------- */
.form-control, .form-select {
    border-radius: .7rem;
    border-color: var(--app-border);
    background-color: var(--app-surface);
    padding: .6rem .85rem;
}
[data-bs-theme="dark"] .form-control, [data-bs-theme="dark"] .form-select { background-color: #12132a; border-color: #34365a; }
.form-control-sm, .form-select-sm { padding: .35rem .65rem; border-radius: .55rem; }
.form-control:focus, .form-select:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 .25rem rgba(109, 93, 252, .15);
}
.form-label { font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
.input-group-text { background: var(--app-primary-soft); color: var(--app-primary); border-color: var(--app-border); font-weight: 600; }
.form-check-input:checked { background-color: var(--app-primary); border-color: var(--app-primary); }

/* ---------- Tarjetas ---------- */
.card {
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
    overflow: hidden;
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--app-border);
    padding: .9rem 1.1rem;
    font-weight: 700;
}
.card-body { padding: 1.1rem; }

.seccion-titulo { font-weight: 700; font-size: 1rem; display: flex; align-items: center; gap: .5rem; }
.seccion-titulo i { color: var(--app-primary); }

/* ---------- Listas ---------- */
.list-group { --bs-list-group-bg: var(--app-surface); --bs-list-group-border-color: var(--app-border); }
.list-group-item { padding: .85rem 1.1rem; }
.list-group-item-action:hover { background: var(--app-primary-soft); }
.list-group-item .meta, .meta { font-size: .78rem; color: var(--app-muted); }
.meta > span + span::before { content: "·"; margin: 0 .35rem; opacity: .6; }
.min-w-0 { min-width: 0; }

/* ---------- Badges ---------- */
.badge { font-weight: 600; border-radius: 2rem; padding: .35em .7em; }
.chip { display: inline-flex; align-items: center; gap: .25rem; font-size: .72rem; font-weight: 600; padding: .15rem .55rem; border-radius: 2rem; background: var(--app-primary-soft); color: var(--app-primary); white-space: nowrap; }
.chip-success { background: var(--app-success-soft); color: var(--app-success); }
.chip-danger { background: var(--app-danger-soft); color: var(--app-danger); }
.chip-warning { background: var(--app-warning-soft); color: var(--app-warning); }
.chip-neutral { background: var(--bs-tertiary-bg); color: var(--app-muted); }

/* ---------- Íconos redondos / avatares ---------- */
.icono-burbuja, .avatar {
    width: 2.6rem; height: 2.6rem; border-radius: .9rem; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center; font-size: 1.15rem;
}
.avatar { border-radius: 50%; font-size: .85rem; font-weight: 700; }
.avatar-sm { width: 2rem; height: 2rem; font-size: .72rem; }
.c-0 { background: #efedff; color: #6d5dfc; }
.c-1 { background: #e3f6ff; color: #0284c7; }
.c-2 { background: #e7f8ee; color: #16a34a; }
.c-3 { background: #fff1e6; color: #ea580c; }
.c-4 { background: #fde8f3; color: #db2777; }
.c-5 { background: #fef9c3; color: #a16207; }
.c-6 { background: #e0f2f1; color: #0f766e; }
.c-7 { background: #f1f5f9; color: #475569; }
[data-bs-theme="dark"] .c-0 { background: rgba(109, 93, 252, .2); color: #a99fff; }
[data-bs-theme="dark"] .c-1 { background: rgba(2, 132, 199, .2); color: #7dd3fc; }
[data-bs-theme="dark"] .c-2 { background: rgba(22, 163, 74, .2); color: #86efac; }
[data-bs-theme="dark"] .c-3 { background: rgba(234, 88, 12, .2); color: #fdba74; }
[data-bs-theme="dark"] .c-4 { background: rgba(219, 39, 119, .2); color: #f9a8d4; }
[data-bs-theme="dark"] .c-5 { background: rgba(161, 98, 7, .25); color: #fde047; }
[data-bs-theme="dark"] .c-6 { background: rgba(15, 118, 110, .25); color: #5eead4; }
[data-bs-theme="dark"] .c-7 { background: rgba(71, 85, 105, .3); color: #cbd5e1; }
.c-yo { background: var(--app-gradient); color: #fff; }

/* ---------- Navegación ---------- */
.app-navbar {
    position: sticky; top: 0; z-index: 1030;
    background: color-mix(in srgb, var(--app-surface) 85%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--app-border);
}
.app-brand { display: flex; align-items: center; gap: .55rem; font-weight: 800; color: var(--app-text); text-decoration: none; font-size: 1.1rem; }
.app-brand:hover { color: var(--app-text); }
.app-logo {
    width: 2.1rem; height: 2.1rem; border-radius: .7rem; background: var(--app-gradient); color: #fff;
    display: inline-flex; align-items: center; justify-content: center; font-size: 1.05rem;
    box-shadow: 0 4px 12px rgba(109, 93, 252, .35);
}
.app-nav .nav-link {
    color: var(--app-muted); font-weight: 600; border-radius: .7rem; padding: .45rem .85rem !important;
    display: flex; align-items: center; gap: .4rem;
}
.app-nav .nav-link:hover { color: var(--app-primary); background: var(--app-primary-soft); }
.app-nav .nav-link.active { color: var(--app-primary); background: var(--app-primary-soft); }
.dropdown-menu {
    border: 1px solid var(--app-border); border-radius: var(--app-radius-sm); box-shadow: var(--app-shadow);
    padding: .4rem; --bs-dropdown-bg: var(--app-surface);
}
.dropdown-item { border-radius: .55rem; padding: .5rem .75rem; font-weight: 500; display: flex; align-items: center; gap: .55rem; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--app-primary-soft); color: var(--app-primary); }
.dropdown-item i { width: 1.1rem; text-align: center; }

/* Barra inferior (celular) */
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
    background: color-mix(in srgb, var(--app-surface) 92%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-top: 1px solid var(--app-border);
    display: flex; justify-content: space-around; align-items: flex-end;
    padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
}
.bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: .1rem;
    color: var(--app-muted); text-decoration: none; font-size: .68rem; font-weight: 600; padding: .25rem 0;
}
.bottom-nav a i { font-size: 1.3rem; line-height: 1; }
.bottom-nav a.active { color: var(--app-primary); }
.bottom-nav .nav-mas {
    flex: 0 0 auto; width: 3.4rem; height: 3.4rem; margin-top: -1.6rem; border-radius: 50%;
    background: var(--app-gradient); color: #fff !important; justify-content: center; box-shadow: var(--app-shadow-lg);
    border: 4px solid var(--app-bg);
}
.bottom-nav .nav-mas i { font-size: 1.5rem; }
.app-main { padding-top: 1rem; padding-bottom: 3rem; }
@media (max-width: 991.98px) {
    /* Espacio para que la barra inferior no tape el final de la página */
    .app-main { padding-bottom: calc(7rem + env(safe-area-inset-bottom)); }
}

/* ---------- Hero (inicio) ---------- */
.hero {
    background: var(--app-gradient);
    color: #fff;
    border-radius: 1.4rem;
    padding: 1.25rem 1.25rem 1.4rem;
    box-shadow: var(--app-shadow-lg);
    position: relative;
    overflow: hidden;
}
.hero::before, .hero::after {
    content: ""; position: absolute; border-radius: 50%; background: rgba(255, 255, 255, .09); pointer-events: none;
}
.hero::before { width: 260px; height: 260px; right: -80px; top: -110px; }
.hero::after { width: 180px; height: 180px; left: -60px; bottom: -100px; }
.hero > * { position: relative; z-index: 1; }
.hero-mes { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: 1rem; }
.hero-mes .btn-mes {
    width: 2.3rem; height: 2.3rem; border-radius: .75rem; border: 0; background: rgba(255, 255, 255, .18); color: #fff;
    display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
}
.hero-mes .btn-mes:hover { background: rgba(255, 255, 255, .3); }
.hero-mes .mes-titulo { position: relative; font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: .4rem; cursor: pointer; }
.hero-mes .mes-titulo input[type=month] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.hero-mes .btn-hoy { color: #fff; font-size: .75rem; font-weight: 700; background: rgba(255, 255, 255, .18); border-radius: 2rem; padding: .15rem .6rem; text-decoration: none; }
.hero-label { font-size: .85rem; opacity: .85; font-weight: 500; }
.hero-monto { font-size: 2.4rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
@media (min-width: 768px) { .hero-monto { font-size: 2.9rem; } }
.hero-sub { font-size: .85rem; opacity: .9; }
.hero .progress { background: rgba(255, 255, 255, .22); height: .5rem; border-radius: 1rem; }
.hero .progress-bar { background: #fff; border-radius: 1rem; }

/* Mini estadísticas */
.stat { display: flex; align-items: center; gap: .8rem; }
.stat-label { font-size: .75rem; color: var(--app-muted); font-weight: 600; }
@media (max-width: 575.98px) {
    .stat .icono-burbuja { display: none; }
    .stat-valor { font-size: 1.05rem !important; }
    .stat .text-truncate { white-space: normal; }
}
.stat-valor { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

.kpi-label { font-size: .75rem; color: var(--app-muted); font-weight: 600; }
.kpi-valor { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.monto { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 700; }

/* Personas (a quién le debo) */
.deudas { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.deuda {
    display: flex; flex-direction: column; gap: .5rem; padding: .9rem; border-radius: var(--app-radius-sm);
    background: var(--app-surface); border: 1px solid var(--app-border); text-decoration: none; color: var(--app-text);
    transition: transform .15s ease, box-shadow .15s ease;
}
.deuda:hover { transform: translateY(-2px); box-shadow: var(--app-shadow); color: var(--app-text); }
.deuda .nombre { font-weight: 700; font-size: .9rem; }

/* ---------- Cuotas ---------- */
.cuota-fila { display: flex; align-items: center; gap: .8rem; }
.cuota-pagada .desc { text-decoration: line-through; opacity: .55; }
.cuota-pagada .monto { opacity: .55; }
.btn-check-pago {
    width: 2.6rem; height: 2.6rem; padding: 0; border-radius: .9rem;
    display: inline-flex; align-items: center; justify-content: center; font-size: 1.15rem;
    border: 2px dashed var(--app-border); background: transparent; color: var(--app-muted);
    transition: all .15s ease;
}
@media (hover: hover) { .btn-check-pago:not(.pagada):hover { border-color: var(--app-success); color: var(--app-success); background: var(--app-success-soft); } }
.btn-check-pago.pagada { border: 0; background: var(--app-success); color: #fff; box-shadow: 0 4px 12px rgba(22, 163, 74, .3); }
.btn-check-pago .bi-x-lg { display: none; }
@media (hover: hover) {
    .btn-check-pago.pagada:hover { background: var(--app-danger); box-shadow: none; }
    .btn-check-pago.pagada:hover .bi-check-lg { display: none; }
    .btn-check-pago.pagada:hover .bi-x-lg { display: inline; }
}

/* ---------- Gráfico de barras ---------- */
.barras { display: flex; align-items: flex-end; gap: .35rem; height: 170px; }
.barras .barra { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; text-decoration: none; color: inherit; }
.barras .barra .relleno {
    width: 100%; max-width: 34px; border-radius: .5rem .5rem .25rem .25rem; min-height: 4px;
    background: linear-gradient(180deg, #a99fff, #6d5dfc); opacity: .55; transition: opacity .15s ease, transform .15s ease;
}
.barras .barra:hover .relleno { opacity: 1; transform: scaleY(1.02); }
.barras .barra.actual .relleno { opacity: 1; background: var(--app-gradient); box-shadow: 0 4px 12px rgba(109, 93, 252, .35); }
.barras .barra small { font-size: .62rem; color: var(--app-muted); white-space: nowrap; margin-top: .35rem; font-weight: 600; }
.barras .barra.actual small { color: var(--app-primary); }

.progress { height: .45rem; border-radius: 1rem; background: var(--bs-tertiary-bg); }
.progress-bar { background: var(--app-gradient); border-radius: 1rem; }
.progress-bar.bg-success { background: var(--app-success) !important; }

/* ---------- Pestañas tipo segmento ---------- */
.segmento { display: inline-flex; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: .9rem; padding: .25rem; gap: .2rem; }
.segmento a { padding: .4rem .9rem; border-radius: .7rem; font-weight: 600; font-size: .88rem; color: var(--app-muted); text-decoration: none; }
.segmento-scroll { overflow-x: auto; scrollbar-width: none; margin-left: -2px; padding-left: 2px; }
.segmento-scroll::-webkit-scrollbar { display: none; }
.segmento a { white-space: nowrap; }
.segmento a.active { background: var(--app-primary); color: #fff; box-shadow: 0 3px 10px rgba(109, 93, 252, .3); }

/* ---------- Selector de mes (resumen) ---------- */
.selector-mes { display: flex; align-items: center; justify-content: space-between; gap: .5rem; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--app-radius); padding: .5rem; box-shadow: var(--app-shadow); }
.selector-mes .btn-mes { width: 2.4rem; height: 2.4rem; border-radius: .75rem; display: inline-flex; align-items: center; justify-content: center; background: var(--app-primary-soft); color: var(--app-primary); text-decoration: none; }
.selector-mes .mes-titulo { position: relative; font-weight: 700; display: flex; align-items: center; gap: .4rem; cursor: pointer; }
.selector-mes .mes-titulo input[type=month] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

/* ---------- Estado vacío ---------- */
.vacio { text-align: center; padding: 2.5rem 1rem; color: var(--app-muted); }
.vacio .icono { width: 4rem; height: 4rem; border-radius: 1.2rem; background: var(--app-primary-soft); color: var(--app-primary); display: inline-flex; align-items: center; justify-content: center; font-size: 1.8rem; margin-bottom: .8rem; }

/* ---------- Pantallas de acceso ---------- */
.auth-wrap { min-height: calc(100vh - 2rem); display: flex; align-items: center; justify-content: center; padding: 1rem 0; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .card-body { padding: 2rem 1.6rem; }
.auth-hero { text-align: center; margin-bottom: 1.5rem; }
.auth-hero .app-logo { width: 3.6rem; height: 3.6rem; font-size: 1.7rem; border-radius: 1.1rem; margin-bottom: .9rem; }
body.auth-body {
    background:
        radial-gradient(circle at 15% 10%, rgba(139, 92, 246, .22), transparent 40%),
        radial-gradient(circle at 85% 90%, rgba(109, 93, 252, .22), transparent 45%),
        var(--app-bg);
}

/* ---------- Avisos flotantes ---------- */
.toast-zona { position: fixed; top: 4.5rem; left: 50%; transform: translateX(-50%); z-index: 1090; width: min(92vw, 460px); }
.toast-app {
    display: flex; align-items: flex-start; gap: .6rem; padding: .8rem 1rem; border-radius: var(--app-radius-sm);
    background: var(--app-surface); border: 1px solid var(--app-border); box-shadow: 0 10px 30px rgba(31, 33, 64, .15);
    font-weight: 500; font-size: .9rem; animation: toast-in .25s ease;
}
.toast-app .bi { font-size: 1.15rem; }
.toast-app.ok .bi { color: var(--app-success); }
.toast-app.error .bi { color: var(--app-danger); }
.toast-app.saliendo { animation: toast-out .3s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }

/* ---------- Selector compra / gasto fijo ---------- */
.tipo-gasto {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    padding: .8rem 1rem; border-radius: var(--app-radius-sm); border: 1px dashed var(--app-border);
    background: var(--bs-tertiary-bg); transition: all .15s ease;
}
.tipo-gasto .bi { color: var(--app-muted); }
.tipo-gasto .form-check-input { width: 2.6em; height: 1.4em; margin-top: .15rem; cursor: pointer; }
.tipo-gasto .form-check-label { cursor: pointer; padding-left: .35rem; }
.tipo-gasto.activo { border-style: solid; border-color: var(--app-primary); background: var(--app-primary-soft); }
.tipo-gasto.activo .bi { color: var(--app-primary); }

/* ---------- Varios ---------- */
.titulo-pagina { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.1rem; }
.titulo-pagina h1 { margin: 0; font-size: 1.5rem; }
.titulo-pagina p { margin: .15rem 0 0; color: var(--app-muted); font-size: .88rem; }
.fade-in { animation: toast-in .3s ease; }
