:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #ec4899;
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.75);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Cairo', 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background: #0b0f19;
    background-image:
        radial-gradient(circle at 0% 0%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 100% 100%, rgba(236, 72, 153, 0.1) 0%, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* Sidebar Layout Core */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border-left: 1px solid var(--glass-border);
    /* Separator on the left for RTL sidebar on right */
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1000;
    transition: all 0.3s ease;
}

[dir="rtl"] .sidebar {
    border-left: 1px solid var(--glass-border);
    border-right: none;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1500;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

.notif-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    /* Changed from right:0 for desktop RTL safety */
    right: auto;
    width: 320px;
    max-width: 90vw;
    z-index: 1000;
    margin-top: 1rem;
    overflow: hidden;
    animation: slideDown 0.3s ease;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.notif-dropdown.active {
    display: block !important;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Global Utilities */
.flex-responsive {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
}

.desktop-only {
    display: flex !important;
}

@media (max-width: 992px) {
    .flex-responsive {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1rem !important;
    }

    .desktop-only {
        display: none !important;
    }
}

.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.content-wrapper {
    padding: 1.5rem 2rem;
    width: 100%;
    flex: 1;
}

/* Mobile Header (Hidden on Desktop) */
.mobile-header {
    display: none;
    height: 60px;
    padding: 0 1.5rem;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 999;
}

/* Desktop Top Header */
.top-header {
    height: 70px;
    padding: 0 2rem;
    border-bottom: 1px solid var(--glass-border) !important;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    background: rgba(15, 23, 42, 0.3);
}

/* Navigation Menu */
.sidebar-logo {
    padding: 2rem 1.5rem;
    text-align: center;
}

.nav-menu {
    list-style: none;
    padding: 0 1rem;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    margin-bottom: 0.3rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.75rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 12px;
    transition: 0.2s;
    font-weight: 500;
    font-size: 0.95rem;
}

.nav-link:hover,
.nav-link.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary-color);
}

.nav-link.active {
    background: rgba(99, 102, 241, 0.15);
    font-weight: 700;
}

/* Glass Cards */
.glass {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: 20px;
    padding: 1.5rem;
}

/* Auth Pages */
.auth-container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    position: relative;
    z-index: 1;
}

.auth-card {
    width: 100%;
    margin: 0 auto;
    animation: fadeIn 0.5s ease;
}

.auth-card .btn {
    width: 100%;
    margin-top: 1rem;
}

.uofk-header {
    text-align: center;
    margin-bottom: 2rem;
}

.uofk-logo {
    width: 80px;
    margin-bottom: 1rem;
    filter: drop-shadow(0 0 10px rgba(99, 102, 241, 0.3));
}

.uofk-title {
    font-weight: 800;
    background: linear-gradient(135deg, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Form Controls */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: white;
    font-size: 0.95rem;
    transition: 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
    background: rgba(15, 23, 42, 0.8);
}

.form-control::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Buttons System */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.7rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    text-decoration: none;
    font-size: 0.95rem;
    white-space: nowrap;
    width: auto;
    /* Default is auto */
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.2);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--primary-color);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
}

.results-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}

.stat-card {
    position: relative;
    padding: 1.5rem;
    overflow: hidden;
}

.stat-val {
    font-size: 2rem;
    font-weight: 800;
    margin: 0.5rem 0;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
}

/* Chat UI - Modern Mobile App Feel */
.chat-window {
    background: #0b0f19 !important;
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 600px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    background-image: radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.05) 0%, transparent 100%);
}

.chat-body::-webkit-scrollbar {
    width: 4px;
}

