/* ==========================================================================
   EMTOP — Menu mobile (layout/_menu_mobile.html.twig, contrôleur Stimulus « menu-mobile »)
   Écrans < 768 px et application installée : barre d'onglets en bas de l'écran façon application mobile,
   bouton central « Ajouter » aux couleurs EMTOP, feuilles glissantes « Menu » et « Ajouter ».
   Sur mobile, le bouton hamburger du header est remplacé par l'onglet « Menu ».
   Classes préfixées « mm- » : aucun impact sur les autres modules ni sur l'affichage ordinateur / tablette.
   ========================================================================== */

:root {
    --mm-hauteur: 64px;
    --mm-bas: env(safe-area-inset-bottom, 0px); /* barre d'accueil des iPhone (application installée) */
    --mm-accent: var(--em-brand);
}

html[data-theme="dark"] { --mm-accent: #ff6b6e; }

.mm { display: none; }

/* --- Barre d'onglets ---------------------------------------------------------------------- */
.mm-barre {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1030;
    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    height: calc(var(--mm-hauteur) + var(--mm-bas));
    padding: 0 4px var(--mm-bas);
    border-top: 1px solid var(--em-border);
    background: var(--em-card-bg);
    box-shadow: 0 -8px 24px rgba(16, 24, 40, .06);
}

.mm-onglet {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    height: var(--mm-hauteur);
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    font-size: .6875rem;
    font-weight: 500;
    line-height: 1.2;
    color: var(--em-muted);
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.mm-onglet:hover,
.mm-onglet:focus { color: var(--em-heading-color); }

.mm-onglet-icone {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 30px;
    border-radius: 15px;
    transition: background-color .2s ease, transform .15s ease;
}

.mm-onglet-icone .em-icon { width: 24px; height: 24px; }
.mm-onglet-texte { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mm-onglet:active .mm-onglet-icone { transform: scale(.9); }
.mm-onglet:focus-visible { outline: 0; }
.mm-onglet:focus-visible .mm-onglet-icone { box-shadow: 0 0 0 2px var(--mm-accent); }

/* Onglet actif : pastille et texte aux couleurs EMTOP (comme le repère du menu latéral) */
.mm-onglet.is-active { font-weight: 600; color: var(--mm-accent); }
.mm-onglet.is-active .mm-onglet-icone { background: rgba(var(--em-brand-rgb), .1); }
html[data-theme="dark"] .mm-onglet.is-active .mm-onglet-icone { background: rgba(255, 107, 110, .14); }
.mm-onglet.is-active .em-icon { stroke-width: 2; }

/* Bouton central « Ajouter » */
.mm-ajouter {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    height: var(--mm-hauteur);
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.mm-ajouter-bouton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    margin-top: -20px;
    border-radius: 50%;
    background: var(--em-brand-gradient);
    color: #fff;
    box-shadow: 0 0 0 5px var(--em-card-bg), 0 10px 22px -6px rgba(var(--em-brand-rgb), .6);
    transition: transform .25s cubic-bezier(.32, .72, 0, 1);
}

.mm-ajouter-bouton .em-icon { width: 28px; height: 28px; stroke-width: 2; }
.mm-ajouter:active .mm-ajouter-bouton { transform: scale(.92); }
.mm-ajouter[aria-expanded="true"] .mm-ajouter-bouton { transform: rotate(45deg); }
.mm-ajouter:focus-visible { outline: 0; }
.mm-ajouter:focus-visible .mm-ajouter-bouton { box-shadow: 0 0 0 5px var(--em-card-bg), 0 0 0 7px var(--mm-accent); }

/* --- Feuilles glissantes (<dialog>) ---------------------------------------------------------- */
html:has(.mm-feuille[open]) { overflow: hidden; }

.mm-feuille {
    position: fixed;
    inset: auto 0 0;
    width: 100%;
    max-width: 100%;
    max-height: min(88vh, 88dvh);
    margin: 0;
    padding: 0 0 var(--mm-bas);
    border: 0;
    border-radius: 22px 22px 0 0;
    background: var(--em-card-bg);
    color: var(--em-body-color);
    box-shadow: 0 -12px 40px rgba(16, 24, 40, .25);
    transform: translateY(100%);
    transition: transform .28s cubic-bezier(.32, .72, 0, 1);
}

.mm-feuille[open] { display: flex; flex-direction: column; }
.mm-feuille.is-ouverte { transform: none; }
.mm-feuille.is-glisse { transition: none; }

.mm-feuille::backdrop {
    background: rgba(17, 18, 24, .5);
    opacity: 0;
    transition: opacity .28s ease;
}

.mm-feuille.is-ouverte::backdrop { opacity: 1; }

.mm-feuille-poignee { display: flex; flex-shrink: 0; justify-content: center; padding: 10px 0 6px; cursor: grab; touch-action: none; }
.mm-feuille-poignee span { width: 40px; height: 5px; border-radius: 3px; background: var(--em-border-strong); }

.mm-feuille-tete { display: flex; flex-shrink: 0; align-items: center; gap: 12px; padding: 4px 18px 14px; touch-action: none; }
.mm-feuille-titre { flex: 1 1 auto; margin: 0; font-size: 1.25rem; font-weight: 700; color: var(--em-heading-color); }

.mm-fermer {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--em-light);
    color: var(--em-heading-color);
    cursor: pointer;
}

.mm-fermer .em-icon { width: 20px; height: 20px; }

.mm-feuille-corps { flex: 1 1 auto; min-height: 0; padding: 0 18px 22px; overflow-y: auto; overscroll-behavior: contain; }

.mm-section { margin: 4px 2px 10px; font-size: .75rem; font-weight: 700; color: var(--em-muted); text-transform: uppercase; letter-spacing: .05em; }

.mm-fleche { flex-shrink: 0; width: 18px; height: 18px; color: var(--em-muted); }

/* Profil (en-tête de la feuille « Menu ») */
.mm-profil {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 16px;
    background: var(--em-band);
    color: inherit;
    text-decoration: none;
}

.mm-avatar { flex-shrink: 0; width: 44px; height: 44px; font-size: .9375rem; }
.mm-profil-texte { display: flex; flex: 1 1 auto; flex-direction: column; min-width: 0; line-height: 1.3; }
.mm-profil-texte strong { overflow: hidden; font-size: .9375rem; color: var(--em-heading-color); text-overflow: ellipsis; white-space: nowrap; }
.mm-profil-texte span { font-size: .8125rem; color: var(--em-muted); }

/* Pastilles d'icône colorées (tuiles, actions rapides) : une couleur par module */
.mm-tuile,
.mm-action { --mm-c: var(--em-primary); }
[data-icone="layout-dashboard"] { --mm-c: var(--em-primary); }
[data-icone="calendar"],
[data-icone="calendar-plus"] { --mm-c: #7e57c2; }
[data-icone="route"] { --mm-c: #e08e0b; }
[data-icone="map-pin"] { --mm-c: #f26b21; }
[data-icone="target"] { --mm-c: #1e9cc7; }
[data-icone="briefcase"] { --mm-c: #0b8a4c; }
[data-icone="users"],
[data-icone="user-cog"] { --mm-c: var(--em-primary); }
[data-icone="building"] { --mm-c: var(--em-purple); }
[data-icone="tag"],
[data-icone="tags"] { --mm-c: #d6458f; }
html[data-theme="dark"] [data-icone="briefcase"] { --mm-c: #34d399; }

.mm-pastille {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: color-mix(in srgb, var(--mm-c) 14%, transparent);
    color: var(--mm-c);
}

.mm-pastille .em-icon { width: 24px; height: 24px; }

/* Modules : grille de tuiles */
.mm-grille { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 0 0 20px; padding: 0; list-style: none; }

.mm-tuile {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    height: 100%;
    padding: 14px 6px 12px;
    border-radius: 16px;
    background: var(--em-band);
    font-size: .75rem;
    font-weight: 500;
    line-height: 1.25;
    color: var(--em-heading-color);
    text-align: center;
    text-decoration: none;
    transition: transform .15s ease, background-color .15s ease;
    -webkit-tap-highlight-color: transparent;
}

a.mm-tuile:active { transform: scale(.96); }
a.mm-tuile:hover { color: var(--em-heading-color); background: var(--em-light); }
.mm-tuile-texte { overflow-wrap: anywhere; }

.mm-tuile.is-active { background: rgba(var(--em-brand-rgb), .07); box-shadow: inset 0 0 0 1.5px rgba(var(--em-brand-rgb), .35); font-weight: 600; color: var(--mm-accent); }
.mm-tuile.is-indisponible { cursor: not-allowed; opacity: .55; }
.mm-bientot { position: absolute; top: 6px; right: 6px; padding: 1px 6px; border-radius: var(--em-radius-pill); background: var(--em-light); font-size: .5625rem; font-weight: 600; color: var(--em-muted); }

/* Actions rapides */
.mm-actions { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }

.mm-action {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border-radius: 16px;
    background: var(--em-band);
    color: inherit;
    text-decoration: none;
    transition: transform .15s ease, background-color .15s ease;
    -webkit-tap-highlight-color: transparent;
}

.mm-action:active { transform: scale(.98); }
.mm-action:hover { color: inherit; background: var(--em-light); }
.mm-action-texte { display: flex; flex: 1 1 auto; flex-direction: column; min-width: 0; line-height: 1.3; }
.mm-action-texte strong { font-size: .9375rem; color: var(--em-heading-color); }
.mm-action-texte span { font-size: .8125rem; color: var(--em-muted); }

/* Réglages : mode sombre, profil, déconnexion */
.mm-reglages { display: flex; flex-direction: column; gap: 8px; }

.mm-ligne {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 52px;
    padding: 0 14px;
    border: 0;
    border-radius: 14px;
    background: var(--em-band);
    font: inherit;
    font-size: .9375rem;
    font-weight: 500;
    color: var(--em-heading-color);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.mm-ligne:hover { color: var(--em-heading-color); background: var(--em-light); }
.mm-ligne > .em-icon:first-child { flex-shrink: 0; width: 22px; height: 22px; color: var(--em-muted); }
.mm-ligne-texte { flex: 1 1 auto; }
.mm-ligne--danger,
.mm-ligne--danger:hover,
.mm-ligne--danger > .em-icon:first-child { color: var(--em-danger); }

.mm-interrupteur { position: relative; flex-shrink: 0; width: 44px; height: 26px; border-radius: 13px; background: var(--em-border-strong); transition: background-color .2s ease; }
.mm-interrupteur::after { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); content: ""; transition: transform .2s ease; }
html[data-theme="dark"] .mm-interrupteur { background: var(--em-primary); }
html[data-theme="dark"] .mm-interrupteur::after { transform: translateX(18px); }

/* --- Mobile uniquement ---------------------------------------------------------------------- */
@media (max-width: 767.98px) {
    .mm { display: block; }

    /* Contenu et pied de page au-dessus de la barre d'onglets */
    .app-content { padding-bottom: calc(var(--mm-hauteur) + var(--mm-bas)); }

    /* Le menu passe dans la barre d'onglets : plus de bouton hamburger dans le header */
    .topbar-toggle { display: none; }

    /* Fenêtre « plannings du jour » du planning (en bas de l'écran) : au-dessus de la barre */
    .pl-popover { bottom: calc(var(--mm-hauteur) + var(--mm-bas) + 12px); }
}

@media (prefers-reduced-motion: reduce) {
    .mm-feuille,
    .mm-feuille::backdrop,
    .mm-ajouter-bouton { transition: none; }
}

@media print {
    .mm { display: none !important; }
}
