// ========================================
// Global Variables & Base Styles
// ========================================

// Variables
$primary-color: #4361ee;
$secondary-color: #3f37c9;
$accent-color: #4895ef;
$success-color: #4cc9f0;
$danger-color: #f72585;
$warning-color: #f8961e;
$info-color: #0dcaf0;
$light-bg: #f8f9fa;
$dark-bg: #212529;
$purple-color: #6f42c1;
$teal-color: #20c997;
$pink-color: #d63384;
$indigo-color: #6610f2;
$orange-color: #fd7e14;
$cyan-color: #0dcaf0;
$gray-color: #6c757d;
$card-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
$transition: all 0.3s ease;
$border-radius: 0.5rem;

// CSS Variables (for runtime theming)
:root {
    --primary-color: #4361ee;
    --secondary-color: #3f37c9;
    --accent-color: #4895ef;
    --success-color: #4cc9f0;
    --danger-color: #f72585;
    --warning-color: #f8961e;
    --info-color: #0dcaf0;
    --light-bg: #f8f9fa;
    --dark-bg: #212529;
    --purple-color: #6f42c1;
    --teal-color: #20c997;
    --pink-color: #d63384;
    --indigo-color: #6610f2;
    --orange-color: #fd7e14;
    --cyan-color: #0dcaf0;
    --gray-color: #6c757d;
    --card-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
    --border-radius: 0.5rem;
}

// ========================================
// BASE STYLES
// ========================================
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: $light-bg;
    color: #333;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

// ========================================
// LAYOUT SYSTEM - Responsive
// ========================================
.main-content {
    margin-left: 280px;
    padding: 1.5rem;
    background-color: $light-bg;
    min-height: 100vh;
    width: calc(100% - 280px);
    overflow-x: auto;
    transition: $transition;
}

.container-fluid {
    padding: 0;
    margin: 0;
    width: 100%;
}

