#template-menu {
    --tm-yellow: #fee100;
    --tm-dark: #333333;

    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 2147483647;

    display: flex;
    flex-direction: column;
    width: clamp(240px, 26vw, 340px);
    max-height: min(70vh, 640px);

    font-family: system-ui, sans-serif;
    background: #fff;
    border: 2px solid var(--tm-dark);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
    overflow: hidden;
}

#template-menu * {
    box-sizing: border-box;
}

/* Reset : le menu est injecté dans la page, on neutralise tout le CSS du site
   (Pico, boutons/inputs full-width, marges, focus rings…) sur ses contrôles. */
#template-menu button,
#template-menu input,
#template-menu a,
#template-menu strong {
    all: unset;
    box-sizing: border-box;
    font-family: inherit;
}

#template-menu ul,
#template-menu li {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* --- Header (toggle + titre + filtre) --- */
#template-menu header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem .5rem;

    background-image: linear-gradient(45deg, var(--tm-yellow) 25%, var(--tm-dark) 25%, var(--tm-dark) 50%, var(--tm-yellow) 50%, var(--tm-yellow) 75%, var(--tm-dark) 75%, var(--tm-dark) 100%);
    background-size: 56.57px 56.57px;
}

#template-menu .tm-toggle {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 6px;
    background: #fff;
    color: var(--tm-dark);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

#template-menu .tm-toggle::before {
    content: '\2716'; /* ✖ */
}

#template-menu .tm-title {
    color: #fff;
    text-shadow: 1px 1px var(--tm-dark);
    font-size: .85rem;
    white-space: nowrap;
}

#template-menu .tm-filter {
    flex: 1 1 auto;
    min-width: 0;
    padding: .25rem .5rem;
    border: 1px solid var(--tm-dark);
    border-radius: 6px;
    background: #fff;
    color: #333;
    font-size: .8rem;
}

#template-menu .tm-filter:focus-visible,
#template-menu .tm-toggle:focus-visible {
    outline: 2px solid var(--tm-dark);
    outline-offset: 1px;
}

/* --- Corps scrollable --- */
#template-menu .tm-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: .5rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

#template-menu .tm-section {
    display: flex;
    flex-direction: column;
}

#template-menu .tm-section-title {
    position: sticky;
    top: -.5rem;
    padding: .25rem 0;
    background: #fff;
}

#template-menu .tm-section-title strong {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #888;
}

#template-menu .tm-item a {
    display: flex;
    flex-direction: column;
    padding: .3rem .4rem;
    border-radius: 6px;
    color: #555;
    text-decoration: none;
    line-height: 1.25;
}

#template-menu .tm-item a span {
    font-size: .85rem;
    font-weight: 600;
}

#template-menu .tm-item a i {
    font-size: .65rem;
    font-style: normal;
    color: #999;
}

#template-menu .tm-item a:hover {
    background: #f4f4f4;
    color: #000;
}

#template-menu .tm-item.selected a {
    background: var(--tm-yellow);
    color: #000;
}

#template-menu .tm-item.selected a i {
    color: #555;
}

#template-menu .tm-empty {
    padding: .5rem .4rem;
    font-size: .75rem;
    color: #999;
}

/* --- État réduit : un bouton rond propre --- */
#template-menu.closed {
    width: auto;
    max-height: none;
    border: 0;
    border-radius: 999px;
    background: none;
    box-shadow: none;
    overflow: visible;
    cursor: pointer;
}

#template-menu.closed header {
    padding: 0;
    background: none;
}

#template-menu.closed .tm-title,
#template-menu.closed .tm-filter,
#template-menu.closed .tm-body {
    display: none;
}

#template-menu.closed .tm-toggle {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 999px;
    background: var(--tm-yellow);
    color: var(--tm-dark);
    font-size: 1.25rem;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
}

#template-menu.closed .tm-toggle::before {
    content: '\2630'; /* ☰ */
}

@media screen and (max-width: 700px) {
    #template-menu {
        right: .5rem;
        bottom: .5rem;
        width: calc(100vw - 1rem);
        max-height: 60vh;
    }
}
