:root {
    --bg-base: #09090b;
    --bg-surface: #18181b;
    --bg-surface-hover: #27272a;
    
    --border: #27272a;
    --border-hover: #3f3f46;
    
    --text-main: #f4f4f5;
    --text-muted: #a1a1aa;
    
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-glow: rgba(59, 130, 246, 0.5);
    
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.1);
    
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.1);

    --font-family: 'Tajawal', system-ui, sans-serif;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 20px -5px var(--primary-glow);
    
    --glass-bg: rgba(24, 24, 27, 0.7);
    --glass-border: rgba(255, 255, 255, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    font-family: var(--font-family);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 50% 50%, rgba(59, 130, 246, 0.03) 0%, transparent 50%);
    z-index: -1;
    pointer-events: none;
}

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.025em; }
h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.025em; }
h3 { font-size: 1.25rem; font-weight: 600; }
p { color: var(--text-muted); font-size: 0.95rem; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.95rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: var(--font-family);
}

.btn-primary {
    background: linear-gradient(180deg, #428af8 0%, #3b82f6 100%);
    color: white;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), var(--shadow-sm);
}

.btn-primary:hover {
    background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), var(--shadow-glow);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border-color: var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-hover);
}

.btn-warning { background: var(--warning); color: #fff; }
.btn-accent { background: var(--success); color: #fff; }

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-icon:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-main);
}
.btn-icon.text-danger:hover {
    color: var(--danger);
    background: var(--danger-bg);
}
.btn-icon.text-primary:hover {
    color: var(--primary);
    background: var(--primary-glow);
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-main);
    font-weight: 500;
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 1rem;
    transition: all 0.2s;
    font-family: var(--font-family);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

select.form-control option { background: var(--bg-surface); color: var(--text-main); }

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

.sidebar {
    width: 280px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    z-index: 10;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1rem 2rem 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
}

.brand h3 {
    font-size: 1.2rem;
    font-weight: 800;
    background: linear-gradient(to right, #fff, #a1a1aa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

.nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
    cursor: pointer;
}

.nav-item-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-item i {
    font-size: 1.25rem;
}

.nav-item:hover {
    background: var(--bg-surface-hover);
    color: var(--text-main);
}

.nav-item.active {
    background: var(--primary-glow);
    color: var(--primary);
    border-right: 3px solid var(--primary);
}

.submenu {
    list-style: none;
    padding-right: 2rem;
    margin-top: 0.25rem;
    display: none;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-item.open + .submenu {
    display: flex;
}

.nav-item.open .caret {
    transform: rotate(180deg);
}
.caret { transition: transform 0.2s; }

.submenu-item {
    padding: 0.6rem 1rem;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    position: relative;
}

.submenu-item::before {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--text-muted);
}

.submenu-item:hover {
    color: var(--text-main);
    background: rgba(255,255,255,0.02);
}

.submenu-item.active {
    color: var(--primary);
    background: var(--primary-glow);
}
.submenu-item.active::before { background: var(--primary); }

.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.topbar {
    height: 70px;
    background: rgba(9, 9, 11, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    z-index: 5;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-surface-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    font-weight: bold;
    color: var(--primary);
}

.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

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

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    border-color: var(--primary);
}

.stat-info p {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.stat-info h2 {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
}

.stat-card .progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    background: var(--primary);
    border-radius: 0 0 0 var(--radius-lg);
    opacity: 0.5;
}

.dashboard-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
    margin-top: 1.5rem;
    align-items: start;
}

@media (max-width: 1024px) {
    .dashboard-layout {
        grid-template-columns: 1fr;
    }
}

.chart-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.chart-container {
    flex: 1;
    min-height: 250px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.welcome-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    padding: 2rem;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, transparent 100%);
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
    position: relative;
    overflow: hidden;
}

.welcome-section::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
    height: 100%;
    background: radial-gradient(circle at top right, rgba(59, 130, 246, 0.1), transparent 70%);
    pointer-events: none;
}

.welcome-text h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.welcome-text p {
    font-size: 1.1rem;
    color: var(--text-muted);
}

.icon-danger { background: var(--danger-bg); color: var(--danger); }
.icon-warning { background: var(--warning-bg); color: var(--warning); }
.icon-success { background: var(--success-bg); color: var(--success); }

.table-container {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
}

.table-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
}

th {
    padding: 1rem 1.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: rgba(255,255,255,0.02);
    border-bottom: 1px solid var(--border);
}

