:root {
    --brand: #4f46e5;
    --brand-2: #6366f1;
    --brand-dark: #312e81;
    --sidebar-w: 264px;
    --bg: #f1f5f9;
    --card-shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 16px rgba(15, 23, 42, .06);
    --radius: 14px;
}

* { font-family: 'dmsans', system-ui, -apple-system, sans-serif; }

body {
    background: var(--bg);
    color: #1e293b;
    font-size: .925rem;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    min-height: 100vh;
    background: linear-gradient(180deg, #1e1b4b 0%, #312e81 100%);
    color: #c7d2fe;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    /* La barra de scroll del menú no debe consumir ancho: si lo hace, el
       contenido deja de estar centrado en el riel contraído. */
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 1rem;
    z-index: 1040;
}
.sidebar::-webkit-scrollbar { width: 0; height: 0; }
.sidebar .brand {
    display: flex; align-items: center; justify-content: center;
    gap: .55rem;
    font-weight: 800; font-size: 1.05rem; color: #fff;
    padding: 1.1rem 1.4rem;
    letter-spacing: -.01em;
}
.brand-dot {
    width: 11px; height: 11px; border-radius: 4px;
    background: linear-gradient(135deg, #818cf8, #34d399);
    display: inline-block;
}
.brand-logo {
    height: 46px; width: auto;
    max-width: 240px; object-fit: contain;
    flex-shrink: 0;
}
.brand-icon {
    display: none;
    height: 40px; width: auto;
    flex-shrink: 0;
}
.brand-logo-login { height: 96px; max-width: 320px; }
.login-logo .brand-logo { height: 96px; width: auto; }
.sidebar .nav { padding: .25rem .75rem; }
.sidebar .nav-link {
    color: #c7d2fe; border-radius: 10px;
    padding: .52rem .8rem; font-size: .875rem; font-weight: 500;
    margin-bottom: .15rem;
    display: flex; align-items: center; gap: .15rem;
    white-space: nowrap;
    transition: all .15s ease;
}
.sidebar .nav-link .nav-label {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.nav-badge {
    margin-left: auto;
    min-width: 20px; height: 20px; padding: 0 5px;
    border-radius: 10px;
    background: #ef4444; color: #fff;
    font-size: .68rem; font-weight: 700; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.prop-chip {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    background: rgba(255,255,255,.9);
    border: 1px solid rgba(99,102,241,.3);
    border-radius: 999px;
    padding: .28rem .7rem;
    font-size: .82rem;
    color: #334155;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(15,23,42,.06);
}
.prop-chip .badge { font-weight: 600; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar .nav-link.active {
    background: linear-gradient(90deg, #6366f1, #818cf8);
    color: #fff; font-weight: 600;
    box-shadow: 0 4px 12px rgba(99,102,241,.35);
}
.sidebar .nav-sec {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
    color: #818cf8; padding: .9rem .8rem .35rem; font-weight: 700;
}
.sidebar-foot { padding: .8rem 1.4rem; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-collapsed .sidebar {
    width: 78px;
    flex-basis: 78px;
    transition: width .2s ease, flex-basis .2s ease;
}
.sidebar-collapsed .sidebar .brand { padding: 1.1rem .5rem; }
.sidebar-collapsed .sidebar .brand-logo { display: none; }
.sidebar-collapsed .sidebar .brand-icon { display: inline-block; height: 44px; }
.sidebar-collapsed .sidebar .nav { padding: .25rem .45rem; }
.sidebar-collapsed .sidebar .nav-link {
    justify-content: center;
    padding: .55rem .5rem;
}
.sidebar-collapsed .sidebar .nav-link .nav-label,
.sidebar-collapsed .sidebar .nav-link .nav-badge,
.sidebar-collapsed .sidebar .nav-sec,
.sidebar-collapsed .sidebar .sidebar-foot span {
    display: none;
}
.sidebar-collapsed .sidebar .nav-link i { margin: 0 !important; }
.sidebar-collapsed .sidebar .sidebar-foot { padding: .9rem .5rem; text-align: center; font-size: 0; }
.sidebar-collapsed .sidebar .sidebar-foot .badge { font-size: .7rem; }
.sidebar-mobile { background: #1e1b4b; color: #c7d2fe; }
.sidebar-mobile .brand { display: flex; align-items: center; justify-content: center; }
.sidebar-mobile .nav-link { color: #c7d2fe; border-radius: 10px; padding: .55rem .9rem; display: flex; align-items: center; white-space: nowrap; }
.sidebar-mobile .nav-link .nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sidebar-mobile .nav-link.active { background: #6366f1; color: #fff; }
.sidebar-mobile .nav-sec {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
    color: #818cf8; padding: .9rem .8rem .35rem; font-weight: 700;
}

/* ---------- Contenido ---------- */
.content-wrap { min-width: 0; overflow-x: auto; width: 100%; }

.topbar {
    background: rgba(255,255,255,.9);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid #e2e8f0;
    padding: .7rem 1.4rem;
    position: sticky; top: 0; z-index: 1020;
}
.topbar-title { font-weight: 700; font-size: 1.02rem; line-height: 1.1; }
.topbar-sub { font-size: .74rem; color: #64748b; }
.tasa-chip {
    background: #eef2ff; color: #4338ca;
    border: 1px solid #e0e7ff; border-radius: 999px;
    padding: .35rem .85rem; font-size: .78rem; font-weight: 600;
}
.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #34d399);
    color: #fff; font-weight: 700; font-size: .85rem;
    display: inline-flex; align-items: center; justify-content: center;
}
.page-body { padding: 1.4rem; }
.page-footer { padding: .9rem 1.4rem 1.4rem; }

.datos-metodo {
    margin: 0; padding: .6rem .8rem; white-space: pre-wrap;
    font-size: .8rem; color: #1e293b; background: #f8fafc;
    border: 1px solid #e2e8f0; border-radius: 8px;
}

/* ---------- Componentes ---------- */
.card { border: 0; border-radius: var(--radius); box-shadow: var(--card-shadow); }
.card-header {
    background: #fff; border: 0; border-radius: var(--radius) var(--radius) 0 0 !important;
    padding: 1rem 1.25rem;
}
.card-title { font-weight: 700; }
.table > :not(caption) > * > * { padding: .6rem .75rem; }
.table thead th {
    font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
    color: #64748b; font-weight: 700; border-bottom: 1px solid #e2e8f0;
}
.table tbody tr:hover { background: #f8fafc; }

.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-body { padding: 1.4rem 1.5rem; }
.stat-card .stat-icon {
    position: absolute; right: -8px; top: -8px; font-size: 4.5rem;
    opacity: .08;
}
.stat-card .stat-label { font-size: .76rem; color: #64748b; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .stat-value { font-size: 1.55rem; font-weight: 800; letter-spacing: -.02em; }

.btn-brand {
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #fff; border: 0; font-weight: 600;
    box-shadow: 0 4px 12px rgba(79,70,229,.3);
}
.btn-brand:hover { color: #fff; filter: brightness(1.08); }
.btn-brand-outline {
    border: 1.5px solid #6366f1; color: #4f46e5; background: #fff; font-weight: 600;
}
.btn-brand-outline:hover { background: #eef2ff; color: #312e81; }
.btn-outline-danger:hover { background: #fdecec; color: #b91c1c; border-color: #dc3545; }
.btn-outline-warning:hover { background: #fff8e6; color: #b45309; border-color: #ffc107; }
.btn-outline-success:hover { background: #e9f9ef; color: #15803d; border-color: #198754; }
#btnEliminarSel:disabled, #btnAjusteSel:disabled { pointer-events: auto; cursor: not-allowed; }

.form-control, .form-select {
    border-radius: 10px; border-color: #cbd5e1;
    font-size: .9rem;
}
.form-control:focus, .form-select:focus {
    border-color: #818cf8; box-shadow: 0 0 0 .2rem rgba(99,102,241,.15);
}
.form-label { font-weight: 600; font-size: .82rem; color: #475569; }

.badge { font-weight: 600; padding: .45em .7em; }

.nav-pills .nav-link { font-weight: 600; color: #475569; }
.nav-pills .nav-link.active { background: #eef2ff; color: #4f46e5; }

.filter-bar { background: #fff; border: 1px solid #e2e8f0; border-radius: var(--radius); }

/* Listado pagos / mensajes */
.list-msg { border: 1px solid #e2e8f0; border-radius: var(--radius); }
.list-msg:hover { border-color: #c7d2fe; background: #f8fafc; }
.msg-unread { border-left: 4px solid #6366f1; background: #f5f6ff; }

/* Login */
.login-wrap {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1e1b4b 0%, #3730a3 60%, #4f46e5 100%);
    padding: 1.5rem;
}
.login-card { width: 100%; max-width: 420px; border-radius: 20px; }
.login-logo { font-weight: 800; font-size: 1.35rem; }

/* Utilidades */
.cursor-pointer { cursor: pointer; }
.text-usd { color: #047857; font-weight: 600; }
.text-bs { color: #b45309; font-weight: 600; }

html { scroll-behavior: smooth; }

/* Histórico de cuotas pagadas (owner): grid con la MISMA plantilla en la cabecera
   (etiquetas) y en cada fila del acordeón, de modo que las columnas siempre alinean,
   incluso en móvil. */
.hist-cols {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 7.5rem 11rem 6.5rem;
    align-items: center;
    gap: .5rem;
}
.hist-head { padding-inline: 0; }
.hist-col-periodo { min-width: 0; }
.hist-col-cuotas  { text-align: right; }
.hist-col-total   { text-align: right; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-col-recibo  { text-align: center; min-width: 0; }
.hist-label {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .02em;
    color: #64748b;
    font-weight: 700;
}
@media (max-width: 575.98px) {
    /* Oculta el RIF/cedula del condominio en la barra superior (solo móvil) */
    .cond-rif { display: none; }
    /* Móvil: 3 columnas (Periodo · Total · Recibo); la columna Cuotas se oculta
       para que las columnas queden anchas y perfectamente alineadas. */
    .hist-cols { grid-template-columns: minmax(0, 1fr) 7rem 6.5rem; gap: .25rem; padding-inline: .5rem; }
    .hist-col-cuotas { display: none; }
    /* El botón Recibo ocupa toda su celda para no descuadrar en móvil */
    .hist-col-recibo { display: flex; align-items: center; justify-content: center; }
    .hist-col-recibo .btn { width: auto; padding-left: .4rem; padding-right: .4rem; white-space: nowrap; }
    /* Más respiración al título PERIODO en móvil */
    .hist-head .hist-col-periodo { padding-left: .25rem; }
    /* Historial de pagos (vista móvil): fila tipo tarjeta */
    .pago-movil { padding: .6rem .25rem; border-bottom: 1px solid #eef2f7; }
    .pago-movil:last-child { border-bottom: 0; }
    /* Detalle de conceptos resumido dentro del acordeón de cuotas pendientes */
    .pend-concepto { padding: .5rem .25rem; border-bottom: 1px solid #eef2f7; }
    .pend-concepto:last-child { border-bottom: 0; }
    .min-w-0 { min-width: 0; }
    /* Reportar pago: "Seleccione qué desea pagar" como tarjeta compacta en móvil
       (solo tilde · concepto resumido · monto) */
    .cuotas-pagar-table thead { display: none; }
    .cuotas-pagar-table, .cuotas-pagar-table tbody, .cuotas-pagar-table tr, .cuotas-pagar-table td { display: block; width: 100%; }
    .cuotas-pagar-table tr { display: flex; align-items: center; gap: .6rem; border: 1px solid #eef2f7; border-radius: .5rem; margin-bottom: .6rem; padding: .4rem .6rem; }
    .cuotas-pagar-table td { border: 0; padding: 0; width: auto; display: block; }
    .cuotas-pagar-table td::before { content: none; }
    .cuotas-pagar-table td.cell-chk { flex: 0 0 auto; }
    .cuotas-pagar-table td[data-label="Concepto"] { flex: 1 1 auto; min-width: 0; }
    .cuotas-pagar-table td[data-label="Saldo"] { flex: 0 0 auto; text-align: right; }
    .cuotas-pagar-table td[data-label="Periodo"],
    .cuotas-pagar-table td[data-label="Propiedad"] { display: none; }
    .concepto-res { display: block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
    .concepto-res:focus, .concepto-res.expanded { white-space: normal; overflow: visible; outline: none; }
    .concepto-res .concepto-det { display: none; font-weight: 400; color: #64748b; }
    .concepto-res.expanded .concepto-det { display: block; white-space: normal; margin-top: .15rem; }
    /* Mis recibos: filas como tarjetas en móvil */
    .recibos-table thead { display: none; }
    .recibos-table, .recibos-table tbody, .recibos-table tr, .recibos-table td { display: block; width: 100%; }
    .recibos-table tr { border: 1px solid #eef2f7; border-radius: .5rem; margin-bottom: .75rem; padding: .35rem .6rem; }
    .recibos-table td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .25rem 0; border: 0; }
    .recibos-table td::before { content: attr(data-label); font-size: .7rem; text-transform: uppercase; letter-spacing: .02em; color: #64748b; font-weight: 700; }
    .recibos-table td.cell-recibo { justify-content: flex-end; }
    .recibos-table td.cell-recibo::before { content: none; }
    /* Desglose de gastos (móvil): tarjeta resumen + detalle al tocar */
    .gasto-card { border: 1px solid #eef2f7; border-radius: .5rem; margin-bottom: .6rem; overflow: hidden; }
    .gasto-sum { display: flex; align-items: center; gap: .6rem; padding: .6rem .7rem; cursor: pointer; }
    .gasto-det { display: none; padding: 0 .7rem .6rem; border-top: 1px solid #eef2f7; }
    .gasto-card.open .gasto-det { display: block; }
    .gd-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .3rem 0; font-size: .85rem; border-bottom: 1px solid #f1f5f9; }
    .gd-row:last-child { border-bottom: 0; }
    .gd-row > span { color: #64748b; }
    .gasto-chev { transition: transform .2s; color: #94a3b8; }
    .gasto-card.open .gasto-chev { transform: rotate(180deg); }
    /* Mensajes: items más compactos en móvil (cuerpo recortado) */
    .msg-item { padding: .75rem 1rem !important; gap: .75rem !important; }
    .msg-item .avatar { width: 2.25rem; height: 2.25rem; font-size: .8rem; }
    .msg-item p { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: .5rem; }
    /* Pulso para resaltar el botón "Todo" en móvil */
    .btn-pulse { animation: btnPulse 1.8s infinite; }
    @keyframes btnPulse {
        0%   { box-shadow: 0 0 0 0 rgba(180, 83, 9, .55); }
        70%  { box-shadow: 0 0 0 .6rem rgba(180, 83, 9, 0); }
        100% { box-shadow: 0 0 0 0 rgba(180, 83, 9, 0); }
    }
    /* Modal recibo/presupuesto: el comprobante (279mm) debe caber en móvil */
    #reciboContenido, #presupuestoContenido { padding: 8px !important; display: block !important; overflow-x: auto; }
    #reciboContenido .rbo, #presupuestoContenido .rbo {
        width: 100% !important; min-height: auto !important; padding: 8mm !important;
        box-shadow: none !important; transform: none !important;
    }
    #reciboContenido .rbo-banner, #presupuestoContenido .rbo-banner { flex-direction: column; align-items: flex-start; gap: 8px; }
    #reciboContenido .rbo-datos, #presupuestoContenido .rbo-datos { flex-direction: column; gap: 6px; }
    #reciboContenido .rbo-pago, #presupuestoContenido .rbo-pago { flex-direction: column; align-items: stretch; }
    #reciboContenido .rbo-tipos-grid, #presupuestoContenido .rbo-tipos-grid { grid-template-columns: 1fr; }
    #reciboContenido .rbo-total .amt, #presupuestoContenido .rbo-total .amt { font-size: 18px; }
    /* Tablas del recibo (Pagos aplicados, Gastos, Detalle): quitar anchos fijos
       inline y usar columnas fluidas para que caben y queden alineadas */
    #reciboContenido .rbo-tab, #presupuestoContenido .rbo-tab { table-layout: fixed; font-size: 11px; }
    #reciboContenido .rbo-tab th, #presupuestoContenido .rbo-tab th,
    #reciboContenido .rbo-tab td, #presupuestoContenido .rbo-tab td { padding: 5px 6px; }
    #reciboContenido .rbo-tab th[style], #presupuestoContenido .rbo-tab th[style] { width: auto !important; }
    #reciboContenido .rbo-tab .r, #presupuestoContenido .rbo-tab .r { white-space: normal !important; }
    /* El comprobante nunca debe rebalsar su tarjeta blanca */
    #reciboContenido .rbo, #presupuestoContenido .rbo { overflow: hidden !important; }
    #modalRecibo .modal-footer, #modalPresupuesto .modal-footer { flex-wrap: wrap; }
    #modalRecibo .modal-footer .btn, #modalPresupuesto .modal-footer .btn { flex: 1 1 auto; }
}

@media (max-width: 991.98px) {
    .page-body { padding: 1rem; }
}

/* Detalle completo del cargo (oculto hasta tocar/Enter; solo se muestra expandido en móvil) */
.concepto-res .concepto-det { display: none; }
