/**
 * Consultation de l'offre financière – responsive (mobile, tablette, desktop).
 * Toutes les règles sont scopées à la modal du wizard pour ne pas impacter le reste de l'app.
 */
#offreFinanciereWizardModal {
  --offre-wizard-preview-height: 600px;
  --offre-wizard-preview-min: 500px;
}

/* ----- Modal & header ----- */
#offreFinanciereWizardModal .modal-dialog {
  max-width: min(1600px, 100vw);
  margin-left: auto;
  margin-right: auto;
}

#offreFinanciereWizardModal .modal-header .d-flex.gap-3 {
  flex-wrap: wrap;
  gap: 0.5rem !important;
}

#offreFinanciereWizardModal .modal-header .modal-title {
  font-size: 1.1rem;
}

@media (min-width: 576px) {
  #offreFinanciereWizardModal .modal-header .modal-title {
    font-size: 1.25rem;
  }
}

#offreFinanciereWizardModal .modal-header .small.text-muted {
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}

/* ----- Barre d'étapes : visible sur tout support (cercle + label entiers) ----- */
#offreFinanciereWizardModal .offre-financiere-wizard-steps {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 0 0.75rem;
  min-height: 5rem;
}

#offreFinanciereWizardModal .offre-financiere-wizard-steps .d-flex.justify-content-between {
  flex-wrap: nowrap;
  min-width: min-content;
  gap: 0;
  align-items: flex-start;
  padding: 0 0.25rem;
}

#offreFinanciereWizardModal .offre-financiere-wizard-steps .flex-fill {
  flex: 0 0 auto;
  min-width: 3.5rem;
  max-width: 6rem;
}

@media (min-width: 768px) {
  #offreFinanciereWizardModal .offre-financiere-wizard-steps .flex-fill {
    min-width: 0;
    max-width: none;
    flex: 1 1 0%;
  }
}

#offreFinanciereWizardModal .offre-financiere-wizard-steps .rounded-circle {
  flex-shrink: 0;
}

#offreFinanciereWizardModal .offre-financiere-wizard-steps .flex-fill small,
#offreFinanciereWizardModal .offre-financiere-wizard-steps .flex-fill .d-block {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.2;
  display: block;
}

@media (min-width: 992px) {
  #offreFinanciereWizardModal .offre-financiere-wizard-steps .flex-fill small,
  #offreFinanciereWizardModal .offre-financiere-wizard-steps .flex-fill .d-block {
    white-space: normal;
  }
}

/* ----- Body padding ----- */
#offreFinanciereWizardModal .offre-financiere-wizard-body {
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

@media (min-width: 576px) {
  #offreFinanciereWizardModal .offre-financiere-wizard-body {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}

/* ----- Fiche de synthèse : responsive UNIQUEMENT en mobile/tablette (max 991px).
     Au-delà (desktop), on ne touche pas à .business-dashboard : la mise en page d’origine
     du template (une page, blocs conformes) est conservée pour affichage et capture PDF. ----- */
@media (max-width: 991px) {
  #offreFinanciereWizardModal .business-dashboard {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  #offreFinanciereWizardModal .business-dashboard .card {
    grid-column: 1 / -1 !important;
  }

  #offreFinanciereWizardModal .business-dashboard .info-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 991px) and (min-width: 768px) {
  #offreFinanciereWizardModal .business-dashboard {
    grid-template-columns: repeat(2, 1fr);
  }
  #offreFinanciereWizardModal .business-dashboard .indicators-business {
    grid-column: span 2;
  }
  #offreFinanciereWizardModal .business-dashboard .general-info {
    grid-column: span 2;
  }
  #offreFinanciereWizardModal .business-dashboard .financial-info,
  #offreFinanciereWizardModal .business-dashboard .score,
  #offreFinanciereWizardModal .business-dashboard .credit-opinion,
  #offreFinanciereWizardModal .business-dashboard .ratios {
    grid-column: span 1;
  }
  #offreFinanciereWizardModal .business-dashboard .risk {
    grid-column: span 2;
  }
}

@media (max-width: 991px) and (min-width: 576px) {
  #offreFinanciereWizardModal .business-dashboard .info-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Fiche synthèse : boutons et zone rendu */
#offreFinanciereWizardModal [data-controller*="fiche-synthese-charts"] .d-flex.justify-content-between {
  flex-wrap: wrap;
  gap: 0.5rem;
}

#offreFinanciereWizardModal #fiche-rendu-container {
  overflow-x: auto;
}

#offreFinanciereWizardModal [data-controller*="fiche-synthese-charts"] .d-flex.justify-content-end {
  flex-wrap: wrap;
}

