/* Styles principaux et reset léger */
* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background-color: #f4f6f4;
    color: #1d501f;
    line-height: 1.45;
    padding-top: 50px; /* espace pour la navbar fixe */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* garantit la hauteur min pour le footer */
}

/* Assure que le footer reste en bas de la page en cas de contenu court */
main, .main-container {
    flex: 1 0 auto;
    margin: 0 1rem;
}

/* Certaines pages (ex : recette.php) n'utilisent pas .main-container ; s'assurer qu'une .texte-info à la racine prenne la place disponible */
body > .texte-info {
    flex: 1 0 auto;
}

footer {
    flex-shrink: 0;
    padding: 20px 12px;
    text-align: center;
    font-size: 14px;
    color: white;
    background: #1d501f;
}

/* NAVBAR */
nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: linear-gradient(90deg,#1d501f 0%, #2e7d32 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.navbar {
    max-width: 1180px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    position: relative; /* permet de centrer .navbar-center en absolute en mobile */
}

.nav-menu { display: none; }
.nav-toggle {
    display: none; /* visible sur petits écrans via media queries */
    background: transparent;
    border: 0;
    width: 44px;
    height: 44px;
    cursor: pointer;
    color: white;
    justify-content: center;
    align-items: anchor-center;
}

.nav-toggle .hamburger,
.nav-toggle .hamburger::before,
.nav-toggle .hamburger::after {
    display: block;
    width: 26px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: all .25s ease;
    position: relative;
}

.nav-toggle .hamburger::before,
.nav-toggle .hamburger::after {
    content: '';
    position: absolute;
    left: 0;
}

.nav-toggle .hamburger::before { top: -8px; }
.nav-toggle .hamburger::after  { top: 8px; }

.nav-toggle.active .hamburger::before { transform: rotate(90deg) translateX(0); top: 0; }
.nav-toggle.active .hamburger::after  { opacity: 0; }

.navbar-items {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 12px;
}

.navbar-left,
.navbar-center,
.navbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.navbar-left { justify-content: flex-start; }
.navbar-center { justify-content: center; flex: 1; white-space: nowrap; }
.navbar-right { justify-content: flex-end; }

.navbar-center p {
    margin: 0;
    font-weight: 700;
    font-size: 2rem;
    letter-spacing: .6px;
}
.navbar-center a {
    text-decoration: none;
    color: unset;
}

.navbar-left a,
.navbar-right a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    text-decoration: none;
}

/* Contenu principal */
header {
    background-color: #2e7d32;
    color: white;
    padding: 2rem;
    text-align: center;
}

footer {
    padding: 20px 12px;
    text-align: center;
    font-size: 14px;
    color: white;
    background: #1d501f;
}

.container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 16px;
}

/* Texte info / cartes */
.texte-info {
    margin: 20px auto;
    padding: 20px;
    background-color: white;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: 0 6px 14px rgba(44,96,59,0.08);
    text-align: center;
}

.texte-info img.file {
    max-width: 100%;
    height: auto;
    box-shadow: 0 6px 14px rgba(44,96,59,0.08);
    border-radius: 8px;
}

