/* ==========================================================================
   CREDIXA by JF - Design System & Stylesheet
   Loan Management Software
   Colors: #0B1220 (Navy), #155EEF (Tech Blue), #12B76A (Growth Green), #F8FAFC (BG)
   Typography: Manrope (Branding) | Inter (UI)
   ========================================================================== */

:root {
    /* Brand Color Palette */
    --bg-navy: #0B1220;
    --bg-navy-card: #131E35;
    --bg-navy-hover: #1E2D4A;
    
    --primary: #155EEF;
    --primary-hover: #1048BD;
    --primary-light: #EFF4FF;
    --primary-dark: #0D3C9B;
    
    --success: #12B76A;
    --success-hover: #0E9355;
    --success-light: #ECFDF3;
    --success-dark: #027A48;
    
    --warning: #F79009;
    --warning-light: #FFFAEB;
    --warning-dark: #B54708;
    
    --danger: #F04438;
    --danger-light: #FEF3F2;
    --danger-dark: #B42318;

    --purple: #7F56D9;
    --purple-light: #F9F5FF;
    
    --bg-body: #F8FAFC;
    --bg-surface: #FFFFFF;
    --bg-sidebar: #0B1220;
    --bg-sidebar-hover: #172239;
    --bg-sidebar-active: #155EEF;
    
    --text-main: #0B1220;
    --text-muted: #667085;
    --text-light: #98A2B3;
    --text-white: #FFFFFF;
    
    --border-color: #EAECF0;
    --border-focus: #155EEF;
    
    --font-brand: 'Manrope', system-ui, -apple-system, sans-serif;
    --font-ui: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 9999px;
    
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.1), 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 8px -2px rgba(16, 24, 40, 0.1), 0 2px 4px -2px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 12px 16px -4px rgba(16, 24, 40, 0.08), 0 4px 6px -2px rgba(16, 24, 40, 0.03);
    --shadow-xl: 0 20px 24px -4px rgba(16, 24, 40, 0.08), 0 8px 8px -4px rgba(16, 24, 40, 0.03);

    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Global Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-ui);
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    font-size: 14.5px;
    -webkit-font-smoothing: antialiased;
}

/* Typography Helpers */
.brand-font { font-family: var(--font-brand); }
.font-brand { font-family: var(--font-brand); }

/* Layout Structure */
.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100vw;
    overflow-x: hidden;
    position: relative;
}

/* Top Bar (Mobile / Small Screens) */
.top-bar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg-navy);
    color: var(--text-white);
    padding: 0 1.25rem;
    align-items: center;
    justify-content: space-between;
    z-index: 40;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: var(--shadow-md);
}

.top-bar .brand-text {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.menu-toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-white);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.menu-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Sidebar Navigation */
.sidebar {
    width: 270px;
    background: var(--bg-sidebar);
    color: var(--text-white);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    min-height: 100vh;
    position: sticky;
    top: 0;
    z-index: 50;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    padding: 1.5rem 1.25rem 1.25rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

/* Brand Lockup Component */
.credixa-brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    text-decoration: none;
}

.credixa-logo-icon {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
}

.credixa-title {
    font-family: var(--font-brand);
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text-white);
    line-height: 1.1;
    display: flex;
    align-items: center;
}

.credixa-title .accent-x {
    color: #38BDF8;
    background: linear-gradient(135deg, #38BDF8 0%, #12B76A 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
    padding: 0 1px;
}

.credixa-subtitle {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #94A3B8;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.2rem;
}

.by-jf-badge {
    font-weight: 800;
    color: #38BDF8;
    background: rgba(56, 189, 248, 0.12);
    padding: 0.05rem 0.35rem;
    border-radius: var(--radius-sm);
    letter-spacing: normal;
    text-transform: none;
}

.sidebar-nav {
    flex: 1;
    padding: 1.25rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.75rem 1rem;
    color: #94A3B8;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.sidebar-link:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-white);
    transform: translateX(2px);
}

.sidebar-link.active {
    background: var(--primary);
    color: var(--text-white);
    font-weight: 700;
    box-shadow: 0 4px 14px rgba(21, 94, 239, 0.4);
}

.sidebar-link .icon {
    font-size: 1.2rem;
    width: 22px;
    text-align: center;
}

.sidebar-footer {
    padding: 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.2);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.95rem;
    font-size: 0.9rem;
    color: var(--text-white);
}