.chat-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.message {
    max-width: 80%;
    margin-bottom: 0.2rem;
    position: relative;
    animation: bubbleIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes bubbleIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.user {
    align-self: flex-start;
}

.message.assistant {
    align-self: flex-end;
}

.message .bubble {
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.6;
    position: relative;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.user .bubble {
    background: var(--primary-color);
    color: white;
    border-bottom-left-radius: 4px;
    border-top-left-radius: 20px;
}

.assistant .bubble {
    background: #1e293b;
    color: #f1f5f9;
    border-bottom-right-radius: 4px;
    border-top-right-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-footer {
    padding: 1.2rem;
    background: #111827;
    border-top: 1px solid var(--glass-border);
}

.input-wrapper textarea {
    background: #0f172a !important;
    border: 1px solid var(--glass-border) !important;
    border-radius: 25px !important;
    padding: 12px 20px !important;
    color: white !important;
    font-size: 0.9rem !important;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    min-height: 45px;
}

/* Mobile Optimization (The App Feel) */
@media (max-width: 1024px) {
    .grid-4 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 992px) {
    .sidebar {
        position: fixed !important;
        right: -300px !important;
        left: auto !important;
        top: 0;
        z-index: 2000;
        height: 100vh;
        width: 280px;
        border-right: 1px solid var(--glass-border);
    }

    .sidebar.active {
        right: 0 !important;
    }

    .mobile-header {
        display: flex;
    }

    .top-header {
        display: none;
    }

    .content-wrapper {
        padding: 1rem;
    }

    .dashboard-grid,
    .results-layout {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 1.5rem !important;
    }

    .results-layout>div {
        width: 100% !important;
        min-width: 0 !important;
    }

    .sticky-filter {
        position: relative !important;
        flex-direction: column !important;
        align-items: stretch !important;
        margin: 0 0 1rem 0 !important;
        padding: 1.2rem !important;
        gap: 1rem !important;
    }

    .sticky-filter div {
        flex-direction: column !important;
        width: 100% !important;
        gap: 0.8rem !important;
    }

    .sticky-filter select {
        width: 100% !important;
    }

    .chat-layout {
        grid-template-columns: 1fr !important;
        height: auto !important;
        display: flex;
        flex-direction: column;
    }

    .sidebar-sticky {
        order: 2;
        position: relative !important;
        top: 0 !important;
        width: 100% !important;
        max-width: none !important;
    }

    .main-content {
        width: 100%;
        min-width: 0;
    }

    .app-container {
        display: block;
        /* Stack or just let main-content take over */
    }

    .chat-main-container {
        order: 1;
        width: 100%;
        margin-bottom: 1.5rem;
    }

    .chat-window {
        height: 500px;
    }

    /* Global fixes for admin pages grid layouts */
    .form-group.flex-responsive,
    form[style*="display: flex; gap: 1.5rem;"] {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1rem !important;
    }

    .form-group.flex-responsive div {
        flex: none !important;
        width: 100% !important;
    }

    .card.glass[style*="display: flex; gap: 2rem;"] {
        flex-direction: column !important;
        gap: 1rem !important;
    }

    /* Student Tasks Adjustments */
    .rank-badge {
        flex: 1;
        width: 100%;
        margin-bottom: 0.5rem;
    }

    div[style*="display: flex; gap: 1.5rem;"] {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    div[style*="justify-content: space-between; align-items: center;"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.8rem !important;
    }

    .notif-dropdown {
        left: auto !important;
        right: -50px !important;
        /* Move it slightly to the left on mobile since bell is on the right */
    }
}

@media (max-width: 600px) {
    .grid-4 {
        grid-template-columns: 1fr !important;
    }

    h1 {
        font-size: 1.6rem !important;
    }

    .stat-val {
        font-size: 1.6rem;
    }
}

/* RTL Adjustments */
[dir="rtl"] .user .bubble {
    border-bottom-right-radius: 4px;
    border-bottom-left-radius: 18px;
}

[dir="rtl"] .assistant .bubble {
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 18px;
}

/* Utility Classes */
.flex-responsive {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .flex-responsive {
        flex-direction: column;
        align-items: flex-start;
    }
}

.table-container {
    overflow-x: auto;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 15px;
    padding: 0.5rem;
}

.modern-table {
    width: 100%;
    min-width: 600px;
    border-collapse: separate;
    border-spacing: 0 0.5rem;
}