/* =========================================================
   RESPONSIVE.CSS — Couche responsive centrale
   Correctifs ciblés par breakpoint, complémentaires à app.css.

   Breakpoints retenus :
     ≥ 1280px   Desktop large
     1024–1279  Desktop / laptop
     768–1023   Tablette paysage
     600–767    Tablette portrait
     360–599    Mobile
     < 360      Très petit mobile

   Règles d'organisation :
   - Ne jamais dupliquer une règle déjà correcte dans app.css.
   - Ne jamais utiliser overflow-x:hidden sur html/body pour masquer
     un débordement : corriger la cause à la source.
   - Favoriser min(), max(), clamp(), minmax() et dvh.
   - Eviter !important sauf pour surcharger un composant tiers.
   ========================================================= */


/* ==========================================================
   0) FONDATION GLOBALE — safe areas + anti-overflow défensif
   ========================================================== */

/* Tous les médias se limitent à leur conteneur */
img, video, iframe, embed, svg {
  max-width: 100%;
}

/* Le code formaté défile plutôt que de déborder */
pre, code {
  overflow-x: auto;
  max-width: 100%;
}

/* Safe areas pour le header sticky */
.app-header {
  padding-left: max(var(--header-pad-x, 12px), env(safe-area-inset-left));
  padding-right: max(var(--header-pad-x, 12px), env(safe-area-inset-right));
}

