/* =========================================================================
   layout.css - Structure de l'application
   -------------------------------------------------------------------------
   Bureau : barre en haut, puis 3 colonnes (photos | aperçu | réglages).
   Écran étroit : une seule colonne qui défile (aperçu, photos, réglages),
   avec la barre d'export collée en bas.
   ========================================================================= */

.app {
    display: grid;
    grid-template-columns: 272px minmax(0, 1fr) 316px;
    grid-template-rows: 60px minmax(0, 1fr); /* meme hauteur de barre que les autres outils Barbatools */
    grid-template-areas:
        "top    top   top"
        "photos stage settings";
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* -------------------------------------------------------------------------
   Barre supérieure
   ------------------------------------------------------------------------- */
.topbar {
    grid-area: top;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 18px 0 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    z-index: 5;
}

/* Espacements alignes sur VCF Contacts : 6 px entre les boutons, 10 px de chaque
   cote du separateur (6 px d'ecart + 4 px de marge), icones de 36 px. */
.topbar__actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.topbar__sep {
    width: 1px;
    height: 20px;
    margin: 0 4px;
    background: var(--line);
}

.topbar .icon-btn {
    width: 36px;
    height: 36px;
}

/* -------------------------------------------------------------------------
   Panneaux latéraux
   ------------------------------------------------------------------------- */
.panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--panel);
}

.panel--photos {
    grid-area: photos;
    border-right: 1px solid var(--line);
}

.panel--settings {
    grid-area: settings;
    border-left: 1px solid var(--line);
}

/* -------------------------------------------------------------------------
   Zone centrale (plan de travail pointillé)
   ------------------------------------------------------------------------- */
.stage {
    grid-area: stage;
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background-color: var(--stage);
    background-image: radial-gradient(var(--stage-dot) 1px, transparent 1.3px);
    background-size: 18px 18px;
    background-position: 9px 9px;
}

.stage__viewport {
    position: relative;
    flex: 1;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: 36px 36px 72px;
    overflow: hidden;
}

/* -------------------------------------------------------------------------
   Adaptations
   ------------------------------------------------------------------------- */
@media (max-width: 1180px) {
    .app { grid-template-columns: 236px minmax(0, 1fr) 296px; }
}

@media (max-width: 920px) {
    .app {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 100dvh;
        overflow: visible;
    }

    .topbar {
        position: sticky;
        top: 0;
        min-height: 60px; /* meme hauteur qu'en grand ecran et que les autres outils */
    }

    .stage {
        order: 1;
        flex: none;
        height: min(58vh, 560px);
        border-bottom: 1px solid var(--line);
    }

    .stage__viewport { padding: 20px 16px 64px; }

    .panel--photos {
        order: 2;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .panel--settings {
        order: 3;
        border-left: 0;
    }
}

@media (max-width: 560px) {
    .topbar { padding: 0 8px 0 12px; }
    .brand__tag,
    .topbar__add-label,
    .topbar__sep { display: none; }
}

/* -------------------------------------------------------------------------
   Menu Barbatools et menu de l'ecran etroit
   Grand ecran : icone Barbatools tout a droite de la barre (menu des autres
   outils). Ecran etroit (seuil ci-dessous, choisi par mesure) : l'icone, les
   raccourcis et le theme quittent la barre ; un chevron a cote du logo ouvre
   un menu avec le theme, les raccourcis, puis Barbatools et les autres outils.
   ------------------------------------------------------------------------- */
.brand__menu {
    display: none;
    place-items: center;
    flex: none;
    width: 22px;
    height: 34px;
    margin-left: -6px;
    padding: 0;
    border: 0;
    border-radius: 7px;
    background: none;
    color: var(--text-2);
    cursor: pointer;
}
.brand__menu:hover { background: var(--hover); color: var(--text); }
.brand__menu .icon { width: 16px; height: 16px; }

/* .popover.app-menu : plus precis que .popover (components.css, charge apres) */
.popover.app-menu {
    position: fixed;
    inset: auto;
    top: 64px;
    left: 8px;
    margin: 0;
    width: auto;
    min-width: 250px;
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 76px);
    overflow: auto;
    padding: 6px;
    font-size: 14px;
}
.popover.app-menu::backdrop { background: transparent; backdrop-filter: none; }

.app-menu__label {
    margin: 0;
    padding: 6px 10px 4px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-3);
}

.app-menu__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 40px;
    padding: 6px 10px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.app-menu__item:hover,
.app-menu__item:focus-visible { background: var(--hover); outline: none; }
.app-menu__item .icon { color: var(--text-2); }
.app-menu__check { margin-left: auto; visibility: hidden; }
.app-menu__item[aria-checked="true"] .app-menu__check { visibility: visible; color: var(--accent); }

.app-menu__sep { height: 1px; margin: 6px 4px; background: var(--line); }

@media (max-width: 720px) {
    .barba-desktop,
    #btn-help,
    #btn-theme,
    .topbar__sep { display: none; }
    .brand__menu { display: inline-grid; }
}

@media (min-width: 721px) {
    .popover.app-menu { display: none; }
}
