/* Global Resets & Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --color-slate-900: #0f172a;
    --color-slate-800: #1e293b;
    --color-slate-700: #334155;
    --color-slate-600: #475569;
    --color-primary: #2563eb;
    --color-text-main: #f1f5f9;
    --color-text-muted: #94a3b8;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--color-slate-900);
    color: var(--color-text-main);
    margin: 0;
    padding: 0;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--color-slate-900);
}
::-webkit-scrollbar-thumb {
    background: var(--color-slate-700);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--color-slate-600);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.animate-up {
    animation: fadeIn 0.4s ease-out forwards;
}

/* Dashboard Layout */
.dashboard-layout {
    display: flex;
    height: 100vh;
    height: 100dvh; /* Mobile: avoid the 100vh address-bar bug */
    overflow: hidden;
    background-color: var(--color-slate-900);
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--color-slate-800);
    border-right: 1px solid var(--color-slate-700);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease-in-out, width 0.18s ease-in-out;
    z-index: 60;
}

/* Sidebar UX polish (V4) */
.sidebar .sidebar-nav {
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.25) transparent;
}
.sidebar .sidebar-nav::-webkit-scrollbar {
    width: 10px;
}
.sidebar .sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.22);
    border-radius: 9999px;
    border: 2px solid rgba(15, 23, 42, 0.0);
}
.sidebar .sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar .sidebar-link.is-active {
    background: rgba(59, 130, 246, 0.14) !important;
    border-color: rgba(59, 130, 246, 0.28) !important;
    color: #ffffff !important;
}
.sidebar .sidebar-link.is-active i {
    color: rgba(147, 197, 253, 1) !important; /* blue-200/300 */
}

/* Optional collapsed sidebar (desktop only) */
@media (min-width: 1024px) {
    .sidebar.is-collapsed {
        width: 88px;
    }
    .sidebar.is-collapsed .sidebar-brand-text,
    .sidebar.is-collapsed .sidebar-label,
    .sidebar.is-collapsed .sidebar-heading,
    .sidebar.is-collapsed .sidebar-badge {
        display: none !important;
    }
    .sidebar.is-collapsed .sidebar-sublink {
        display: none !important;
    }
    .sidebar.is-collapsed .sidebar-link {
        justify-content: center !important;
        gap: 0 !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
    .sidebar.is-collapsed .sidebar-link i {
        width: auto !important;
    }
}

/* Topbar */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background-color: var(--color-slate-900);
}

.top-bar {
    height: 64px;
    background-color: var(--color-slate-800);
    border-bottom: 1px solid var(--color-slate-700);
    display: flex;
    align-items: center;
    padding: 0 24px;
    flex-shrink: 0;
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    -webkit-overflow-scrolling: touch;
}

/* Responsive Sidebar */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        height: 100%;
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    
    /* Content Padding adjustments for mobile */
    .content-area {
        padding: 16px;
    }
    .top-bar {
        padding: 0 16px;
    }
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
    backdrop-filter: blur(2px);
}

/* Mobile performance: reduce expensive backdrop blur on the fixed topbar.
   This also removes the "extra blurry band" some mobile browsers show under the header. */
@media (max-width: 640px) {
    .v4-topbar {
        /* Mobile browsers sometimes render backdrop-filter as a "blurry band".
           Disable blur on small screens for a cleaner look + smoother scroll. */
        background: linear-gradient(
            180deg,
            rgba(15, 23, 42, 0.88) 0%,
            rgba(15, 23, 42, 0.62) 100%
        ) !important;
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
        box-shadow: none !important;
    }
}


/* Prevent background scroll when the mobile sidebar is open */
@media (max-width: 1024px) {
    html.v4-sidebar-open,
    body.v4-sidebar-open {
        overflow: hidden;
    }
    html.v4-sidebar-open .content-area {
        overflow: hidden;
    }
}

/* On mobile, full-screen teacher tools (create/import/ai) should own the top area.
   Hide the global header strip so it cannot overlap the editor save bar on iPhone Safari. */
@media (max-width: 1024px) {
    body.teacher-overlay-view #v4-header,
    body.teacher-overlay-view #plan-limit-strip {
        display: none !important;
    }
}

/* Utility Classes for Cards */
.dashboard-card {
    background: var(--color-slate-800);
    border-radius: 12px;
    border: 1px solid var(--color-slate-700);
    padding: 20px;
    transition: all 0.2s;
    color: #f8fafc;
}
.dashboard-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    border-color: var(--color-slate-600);
}

/* Category Card Styling (Matches App.js logic class) */
.category-card {
    background: var(--color-slate-800);
    border: 1px solid var(--color-slate-700);
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.category-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.1);
    transform: translateY(-2px);
    background: var(--color-slate-800);
}
.category-card i {
    font-size: 2rem;
    color: #3b82f6;
    background: rgba(59, 130, 246, 0.1); /* Blue 500/10 */
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    margin-bottom: 8px;
}
.category-card h3 {
    font-weight: 600;
    color: #f8fafc; /* Slate 50 */
    margin: 0;
}
.category-card p {
    color: #94a3b8; /* Slate 400 */
    font-size: 0.875rem;
    margin: 0;
}

