/* ==========================================================================
   KOIN — SOFTWARE PARA PRESTAMISTAS
   Design System & Fintech UI Stylesheet
   Brand Palette: Azul Principal (#2563EB) · Azul Oscuro (#0F2D5B) · Blanco (#FFFFFF)
   Typography: Plus Jakarta Sans (Regular 400, Medium 500, SemiBold 600, Bold 700, ExtraBold 800)
   ========================================================================== */

:root {
    /* Core Brand Tokens (Koin Branding Sheet) */
    --koin-blue: #2563EB;
    --koin-blue-hover: #1D4ED8;
    --koin-blue-light: #60A5FA;
    --koin-ice: #DBEAFE;
    --koin-ice-subtle: #EFF6FF;
    --koin-navy: #0F2D5B;
    --koin-navy-deep: #091D3C;
    --koin-white: #FFFFFF;

    /* Light Mode Surface & Semantic Palette */
    --bg-body: #F4F7FB;
    --bg-card: #FFFFFF;
    --bg-subtle: #F8FAFC;
    --bg-sidebar: #0F2D5B;
    --text-sidebar: #FFFFFF;
    --text-sidebar-muted: #93C5FD;
    --text-sidebar-hover: #60A5FA;
    --text-primary: #0F2D5B;
    --text-secondary: #334155;
    --text-muted: #64748B;
    --border-color: #E2E8F0;
    --border-strong: #CBD5E1;

    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --primary-glow: rgba(37, 99, 235, 0.18);
    --primary-soft: rgba(37, 99, 235, 0.08);

    --success: #059669;
    --success-soft: rgba(5, 150, 105, 0.1);
    --warning: #D97706;
    --warning-soft: rgba(217, 119, 6, 0.12);
    --danger: #DC2626;
    --danger-soft: rgba(220, 38, 38, 0.1);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-xs: 0 1px 2px rgba(15, 45, 91, 0.04);
    --shadow: 0 4px 16px -2px rgba(15, 45, 91, 0.06), 0 2px 6px -1px rgba(15, 45, 91, 0.04);
    --shadow-lg: 0 16px 36px -6px rgba(15, 45, 91, 0.12), 0 4px 12px -2px rgba(15, 45, 91, 0.06);
    --transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);

    --sidebar-width: 268px;
}

[data-theme="dark"] {
    --bg-body: #071020;
    --bg-card: #0D1B33;
    --bg-subtle: #112240;
    --bg-sidebar: #050C18;
    --text-sidebar: #F8FAFC;
    --text-sidebar-muted: #94A3B8;
    --text-sidebar-hover: #60A5FA;
    --text-primary: #F8FAFC;
    --text-secondary: #CBD5E1;
    --text-muted: #94A3B8;
    --border-color: #1B2E4B;
    --border-strong: #2A4365;

    --primary: #3B82F6;
    --primary-hover: #2563EB;
    --primary-glow: rgba(59, 130, 246, 0.25);
    --primary-soft: rgba(59, 130, 246, 0.14);

    --success: #10B981;
    --success-soft: rgba(16, 185, 129, 0.15);
    --warning: #F59E0B;
    --warning-soft: rgba(245, 158, 11, 0.15);
    --danger: #EF4444;
    --danger-soft: rgba(239, 68, 68, 0.15);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 20px 40px -8px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   BASE & TYPOGRAPHY
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.55;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.25;
}

/* Tabular figures for financial precision */
.kpi-value,
.revenue-amount,
.table td,
.summary-box strong,
.plan-config-price .price,
.cobranza-item h2,
#cobCuotaMonto,
#presPreviewTotal,
#presPreviewCuota {
    font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   APP SHELL & SIDEBAR (KOIN DEEP NAVY #0F2D5B)
   ========================================================================== */
.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--bg-sidebar) 0%, #091D3C 100%);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

/* Subtle Koin geometric diagonal watermark at bottom of sidebar */
.sidebar::after {
    content: '';
    position: absolute;
    bottom: -40px;
    right: -30px;
    width: 140px;
    height: 180px;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.14), rgba(219, 234, 254, 0.04));
    border-radius: 20px;
    transform: skewX(-32deg);
    pointer-events: none;
    z-index: 0;
}

.sidebar > * {
    position: relative;
    z-index: 1;
}

