/**
 * PWA Navigation Bar
 * Barre de navigation flottante pour PWA et navigation mobile
 * 
 * Fonctionnalités :
 * - Bouton Retour (toujours visible)
 * - Bouton Scroll to Top (apparaît après scroll)
 * - Navigation intra-page pour recettes (sections)
 * 
 * @version 1.1.0
 * @date 2025-11-29
 * @author Savoor.fr
 */

/* ============================================
   VARIABLES
============================================ */
:root {
    --pwa-nav-height: 70px;
    --pwa-nav-btn-size: 60px;
    --pwa-nav-bg: transparent;
    --pwa-nav-bg-light: transparent;
    --pwa-nav-border: transparent;
    --pwa-nav-border-light: transparent;
    --pwa-nav-shadow: none;
    --pwa-nav-btn-hover: rgba(255, 255, 255, 0.1);
    --pwa-nav-btn-hover-light: rgba(0, 0, 0, 0.05);
    --pwa-nav-text: #ffffff;
    --pwa-nav-text-light: #333333;
    --pwa-nav-accent: #ff6b6b;
    --pwa-nav-z-index: 999999;
    --pwa-safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --pwa-viewport-offset: 0px;
}

/* ============================================
   BARRE DE NAVIGATION PRINCIPALE
============================================ */
.pwa-nav-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--pwa-nav-height) + var(--pwa-safe-area-bottom));
    padding-bottom: var(--pwa-safe-area-bottom);
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-top: none;
    box-shadow: none;
    z-index: var(--pwa-nav-z-index);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-left: 24px;
    padding-right: 24px;
    transform: translateY(0);
    transition: transform 0.3s ease;
    pointer-events: none;
}

/* Mode clair */
.light-mode .pwa-nav-bar {
    background: transparent;
    border-top-color: transparent;
}

/* État masqué (au scroll down ou lightbox ouverte) */
.pwa-nav-bar.hidden {
    transform: translateY(100%);
    pointer-events: none;
}

.pwa-nav-bar.hidden .pwa-nav-btn {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* État semi-transparent au scroll - DÉSACTIVÉ (barre invisible) */
/*
.pwa-nav-bar.scrolling {
    opacity: 0.7;
}

.pwa-nav-bar.scrolling:hover {
    opacity: 1;
}
*/

/* ============================================
   BOUTONS DE NAVIGATION
============================================ */
.pwa-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--pwa-nav-btn-size);
    height: var(--pwa-nav-btn-size);
    border: none;
    border-radius: 50%;
    background: #FF6B6B;
    color: white;
    cursor: pointer;
    transition: transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    pointer-events: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    z-index: 99999;
}

.pwa-nav-btn:hover,
.pwa-nav-btn:focus,
.pwa-nav-btn:active {
    background: #FF6B6B;
    color: white;
    outline: none;
}

.pwa-nav-btn:active {
    transform: scale(0.95);
}

/* Mode clair */
.light-mode .pwa-nav-btn,
.light-mode .pwa-nav-btn:hover,
.light-mode .pwa-nav-btn:focus,
.light-mode .pwa-nav-btn:active {
    background: #FF6B6B;
    color: white;
    outline: none;
}

/* Icônes des boutons */
.pwa-nav-btn i {
    font-size: 1.4rem;
}

/* Bouton avec label */
.pwa-nav-btn.with-label {
    width: auto;
    padding: 0 16px;
    gap: 8px;
}

.pwa-nav-btn .btn-label {
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

/* ============================================
   BOUTON RETOUR (à gauche)
============================================ */
.pwa-nav-back {
    order: 1;
    position: absolute;
    left: 40px;
    bottom: calc(20px + var(--pwa-viewport-offset));
}

/* ============================================
   BOUTON SCROLL TO TOP (à droite)
============================================ */
.pwa-nav-top {
    order: 3;
    position: absolute;
    right: 40px;
    bottom: calc(20px + var(--pwa-viewport-offset));
    opacity: 0;
    visibility: hidden;
    transform: scale(0);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}

.pwa-nav-top.visible {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0s;
}

/* ============================================
   BOUTON SECTIONS (NAVIGATION INTRA-PAGE - au centre)
============================================ */
.pwa-nav-sections {
    order: 2;
    position: absolute;
    /* Centrage sans transform pour éviter le décalage sur mobile */
    left: 0;
    right: 0;
    bottom: calc(20px + var(--pwa-viewport-offset));
    margin-left: auto;
    margin-right: auto;
    width: var(--pwa-nav-btn-size);
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* Bouton actif (panel ouvert) */
.pwa-nav-sections.active {
    background: #FF6B6B;
    color: white;
}

.light-mode .pwa-nav-sections.active {
    background: #FF6B6B;
    color: white;
}

/* ============================================
   PANEL DES SECTIONS
============================================ */
.pwa-sections-panel {
    position: fixed;
    /* Position: bouton bottom (20px) + taille bouton + petit espace (8px) + offset viewport */
    bottom: calc(20px + var(--pwa-nav-btn-size) + 8px + var(--pwa-viewport-offset));
    left: 50%;
    transform: translateX(-50%) scale(0.95);
    opacity: 0;
    visibility: hidden;
    background: rgb(42, 51, 52);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.25);
    padding: 8px;
    min-width: 200px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 150px);
    overflow-y: auto;
    transition: all 0.2s ease;
    z-index: calc(var(--pwa-nav-z-index) + 1);
    pointer-events: auto;
}

