/**
 * Base Styles
 * - CSS Reset
 * - CSS Variables (Design Tokens)
 * - Typography
 * - Utility Classes
 */

/* ===== CSS Reset ===== */

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    /* System font stack - no external font loading (Firefox privacy-friendly) */
    /* Only use fonts that are guaranteed to be system fonts */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--color-text);
    background-color: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    overflow-y: scroll;
}

/* ===== CSS Variables (Design Tokens) ===== */

:root {
    /* Colors - Primary */
    --color-primary: #3b82f6;
    --color-primary-dark: #2563eb;
    --color-primary-light: #60a5fa;
    --color-primary-hover: #2563eb;

    /* Colors - Neutral */
    --color-text: #1f2937;
    --color-text-light: #6b7280;
    --color-text-lighter: #9ca3af;
    --color-bg: #ffffff;
    --color-bg-light: #f9fafb;
    --color-bg-dark: #f3f4f6;
    --color-border: #e5e7eb;
    --color-border-light: #f3f4f6;

    /* Colors - UI Components */
    --color-card-bg: #ffffff;
    --color-card-border: #e5e7eb;
    --color-card-hover: #f9fafb;
    --color-input-bg: #ffffff;
    --color-input-border: #d1d5db;
    --color-input-focus: #3b82f6;
    --color-navbar-bg: #ffffff;
    --color-navbar-border: #e5e7eb;
    --color-sidebar-bg: #f9fafb;
    --color-dropdown-bg: #ffffff;
    --color-dropdown-hover: #f3f4f6;
    --color-modal-bg: #ffffff;
    --color-modal-overlay: rgba(0, 0, 0, 0.5);

    /* Colors - Semantic */
    --color-success: #10b981;
    --color-success-light: #d1fae5;
    --color-error: #ef4444;
    --color-error-light: #fee2e2;
    --color-warning: #f59e0b;
    --color-warning-light: #fef3c7;
    --color-info: #3b82f6;
    --color-info-light: #dbeafe;

    /* Colors - Extended Palette */
    --color-purple: #a855f7;
    --color-pink: #ec4899;
    --color-indigo: #6366f1;

    /* Colors - Role-Based (Default: Teacher) */
    --color-role-primary: #0ea5e9;
    --color-role-primary-light: #38bdf8;
    --color-role-hover: #f0f9ff;
    --color-role-border: #0ea5e9;
    --color-role-bg-light: #f0f9ff;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;

    /* Z-Index */
    --z-dropdown: 1000;
    --z-modal: 2000;
    --z-toast: 3000;
}

/* ===== Dark Mode Theme ===== */

[data-theme="dark"] {
    /* Colors - Primary (brighter in dark mode for contrast) */
    --color-primary: #60a5fa;
    --color-primary-dark: #3b82f6;
    --color-primary-light: #93c5fd;
    --color-primary-hover: #3b82f6;

    /* Colors - Neutral */
    --color-text: #e5e7eb;
    --color-text-light: #d1d5db;
    --color-text-lighter: #9ca3af;
    --color-bg: #0f172a;
    --color-bg-light: #1e293b;
    --color-bg-dark: #334155;
    --color-border: #475569;
    --color-border-light: #64748b;

    /* Colors - UI Components (Blue theme: light blue cards on dark blue bg) */
    --color-card-bg: #1e3a8a;
    --color-card-border: #3b82f6;
    --color-card-hover: #1e40af;
    --color-input-bg: #1e293b;
    --color-input-border: #475569;
    --color-input-focus: #60a5fa;
    --color-navbar-bg: #1e293b;
    --color-navbar-border: #334155;
    --color-sidebar-bg: #1e293b;
    --color-dropdown-bg: #1e293b;
    --color-dropdown-hover: #334155;
    --color-modal-bg: #1e3a8a;
    --color-modal-overlay: rgba(0, 0, 0, 0.75);

    /* Colors - Semantic */
    --color-success: #34d399;
    --color-success-light: #064e3b;
    --color-error: #f87171;
    --color-error-light: #7f1d1d;
    --color-warning: #fbbf24;
    --color-warning-light: #78350f;
    --color-info: #60a5fa;
    --color-info-light: #1e3a8a;

    /* Colors - Extended Palette */
    --color-purple: #c084fc;
    --color-pink: #f472b6;
    --color-indigo: #818cf8;

    /* Colors - Role-Based (Default: Teacher in Dark Mode) */
    --color-role-primary: #38bdf8;
    --color-role-primary-light: #7dd3fc;
    --color-role-hover: #0c4a6e;
    --color-role-border: #38bdf8;
    --color-role-bg-light: #0c4a6e;

    /* Shadows (darker in dark mode) */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

/* ===== Typography ===== */

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
    color: var(--color-text);
}