.sidebar-header {
    padding: 22px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.brand-title-group {
    display: flex;
    flex-direction: column;
}

.sidebar-header h2 {
    color: #FFFFFF;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.brand-subtitle {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-sidebar-muted);
    letter-spacing: 0.01em;
    margin-top: 2px;
}

.logo-icon {
    color: var(--text-sidebar-hover);
}

/* User Profile in Sidebar */
.sidebar-user-profile {
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius);
    margin: 14px 14px 6px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.user-profile-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-user-profile .user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--koin-blue) 0%, #1D4ED8 100%);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
}

.user-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-user-profile .user-name {
    color: #FFFFFF;
    font-weight: 600;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-profile .user-email {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-plan-row {
    display: flex;
    align-items: center;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    background: transparent;
    border: 1px solid transparent;
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 10px;
    text-align: left;
    transition: var(--transition);
    position: relative;
}

.nav-item i,
.nav-item svg {
    width: 19px;
    height: 19px;
    color: rgba(255, 255, 255, 0.65);
    transition: var(--transition);
    flex-shrink: 0;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.07);
    color: #FFFFFF;
}

.nav-item:hover i,
.nav-item:hover svg {
    color: #FFFFFF;
}

.nav-item.active {
    background-color: var(--koin-blue);
    color: #FFFFFF;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}

.nav-item.active i,
.nav-item.active svg {
    color: #FFFFFF;
}

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-footer .logout-btn {
    width: 100%;
    justify-content: flex-start;
    background: rgba(239, 68, 68, 0.12);
    color: #FCA5A5;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.sidebar-footer .logout-btn:hover {
    background: rgba(239, 68, 68, 0.22);
    color: #FECACA;
}

.sidebar-footer .logout-btn i,
.sidebar-footer .logout-btn svg {
    color: #FCA5A5;
}

/* ==========================================================================
   MAIN WORKSPACE & HEADER
   ========================================================================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    min-width: 0;
}

.main-header {
    padding: 20px 36px;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(12px);
}

.main-header h1 {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--text-primary);
}

.mobile-toggle {
    display: none;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    background: var(--bg-subtle);
}

.content-body {
    padding: 32px 36px;
    flex: 1;
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
}

/* Sections */
.page-section {
    display: none;
    animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.page-section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   SURFACES & BUTTONS
   ========================================================================== */
.bg-card {
    background-color: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
    font-size: 0.9rem;
    line-height: 1.2;
    text-decoration: none;
}

.btn svg,
.btn i {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
}

.btn-sm {
    padding: 7px 12px;
    font-size: 0.82rem;
    border-radius: 7px;
}

.btn-primary {
    background-color: var(--primary);
    color: #FFFFFF;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.32);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-outline {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    box-shadow: var(--shadow-xs);
}

.btn-outline:hover {
    background-color: var(--bg-subtle);
    border-color: var(--border-strong);
}

.btn-danger {
    background-color: var(--danger);
    color: #FFFFFF;
}

.btn-danger:hover {
    opacity: 0.92;
}

.btn-text {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: var(--transition);
}

.btn-text:hover {
    background-color: var(--primary-soft);
}

/* Step 2 Async / Busy / Disabled States (Supabase & Form Controls) */
.btn:disabled,
button:disabled,
.plan-select:disabled {
    opacity: 0.65;
    cursor: not-allowed !important;
    transform: none !important;
    box-shadow: none !important;
}

.btn[aria-busy="true"],
button[aria-busy="true"] {
    position: relative;
    pointer-events: none;
}

.btn[aria-busy="true"]::after,
button[aria-busy="true"]::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: 6px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: koinSpin 0.65s linear infinite;
    vertical-align: middle;
}

.plan-select[aria-busy="true"] {
    opacity: 0.6;
    pointer-events: none;
    border-color: var(--primary);
}

@keyframes koinSpin {
    to { transform: rotate(360deg); }
}

/* SweetAlert2 Koin Brand Integration (Alerts, Modals, Spinners & Toasts) */
.swal2-popup {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif !important;
    background-color: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-lg) !important;
    padding: 28px 24px !important;
}

.swal2-title {
    color: var(--text-primary) !important;
    font-weight: 700 !important;
    font-size: 1.35rem !important;
    letter-spacing: -0.02em !important;
}

.swal2-html-container {
    color: var(--text-secondary) !important;
    font-size: 0.94rem !important;
    line-height: 1.55 !important;
}

.swal2-styled.swal2-confirm {
    background-color: var(--koin-blue) !important;
    color: #FFFFFF !important;
    border-radius: var(--radius-sm) !important;
    font-weight: 600 !important;
    font-size: 0.92rem !important;
    padding: 10px 22px !important;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28) !important;
    transition: var(--transition) !important;
}