.sidebar-user .avatar-circle {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #155EEF 0%, #0B1220 100%);
    border: 1.5px solid rgba(56, 189, 248, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--text-white);
    font-family: var(--font-brand);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(11, 18, 32, 0.7);
    backdrop-filter: blur(4px);
    z-index: 45;
}

/* Main Content Area */
.main-content {
    flex: 1;
    min-width: 0;
    padding: 2.25rem 2.75rem;
    overflow-y: auto;
    height: 100vh;
}

/* Typography & Headings */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-title {
    font-family: var(--font-brand);
    font-size: 1.65rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.03em;
}

.page-subtitle {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

/* Cards & Surfaces */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    transition: var(--transition);
    overflow: hidden;
}

.card:hover {
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 1.15rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: #FCFCFD;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h3 {
    font-family: var(--font-brand);
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: #FCFCFD;
}

/* KPI Cards Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.75rem;
}

.kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.35rem 1.4rem;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-xs);
    transition: var(--transition);
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3.5px;
}

.kpi-blue::before { background: var(--primary); }
.kpi-green::before { background: var(--success); }
.kpi-teal::before { background: #06B6D4; }
.kpi-red::before { background: var(--danger); }
.kpi-purple::before { background: var(--purple); }
.kpi-amber::before { background: var(--warning); }

.kpi-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.kpi-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
}

.kpi-blue .kpi-icon { background: var(--primary-light); color: var(--primary); }
.kpi-green .kpi-icon { background: var(--success-light); color: var(--success); }
.kpi-teal .kpi-icon { background: #ECFEFF; color: #0891B2; }
.kpi-red .kpi-icon { background: var(--danger-light); color: var(--danger); }
.kpi-purple .kpi-icon { background: var(--purple-light); color: var(--purple); }
.kpi-amber .kpi-icon { background: var(--warning-light); color: var(--warning); }

.kpi-value {
    font-family: var(--font-brand);
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.kpi-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 0.3rem;
}

/* Modern Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.88rem;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
    line-height: 1.2;
    white-space: nowrap;
    font-family: var(--font-ui);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: var(--text-white);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 10px rgba(21, 94, 239, 0.3);
}

.btn-success {
    background: var(--success);
    color: var(--text-white);
}
.btn-success:hover {
    background: var(--success-hover);
    box-shadow: 0 4px 10px rgba(18, 183, 106, 0.3);
}

.btn-danger {
    background: var(--danger);
    color: var(--text-white);
}
.btn-danger:hover {
    background: var(--danger-dark);
}

.btn-warning {
    background: var(--warning);
    color: var(--text-white);
}
.btn-warning:hover {
    background: var(--warning-dark);
}

.btn-outline {
    background: var(--bg-surface);
    border-color: #D0D5DD;
    color: #344054;
    box-shadow: var(--shadow-xs);
}
.btn-outline:hover {
    background: #F9FAFB;
    border-color: #98A2B3;
}

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
}

.btn-lg {
    padding: 0.85rem 1.75rem;
    font-size: 1rem;
    border-radius: var(--radius-md);
}

/* Badges & Tags */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-success { background: var(--success-light); color: var(--success-dark); border: 1px solid rgba(18, 183, 106, 0.3); }
.badge-warning { background: var(--warning-light); color: var(--warning-dark); border: 1px solid rgba(247, 144, 9, 0.3); }
.badge-danger { background: var(--danger-light); color: var(--danger-dark); border: 1px solid rgba(240, 68, 56, 0.3); }
.badge-info { background: var(--primary-light); color: var(--primary-dark); border: 1px solid rgba(21, 94, 239, 0.3); }
.badge-secondary { background: #F2F4F7; color: #344054; border: 1px solid #EAECF0; }

/* Tables */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9rem;
}

