/* ==========================================================================
   AcademiZ — optimisations mobiles (panneaux Filament admin & parent)
   ========================================================================== */

/* Zones sûres (encoche, barre de geste) quand l'app est installée */
@supports (padding: env(safe-area-inset-top)) {
    @media (display-mode: standalone) {
        .fi-topbar > nav { padding-top: env(safe-area-inset-top); height: auto; min-height: 4rem; }
        .fi-sidebar-header { padding-top: env(safe-area-inset-top); height: auto; min-height: 4rem; }
        .fi-main { padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)); }
    }
}

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }

/* Retour tactile plus propre */
a, button, [role="button"], label { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

@media (max-width: 767px) {
    /* Évite le zoom automatique d'iOS sur les champs (police < 16px) */
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
    select,
    textarea,
    .fi-input,
    .fi-select-input,
    .choices__input,
    .choices__inner { font-size: 16px !important; }

    /* Contenu principal : marges réduites pour gagner de la place */
    .fi-main { padding-left: .75rem !important; padding-right: .75rem !important; }
    .fi-page > section { row-gap: 1rem; }
    .fi-header { gap: .75rem; }
    .fi-header-heading { font-size: 1.375rem !important; line-height: 1.75rem !important; }
    .fi-header-subheading { font-size: .875rem; }

    /* Boutons d'en-tête : pleine largeur, faciles à toucher */
    .fi-header .fi-ac { width: 100%; flex-wrap: wrap; }
    .fi-header .fi-ac > .fi-btn,
    .fi-header .fi-ac > * { flex: 1 1 auto; }
    .fi-btn { min-height: 2.5rem; }
    .fi-icon-btn { min-width: 2.25rem; min-height: 2.25rem; }

    /* Sections et cartes plus compactes */
    .fi-section-content { padding: 1rem !important; }
    .fi-section-header { padding: .875rem 1rem !important; }
    .fi-wi-stats-overview-stat { padding: 1rem !important; }

    /* Tableaux : défilement horizontal fluide plutôt que débordement de page */
    .fi-ta-ctn { border-radius: .75rem; }
    .fi-ta-content,
    .fi-main .overflow-x-auto { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
    .fi-ta-header-toolbar { flex-wrap: wrap; gap: .5rem; padding: .625rem .75rem !important; }
    .fi-ta-search-field { flex: 1 1 100%; }
    .fi-pagination { padding: .625rem .75rem; }

    /* Tableaux HTML des pages personnalisées (saisie des notes, statistiques…) */
    .fi-main .fi-page table:not(.fi-ta-table):not(.fi-fo-field-wrp table):not(.fi-in-entry-wrp table) {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Grilles de formulaire : une colonne */
    .fi-fo-component-ctn { gap: 1rem !important; }

    /* Fenêtres modales : quasi plein écran, en bas de l'écran (plus naturel au pouce) */
    .fi-modal-window { max-height: calc(100dvh - 1rem); }
    .fi-modal-window .fi-modal-content { overflow-y: auto; }
    .fi-modal-footer-actions { flex-direction: column-reverse; }
    .fi-modal-footer-actions > * { width: 100%; }

    /* Onglets : défilables sans retour à la ligne */
    .fi-tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
    .fi-tabs::-webkit-scrollbar { display: none; }
    .fi-tabs-item { flex: none; }

    /* Notifications : ne pas masquer toute la largeur */
    .fi-no { padding: .75rem !important; }

    /* Menu latéral : liens plus hauts pour le doigt */
    .fi-sidebar-item-button { min-height: 2.75rem; }
    .fi-sidebar { max-width: 85vw; }

    /* Images et médias ne dépassent jamais */
    .fi-main img, .fi-main video, .fi-main iframe, .fi-main canvas { max-width: 100%; }
    .fi-main canvas { height: auto !important; }

    /* Pages de connexion */
    .fi-simple-main { padding-left: 1rem !important; padding-right: 1rem !important; margin-top: 1rem !important; margin-bottom: 1rem !important; }
}

/* Boutons d'en-tête : retour à la ligne au lieu de déborder (tablettes, petits écrans) */
@media (max-width: 1279px) {
    .fi-header { flex-direction: column; align-items: flex-start !important; }
    .fi-header > * { max-width: 100%; min-width: 0; flex-shrink: 1 !important; }
    .fi-header .fi-ac { flex-wrap: wrap; }
}

/* Contenu principal ne déborde jamais de l'écran */
@media (max-width: 1023px) {
    .fi-main-ctn, .fi-main { min-width: 0; max-width: 100vw; }
    .fi-topbar .fi-global-search { flex: 1; }
}