.swal2-styled.swal2-confirm:hover {
    background-color: var(--koin-blue-hover) !important;
}

.swal2-styled.swal2-confirm:focus {
    box-shadow: 0 0 0 3px var(--primary-glow) !important;
}

.swal2-styled.swal2-cancel {
    background-color: var(--bg-subtle) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-sm) !important;
    font-weight: 600 !important;
    font-size: 0.92rem !important;
    padding: 10px 22px !important;
}

.swal2-loader {
    border-color: var(--koin-blue) transparent var(--koin-blue) transparent !important;
}

.swal2-popup.swal2-toast {
    padding: 12px 18px !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-lg) !important;
}

/* ==========================================================================
   KPI CARDS & DASHBOARD WIDGETS
   ========================================================================== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(235px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.kpi-card {
    padding: 22px 24px;
    border-radius: var(--radius);
    background-color: var(--bg-card);
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    gap: 16px;
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

.kpi-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary);
}

.kpi-card.summary-card::before { background: var(--primary); }
.kpi-card.success-card::before { background: var(--success); }
.kpi-card.warning-card::before { background: var(--warning); }
.kpi-card.danger-card::before { background: var(--danger); }

.kpi-icon {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background-color: var(--primary-soft);
}

.summary-card .kpi-icon {
    background-color: var(--primary-soft);
    color: var(--primary);
}

.success-card .kpi-icon {
    background-color: var(--success-soft);
    color: var(--success);
}

.warning-card .kpi-icon {
    background-color: var(--warning-soft);
    color: var(--warning);
}

.danger-card .kpi-icon {
    background-color: var(--danger-soft);
    color: var(--danger);
}

.kpi-data {
    min-width: 0;
    flex: 1;
}

.kpi-data h3 {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 6px;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    line-height: 1.15;
}

/* Dashboard Widgets */
.dashboard-widgets {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 24px;
}

.widget {
    background-color: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.widget-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ==========================================================================
   TABLES & STATUS BADGES
   ========================================================================== */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 14px 18px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    background-color: var(--bg-subtle);
    letter-spacing: 0.02em;
}

.table tbody tr {
    transition: background-color 0.15s ease;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover td {
    background-color: var(--primary-soft);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 600;
    text-transform: capitalize;
    letter-spacing: 0.01em;
}

.badge.act,
.badge.pagada {
    background-color: var(--success-soft);
    color: var(--success);
}

.badge.inact,
.badge.vencida {
    background-color: var(--danger-soft);
    color: var(--danger);
}

.badge.pend {
    background-color: var(--warning-soft);
    color: var(--warning);
}

.badge.parcial {
    background-color: var(--primary-soft);
    color: var(--primary);
}

/* ==========================================================================
   FORMS, SEARCH & FILTERS
   ========================================================================== */
.section-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.search-box {
    display: flex;
    align-items: center;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    width: 340px;
    max-width: 100%;
    box-shadow: var(--shadow-xs);
    transition: var(--transition);
}

.search-box:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.search-box i,
.search-box svg {
    color: var(--text-muted);
    margin-right: 10px;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.search-box input {
    border: none;
    background: transparent;
    outline: none;
    flex: 1;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.form-group {
    margin-bottom: 18px;
}

.form-group.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.86rem;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--bg-subtle);
    color: var(--text-primary);
    font-size: 0.92rem;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    background-color: var(--bg-card);
    box-shadow: 0 0 0 3px var(--primary-glow);
    outline: none;
}

.input-prefix {
    display: flex;
    align-items: stretch;
}

.input-prefix span {
    display: inline-flex;
    align-items: center;
    padding: 0 14px;
    background-color: var(--border-color);
    color: var(--text-primary);
    font-weight: 600;
    border: 1px solid var(--border-color);
    border-right: none;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.input-prefix input {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.resumen-box {
    background: var(--primary-soft);
    border: 1px solid rgba(37, 99, 235, 0.2);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.resumen-box h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 2px;
}

/* ==========================================================================
   MODALS
   ========================================================================== */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(9, 29, 60, 0.55);
    backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal.show {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-lg { max-width: 720px; }
.modal-sm { max-width: 380px; }

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
}

.btn-close {
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition);
}

.btn-close:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-subtle);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ==========================================================================
   COBRANZAS LIST & CLIENT/LOAN DETAILS
   ========================================================================== */
.cobranzas-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cobranza-item {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 18px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid var(--warning);
    box-shadow: var(--shadow-xs);
    transition: var(--transition);
}

.cobranza-item:hover {
    box-shadow: var(--shadow);
}

.cobranza-item.vencida {
    border-left-color: var(--danger);
}

.cobranza-item.cobrada {
    border-left-color: var(--success);
    opacity: 0.72;
}

.cobranza-item-info h3 {
    margin-bottom: 6px;
    font-size: 1.05rem;
    font-weight: 600;
}

.cobranza-item-info p {
    color: var(--text-muted);
    font-size: 0.86rem;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.cob-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Detail Views */
.detail-view {
    padding-bottom: 40px;
}

.perfil-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 24px;
    align-items: start;
}

.perfil-card {
    padding: 28px 24px;
}

.spacer {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 20px 0;
}

.perfil-stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.stat-lbl {
    color: var(--text-muted);
    font-size: 0.8rem;
    display: block;
    margin-bottom: 2px;
}

.stat-val {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text-primary);
}

