/*
 * Modale unique (audit cohérence UI, V2) — socle <dialog> natif.
 * Cf. templates/components/ui/_modal.html.twig + assets/js/ui/modal.js.
 * Couleurs unies (pas de gradient), border-radius conforme.
 */
dialog.upk-modal {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    overflow: visible;
    display: grid;
    place-items: center;
}

dialog.upk-modal:not([open]) {
    display: none;
}

dialog.upk-modal::backdrop {
    background: rgba(15, 23, 42, 0.55);
}

.upk-modal__panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(92vw, 640px);
    max-height: 88vh;
    background: #ffffff;
    border-radius: 0.75rem;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
    overflow: hidden;
    will-change: transform;
}

.upk-modal__handle {
    cursor: move;
    touch-action: none;
}

.upk-modal__handle button {
    cursor: pointer;
}

/* Poignées de redimensionnement (4 bords + 4 coins, à l'intérieur du panneau) */
.upk-modal__rz {
    position: absolute;
    z-index: 3;
    touch-action: none;
}

.upk-modal__rz--n  { top: 0; left: 12px; right: 12px; height: 6px; cursor: ns-resize; }
.upk-modal__rz--s  { bottom: 0; left: 12px; right: 12px; height: 6px; cursor: ns-resize; }
.upk-modal__rz--e  { right: 0; top: 12px; bottom: 12px; width: 6px; cursor: ew-resize; }
.upk-modal__rz--w  { left: 0; top: 12px; bottom: 12px; width: 6px; cursor: ew-resize; }
.upk-modal__rz--ne { top: 0; right: 0; width: 12px; height: 12px; cursor: nesw-resize; }
.upk-modal__rz--nw { top: 0; left: 0; width: 12px; height: 12px; cursor: nwse-resize; }
.upk-modal__rz--se { bottom: 0; right: 0; width: 14px; height: 14px; cursor: nwse-resize; }
.upk-modal__rz--sw { bottom: 0; left: 0; width: 12px; height: 12px; cursor: nesw-resize; }

/* Grip visible sur le coin bas-droit */
.upk-modal__rz--se::after {
    content: "";
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 8px;
    height: 8px;
    border-right: 2px solid #cbd5e1;
    border-bottom: 2px solid #cbd5e1;
}

dialog.upk-modal.upk-modal--fullscreen .upk-modal__rz {
    display: none;
}

/* Plein écran / restaurer */
dialog.upk-modal.upk-modal--fullscreen {
    padding: 0;
}

dialog.upk-modal.upk-modal--fullscreen .upk-modal__panel {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    transform: none !important;
}

@media (prefers-reduced-motion: no-preference) {
    /* Sur [open] uniquement (pas :not(--fullscreen)) : sinon la restauration depuis le
       plein écran re-matche le sélecteur et rejoue l'animation d'entrée. */
    dialog.upk-modal[open] .upk-modal__panel {
        animation: upkModalIn 140ms ease-out;
    }

    @keyframes upkModalIn {
        from {
            opacity: 0;
            transform: translateY(8px);
        }
        to {
            opacity: 1;
        }
    }
}
