/* SIG-FDSU RDC — surcharge tablette / mobile uniquement.
   Référence desktop = état pré-mobile `e391c3d` (264 px, styles.css).
   Seuils :
     desktop  ≥ 1081 px  → layout historique, aucune réduction ici
     tablette   768–1080 px → rail compact / drawer
     mobile   ≤ 767 px  → drawer hamburger, 1 colonne
   Ces règles ne doivent plus déformer le desktop. */

:root {
  --sig-bp-desktop: 1081px;
  --sig-bp-tablet: 1080px;
  --sig-bp-mobile: 767px;
  --sig-touch: 44px;
}

/* ── Tablette : icônes par défaut, 2 colonnes ─ */
@media (min-width: 768px) and (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 76px 1fr;
  }

  .app-shell[data-sidebar-mode="expanded"] {
    grid-template-columns: 248px 1fr;
  }

  .app-shell[data-sidebar-mode="compact"] {
    grid-template-columns: 76px 1fr;
  }

  .app-shell[data-sidebar-mode="hidden"] {
    grid-template-columns: 0 1fr;
  }

  .sidebar {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    justify-content: flex-start;
  }

  .nav-menu {
    width: 100%;
    margin-top: 0;
  }

  .main-content {
    padding: 10px 16px;
    min-width: 0;
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    padding: 8px 14px;
    gap: 12px;
  }

  .topbar-actions {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .search-field,
  .notification-button,
  .profile-card {
    width: auto;
  }

  .sidebar-toggle-btn,
  .sidebar-reopen-btn,
  .notification-button {
    width: var(--sig-touch);
    height: var(--sig-touch);
  }
}

