/*
 * Panneau latéral droit — composant `side-panel`, porté de Refactia
 * (Billing : components/side-panel.css, doc/design/side-panel.md, 18/10/2026).
 *
 * Coquille commune de tous les panneaux droits de Badging : détail d'un élément
 * de liste, filtres, relevés… La page garde sa fonction d'ouverture/fermeture
 * et sa classe d'état historique (`right-menu-visible`, `is-open`,
 * `right-toolMenu-visible`) ; ce fichier porte seulement l'apparence, le
 * mouvement et le comportement responsive. Comportement partagé (aria, Échap,
 * focus) : public/assets/js/components/side-panel.js.
 *
 * Mêmes classes, même géométrie et mêmes neutres que Refactia (Billing HEAD
 * 65064bda) ; seules les teintes de marque passent au bleu Badging (--ds-brand,
 * --ds-accent). Chargé après les CSS de page
 * (components/design_system_overlay_stylesheets.html.twig).
 * Registre : doc/design-system/README.md.
 *
 * Les règles de coquille utilisent `.side-panel.side-panel` exprès : plusieurs
 * CSS de page positionnent encore `.right-menu` / `.filter-right-menu` avec
 * deux classes. La coquille partagée doit gagner tant que ces règles existent.
 */

.side-panel {
    --sp-width: 390px;
    --sp-top: 75px; /* sous l'en-tête .nav-bar (app/navbar/nav-bar.css) */
    --sp-edge: color-mix(in srgb, var(--ds-brand, #1f6fff) 24%, transparent);

    /* Neutres et états : valeurs de Refactia (Billing HEAD 65064bda, gamme bleu nuit). */
    --sp-surface-solid: #ffffff;
    --sp-surface-grouped: #f4f7f9;
    --sp-surface-hover: #eaf1f4;
    --sp-surface-active: #e0eaee;
    --sp-line: #e3eaf0;
    --sp-line-strong: #d2dce8;

    --sp-text: #18304d;
    --sp-text-secondary: #5f7897;
    --sp-text-tertiary: #8297ad;

    /* Marque : bleu Badging au lieu du turquoise. */
    --sp-accent: var(--ds-brand, #1f6fff);
    --sp-accent-strong: var(--ds-accent, #1555d5);
    --sp-accent-soft: rgba(31, 111, 255, 0.14);

    --sp-success: #1f7a50;
    --sp-success-soft: #e3f5ec;
    --sp-warning: #94600f;
    --sp-warning-soft: #fdf1dc;
    --sp-danger: #b93a41;
    --sp-danger-soft: #fde8e9;
    --sp-info: #2c6aa8;
    --sp-info-soft: #e6f0fa;
    --sp-neutral: #50657c;
    --sp-neutral-soft: #eef2f6;

    --sp-radius-group: 14px;
    --sp-radius-control: var(--ds-radius-md, 12px);
    --sp-shadow: -20px 0 44px rgba(12, 23, 42, 0.18);
    --sp-ease: cubic-bezier(0.32, 0.72, 0, 1);
    --sp-duration: 360ms;
}

.side-panel--wide {
    --sp-width: 520px;
}

/* -------------------------------------------------------------------------- */
/* Coquille                                                                   */
/* -------------------------------------------------------------------------- */

.side-panel.side-panel {
    position: fixed;
    z-index: var(--z-layer-sidepanel, 10040);
    inset: var(--sp-top) 0 0 auto;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    width: min(var(--sp-width), calc(100vw - 14px));
    max-width: none;
    height: auto;
    min-height: 0;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    color: var(--sp-text);
    font-family: var(--ds-font, "Plus Jakarta Sans", sans-serif);
    background: var(--sp-surface-solid);
    border: 0;
    border-left: 1px solid var(--sp-edge);
    border-radius: 0;
    box-shadow: var(--sp-shadow);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    clip-path: none;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(100%);
    transition:
        transform var(--sp-duration) var(--sp-ease),
        opacity 220ms ease,
        visibility 0s linear var(--sp-duration);
}

.side-panel.side-panel:is(.right-menu-visible, .is-open, .right-toolMenu-visible) {
    /* Repose la position : des règles historiques mettent right: auto sur l'état ouvert. */
    inset: var(--sp-top) 0 0 auto;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
    transition:
        transform var(--sp-duration) var(--sp-ease),
        opacity 160ms ease,
        visibility 0s;
}

.side-panel:focus {
    outline: none;
}

/* Des règles de page donnent un display explicite à certaines parties :
 * l'attribut hidden doit quand même gagner dans le panneau. */
.side-panel [hidden] {
    display: none !important;
}

.side-panel:focus-visible {
    outline: 2px solid var(--sp-accent);
    outline-offset: 2px;
}

/* -------------------------------------------------------------------------- */
/* En-tête                                                                    */
/* -------------------------------------------------------------------------- */

.side-panel__header {
    position: relative;
    display: flex;
    flex: 0 0 auto;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    box-sizing: border-box;
    width: 100%;
    min-height: 0;
    margin: 0;
    padding: 20px 20px 16px 24px;
    background: transparent;
    border-bottom: 1px solid var(--sp-line);
}

.side-panel__titles {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    padding-top: 2px;
}

.side-panel__eyebrow {
    margin: 0;
    color: var(--sp-accent-strong);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.side-panel__title {
    margin: 0;
    padding: 0;
    color: var(--sp-text);
    font-family: var(--ds-font, "Plus Jakarta Sans", sans-serif);
    font-size: 19px;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
}

.side-panel__subtitle {
    margin: 0;
    color: var(--sp-text-secondary);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.45;
}

/* Fermeture officielle (`button.app-close`), toujours en haut à droite. */
.side-panel__header > .side-panel__close,
.side-panel__header > .app-close {
    position: relative;
    inset: auto;
    order: 2;
    flex: 0 0 auto;
    margin: 0;
}

/* -------------------------------------------------------------------------- */
/* Corps                                                                      */
/* -------------------------------------------------------------------------- */

.side-panel__body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 24px;
    box-sizing: border-box;
    width: 100%;
    min-height: 0;
    height: auto;
    margin: 0;
    padding: 20px 24px 24px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(24, 48, 77, 0.22) transparent;
}

.side-panel__body::-webkit-scrollbar {
    width: 8px;
}

.side-panel__body::-webkit-scrollbar-thumb {
    background: rgba(24, 48, 77, 0.2);
    background-clip: padding-box;
    border: 2px solid transparent;
    border-radius: 999px;
}

/* Conteneurs dynamiques historiques rendus dans le corps : même rythme.
 * Trois classes (une de plus que Refactia) : des CSS de page historiques
 * (list-global-cool_1.css…) leur donnent encore une marge interne. */
.side-panel > .side-panel__body > :is(.dynamique-content, .dynamique-filter-content) {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 24px;
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow: visible;
}

/* Titres historiques (h3 de `title-form`) quand le JS de la page les réécrit dans l'en-tête. */
.side-panel__header :is(h2, h3).side-panel__title {
    margin: 0;
}

/* -------------------------------------------------------------------------- */
/* Sections et champs                                                         */
/* -------------------------------------------------------------------------- */

.side-panel__section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.side-panel__section-title {
    margin: 0;
    padding: 0;
    color: var(--sp-text-secondary);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.side-panel__section-hint {
    margin: -6px 0 0;
    color: var(--sp-text-tertiary);
    font-size: 12.5px;
    line-height: 1.45;
}

.side-panel__fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    min-width: 0;
}

.side-panel__fields--two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 12px;
}

.side-panel .input-field__label {
    color: var(--sp-text);
    font-size: 13px;
}

/* -------------------------------------------------------------------------- */
/* Contenu de détail                                                          */
/* -------------------------------------------------------------------------- */

.side-panel__hero {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.side-panel__hero-meta {
    margin: 0;
    color: var(--sp-text-tertiary);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.side-panel__hero-title {
    margin: 0;
    color: var(--sp-text);
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.side-panel__hero-value {
    margin: 0;
    color: var(--sp-text);
    font-size: 26px;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.side-panel__hero-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.side-panel__badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-sizing: border-box;
    min-height: 24px;
    padding: 3px 10px;
    color: var(--sp-neutral);
    background: var(--sp-neutral-soft);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.3;
    white-space: nowrap;
}

.side-panel__badge::before {
    width: 6px;
    height: 6px;
    flex: 0 0 auto;
    background: currentColor;
    border-radius: 50%;
    content: "";
}

.side-panel__badge--success { color: var(--sp-success); background: var(--sp-success-soft); }
.side-panel__badge--warning { color: var(--sp-warning); background: var(--sp-warning-soft); }
.side-panel__badge--danger  { color: var(--sp-danger);  background: var(--sp-danger-soft); }
.side-panel__badge--info    { color: var(--sp-info);    background: var(--sp-info-soft); }
.side-panel__badge--accent  { color: var(--sp-accent-strong); background: var(--sp-accent-soft); }

/* Liste clé / valeur, groupée comme une liste en retrait. */
.side-panel__facts {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0 14px;
    background: var(--sp-surface-grouped);
    border-radius: var(--sp-radius-group);
}

.side-panel__fact {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    min-width: 0;
    padding: 11px 0;
    border-bottom: 1px solid var(--sp-line);
}

.side-panel__fact:last-child {
    border-bottom: 0;
}

.side-panel__fact-label {
    flex: 0 1 auto;
    min-width: 0;
    margin: 0;
    color: var(--sp-text-secondary);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
}

.side-panel__fact-value {
    flex: 0 1 auto;
    min-width: 0;
    margin: 0;
    color: var(--sp-text);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    text-align: right;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.side-panel__fact--emphasis .side-panel__fact-label {
    color: var(--sp-text);
    font-weight: 700;
}

.side-panel__fact--emphasis .side-panel__fact-value {
    font-size: 15px;
    font-weight: 800;
}

.side-panel__fact--positive .side-panel__fact-value { color: var(--sp-success); }
.side-panel__fact--negative .side-panel__fact-value { color: var(--sp-danger); }

/* Alerte dans le panneau (avertissement, refus, information). */
.side-panel__notice {
    display: flex;
    gap: 10px;
    margin: 0;
    padding: 12px 14px;
    color: var(--sp-info);
    background: var(--sp-info-soft);
    border-radius: var(--sp-radius-control);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.5;
}

.side-panel__notice > :is(p, div) {
    margin: 0;
}

.side-panel__notice--warning { color: var(--sp-warning); background: var(--sp-warning-soft); }
.side-panel__notice--danger  { color: var(--sp-danger);  background: var(--sp-danger-soft); }
.side-panel__notice--success { color: var(--sp-success); background: var(--sp-success-soft); }

/* Valeur à copier (lien, identifiant, code…). */
.side-panel__copy {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 6px 6px 6px 12px;
    background: var(--sp-surface-grouped);
    border-radius: var(--sp-radius-control);
}

.side-panel__copy-value {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    color: var(--sp-text);
    font-size: 13px;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.side-panel__copy-button {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 6px 12px;
    color: var(--sp-accent-strong);
    background: var(--sp-surface-solid);
    border: 1px solid var(--sp-line-strong);
    border-radius: 999px;
    font: inherit;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 160ms ease, border-color 160ms ease;
}

.side-panel__copy-button:hover {
    border-color: var(--sp-accent);
    background: var(--sp-accent-soft);
}

.side-panel__copy-button:focus-visible {
    outline: 2px solid var(--sp-accent);
    outline-offset: 2px;
}

/* Liste d'actions : une ligne par action, groupée comme une liste en retrait. */
.side-panel__actions {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 4px;
    list-style: none;
    background: var(--sp-surface-grouped);
    border-radius: var(--sp-radius-group);
}

.side-panel__action {
    display: flex;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    width: 100%;
    min-height: 48px;
    margin: 0;
    padding: 8px 10px;
    color: var(--sp-text);
    background: transparent;
    border: 0;
    border-radius: 10px;
    font-family: var(--ds-font, "Plus Jakarta Sans", sans-serif);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 160ms ease, color 160ms ease;
}

.side-panel__action:hover {
    color: var(--sp-text);
    background: var(--sp-surface-hover);
}

.side-panel__action:active {
    background: var(--sp-surface-active);
}

.side-panel__action:focus-visible {
    outline: 2px solid var(--sp-accent);
    outline-offset: -2px;
}

.side-panel__action:is(:disabled, [aria-disabled="true"]) {
    opacity: 0.5;
    cursor: not-allowed;
}

.side-panel__action-icon {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    color: var(--sp-accent-strong);
    background: var(--sp-accent-soft);
    border-radius: 9px;
}

.side-panel__action-icon > :is(svg, img, i) {
    width: 17px;
    height: 17px;
    font-size: 15px;
}

.side-panel__action-label {
    flex: 1 1 auto;
    min-width: 0;
}

.side-panel__action-meta {
    flex: 0 0 auto;
    color: var(--sp-text-tertiary);
    font-size: 12px;
    font-weight: 600;
}

.side-panel__action::after {
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    margin-right: 4px;
    border-top: 2px solid var(--sp-text-tertiary);
    border-right: 2px solid var(--sp-text-tertiary);
    transform: rotate(45deg);
    content: "";
    opacity: 0.7;
}

.side-panel__action--danger,
.side-panel__action--danger:hover {
    color: var(--sp-danger);
}

.side-panel__action--danger .side-panel__action-icon {
    color: var(--sp-danger);
    background: var(--sp-danger-soft);
}

.side-panel__action--danger::after,
.side-panel__action--plain::after {
    display: none;
}

/* État vide / aucune sélection. */
.side-panel__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin: auto 0;
    padding: 32px 12px;
    color: var(--sp-text-secondary);
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
}

.side-panel__empty-title {
    margin: 0;
    color: var(--sp-text);
    font-size: 15px;
    font-weight: 700;
}

/* -------------------------------------------------------------------------- */
/* Pied                                                                       */
/* -------------------------------------------------------------------------- */

.side-panel__footer {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    box-sizing: border-box;
    width: 100%;
    margin: 0;
    padding: 14px 24px 18px;
    background: rgba(255, 255, 255, 0.72);
    border-top: 1px solid var(--sp-line);
}

/* Les classes de page gardées sur le pied (ex. user-management-filter-actions)
 * ne doivent pas changer son orientation. */
.side-panel > .side-panel__footer {
    flex-direction: row;
    flex-wrap: nowrap;
}

/* Refactia pose btndpm-classique puis btndpm ; Badging pose app-btn--secondary puis app-btn--primary. */
.side-panel__footer > :is(.app-btn, .btndpm, .btndpm-classique, button, a) {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    min-height: 44px;
    margin: 0;
    text-align: center;
}

.side-panel__footer > :is(.app-btn, .btndpm, .btndpm-classique):only-child {
    flex: 1 1 100%;
}

/* -------------------------------------------------------------------------- */
/* Mobile : plein écran, comme avant                                          */
/* -------------------------------------------------------------------------- */

@media (max-width: 780px) {
    .side-panel.side-panel,
    .side-panel.side-panel:is(.right-menu-visible, .is-open, .right-toolMenu-visible) {
        z-index: var(--z-layer-mobile-sidepanel, 10060);
        inset: 0;
        width: 100%;
        border-left: 0;
        box-shadow: none;
    }

    .side-panel__header {
        padding: 18px 16px 14px 20px;
    }

    .side-panel__body {
        padding: 18px 20px 24px;
    }

    .side-panel__footer {
        padding: 12px 20px calc(14px + env(safe-area-inset-bottom, 0px));
    }

    .side-panel__fields--two {
        grid-template-columns: minmax(0, 1fr);
    }

    html:has(.side-panel:is(.right-menu-visible, .is-open, .right-toolMenu-visible)) {
        overflow: hidden;
        overscroll-behavior: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .side-panel.side-panel,
    .side-panel.side-panel:is(.right-menu-visible, .is-open, .right-toolMenu-visible) {
        transform: none;
        transition: opacity 120ms linear, visibility 0s linear 120ms;
    }

    .side-panel.side-panel:is(.right-menu-visible, .is-open, .right-toolMenu-visible) {
        transition: opacity 120ms linear, visibility 0s;
    }

    .side-panel__action,
    .side-panel__copy-button {
        transition: none;
    }
}
