/**
 * Material Design 3 Theme
 * Base styles and design tokens for the Auto-Grading System
 * Supports Light and Dark modes
 */

/* ===== LIGHT MODE (Default) ===== */
:root,
[data-theme="light"] {
    /* Custom Color Palette */
    --text: #08090c;
    --background: #fcfcfd;
    --primary: #6f77a5;
    --secondary: #c3b1ce;
    --accent: #af8ab7;
    
    /* Material Design Color Tokens - Mapped from custom palette */
    --md-sys-color-surface: #fcfcfd;
    --md-sys-color-on-surface: #08090c;
    --md-sys-color-surface-dim: #e8e8ea;
    --md-sys-color-surface-bright: #ffffff;
    --md-sys-color-primary: #6f77a5;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #d8daf0;
    --md-sys-color-on-primary-container: #2a2f4a;
    --md-sys-color-secondary: #c3b1ce;
    --md-sys-color-on-secondary: #1f1a22;
    --md-sys-color-secondary-container: #ebe4ef;
    --md-sys-color-on-secondary-container: #3d3542;
    --md-sys-color-tertiary: #af8ab7;
    --md-sys-color-on-tertiary: #ffffff;
    --md-sys-color-tertiary-container: #e8d8eb;
    --md-sys-color-on-tertiary-container: #402d44;
    --md-sys-color-surface-container: #ffffff;
    --md-sys-color-surface-container-low: #f8f8f9;
    --md-sys-color-surface-container-high: #f0f0f2;
    --md-sys-color-surface-container-highest: #e8e8ea;
    --md-sys-color-surface-variant: #f0f0f4;
    --md-sys-color-on-surface-variant: #4a4a52;
    --md-sys-color-outline: #c5c5cc;
    --md-sys-color-outline-variant: #dddde2;
    --md-sys-color-inverse-surface: #2d2d32;
    --md-sys-color-inverse-on-surface: #f3f4f7;
    --md-sys-color-inverse-primary: #a8aed0;
    
    /* Semantic Colors */
    --md-sys-color-error: #ba1a1a;
    --md-sys-color-on-error: #ffffff;
    --md-sys-color-error-container: #ffdad6;
    --md-sys-color-on-error-container: #410002;
    --md-sys-color-success: #1e8e3e;
    --md-sys-color-on-success: #ffffff;
    --md-sys-color-success-container: #d4f5dc;
    --md-sys-color-on-success-container: #0d3d16;
    --md-sys-color-warning: #ea8600;
    --md-sys-color-on-warning: #ffffff;
    --md-sys-color-warning-container: #fef3e0;
    --md-sys-color-on-warning-container: #3d2e00;
    --md-sys-color-info: #6f77a5;
    --md-sys-color-on-info: #ffffff;
    --md-sys-color-info-container: #d8daf0;
    --md-sys-color-on-info-container: #2a2f4a;
    
    /* Background Colors (semantic aliases) */
    --md-sys-color-error-background: var(--md-sys-color-error-container);
    --md-sys-color-success-background: var(--md-sys-color-success-container);
    --md-sys-color-warning-background: var(--md-sys-color-warning-container);
    --md-sys-color-info-background: var(--md-sys-color-info-container);
    
    /* Layout Dimensions */
    --nav-width: 256px;
    --top-bar-height: 64px;
    --progress-sidebar-width: 320px;
    --progress-sidebar-width-minimized: 60px;
    
    /* Border Radius */
    --md-sys-shape-corner-extra-small: 4px;
    --md-sys-shape-corner-small: 8px;
    --md-sys-shape-corner-medium: 12px;
    --md-sys-shape-corner-large: 16px;
    --md-sys-shape-corner-extra-large: 24px;
    
    /* Spacing Scale */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Elevation/Shadow */
    --elevation-1: 0 1px 3px rgba(0, 0, 0, 0.1);
    --elevation-2: 0 2px 6px rgba(0, 0, 0, 0.12);
    --elevation-3: 0 4px 12px rgba(0, 0, 0, 0.15);
    --elevation-4: 0 8px 24px rgba(0, 0, 0, 0.18);
    
    /* Hover States */
    --md-sys-state-hover-opacity: 0.08;
    --md-sys-state-focus-opacity: 0.12;
    --md-sys-state-pressed-opacity: 0.12;
    --hover-overlay: rgba(0, 0, 0, 0.05);
    --active-tint: #e8f0fe;
    
    /* Transition */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
    --transition-slow: 300ms ease;
    
    /* Scrollbar */
    --scrollbar-thumb: #c1c1c1;
    --scrollbar-track: transparent;
    
    /* Code / Pre */
    --code-background: #f5f5f5;
    --code-text: #333333;
}

