:root {
    --primary: #4338ca;
    --primary-light: #eef2ff;
    --primary-hover: #3730a3;
    --bg: #f8fafc;
    --bg-alt: #f1f5f9;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --border: #e2e8f0;
    --glass: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.4);
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-premium: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.03);
    --sidebar-width: 260px;
    --radius-md: 0.75rem;
    --radius-lg: 1.25rem;
    --radius-full: 9999px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
}

/* Glassmorphism Classes */
.glass {
    background: var(--glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--border);
    padding: 2.5rem 1.25rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 3.5rem;
    padding: 0 0.5rem;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-link:hover {
    background: var(--bg-alt);
    color: var(--primary);
    transform: translateX(4px);
}

.nav-item.active .nav-link {
    background: var(--primary);
    color: white;
    box-shadow: 0 10px 15px -3px rgba(67, 56, 202, 0.3);
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 3rem;
    max-width: 1440px;
}

.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
}

.welcome-text h1 {
    font-size: 1.875rem;
    font-weight: 800;
    letter-spacing: -0.025em;
}

.welcome-text p {
    color: var(--text-muted);
    font-weight: 500;
}

/* Cards & Grid */
.premium-card {
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(226, 232, 240, 0.6);
    box-shadow: var(--shadow-premium);
    padding: 1.5rem;
    transition: all 0.3s ease;
}

.premium-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 25px 30px -5px rgba(0, 0, 0, 0.06);
}

.stat-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-icon {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 1rem;
    display: grid;
    place-items: center;
    font-size: 1.5rem;
    font-style: normal;
}

.stat-icon i,
.fab i {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    margin: 0 !important;
    padding: 0 !important;
    line-height: normal !important;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.025em;
}

.stat-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: 0.875rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(67, 56, 202, 0.2);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(67, 56, 202, 0.3);
}

/* Data Tables */
.table-container {
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
}

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

.data-table th {
    background: var(--bg);
    padding: 1rem 1.5rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--bg);
    font-size: 0.9375rem;
}

.data-table tr:hover td {
    background: var(--bg);
}

/* Badge System */
.status-badge {
    padding: 0.375rem 1rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
}

.status-badge.pending {
    background: #fef3c7;
    color: #92400e;
}

.status-badge.paid {
    background: #dcfce7;
    color: #166534;
}

/* Modals & Forms */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

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

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 700;
    margin-bottom: 0.625rem;
    color: var(--text-main);
}

.password-field {
    position: relative;
    display: flex;
    align-items: center;
}

.password-toggle {
    position: absolute;
    right: 1.25rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.2s;
    background: none;
    border: none;
    padding: 0;
}

.password-toggle:hover {
    color: var(--primary);
}

input,
select,
textarea {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg);
    font-size: 1rem;
    color: var(--text-main);
    transition: all 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    background: white;
    outline: none;
    box-shadow: 0 0 0 4px var(--primary-light);
}

/* Categories UI */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.category-option {
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
}

.category-option i {
    display: block;
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.category-option span {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
}

.category-option.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.category-option.selected i,
.category-option.selected span {
    color: var(--primary);
}

/* Floating Action Button */
/* Floating Action Button - FIXED & CONSOLIDATED */
.fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 4.5rem;
    height: 4.5rem;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 2rem;
    box-shadow: 0 15px 35px -5px rgba(67, 56, 202, 0.6);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 1000;
    text-decoration: none;
    border: none;
    outline: none;
}

/* No separate .fab i rule needed anymore due to the generic one above */

/* Responsive Table Cards (for mobile) */
@media (max-width: 768px) {
    .mobile-cards thead {
        display: none;
    }

    .mobile-cards,
    .mobile-cards tbody,
    .mobile-cards tr,
    .mobile-cards td {
        display: block;
        width: 100%;
    }

    .mobile-cards tr {
        margin-bottom: 1.5rem;
        background: white;
        border-radius: 1rem;
        padding: 1rem;
        border: 1px solid var(--border);
        box-shadow: var(--shadow-sm);
    }

    .mobile-cards td {
        padding: 0.5rem 0;
        border: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
    }

    .mobile-cards td::before {
        content: attr(data-label);
        font-weight: 800;
        font-size: 0.75rem;
        text-transform: uppercase;
        color: var(--text-muted);
        text-align: left;
    }
}

/* Mobile Toggle */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 1.25rem;
    left: 1.25rem;
    z-index: 200;
    background: white;
    width: 3rem;
    height: 3rem;
    border-radius: 12px;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: var(--primary);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    cursor: pointer;
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Stats & Analysis Grids */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.analysis-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    margin-top: 2rem;
}

/* Desktop Refinements (Balancing the layout) */
@media (min-width: 1025px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr); /* Balanced 3-column layout */
    }

    .analysis-row {
        grid-template-columns: 1.6fr 1fr; /* Larger chart, smaller loans block */
    }

    .main-content {
        padding: 3rem 4rem;
        max-width: 1600px; /* Prevent over-stretching on ultra-wide */
    }
}

/* Responsive Overrides */
@media (max-width: 1024px) {
    .mobile-toggle {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.open {
        transform: translateX(0);
        display: flex !important;
    }

    .analysis-row, .stats-grid {
        gap: 1.25rem;
    }

    .loan-stat-item {
        border-right: none !important;
        padding: 0 !important;
    }

    .status-badge {
        padding: 0.25rem 0.5rem !important;
        font-size: 0.65rem !important;
    }

    .btn-action {
        width: 32px !important;
        height: 32px !important;
        font-size: 0.9rem !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 5.5rem 1rem 6.5rem !important;
        width: 100%;
        overflow-x: hidden;
    }
}

@media (max-width: 400px) {
    .welcome-text h1 {
        font-size: 1.25rem;
    }

    .main-content {
        padding: 5rem 0.5rem 6rem !important;
    }

    .premium-card {
        padding: 0.875rem;
    }

    input,
    select,
    textarea {
        padding: 0.75rem;
        font-size: 0.9375rem;
    }
}