/* ----- Pièces complémentaires ----- */
#offreFinanciereWizardModal .text-center.m-5 {
  margin: 1rem !important;
  padding: 0;
}

@media (min-width: 576px) {
  #offreFinanciereWizardModal .text-center.m-5 {
    margin: 1.5rem !important;
  }
}

@media (min-width: 768px) {
  #offreFinanciereWizardModal .text-center.m-5 {
    margin: 2rem !important;
  }
}

/* ----- Term Sheet & Validation offre : card header (document + inputs + signatures requises + état signature) ----- */
/* Mobile : tout en colonne, inputs et « Signatures requises » empilés */
#offreFinanciereWizardModal .card.shadow-sm .card-header {
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
}

#offreFinanciereWizardModal .card.shadow-sm .card-header > .d-flex.justify-content-center {
  flex-wrap: wrap;
  gap: 1rem;
}

#offreFinanciereWizardModal .card.shadow-sm .card-header .row.g-3 {
  width: 100%;
}

#offreFinanciereWizardModal .card.shadow-sm .card-header .row.g-3 .col-md-4 {
  flex: 0 0 100%;
  max-width: 100%;
}

/* Desktop : même ligne pour inputs position/page ET « Signatures requises » */
@media (min-width: 768px) {
  #offreFinanciereWizardModal .card.shadow-sm .card-header {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
  }

  #offreFinanciereWizardModal .card.shadow-sm .card-header > .d-flex.justify-content-center {
    flex-wrap: nowrap;
    flex: 1 1 auto;
    min-width: 0;
  }

  #offreFinanciereWizardModal .card.shadow-sm .card-header .row.g-3 {
    width: auto;
    flex: 0 0 auto;
    margin-bottom: 0 !important;
  }

  #offreFinanciereWizardModal .card.shadow-sm .card-header .row.g-3 .col-md-4 {
    flex: 0 0 33.333333%;
    max-width: 33.333333%;
  }

  /* « Signatures requises » reste sur la même ligne que les 3 inputs */
  #offreFinanciereWizardModal .card.shadow-sm .card-header > .d-flex.justify-content-center > .d-flex.flex-column.gap-2 {
    flex-shrink: 0;
  }
}

/* Bloc « État de la signature électronique » : pleine largeur sur petit écran */
#offreFinanciereWizardModal .offre-wizard-signature-state {
  width: 100%;
  min-width: 0;
}

@media (min-width: 992px) {
  #offreFinanciereWizardModal .offre-wizard-signature-state {
    width: 25%;
    flex: 0 0 25%;
  }
}

/* ----- Aperçu PDF (hauteur responsive) ----- */
#offreFinanciereWizardModal [data-controller="pdf-signature-preview"] {
  height: min(var(--offre-wizard-preview-height), 50vh);
  min-height: 280px;
  max-height: 70vh;
}

#offreFinanciereWizardModal [data-controller="pdf-signature-preview"] .position-relative.d-flex {
  min-height: 200px;
}

@media (min-width: 768px) {
  #offreFinanciereWizardModal [data-controller="pdf-signature-preview"] {
    height: var(--offre-wizard-preview-height);
    min-height: var(--offre-wizard-preview-min);
    max-height: none;
  }
  #offreFinanciereWizardModal [data-controller="pdf-signature-preview"] .position-relative.d-flex {
    min-height: 500px;
  }
}

#offreFinanciereWizardModal [data-controller="pdf-signature-preview"] .d-flex.justify-content-between.align-items-center {
  flex-wrap: wrap;
  gap: 0.25rem;
}

#offreFinanciereWizardModal [data-controller="pdf-signature-preview"] .btn {
  white-space: nowrap;
}

/* Zone « Aucun aperçu » */
#offreFinanciereWizardModal .border.rounded.bg-light.d-flex.flex-column.align-items-center.justify-content-center {
  min-height: 240px;
  height: 40vh;
}

@media (min-width: 768px) {
  #offreFinanciereWizardModal .border.rounded.bg-light.d-flex.flex-column.align-items-center.justify-content-center {
    min-height: 400px;
  }
}

/* ----- Modals imbriquées (GED Term Sheet / Offre validée) : dialog responsive ----- */
#offreFinanciereWizardModal .modal .modal-dialog.modal-xl {
  max-width: calc(100vw - 2rem);
  margin: 1rem auto;
}

@media (min-width: 1200px) {
  #offreFinanciereWizardModal .modal .modal-dialog.modal-xl {
    max-width: 1140px;
  }
}
