:root {
    --sidebar-width: 280px;
}

body {
    overflow-x: hidden;
}

/* ── Accesibilidad: focus visible para navegación con teclado ── */
:focus-visible {
    outline: 2px solid #6b8cff !important;
    outline-offset: 2px;
}
.sidebar-link:focus-visible,
.offcanvas .sidebar-link:focus-visible {
    outline-color: #fff;
    background: rgba(255, 255, 255, 0.15);
}
.toggle-btn:focus-visible {
    outline-color: #1a1c2e;
}
.btn:focus-visible {
    outline-offset: 1px;
}
.btn:disabled,
button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

/* Mobile top bar */
.mobile-navbar {
    display: flex;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 44px;
    background: #1a1c2e;
    z-index: 1050;
    padding: 0 10px;
}

@media (min-width: 1200px) {
    .mobile-navbar {
        display: none;
    }
}

.mobile-navbar .hamburger {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 6px;
}

.mobile-navbar .mobile-title {
    color: #fff;
    font-weight: 600;
    margin-left: 6px;
    font-size: 0.9rem;
}

/* Desktop sidebar */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(135deg, #1a1c2e 0%, #16181f 100%);
    top: 0;
    left: 0;
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.25s ease;
}

.sidebar.collapsed {
    width: 0;
    overflow: hidden;
}

.toggle-btn {
    position: fixed;
    top: 20px;
    left: calc(var(--sidebar-width) - 16px);
    background: white;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    z-index: 1080;
    cursor: pointer;
    transition: left 0.3s ease, transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1a1c2e;
}

.sidebar.collapsed ~ .toggle-btn {
    left: 10px;
    transform: rotate(180deg);
}

.collapsed .hide-on-collapse {
    opacity: 0;
    visibility: hidden;
}

.collapsed .logo-text {
    opacity: 0;
}

.collapsed .profile-info {
    opacity: 0;
}

.collapsed .sidebar-link {
    display: none;
}

.profile-info {
    transition: opacity 0.2s ease;
}

.sidebar-link {
    color: #a0a3bd;
    transition: all 0.2s ease;
    border-radius: 6px;
    margin: 2px 1px;
    white-space: nowrap;
    overflow: hidden;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    display: block;
}

.sidebar-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(5px);
}

.sidebar .collapse .sidebar-link,
.sidebar .collapsing .sidebar-link {
    color: #ffffff;
}

/* ── Submenu chevron rotation ── */
.sidebar-link[data-bs-toggle] .fa-chevron-down,
.sidebar-link[data-bs-toggle] .fa-chevron-down {
    transition: transform 0.25s ease;
}
.sidebar-link[aria-expanded="true"] .fa-chevron-down {
    transform: rotate(180deg);
}

/* ── Active submenu item indicator ── */
.sidebar .collapse .sidebar-link.active,
.offcanvas .collapse .sidebar-link.active {
    font-weight: 600;
    border-left: 3px solid #6b8cff;
    padding-left: calc(3rem - 3px) !important;
}

/* ── Sidebar dividers ── */
.sidebar-divider {
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin: 4px 16px;
}

.offcanvas#sidebarOffcanvas .collapse .sidebar-link,
.offcanvas#sidebarOffcanvas .collapsing .sidebar-link {
    color: #ffffff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-link.active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.logo-text {
    background: linear-gradient(45deg, #6b8cff, #8b9fff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.notification-badge {
    background: #ff6b6b;
    padding: 1px 3px;
    border-radius: 6px;
    font-size: 0.7rem;
}

.profile-section {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Offcanvas sidebar */
.offcanvas#sidebarOffcanvas {
    background: #1a1c2e;
}

.offcanvas#sidebarOffcanvas .sidebar-link {
    color: #a0a3bd;
    border-radius: 0;
    margin: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.offcanvas#sidebarOffcanvas .sidebar-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.offcanvas#sidebarOffcanvas .sidebar-link.active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

/* Main content */
.main-content {
    margin-left: 0;
    background-color: #f8f9fa;
    min-height: 100vh;
    padding: 12px;
    padding-top: 56px;
}

/* Force full width below desktop (< 1200px) — kills any leftover sidebar offset */
@media (max-width: 1199.98px) {
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    .toggle-btn {
        display: none;
    }
}

@media (min-width: 1200px) {
    .main-content {
        margin-left: var(--sidebar-width);
        padding-top: 15px;
    }
    .sidebar.collapsed ~ .main-content {
        margin-left: 0;
    }
}