/* ===== DARK MODE ===== */
[data-theme="dark"] {
    /* Custom Color Palette */
    --text: #f3f4f7;
    --background: #020203;
    --primary: #5a6290;
    --secondary: #43314e;
    --accent: #6d4875;
    
    /* Material Design Color Tokens - Dark Theme */
    --md-sys-color-surface: #0e0e10;
    --md-sys-color-on-surface: #f3f4f7;
    --md-sys-color-surface-dim: #020203;
    --md-sys-color-surface-bright: #2a2a2e;
    --md-sys-color-primary: #a8aed0;
    --md-sys-color-on-primary: #2a2f4a;
    --md-sys-color-primary-container: #454b6e;
    --md-sys-color-on-primary-container: #d8daf0;
    --md-sys-color-secondary: #d4c8dc;
    --md-sys-color-on-secondary: #2d2532;
    --md-sys-color-secondary-container: #43314e;
    --md-sys-color-on-secondary-container: #ebe4ef;
    --md-sys-color-tertiary: #d4b5da;
    --md-sys-color-on-tertiary: #402d44;
    --md-sys-color-tertiary-container: #6d4875;
    --md-sys-color-on-tertiary-container: #e8d8eb;
    --md-sys-color-surface-container: #1a1a1c;
    --md-sys-color-surface-container-low: #141416;
    --md-sys-color-surface-container-high: #222224;
    --md-sys-color-surface-container-highest: #2c2c2e;
    --md-sys-color-surface-variant: #2a2a30;
    --md-sys-color-on-surface-variant: #c8c8ce;
    --md-sys-color-outline: #5a5a62;
    --md-sys-color-outline-variant: #3a3a42;
    --md-sys-color-inverse-surface: #f3f4f7;
    --md-sys-color-inverse-on-surface: #2d2d32;
    --md-sys-color-inverse-primary: #5a6290;
    
    /* Semantic Colors - Dark */
    --md-sys-color-error: #ffb4ab;
    --md-sys-color-on-error: #690005;
    --md-sys-color-error-container: #93000a;
    --md-sys-color-on-error-container: #ffdad6;
    --md-sys-color-success: #81c995;
    --md-sys-color-on-success: #0d3d16;
    --md-sys-color-success-container: #0f5223;
    --md-sys-color-on-success-container: #c4eed0;
    --md-sys-color-warning: #fdd663;
    --md-sys-color-on-warning: #3d2e00;
    --md-sys-color-warning-container: #5c4500;
    --md-sys-color-on-warning-container: #ffdf9e;
    --md-sys-color-info: #a8aed0;
    --md-sys-color-on-info: #2a2f4a;
    --md-sys-color-info-container: #454b6e;
    --md-sys-color-on-info-container: #d8daf0;
    
    /* Background Colors (semantic aliases) */
    --md-sys-color-error-background: rgba(255, 180, 171, 0.15);
    --md-sys-color-success-background: rgba(129, 201, 149, 0.15);
    --md-sys-color-warning-background: rgba(253, 214, 99, 0.15);
    --md-sys-color-info-background: rgba(168, 174, 208, 0.15);
    
    /* Elevation/Shadow - Dark (lighter shadows) */
    --elevation-1: 0 1px 3px rgba(0, 0, 0, 0.3);
    --elevation-2: 0 2px 6px rgba(0, 0, 0, 0.35);
    --elevation-3: 0 4px 12px rgba(0, 0, 0, 0.4);
    --elevation-4: 0 8px 24px rgba(0, 0, 0, 0.45);
    
    /* Hover States - Dark */
    --hover-overlay: rgba(255, 255, 255, 0.08);
    --active-tint: rgba(168, 199, 250, 0.2);
    
    /* Scrollbar - Dark */
    --scrollbar-thumb: #5f6368;
    --scrollbar-track: transparent;
    
    /* Code / Pre - Dark */
    --code-background: #2d2d2d;
    --code-text: #e8e8e8;
}