h1 {
    font-size: 2.25rem;
    margin-bottom: var(--space-lg);
}

h2 {
    font-size: 1.875rem;
    margin-bottom: var(--space-md);
}

h3 {
    font-size: 1.5rem;
    margin-bottom: var(--space-md);
}

h4 {
    font-size: 1.25rem;
    margin-bottom: var(--space-sm);
}

h5 {
    font-size: 1.125rem;
    margin-bottom: var(--space-sm);
}

h6 {
    font-size: 1rem;
    margin-bottom: var(--space-sm);
}

p {
    margin-bottom: var(--space-md);
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-dark);
}

/* ===== Utility Classes ===== */

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-muted {
    color: var(--color-text-light);
}

.text-small {
    font-size: 0.875rem;
}

.text-large {
    font-size: 1.125rem;
}

.font-bold {
    font-weight: 600;
}

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-sm); }
.mt-2 { margin-top: var(--space-md); }
.mt-3 { margin-top: var(--space-lg); }
.mt-4 { margin-top: var(--space-xl); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-sm); }
.mb-2 { margin-bottom: var(--space-md); }
.mb-3 { margin-bottom: var(--space-lg); }
.mb-4 { margin-bottom: var(--space-xl); }

.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }

/* ===== Loading Screen ===== */

.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: var(--space-lg);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--color-bg-dark);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Scrollbar ===== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-lighter);
}

/* ===== Role-Based Theme Overrides ===== */

/* Teacher Role (Default - Cyan/Sky Blue) */
[data-user-role="teacher"] {
    --color-role-primary: #0ea5e9;
    --color-role-primary-light: #38bdf8;
    --color-role-hover: #f0f9ff;
    --color-role-border: #0ea5e9;
    --color-role-bg-light: #f0f9ff;
}

[data-theme="dark"][data-user-role="teacher"] {
    --color-role-primary: #38bdf8;
    --color-role-primary-light: #7dd3fc;
    --color-role-hover: #0c4a6e;
    --color-role-border: #38bdf8;
    --color-role-bg-light: #0c4a6e;
}

/* Admin Role (Purple/Violet) */
[data-user-role="admin"] {
    --color-role-primary: #a855f7;
    --color-role-primary-light: #c084fc;
    --color-role-hover: #faf5ff;
    --color-role-border: #a855f7;
    --color-role-bg-light: #faf5ff;
}

[data-theme="dark"][data-user-role="admin"] {
    --color-role-primary: #c084fc;
    --color-role-primary-light: #e9d5ff;
    --color-role-hover: #2e1065;
    --color-role-border: #c084fc;
    --color-role-bg-light: #2e1065;
}

/* Guest Role (Green/Emerald) */
[data-user-role="guest"] {
    --color-role-primary: #10b981;
    --color-role-primary-light: #34d399;
    --color-role-hover: #ecfdf5;
    --color-role-border: #10b981;
    --color-role-bg-light: #ecfdf5;
}

[data-theme="dark"][data-user-role="guest"] {
    --color-role-primary: #34d399;
    --color-role-primary-light: #6ee7b7;
    --color-role-hover: #064e3b;
    --color-role-border: #34d399;
    --color-role-bg-light: #064e3b;
}