.perfil-prestamos {
    padding: 28px 24px;
}

/* Prestamo Summary Grid */
.prestamo-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    padding: 18px 20px;
    border-radius: var(--radius);
}

.summary-box small {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 4px;
}

.summary-box strong {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ==========================================================================
   SUBSCRIPTION PLANS, ADMIN PANEL & ACCOUNT VIEWS
   ========================================================================== */
.plan-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 11px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.plan-badge.plan-trial {
    background-color: rgba(148, 163, 184, 0.16);
    color: #94A3B8;
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.plan-badge.plan-basico {
    background-color: rgba(37, 99, 235, 0.15);
    color: #60A5FA;
    border: 1px solid rgba(37, 99, 235, 0.35);
}

[data-theme="light"] .main-content .plan-badge.plan-basico {
    color: var(--koin-blue);
}

.plan-badge.plan-intermedio {
    background-color: rgba(37, 99, 235, 0.2);
    color: #38BDF8;
    border: 1px solid rgba(56, 189, 248, 0.35);
}

[data-theme="light"] .main-content .plan-badge.plan-intermedio {
    color: var(--koin-navy);
    background-color: var(--koin-ice);
    border-color: #93C5FD;
}

.plan-badge.plan-premium {
    background-color: rgba(245, 158, 11, 0.16);
    color: #F59E0B;
    border: 1px solid rgba(245, 158, 11, 0.35);
}

.plan-badge.plan-expired,
.plan-badge.plan-suspendido {
    background-color: rgba(239, 68, 68, 0.15);
    color: #EF4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Warning Banner */
.warning-banner {
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

/* Plan Configuration Cards */
.plans-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(225px, 1fr));
    gap: 20px;
    margin-top: 16px;
}

.plan-config-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 26px 22px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

.plan-config-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.plan-config-card.premium-popular,
.plan-config-card.plan-intermedio-card {
    border: 2px solid var(--koin-blue);
    box-shadow: 0 10px 28px -6px rgba(37, 99, 235, 0.18);
}

.plan-config-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--koin-blue);
    color: #FFFFFF;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.plan-config-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.plan-config-header h3 {
    font-size: 1.12rem;
    font-weight: 700;
}

.plan-config-price {
    margin-bottom: 20px;
}

.plan-config-price .price {
    font-size: 2.1rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.03em;
}

.plan-config-price .period {
    font-size: 0.84rem;
    color: var(--text-muted);
    margin-left: 4px;
}

.plan-config-features {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 24px;
    flex: 1;
}

.plan-config-features li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.86rem;
    color: var(--text-primary);
}

.plan-config-features li.disabled {
    color: var(--text-muted);
    opacity: 0.5;
}

.plan-config-features li i,
.plan-config-features li svg {
    flex-shrink: 0;
}

/* Admin Widgets & Charts */
.revenue-display {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 16px 0;
}

.revenue-amount {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--success);
    letter-spacing: -0.03em;
}

.revenue-label {
    font-size: 0.95rem;
    color: var(--text-muted);
    font-weight: 500;
}