.data-table thead {
    background: #F9FAFB;
    border-bottom: 1.5px solid var(--border-color);
}

.data-table th {
    padding: 0.85rem 1rem;
    font-weight: 700;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.data-table td {
    padding: 0.95rem 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

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

.data-table tbody tr:hover {
    background: #F8FAFC;
}

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

.overdue-row { background: #FEF3F2 !important; }
.overdue-row:hover { background: #FEE4E2 !important; }
.paid-row { background: #ECFDF3 !important; }
.partial-row { background: #FFFAEB !important; }

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1.15rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.84rem;
    font-weight: 600;
    color: #344054;
    margin-bottom: 0.4rem;
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 0.65rem 0.9rem;
    border: 1.5px solid #D0D5DD;
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-main);
    font-size: 0.93rem;
    font-family: var(--font-ui);
    transition: var(--transition);
    outline: none;
    box-shadow: var(--shadow-xs);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(21, 94, 239, 0.15);
}

.form-textarea {
    resize: vertical;
}

/* Modals */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 18, 32, 0.65);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    z-index: 100;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 620px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalScale 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid var(--border-color);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #FCFCFD;
}

.modal-header h3 {
    font-family: var(--font-brand);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: #FCFCFD;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Alerts */
.alert {
    padding: 0.9rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-md);
}

.alert-success { background: #ECFDF3; color: #027A48; border-left: 4px solid var(--success); }
.alert-error, .alert-danger { background: #FEF3F2; color: #B42318; border-left: 4px solid var(--danger); }
.alert-warning { background: #FFFAEB; color: #B54708; border-left: 4px solid var(--warning); }
.alert-info { background: #EFF4FF; color: #175CD3; border-left: 4px solid var(--primary); }

/* Stats & Chart Grids */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
    width: 100%;
}

.chart-wrapper {
    position: relative;
    width: 100%;
    height: 280px;
}

/* Amounts & Numbers */
.amount {
    font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}
.empty-state p {
    font-size: 0.95rem;
    font-weight: 500;
}

/* Loading Spinner */
.loading-spinner {
    display: inline-block;
    width: 38px;
    height: 38px;
    border: 3px solid rgba(21, 94, 239, 0.2);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 0.8s linear infinite;
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalScale {
    from { transform: scale(0.96); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Utilities */
.d-flex { display: flex; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 0.85rem; }
.gap-3 { gap: 1.25rem; }
.w-full { width: 100%; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 0.85rem; }
.mt-3 { margin-top: 1.25rem; }
.mt-4 { margin-top: 1.75rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 0.85rem; }
.mb-3 { margin-bottom: 1.25rem; }
.mb-4 { margin-bottom: 1.75rem; }
.font-bold { font-weight: 700; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Responsive Mobile Rules */
@media (max-width: 768px) {
    .top-bar {
        display: flex;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
    }

    .sidebar.sidebar-open {
        transform: translateX(0);
    }

    .sidebar-overlay[style*="display: block"],
    .sidebar-overlay:not([style*="display: none"]) {
        display: block;
    }

    .main-content {
        padding: 5.25rem 1rem 2rem 1rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .kpi-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 0.85rem;
    }

    .kpi-card {
        padding: 1rem;
    }

    .kpi-value {
        font-size: 1.25rem;
    }

    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 1.25rem !important;
    }

    .chart-wrapper {
        height: 250px !important;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .modal {
        max-width: 100%;
        margin: 0.5rem;
        max-height: 95vh;
        border-radius: var(--radius-lg);
    }

    .card-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .d-flex.gap-2, .d-flex.gap-3 {
        flex-direction: column;
        width: 100%;
    }
}

/* Print Styles */
@media print {
    .sidebar, .top-bar, .btn, .modal-overlay, .sidebar-overlay, .card-header button {
        display: none !important;
    }
    .main-content {
        padding: 0 !important;
        height: auto !important;
        overflow: visible !important;
    }
    body {
        background: white !important;
        color: black !important;
    }
    .card {
        border: none !important;
        box-shadow: none !important;
    }
}
