/**
 * Core CSS - Styles du framework
 * @version 1.0.0
 */

/* =========================================
   Theme Variables (Custom)
   Bootstrap 5.3 gère automatiquement ses propres variables
   via data-bs-theme, on ajoute ici nos variables custom
   ========================================= */

/* Thème clair (défaut) */
:root,
[data-theme="light"] {
    /* Couleurs de surface custom */
    --app-surface: #ffffff;
    --app-surface-alt: #f8f9fa;
    --app-surface-hover: #e9ecef;

    /* Texte custom */
    --app-text: #212529;
    --app-text-muted: #6c757d;
    --app-text-light: #adb5bd;

    /* Bordures custom */
    --app-border: #dee2e6;
    --app-border-light: #e9ecef;

    /* Ombres */
    --app-shadow: rgba(0, 0, 0, 0.1);
    --app-shadow-lg: rgba(0, 0, 0, 0.15);

    /* Cards */
    --app-card-bg: #ffffff;
    --app-card-border: #e9ecef;
}

/* Thème sombre */
[data-theme="dark"] {
    /* Couleurs de surface custom */
    --app-surface: #1a1d21;
    --app-surface-alt: #212529;
    --app-surface-hover: #2b3035;

    /* Texte custom */
    --app-text: #e9ecef;
    --app-text-muted: #adb5bd;
    --app-text-light: #6c757d;

    /* Bordures custom */
    --app-border: #495057;
    --app-border-light: #343a40;

    /* Ombres */
    --app-shadow: rgba(0, 0, 0, 0.3);
    --app-shadow-lg: rgba(0, 0, 0, 0.5);

    /* Cards */
    --app-card-bg: #212529;
    --app-card-border: #343a40;
}

/* =========================================
   Reset & Base
   ========================================= */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    height: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    min-height: 100%;
    margin: 0;
    padding: 0;
    padding-bottom: 70px; /* Space for bottom menu */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* =========================================
   App Layout
   ========================================= */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-main {
    flex: 1;
    padding-bottom: 60px;
}

#main-content {
    min-height: 200px;
}

/* =========================================
   Bottom Navigation Menu
   ========================================= */
.app-menu {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bs-body-bg, #fff);
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.app-menu .nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 60px;
}

.app-menu .menu-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    color: var(--bs-secondary-color, #6c757d);
    text-decoration: none;
    font-size: 0.7rem;
    transition: color 0.2s;
}

.app-menu .menu-link i {
    font-size: 1.25rem;
    margin-bottom: 2px;
}

.app-menu .menu-link.active,
.app-menu .menu-link:hover {
    color: var(--bs-primary, #0d6efd);
}

/* =========================================
   Loading
   ========================================= */
.app-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bs-body-bg, #fff);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.app-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bs-border-color, #dee2e6);
    border-top-color: var(--bs-primary, #0d6efd);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* =========================================
   Page Transitions
   ========================================= */
#main-content {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* =========================================
   Debug Logs
   ========================================= */
.debug-toggle {
    position: fixed;
    bottom: 75px;
    right: 15px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.7);
    color: #0f0;
    font-size: 18px;
    cursor: pointer;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    opacity: 0.6;
}

.debug-toggle:hover {
    opacity: 1;
    transform: scale(1.1);
}

.debug-toggle.active {
    background: #0f0;
    color: #000;
    opacity: 1;
}

#logs {
    position: fixed;
    bottom: 70px;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.95);
    color: #0f0;
    font-family: monospace;
    font-size: 11px;
    padding: 8px;
    z-index: 1000;
    border-top: 1px solid #0f0;
}

#logs .log-debug { color: #888; }
#logs .log-info { color: #0f0; }
#logs .log-warn { color: #ff0; }
#logs .log-error { color: #f00; }

/* =========================================
   App Card (utilise les variables custom)
   ========================================= */
.app-card {
    background: var(--app-card-bg);
    border: 1px solid var(--app-card-border);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px var(--app-shadow);
}

.app-card-title {
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--app-text);
}

/* =========================================
   Theme Toggle Button
   ========================================= */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--app-border);
    background: var(--app-surface);
    color: var(--app-text);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background: var(--app-surface-hover);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}

/* Icône selon le thème */
[data-theme="light"] .theme-toggle .bi-moon-fill { display: inline; }
[data-theme="light"] .theme-toggle .bi-sun-fill { display: none; }
[data-theme="dark"] .theme-toggle .bi-moon-fill { display: none; }
[data-theme="dark"] .theme-toggle .bi-sun-fill { display: inline; }

/* =========================================
   Toast Container Adjustments
   ========================================= */
/* Ajuster les toasts pour ne pas couvrir le menu bottom */
.toast-container.bottom-0 {
    bottom: 80px !important; /* Menu height + spacing */
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .toast-container.bottom-0 {
        bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    }
}

/* =========================================
   iOS Modal/Offcanvas Scroll Fix
   ========================================= */
/* Empêche le scroll du body quand modal/offcanvas est ouvert */
body.modal-open,
body.offcanvas-open {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Fix pour iOS - empêche le scroll elastique */
.modal,
.offcanvas {
    -webkit-overflow-scrolling: touch;
}

.modal.show,
.offcanvas.show {
    -webkit-overflow-scrolling: touch;
}

/* Le contenu scrollable du modal/offcanvas doit avoir le scroll */
.modal-body,
.offcanvas-body {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
}

/* =========================================
   Utilities
   ========================================= */
.hidden { display: none !important; }
.invisible { visibility: hidden; }

/* =========================================
   PWA Install Button
   ========================================= */
.pwa-install-btn {
    position: fixed;
    bottom: 80px;
    right: 20px;
    display: none;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    z-index: 9999;
    transition: all 0.3s ease;
    animation: slideInUp 0.5s ease;
}

.pwa-install-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.pwa-install-btn:active {
    transform: translateY(0);
}

.pwa-install-btn i {
    font-size: 16px;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive */
@media (max-width: 576px) {
    .pwa-install-btn {
        bottom: 70px;
        right: 15px;
        font-size: 13px;
        padding: 10px 16px;
    }
}

/* Safe area for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    body {
        padding-bottom: calc(70px + env(safe-area-inset-bottom));
    }
}
