/* ==========================================================================
   CDM — Navigation « app »
   Barre supérieure (tous formats) + barre d'onglets fixe en bas (mobile).
   Utilisée par _app_nav.html, incluse sur toutes les pages publiques.
   ========================================================================== */

:root {
    --nav-bg: rgba(10, 10, 10, .78);
    --nav-sheet-bg: #14151c;
    --nav-sheet-bg-2: #1d1e29;
    --nav-text: #f5f5f5;
    --nav-muted: #9a9a9a;
    --nav-line: rgba(255, 255, 255, .12);
    --nav-line-strong: rgba(255, 255, 255, .25);
    --nav-accent: #2563eb;
    --nav-h: 64px;
    --tabbar-h: 62px;
    --rail-w: 232px;
    --topbar-h: 58px;
}

/* ─────────────── Bandeau du mode démonstration (local uniquement) ─────── */
.bandeau-demo {
    position: relative;
    z-index: 200;
    background: #b91c1c;
    color: #fff;
    font-size: 13px;
    line-height: 1.5;
    padding: 10px 20px;
    text-align: center;
}

.bandeau-demo strong { font-weight: 800; }

.bandeau-demo button {
    background: rgba(0, 0, 0, .3);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .5);
    border-radius: 999px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    margin-left: 10px;
    cursor: pointer;
}

.bandeau-demo button:hover { background: rgba(0, 0, 0, .55); }

/* Sur desktop, le rail et la pilule sont fixes : le bandeau doit l'être aussi,
   sinon il se retrouve poussé au milieu de la page par le retrait du corps. */
@media (min-width: 900px) {
    .bandeau-demo {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 0 20px;
    }

    body:has(.bandeau-demo) { padding-top: calc(var(--topbar-h) + 44px); }
    body:has(.bandeau-demo) .appbar { top: 44px; }
    body:has(.bandeau-demo) .appbar-cta { top: 56px; }
}

/* Chaque page porte ses propres règles `nav { … }` / `nav a { … }` héritées de
   l'ancienne navigation (majuscules, fond, bordure, marges). Comme .appbar-tabs
   est un élément <nav>, il faut neutraliser cet héritage explicitement. */
nav.appbar-tabs {
    background: none;
    border: none;
    padding: 0;
    position: static;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    height: auto;
    justify-content: flex-start;
}

nav.appbar-tabs > .navtab,
.tabbar .navtab,
.nav-sheet > a {
    text-transform: none;
    margin: 0;
}

/* --------------------------------------------------------- Barre du haut */
.appbar {
    position: sticky;
    top: 0;
    z-index: 120;
    background: var(--nav-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--nav-line-strong);
}

.appbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    min-height: var(--nav-h);
}

.appbar-logo {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    text-decoration: none;
}

.appbar-logo img {
    height: 42px;
    width: auto;
    display: block;
}

