/* ═══════════════════════════════════════════════════════════════
    AdminPanel — Responsive
    Breakpoints :
        > 900px   → desktop  (sidebar fixe, layout complet)
        768–900px → tablette (sidebar overlay, 1 colonne)
        < 768px   → mobile   (sidebar overlay, filtres overlay, barre fixe)
        < 480px   → petit mobile
   ═══════════════════════════════════════════════════════════════ */

/* ───────────────────────────────────────────────
    Tableau expandable — desktop (colonnes toutes visibles)
   ─────────────────────────────────────────────── */

.admin-table__th-expand,
.admin-table__td-expand { display: none; }
.admin-table__row-detail    { display: none; }
.admin-table__row-detail.open { display: table-row; }

/* ───────────────────────────────────────────────
    Barre recherche + bouton filtres
   ─────────────────────────────────────────────── */

.admin-search__row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.admin-search__row .admin-search__form { flex: 1; }

/* Badge filtre actif */
.admin-search__filter-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--accent);
    color: #fff;
    border-radius: 9px;
    font-size: 0.7rem;
    font-weight: 600;
    position: absolute;
    top: 2px;
    right: 2px;
}

/* Bouton icône filtre — masqué sur desktop */
.admin-search__filter-toggle {
    display: none;
    position: relative;
}

/* Overlay backdrop */
.admin-filter__overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 198;
}
.admin-filter__overlay.active { display: block; }

/* Utilitaires mobile show/hide */
.admin-btn--show-mobile { display: none; }

/* ───────────────────────────────────────────────
    Tablette (≤ 900px) — sidebar en overlay
   ─────────────────────────────────────────────── */
@media (max-width: 900px) {
    /* Sidebar → overlay glissant depuis la gauche */
    .admin-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        height: 100dvh;
        width: 15rem;
        transform: translateX(-100%);
        transition: transform var(--transition);
        z-index: 200;
    }

    .admin-sidebar.mobile-open {
        transform: translateX(0);
    }

    .admin-sidebar__overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 199;
    }
    .admin-sidebar__overlay.active { display: block; }

    /* Formulaires : 2 colonnes → 1 */
    .form-grid-2 { grid-template-columns: 1fr; }

    /* Contenu légèrement réduit */
    .admin-content { padding: 1.25rem; }

    /* Stat cards : 2 colonnes max */
    .admin-stats__grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

    /* Table : scroll horizontal sur tablette, retiré sur petit écran */
    .admin-table__wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .admin-table { min-width: 600px; }
    .admin-table { table-layout: auto; }

    /* Expand : colonnes secondaires masquées, bouton visible */
    .admin-table__col-secondary          { display: none; }
    .admin-table__th-expand, .admin-table__td-expand  { display: table-cell; }

    .admin-table__td-expand {
        width: 32px;
        padding: 0 0.25rem !important;
        vertical-align: middle;
    }

    .admin-table__expand-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 28px;
        height: 28px;
        border: 1px solid var(--border-light);
        background: none;
        border-radius: var(--radius);
        color: var(--text-muted);
        transition: all var(--transition);
    }

    .admin-table__expand-btn:hover,
    .admin-table__expand-btn.open {
        background: var(--bg-hover);
        color: var(--text-main);
        border-color: var(--border-light);
    }

    .admin-table__expand-btn .admin-table__expand-icon {
        transition: transform var(--transition);
    }

    .admin-table__expand-btn.open .admin-table__expand-icon {
        transform: rotate(90deg);
    }

    /* Ligne de détail dépliée */
    .admin-table__row-detail.open > td {
        padding: 0.5rem 1rem 0.875rem;
        background: var(--bg-hover);
        border-bottom: 1px solid var(--border);
        line-height: 2.5;
    }

    .admin-table__detail-grid {
        gap: 0.6rem 1.5rem;
        width: 85vw;
    }

    .admin-table__detail-item {
        display: flex;
        flex-direction: column;
        gap: 0.15rem;
        min-width: 90px;
    }

    .admin-table__detail-label {
        font-size: 0.68rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--text-muted);
    }

    .admin-table__detail-value {
        font-size: 0.85rem;
        color: var(--text-main);
        word-break: break-word;
    }
}

