/**
 * Couche mobile finale — formulaires & modules terrain
 * Priorité maximale (chargé en dernier dans base_modern_complete.html)
 * Cible : usage smartphone (magasiniers, commerciaux, superviseurs)
 */

@media (max-width: 991px) {
  body:not(.page-login) .veille-pro,
  body:not(.page-login) .mpa-wrap,
  body:not(.page-login) .page-header-hl,
  body:not(.page-login) .card-hl,
  body:not(.page-login) .form-hl,
  body:not(.page-login) .form-container {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    box-sizing: border-box;
  }

  body:not(.page-login) .veille-pro[style*="max-width"] {
    max-width: 100% !important;
  }
}

@media (max-width: 768px) {
  /* --- Formulaires : champs pleine largeur, pas de zoom iOS --- */
  form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  form select,
  form textarea,
  form .form-control,
  form .form-select {
    width: 100% !important;
    max-width: 100% !important;
    font-size: 16px !important;
    min-height: 44px;
    box-sizing: border-box;
  }

  form textarea {
    min-height: 120px;
  }

  form input[type="file"].form-control {
    padding: 0.5rem !important;
    font-size: 0.9rem !important;
    min-height: 48px;
  }

  /* Grilles Bootstrap : une colonne sur mobile */
  form .row > [class*="col-"],
  .veille-glass__body .row > [class*="col-"],
  .form-hl .row > [class*="col-"],
  .card-hl .row > [class*="col-"] {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Cases à cocher / radio — cibles tactiles */
  form .form-check {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-left: 0;
  }

  form .form-check-input {
    width: 1.25rem !important;
    height: 1.25rem !important;
    margin-top: 0 !important;
    flex-shrink: 0;
  }

  /* --- Barres d'actions formulaire --- */
  form .d-flex.gap-2,
  form .d-flex.gap-3,
  .veille-glass__body .d-flex.gap-2,
  .veille-glass__body .d-flex.gap-3,
  .form-actions,
  .form-buttons {
    flex-direction: column !important;
    align-items: stretch !important;
    width: 100% !important;
    gap: 0.5rem !important;
  }

  form .d-flex.gap-2 > *,
  form .d-flex.gap-3 > *,
  .veille-glass__body .d-flex.gap-2 > *,
  .form-actions > *,
  .form-actions > a,
  .form-buttons > * {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  /* Tous types de boutons dans les formulaires */
  form .veille-btn-primary,
  form .veille-btn-ghost,
  form .btn,
  form .btn-hl,
  form button[type="submit"],
  form a.btn,
  form a.veille-btn-ghost,
  form a.veille-btn-primary,
  .form-actions .btn-hl,
  .form-actions .btn,
  .form-actions .veille-btn-primary,
  .form-actions .veille-btn-ghost {
    width: 100% !important;
    min-height: 44px !important;
    justify-content: center !important;
    display: inline-flex !important;
    align-items: center !important;
  }

  /* --- Module Veille --- */
  .veille-hero {
    flex-direction: column;
    align-items: stretch;
  }

  .veille-hero__actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .veille-hero__actions > .veille-toolbar {
    order: -1;
    width: 100%;
  }

  .veille-hero__actions > .veille-btn-primary,
  .veille-hero__actions > .veille-btn-ghost,
  .veille-hero__actions > a.veille-btn-primary,
  .veille-hero__actions > a.veille-btn-ghost,
  .veille-hero__actions > .veille-currency {
    width: 100% !important;
  }

  .veille-hero__actions .veille-currency .form-select {
    width: 100%;
  }

  .veille-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    max-width: 100%;
  }

  .veille-toolbar::-webkit-scrollbar {
    display: none;
  }

  .veille-toolbar a {
    flex-shrink: 0;
    min-height: 44px;
    padding: 0.5rem 0.85rem;
    white-space: nowrap;
  }

  .veille-glass__head,
  .veille-glass__body {
    padding: 1rem !important;
  }

  .veille-glass__head {
    flex-direction: column;
    align-items: flex-start;
  }

  .veille-kpis {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .veille-filter-bar .row {
    flex-direction: column;
  }

  .veille-pro .table-responsive {
    margin-left: -0.25rem;
    margin-right: -0.25rem;
    border-radius: 0.75rem;
  }

  /* --- Message Pro Admin --- */
  .mpa-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.15rem;
  }

  .mpa-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.25rem;
  }

  .mpa-nav::-webkit-scrollbar {
    display: none;
  }

  .mpa-nav a {
    flex-shrink: 0;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .mpa-form {
    grid-template-columns: 1fr !important;
  }

  .mpa-form .mpa-btn,
  .mpa-card .mpa-btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .mpa-table-scroll {
    max-height: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table.mpa-table {
    min-width: 520px;
  }

  /* --- En-têtes de page legacy --- */
  .page-header-hl {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .page-header-hl .d-flex,
  .page-header-hl .btn-group {
    flex-direction: column;
    width: 100%;
  }

  .page-header-hl .btn,
  .page-header-hl .btn-hl {
    width: 100%;
  }
}

@media (max-width: 480px) {
  body:not(.page-login) .veille-pro {
    margin: 0 0 1.5rem !important;
  }

  .veille-kpis {
    grid-template-columns: 1fr;
  }

  .veille-hero__title {
    font-size: clamp(1.2rem, 5.5vw, 1.65rem);
  }

  .veille-hero__sub {
    font-size: 0.85rem;
  }

  .veille-glass__head h2,
  .veille-glass__head h3 {
    font-size: 0.95rem;
  }

  .mpa-kpis {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 360px) {
  .mpa-kpis {
    grid-template-columns: 1fr;
  }
}

@supports (padding: max(0px)) {
  @media (max-width: 768px) {
    body:not(.page-login) .main-content {
      padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px)) !important;
    }

    body:not(.page-login) .top-header {
      padding-left: max(1rem, env(safe-area-inset-left, 0px)) !important;
      padding-right: max(1rem, env(safe-area-inset-right, 0px)) !important;
    }
  }
}