/* ===== AUTO THEME (System Preference) ===== */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        /* Apply dark theme when no explicit preference is set and system prefers dark */
        /* Custom Color Palette */
        --text: #f3f4f7;
        --background: #020203;
        --primary: #5a6290;
        --secondary: #43314e;
        --accent: #6d4875;
        
        --md-sys-color-surface: #0e0e10;
        --md-sys-color-on-surface: #f3f4f7;
        --md-sys-color-surface-dim: #020203;
        --md-sys-color-surface-bright: #2a2a2e;
        --md-sys-color-primary: #a8aed0;
        --md-sys-color-on-primary: #2a2f4a;
        --md-sys-color-primary-container: #454b6e;
        --md-sys-color-on-primary-container: #d8daf0;
        --md-sys-color-secondary: #d4c8dc;
        --md-sys-color-on-secondary: #2d2532;
        --md-sys-color-secondary-container: #43314e;
        --md-sys-color-on-secondary-container: #ebe4ef;
        --md-sys-color-tertiary: #d4b5da;
        --md-sys-color-on-tertiary: #402d44;
        --md-sys-color-tertiary-container: #6d4875;
        --md-sys-color-on-tertiary-container: #e8d8eb;
        --md-sys-color-surface-container: #1a1a1c;
        --md-sys-color-surface-container-low: #141416;
        --md-sys-color-surface-container-high: #222224;
        --md-sys-color-surface-container-highest: #2c2c2e;
        --md-sys-color-surface-variant: #2a2a30;
        --md-sys-color-on-surface-variant: #c8c8ce;
        --md-sys-color-outline: #5a5a62;
        --md-sys-color-outline-variant: #3a3a42;
        --md-sys-color-inverse-surface: #f3f4f7;
        --md-sys-color-inverse-on-surface: #2d2d32;
        --md-sys-color-inverse-primary: #5a6290;
        --md-sys-color-error: #ffb4ab;
        --md-sys-color-on-error: #690005;
        --md-sys-color-error-container: #93000a;
        --md-sys-color-on-error-container: #ffdad6;
        --md-sys-color-success: #81c995;
        --md-sys-color-on-success: #0d3d16;
        --md-sys-color-success-container: #0f5223;
        --md-sys-color-on-success-container: #c4eed0;
        --md-sys-color-warning: #fdd663;
        --md-sys-color-on-warning: #3d2e00;
        --md-sys-color-warning-container: #5c4500;
        --md-sys-color-on-warning-container: #ffdf9e;
        --md-sys-color-info: #a8aed0;
        --md-sys-color-on-info: #2a2f4a;
        --md-sys-color-info-container: #454b6e;
        --md-sys-color-on-info-container: #d8daf0;
        --md-sys-color-error-background: rgba(255, 180, 171, 0.15);
        --md-sys-color-success-background: rgba(129, 201, 149, 0.15);
        --md-sys-color-warning-background: rgba(253, 214, 99, 0.15);
        --md-sys-color-info-background: rgba(168, 174, 208, 0.15);
        --elevation-1: 0 1px 3px rgba(0, 0, 0, 0.3);
        --elevation-2: 0 2px 6px rgba(0, 0, 0, 0.35);
        --elevation-3: 0 4px 12px rgba(0, 0, 0, 0.4);
        --elevation-4: 0 8px 24px rgba(0, 0, 0, 0.45);
        --hover-overlay: rgba(255, 255, 255, 0.08);
        --active-tint: rgba(90, 98, 144, 0.2);
        --scrollbar-thumb: #5a5a62;
        --scrollbar-track: transparent;
        --code-background: #1a1a1c;
        --code-text: #f3f4f7;
    }
}

/* Base Body Styles */
body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    margin: 0;
    padding: 0;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Scrollbar Styling ===== */
/* Webkit browsers (Chrome, Safari, Edge) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: 4px;
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--md-sys-color-outline);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* Layout Container */
body.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Typography Helpers */
h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
    font-weight: 500;
}

/* Alert Components */
.alert {
    padding: var(--spacing-md);
    border-radius: var(--md-sys-shape-corner-small);
    margin-bottom: var(--spacing-md);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.alert-success {
    background-color: var(--md-sys-color-success-background);
    color: var(--md-sys-color-success);
}

.alert-error {
    background-color: var(--md-sys-color-error-background);
    color: var(--md-sys-color-error);
}

.alert-warning {
    background-color: var(--md-sys-color-warning-background);
    color: var(--md-sys-color-warning);
}

.alert-info {
    background-color: var(--md-sys-color-info-background);
    color: var(--md-sys-color-info);
}

/* Card Component */
.md-card {
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-medium);
    padding: var(--spacing-lg);
    box-shadow: var(--elevation-1);
}

.md-card:hover {
    box-shadow: var(--elevation-2);
    transition: box-shadow 0.2s ease;
}

/* Material Web Button Icon Fixes */
md-filled-button md-icon[slot="icon"],
md-outlined-button md-icon[slot="icon"],
md-text-button md-icon[slot="icon"],
md-filled-tonal-button md-icon[slot="icon"] {
    margin: 0;
    padding: 0;
    --md-icon-size: 18px;
    font-size: 18px;
}

/* Utility Classes */
.flex-spacer {
    flex: 1;
}

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

.mb-0 { margin-bottom: 0; }
.mb-xs { margin-bottom: var(--spacing-xs); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }
.mb-xl { margin-bottom: var(--spacing-xl); }

.mt-0 { margin-top: 0; }
.mt-xs { margin-top: var(--spacing-xs); }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mt-xl { margin-top: var(--spacing-xl); }

/* Mobile Responsive Breakpoints */
@media (max-width: 768px) {
    :root {
        --nav-width: 100%;
        --top-bar-height: 56px;
    }
}

@media (max-width: 480px) {
    :root {
        --spacing-md: 12px;
        --spacing-lg: 16px;
    }
}