/* Messages container — alineado con main-content */
#messagesContainer {
    position: relative;
    z-index: 1060;
    width: auto;
}
@media (min-width: 1200px) {
    #messagesContainer {
        margin-left: var(--sidebar-width);
    }
    .sidebar.collapsed ~ #messagesContainer {
        margin-left: 0;
    }
}
@media (max-width: 767.98px) {
    #messagesContainer {
        padding-top: 52px;
    }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 1199.98px) {
    .main-content .table-sm td,
    .main-content .table-sm th {
        padding: 0.2rem 0.15rem;
        font-size: 0.68rem;
    }
    .main-content .table-sm .btn-sm {
        font-size: 0.6rem;
        padding: 0.1rem 0.25rem;
    }
    .main-content .badge {
        font-size: 0.6rem;
    }
    .nav-tabs .nav-link {
        font-size: 0.75rem;
        padding: 0.35rem 0.4rem;
    }
}

/* Mobile (< 768px) */
@media (max-width: 767.98px) {
    .main-content {
        padding: 0;
        padding-top: 44px;
    }

    .main-content h2 {
        font-size: 1.3rem;
        margin-bottom: 0.5rem;
    }

    .main-content .card-body {
        padding: 0.5rem;
    }

    .main-content .card-header {
        padding: 0.3rem 0.5rem;
    }

    .main-content .card-header strong {
        font-size: 0.95rem;
    }

    /* Nav tabs */
    .nav-tabs .nav-link {
        font-size: 0.9rem;
        padding: 0.3rem;
    }

    /* Badges */
    .badge {
        font-size: 0.8rem;
    }

    /* Form elements */
    .main-content .form-control,
    .main-content .form-select {
        font-size: 0.95rem;
    }
    .main-content .btn {
        font-size: 0.85rem;
        padding: 0.15rem 0.3rem;
    }
    .main-content small,
    .main-content .text-muted {
        font-size: 0.8rem;
    }

    /* Buttons inside tables */
    .main-content .btn-sm {
        font-size: 0.75rem;
        padding: 0.1rem 0.2rem;
    }
    .main-content .btn-sm i {
        font-size: 0.75rem;
    }

    /* Inputs */
    .main-content input[style*="width:100px"] {
        width: 55px !important;
        min-width: 45px !important;
        font-size: 0.8rem;
        padding: 0.1rem 0.15rem;
    }
    .main-content input.mora-input {
        width: 55px !important;
        min-width: 45px !important;
        font-size: 0.8rem;
        padding: 0.1rem 0.15rem;
    }

    /* Mora data en tarjetas de cuota (mobile) */
    .cuota-card .cuota-label {
        font-size: 0.9rem;
    }
    .cuota-card .cuota-value {
        font-size: 0.95rem;
    }
    .cuota-card input.mora-input {
        font-size: 0.95rem;
        width: 75px !important;
        min-width: 65px !important;
        padding: 0.2rem 0.3rem;
    }
}

/* ═══════════════════════════════════════════════════════════════
   CUOTAS: TARJETAS UNIFICADAS (Desktop + Mobile)
   ═══════════════════════════════════════════════════════════════ */

/* ── Contenedor de tarjetas ── */
.cuota-card-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 4px;
}

/* ── Tarjeta base ── */
.cuota-card-item {
    background: #fff;
    border: 1px solid #000;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: inset 4px 0 0 0 var(--edge, transparent), 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.cuota-card-item:hover {
    box-shadow: inset 4px 0 0 0 var(--edge, transparent), 0 4px 12px rgba(0,0,0,0.08);
}

