/**
 * ImunCar - Styles principaux
 */

:root {
    /* Couleurs principales */
    --color-primary: #2563eb;
    --color-primary-dark: #1e40af;
    --color-primary-light: #3b82f6;
    --color-success: #10b981;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;
    --color-info: #06b6d4;
    
    /* Couleurs de fond */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-dark: #1f2937;
    --bg-sidebar: #1f2937;
    --bg-header: #ffffff;
    
    /* Couleurs de texte */
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --text-white: #ffffff;
    
    /* Dimensions */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 80px;
    --header-height: 70px;
    
    /* Espacements */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    
    /* Ombres */
    --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);
    
    /* Transitions */
    --transition-fast: 0.15s ease-in-out;
    --transition-normal: 0.3s ease-in-out;
    --transition-slow: 0.5s ease-in-out;
}

/* Reset et base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    overflow-x: hidden;
}

/* Layout principal */
.wrapper {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
    transition: margin-left var(--transition-normal);
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--bg-sidebar);
    color: var(--text-white);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    transition: transform var(--transition-normal);
}

.sidebar-header {
    padding: var(--spacing-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--text-white);
}

.logo i {
    font-size: 1.5rem;
    color: var(--color-primary-light);
}

.btn-close-sidebar {
    color: var(--text-white);
    background: none;
    border: none;
    font-size: 1.25rem;
    padding: var(--spacing-xs);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md) 0;
}

.nav-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    margin: var(--spacing-xs) 0;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md) var(--spacing-lg);
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
}

.sidebar .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-white);
}

.sidebar .nav-link.active {
    background-color: rgba(37, 99, 235, 0.2);
    color: var(--text-white);
    border-left-color: var(--color-primary-light);
}

.sidebar .nav-link i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.nav-divider {
    height: 1px;
    background-color: rgba(255, 255, 255, 0.1);
    margin: var(--spacing-md) var(--spacing-lg);
}

.sidebar-footer {
    padding: var(--spacing-lg);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-form {
    margin: 0;
}

/* Sidebar Overlay (Mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.active {
    display: block;
}

/* Header */
.header {
    height: var(--header-height);
    background-color: var(--bg-header);
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-lg);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    flex: 1;
}

.header-center {
    flex: 1;
    max-width: 500px;
    margin: 0 var(--spacing-lg);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.vehicle-selector {
    min-width: 200px;
}

.search-box {
    position: relative;
}

.search-box i {
    position: absolute;
    left: var(--spacing-md);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-box input {
    padding-left: 2.5rem;
}

/* Notifications */
.notifications-dropdown .dropdown-menu {
    width: 350px;
    max-height: 500px;
    overflow-y: auto;
}

.notifications-list {
    max-height: 400px;
    overflow-y: auto;
}

.notification-item {
    display: flex;
    align-items: flex-start;
    padding: var(--spacing-md);
    border-bottom: 1px solid #e5e7eb;
    transition: background-color var(--transition-fast);
}

.notification-item:hover {
    background-color: var(--bg-secondary);
}

.notification-item.unread {
    background-color: #eff6ff;
}

.notification-content {
    flex: 1;
    min-width: 0;
}

.notification-title {
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: var(--spacing-xs);
}

.notification-message {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
}

.notification-time {
    font-size: 0.75rem;
    color: var(--text-light);
}

.notification-actions {
    margin-left: var(--spacing-sm);
}

/* User Dropdown */
.user-dropdown .user-avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--color-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-white);
    margin-right: var(--spacing-sm);
}

/* Content */
.content {
    flex: 1;
    min-width: 0;
    padding: var(--spacing-lg);
    overflow-y: auto;
}

.breadcrumb-nav {
    margin-bottom: var(--spacing-lg);
}

/* Footer */
.footer {
    padding: var(--spacing-lg);
    background-color: var(--bg-primary);
    border-top: 1px solid #e5e7eb;
    margin-top: auto;
}

/* ============================================
 * Bottom Navigation Mobile
 * ============================================ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-primary);
    border-top: 1px solid #e5e7eb;
    display: none;
    justify-content: space-around;
    align-items: center;
    z-index: 1050;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 8px;
    transition: color var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    background: none;
    border: none;
    cursor: pointer;
    min-width: 56px;
    min-height: 44px;
}

.bottom-nav-item i {
    font-size: 20px;
    line-height: 1;
}

.bottom-nav-item.active {
    color: var(--color-primary);
}

.bottom-nav-item:active {
    transform: scale(0.9);
}

.bottom-nav-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: var(--color-danger);
    color: white;
    font-size: 9px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    border-radius: 8px;
}

/* ============================================
 * Bottom Sheet (menu "Plus")
 * ============================================ */
.bottom-sheet-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1060;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.bottom-sheet-overlay.active {
    display: block;
    opacity: 1;
}

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-radius: 16px 16px 0 0;
    z-index: 1070;
    transform: translateY(100%);
    transition: transform var(--transition-normal) cubic-bezier(0.4, 0, 0.2, 1);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    max-height: 70vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.15);
}

.bottom-sheet.active {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #d1d5db;
    margin: 12px auto;
}

.bottom-sheet-nav {
    padding: 4px 8px 16px;
}

.bottom-sheet-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: 14px 16px;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 10px;
    transition: background-color var(--transition-fast);
    font-size: 0.95rem;
    min-height: 48px;
}

.bottom-sheet-item:hover,
.bottom-sheet-item:active {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.bottom-sheet-item i {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
    color: var(--text-secondary);
}

.bottom-sheet-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 8px 16px;
}

