/* ============================================================
   OFT App — Surcouche MOBILE (≤ 768px)
   --------------------------------------------------------------
   Tout est gated par @media. Aucune règle n'a d'effet sur
   desktop / tablette paysage. Pour désactiver totalement :
   commenter le <link> dans base.html.
   ============================================================ */

/* ── Bouton hamburger : caché sur desktop ──────────────────── */
.mobile-menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  cursor: pointer;
  margin-right: 10px;
  flex-shrink: 0;
  color: var(--text);
  transition: background .15s, border-color .15s;
}
.mobile-menu-toggle:hover {
  background: var(--surface2);
  border-color: var(--green);
}
.mobile-menu-toggle svg {
  width: 22px;
  height: 22px;
}

/* ── Overlay : caché sur desktop ───────────────────────────── */
.mobile-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  transition: opacity .25s ease;
}
.mobile-sidebar-overlay.open {
  display: block;
  opacity: 1;
}

/* ============================================================
   ▼▼▼  TOUT CE QUI SUIT NE S'ACTIVE QU'EN DESSOUS DE 768px ▼▼▼
   ============================================================ */
@media (max-width: 768px) {

  /* ── Bouton hamburger visible ──────────────────────────── */
  .mobile-menu-toggle {
    display: inline-flex !important;
  }

  /* ── Sidebar = drawer qui glisse depuis la gauche ──────── */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 82vw;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.22,1,.36,1);
    z-index: 100;
    box-shadow: 4px 0 32px rgba(0,0,0,.18);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* ── Main prend toute la largeur ────────────────────────── */
  .app {
    /* le sidebar est en position:fixed, donc le main n'est plus
       contraint par le flex et peut prendre 100% */
    display: block;
    height: 100vh;
    overflow: hidden;
  }
  .main {
    width: 100vw;
    height: 100vh;
  }
  .content {
    padding: 14px;
  }

  /* ── Topbar compactée ──────────────────────────────────── */
  .topbar {
    padding: 10px 12px;
    gap: 6px;
  }
  .topbar-title {
    font-size: 13px;
    letter-spacing: .5px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* Recherche globale : on garde mais plus petite, sans marges latérales */
  .oft-global-search-wrap {
    margin: 0 !important;
    max-width: 100% !important;
    flex: 1 1 100% !important;
    order: 99;
  }
  @media (max-width: 480px) {
    .oft-global-search-wrap {
      display: none !important;
    }
  }
  .topbar-actions {
    flex-wrap: nowrap;
    gap: 6px;
    flex-shrink: 0;
    order: 2;
  }
  .oft-design-btn {
    padding: 7px 10px !important;
    font-size: 11px !important;
  }
  .topbar-actions .btn,
  .topbar-actions a {
    font-size: 11px !important;
    padding: 6px 10px !important;
  }

  /* ── Inputs : 16px minimum sinon Safari iOS zoome ───────── */
  input[type="text"],
  input[type="email"],
  input[type="number"],
  input[type="search"],
  input[type="tel"],
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px !important;
  }

  /* ── Cibles tactiles : minimum 44×44 pour les boutons ──── */
  button,
  .btn,
  a.btn {
    min-height: 38px;
  }

  /* ── Tableaux : scroll horizontal au lieu de débordement ─ */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  /* Pour les tableaux qu'on a explicitement laissés en mode block */
  table.no-mobile-scroll {
    display: table;
    overflow: visible;
    white-space: normal;
  }

  /* ── Grilles multi-colonnes → empilées ─────────────────── */
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr !important;
  }
  /* Cartes KPI inline-style ex. grid-template-columns:repeat(5,1fr) */
  [style*="grid-template-columns:repeat(5,1fr)"],
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns:repeat(3,1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Modals : plein écran sur mobile ───────────────────── */
  /* Cible les modals classiques position:fixed inset:0 */
  div[style*="position:fixed"][style*="inset:0"] > div[style*="max-width"] {
    max-width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    min-height: 100vh;
  }

  /* ── Body : scroll bloqué quand sidebar ouverte ────────── */
  body.mobile-sidebar-open {
    overflow: hidden;
  }
}

/* ============================================================
   Tablette portrait (entre 768 et 1024) : ajustements légers
   ============================================================ */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar {
    width: 200px;
  }
  .oft-global-search-wrap {
    max-width: 200px !important;
    margin: 0 12px !important;
  }
}

/* ============================================================
   MODE TERRAIN — interface épurée pour usage sur chantier
   Activé par : body.mode-terrain (via JS / paramètres)
   ============================================================ */

/* Masquer tout ce qui n'est pas essentiel en mode terrain */
body.mode-terrain .sb-nav .sb-pole { display: none; }

/* Afficher uniquement les 4 pôles terrain autorisés */
body.mode-terrain .sb-nav .sb-pole[data-pole="chantiers"],
body.mode-terrain .sb-nav .sb-pole[data-pole="logistique"],
body.mode-terrain .sb-nav .sb-pole[data-pole="communication"],
body.mode-terrain .sb-nav .sb-pole[data-pole="documents"] {
  display: block;
}

/* Toujours ouverts en mode terrain */
body.mode-terrain .sb-nav .sb-pole[data-pole="chantiers"],
body.mode-terrain .sb-nav .sb-pole[data-pole="logistique"] {
  open: true;
}

/* Boutons plus grands en mode terrain */
body.mode-terrain .sb-item {
  padding: 14px 16px !important;
  font-size: 15px !important;
  font-weight: 600 !important;
  min-height: 48px;
  display: flex;
  align-items: center;
}

/* Bandeau "Mode Terrain" visible */
body.mode-terrain::before {
  content: '⛏ MODE TERRAIN ACTIF';
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: #00e676;
  color: #0a1a0f;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  padding: 4px 0;
  pointer-events: none;
}
body.mode-terrain .app {
  padding-top: 22px;
}

/* Bouton de sortie du mode terrain */
.btn-mode-terrain-exit {
  position: fixed;
  bottom: 80px;
  left: 16px;
  z-index: 300;
  background: #0a1a0f;
  color: #00e676;
  border: 1.5px solid #00e676;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  display: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
body.mode-terrain .btn-mode-terrain-exit { display: block; }

/* FAB IA encore plus visible en mode terrain */
body.mode-terrain .mobile-fab-agent {
  width: 62px !important;
  height: 62px !important;
  border-radius: 18px !important;
  box-shadow: 0 10px 30px rgba(0,230,118,.50) !important;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
}

/* Topbar IA plus grande */
body.mode-terrain .topbar-ia-btn {
  padding: 10px 18px !important;
  font-size: 14px !important;
  font-weight: 800 !important;
  background: rgba(0,230,118,.15) !important;
  border-color: var(--green) !important;
}