/* Safe areas pour le panneau de filtres en mode drawer (≤640px, voir app.css) */
.filters-collapse-panel {
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

/* DataTables Dash : jamais à l'origine d'un overflow horizontal global */
.dash-spreadsheet-container,
.dash-table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* Plotly Graph : répond toujours à la largeur de son conteneur */
.js-plotly-plot,
.plot-container {
  max-width: 100%;
}

/* dvh : fallback pour les éléments qui utilisent 100vh */
@supports (height: 100dvh) {
  .modal-overlay-transparent {
    height: 100dvh;
  }
  .filters-collapse-panel {
    /* déjà à 100dvh dans app.css ≤640px, cohérence assurée */
  }
}


/* ==========================================================
   1) LOGIN CARD — largeur adaptative (320px friendly)
   ========================================================== */

/* app.css fixe width:350px → débordement sur 320–349px */
.login-card {
  width: min(350px, calc(100% - 24px));
}


/* ==========================================================
   2) SPLIT PANE — corrections min-width et touch targets
   ========================================================== */

/* Sur tablette/mobile (≤ 1100px) le split pane passe en
   flex-direction:column (app.css).
   La règle min-width:360px sur .pane-right s'applique alors
   à l'axe de largeur et provoque un overflow sur < 360px.
   On la neutralise ici. */
@media (max-width: 1100px) {
  .pane-right {
    min-width: 0;
  }
}

/* Sur mobile (≤ 599px) : layout empilé sans hauteur fixe.
   On remplace la hauteur fixe du conteneur (calc(100vh-260px) dans
   app.css ≤1100px) par auto, et on donne aux panneaux des bases
   explicites en px pour éviter la résolution d'un pourcentage indéfini
   dans un conteneur à hauteur automatique. */
@media (max-width: 599px) {
  .split-pane:not(.doc-split-pane) {
    height: auto;
    min-height: 0;
  }

  /* flex: 0 0 auto → taille déterminée par min/max-height explicites */
  .pane-left {
    flex: 0 0 auto;
    min-height: 200px;
    max-height: min(50dvh, 380px);
  }

  /* Panneau droit : prend le reste disponible */
  .pane-right {
    flex: 1 1 auto;
    min-height: 200px;
    max-height: none;
  }

  /* Splitter horizontal : plus large pour la visibilité */
  .splitter {
    flex-basis: 18px !important;
    cursor: row-resize;
  }

  /* Pane-toggle buttons : trop petits (22px) et redondants en layout
     empilé (le splitter horizontal suffit) */
  .pane-toggle-btn {
    display: none;
  }
}

/* Sur tablette portrait (600–767px) */
@media (min-width: 600px) and (max-width: 767px) {
  .split-pane:not(.doc-split-pane) {
    height: auto;
    min-height: 0;
  }

  .pane-left {
    flex: 0 0 auto;
    min-width: 0;
    min-height: 200px;
    max-height: min(45dvh, 360px);
  }

  .pane-right {
    min-width: 0;
    flex: 1 1 auto;
    min-height: 200px;
    max-height: none;
  }
}

/* Touch targets : écrans tactiles uniquement */
@media (hover: none) and (pointer: coarse) {
  /* Splitter : zone tactile élargie, visuel inchangé */
  .splitter {
    flex-basis: 20px !important;
  }

  /* Pane-toggle buttons : zone cliquable ≥ 44×44px */
  .pane-toggle-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
  }

  /* Pane scroll-top : zone ≥ 44×44px */
  .pane-scroll-top {
    width: 44px;
    height: 44px;
    font-size: 1.3rem;
    opacity: 0.45;
  }

  /* Modal close : zone ≥ 44×44px */
  .modal-close {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}


/* ==========================================================
   3) DOCUMENT / PDF — panneau sur mobile et tablette
   ========================================================== */

/* Sur tablette et mobile, la contrainte min-height:1123px (A4)
   et la hauteur fixe rendent le panneau inutilisable.
   On passe en layout empilé scrollable. */
@media (max-width: 1023px) {
  .doc-split-pane {
    height: auto !important;
    min-height: 0 !important;
    flex-direction: column;
  }

  /* Explorateur de fichiers : hauteur bornée, scrollable */
  .doc-split-pane > .pane-left {
    max-width: 100% !important;
    flex: 0 0 auto;
    min-height: 120px;
    max-height: min(35dvh, 300px);
    overflow-y: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  /* Visionneuse PDF : hauteur exploitable */
  .doc-split-pane > .pane-right {
    flex: 1 1 auto;
    min-height: 0;
    padding-left: 0;
    padding-top: 8px;
  }

  /* Ne PAS borner la hauteur de l'iframe à une fraction du viewport : le
     lecteur PDF natif défile alors en interne, et ce scroll tactile
     intra-iframe est notoirement peu fiable sur mobile (Safari iOS
     notamment) → symptôme "iframe coupé, impossible de scroller".
     On reprend la stratégie desktop (cf. .doc-split-pane plus haut) :
     iframe assez haute pour que ce soit la PAGE qui défile, pas l'iframe. */
  .pdf-inline-frame {
    height: max(140dvh, 900px);
  }
}


/* ==========================================================
   4) MODALS — mobile et tablette portrait
   ========================================================== */

@media (max-width: 599px) {
  /* Modale standard */
  .modal-card {
    width: calc(100vw - 16px);
    max-width: none;
    padding: var(--spacing-md);
    border-radius: var(--radius-lg);
    max-height: calc(100dvh - 16px);
  }

  /* Modale large */
  .modal-card.modal-card-lg {
    width: calc(100vw - 16px);
    max-width: none;
  }

  /* Modale fixe */
  .modal-card-fixed {
    width: calc(100vw - 16px);
    max-width: none;
    height: auto;
    max-height: calc(100dvh - 16px);
  }

  /* Corps scrollable : padding réduit */
  .modal-body-scroll {
    padding: var(--spacing-md);
  }

  /* Titre : espacement pour le bouton fermer */
  .modal-title {
    font-size: 1.15rem;
    padding-right: 40px;
  }

  /* Actions : s'empilent si besoin */
  .modal-actions {
    flex-wrap: wrap;
  }

  .modal-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
  }

  /* Header sticky dans les modales fixes */
  .modal-header-sticky {
    padding: var(--spacing-sm) var(--spacing-md);
  }
}

@media (min-width: 600px) and (max-width: 767px) {
  .modal-card {
    width: calc(100vw - 32px);
    max-width: none;
    max-height: calc(100dvh - 24px);
  }

  .modal-card-fixed {
    width: calc(100vw - 32px);
    max-width: none;
    max-height: calc(100dvh - 24px);
  }
}


/* ==========================================================
   5) HEADER — protection 320px et très petit mobile
   ========================================================== */

@media (max-width: 359px) {
  .app-header {
    gap: 4px;
    padding-inline: 6px;
  }

  /* Year dropdown plus compact */
  #year-dd,
  #year-dd .Select-control {
    min-width: 70px !important;
    width: 70px !important;
  }

  /* Masquer le texte des boutons header, ne garder que les icônes */
  .header-btn-label {
    display: none;
  }

  /* Titre de l'app masqué (déjà géré à 480px dans app.css,
     confirmé ici pour 320–359px) */
  .app-title {
    display: none;
  }
}