/* Features section */
.features {
    text-align: center;
    padding: 2.2em 0;
    background: linear-gradient(180deg,#2e7d32 0%, #2aa15a 100%);
    color: #fff;
}

.features-container {
    display: flex;
    justify-content: center;
    gap: 2.5rem;
    padding: 1rem;
    flex-wrap: wrap;
}

.feature {
    max-width: 260px;
    flex: 1 1 200px;
}

.feature img { max-width: 60px; margin-bottom: .6rem; }

a.btn {
    display: inline-block;
    background-color: #fff;
    color: #1d501f;
    padding: 0.6em 1.2em;
    border-radius: 30px;
    font-weight: 700;
    transition: transform .2s ease, box-shadow .2s ease;
    box-shadow: 0 6px 14px rgba(44,96,59,0.12);
    text-transform: uppercase;
    text-decoration: none;
}

a.btn:hover { transform: translateY(-3px); }

/* Style pour la hierarchie */
.hierarchie {  
    margin: 2%; 
    text-align: center;
    ul {
        list-style-type: none; /* Supprime les puces */
        padding-left: 0;
        display: ruby; /* Affiche les éléments de la liste horizontalement */
        margin: auto;      
        width: fit-content;
        position: relative;
    }
    ul ul {
        display: none; /* Cache les sous-listes par défaut */
        position: absolute; /* Positionne les sous-listes par rapport à l'élément parent */
        left: 0; /* Positionne la sous-liste à droite de l'élément parent */
        top: 105%;
        background-color: #f4f6f4;
        padding: 5px;
        border-radius: 5px;
        box-shadow: 0 2px 5px #2c603b;
        z-index: 10; /* Assure que la sous-liste se place au-dessus des autres éléments */
        width: max-content;
    }
}
.hierarchie li {
    margin: 5px 20px;
    position: relative;
}
.hierarchie li:hover > ul {
    display: block; /* Affiche la sous-liste quand on survole un élément */
}
.hierarchie a {
    text-decoration: none;
    color: #1d501f;
    display: block; /* Pour rendre le lien cliquable sur toute la largeur */
    padding: 5px;
}
.hierarchie li:hover > a {
    background-color: #ddd; /* Mise en évidence */
}
.hierarchie li:has(> ul) > a::after {
    content: ' ▼';
    font-size: 10px;
    color: #1d501f;
    margin-left: 5px;
    transition: transform 0.3s ease; /* Transition pour la rotation de la flèche */
}

/* Style pour le chemin de la hierarchie */
h3.chemin, h6.chemin {
    color: #2e7d32;
    a {
        color: #2e7d32;
    }
}

/* Refonte : grille des recettes et cartes */
.recette-list {
    text-align: center;
    margin: 20px 0;
    padding: 0 12px;
}

/* Grille moderne : auto-fit pour optimiser l'espace disponible */
.recette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    align-items: stretch; /* cards same height per row */
    width: 100%;
    padding: 8px 4px;
}

/* Carte : format compact, accessible, pleine hauteur dans la cellule */
.card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    text-decoration: none;
    color: inherit;
    background: #fff;
    border: 1px solid #e6e6e6;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 6px 18px rgba(38,89,38,0.06);
    transition: transform .18s ease, box-shadow .18s ease;
    width: 100%;
    height: 100%; /* permet d'avoir des cartes de même hauteur */
    max-width: 200px;
    margin: auto;
}

/* Zone image avec ratio contrôlé */
.recette-photo {
    position: relative;
    width: 100%;
    padding-top: 100%;
    background: #fff;
}