/* ───────────────────────────────────────────────
   Mobile large (≤ 768px)
   ─────────────────────────────────────────────── */

@media (max-width: 768px) {
    /* Affichage/masquage adaptatif */
    .admin-btn--hide-mobile { display: none !important; }
    .admin-btn--show-mobile { display: flex; }
    .admin-search__filter-toggle { display: flex; }

    /* Actions page détail — flottantes en bas à droite */
    .admin-page__actions {
        position: fixed;
        bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        right: calc(1rem + env(safe-area-inset-right, 0px));
        z-index: 150;
        gap: 0.5rem;
    }

    /* Sidebar filtre → overlay depuis la droite */
    .admin-filter__sidebar {
        position: fixed;
        top: 0;
        right: 0;
        height: 100%;
        height: 100dvh;
        width: 220px;
        max-height: none;
        border-radius: 0;
        border-left: 1px solid var(--border);
        border-right: none;
        transform: translateX(100%);
        transition: transform var(--transition);
        z-index: 200;
        overflow-y: auto;
    }
    .admin-filter__sidebar.mobile-open { transform: translateX(0); }
    .admin-filter__sidebar .admin-filter__body {
        max-height: none;
        overflow-y: visible;
    }

    /* Forcer 1 colonne même si filter-collapsed */
    .admin-list__layout,
    .admin-list__layout.filter-collapsed { grid-template-columns: 1fr; }

    /* Fermer le chevron sidebar filtre, afficher × */
    #filterToggle svg { display: none; }
    #filterToggle::after { content: '✕'; font-size: 1rem; line-height: 1; }



    /* Dropdown kebab menu ouvert vers le haut */
    .admin-page__actions .admin-menu__dropdown {
        top: auto;
        bottom: calc(100% + 4px);
        right: 0;
    }

    /* Delete zone : empiler sur mobile */
    .admin-danger-zone {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ───────────────────────────────────────────────
   Bulk / group actions — mobile wrap
   ─────────────────────────────────────────────── */

@media (max-width: 768px) {
    .admin-group-action__bar {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .admin-group-action__btns {
        width: 100%;
        flex-wrap: wrap;
        justify-content: flex-end;
    }
    .admin-group-action__selects {
        width: 100%;
        flex-wrap: wrap;
    }
    .admin-group-action__select {
        flex: 1 1 calc(50% - 0.25rem);
        min-width: 0;
    }
}

@media (max-width: 480px) {
    /* Bulk action bar — tous les boutons pleine largeur */
    .admin-group-action__selects .btn,
    .admin-group-action__btns > .btn {
        width: 100%;
    }
    /* History filters — selects uniformes pleine largeur */
    .history-filter-select {
        width: 100%;
    }
}

/* ───────────────────────────────────────────────
   Mobile (≤ 600px)
   ─────────────────────────────────────────────── */

@media (max-width: 600px) {
    /* Topbar */
    .admin-topbar { padding: 0 0.875rem; gap: 0.5rem; justify-content: space-around; }
    .admin-topbar__breadcrumb { display: none; }
    .admin-topbar__user span { display: none; } /* masque le nom, garde l'avatar */
    .admin-search__row {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        margin-bottom: 1rem;
        justify-content: space-between;
    }
    /* Contenu */
    .admin-content {
        padding: 0.875rem;
        padding-bottom: 4.5rem; /* espace pour pagination fixe */
    }

    /* Page header → colonne */
    .admin-page__header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    /* Stats → 2 colonnes serrées */
    .admin-stats__grid { grid-template-columns: 1fr 1fr; gap: 0.75rem; }
    .admin-stats__value { font-size: 1.4rem; }

    /* Card padding réduit */
    .admin-card__body { padding: 0.875rem; }
    .admin-card__header { padding: 0.75rem 0.875rem; }

    /* Pagination fixée en bas (liste uniquement) */
    #list-content .admin-pagination {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-card);
        border-top: 1px solid var(--border);
        z-index: 140;
        gap: 1.5rem;
        padding: 0.6rem 1rem;
        padding-bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px));
        justify-content: space-between;
    }

    /* Table encore plus compacte */
    .admin-table th { width: 43vw }
    .admin-table td { padding: 0.6rem 0.75rem; font-size: 0.82rem; }
    .admin-table { min-width: 95vw; }

    /* Formulaires */
    .form-group { gap: 0.3rem; }
    .number-field input,
    .select-field select,
    .form-control { font-size: 0.95rem; } /* plus lisible sur mobile */

    /* Vue détail */
    .detail-row { grid-template-columns: 1fr; gap: 0.25rem; }
    .detail-key { padding-top: 0; }

    /* Alert */
    .admin-alert { padding: 0.7rem 0.875rem; font-size: 0.85rem; }
}