.pwa-sections-panel.open {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) scale(1);
}

/* Mode clair */
.light-mode .pwa-sections-panel {
    background: rgb(255, 255, 255);
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
}

/* Flèche du panel */
.pwa-sections-panel::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid rgb(42, 51, 52);
}

.light-mode .pwa-sections-panel::after {
    border-top-color: rgb(255, 255, 255);
}

/* Scrollbar personnalisée pour le panel */
.pwa-sections-panel::-webkit-scrollbar {
    width: 4px;
}

.pwa-sections-panel::-webkit-scrollbar-track {
    background: transparent;
}

.pwa-sections-panel::-webkit-scrollbar-thumb {
    background: var(--pwa-nav-border);
    border-radius: 2px;
}

/* ============================================
   ITEMS DU PANEL
============================================ */
.pwa-section-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 20px;
    border-radius: 10px;
    color: var(--pwa-nav-text);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
}

.pwa-section-item:hover {
    background: var(--pwa-nav-btn-hover);
}

.pwa-section-item:active {
    transform: scale(0.98);
}

/* Mode clair */
.light-mode .pwa-section-item {
    color: var(--pwa-nav-text-light);
}

.light-mode .pwa-section-item:hover {
    background: var(--pwa-nav-btn-hover-light);
}

/* Icône des items */
.pwa-section-item i {
    width: 20px;
    text-align: center;
    color: var(--pwa-nav-accent);
    font-size: 1rem;
    flex-shrink: 0;
}

/* Icône SVG nutrition personnalisée */
.pwa-section-item .pwa-nutrition-icon {
    width: 20px;
    height: 20px;
    color: var(--pwa-nav-accent);
    flex-shrink: 0;
}

.pwa-section-item .pwa-nutrition-icon .nutrition-circle {
    stroke-dasharray: 1005.31;
    stroke-dashoffset: 251.33; /* 75% visible */
    transform: rotate(-90deg);
    transform-origin: center;
}

/* Texte des items */
.pwa-section-item span {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Séparateur - DÉSACTIVÉ */
.pwa-section-separator {
    display: none;
}

/* ============================================
   OVERLAY POUR FERMER LE PANEL
============================================ */
.pwa-sections-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: calc(var(--pwa-nav-z-index) - 1);
    display: none;
    background: transparent;
}

.pwa-sections-overlay.active {
    display: block;
}

/* ============================================
   BADGE DE POSITION ACTUELLE (désactivé)
============================================ */
/* Surlignage désactivé volontairement pour une UX plus épurée
.pwa-section-item.active {
    background: rgba(255, 107, 107, 0.15);
}

.pwa-section-item.active::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--pwa-nav-accent);
    border-radius: 2px;
}
*/

/* ============================================
   RESPONSIVE - DESKTOP (> 1024px)
   Masquer sur desktop sauf PWA standalone
============================================ */
@media (min-width: 1025px) {
    :root {
        --pwa-nav-btn-size: 60px;
    }
    
    /* Afficher uniquement en mode PWA standalone */
    @media (display-mode: standalone) {
        .pwa-nav-bar {
            display: flex;
        }
        
        body {
            padding-bottom: calc(var(--pwa-nav-height) + var(--pwa-safe-area-bottom));
        }
    }
}

/* ============================================
   RESPONSIVE - TABLETTE ET MOBILE (≤ 1024px)
============================================ */
@media (max-width: 1024px) {
    .pwa-nav-bar {
        display: flex;
    }
    
    /* Ajuster l'espacement du contenu principal */
    body {
        padding-bottom: calc(var(--pwa-nav-height) + var(--pwa-safe-area-bottom));
    }
    
    /* Ajuster le footer pour ne pas être caché */
    footer {
        margin-bottom: 0;
        padding-bottom: calc(var(--pwa-nav-height) + var(--pwa-safe-area-bottom));
    }
}

