/**
 * eduDRC — anti-débordement petits écrans (mobile / tablette étroite).
 * Chargé en dernier sur les layouts publics, auth et tableau de bord.
 */

/* ——— Garde-fous globaux ——— */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: clip;
}

@supports not (overflow-x: clip) {
  body {
    overflow-x: hidden;
  }
}

img,
video,
svg,
canvas {
  max-width: 100%;
  height: auto;
}

pre,
code {
  max-width: 100%;
  overflow-x: auto;
}

/* Conteneurs flex / grid : autoriser le rétrécissement */
.container,
main,
.dash-workspace,
.dash-panel,
.dash-page,
.dash-surface,
.dash-hero,
.dash-card,
.dash-topbar,
.dash-topbar__left,
.dash-topbar__right,
.auth-layout,
.auth-card,
.home-nav__inner,
.hero__grid > * {
  min-width: 0;
  max-width: 100%;
}

/* ——— Listes déroulantes natives (<select>) ——— */
select,
.dash-select,
.sf-input:is(select),
.install-body select,
.auth-card select {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  text-overflow: ellipsis;
}

.dash-field,
.dash-form__grid > *,
.dash-form__row > *,
.sf-field,
.sf-filters .sf-field,
.install-field,
.auth-field {
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 1023px) {
  select.dash-select,
  select.sf-input,
  .install-body select,
  .auth-card select {
    font-size: max(16px, 0.92rem);
  }
}

/* Select2 (si chargé) : conteneur dans barres d’outils / grilles */
.select2-container {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

label:has(> .select2-container),
label:has(> select) {
  min-width: 0;
  max-width: 100%;
}

/* Boutons dans cartes et barres d’outils */
.btn,
.btn-dash,
.btn--primary,
.btn--ghost {
  max-width: 100%;
  box-sizing: border-box;
}

/* ——— Pied de page (dashboard + public) ——— */
@media (max-width: 1023px) {
  body.body-app-dashboard .sf-footer {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  html.dash-nav--icons-only body.body-app-dashboard .sf-footer {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ——— Tableau de bord : tables & toolbars ——— */
.dash-table-wrap,
.dash-table-wrap--users,
.dash-table-wrap--owner-users,
.dash-cashier-table-wrap,
.dash-reglement-report-table-wrap,
.dash-reglement-situation-table-wrap,
.sf-owner__table-wrap,
.dash-ech-health__table-wrap {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

@media (max-width: 640px) {
  .dash-table-wrap,
  .dash-table-wrap--users,
  .dash-table-wrap--owner-users {
    overflow-x: visible !important;
  }
}

@media (max-width: 1023px) {
  .dash-dt__search,
  .dash-dt__size,
  .dash-quick-filter .dash-input {
    width: 100%;
    min-width: 0 !important;
    max-width: 100%;
  }

  .dash-dt__left,
  .dash-dt__right,
  .dash-dt__label {
    width: 100%;
    min-width: 0;
  }

  .dash-topbar__school-switcher {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
  }

  .dash-topbar__school-switcher .select2-container,
  .dash-topbar__school-switcher select {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .dash-quick-filter,
  .dash-dt__toolbar {
    flex-wrap: wrap;
  }

  .dash-quick-filter .select2-container,
  .dash-quick-filter select {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
  }

  .dash-topbar__right {
    flex: 1 1 100%;
    min-width: 0;
    justify-content: flex-end;
  }

  .sf-owner__meter--inline,
  .sf-owner__meter-track--lg {
    min-width: 0 !important;
    flex: 1 1 auto;
  }
}

@media (max-width: 640px) {
  .dash-form__grid,
  .dash-ci-card .dash-form__grid,
  #sf-students-app .sf-grid,
  #sf-students-app .sf-grid-enroll {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .dash-page--echeances .dash-ech-quickbar__actions-tools {
    flex-wrap: wrap !important;
    justify-content: flex-start;
    margin-left: 0;
    width: 100%;
  }

  .dash-ech-toolbar-cta__label {
    white-space: normal;
  }
}

/* Grilles KPI / cartes */
.dash-grid,
.dash-bento--overview {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
}

/* ——— Règlement caisse : lignes denses ——— */
@media (max-width: 520px) {
  #reg-student-situation .dash-reglement-situation-dense__head--pay,
  #reg-student-situation .dash-reglement-situation-dense--payments .dash-reglement-situation-dense__item--pay {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  #reg-student-situation .dash-reglement-situation-dense__nums {
    flex-wrap: wrap;
    justify-content: flex-end;
    flex-shrink: 1;
    min-width: 0;
  }

  #reg-student-situation .dash-reglement-situation-dense__paid,
  #reg-student-situation .dash-reglement-situation-dense__rest,
  #reg-student-situation .dash-reglement-situation-dense__amount,
  #reg-student-situation .dash-reglement-situation-dense__meta {
    white-space: normal;
  }

  #reg-student-situation .dash-kpi--situation-compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  #reg-student-situation .dash-kpi--situation-compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ——— Élèves ——— */
@media (max-width: 900px) {
  #sf-students-app .sf-table .sf-row-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  #sf-students-app .sf-btn-with-icon {
    white-space: normal;
    text-align: center;
  }
}

/* ——— Secrétariat ——— */
@media (max-width: 640px) {
  .sec-alert-banner__text,
  .dash-page--dossiers .sec-dossiers-search {
    min-width: 0 !important;
    max-width: 100% !important;
    flex: 1 1 100%;
  }

  .dash-page--dossiers .sec-dossiers-notes {
    max-width: 100%;
    white-space: normal;
  }
}

/* ——— Accueil ——— */
.home-nav__brand {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.home-nav__brand-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

@media (max-width: 680px) {
  .floating-cta {
    white-space: normal;
    line-height: 1.25;
    text-align: center;
  }
}

/* ——— Auth ——— */
@media (max-width: 580px) {
  .auth-layout {
    padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
  }

  .auth-card,
  .auth-showcase {
    max-width: 100%;
  }
}
