:root {
    --primary-color: #1e8f4e;
    --primary-dark: #146b39;      /* texte vert sur fond clair (contraste ≥ 4,5:1) */
    --primary-light: #e8f4f8;
    --bg-color: #f8f9fa;
    --text-color: #333;
    --text-muted: #5f6b76;
    --texte-secondaire: #6c757d;
    --laser-color: #e63946;
    --bar-height: 80px; 
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    background-color: var(--bg-color);
    overscroll-behavior-y: none;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding-top: calc(var(--bar-height) + env(safe-area-inset-top));
    /* Intègre la hauteur de la barre fixe + la zone home indicator d'iOS + marge */
    padding-bottom: calc(var(--bar-height) + env(safe-area-inset-bottom) + 1.5rem);
    overscroll-behavior-y: none;
}

.app-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Repli pour les navigateurs sans unité dvh */
    min-height: calc(100vh - (var(--bar-height) * 2) - 1.25rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    min-height: calc(100dvh - (var(--bar-height) * 2) - 1.25rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 1rem;
}

.top-action-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: calc(var(--bar-height) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 1.5rem 0 1.5rem;
    background: rgba(248, 249, 250, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
    /* Ancrage matériel iOS */
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    will-change: transform;
}

.bottom-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    /* Remplace le 1.75rem statique pour gérer précisément la barre d'accueil iOS */
    padding: 0.75rem 1.5rem calc(0.75rem + env(safe-area-inset-bottom));
    background: rgba(248, 249, 250, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    box-sizing: border-box;
    /* Ancrage matériel iOS contre le décrochage */
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    will-change: transform;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.brand:active {
    opacity: 0.7;
}

.app-logo {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

/* ZeDiet : logo complet (logodiet.png) à la place de l'icône et du titre */
.app-logo-image {
    height: 40px;
    width: auto;
    max-width: 60vw;
    flex-shrink: 0;
}

#app-title {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--text-color);
    margin: 0;
    letter-spacing: -0.5px;
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s ease;
    min-width: 44px;
    min-height: 44px;
}

.icon-btn:active {
    transform: scale(0.9);
}

.submenu {
    position: fixed;
    top: calc(var(--bar-height) + env(safe-area-inset-top));
    left: 0;
    width: 100%;
    background: #ffffff;
    box-shadow: 0 12px 24px rgba(0,0,0,0.12);
    z-index: 999;
    transform-origin: top;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.2s ease, visibility 0s linear 0s;
}

/* Menu fermé : invisible aussi pour le clavier et les lecteurs d'écran (visibility), après l'animation */
.submenu.hidden-menu {
    transform: scaleY(0);
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.2s ease, visibility 0s linear 0.3s;
}

.submenu ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.submenu li {
    border-bottom: 1px solid #f1f3f5;
}

.submenu a {
    display: block;
    padding: 1.2rem 1.5rem;
    color: var(--text-color);
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1rem;
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-decoration: none;
    box-sizing: border-box;
    background-color: var(--primary-color);
    color: white;
    font-size: 1.1rem;
    padding: 1rem 2rem;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 12px rgba(30, 143, 78, 0.3);
    transition: transform 0.1s ease, background-color 0.2s ease;
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-primary.btn-cancel {
    background-color: #e63946;
    box-shadow: 0 4px 12px rgba(230, 57, 70, 0.3);
}

#scanner-ui {
    position: relative;
    width: 100%;
    max-width: 360px;
    aspect-ratio: 4 / 3;
    margin: 2rem auto;
    border-radius: 24px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.15), 0 0 0 4px rgba(30, 143, 78, 0.1);
    transform: translateZ(0); 
}

#camera-stream {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: contrast(1.1) brightness(1.05); 
    /* Fond noir tant que la caméra n'a pas livré sa première image : masque l'icône
       « lecture » grise que la WebView Android affiche par défaut sur une vidéo vide */
    background: #000;
    opacity: 0;
    transition: opacity 0.25s ease;
}

#camera-stream.video-active {
    opacity: 1;
}

.scanner-frame {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    box-shadow: inset 0 0 0 25px rgba(0, 0, 0, 0.45);
}

.scanner-frame::before {
    content: '';
    position: absolute;
    top: 25px; left: 25px; right: 25px; bottom: 25px;
    
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15); 
    border-radius: 12px;
    
    background: 
        linear-gradient(to right, var(--primary-color) 4px, transparent 4px) 0 0,
        linear-gradient(to bottom, var(--primary-color) 4px, transparent 4px) 0 0,
        linear-gradient(to left, var(--primary-color) 4px, transparent 4px) 100% 0,
        linear-gradient(to bottom, var(--primary-color) 4px, transparent 4px) 100% 0,
        linear-gradient(to right, var(--primary-color) 4px, transparent 4px) 0 100%,
        linear-gradient(to top, var(--primary-color) 4px, transparent 4px) 0 100%,
        linear-gradient(to left, var(--primary-color) 4px, transparent 4px) 100% 100%,
        linear-gradient(to top, var(--primary-color) 4px, transparent 4px) 100% 100%;
    background-repeat: no-repeat;
    background-size: 30px 30px; 
    
    background-clip: padding-box;
    -webkit-background-clip: padding-box;
}

.scanner-laser {
    position: absolute;
    width: calc(100% - 70px); 
    left: 35px;
    height: 2px;
    background-color: var(--laser-color); 
    box-shadow: 0 0 12px var(--laser-color), 0 0 20px var(--laser-color);
    z-index: 10;
    animation: scan-laser 2.5s ease-in-out infinite;
}

@keyframes scan-laser {
    0%, 100% { top: 40px; }
    50% { top: calc(100% - 40px); }
}

#result-ui {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease-out;
}

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

.hidden {
    display: none !important;
}


.hero-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem 1.5rem;
    height: 100%;
    width: 100%;
    box-sizing: border-box;
}

.hero-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

.hero-badge {
    background-color: var(--primary-light, #e8f4f8);
    color: var(--primary-dark, #146b39);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.35rem 0.8rem;
    border-radius: 50px;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hero-welcome h1,
.hero-welcome h2 {
    font-size: 1.75rem;
    color: var(--text-color, #2c3e50);
    margin-bottom: 0.75rem;
    line-height: 1.3;
    text-align: center;
}

.hero-welcome p {
    font-size: 0.95rem;
    color: var(--text-muted, #5f6b76);
    line-height: 1.5;
    margin: 0 auto;
    text-align: center;
}

.mut {
	color: var(--primary-color); text-decoration: underline;
}

@media (min-width: 768px) {
    .hero-welcome {
        height: auto;
        padding: 1.5rem;
    }
}

/* Accueil sans défilement uniquement si l'écran est assez haut pour tout afficher */
@media (min-width: 768px) and (min-height: 720px) {
    body:has(#home-welcome-ui:not(.hidden)) {
        overflow-y: hidden;
    }
}

/* Navigation au clavier : focus toujours visible */
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid var(--primary-dark);
    outline-offset: 2px;
}

/* Réglage système « réduire les animations » */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .scanner-laser {
        animation: none;
        top: 50%;
    }
}