/* Special Exam Card Override */
#special-exams-grid .category-card {
    background: linear-gradient(145deg, #1e293b, #0f172a);
    border: 1px solid rgba(251, 191, 36, 0.2);
    border-top: 4px solid #fbbf24;
    color: white;
}
#special-exams-grid .category-card:hover {
    box-shadow: 0 10px 15px -3px rgba(251, 191, 36, 0.1);
}
#special-exams-grid .category-card i {
    background: rgba(251, 191, 36, 0.1);
    color: #fbbf24;
}
#special-exams-grid .category-card h3 {
    color: #fbbf24;
}
#special-exams-grid .category-card p {
    color: #94a3b8;
}

/* Glassmorphism Utilities */
.glass {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Form Elements */
input, select, textarea {
    background-color: var(--color-slate-900);
    color: white;
    border-color: var(--color-slate-700);
}
input:focus, select:focus, textarea:focus {
    border-color: var(--color-primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

/* -------------------------------------------------------------------------- */
/* Tailwind Light-UI Overrides (Dashboard Pages)                               */
/*                                                                            */
/* Several pages (teacher/index/account/etc.) use Tailwind utility classes like */
/* bg-white/bg-gray-50/text-gray-900 that conflict with the site's dark theme */
/* defined above. These overrides keep the layout/spacing from Tailwind while */
/* forcing the dark palette inside the dashboard shell.                        */
/* -------------------------------------------------------------------------- */

.dashboard-layout .bg-white { background-color: var(--color-slate-800) !important; }
.dashboard-layout .bg-gray-50 { background-color: var(--color-slate-900) !important; }
.dashboard-layout .bg-gray-100 { background-color: var(--color-slate-700) !important; }
.dashboard-layout .bg-gray-200 { background-color: var(--color-slate-700) !important; }

.dashboard-layout .text-gray-900,
.dashboard-layout .text-gray-800,
.dashboard-layout .text-gray-700 { color: var(--color-text-main) !important; }

.dashboard-layout .text-gray-600,
.dashboard-layout .text-gray-500,
.dashboard-layout .text-gray-400 { color: var(--color-text-muted) !important; }

.dashboard-layout .border-gray-300,
.dashboard-layout .border-gray-200,
.dashboard-layout .border-gray-100 { border-color: var(--color-slate-700) !important; }

.dashboard-layout .divide-gray-200 > :not([hidden]) ~ :not([hidden]),
.dashboard-layout .divide-gray-100 > :not([hidden]) ~ :not([hidden]) {
    border-color: var(--color-slate-700) !important;
}

.dashboard-layout .placeholder-gray-500::placeholder,
.dashboard-layout .placeholder-gray-400::placeholder {
    color: rgba(148, 163, 184, 0.85) !important;
}

/* Form elements inside dashboard pages should always be dark (Tailwind may set bg-white). */
.dashboard-layout input,
.dashboard-layout select,
.dashboard-layout textarea {
    background-color: var(--color-slate-900) !important;
    color: var(--color-text-main) !important;
    border-color: var(--color-slate-700) !important;
}

/* Plan/limit strip: ensure it matches dark theme even if Tailwind sets a light gradient. */
#plan-limit-strip {
    background: linear-gradient(90deg, rgba(30, 41, 59, 0.92), rgba(15, 23, 42, 0.92)) !important;
    border-bottom-color: var(--color-slate-700) !important;
}
#plan-limit-strip .w-px { background-color: var(--color-slate-700) !important; }

/* Teacher: Create Quiz method selector (Manual vs AI) */
.dashboard-layout #create-private-quiz-section .tab-btn {
    background: rgba(15, 23, 42, 0.35) !important; /* slate-900/35 */
    border: 1px solid rgba(51, 65, 85, 0.9) !important; /* slate-700 */
    color: var(--color-text-muted) !important;
}
.dashboard-layout #create-private-quiz-section .tab-btn:hover {
    background: rgba(51, 65, 85, 0.55) !important; /* slate-700/55 */
    color: var(--color-text-main) !important;
}
.dashboard-layout #create-private-quiz-section .tab-btn.active {
    background: rgba(37, 99, 235, 0.22) !important; /* primary/22 */
    border-color: rgba(37, 99, 235, 0.45) !important;
    color: #ffffff !important;
    box-shadow: 0 10px 22px -16px rgba(37, 99, 235, 0.55);
}
.dashboard-layout #create-private-quiz-section .tab-btn.active i {
    color: rgba(147, 197, 253, 1) !important; /* blue-200 */
}