.recette-photo img.file {
    position: absolute;
    inset: 0; /* top/right/bottom/left: 0 */
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Badge favoris positionné dans la zone image */
.recette-photo img.fav {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    padding: 6px;
    border-radius: 8px;
    background: rgba(255,255,255,0.95);
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    cursor: pointer;
    z-index: 5;
}

/* Corps de la carte */
.card .card-body {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1 1 auto;
    justify-content: flex-start;
}

.card h4 {
    margin: 0;
    font-size: 1rem;
    color: #1d501f;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* tronque sur 2 lignes */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card .meta {
    margin: 0;
    font-size: 0.86rem;
    color: #4b6b4b;
}

.card .card-actions {
    margin-top: auto;
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.card:hover {
    transform: translateY(-6px);
    box-shadow: 0 18px 38px rgba(0,0,0,0.12);
}

/* Petite vignette pour listes plus compactes */
.card.compact .recette-photo { padding-top: 50%; }

.texte-info.recette-detail {
    text-align: left;
}

/* Page détail : s'assurer que la zone image garde aspect et n'overflows pas */
.texte-info.recette-detail .recette-photo { padding-top: 70%; }

@media (min-width: 900px) {
    .texte-info.recette-detail {
        width: 50vw;
        padding: 20px;
    }

    /* Photo dimension réduite pour desktop */
    .texte-info.recette-detail .recette-photo {
        width: 50%;
        padding-top: 50%; /* ratio 16:9 */
        border-radius: 12px;
        margin: auto;
    }
}

/* Responsiveness : adapter le nombre de colonnes et la taille des cartes */
@media (max-width: 1024px) {
    .recette-grid { gap: 18px; }
}

@media (max-width: 768px) {
    .recette-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
    .card h4 { font-size: 0.98rem; }
}

@media (max-width: 520px) {
    .recette-grid {
        grid-template-columns: 1fr; /* une colonne sur mobile */
    }
    .recette-grid { gap: 12px; }
    .recette-photo { padding-top: 56%; }
}

/* Recherche par ingrédients */
table.recherche { margin: auto; padding: 10px; text-align: center; width: 100%; max-width: 920px; }
table.recherche td { vertical-align: top; padding: 8px; width: 50%; }

table.recherche input[type="text"], table.recherche input[type="search"] {
    width: 100%;
    padding: 10px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
}

.aliments-list { margin-top: 10px; }
.aliments-list .aliment { background-color: #e9ece9; padding: 8px; border-radius: 6px; display:flex; gap:8px; align-items:center; }
.aliments-list .aliment span { flex: 1; }
.aliments-list .aliment button { background-color: #ff6b6b; color: white; border: none; padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.aliments-list .aliment button:hover { background-color: #e63946; }

/* Suggestions (autocomplete) */
.suggestions { position: absolute; background-color: #fff; width: 100%; max-width: 40vw; z-index: 200; overflow: auto; max-height: 260px; border-radius: 6px; box-shadow: 0 6px 14px rgba(44,96,59,0.08); }
.suggestion-item { padding: 8px; cursor: pointer; border-radius: 4px; }
.suggestion-item:hover { background-color: #f5f5f5; }
.no-suggestions { padding: 8px; color: #888; font-style: italic; }

/* Formulaires et erreurs */
.invalid { border: 2px solid #e63946; }
.errors p { color: #e63946; margin: 6px 0; }
form table { text-align: right; border-spacing: 10px; margin: auto; }
.form-actions input { margin: 10px; }

/* Responsive rules */
@media (max-width: 1024px) {
    .features-container { gap: 1.5rem; }
}

@media (max-width: 768px) {
    .nav-toggle { display: inline-flex; }

    .navbar-items { display: none; }
    .navbar-items.open { display: flex; flex-direction: column; gap: 8px; background: transparent; width: 100%; }

    .navbar-center {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        pointer-events: none; /* permet de cliquer facilement sur icônes à gauche/droite */
    }

    .navbar-center p { margin: 0; pointer-events: auto; }

    .navbar-left, .navbar-right { justify-content: space-between; padding: 0 8px; }

    .navbar-right, .navbar-left { width: 100%; }

    .navbar { padding: 8px 12px; }

    .recette-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

@media (max-width: 480px) {
    .navbar-center p { font-size: 1.5rem; }
    header { padding: 1.5rem; }
    .features { padding: 1.2rem 0; }
    .card { max-width: 100%; }
    .texte-info { margin: 12px; padding: 12px; }
    table.recherche input { max-width: 100%; }
}

/* Styles pour le menu mobile (hamburger) */
@media (max-width: 700px) {
    .nav-toggle {
        display: flex; /* afficher le bouton hamburger */
        align-items: center;
        justify-content: center;
    }

    /* Cacher les icones de la navbar principale qui sont dupliquées dans le menu mobile */
    .navbar-left a,
    .navbar-right a {
        display: none;
    }

    /* Ajuste le titre pour qu'il rentre mieux */
    .navbar-center p {
        font-size: 1.2rem;
        margin: 0;
    }

    /* Menu caché par défaut */
    .nav-menu {
        display: none;
        position: fixed;
        left: 0;
        right: 0;
        top: 56px; /* position sous la navbar fixe */
        background: linear-gradient(90deg,#1d501f 0%, #2e7d32 100%);
        color: #fff;
        z-index: 999;
        padding: 8px 12px;
        flex-direction: column;
        gap: 6px;
        box-shadow: 0 6px 16px rgba(0,0,0,0.18);
    }

    /* Etat ouvert : menu visible */
    .nav-menu.open {
        display: flex;
    }

    .nav-menu-item {
        display: flex;
        align-items: center;
        gap: 10px;
        color: #fff;
        text-decoration: none;
        padding: 10px 12px;
        border-radius: 8px;
        transition: background .15s ease, transform .08s ease;
    }

    .nav-menu-item img {
        width: 22px;
        height: 22px;
        object-fit: contain;
        filter: brightness(0) invert(1);
    }

    .nav-menu-item span {
        font-weight: 700;
        font-size: 1rem;
        line-height: 1;
    }

    .nav-menu-item:hover {
        background: rgba(255,255,255,0.06);
        transform: translateY(-1px);
    }

    /* Petite amélioration du bouton hamburger actif */
    .nav-toggle { margin-left: 6px; }
    .nav-toggle.active .hamburger { background: transparent; }
    .nav-toggle.active .hamburger::before { transform: rotate(45deg); top: 0; }
    .nav-toggle.active .hamburger::after { transform: rotate(-45deg); top: 0; opacity: 1; }
}
