/* ============================================
   Code de la Route — Core Styles
   Warm, calm, supportive design system
   ============================================ */

:root {
    /* Primary palette */
    --primary: #2E5984;
    --primary-light: #4A7FB5;
    --primary-dark: #1B3A5C;
    --primary-50: rgba(46, 89, 132, 0.08);
    --primary-100: rgba(46, 89, 132, 0.15);

    /* Accent */
    --accent: #F5A623;
    --accent-light: #FFCB6B;
    --accent-dark: #E09000;

    /* Feedback */
    --success: #4CAF50;
    --success-light: #E8F5E9;
    --success-dark: #2E7D32;
    --error: #E57373;
    --error-light: #FFEBEE;
    --error-dark: #C62828;
    --warning: #FF9800;
    --warning-light: #FFF3E0;
    --warning-dark: #F57F17;
    --info: #1976D2;
    --info-light: #E3F2FD;
    --info-dark: #1565C0;
    --missed: #FF9800;

    /* Neutrals */
    --bg: #F8F9FA;
    --surface: #FFFFFF;
    --surface-elevated: #FFFFFF;
    --border: #E8EBF0;
    --border-light: #F0F2F5;
    --text-primary: #212121;
    --text-secondary: #757575;
    --text-tertiary: #BDBDBD;
    --text-on-primary: #FFFFFF;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-xxl: 48px;

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 50%;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

    /* Typography */
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-size-xs: 11px;
    --font-size-sm: 13px;
    --font-size-base: 15px;
    --font-size-md: 17px;
    --font-size-lg: 20px;
    --font-size-xl: 24px;
    --font-size-xxl: 32px;
    --font-size-hero: 48px;

    /* Layout */
    --nav-height: 64px;
    --header-height: 56px;
    --max-width: 480px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* === DARK MODE === */
[data-theme="dark"] {
    --primary: #5B9BD5;
    --primary-light: #7BB3E0;
    --primary-dark: #3A7BC8;
    --primary-50: rgba(91, 155, 213, 0.12);
    --primary-100: rgba(91, 155, 213, 0.2);

    --accent: #F5A623;
    --accent-light: #3D3020;
    --accent-dark: #FFCB6B;

    --success: #66BB6A;
    --success-light: #1B3A1B;
    --success-dark: #81C784;
    --error: #EF5350;
    --error-light: #3A1B1B;
    --error-dark: #FF8A80;
    --warning: #FFA726;
    --warning-light: #3A2D1B;
    --warning-dark: #FFB74D;
    --info: #42A5F5;
    --info-light: #1B2A3A;
    --info-dark: #64B5F6;

    --bg: #121212;
    --surface: #1E1E1E;
    --surface-elevated: #2A2A2A;
    --border: #333333;
    --border-light: #2A2A2A;
    --text-primary: #E0E0E0;
    --text-secondary: #9E9E9E;
    --text-tertiary: #616161;
    --text-on-primary: #FFFFFF;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

/* Auto-detect system preference when no manual override */
@media (prefers-color-scheme: dark) {
    [data-theme="auto"] {
        --primary: #5B9BD5;
        --primary-light: #7BB3E0;
        --primary-dark: #3A7BC8;
        --primary-50: rgba(91, 155, 213, 0.12);
        --primary-100: rgba(91, 155, 213, 0.2);

        --accent: #F5A623;
        --accent-light: #3D3020;
        --accent-dark: #FFCB6B;

        --success: #66BB6A;
        --success-light: #1B3A1B;
        --success-dark: #81C784;
        --error: #EF5350;
        --error-light: #3A1B1B;
        --error-dark: #FF8A80;
        --warning: #FFA726;
        --warning-light: #3A2D1B;
        --warning-dark: #FFB74D;
        --info: #42A5F5;
        --info-light: #1B2A3A;
        --info-dark: #64B5F6;

        --bg: #121212;
        --surface: #1E1E1E;
        --surface-elevated: #2A2A2A;
        --border: #333333;
        --border-light: #2A2A2A;
        --text-primary: #E0E0E0;
        --text-secondary: #9E9E9E;
        --text-tertiary: #616161;
        --text-on-primary: #FFFFFF;

        --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
        --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
        --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
    }
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    font-size: var(--font-size-base);
    color: var(--text-primary);
    background: var(--bg);
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    height: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    position: relative;
    background: var(--bg);
}

/* Screens */
.screen {
    display: none;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* Splash Screen */
#splash-screen {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    justify-content: center;
    align-items: center;
    color: var(--text-on-primary);
    z-index: 100;
}

.splash-content {
    text-align: center;
    animation: fadeInUp 0.6s ease;
}

.splash-icon {
    font-size: 72px;
    margin-bottom: var(--space-lg);
    animation: carDrive 2s ease-in-out infinite;
}

.splash-content h1 {
    font-size: var(--font-size-xl);
    font-weight: 700;
    margin-bottom: var(--space-sm);
}

.splash-subtitle {
    font-size: var(--font-size-base);
    opacity: 0.8;
    margin-bottom: var(--space-xl);
}

.splash-loader {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

/* Onboarding */
#onboarding-screen {
    background: var(--surface);
    flex-direction: column;
}

.onboarding-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: var(--space-xl);
    padding-top: 60px;
}

.onboarding-pages {
    flex: 1;
    position: relative;
}

.onboarding-page {
    display: none;
    text-align: center;
    animation: fadeInUp 0.4s ease;
}

.onboarding-page.active {
    display: block;
}

.onboarding-illustration {
    font-size: 80px;
    margin-bottom: var(--space-xl);
}

.onboarding-page h2 {
    font-size: var(--font-size-xl);
    color: var(--primary);
    margin-bottom: var(--space-md);
}

.onboarding-page p {
    font-size: var(--font-size-md);
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: var(--space-md);
}

.onboarding-detail {
    font-size: var(--font-size-sm) !important;
    color: var(--text-tertiary) !important;
}

.onboarding-love {
    margin-top: var(--space-xl);
    font-size: var(--font-size-md) !important;
    color: var(--accent-dark) !important;
    font-style: italic;
    font-weight: 500;
}

.onboarding-dots {
    display: flex;
    justify-content: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    transition: all 0.3s ease;
}

.dot.active {
    background: var(--primary);
    width: 24px;
    border-radius: 4px;
}

.onboarding-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding-bottom: var(--space-xl);
}