/* Colores de estado — solo cambia border-color y la sombra izquierda */
.cuota-card-item.cuota-danger  { --edge: #ef4444; border-color: #ef4444; }
.cuota-card-item.cuota-success { --edge: #22c55e; border-color: #22c55e; }
.cuota-card-item.cuota-info    { --edge: #3b82f6; border-color: #3b82f6; }
.cuota-card-item.cuota-abono   { --edge: #8b5cf6; border-color: #8b5cf6; background: #faf5ff; }

/* ── Header de tarjeta ── */
.cuota-card-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-bottom: 1px solid #e2e8f0;
}

.cuota-card-item-title {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 8px;
}

.cuota-card-item-header .cuota-num {
    font-weight: 700;
    font-size: 0.9rem;
    color: #1e293b;
}

.cuota-card-item-header .cuota-date {
    font-size: 0.8rem;
    color: #64748b;
}

.cuota-card-item-header .badge {
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: 500;
}

/* ── Cuerpo de tarjeta ── */
.cuota-card-item-body {
    padding: 8px 10px;
}

.cuota-card-item-row {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
}

/* ── Campo individual ── */
.cuota-card-item-field {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 3px;
    padding: 1px 6px;
    background: transparent;
    border-radius: 0;
    border-bottom: 1px solid #f0f0f0;
    min-width: 0;
}
.cuota-card-item-field:last-child { border-bottom: none; }

.cuota-card-item-field .cuota-label {
    font-size: 0.5rem;
    color: #94a3b8;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-align: left;
    min-width: 50px;
}

.cuota-card-item-field .cuota-value {
    font-size: 0.65rem;
    color: #1e293b;
    font-weight: 600;
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-height: 12px;
}

/* ── Destacados ── */
.cuota-card-item-field.field-highlight {
    background: transparent;
    border: none;
    border-bottom: 1px solid #f0f0f0;
}
.cuota-card-item-field.field-highlight .cuota-value {
    color: #065f46;
    font-weight: 700;
}

.cuota-card-item-field.field-saldo {
    background: transparent;
    border: none;
    border-bottom: 1px solid #f0f0f0;
}
.cuota-card-item-field.field-saldo .cuota-value {
    color: #92400e;
    font-weight: 700;
}

/* Total cuota inline badge */
.cuota-card-item-field .total-cuota-cell {
    display: inline-block;
    background: #d1fae5;
    color: #065f46;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 6px;
}

/* ── Input de mora ── */
.cuota-card-item-field input.mora-input {
    width: 55px !important;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 1px 3px;
    text-align: right;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.cuota-card-item-field input.mora-input:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
    outline: none;
}

.bg-fuchsia { background-color: #EE27F5 !important; }
.bg-amber { background-color: #F59F27 !important; }

/* ── Acciones ── */
.cuota-card-item-actions {
    padding: 6px 10px;
    background: #fafbfc;
    border-top: 1px solid #e2e8f0;
}

.cuota-card-item-actions form {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.cuota-card-item-actions .btn {
    min-width: 100px;
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 8px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.cuota-card-item-actions .btn i {
    font-size: 0.7rem;
}

/* ── Collapse de cuotas pagadas (mobile) ── */
.cuota-collapse-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #64748b;
    border-radius: 8px;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.cuota-collapse-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
    border-color: #94a3b8;
}

.cuota-collapse-btn .cuota-chevron {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.cuota-collapse-btn.collapsed .cuota-chevron {
    transform: rotate(-90deg);
}

/* ── Abonos ── */
.cuota-card-item.abono-card {
    border-left: 5px solid #6366f1;
}

.cuota-card-item.abono-card .cuota-card-item-header {
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
    color: #3730a3;
}

.cuota-card-item.abono-card .cuota-card-item-field {
    background: #f8faff;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

.cuota-card-item.abono-card .cuota-card-item-field .cuota-label,
.cuota-card-item.abono-card .cuota-card-item-field .cuota-value {
    text-align: left;
    justify-content: flex-start;
}

/* ═══════════════════════════════════════════════════════════════
   RECAUDO: STICKY HEADER (desktop/tablet ≥ 992px)
   ═══════════════════════════════════════════════════════════════ */

#infoCredito {
    transition: padding-top .25s ease, padding-bottom .25s ease;
}

#infoCredito.is-stuck {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid #dee2e6;
    padding-top: 0;
    padding-bottom: 0;
    background: #f5f6fa;
}
#infoCredito.is-stuck .card-body {
    padding-top: 6px !important;
    padding-bottom: 6px !important;
}
#infoCredito.is-stuck .card-header {
    padding-top: 4px;
    padding-bottom: 4px;
}
#infoCredito.is-stuck .mb-4,
#infoCredito.is-stuck .mb-3 {
    margin-bottom: 0.25rem !important;
}
#infoCredito.is-stuck .row.g-3 {
    --bs-gutter-x: 0.25rem;
    --bs-gutter-y: 0.25rem;
}

/* Seguridad: en pantallas pequeñas NUNCA fijar (JS puede activarse en tablets) */
@media (max-width: 991.98px) {
    #infoCredito {
        position: static !important;
        top: auto !important;
        left: auto !important;
        width: auto !important;
        z-index: auto !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   CUOTAS: RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 1199.98px) {
    .cuota-card-item-row {
        grid-template-columns: repeat(5, 1fr);
    }

    .cuota-card-item-field {
        padding: 5px 7px;
        gap: 2px;
    }

    .cuota-card-item-field .cuota-label {
        font-size: 0.6rem;
        line-height: 1.1;
    }

    .cuota-card-item-field .cuota-value {
        font-size: 0.75rem;
        min-height: 16px;
    }
}

@media (max-width: 767.98px) {
    .cuota-card-list {
        gap: 12px;
        padding: 0;
    }

    .cuota-card-item-header {
        padding: 10px 14px;
    }

    .cuota-card-item-header .cuota-num {
        font-size: 0.95rem;
    }

    .cuota-card-item-header .cuota-date {
        font-size: 0.78rem;
    }

    .cuota-card-item-body {
        padding: 12px;
    }

    .cuota-card-item-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .cuota-card-item-field {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 8px 12px;
        gap: 10px;
    }

    .cuota-card-item-field .cuota-label {
        font-size: 0.78rem;
        text-align: left;
    }

    .cuota-card-item-field .cuota-value {
        font-size: 0.85rem;
        text-align: right;
        justify-content: flex-end;
    }

    .cuota-card-item-field input.mora-input {
        width: 85px !important;
        font-size: 0.85rem;
        padding: 4px 6px;
    }

    .cuota-card-item.abono-card .cuota-card-item-field {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .cuota-card-item.abono-card .cuota-card-item-field .cuota-value {
        justify-content: flex-start;
    }

    .cuota-card-item-actions {
        padding: 10px 12px;
    }

    .cuota-card-item-actions form {
        gap: 6px;
    }

    .cuota-card-item-actions .btn {
        flex: 1;
        min-width: 70px;
        font-size: 0.78rem;
        padding: 8px 6px;
    }
}

@media (max-width: 575.98px) {
    .cuota-card-item-actions .btn span {
        display: none;
    }

    .cuota-card-item-actions .btn {
        min-width: 44px;
        padding: 8px 4px;
    }

    .cuota-card-item-actions .btn i {
        font-size: 0.9rem;
    }
}

/* ── Saldo Cuota cell ── */
.saldocuota-cell {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

/* Mobile credit info */
.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid #f0f0f0;
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    font-size: 0.72rem;
    color: #6c757d;
    font-weight: 500;
    flex-shrink: 0;
}

.info-value {
    font-size: 0.78rem;
    color: #212529;
    text-align: right;
    padding-left: 8px;
}

/* ── Análisis fintech dashboard ── */

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.kpi-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c757d;
    font-weight: 600;
    line-height: 1.1;
}

.kpi-value {
    font-size: 1.3rem;
    font-weight: 800;
    line-height: 1.2;
}

@media (max-width: 767.98px) {
    .kpi-icon {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
    .kpi-value {
        font-size: 1.1rem;
    }
    .card-kpi .card-body {
        padding: 0.5rem;
    }
}

/* Score badges */
.score-aplus {
    background: linear-gradient(135deg, #00b09b, #96c93d) !important;
    color: #fff !important;
}
.score-a {
    background: #28a745 !important;
    color: #fff !important;
}
.score-b {
    background: #ffc107 !important;
    color: #212529 !important;
}
.score-c {
    background: #dc3545 !important;
    color: #fff !important;
}

/* Risk badges */
.riesgo-bajo {
    background: #d1e7dd !important;
    color: #0f5132 !important;
    font-weight: 600;
}
.riesgo-medio {
    background: #fff3cd !important;
    color: #664d03 !important;
    font-weight: 600;
}
.riesgo-alto {
    background: #f8d7da !important;
    color: #842029 !important;
    font-weight: 600;
}
.riesgo-critico {
    background: #dc3545 !important;
    color: #fff !important;
    font-weight: 600;
}

/* Heatmap cells */
.heatmap-value {
    width: 32px;
    height: 28px;
    border-radius: 4px;
    line-height: 28px;
    font-size: 0.7rem;
    font-weight: 600;
    color: #fff;
    display: inline-block;
}
.heatmap-green {
    background: #28a745;
}
.heatmap-yellow {
    background: #ffc107;
    color: #212529 !important;
}
.heatmap-red {
    background: #dc3545;
}
.heatmap-cell-active {
    --bs-table-bg: #e8f0fe;
    background-color: #e8f0fe;
}
.heatmap-cell-inactive {
    --bs-table-bg: #f8f9fa;
    background-color: #f8f9fa;
}

/* Credit cards (collapsible) */
.credit-card {
    border-radius: 12px;
    transition: box-shadow 0.2s ease;
}
.credit-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.08) !important;
}
.credit-card-header {
    cursor: pointer;
    user-select: none;
}
.credit-card-header:hover {
    background: #f8f9fa !important;
}
.collapse-chevron {
    transition: transform 0.25s ease;
}
.credit-card-header[aria-expanded="true"] .collapse-chevron {
    transform: rotate(180deg);
}

/* Purple text utility */
.text-purple {
    color: #6610f2;
}
.bg-purple-subtle {
    background-color: #e0d4fc !important;
}

/* Ranking table row hover */
#ranking-table tbody tr:hover {
    background: #f0f4ff;
}

/* PDF print optimizations */
@media print {
    .sidebar, .toggle-btn, .mobile-navbar, .btn, form, footer, #messagesContainer, .offcanvas {
        display: none !important;
    }
    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    .card {
        break-inside: avoid;
        box-shadow: none !important;
        border: 1px solid #dee2e6 !important;
    }
    .credit-card .collapse {
        display: block !important;
    }
    .credit-card-header[data-bs-toggle="collapse"] {
        cursor: default;
    }
    .collapse-chevron {
        display: none !important;
    }
}