/* ============================================
   RESPONSIVE - MOBILE (< 768px)
============================================ */
@media (max-width: 768px) {
    .pwa-nav-bar {
        gap: 4px;
        padding-left: 16px;
        padding-right: 16px;
    }
    
    .pwa-nav-back {
        left: 16px;
    }
    
    .pwa-nav-top {
        right: 16px;
    }
    
    .pwa-nav-btn {
        width: 56px !important;
        height: 56px !important;
        min-width: 56px;
        min-height: 56px;
    }
    
    .pwa-nav-btn i {
        font-size: 1.4rem;
    }
    
    .pwa-nav-btn.with-label {
        padding: 0 12px;
    }
    
    .pwa-nav-btn .btn-label {
        display: none;
    }
    
    .pwa-sections-panel {
        min-width: 180px;
        max-width: calc(100vw - 24px);
    }
}

/* ============================================
   RESPONSIVE - PETIT MOBILE (< 480px)
============================================ */
@media (max-width: 480px) {
    :root {
        --pwa-nav-height: 65px;
        --pwa-nav-btn-size: 52px;
    }
    
    .pwa-nav-btn {
        width: 52px !important;
        height: 52px !important;
        min-width: 52px;
        min-height: 52px;
    }
    
    .pwa-nav-btn i {
        font-size: 1.3rem;
    }
    
    .pwa-section-item {
        padding: 10px 14px;
        font-size: 0.8125rem;
    }
    
    .pwa-section-item i {
        width: 18px;
        font-size: 0.9rem;
    }
    
    .pwa-section-item .pwa-nutrition-icon {
        width: 18px;
        height: 18px;
    }
}

/* ============================================
   RESPONSIVE - TRÈS PETIT MOBILE (< 320px)
============================================ */
@media (max-width: 320px) {
    .pwa-nav-bar {
        gap: 2px;
        padding-left: 12px;
        padding-right: 12px;
    }
    
    .pwa-nav-back {
        left: 12px;
    }
    
    .pwa-nav-top {
        right: 12px;
    }
    
    .pwa-nav-btn {
        width: 48px !important;
        height: 48px !important;
        min-width: 48px;
        min-height: 48px;
    }
    
    .pwa-nav-btn i {
        font-size: 1.2rem;
    }
    
    .pwa-sections-panel {
        min-width: 160px;
    }
    
    .pwa-section-item {
        padding: 8px 12px;
        gap: 10px;
    }
    
    .pwa-section-item .pwa-nutrition-icon {
        width: 16px;
        height: 16px;
    }
}

/* ============================================
   ANIMATIONS
============================================ */
/* Animation de chargement désactivée pour une apparition immédiate */

/* ============================================
   ACCESSIBILITÉ
============================================ */
.pwa-nav-btn:focus-visible {
    outline: 2px solid var(--pwa-nav-accent);
    outline-offset: 2px;
}

.pwa-section-item:focus-visible {
    outline: 2px solid var(--pwa-nav-accent);
    outline-offset: -2px;
}

/* Réduire les animations si préférence utilisateur */
@media (prefers-reduced-motion: reduce) {
    .pwa-nav-bar,
    .pwa-nav-btn,
    .pwa-nav-top,
    .pwa-sections-panel {
        transition: none;
        animation: none;
    }
}

/* ============================================
   PRINT - Masquer à l'impression
============================================ */
@media print {
    .pwa-nav-bar,
    .pwa-sections-panel,
    .pwa-sections-overlay {
        display: none !important;
    }
    
    body {
        padding-bottom: 0 !important;
    }
    
    footer {
        padding-bottom: 0 !important;
    }
}

/* ============================================
   COMPATIBILITÉ DARK MODE NATIF
============================================ */
@media (prefers-color-scheme: dark) {
    /* Si body n'a pas la classe light-mode, appliquer le dark mode */
    body:not(.light-mode) .pwa-nav-bar {
        background: transparent;
        border-top-color: transparent;
    }
    
    body:not(.light-mode) .pwa-nav-btn {
        color: var(--pwa-nav-text);
    }
    
    body:not(.light-mode) .pwa-sections-panel {
        background: rgb(42, 51, 52);
        border-color: rgba(255, 255, 255, 0.1);
    }
    
    body:not(.light-mode) .pwa-section-item {
        color: var(--pwa-nav-text);
    }
}
