/* ============================================================
   MOBILE — Expérience application native (≤ 767px)
   Tiroir latéral + barre de navigation inférieure + bottom-sheets
   ============================================================ */

/* Boutons/éléments mobiles cachés sur desktop */
.mobile-menu-btn { display: none; }
.bottom-nav { display: none; }
.drawer-backdrop { display: none; }

@media (max-width: 767px) {

  /* ---------- LAYOUT RACINE ---------- */
  body { padding: 0; gap: 0; }

  .main-content {
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }

  /* ---------- SIDEBAR → TIROIR ---------- */
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    height: 100dvh;
    width: 82vw;
    max-width: 320px;
    min-width: 0;
    border-radius: 0 22px 22px 0;
    transform: translateX(-108%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 1200;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 24px 0 60px rgba(0,0,0,0.30);
  }
  /* Neutralise l'état "collapsed" desktop dans le tiroir */
  .sidebar.collapsed { width: 82vw; min-width: 0; max-width: 320px; }
  .sidebar.collapsed .nav-label,
  .sidebar.collapsed .nav-badge { display: inline-block; }
  .sidebar.collapsed .nav-section-label { display: block; opacity: 1; }
  .sidebar.collapsed .user-details { display: block; }
  .sidebar-toggle { display: none; }
  .sidebar-nav { -webkit-overflow-scrolling: touch; padding-bottom: 20px; }
  .nav-item { padding: 13px 14px; font-size: 14px; }
  .sidebar-footer { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }

  .drawer-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(18,18,20,0.45);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    z-index: 1150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }
  .drawer-backdrop.show { opacity: 1; pointer-events: auto; }

  /* ---------- TOPBAR COMPACTE ---------- */
  .topbar {
    height: 58px;
    padding: 0 10px 0 6px;
    gap: 6px;
  }
  .mobile-menu-btn {
    display: flex;
    width: 42px; height: 42px;
    flex-shrink: 0;
    background: none;
  }
  .page-title { font-size: 17px; }
  .breadcrumb { display: none; }
  .search-bar { display: none; }
  .live-indicator { display: none; }
  #langSwitcherMount { display: none; }
  .btn-icon { width: 38px; height: 38px; }

  /* ---------- CONTENU ---------- */
  .page-content {
    padding: 14px 14px calc(84px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }

  /* ---------- BARRE DE NAVIGATION INFÉRIEURE ---------- */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 900;
    background: rgba(255,255,255,0.88);
    -webkit-backdrop-filter: blur(20px) saturate(1.6);
    backdrop-filter: blur(20px) saturate(1.6);
    border-top: 1px solid var(--border);
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    flex: 1;
    min-width: 0;
    padding: 5px 2px 4px;
    border-radius: 14px;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.01em;
    position: relative;
    transition: color 0.18s ease, transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
  }
  .bottom-nav-item:active { transform: scale(0.92); }
  .bottom-nav-item svg {
    width: 23px; height: 23px;
    stroke: currentColor; fill: none;
    stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
  }
  .bottom-nav-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }
  .bottom-nav-item.active { color: var(--benfica-red); font-weight: 800; }
  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: -8px;
    width: 26px; height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--benfica-red);
  }
  .bn-dot {
    position: absolute;
    top: 2px; right: calc(50% - 16px);
    min-width: 15px; height: 15px;
    padding: 0 4px;
    background: var(--benfica-red);
    color: #fff;
    font-size: 9px; font-weight: 800;
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid #fff;
  }

  /* ---------- GRILLES ---------- */
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid-3, .grid-2 { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .grid-auto { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .grid-4 > *, .grid-3 > *, .grid-2 > * { min-width: 0; }
  .stat-card { min-width: 0; overflow: hidden; }

  /* ---------- CARTES ---------- */
  .card { padding: 16px; border-radius: 16px; }
  .card:hover { transform: none; }

  /* ---------- TACTILE ---------- */
  .btn { min-height: 42px; padding: 10px 16px; }
  .btn-sm, .btn.btn-sm { min-height: 36px; padding: 7px 12px; }
  /* Inputs ≥16px : empêche le zoom automatique iOS */
  input, select, textarea { font-size: 16px; }
  .form-row { grid-template-columns: 1fr; gap: 10px; }

  /* ---------- ONGLETS DÉFILABLES ---------- */
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-left: -14px; margin-right: -14px;
    padding-left: 14px; padding-right: 14px;
    border-radius: 0;
    background: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn { white-space: nowrap; flex-shrink: 0; background: var(--bg-soft); }
  .tab-btn.active { background: var(--benfica-red); color: #fff; }

  /* ---------- TABLEAUX ---------- */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 620px; }
  table { font-size: 12px; }
  th, td { padding: 8px 10px; }

  /* ---------- MODALES → BOTTOM SHEET ---------- */
  .modal-overlay { align-items: flex-end; }
  .modal, .modal-overlay.open .modal {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 22px 22px 0 0;
    animation: sheetUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  }
  .modal::before {
    content: '';
    display: block;
    width: 44px; height: 5px;
    border-radius: 3px;
    background: var(--border-light);
    margin: 8px auto 0;
    flex-shrink: 0;
  }
  .modal-header { padding: 12px 18px 14px; }
  .modal-header h3 { font-size: 16px; }
  .modal-body { padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
  @keyframes sheetUp {
    from { transform: translateY(60px); opacity: 0.5; }
    to   { transform: translateY(0);    opacity: 1; }
  }

  /* ---------- PANNEAU NOTIFICATIONS ---------- */
  .notif-panel { width: 100vw; right: -100vw; }

  /* ---------- PAGE CALENDRIER ---------- */
  .cal-page { height: auto !important; overflow: visible !important; }
  .cal-layout {
    grid-template-columns: minmax(0, 1fr) !important;
    height: auto !important;
  }
  .cal-side {
    height: auto !important;
    min-width: 0;
    overflow: visible !important;
    order: 2; /* mini-cal + filtres sous la vue principale */
  }
  .cal-main {
    height: auto !important;
    min-height: 55vh;
    min-width: 0;
    order: 1;
    overflow: hidden !important;
  }
  .cal-main > div:last-child {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  /* Vue mois : grille 7 jours lisible, défilable horizontalement */
  .cal-main > div:last-child > div[style*="repeat(7"] { min-width: 640px; }
  .cal-main table { min-width: 0; }

  /* ---------- PLANNING SEMAINE (séances) ---------- */
  .week-strip {
    display: flex !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 8px !important;
    padding-bottom: 4px;
  }
  .week-strip::-webkit-scrollbar { display: none; }
  .week-strip > div { min-width: 116px; flex: 0 0 auto; }

  /* ---------- MESSAGERIE : 2 écrans (liste, puis conversation) ---------- */
  .msg-page { height: calc(100dvh - 156px) !important; }
  .msg-layout {
    display: flex !important;
    flex-direction: column;
    grid-template-columns: none !important;
  }
  .msg-list-pane { border-right: none !important; flex: 1; min-height: 0; }
  /* La zone chat est cachée tant qu'aucune conversation n'est ouverte */
  #chat-zone { display: none !important; }
  /* Conversation ouverte : chat PLEIN ÉCRAN par-dessus tout (style WhatsApp) */
  .msg-layout.chat-open .msg-list-pane { display: none !important; }
  .msg-layout.chat-open #chat-zone {
    display: flex !important;
    position: fixed;
    inset: 0;
    z-index: 1300;
    background: var(--bg-secondary);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .msg-back { display: flex !important; }

  /* ---------- ROSTER ATHLÈTES ---------- */
  .roster-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
  .roster-card .btn { min-height: 38px; font-size: 12px; padding: 7px 8px; }

  /* ---------- STUDIO ANALYSE COMBAT ---------- */
  .fight-studio { grid-template-columns: minmax(0, 1fr) !important; }
  .fight-video-col { position: static !important; }

  /* ---------- GRAPHIQUES DU TABLEAU DE BORD ---------- */
  .dash-charts-row, .dash-charts-row-2 {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .page-content canvas { max-width: 100% !important; }

  /* Widget calendrier du dashboard : mini-cal au-dessus des échéances */
  .dash-cal-widget { grid-template-columns: minmax(0, 1fr) !important; }
  .dash-cal-mini { min-width: 0 !important; }
  .dash-cal-mini .mini-cal { max-width: 300px; margin: 0 auto; }

  /* ---------- DIVERS ---------- */
  ::-webkit-scrollbar { width: 0; height: 0; }
  .empty-state { padding: 28px 14px; }
  .profile-header { padding: 16px; }

  /* Bandeaux héro : boutons en pleine largeur, empilés */
  .hero-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; }
  .hero-actions .btn { width: 100%; justify-content: center; }
}

/* ---------- Petit mobile (≤ 380px) ---------- */
@media (max-width: 380px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .page-title { font-size: 15px; }
  .bottom-nav-item { font-size: 9px; }
  .bottom-nav-item svg { width: 21px; height: 21px; }
}

/* ---------- Tablette (768–1024px) : sidebar réduite ---------- */
@media (min-width: 768px) and (max-width: 1024px) {
  :root { --sidebar-width: 220px; }
  .search-bar { width: 170px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