// ========================================
// SIDEBAR - Fully Responsive with Scroll
// ========================================
.sidebar {
    width: 280px;
    background: linear-gradient(180deg, #1a1e2b 0%, #0f1119 100%);
    color: #e2e8f0;
    height: 100vh !important;
    min-height: 100vh !important;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1000;
    transition: $transition;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);

    // Scrollable Navigation Area
    .sidebar-nav {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 0.5rem 0;
        scrollbar-width: thin;
        scrollbar-color: #667eea rgba(102, 126, 234, 0.2);
        min-height: 0;

        // Custom Scrollbar Styling
        &::-webkit-scrollbar {
            width: 4px;
        }

        &::-webkit-scrollbar-track {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 4px;
        }

        &::-webkit-scrollbar-thumb {
            background: #667eea;
            border-radius: 4px;

            &:hover {
                background: #5a67d8;
            }
        }

        // Navigation Links
        .nav {
            flex-direction: column;
            gap: 2px;
            list-style: none;
            padding-left: 0;
            margin-bottom: 0;
        }

        .nav-item {
            width: 100%;
        }

        .nav-link {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 0.6rem 1rem;
            color: #cbd5e1;
            transition: $transition;
            font-size: 0.85rem;
            font-weight: 500;
            border-radius: 10px;
            margin: 0 6px;
            text-decoration: none;
            cursor: pointer;

            i {
                width: 22px;
                font-size: 1rem;
                text-align: center;
            }

            span {
                flex: 1;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            }

            .chevron-icon {
                width: auto;
                font-size: 0.7rem;
                transition: transform 0.3s ease;
            }

            &:hover {
                background: rgba(255, 255, 255, 0.08);
                color: white;
            }

            &.active {
                background: linear-gradient(90deg, #667eea 0%, rgba(102, 126, 234, 0.2) 100%);
                color: white;
                border-left: 3px solid #667eea;
            }
        }

        // Salary Link Special Style
        .salary-link {
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.2) 0%, rgba(118, 75, 162, 0.2) 100%);
            border: 1px solid rgba(102, 126, 234, 0.3);
            margin: 4px 6px;
        }

        // Submenu
        .submenu {
            margin-left: 28px !important;
            background: rgba(0, 0, 0, 0.2);
            border-radius: 10px;
            margin-top: 2px;
            margin-bottom: 2px;
            display: none;
            list-style: none;
            padding-left: 0;

            .nav-link {
                padding: 0.5rem 0.8rem;
                font-size: 0.75rem;
                margin: 0 6px;

                i {
                    font-size: 0.75rem;
                    width: 20px;
                }

                &.active {
                    background: linear-gradient(90deg, #667eea 0%, rgba(102, 126, 234, 0.15) 100%);
                }
            }
        }
    }

    // Sidebar Sections - Prevent shrinking
    .sidebar-header {
        flex-shrink: 0;
        padding: 1rem 1rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);

        .sidebar-logo {
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 1.25rem;
            font-weight: 700;
            color: white;

            i {
                font-size: 1.5rem;
                background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                padding: 6px;
                border-radius: 10px;
            }
        }

        .sidebar-tagline {
            font-size: 0.65rem;
            color: #a0aec0;
            margin-top: 6px;
            margin-left: 2px;
        }
    }

    .user-info-card {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 0.75rem 1rem;
        margin: 0.5rem 0.75rem;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 12px;
        border: 1px solid rgba(255, 255, 255, 0.08);

        .user-avatar i {
            font-size: 2rem;
            color: #a0aec0;
        }

        .user-name {
            font-weight: 600;
            color: white;
            font-size: 0.85rem;
            margin-bottom: 2px;
        }

        .user-role {
            font-size: 0.65rem;
            color: #a0aec0;
            display: flex;
            align-items: center;
            gap: 4px;
        }
    }

    .role-toggle-container {
        flex-shrink: 0;
        padding: 0.5rem 1rem;
        margin: 0 0.75rem 0.75rem;
        background: linear-gradient(135deg, rgba(102, 126, 234, 0.15) 0%, rgba(118, 75, 162, 0.15) 100%);
        border-radius: 12px;
        border: 1px solid rgba(102, 126, 234, 0.3);

        .role-toggle-label {
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 0.65rem;
            color: #a0aec0;
            margin-bottom: 6px;
        }

        .role-toggle-switch {
            display: flex;
            align-items: center;
            justify-content: space-between;
            cursor: pointer;
            gap: 10px;
        }

        .role-toggle-track {
            width: 44px;
            height: 22px;
            background: #2d3748;
            border-radius: 30px;
            position: relative;
            transition: $transition;

            .role-toggle-thumb {
                width: 18px;
                height: 18px;
                background: #667eea;
                border-radius: 50%;
                position: absolute;
                top: 2px;
                left: 3px;
                transition: $transition;
            }

            &.admin-mode .role-toggle-thumb {
                transform: translateX(0);
            }

            &.director-mode .role-toggle-thumb {
                transform: translateX(20px);
                background: #f59e0b;
            }
        }

        .role-toggle-status {
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 0.7rem;
            font-weight: 500;
        }
    }

    // Logout Button
    .logout-btn {
        background: rgba(239, 68, 68, 0.1);
        border: 1px solid rgba(239, 68, 68, 0.3);
        margin: 0.5rem 6px;
        width: calc(100% - 12px);
        text-align: left;

        &:hover {
            background: rgba(239, 68, 68, 0.2);
            color: #ef4444;
        }
    }
}

// Badges
.nav-badge {
    background: #ef4444;
    color: white;
    font-size: 0.55rem;
    padding: 2px 5px;
    border-radius: 20px;
    margin-left: 6px;
    display: inline-block;
}

.new-badge {
    background: linear-gradient(135deg, #10b981, #059669);
    animation: pulse 2s infinite;
}

// Role-based visibility
.admin-only {
    display: none;
}

body.admin-mode .admin-only {
    display: flex;
}

// ========================================
// ANIMATIONS
// ========================================
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.animate-slide-in {
    animation: slideIn 0.3s ease-out;
}

// ========================================
// RESPONSIVE BREAKPOINTS
// ========================================

// Large Desktop (1400px and above)
@media (min-width: 1400px) {
    .sidebar {
        width: 300px;
    }
    .main-content {
        margin-left: 300px;
        width: calc(100% - 300px);
    }
}

// Desktop (1200px - 1399px)
@media (max-width: 1399px) and (min-width: 1200px) {
    .sidebar {
        width: 280px;
    }
    .main-content {
        margin-left: 280px;
        width: calc(100% - 280px);
    }
}

// Small Desktop / Large Tablet (992px - 1199px)
@media (max-width: 1199px) and (min-width: 992px) {
    .sidebar {
        width: 260px;
    }
    .main-content {
        margin-left: 260px;
        width: calc(100% - 260px);
    }
}

// Tablet (768px - 991px)
@media (max-width: 991px) {
    .sidebar {
        width: 240px;
    }
    .main-content {
        margin-left: 240px;
        width: calc(100% - 240px);
        padding: 1rem;
    }
    .sidebar-nav .nav-link {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }
    .stat-card {
        height: 120px;
        h2 {
            font-size: 1.5rem;
        }
    }
    .card-body {
        padding: 1rem;
    }
}

// Mobile Landscape (576px - 767px)
@media (max-width: 767px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        min-height: auto;
        max-height: 60vh;
        overflow-y: auto;
    }
    .sidebar-nav {
        max-height: none;
    }
    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 1rem;
    }
    .sidebar-nav .nav-link {
        padding: 0.6rem 1rem;
    }
}