/* ───────────────────────────────────────────────
   Petit mobile (≤ 480px) — 320px inclus
   ─────────────────────────────────────────────── */
@media (max-width: 320px) {
    .admin-table {
        min-width: 0;
        table-layout: fixed;
        width: 100%;
        display: block;
    }
}
@media (min-width:321px) and (max-width: 480px) {
    /* Table : supprime min-width, layout fixe pour contrôler les colonnes */
    .admin-table {
        min-width: 0;
        table-layout: fixed;
        width: 100%;
    }

    .admin-table__wrapper { overflow-x: auto; }

    /* Largeurs fixées via <colgroup> — priorité absolue dans table-layout:fixed,
        contourne le bug Chrome mobile où l'apparition de row-detail déclenche
        un recalcul qui ignore les largeurs définies sur th/td */
    .admin-table col.admin-table__col-bulk    { width: 12%; }
    .admin-table col.admin-table__col-id      { width: 13%; }
    .admin-table col.admin-table__col-expand  { width: 9%;  }
    .admin-table col.admin-table__col-actions { width: 20%; }
    /* col-main (1er visible) = ~46% auto — colonnes proportionnelles sur tous les mobiles */

    .admin-table td:nth-child(2) .admin-table__td-content {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        -webkit-line-clamp: unset;
    }

    /* Empêche admin-table__detail-grid (width:85vw héritée de ≤900px) de forcer
       le tableau à s'élargir et de déclencher un recalcul de layout */
    .admin-table__detail-grid {
        width: auto;
        max-width: 100%;
    }

    /* id-badge plus compact */
    .admin-badge--id { padding: 0.1rem 0.3rem; font-size: 0.72rem; }


    /* Stats → 1 colonne */
    .admin-stats__grid { grid-template-columns: 1fr; }

    /* Actions tableau : wrap */
    .admin-table__actions { flex-wrap: wrap; }

    /* Page title plus petit */
    .admin-page__title { font-size: 1.1rem; }

    /* Card form pleine largeur */
    .admin-card--form { max-width: 100%; }

    /* Search bar pleine largeur */
    .admin-search__input { max-width: 100%; }
    .search-bar input { min-width: 0; }

    /* Form actions : pleine largeur */
    .admin-form__actions {
        flex-direction: column-reverse;
        gap: 0.5rem;
    }
    .admin-form__actions .btn { width: 100%; justify-content: center; }

    /* Sidebar filtre plus large sur très petit écran */
    .admin-filter__sidebar { width: 55vw; border-left: none; }
}

/* ───────────────────────────────────────────────
    Dashboard resources — override après les règles génériques
    La table Resources n'a pas de colonne ID en première position,
    elle doit rester en table-layout:auto.
   ─────────────────────────────────────────────── */

@media (max-width: 480px) {
    .admin-table.admin-table--resources {
        table-layout: auto;
    }
    .admin-table.admin-table--resources th:first-child,
    .admin-table.admin-table--resources td:first-child {
        width: auto;
    }
    .admin-table.admin-table--resources th:last-child,
    .admin-table.admin-table--resources td:last-child {
        white-space: nowrap;
    }
}

/* ───────────────────────────────────────────────
    Large desktop (≥ 1400px)
   ─────────────────────────────────────────────── */

@media (min-width: 1400px) {
    .admin-content { padding: 2rem 2.5rem; }
    .admin-stats__grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}

@media (max-width: 480px) {
    .admin-group-edit__perm-grid { gap: 0.5rem 1rem; }
    .admin-group-edit__perm-grid .boolean-field { min-width: 110px; }
    .admin-group-edit__section-header { flex-direction: column; align-items: flex-start; }
}