td {
    padding: 1rem 1.5rem;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    white-space: nowrap;
}

tr:last-child td {
    border-bottom: none;
}

tbody tr {
    transition: background 0.2s;
}

tbody tr:hover {
    background: rgba(255,255,255,0.02);
}

.badge {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap !important;
    gap: 6px;
}

th, td {
    padding: 1rem 0.75rem;
    text-align: right;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    white-space: nowrap !important;
}

.report-table th, .report-table td {
    padding: 0.75rem 0.5rem;
    font-size: 0.85rem;
}

.report-table td:nth-child(3) { /* Title in report */
    min-width: 200px;
}

.report-table td:nth-child(5), 
.report-table td:nth-child(6), 
.report-table td:nth-child(7) {
    font-size: 0.75rem;
}

.badge-pending { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.2); }
.badge-assigned { background: var(--primary-glow); color: var(--primary); border: 1px solid rgba(59, 130, 246, 0.2); }
.badge-in_progress { background: rgba(16, 185, 129, 0.2); color: var(--success); border: 1px solid rgba(16, 185, 129, 0.2); }
.badge-completed { background: rgba(161, 161, 170, 0.1); color: var(--text-muted); border: 1px solid rgba(161, 161, 170, 0.2); }

.modal-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 550px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    background: rgba(255,255,255,0.01);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.fade-in { animation: fadeIn 0.4s ease-out; }

.login-container {
    display: flex;
    min-height: 100vh;
    width: 100vw;
}

.login-left {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-md);
}

.login-right {
    flex: 1;
    background: linear-gradient(135deg, var(--bg-base) 0%, #1e1b4b 100%);
    display: none;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

@media (min-width: 992px) {
    .login-right { display: flex; }
}

.login-right::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    background: var(--primary);
    border-radius: 50%;
    filter: blur(150px);
    opacity: 0.15;
}

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

.perm-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255,255,255,0.02);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}
.perm-checkbox:hover {
    background: rgba(255,255,255,0.05);
}
.perm-checkbox input {
    accent-color: var(--primary);
    width: 1.1rem;
    height: 1.1rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        right: -280px;
        top: 0; bottom: 0;
        transition: right 0.3s ease;
        box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    }
    .sidebar.active {
        right: 0;
    }
    main {
        padding: 1rem;
    }
    .top-nav {
        margin-right: 0 !important;
    }
}

@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr !important;
    }
    .top-nav {
        padding: 0.5rem 1rem;
    }
    .brand h2 {
        font-size: 1.2rem;
    }
    .modal-content {
        width: 95%;
        margin: 10px;
        padding: 1rem;
    }
    .btn {
        width: 100%;
        justify-content: center;
    }
    .filters-bar {
        grid-template-columns: 1fr !important;
    }
}

/* Mobile Menu Toggle */
.menu-toggle {
    display: none;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 8px;
    border-radius: 8px;
    color: var(--text-main);
    cursor: pointer;
    margin-left: 1rem;
}

@media (max-width: 1024px) {
    .menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
}

.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.report-table {
    min-width: 1000px; /* Ensure table doesn't get too squashed */
}

.dashboard-card {
    min-width: 0;
}

@media print {
    .sidebar, .topbar, .welcome-section, .no-print, .menu-toggle, .btn, .nav-menu, .brand, .main-content > div:first-child {
        display: none !important;
    }
    
    #app {
        display: block !important;
        height: auto !important;
    }

    .main-wrapper {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        display: block !important;
    }
    
    .main-content {
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        display: block !important;
    }
    
    .table-container {
        border: none !important;
        box-shadow: none !important;
        overflow: visible !important;
        width: 100% !important;
    }
    
    table {
        width: 100% !important;
        border-collapse: collapse !important;
    }
    
    th, td {
        border: 1px solid #e2e8f0 !important;
        color: #000 !important;
        padding: 8px !important;
        font-size: 10pt !important;
    }
    
    th {
        background-color: #f8fafc !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    body {
        background: white !important;
        color: black !important;
    }

    #reportPrintArea {
        display: block !important;
        width: 100% !important;
    }
    
    #reportHeader {
        display: block !important;
        text-align: center;
        margin-bottom: 2rem;
    }

    #reportHeader h1 {
        color: #3b82f6 !important;
        margin: 0;
    }

    @page {
        size: A4 landscape;
        margin: 1cm;
    }
}
