:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --glass: rgba(255, 255, 255, 0.03);
    --border: rgba(255, 255, 255, 0.1);
    --success: #10b981;
    --error: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', 'Outfit', 'Cairo', sans-serif;
}

body {
    background: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    width: 100%;
}

.dashboard-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* Sidebar */
nav.sidebar {
    width: 260px;
    background: rgba(15, 23, 42, 0.9);
    border-right: 1px solid var(--border);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 3rem;
    background: linear-gradient(45deg, #818cf8, #c084fc);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    list-style: none;
}

.nav-links li {
    padding: 1rem;
    margin-bottom: 0.5rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-links li:hover,
.nav-links li.active {
    background: var(--glass);
    color: var(--text-main);
}

.nav-links li.active {
    background: var(--primary);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

/* Main Content */
main.content {
    flex: 1;
    min-width: 0;
    width: 100%;
    padding: 2rem 3rem;
    background: radial-gradient(circle at 50% 0%, #1e293b, #0f172a);
}

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

.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-item {
    padding: 1.5rem;
}

.stat-title {
    color: var(--text-dim);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
}

/* Forms & Tables */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

input,
select {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--border);
    padding: 0.75rem;
    border-radius: 8px;
    color: white;
    width: 100%;
    margin-bottom: 1rem;
    outline: none;
}

select option {
    background-color: #1e293b;
    color: white;
}

input::placeholder {
    color: #64748b;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

th,
td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-dim);
    font-weight: 500;
}

.hidden {
    display: none;
}

[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] th,
[dir="rtl"] td {
    text-align: right;
}

#print-area {
    display: none;
}

/* Scheduler Styles */
.scheduler-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 12px;
    align-items: center;
}

.timeline-container {
    overflow-x: auto;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 20px;
    position: relative;
    margin-top: 20px;
}

.timeline-hours {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
    position: relative;
    min-width: 1200px;
    margin-right: 165px;
}

.hour-mark {
    flex: 1;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-dim);
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 5px;
}

.employee-row {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
    min-width: 1200px;
}

.emp-name-tag {
    width: 150px;
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shift-track {
    flex: 1;
    height: 35px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    position: relative;
}

.shift-bar {
    position: absolute;
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #818cf8);
    border-radius: 6px;
    cursor: ew-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: white;
    user-select: none;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.peak-track {
    height: 10px;
    margin-bottom: 20px;
    position: relative;
    border-radius: 4px;
    background: rgba(239, 68, 68, 0.1);
    min-width: 1200px;
    margin-right: 165px;
}

.peak-marker {
    position: absolute;
    height: 100%;
    background: var(--error);
    border-radius: 4px;
    opacity: 0.6;
    cursor: ew-resize;
}

.peak-marker:hover {
    opacity: 1;
}

@media print {
    body> :not(#print-area) {
        display: none !important;
    }

    body {
        background: white !important;
        display: block !important;
    }

    #print-area {
        display: block !important;
        position: static;
        background: white;
        color: black;
        padding: 20px;
        width: 100%;
        direction: rtl;
    }

    #print-area table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 20px;
        color: black;
        background: white;
    }

    #print-area th,
    #print-area td {
        border: 1px solid #333;
        padding: 8px;
        color: black;
        text-align: center;
    }

    #print-area th {
        background: #f1f5f9;
        font-weight: bold;
    }

    #print-area .print-header {
        text-align: center;
        margin-bottom: 20px;
        border-bottom: 2px solid #333;
        padding-bottom: 10px;
    }

    #print-area .print-header h2 {
        margin: 0;
        font-size: 24px;
        font-weight: bold;
    }

    #print-area h3 {
        margin-bottom: 15px;
    }
}

/* Map & GPS UI */
#admin-map {
    border: 1px solid var(--border);
    background: #000;
}

.swal2-html-container {
    overflow: visible !important;
}

.leaflet-control-container .leaflet-top,
.leaflet-control-container .leaflet-bottom {
    z-index: 1001 !important;
}

/* Responsiveness */
.sidebar-toggle-btn {
    display: none;
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1001;
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
}

@media (max-width: 992px) {
    nav.sidebar {
        position: fixed;
        right: -280px;
        /* Increased to be safe */
        left: auto !important;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transition: right 0.3s ease;
        box-shadow: -5px 0 15px rgba(0, 0, 0, 0.5);
    }

    nav.sidebar.active {
        right: 0;
    }

    .sidebar-toggle-btn {
        display: block;
    }

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

    main.content {
        padding: 4.5rem 1rem 2rem;
    }
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .glass-card {
        padding: 1rem;
        border-radius: 14px;
        overflow-x: auto;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    header h1 {
        font-size: 1.3rem;
    }

    /* Tables: horizontal scroll wrapper */
    .table-container {
        border-radius: 12px;
        padding: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 450px;
        /* Reduced min-width to avoid excessive scroll */
        font-size: 0.8rem;
    }

    th,
    td {
        padding: 0.6rem 0.5rem;
        white-space: nowrap;
        font-size: 0.78rem;
    }

    /* Filter bars: stack vertically */
    .filter-bar,
    .glass-inner {
        flex-direction: column !important;
        gap: 8px !important;
    }

    .filter-bar>*,
    .glass-inner>* {
        flex: unset !important;
        width: 100% !important;
        min-width: unset !important;
    }

    /* Form elements */
    form {
        display: flex;
        flex-direction: column;
    }

    select,
    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="month"],
    input[type="password"],
    input[type="time"] {
        font-size: 0.85rem;
        padding: 0.65rem;
    }

    .btn {
        padding: 0.65rem 1.2rem;
        font-size: 0.85rem;
        width: 100%;
        text-align: center;
    }

    h2 {
        font-size: 1.15rem;
    }

    h3 {
        font-size: 1rem;
    }

    /* Scheduler controls stack */
    .scheduler-controls {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }

    .scheduler-controls>* {
        width: 100%;
    }

    /* Notification dropdown */
    #notif-dropdown {
        width: calc(100vw - 2rem) !important;
        left: 1rem !important;
        right: 1rem !important;
        max-width: none !important;
    }

    /* Employee modal */
    #modal-emp>.glass-card {
        width: 95vw !important;
        max-width: 95vw !important;
        padding: 15px !important;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* SweetAlert modals */
    .swal2-popup {
        width: 95% !important;
        padding: 1rem !important;
    }

    /* User info in header */
    .user-info {
        font-size: 0.8rem;
    }

    /* Permissions checkboxes layout */
    .perm-cb-container {
        flex-direction: column;
        gap: 8px !important;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    main.content {
        padding: 4rem 0.5rem 1rem;
    }

    .glass-card {
        padding: 0.75rem;
        border-radius: 10px;
    }

    header h1 {
        font-size: 1.1rem;
    }

    table {
        font-size: 0.75rem;
    }

    th,
    td {
        padding: 0.5rem 0.4rem;
        font-size: 0.72rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stat-title {
        font-size: 0.8rem;
    }

    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.8rem;
    }
}

/* Scrollbar styling for better look */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

@keyframes pulse-new {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}