// Mobile Portrait (below 576px)
@media (max-width: 575px) {
    .main-content {
        padding: 0.75rem;
    }
    .sidebar {
        max-height: 50vh;
    }
    .sidebar-nav .nav-link {
        padding: 0.5rem 0.8rem;
        font-size: 0.75rem;
        
        i {
            width: 20px;
            font-size: 0.9rem;
        }
    }
    .user-name {
        font-size: 0.75rem;
    }
    .role-toggle-status {
        font-size: 0.65rem;
    }
    .stat-card {
        height: 100px;
        h2 {
            font-size: 1.2rem;
        }
    }
}

// Zoom Support - 150%
@media screen and (max-width: 850px) and (min-width: 768px) {
    .sidebar {
        width: 220px;
    }
    .main-content {
        margin-left: 220px;
        width: calc(100% - 220px);
    }
}

// Zoom Support - 200%
@media screen and (max-width: 680px) and (min-width: 576px) {
    .sidebar {
        width: 200px;
    }
    .main-content {
        margin-left: 200px;
        width: calc(100% - 200px);
    }
    .sidebar-nav .nav-link {
        padding: 0.45rem 0.7rem;
        font-size: 0.7rem;
        
        i {
            width: 18px;
            font-size: 0.8rem;
        }
    }
    .user-name {
        font-size: 0.7rem;
    }
    .user-avatar i {
        font-size: 1.6rem;
    }
}

// Extra Zoom Support
@media screen and (max-width: 520px) {
    .sidebar {
        width: 180px;
    }
    .main-content {
        margin-left: 180px;
        width: calc(100% - 180px);
    }
}

// ========================================
// CARDS & TABLES (Responsive)
// ========================================
.card {
    border: none;
    border-radius: $border-radius;
    box-shadow: $card-shadow;
    transition: $transition;
    margin-bottom: 1.5rem;
    background: white;

    &:hover {
        transform: translateY(-5px);
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
    }

    .card-body {
        padding: 1.5rem;
    }

    .card-header {
        color: grey;
        text-align: center;
        background: #f8f9fa;
        border-bottom: 1px solid #e3e6f0;
        padding: 1rem 1.25rem;
        background-color: #f8fafc;
        border-bottom: 1px solid #e2e8f0;
        padding: 0.75rem 1rem 0 1rem;

        .nav-tabs {
            .nav-link {
                color: #4a5568;
                background-color: #f8f9fc;
                border: 1px solid #e2e8f0;
                border-bottom: none;
                margin-right: 4px;
                padding: 0.75rem 1.25rem;
                font-weight: 500;
                transition: all 0.25s ease;
                position: relative;
                border-radius: 0.5rem 0.5rem 0 0;

                i {
                    margin-right: 0.5rem;
                    font-size: 0.9rem;
                }

                .badge {
                    margin-left: 0.5rem;
                    transition: all 0.2s ease;
                    font-size: 0.7rem;
                    padding: 0.25rem 0.5rem;
                }

                &:not(.active) {
                    background-color: #f1f5f9;
                    border-color: #e2e8f0;
                    color: #334155;

                    .badge {
                        background-color: #94a3b8;
                        color: white;
                    }

                    &:hover {
                        background-color: #e2e8f0;
                        border-color: #cbd5e1;
                        color: #1e293b;
                        transform: translateY(-1px);
                    }
                }

                &.active {
                    color: #2563eb;
                    background-color: #ffffff;
                    border-color: #bfdbfe;
                    border-bottom-color: #ffffff;
                    font-weight: 600;
                    box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.02);

                    .badge {
                        background-color: #2563eb;
                        color: white;
                    }

                    &::after {
                        content: '';
                        position: absolute;
                        bottom: -1px;
                        left: 0;
                        right: 0;
                        height: 2px;
                        background-color: #2563eb;
                        border-radius: 2px 2px 0 0;
                    }

                    &:hover {
                        background-color: #ffffff;
                        color: #1d4ed8;
                    }
                }

                &:focus {
                    box-shadow: none;
                    outline: none;
                }
            }
        }
    }
}