/* ==========================================================
   5b) NAVIGATION MOBILE — menu déroulant (≤ 767px)
   Remplace la barre d'onglets par un sélecteur stylisé.
   Design : barre de navigation compacte avec nom de l'onglet actif
   centré et chevron ancré à droite, sans chevauchement.
   ========================================================== */

/* Caché sur desktop */
.tabs-mobile-nav {
  display: none;
}

/* ── Visible sur mobile et tablette portrait ──────────────── */
@media (max-width: 767px) {

  /* Wrapper : bande de navigation */
  .tabs-mobile-nav {
    display: block;
    padding: 6px var(--page-gutter, 12px) 6px;
    background: var(--bg-app);
    border-bottom: 1px solid var(--border-color);
  }

  /* Masquer la barre d'onglets classique */
  .custom-tabs .tab-container,
  #tabs.tab-container {
    display: none !important;
  }

  /* ────────────────────────────────────────────────────────
     CONTROL — flex row : [icône nav] [nom onglet …] [chevron]
     react-select v1 utilise display:table par défaut.
     On force flex + on réinitialise les positions absolues
     internes pour éviter tout chevauchement.
  ──────────────────────────────────────────────────────── */

  .tabs-mobile-dd .Select-control {
    display: flex !important;
    align-items: center !important;
    height: 52px !important;
    min-height: 52px !important;
    padding: 0 !important;
    border: 1.5px solid var(--border-color) !important;
    border-radius: var(--radius-lg) !important;
    background: var(--bg-surface) !important;
    box-shadow: var(--shadow-sm) !important;
    cursor: pointer !important;
    transition: border-color 150ms ease, box-shadow 150ms ease !important;
    overflow: hidden !important;
  }

  .tabs-mobile-dd.is-open   .Select-control,
  .tabs-mobile-dd.is-focused .Select-control {
    border-color: var(--primary) !important;
    box-shadow: var(--focus-ring) !important;
  }

  /* Icône navigation (pseudo-element sur le control) */
  .tabs-mobile-dd .Select-control::before {
    content: "☰";
    flex: 0 0 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: var(--primary);
    border-right: 1px solid var(--border-color);
    height: 100%;
    background: var(--bg-subtle);
    pointer-events: none;
  }

  /* Wrapper interne : prend tout l'espace entre icône et flèche,
     centré horizontalement (les deux côtés sont à 44px). */
  .tabs-mobile-dd .Select-multi-value-wrapper {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    padding: 0 !important;
    height: 100% !important;
    text-align: center !important;
  }

  /* Nom de l'onglet actif : position static (neutralise l'absolu de react-select) */
  .tabs-mobile-dd .Select--single > .Select-control .Select-value {
    position: static !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    height: 100% !important;
    padding: 0 !important;
    font-size: 1.05rem !important;
    font-weight: 700 !important;
    color: var(--primary) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    text-align: center !important;
  }

  .tabs-mobile-dd .Select-value-label {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    display: block !important;
    text-align: center !important;
  }

  /* Placeholder (avant sélection) */
  .tabs-mobile-dd .Select-placeholder {
    position: static !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 100% !important;
    width: 100% !important;
    padding: 0 !important;
    font-size: 1.05rem !important;
    font-weight: 600 !important;
    color: var(--text-muted) !important;
    text-align: center !important;
  }

  /* Input caché */
  .tabs-mobile-dd .Select-input {
    position: absolute !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  /* ── Zone flèche : ancré à droite, jamais sur le texte ── */
  .tabs-mobile-dd .Select-arrow-zone {
    flex: 0 0 44px !important;
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
  }

  /* Remplace le triangle CSS par un vrai chevron textuel */
  .tabs-mobile-dd .Select-arrow {
    display: none !important;
  }

  .tabs-mobile-dd .Select-arrow-zone::after {
    content: "▾";
    font-size: 1.35rem;
    line-height: 1;
    color: var(--primary);
    display: block;
    transition: transform 200ms ease;
  }

  .tabs-mobile-dd.is-open .Select-arrow-zone::after {
    transform: rotate(180deg);
  }

  /* ── MENU DÉROULANT ─────────────────────────────────────── */

  .tabs-mobile-dd .Select-menu-outer {
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-lg) !important;
    overflow: hidden !important;
    z-index: 1300 !important;
    margin-top: 4px !important;
    /* Largeur identique au contrôle */
    left: 0 !important;
    right: 0 !important;
  }

  .tabs-mobile-dd .Select-menu {
    max-height: min(65dvh, 480px) !important;
    overflow-y: auto !important;
    padding: 4px 0 !important;
  }

  /* ── ITEMS DE NAVIGATION ─────────────────────────────────── */

  .tabs-mobile-dd .Select-option {
    display: flex !important;
    align-items: center !important;
    height: 52px !important;
    padding: 0 16px !important;
    font-size: 1rem !important;
    font-weight: 500 !important;
    color: var(--text-primary) !important;
    background: var(--bg-surface) !important;
    border-left: 3px solid transparent !important;
    transition: background 120ms ease, border-color 120ms ease !important;
    cursor: pointer !important;
  }

  /* Séparateur subtil entre items */
  .tabs-mobile-dd .Select-option + .Select-option {
    border-top: 1px solid var(--border-color) !important;
  }

  /* Hover */
  .tabs-mobile-dd .Select-option.is-focused {
    background: var(--bg-subtle) !important;
    color: var(--text-primary) !important;
    border-left-color: var(--border-strong) !important;
  }

  /* Onglet actif : accent teal à gauche */
  .tabs-mobile-dd .Select-option.is-selected {
    background: var(--primary-light) !important;
    color: var(--primary) !important;
    font-weight: 700 !important;
    border-left-color: var(--primary) !important;
  }

  /* Hover sur l'item actif */
  .tabs-mobile-dd .Select-option.is-selected.is-focused {
    background: #d3eeeb !important;
  }
}

