/* ==========================================================================
   MODAL COMPONENTS
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: var(--z-modal);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
  overscroll-behavior: contain;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1200px;
  /* margin auto = le centrage qui SURVIT à une modale plus haute que la
     fenêtre : avec le seul align-items:center de l'overlay, un enfant flex
     plus grand que son parent déborde des DEUX côtés et son haut devient
     inatteignable (classique WebKit). auto centre à l'identique quand ça
     tient, et cale en haut quand ça ne tient pas. */
  margin: auto;
  transform: scale(0.95);
  transition: transform var(--transition);
}

.modal-overlay.show .modal {
  /* none, PAS scale(1) : un transform — même identité — fait de la modale le
     BLOC CONTENEUR de tout position:fixed descendant (panneau msPanel d'un
     chip de filtre…), qui se retrouve alors rogné par overflow:hidden.
     L'animation d'entrée (scale .95 → identité) est inchangée. */
  transform: none;
}

.modal-md {
  /* Ajoutée 2026-08-27 : 'md' était passé à modal()/modal_start() sur 20+
     sites (airfact, plan, xorizo, portal, build) mais n'existait QUE dans
     build/configurator/dossiers.css — partout ailleurs la modale « moyenne »
     rendait à 1200px. Valeur = celle du seul définisseur historique. */
  max-width: 480px;
}

.modal-sm {
  max-width: 440px;
}

.modal-lg {
  max-width: 800px;
}

.modal-xl { 
  width: 95vw;
  max-width: 1200px;
}

.modal-xxl {
  width: 100%;
  max-width: 100% !important;
}

/* ── Modale de DOCUMENT (aperçu PDF / image) ───────────────────────────────
   Le corps EST le visualiseur : un <iframe> qui remplit la fenêtre.

   La HAUTEUR est fixe, et ce n'est pas un choix esthétique : .modal n'a qu'un
   max-height, sa hauteur vient donc de son contenu — et un <iframe> n'en
   apporte pas (height:100% d'un parent en hauteur auto se résout à auto). Sans
   cette ligne le cadre retombe sur les 150 px INTRINSÈQUES d'un <iframe> :
   mesuré au navigateur, 154 px au lieu de ~670 (airfact/cli/probe-apercu-pdf-
   modale.mjs, contrôle négatif). Même cause, même remède que .modal-tabbed.

   Le padding du corps tombe et son overflow passe à hidden : c'est l'iframe
   qui défile, pas la boîte autour. La règle NE VIT PAS en style inline (cf.
   CLAUDE.md : jamais de max-height/overflow inline sur .modal-body) — elle est
   portée par la classe, qui dit ce que la modale EST. */
.modal-doc { height: 88vh; }

.modal-doc .modal-body {
  padding: 0;
  overflow: hidden;
  background: var(--gray-100);
}

.modal-doc .modal-body > iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.modal-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.modal-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.modal-header-total {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--gray-100);
  border-radius: var(--radius);
}

.modal-header-total-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.modal-header-total-value {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius);
  transition: all var(--transition);
  line-height: 1;
}

.modal-close:hover { 
  background: var(--gray-100); 
}

.modal-body {
  padding: var(--space-4);
  overflow-y: auto;
  flex: 1;
  /* min-height:0 EXPLICITE : un enfant flex ne descend pas sous sa taille de
     contenu (min-height:auto) — overflow-y:auto le met déjà à zéro en spec,
     mais des moteurs l'ont raté ; sans lui le corps pousse la modale au-delà
     de max-height et le pied par-dessus le contenu. */
  min-height: 0;
  overscroll-behavior: contain;
}

.modal-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  background: var(--gray-50);
  flex-shrink: 0;
}

/* La béquille `.modal form { flex column }` est RETIRÉE (2026-08-28) : elle
   couvrait les <form> qui enveloppaient body+footer — les 11 derniers ont été
   convertis (le <form> vit DANS .modal-body, le bouton du footer s'y rattache
   par form="…"), et le balayage plateforme rend 0. Un <form> dans le body est
   un bloc ordinaire, il n'a pas besoin d'être un conteneur flex. */

.modal-body .form-fieldset:last-of-type {
  margin-bottom: 0;
}

/* ==========================================================================
   STEP-UP MODAL (sudo mode password prompt)
   ========================================================================== */

.step-up-help {
  margin: 0 0 var(--space-3);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.step-up-error {
  margin-top: var(--space-2);
  /* css-color-ok: rouge appuyé historique du step-up (c62828), plus sombre que --error */
  color: #c62828;
  font-size: 0.875rem;
}

/* ==========================================================================
   TABBED MODALS — fixed height so tab switches don't resize the modal
   ========================================================================== */

.modal-tabbed {
  height: 90vh;
}

.modal-tabbed .modal-body {
  flex: 1;
  min-height: 0; /* allow flex child to shrink for overflow scroll */
}

/* Tab navigation bar — sits between header and body as a direct flex child */
.pack-modal-tab-nav {
  display: flex;
  gap: 0;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.pack-modal-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.pack-modal-tab-btn:hover {
  color: var(--primary);
  background: var(--gray-50);
}

.pack-modal-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--gray-50);
}

/* Tab panes — only the active one is visible */
.pack-modal-tab-pane {
  display: none;
}

.pack-modal-tab-pane.active {
  display: block;
}

/* Enhanced Help Modal */
#conditionHelpModal .modal {
  max-width: 900px;
  max-height: 80vh;
  overflow-y: auto;
}

#conditionHelpModal .modal-body h4 {
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

#conditionHelpModal .modal-body h4:first-child {
  margin-top: 0;
}

#conditionHelpModal .modal-body code {
  background: linear-gradient(135deg, var(--state-slate-bg) 0%, var(--state-graphite-bg) 100%);
  padding: 3px 8px;
  border-radius: 4px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 13px;
  color: var(--state-slate-fg);
  /* css-color-ok: slate-300 historique, entre gray-300 et graphite */
  border: 1px solid #cbd5e1;
  font-weight: 500;
}

/* Grid Utilities for Help Modal */
#conditionHelpModal .grid {
  display: grid;
}

#conditionHelpModal .grid-cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

#conditionHelpModal .gap-2 {
  gap: 8px;
}

#conditionHelpModal .gap-6 {
  gap: 24px;
}

/* Modal accessibility */
/* Règle .modal-open .entity-dropdown supprimée 2026-08-27 — rien ne pose
   jamais .modal-open, et 1060 restait sous les 2000 de .modal-overlay. */

/* Mobile Responsive */
@media (max-width: 768px) {
  .modal-lg,
  .modal-xl {
    max-width: 95vw;
    margin: var(--space-4);
  }
  
  #conditionHelpModal .grid-cols-2 {
    grid-template-columns: 1fr;
  }
}