/* Main App */
#main-app {
    flex-direction: column;
}

/* Header */
#app-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-md);
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    z-index: 10;
}

#header-title {
    font-size: var(--font-size-md);
    font-weight: 700;
    color: var(--primary);
}

/* Content Area */
#content-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

.view {
    display: none;
    padding: var(--space-md);
    padding-bottom: calc(var(--space-xl) + var(--safe-bottom));
    min-height: 100%;
}

.view.active {
    display: block;
}

/* Bottom Navigation */
#bottom-nav {
    display: flex;
    height: var(--nav-height);
    padding-bottom: var(--safe-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
    z-index: 10;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-tertiary);
    font-size: var(--font-size-xs);
    transition: color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.nav-item.active {
    color: var(--primary);
}

.nav-icon {
    font-size: 22px;
    line-height: 1;
}

.nav-label {
    font-weight: 500;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-base);
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
    gap: var(--space-sm);
    flex-direction: column;
}

.btn-primary {
    background: var(--primary);
    color: var(--text-on-primary);
}

.btn-primary:hover { background: var(--primary-light); }
.btn-primary:active { background: var(--primary-dark); transform: scale(0.98); }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-outline:hover { background: var(--primary-50); }

.btn-text {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}

.btn-text:hover { color: var(--primary); }

.btn-lg {
    padding: 14px 28px;
    font-size: var(--font-size-md);
    border-radius: var(--radius-md);
    width: 100%;
}

.btn-sm { padding: 6px 12px; font-size: var(--font-size-sm); }

.btn-detail {
    font-size: var(--font-size-xs);
    font-weight: 400;
    opacity: 0.8;
}

.btn-danger { color: var(--error-dark); border-color: var(--error); }

/* Section Titles */
.section-title {
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin: var(--space-lg) 0 var(--space-sm);
    font-weight: 600;
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 14px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: var(--shadow-sm);
}

.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Utility */
.hidden { display: none !important; }
.text-secondary { color: var(--text-secondary); }
.text-center { text-align: center; }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-md);
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    max-width: 360px;
    width: 100%;
    animation: fadeInUp 0.3s ease;
}

/* Toast */
#toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    max-width: var(--max-width);
    width: calc(100% - 32px);
}

.toast {
    background: var(--text-primary);
    color: var(--bg);
    padding: 12px var(--space-md);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    animation: fadeInDown 0.3s ease, fadeOut 0.3s ease 2.7s;
    box-shadow: var(--shadow-lg);
}

.toast.success { background: var(--success-dark); }
.toast.error { background: var(--error-dark); }

/* Empty state */
.empty-state {
    text-align: center;
    color: var(--text-tertiary);
    padding: var(--space-xl);
    font-size: var(--font-size-sm);
}

/* Scrollbar */
::-webkit-scrollbar { width: 0; }