/* Sur tablette paysage (768–1023px) : barre d'onglets classique,
   dropdown mobile bien masqué */
@media (min-width: 768px) {
  .tabs-mobile-nav {
    display: none !important;
  }
}

/* ==========================================================
   6) ONGLETS — breakpoint 600–767px + touch targets
   ========================================================== */

/* Sur mobile, les onglets défilent horizontalement (déjà dans app.css).
   On s'assure juste que la hauteur min est tactile. */
@media (max-width: 767px) {
  .custom-tab,
  .custom-tab--selected {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    flex-shrink: 0;
  }
}

@media (max-width: 599px) {
  .custom-tab,
  .custom-tab--selected {
    padding: 10px 12px;
    font-size: 0.82rem;
  }
}


/* ==========================================================
   7) FORMULAIRES — filtres, champs de date, inputs
   ========================================================== */

/* Champs de filtre fixes (160px) : pleine largeur sur mobile */
@media (max-width: 599px) {
  .filter-field {
    width: 100%;
  }

  .filter-field .DateInput,
  .filter-field .SingleDatePickerInput,
  .filter-field .SingleDatePickerInput__withBorder {
    width: 100% !important;
  }

  /* Ligne de filtres gynemap : verticale */
  .gynemap-filter-row {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  .gynemap-filter-row .filter-block {
    width: 100%;
  }
}

/* Sur tablette portrait : champs légèrement élargis */
@media (min-width: 600px) and (max-width: 767px) {
  .filter-field {
    width: 140px;
  }
}


/* ==========================================================
   8) IZICOD / FAQ — breakpoint manquant 600–767px
   ========================================================== */

/* app.css traite 720px et 721–1024px.
   Le range 600–767px (tablette portrait) n'est pas couvert. */
@media (min-width: 600px) and (max-width: 767px) {
  #page5-content .row-wrap,
  #page3-content .row-wrap {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
  }

  #page5-content .form-field,
  #page3-content .form-field {
    flex: 1 1 calc(50% - var(--spacing-md));
    min-width: 200px;
  }

  #page5-content .btn,
  #page3-content .btn {
    width: auto;
  }

  #page5-content .izicod-codelist-row {
    align-items: center;
  }

  #page3-content .search-row-bar {
    flex-wrap: wrap;
    gap: 10px;
  }

  #page3-content .search-half {
    flex: 1 1 100%;
    max-width: 100%;
  }
}


/* ==========================================================
   9) GYNEMAP — white-space: nowrap → overflow sur mobile
   ========================================================== */

/* Ces éléments ont white-space:nowrap dans app.css
   et peuvent déborder sur < 600px */
