:root {
    /* Premium Theme Variables */
    --bg-color: #f8fafc;
    --sidebar-bg: #ffffff;
    --card-bg: rgba(255, 255, 255, 0.8);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;

    /* Accent Colors */
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-gradient: linear-gradient(135deg, #4f46e5, #3b82f6);

    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;

    /* Shadows */
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05);

    --sidebar-width: 270px;
    --header-height: 72px;
    --glass-border: 1px solid rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] {
    --bg-color: #0f172a;
    --sidebar-bg: #1e293b;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --glass-border: 1px solid rgba(255, 255, 255, 0.05);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    transition: background-color 0.2s, border-color 0.2s;
}

body {
    font-family: 'Outfit', 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    background-image:
        radial-gradient(at 0% 0%, rgba(79, 70, 229, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(59, 130, 246, 0.05) 0px, transparent 50%);
    background-attachment: fixed;
    margin: 0;
}

/* Layout System */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    padding: 2rem 1.5rem;
    z-index: 100;
    /* Increased Z-Index */
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar nav {
    flex: 1;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.sidebar nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar nav::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.sidebar nav::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 2.5rem;
    padding-top: calc(var(--header-height) + 2.5rem);
    min-width: 0;
    /* Prevents flex children from blowing out width */
}

.top-bar {
    height: var(--header-height);
    background: rgba(255, 255, 255, 0.7);
    border-bottom: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    /* Reduced padding for better space */
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

[data-theme="dark"] .top-bar {
    background: rgba(30, 41, 59, 0.7);
}

/* UI Elements */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
}

.btn-primary:hover {
    box-shadow: 0 10px 15px -3px rgba(79, 70, 229, 0.3);
    transform: translateY(-1px);
}

.btn-danger {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--danger);
}

.btn-danger:hover {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: var(--danger);
}

/* Cards */
.card {
    background-color: var(--card-bg);
    border-radius: 1.25rem;
    padding: 2rem;
    border: var(--glass-border);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(12px);
    transition: box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

/* Inputs */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 0.875rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.2s;
    outline: none;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    background: var(--card-bg);
}

/* List Items */
.list-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1.25rem;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    background: transparent;
    transition: all 0.2s;
    margin-bottom: 1rem;
}

.list-item:hover {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.5);
    transform: translateX(4px);
}

[data-theme="dark"] .list-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Tags */
.tag {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.tag-blue {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.tag-green {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.tag-red {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.tag-purple {
    background: rgba(139, 92, 246, 0.1);
    color: #8b5cf6;
}

/* Navigation */
.nav-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 0.75rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-color);
}

.nav-link.active {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.nav-link svg {
    width: 20px;
    height: 20px;
    opacity: 0.9;
}

/* Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

/* TAB & DROP ZONE */
.nav-tabs {
    display: flex;
    gap: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.nav-tab {
    background: none;
    border: none;
    padding: 0.75rem 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    font-weight: 600;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.nav-tab:hover {
    color: var(--text-primary);
}

.nav-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.drop-zone {
    padding: 3rem;
    border: 2px dashed var(--border-color);
    text-align: center;
    border-radius: 1rem;
    margin-bottom: 1rem;
    transition: all 0.2s;
    background: var(--bg-color);
    cursor: pointer;
}

.drop-zone:hover {
    border-color: var(--accent);
    background: rgba(79, 70, 229, 0.05);
}

/* TABLES */
.table-responsive {
    overflow-x: auto;
    margin-bottom: 1rem;
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.table th {
    text-align: left;
    padding: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.95rem;
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover td {
    background: rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .table tr:hover td {
    background: rgba(255, 255, 255, 0.05);
}

/* Search */
.search-container {
    background: var(--bg-color);
    padding: 0.75rem 1.25rem;
    border-radius: 3rem;
    display: flex;
    align-items: center;
    width: 320px;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.search-container:focus-within {
    background: var(--card-bg);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.search-container input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    outline: none;
    margin-left: 0.75rem;
    width: 100%;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 3rem;
    transition: background 0.2s;
}

.user-profile:hover {
    background: rgba(0, 0, 0, 0.05);
}

.user-avatar {
    width: 42px;
    height: 42px;
    background: var(--accent-gradient);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 1.5rem;
}

.modal-content {
    background: var(--sidebar-bg);
    border-radius: 1.5rem;
    padding: 2.5rem;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: var(--glass-border);
    position: relative;
    animation: modalSlide 0.3s ease-out;
}

@keyframes modalSlide {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Mobile Breakpoint - STRICTLY at end */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
        --header-height: 60px;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        box-shadow: var(--shadow-lg);
        width: 280px;
        z-index: 1000;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Mobile Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: calc(var(--header-height) + 1rem);
    }

    .top-bar {
        left: 0;
        padding: 0 1rem;
        height: var(--header-height);
    }

    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .search-container {
        display: none;
    }

    .user-profile>div:first-child {
        display: none;
    }

    /* Cards mobile adjustments */
    .card {
        padding: 1rem;
        border-radius: 1rem;
    }

    /* Buttons touch-friendly */
    .btn {
        padding: 0.875rem 1.25rem;
        min-height: 44px;
    }

    /* Tables - horizontal scroll */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table {
        min-width: 600px;
    }

    .table th,
    .table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.85rem;
    }

    /* Modal full-screen on mobile */
    .modal-content {
        max-width: 100%;
        max-height: 90vh;
        margin: 0.5rem;
        padding: 1.5rem;
        border-radius: 1rem;
        overflow-y: auto;
    }

    /* Form controls larger for touch */
    .form-control {
        padding: 1rem;
        font-size: 16px;
        /* Prevents iOS zoom */
    }

    /* Nav links touch-friendly */
    .nav-link {
        padding: 1rem;
        font-size: 0.95rem;
    }

    /* Stats grid on mobile */
    .stat-card,
    [class*="stat"] {
        padding: 1rem !important;
    }

    /* Hide text on small screens, show only icons */
    .btn span.btn-text {
        display: none;
    }

    /* Page headers */
    h1,
    h2 {
        font-size: 1.25rem !important;
    }

    /* Progress bars mobile */
    .progress-bar {
        height: 8px;
    }

    /* Action buttons grid */
    .smart-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .action-btn {
        width: 40px;
        height: 40px;
    }

    /* Employee grid cards on mobile */
    .agent-row {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        padding: 1rem !important;
    }

    .agent-row .grid-layout {
        display: flex;
        flex-direction: column;
    }

    /* Leaderboard cards */
    [style*="grid-template-columns: repeat(auto-fit"] {
        grid-template-columns: 1fr !important;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .main-content {
        padding: 0.75rem;
        padding-top: calc(var(--header-height) + 0.75rem);
    }

    .card {
        padding: 0.875rem;
    }

    .modal-content {
        padding: 1rem;
        margin: 0.25rem;
    }

    /* Stack form columns */
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Smaller fonts */
    body {
        font-size: 14px;
    }

    h1,
    h2 {
        font-size: 1.1rem !important;
    }
}