.stat-card {
    height: 140px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 15px;
    color: white;
    border-radius: $border-radius;

    .card-body {
        padding: 1.25rem;
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    h2 {
        font-size: 1.8rem;
        font-weight: 700;
        margin-bottom: 0.25rem;
        line-height: 1.2;
    }
}

// Card color variants
.card-primary { background: #273364; }
.card-success { background: #2ecc71; }
.card-danger { background: #e74c3c; }
.card-warning { background: #f39c12; }
.card-info { background: #3498db; }
.card-purple { background: #9b59b6; }
.card-teal { background: #1abc9c; }
.card-indigo { background: #3f51b5; }
.card-orange { background: #e67e22; }
.card-cyan { background: #00bcd4; }
.card-gray { background: #95a5a6; }

// Responsive Tables
.table-container {
    background-color: white;
    border-radius: $border-radius;
    box-shadow: $card-shadow;
    padding: 1.5rem;
    margin-bottom: 2rem;
    overflow-x: auto;
}

.table {
    margin-bottom: 0;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 600px;

    th {
        background: #f8f9fa;
        border-bottom: 2px solid #e0e0e0;
        font-weight: 600;
        text-transform: uppercase;
        font-size: 0.8rem;
        padding: 12px 8px;
    }
}

// ========================================
// FORMS
// ========================================
.form-control {
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px 12px;
    transition: $transition;

    &:focus {
        border-color: $primary-color;
        box-shadow: 0 0 0 0.2rem rgba(67, 97, 238, 0.25);
    }
}

// ========================================
// BUTTONS
// ========================================
.btn {
    border-radius: 6px;
    padding: 8px 16px;
    transition: $transition;
    border: 1px solid transparent;
    font-weight: 500;

    &-primary {
        background-color: $primary-color;
        border-color: $primary-color;

        &:hover {
            background-color: #3a56d4;
            border-color: #3a56d4;
            transform: translateY(-1px);
        }
    }
}

// ========================================
// BADGES
// ========================================
.badge {
    font-size: 0.75em;
    font-weight: 500;
    padding: 0.35em 0.65em;
    border-radius: 0.375rem;

    &.bg-success { background-color: $success-color !important; }
    &.bg-danger { background-color: $danger-color !important; }
    &.bg-warning { background-color: $warning-color !important; }
}

// ========================================
// UTILITIES
// ========================================
.positive { color: #28a745; font-weight: 600; }
.negative { color: #dc3545; font-weight: 600; }
.text-success { color: #28a745 !important; }
.text-danger { color: #dc3545 !important; }

.kes {
    color: $primary-color;
    font-weight: 600;
}

// ========================================
// DASHBOARD COMPONENTS
// ========================================
.dashboard-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.dashboard-header {
    background: white;
    padding: 1rem 1.5rem;
    margin: 0 0 1.5rem 0;
    border-radius: $border-radius;
    box-shadow: $card-shadow;
    border-bottom: 1px solid #e3e6f0;
}

// ========================================
// GRID SYSTEM
// ========================================
.row {
    margin-left: -8px;
    margin-right: -8px;
    display: flex;
    flex-wrap: wrap;
}

.col-xl-2, .col-lg-4, .col-md-6, .col-sm-6 {
    padding-left: 8px;
    padding-right: 8px;
}

// ========================================
// RESPONSIVE TAB ADJUSTMENTS
// ========================================
@media (max-width: 768px) {
    .card-header .nav-tabs {
        flex-wrap: wrap;
        gap: 0.25rem;
        
        .nav-link {
            padding: 0.5rem 0.75rem;
            font-size: 0.85rem;
            
            i {
                margin-right: 0.3rem;
                font-size: 0.8rem;
            }
        }
    }
}