/* 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: 24px;
    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;
}

/* ── Menu catégories (volets sous-catégories) ─────────────────────────── */
.hierarchie {
    max-width: 1180px;
    margin: 1rem auto 1.25rem;
    padding: 0 .5rem;
    position: relative;
    z-index: 230;
}

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

/* Niveau racine: badges/menu horizontal en wrap */
.hierarchie > ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .65rem;
}

.hierarchie > ul > li {
    position: relative;
}

.hierarchie a {
    text-decoration: none;
    color: #1d501f;
}

/* Bouton de catégorie principale */
.hierarchie > ul > li > a {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .5rem .85rem;
    border: 1px solid #c8e6c9;
    border-radius: 12px;
    background: #fff;
    font-weight: 600;
    line-height: 1.2;
    transition: background .15s ease, border-color .15s ease, transform .12s ease;
}

.hierarchie > ul > li > a:hover,
.hierarchie > ul > li:focus-within > a {
    background: #e8f5e9;
    border-color: #2e7d32;
    transform: translateY(-1px);
}

/* Panneau sous-catégories: style proche autocomplete (niveau 1 uniquement) */
.hierarchie > ul > li > ul {
    position: absolute;
    top: calc(100% + .18rem);
    left: 0;
    min-width: 260px;
    max-width: min(78vw, 360px);
    max-height: 300px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #c8e6c9;
    border-radius: 12px;
    box-shadow: 0 10px 22px rgba(38,89,38,.14);
    z-index: 220;

    /* caché par défaut */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-4px);
    transition: opacity .15s ease, transform .15s ease, visibility .15s ease;
}

/* Pont invisible pour éviter que le hover se ferme dans le petit espace
   entre la catégorie racine et le panneau overlay. */
.hierarchie > ul > li > ul::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: -12px;
    height: 14px;
    background: transparent;
}

.hierarchie > ul > li:hover > ul,
.hierarchie > ul > li:focus-within > ul {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.hierarchie > ul > li > ul > li > a {
    display: block;
    padding: .55rem .85rem;
    border-bottom: 1px solid #f0f0f0;
    font-size: .95rem;
    transition: background .12s ease;
}

.hierarchie > ul > li > ul > li:last-child > a {
    border-bottom: 0;
}

.hierarchie > ul > li > ul > li > a:hover,
.hierarchie > ul > li > ul > li > a:focus {
    background: #e8f5e9;
    outline: none;
}

/* Sous-niveaux: rendus en flux dans le panneau (pas d'overlay imbriqué) */
.hierarchie > ul > li > ul ul {
    position: static;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
    border: 0;
    box-shadow: none;
    background: transparent;
    max-height: none;
    margin: 0;
    padding: 0 0 0 .6rem;
}

.hierarchie > ul > li > ul ul > li > a {
    font-size: .9rem;
    padding: .4rem .75rem .4rem .95rem;
    border-bottom: 0;
    border-left: 2px solid #e8f5e9;
}

.hierarchie > ul > li > ul ul > li > a:hover,
.hierarchie > ul > li > ul ul > li > a:focus {
    background: #f3fbf4;
    border-left-color: #a5d6a7;
}

.chemin,
h3.chemin,
h6.chemin,
p.chemin {
    color: #2e7d32;
}

.chemin a,
h3.chemin a,
h6.chemin a,
p.chemin a {
    color: #2e7d32;
}

/* Mobile: volets en pile au lieu d'overlay */
@media (max-width: 760px) {

    .hierarchie > ul {
        display: grid;
        grid-template-columns: 1fr;
        gap: .5rem;
    }

    .hierarchie > ul > li > a {
        width: 100%;
        justify-content: flex-start;
        border-radius: 12px;
    }

    .hierarchie > ul > li > ul {
        display: none;
        position: static;
        margin-top: .35rem;
        min-width: 0;
        max-width: 100%;
        max-height: 240px;
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transform: none;
        box-shadow: 0 6px 14px rgba(38,89,38,.12);
    }

    .hierarchie > ul > li:hover > ul,
    .hierarchie > ul > li:focus-within > ul {
        display: block;
    }
}

/* Texte info / cartes */
.texte-info {
    margin: 20px;
    background-color: white;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    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: 24px;
}

/* 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: 24px;
    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); }

.page-back {
    max-width: 1180px;
    margin: 1rem auto 0;
    padding: 0 1rem;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .7rem 1rem;
    border-radius: 16px;
    border: 1px solid #c8e6c9;
    background: #fff;
    color: #1d501f;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 6px 14px rgba(44,96,59,0.10);
    transition: transform .18s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease;
}

.back-btn:hover,
.back-btn:focus {
    background: #e8f5e9;
    border-color: #2e7d32;
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(44,96,59,0.14);
}

.back-btn:focus {
    outline: 2px solid rgba(46,125,50,.25);
    outline-offset: 2px;
}


/* 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: 24px;
    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;
    display: flex;
    overflow: hidden;
    justify-content: center;
    border-radius: 24px;
}

.recette-photo .pictureWave {
    position: absolute;
    bottom: -1.5px;
    z-index: 2;
    height: auto;
    width: 110%;
}

.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: 4%;
    right: 4%;
    width: clamp(24px, 18%, 42px);
    aspect-ratio: 1 / 1;
    height: auto;
    padding: clamp(4px, 1.8%, 7px);
    border-radius: 12px;
    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 .recette-photo {
    border-radius: 0;
}

.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%; }

.recette-contenu {
    margin: 24px;
}

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

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

/* 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%; border-radius: 24px 24px 0 0; }
}

/* ── Recherche (commun aux deux pages) ──────────────────────────────── */
.main-search {
    display: flex;
    flex-direction: column;
}

.page-search {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    min-height: 0;
}

.main-search .search-results,
.main-search #resultats-nom,
.main-search #resultats-ingredients {
    flex: 1 0 auto;
    min-height: 0;
}