.plan-chart {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 8px 0;
}

.chart-bar-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.chart-label {
    width: 90px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: right;
}

.chart-bar-track {
    flex: 1;
    height: 10px;
    background-color: var(--bg-subtle);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.chart-bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.6s ease-in-out;
}

.chart-count {
    width: 30px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* User Profile Row in Admin Tables */
.user-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--koin-blue), var(--koin-navy));
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.92rem;
    flex-shrink: 0;
}

.profile-avatar-large {
    width: 76px;
    height: 76px;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--koin-blue), var(--koin-navy));
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    margin: 0 auto 14px;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.25);
}

.d-block { display: block; }

.admin-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--primary-soft);
    color: var(--primary);
    border: 1px solid rgba(37, 99, 235, 0.25);
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.admin-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.plan-select {
    padding: 7px 11px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--bg-subtle);
    color: var(--text-primary);
    font-size: 0.84rem;
    outline: none;
    cursor: pointer;
    transition: var(--transition);
}

.plan-select:focus {
    border-color: var(--primary);
}

.admin-section {
    display: none;
    animation: fadeIn 0.25s ease-out;
}

.admin-section.active {
    display: block;
}

/* Utilities */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.my-3 { margin-top: 12px; margin-bottom: 12px; }
.mr-2 { margin-right: 8px; }
.p-6 { padding: 24px; }
.w-100 { width: 100%; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* Ocultar elementos de impresión en la pantalla */
.tarjeta-cliente-container { display: none; }

/* ==========================================================================
   RESPONSIVE BREAKPOINTS
   ========================================================================== */
@media (max-width: 900px) {
    .perfil-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        height: 100vh;
        z-index: 50;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open {
        left: 0;
    }
    .mobile-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin-right: 14px;
    }
    .main-header {
        padding: 16px 20px;
        justify-content: flex-start;
    }
    .header-actions {
        margin-left: auto;
    }
    .content-body {
        padding: 20px;
    }
    .kpi-grid {
        grid-template-columns: 1fr;
    }
    .dashboard-widgets {
        grid-template-columns: 1fr;
    }
    .prestamo-summary-grid {
        grid-template-columns: 1fr 1fr;
    }
    .cobranza-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
    }
    .cob-actions {
        width: 100%;
        justify-content: flex-end;
    }
    .form-grid-2,
    .form-group.row {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   ESTILOS DE IMPRESIÓN (A4 / A5 / TARJETAS)
   ========================================================================== */
@media print {
    @page { size: A4; margin: 0; }
    
    body { background: white !important; color: black !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    body * { visibility: hidden; }

    .printable, .printable *, #tarjetaClientePrint, #tarjetaClientePrint * {
        color: black !important;
        background-color: transparent !important;
    }

    body:not(.print-card) .printable, 
    body:not(.print-card) .printable * {
        visibility: visible;
    }
    
    body:not(.print-card) .printable {
        position: absolute; left: 50%; top: 20px; transform: translateX(-50%);
        width: 148mm; min-height: 200mm; border: 1px dashed #000; padding: 10mm !important;
    }

    body.print-card #tarjetaClientePrint,
    body.print-card #tarjetaClientePrint * {
        visibility: visible !important;
    }
    
    body.print-card #tarjetaClientePrint {
        display: block !important;
        position: absolute; left: 50%; top: 10mm; transform: translateX(-50%);
        width: 190mm; border: 2px solid #000; padding: 5mm;
        background: white !important;
    }

    .tarjeta-header { text-align: center; border-bottom: 2px solid #000; margin-bottom: 4mm; padding-bottom: 2mm; }
    .tarjeta-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; border: 1px solid #000; }
    
    .cuota-card {
        border: 1px solid #000;
        padding: 4px;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        min-height: 10mm;
    }
    
    .cuota-card .info { display: flex; flex-direction: column; }
    .cuota-card .num { font-weight: 800; font-size: 10px; color: #000; }
    .cuota-card .fecha { font-size: 11px; }
    .cuota-card .monto { font-weight: 700; font-size: 12px; }
    .cuota-card .check { 
        width: 18px; height: 18px; border: 1.5px solid #000; background: #fff;
    }

    .no-print { display: none !important; }
    .only-print { display: table-cell !important; }
    .table th { background: #eee !important; color: #000 !important; border: 1px solid #000 !important; }
    .table td { border: 1px solid #000 !important; }
}