@media (max-width: 599px) {
  .gynemap-detail-subtitle {
    white-space: normal;
  }

  .gynemap-detail-summary {
    white-space: normal;
  }
}


/* ==========================================================
   10) ADMIN PAGE — responsive
   ========================================================== */

@media (max-width: 767px) {
  .admin-page-header {
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    align-items: flex-start;
  }

  .admin-page-title {
    font-size: 1.3rem;
  }
}

@media (max-width: 599px) {
  .admin-page-title {
    font-size: 1.15rem;
  }

  .admin-main-tabs {
    gap: 4px !important;
  }

  .admin-main-tab {
    padding: 6px 12px !important;
    font-size: 0.82rem !important;
  }

  /* Tables d'admin : scroll horizontal plutôt qu'overflow */
  .admin-tab-access-grid {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}


/* ==========================================================
   11) PCS BUILDER — touch targets et petits mobiles
   ========================================================== */

@media (max-width: 599px) {
  /* Options radio : hauteur tactile suffisante */
  .pcs-option-label {
    padding: 10px 12px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* Hero card : padding réduit */
  .pcs-hero-card {
    padding: var(--spacing-md);
  }
}


/* ==========================================================
   12) CARTES — padding progressif
   ========================================================== */

@media (max-width: 599px) {
  .card {
    padding: var(--spacing-sm) var(--spacing-md);
  }
}

@media (max-width: 359px) {
  .card {
    padding: var(--spacing-sm);
  }
}


/* ==========================================================
   13) TYPOGRAPHIE — hiérarchie responsive
   ========================================================== */

@media (max-width: 599px) {
  /* Titres de section */
  .card-title {
    font-size: 0.78rem;
  }

  /* Texte des badges */
  .badge.tips,
  .badge.warn {
    font-size: 0.8rem;
  }
}

@media (max-width: 359px) {
  /* Légère réduction de la taille de base sur très petits mobiles */
  body {
    font-size: 0.9375rem; /* 15px au lieu de 16px */
  }
}


/* ==========================================================
   14) INDEXTAB — source filter sur mobile
   ========================================================== */

/* Le breakpoint 680px dans app.css s'occupe du passage en colonne.
   Renforcement pour < 600px. */
@media (max-width: 599px) {
  .indextab-source-filter {
    flex: 1 1 100%;
    min-width: 0;
    width: 100%;
  }
}


/* ==========================================================
   15) BOUTONS FLOTTANTS — safe area insets
   ========================================================== */

/* Bouton scroll global (bas-droit) */
@media (max-width: 599px) {
  .global-scroll-btn {
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
  }
}


/* ==========================================================
   16) NOTIF OVERLAY — z-index correct
   ========================================================== */

/* S'assure que l'overlay de notification ne passe pas
   devant les modales mais reste au-dessus du contenu */
.notif-overlay {
  z-index: 1500;
}


/* ==========================================================
   17) TABLETTE PAYSAGE (768–1023px) — fine-tuning
   ========================================================== */

@media (min-width: 768px) and (max-width: 1023px) {
  /* Pane-toggle buttons : taille intermédiaire sur tablette */
  .pane-toggle-btn {
    width: 28px;
    height: 28px;
  }

  /* Modales : conserver la largeur 90% mais limiter à dvh */
  .modal-card,
  .modal-card-fixed {
    max-height: calc(100dvh - 32px);
  }
}


/* ==========================================================
   18) DESKTOP/LAPTOP (1024–1279px) — aucune régression
   ========================================================== */

/* Vérification des éléments fixes à cette taille :
   pas de modification nécessaire — app.css couvre déjà
   1024–1100px et 1101px+. */


/* ==========================================================
   19) PROTECTION ANTI-OVERFLOW — règles défensives finales
   ========================================================== */

/* Tous les conteneurs de pages Dash : ne jamais déborder */
#page1-content,
#page2-content,
#page3-content,
#page4-content,
#page5-content,
#page6-content,
#page7-content,
#page8-content,
#page9-content,
#page10-content,
#page11-content,
#page12-content,
#page13-content {
  min-width: 0;
  max-width: 100%;
}

/* Flex containers : éviter le débordement des enfants */
.row-wrap,
.filter-bar,
.toolbar,
.header-controls {
  min-width: 0;
}

/* Dropdowns Dash : ne jamais dépasser leur conteneur */
.dd,
.Select,
.Select-control {
  min-width: 0;
}