.main-search .search-results,
.main-search #resultats-nom,
.main-search #resultats-ingredients {
    display: block;
}

/* Boîte de recherche centrée (utilisée sur recherche_nom) */
.search-box {
    width: 100%;
    max-width: 640px;
    margin: 1.5rem auto;
    position: relative;
}

.search-box label,
.ingredients-search-col label {
    display: block;
    font-weight: 700;
    margin-bottom: .5rem;
    color: #1d501f;
}

/* Ligne input + bouton */
.search-row {
    display: flex;
    gap: .5rem;
    align-items: stretch;
}

.search-input-wrap {
    position: relative;
    flex: 1 1 auto;
}

.search-input-wrap .search-input {
    width: 100%;
}

.search-input {
    flex: 1;
    min-width: 0;
    padding: .6rem .9rem;
    font-size: 1rem;
    border: 2px solid #2e7d32;
    border-radius: 12px;
    outline: none;
    transition: box-shadow .2s;
    background: #fff;
}

.search-input:focus {
    box-shadow: 0 0 0 3px rgba(46,125,50,.25);
}

.search-btn {
    padding: .6rem 1.4rem;
    flex: 0 0 auto;
    background: #2e7d32;
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background .2s, transform .15s;
    white-space: nowrap;
}

@media (max-width: 700px) {
    .search-box {
        max-width: 100%;
    }

    .search-row {
        flex-direction: column;
        gap: .6rem;
    }

    .search-input,
    .search-btn {
        width: 100%;
    }

    .search-btn {
        min-height: 44px;
    }
}

.search-btn:hover {
    background: #1d501f;
    transform: translateY(-1px);
}

/* Grille deux colonnes pour la recherche par ingrédients */
.ingredients-search-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem 2rem;
    margin: 1.5rem auto;
    max-width: 650px;
}

.ingredients-search-col {
    position: relative;
}

.ingredients-search-actions {
    grid-column: 1 / -1;
    text-align: center;
    padding-top: .25rem;
}

@media (max-width: 620px) {
    .ingredients-search-grid {
        grid-template-columns: 1fr;
    }
}

/* Suggestions (autocomplete) */
.autocomplete-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 6px 18px rgba(38,89,38,.10);
    z-index: 200;
    max-height: 300px;
    overflow-y: auto;
}

.suggestion-item {
    padding: .55rem .9rem;
    cursor: pointer;
    font-size: .95rem;
    border-bottom: 1px solid #f0f0f0;
    transition: background .12s;
}

.suggestion-item:last-child { border-bottom: none; }

.suggestion-item:hover,
.suggestion-item.suggestion-active {
    background: #e8f5e9;
    color: #1d501f;
}

.suggestion-item strong { color: #2e7d32; font-weight: 700; }

.no-suggestions {
    padding: .55rem .9rem;
    color: #888;
    font-style: italic;
    font-size: .9rem;
}

/* Tags d'ingrédients sélectionnés */
.aliments-list { margin-top: .75rem; display: flex; flex-direction: column; gap: .4rem; }
.aliments-list .aliment {
    background: #e8f5e9;
    border: 1px solid #c8e6c9;
    padding: .45rem .75rem;
    border-radius: 24px;
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: .9rem;
}
.aliments-list .aliment span { flex: 1; color: #1d501f; }
.aliments-list .aliment button {
    background: none;
    color: #c62828;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    border-radius: 24px;
    transition: background .15s;
}
.aliments-list .aliment button:hover { background: rgba(198,40,40,.1); }

.no-results {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: 1.5rem;
}

.loading {
    text-align: center;
    color: #2e7d32;
    padding: 1rem;
    font-style: italic;
}

/* Compteur de résultats */
.results-info {
    text-align: center;
    color: #4b6b4b;
    font-size: .9rem;
    margin: .75rem 0 -.25rem;
    font-style: italic;
}

/* ── Pagination ─────────────────────────────────────────────────────────── */
.pagination {
    position: static !important;
    clear: both;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: .35rem;
    flex-wrap: wrap;
    margin-top: 1rem;
    padding: 1.25rem .5rem 1.5rem;
}

.page-btn {
    min-width: 38px;
    height: 38px;
    padding: 0 .65rem;
    border: 2px solid #c8e6c9;
    border-radius: 24px;
    background: #fff;
    color: #1d501f;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, border-color .15s, transform .1s;
    line-height: 1;
    user-select: none;
}

.page-btn:hover:not(.active):not(:disabled):not(.disabled) {
    background: #e8f5e9;
    border-color: #2e7d32;
    transform: translateY(-2px);
}

.page-btn.active {
    background: #2e7d32;
    border-color: #2e7d32;
    color: #fff;
    cursor: default;
}

.page-btn:disabled,
.page-btn.disabled {
    opacity: .35;
    cursor: not-allowed;
    pointer-events: none;
}

.page-ellipsis {
    color: #999;
    font-size: 1rem;
    padding: 0 .2rem;
    align-self: flex-end;
    margin-bottom: 4px;
    user-select: none;
}

/* 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: 0; }
    .search-input { font-size: .95rem; }
}

/* 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: 24px;
        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; }
}
