/* ============================================================
   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; }
  /* Le sélecteur de langue remplace le bouton paramètres en haut à droite */
  #settingsBtn { display: none; }
  #langSwitcherMount { display: block; }
  .lang-menu { right: 0; left: auto; }
  .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; }

  /* ---------- LECTEUR VIDÉO PLEIN ÉCRAN ---------- */
  .modal-overlay.open .modal.video-player-modal,
  .modal.video-player-modal {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important; height: 100dvh !important;
    max-height: 100vh !important; max-height: 100dvh !important;
    border-radius: 0 !important;
    animation: none !important;
  }
  .modal-overlay.open .modal.video-player-modal::before,
  .modal.video-player-modal::before { display: none; }
  .video-player-modal .video-player-layout {
    display: flex !important;
    flex-direction: column;
    grid-template-columns: none !important;
    grid-template-rows: none !important;
    height: 100vh; height: 100dvh;
    overflow: hidden;
  }
  .video-player-modal .vp-main { flex: 0 0 auto; }
  /* En-tête avec le bouton ✕ TOUJOURS visible en haut */
  .video-player-modal .vp-header {
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  }
  .video-player-modal .vp-header .btn-icon {
    width: 42px; height: 42px;
    background: rgba(255,255,255,0.18) !important;
    font-size: 20px;
  }
  .video-player-modal .vp-wrap {
    flex: none;
    height: 34vh; height: 34dvh;
    max-height: 34vh;
  }
  .video-player-modal #vp-video { width: 100%; height: 100%; }
  .video-player-modal .vp-controls { padding: 10px 12px; }
  .video-player-modal .vp-annot-add { min-width: 0; width: 100%; }
  .video-player-modal .vp-side {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    border-left: none;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* ---------- 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; }

  /* ---------- EFFECTIF (cartes photo) : 2 athlètes par ligne ---------- */
  .athletes-grid-photos {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  .athletes-grid-photos .ath-photo-card,
  .athletes-strip .ath-photo-card { padding: 10px; }
  .ath-photo-card .ath-photo-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ath-photo-card .ath-photo-meta { font-size: 11px; }
  .athletes-strip .ath-photo-card { width: 46vw !important; max-width: 190px; }

  /* ---------- STUDIO ANALYSE COMBAT ---------- */
  .fight-studio { grid-template-columns: minmax(0, 1fr) !important; }
  .fight-studio > * { min-width: 0; }
  .fight-video-col { position: static !important; }
  #chrono-card-body { min-width: 0; }
  /* Médias intégrés : jamais plus larges que l'écran */
  .page-content iframe, .page-content video { max-width: 100% !important; }
  /* Colonnes athlète/adversaire : rétrécissables, boutons compacts */
  .sb-cols { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
  .sb-cols > div { padding: 8px !important; min-width: 0; }
  .sb-btns { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .sb-cols .btn {
    font-size: 10.5px;
    padding: 6px 3px;
    min-height: 34px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ---------- STAT CARDS COMPACTES (lisibles en 2 colonnes) ---------- */
  .stat-card { padding: 12px 10px; gap: 9px; align-items: center; }
  .stat-card .card-icon { width: 34px; height: 34px; min-width: 34px; border-radius: 10px; }
  .stat-card .card-icon svg { width: 17px; height: 17px; }
  .stat-card .card-title { font-size: 10.5px; line-height: 1.25; }
  .stat-card .card-value { font-size: 18px; line-height: 1.2; word-break: break-word; }
  .stat-card .stat-body > div:last-child { font-size: 9.5px; line-height: 1.25; }

  /* ---------- CARTE NATIONALE ---------- */
  .heatmap-layout { grid-template-columns: minmax(0, 1fr) !important; gap: 14px !important; }
  .heatmap-layout > * { min-width: 0; }
  #mapContainer { height: 46vh !important; min-height: 300px; width: 100%; border-radius: 12px; }

  /* ---------- FICHE ATHLÈTE (modale, refonte) ---------- */
  .profile-header {
    flex-wrap: wrap;
    padding: 14px !important;
    gap: 12px !important;
  }
  .profile-header > * { min-width: 0; }
  /* En-tête : photo + infos empilés, actions en ligne */
  .ath-head { flex-wrap: wrap; padding: 14px !important; gap: 12px !important; }
  .ath-head-photo { width: 60px; height: 60px; min-width: 60px; font-size: 20px; }
  .ath-head-name { font-size: 17px; }
  .ath-head-actions { grid-template-columns: repeat(3, minmax(0,1fr)); width: 100%; }
  .ath-head-actions .btn { flex: 1 1 auto; }
  /* Stats rapides : 2 colonnes */
  .ath-quickstats { grid-template-columns: repeat(2, minmax(0,1fr)) !important; gap: 8px !important; }
  .ath-qs { padding: 10px 12px !important; }
  .ath-qs-val { font-size: 19px !important; }
  /* Layout : 1 colonne, menu en pills qui PASSENT À LA LIGNE (tous visibles, aucun scroll) */
  .ath-detail-layout { grid-template-columns: minmax(0,1fr) !important; gap: 12px !important; }
  .ath-nav {
    flex-flow: row wrap !important;
    position: static !important;
    gap: 6px !important;
    padding: 2px 0 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
  }
  .ath-nav .ath-tab {
    width: auto !important;
    flex: 0 0 auto;
    white-space: nowrap;
    background: var(--bg-soft);
    padding: 7px 11px !important;
    font-size: 12px !important;
  }
  .ath-nav .ath-tab .ath-tab-txt { flex: 0 0 auto; }
  .ath-nav .ath-tab.active { background: var(--benfica-red); }
  .split-layout, .split-layout.left-wide, .split-layout.right-wide {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 12px;
  }
  .split-layout > * { min-width: 0; }
  .scores-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  .score-item-val { font-size: 20px !important; }

  /* ---------- COMPTES UTILISATEURS : cartes (zéro scroll horizontal) ---------- */
  .acc-table-wrap { display: none !important; }
  .acc-cards { display: flex !important; flex-direction: column; gap: 10px; }
  .acc-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px; padding: 13px; box-shadow: var(--shadow-card); }
  .acc-card .btn { min-height: 34px; }

  /* ---------- PRISE DE PRÉSENCE : grille 2 colonnes ---------- */
  .att-grid { grid-template-columns: repeat(2, minmax(0,1fr)) !important; gap: 10px !important; }
  .att-card { padding: 10px !important; }

  /* ---------- COMPÉTITIONS : cartes (zéro scroll horizontal) ---------- */
  .comp-table-wrap { display: none !important; }
  .comp-cards { display: flex !important; flex-direction: column; gap: 10px; }
  .comp-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px; padding: 13px; box-shadow: var(--shadow-card); }

  /* ---------- RECRUTEMENT ---------- */
  /* Tableau de bord : sections en 1 colonne */
  .rc-grid2 { grid-template-columns: minmax(0, 1fr) !important; }
  .rc-grid2 > * { min-width: 0; }
  /* Fiche prospect : 1 colonne */
  .rf-layout { grid-template-columns: minmax(0, 1fr) !important; }
  .rf-layout > * { min-width: 0; }
  /* Pipeline : colonnes kanban empilées VERTICALEMENT (zéro scroll horizontal) */
  .kb-board { flex-direction: column; overflow-x: visible; gap: 12px; }
  .kb-board .kb-col { flex: 1 1 auto; width: 100%; }
  /* Onglets de la fiche prospect : passent à la ligne (tous visibles, pas de scroll) */
  .rf-tabs { flex-wrap: wrap !important; overflow: visible !important; background: none !important; padding: 0 !important; margin-left: 0 !important; margin-right: 0 !important; gap: 6px !important; }
  .rf-tabs .tab-btn { flex: 0 0 auto; background: var(--bg-soft); font-size: 12px; }
  .rf-tabs .tab-btn.active { background: var(--benfica-red); color: #fff; }
  /* Salle de négociation : tout reste dans l'écran */
  .nego-room { padding: 12px !important; }
  .nego-room .card-title, .nego-room strong { line-height: 1.3; }
  /* Chips chapitres de la négo : plus d'air, lisibles */
  .nego-room [style*="border-radius:14px"] { margin-bottom: 6px; }
  .nego-room .ng-actions { margin-left: 0 !important; width: 100%; }
  .nego-room .ng-actions .btn { flex: 1 1 auto; }
  .nego-room .ng-composer { flex-wrap: wrap; }
  .nego-room .ng-composer textarea { flex: 1 1 160px; min-width: 0; }
  .nego-room .ng-composer .btn { flex: 1 1 100%; justify-content: center; }
  .nego-room input[type="date"] { max-width: 100%; }

  /* ---------- 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); }
}

/* Paramètres : menu latéral au-dessus du contenu sur mobile */
@media (max-width: 767px) {
  .set-layout { grid-template-columns: 1fr !important; }
  .set-layout > .card:first-child { position: static !important; display:flex; flex-wrap:wrap; gap:4px; }
  .set-layout > .card:first-child .set-nav-item { flex:1 1 auto; justify-content:center; }
}

/* ===== CONSTRUCTION DES ÉQUIPES — responsive ===== */
@media (max-width: 1100px) {
  .tm-layout { grid-template-columns: 1fr 1fr !important; }
  .tm-layout > .card:first-child { grid-column: 1 / -1; }
}
@media (max-width: 767px) {
  .tm-layout { grid-template-columns: 1fr !important; }
}

/* ===== Roue de paramètres du menu latéral : MOBILE UNIQUEMENT =====
   Sur desktop la roue existe déjà dans la barre du haut — on la masque
   dans le pied du menu et le bouton déconnexion reprend l'alignement à droite. */
@media (min-width: 768px) {
  .sidebar-settings-gear { display: none !important; }
  .sidebar-logout-btn { margin-left: auto; }
}