/* Onglets horizontaux — desktop uniquement */
.appbar-tabs {
    display: none;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

.appbar-tabs .navtab {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 9px 14px;
    border-radius: 999px;
    color: var(--nav-muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
    border: 1px solid transparent;
    background: none;
    cursor: pointer;
    font-family: inherit;
    transition: color .15s ease, background .15s ease, border-color .15s ease;
}

.appbar-tabs .navtab svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.appbar-tabs .navtab:hover {
    color: var(--nav-text);
    background: rgba(255, 255, 255, .06);
}

.appbar-tabs .navtab.is-active {
    color: var(--nav-text);
    background: rgba(255, 255, 255, .1);
    border-color: var(--nav-line);
}

/* Même vocabulaire visuel que les onglets : pilule, icône, casse normale. */
.appbar-cta {
    margin-left: auto;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, .06);
    color: var(--nav-text);
    padding: 9px 16px;
    border: 1px solid var(--nav-line);
    border-radius: 999px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0.01em;
    white-space: nowrap;
    transition: background .15s ease, border-color .15s ease;
}

.appbar-cta svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.appbar-cta:hover {
    background: rgba(255, 255, 255, .13);
    border-color: var(--nav-line-strong);
    color: var(--nav-text);
}

/* ================= Desktop : la barre devient un rail latéral gauche ======= */
@media (min-width: 900px) {
    body {
        padding-left: var(--rail-w);
    }

    .appbar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: var(--rail-w);
        background: #0b0b0e;
        border-bottom: none;
        border-right: 1px solid var(--nav-line-strong);
        /* Indispensable : un backdrop-filter sur cet élément en ferait le bloc
           conteneur de ses enfants en position:fixed — le bouton « Se connecter »
           resterait alors prisonnier du rail au lieu de se caler sur la fenêtre. */
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .appbar-inner {
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 28px;
        height: 100%;
        max-width: none;
        margin: 0;
        padding: 26px 16px 24px;
    }

    .appbar-logo {
        justify-content: flex-start;
        padding-left: 6px;
    }

    .appbar-tabs {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        margin-left: 0;
    }

    .appbar-tabs .navtab {
        justify-content: flex-start;
        padding: 12px 14px;
        font-size: 13.5px;
        border-radius: 10px;
    }

    .appbar-tabs .navtab svg {
        width: 18px;
        height: 18px;
    }

    /* « Se connecter » quitte le rail pour se fixer en haut à droite.
       La bande réservée en haut du corps de page évite qu'il chevauche
       le bandeau promo ou le contenu. */
    body {
        padding-top: var(--topbar-h);
    }

    .appbar-cta {
        position: fixed;
        top: 12px;
        right: 26px;
        margin: 0;
        z-index: 122;
        background: rgba(20, 21, 28, .82);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
}

/* Rails plus étroits sur les écrans intermédiaires */
@media (min-width: 900px) and (max-width: 1180px) {
    :root { --rail-w: 208px; }
}

/* ------------------------------------------- Barre d'onglets basse (mobile) */
.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 130;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    background: rgba(10, 10, 10, .94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--nav-line-strong);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tabbar .navtab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 9px 2px 8px;
    min-height: var(--tabbar-h);
    color: var(--nav-muted);
    text-decoration: none;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    background: none;
    border: none;
    border-top: 2px solid transparent;
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: color .15s ease, border-color .15s ease;
}

.tabbar .navtab svg {
    width: 21px;
    height: 21px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .15s ease;
}

.tabbar .navtab.is-active {
    color: var(--nav-text);
    border-top-color: var(--nav-accent);
}

.tabbar .navtab.is-active svg {
    transform: translateY(-1px);
}

.tabbar .navtab-label {
    line-height: 1.1;
}

/* Six onglets sur un écran étroit : on resserre pour que les libellés tiennent */
@media (max-width: 400px) {
    .tabbar .navtab { font-size: 9px; padding: 8px 1px 7px; }
    .tabbar .navtab svg { width: 19px; height: 19px; }
}

@media (min-width: 900px) {
    .tabbar { display: none; }
}

/* Espace pour que la barre basse ne masque pas le bas de page */
@media (max-width: 899px) {
    body {
        padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    }

    /* Le CTA sticky de la home se cale au-dessus de la barre d'onglets
       (sans quoi il la recouvrait : son z-index est bien plus élevé).
       Sa translation de repli doit franchir cette hauteur en plus de la sienne,
       sinon il reste posé sur la barre d'onglets à l'état masqué. */
    #mobile-cta-bar {
        bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
        transform: translateY(calc(100% + var(--tabbar-h) + env(safe-area-inset-bottom, 0px)));
    }

    /* Idem pour la bulle de chat flottante */
    #cdm-bubble {
        bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 14px);
    }

    #cdm-panel {
        bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 82px);
        max-height: calc(100vh - var(--tabbar-h) - 160px);
    }
}

/* ------------------------------------------------------- Panneau « Plus » */
.nav-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 121;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
}

.nav-sheet-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

/* z-index inférieur à .tabbar : le panneau glisse derrière la barre d'onglets,
   qui reste visible et cliquable — comportement attendu dans une application. */
.nav-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 125;
    background: var(--nav-sheet-bg);
    border-top: 1px solid var(--nav-line-strong);
    transform: translateY(100%);
    transition: transform .24s cubic-bezier(.4, 0, .2, 1);
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    max-height: 76vh;
    overflow-y: auto;
}

.nav-sheet.open {
    transform: translateY(0);
}

.nav-sheet-handle {
    width: 38px;
    height: 4px;
    border-radius: 99px;
    background: var(--nav-line-strong);
    margin: 10px auto 4px;
}

.nav-sheet a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 22px;
    color: var(--nav-text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    border-top: 1px solid var(--nav-line);
}

.nav-sheet a:first-of-type {
    border-top: none;
}

.nav-sheet a:hover {
    background: var(--nav-sheet-bg-2);
}

.nav-sheet a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: .75;
}

.nav-sheet-langs {
    padding: 14px 22px 18px;
    border-top: 1px solid var(--nav-line);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.nav-sheet-langs .nav-sheet-langs-icon {
    opacity: .6;
    flex-shrink: 0;
}

/* Sur desktop, le panneau sort du rail, en bas à gauche */
@media (min-width: 900px) {
    .nav-sheet {
        left: calc(var(--rail-w) + 10px);
        right: auto;
        bottom: 24px;
        top: auto;
        width: 262px;
        border: 1px solid var(--nav-line-strong);
        border-radius: 0;
        padding-bottom: 0;
        transform: translateX(-10px);
        opacity: 0;
        pointer-events: none;
        transition: opacity .16s ease, transform .16s ease;
        max-height: none;
    }

    .nav-sheet.open {
        transform: translateX(0);
        opacity: 1;
        pointer-events: auto;
    }

    .nav-sheet-handle { display: none; }
    .nav-sheet-backdrop { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .nav-sheet,
    .nav-sheet-backdrop,
    .tabbar .navtab,
    .tabbar .navtab svg,
    .appbar-tabs .navtab {
        transition: none;
    }
}