/* ── Mobile : drawer overlay, header compact, 1 colonne ─────────────────── */
@media (max-width: 767px) {
  html,
  body {
    -webkit-text-size-adjust: 100%;
  }

  .app-shell,
  .app-shell[data-sidebar-mode="expanded"],
  .app-shell[data-sidebar-mode="compact"],
  .app-shell[data-sidebar-mode="hidden"] {
    display: block;
    height: auto;
    min-height: calc(100dvh - var(--footer-height, 32px));
    grid-template-columns: none;
  }

  .main-content {
    padding: 8px 10px 12px;
    min-height: calc(100dvh - var(--footer-height, 32px));
    height: auto;
    min-width: 0;
  }

  .content-area {
    overflow-x: auto;
    min-width: 0;
  }

  .module-panel {
    padding: 12px;
    min-width: 0;
    overflow: visible;
  }

  .module-panel h2 {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 12px;
    min-width: 0;
  }

  .topbar-left {
    min-width: 0;
    flex: 1 1 auto;
    gap: 8px;
    overflow: hidden;
  }

  .topbar-left > div {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
  }

  .page-context,
  .topbar-pill {
    display: none;
  }

  .page-title {
    font-size: 1.05rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    max-width: 100%;
  }

  .topbar-actions {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    width: auto;
    flex: 0 0 auto;
  }

  .search-field.global-search-field {
    display: none;
  }

  #command-center-trigger {
    width: var(--sig-touch);
    min-width: var(--sig-touch);
    height: var(--sig-touch);
    padding: 0;
    justify-content: center;
  }

  .command-center-trigger-label,
  #command-center-trigger .command-center-trigger-kbd {
    display: none !important;
  }

  .command-center-trigger-icon {
    font-size: 1rem;
  }

  .profile-card > div,
  .profile-chevron {
    display: none;
  }

  .profile-card {
    width: var(--sig-touch);
    min-width: var(--sig-touch);
    height: var(--sig-touch);
    padding: 0;
    justify-content: center;
  }

  .sidebar-toggle-btn,
  .notification-button {
    width: var(--sig-touch);
    height: var(--sig-touch);
    min-width: var(--sig-touch);
  }

  .sidebar-reopen-btn {
    display: none !important;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(88vw, 320px);
    max-width: 320px;
    z-index: 240;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
    transform: translateX(-105%);
    transition: transform 0.22s var(--ease-premium, ease);
    pointer-events: auto;
    opacity: 1;
    overflow-y: auto;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.35);
  }

  .app-shell[data-sidebar-mode="hidden"] .sidebar,
  .app-shell[data-sidebar-mode="compact"] .sidebar {
    padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
    width: min(88vw, 320px);
    max-width: 320px;
    opacity: 1;
    pointer-events: auto;
    overflow: auto;
  }

  .app-shell[data-sidebar-mode="hidden"] .sidebar > *:not(.sidebar-reopen-btn),
  .app-shell[data-sidebar-mode="compact"] .brand-copy,
  .app-shell[data-sidebar-mode="compact"] .nav-label,
  .app-shell[data-sidebar-mode="compact"] .sidebar-footer,
  .app-shell[data-sidebar-mode="compact"] .nav-group-title,
  .app-shell[data-sidebar-mode="compact"] .nav-group-chevron {
    display: revert !important;
  }

  .app-shell[data-sidebar-mode="compact"] .nav-item {
    justify-content: flex-start;
    grid-template-columns: auto 1fr;
    padding: 10px 12px;
  }

  .app-shell[data-sidebar-mode="compact"] .nav-group-toggle {
    display: flex;
    grid-template-columns: none;
    pointer-events: auto;
    padding: 8px 4px;
  }

  .app-shell[data-sidebar-mode="compact"] .nav-group-panel,
  .app-shell[data-sidebar-mode="compact"] .nav-group-panel[hidden] {
    display: none !important;
  }

  .app-shell[data-sidebar-mode="compact"] .nav-group[data-open="true"] .nav-group-panel {
    display: grid !important;
    justify-items: stretch;
  }

  body.mobile-nav-open .sidebar {
    transform: translateX(0);
  }

  .mobile-nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 230;
    background: rgba(2, 6, 23, 0.55);
    border: 0;
    padding: 0;
    margin: 0;
  }

  body.mobile-nav-open .mobile-nav-overlay {
    display: block;
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  .nav-item,
  .nav-group-toggle {
    min-height: var(--sig-touch);
  }

  .app-footer {
    height: auto;
    min-height: var(--footer-height);
    padding: 6px 10px max(6px, env(safe-area-inset-bottom, 0px));
    gap: 8px;
    font-size: 0.68rem;
  }

  .app-footer-group {
    gap: 10px;
    flex-wrap: wrap;
  }

  /* Formulaires globaux : 1 colonne, labels au-dessus, pas de zoom iOS */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select,
  textarea {
    max-width: 100%;
    font-size: 16px;
  }

  label {
    display: block;
  }

  .ff-form-grid,
  .ff-review-kv {
    grid-template-columns: 1fr;
  }

  .ff-dialog {
    width: min(96vw, 620px);
  }

  .ff-dialog-actions,
  .ff-step-nav,
  .ff-toolbar,
  .ff-card-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .ff-dialog-actions button,
  .ff-step-nav button,
  .ff-toolbar button,
  .secondary-button,
  .primary-button,
  button.login-submit {
    min-height: var(--sig-touch);
  }

  /* Tableaux : scroll horizontal contrôlé, données conservées */
  .content-area table,
  .module-panel table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Cartes Leaflet : cibles tactiles, carte prioritaire */
  .leaflet-control-zoom a {
    width: var(--sig-touch) !important;
    height: var(--sig-touch) !important;
    line-height: var(--sig-touch) !important;
    font-size: 18px !important;
  }

  .leaflet-popup-content {
    min-width: 0;
    font-size: 0.9rem;
  }

  .dashboard-grid,
  .metrics-grid,
  .governance-kpis,
  .knowledge-kpi-grid {
    grid-template-columns: 1fr;
  }

  .summary-grid,
  .dashboard-kpi-grid,
  .telecom-executive-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .summary-grid .dashboard-card:has(.dashboard-metric-note:not(:empty)),
  .dashboard-kpi-grid .dashboard-card:has(.dashboard-metric-note:not(:empty)) {
    grid-column: 1 / -1;
  }

  .summary-grid .dashboard-card,
  .dashboard-kpi-grid .dashboard-card,
  .national-kpi-grid .dashboard-card,
  .national-kpi-card {
    min-width: 0;
    max-width: 100%;
    align-items: flex-start;
    height: auto;
  }

  .dashboard-metric,
  .summary-label,
  .summary-value,
  .dashboard-metric-note {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .dashboard-card .dashboard-metric .summary-label {
    white-space: normal;
    line-height: 1.25;
  }

  .dashboard-metric-note {
    display: block;
    white-space: normal;
  }

  .national-kpi-grid {
    grid-template-columns: 1fr;
  }

  /* Tuiles Leaflet : ne jamais hériter d'un max-width / blend mobile. */
  .leaflet-container .leaflet-tile,
  .leaflet-container img.leaflet-tile,
  .leaflet-container .leaflet-tile-pane img {
    max-width: none !important;
    max-height: none !important;
    mix-blend-mode: normal !important;
  }

  .content-area .secondary-button,
  .content-area .primary-button,
  .pwa-bar button,
  .ff-dialog-actions button,
  .pwa-assignment-card button {
    width: 100%;
    min-height: var(--sig-touch);
    white-space: normal;
    justify-content: center;
  }

  .pwa-bar,
  .pwa-assignment-card .ff-dialog-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 767px) and (hover: none) {
  .leaflet-tooltip {
    display: none !important;
  }
}

/* Téléphone en paysage (ex. 844×390) : même composition header/KPI, pas le layout desktop. */
@media (max-height: 500px) and (max-width: 960px) {
  .page-context,
  .topbar-pill,
  .search-field.global-search-field,
  .command-center-trigger-label,
  #command-center-trigger .command-center-trigger-kbd {
    display: none !important;
  }

  .topbar,
  .topbar-left,
  .topbar-left > div,
  .page-title {
    min-width: 0;
  }

  .page-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .topbar-actions {
    flex: 0 0 auto;
  }

  .summary-grid,
  .dashboard-kpi-grid,
  .telecom-executive-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .leaflet-container .leaflet-tile,
  .leaflet-container img.leaflet-tile {
    max-width: none !important;
    mix-blend-mode: normal !important;
  }
}