/* ============================================
 * Responsive — Tablette (< 992px)
 * ============================================ */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .header-center {
        display: none;
    }

    /* Bottom nav visible */
    .bottom-nav {
        display: flex;
    }

    /* Espace en bas pour la bottom nav */
    body {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    }

    /* Boutons minimum 44px (Apple HIG / WCAG) */
    .btn {
        min-height: 44px;
    }

    /* Tableaux responsive */
    .table-responsive-mobile {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ============================================
 * Responsive — Mobile (< 768px)
 * ============================================ */
@media (max-width: 767.98px) {
    .vehicle-selector {
        min-width: 150px;
    }

    .content {
        padding: var(--spacing-md);
        padding-left: max(var(--spacing-md), env(safe-area-inset-left));
        padding-right: max(var(--spacing-md), env(safe-area-inset-right));
    }

    /* Header compact mobile */
    .header {
        height: 56px;
        padding: 0 var(--spacing-md);
    }

    /* Stats en grille 2 colonnes */
    .stats-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stats-grid .card {
        margin-bottom: 0;
    }

    /* Cards en colonne unique */
    .row-cols-md-2 > *,
    .row-cols-md-3 > * {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Modals en bottom sheet sur mobile */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        transform: translateY(0);
    }

    .modal-content {
        border-radius: 16px 16px 0 0;
        border: none;
        max-height: 85vh;
        overflow-y: auto;
    }

    .modal.fade .modal-dialog {
        transform: translateY(100%);
        transition: transform var(--transition-normal) cubic-bezier(0.4, 0, 0.2, 1);
    }

    .modal.show .modal-dialog {
        transform: translateY(0);
    }

    /* Footer masqué sur mobile (bottom-nav le remplace) */
    .footer {
        display: none;
    }

    /* Notifications dropdown adapté mobile */
    .notifications-dropdown .dropdown-menu {
        width: calc(100vw - 20px);
        max-width: 400px;
        position: fixed !important;
        top: 56px !important;
        left: 10px !important;
        right: 10px !important;
        transform: none !important;
        border-radius: 0 0 12px 12px;
        z-index: 1060;
    }
}

/* ============================================
 * Responsive — Très petit écran (< 375px)
 * ============================================ */
@media (max-width: 375px) {
    body {
        font-size: 13px;
    }

    .bottom-nav-item span {
        font-size: 9px;
    }

    .bottom-nav-item {
        min-width: 48px;
        padding: 6px 8px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
 * Responsive — Paysage mobile
 * ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    .bottom-nav {
        height: 44px;
    }

    .bottom-nav-item span {
        display: none;
    }

    .bottom-nav-item i {
        font-size: 22px;
    }

    .header {
        height: 48px;
    }
}

/* ============================================
 * Animations & Micro-interactions
 * ============================================ */
@media (prefers-reduced-motion: no-preference) {
    .card {
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }

    .card:active {
        transform: scale(0.98);
    }

    .btn {
        transition: all 0.15s ease;
    }

    .btn:active {
        transform: scale(0.95);
    }

    /* Pulse animation pour badges alertes */
    @keyframes pulse-badge {
        0%, 100% { transform: scale(1); }
        50% { transform: scale(1.15); }
    }

    .bottom-nav-badge {
        animation: pulse-badge 2s infinite;
    }
}

/* Smooth scrolling global */
html {
    scroll-behavior: smooth;
}

/* Accessibilité — Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    .bottom-sheet,
    .sidebar,
    .bottom-nav-item {
        transition: none !important;
    }
}

/* Empêcher le overscroll bounce sur mobile */
body {
    overscroll-behavior-y: contain;
}

/* Tap highlight invisible */
a, button, input, select, textarea {
    -webkit-tap-highlight-color: transparent;
}

/* ============================================
 * Dark Mode (auto via prefers-color-scheme)
 * ============================================ */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a2e;
        --bg-secondary: #16213e;
        --bg-dark: #0f0f23;
        --bg-sidebar: #0f0f23;
        --bg-header: #1a1a2e;
        --text-primary: #e2e8f0;
        --text-secondary: #94a3b8;
        --text-light: #64748b;
        --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.4);
    }

    body {
        color-scheme: dark;
    }

    .bottom-nav {
        background: #1a1a2e;
        border-top-color: #2d3748;
    }

    .bottom-sheet {
        background: #1a1a2e;
    }

    .bottom-sheet-divider {
        background: #2d3748;
    }

    .bottom-sheet-item:hover,
    .bottom-sheet-item:active {
        background: #16213e;
    }

    .header {
        border-bottom-color: #2d3748;
    }

    .footer {
        border-top-color: #2d3748;
    }

    .notification-item:hover {
        background-color: #16213e;
    }

    .notification-item.unread {
        background-color: rgba(37, 99, 235, 0.15);
    }

    .alert-danger { background-color: rgba(239, 68, 68, 0.15); color: #fca5a5; border-color: rgba(239, 68, 68, 0.3); }
    .alert-success { background-color: rgba(16, 185, 129, 0.15); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.3); }

    .form-control, .form-select {
        background-color: #16213e;
        color: #e2e8f0;
        border-color: #2d3748;
    }

    .card {
        background-color: #1a1a2e;
        border-color: #2d3748;
    }

    .table {
        color: #e2e8f0;
    }

    .table > :not(caption) > * > * {
        background-color: transparent;
        border-bottom-color: #2d3748;
    }
}

/* ============================================
 * Utilitaires
 * ============================================ */
.text-primary { color: var(--color-primary) !important; }
.text-success { color: var(--color-success) !important; }
.text-danger { color: var(--color-danger) !important; }
.text-warning { color: var(--color-warning) !important; }

.bg-primary { background-color: var(--color-primary) !important; }
.bg-success { background-color: var(--color-success) !important; }
.bg-danger { background-color: var(--color-danger) !important; }
.bg-warning { background-color: var(--color-warning) !important; }
