/* FDME MonRéseau — Adaptation tablette et téléphone (2.4.0)
   Chargé après app.css / admin.css. Rien ne change au-dessus de 960 px. */

/* Éléments propres au mobile : masqués sur ordinateur */
.bottom-nav, .nav-overlay, .tb-burger, .tb-search-btn, .filters-mobile { display: none; }

/* Panneau de filtres du fil */
.fp-group { border: none; padding: 0; margin: 0 0 18px; }
.fp-group legend { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--text-muted); margin-bottom: 8px; padding: 0; }
.fp-group legend span { text-transform: none; letter-spacing: 0; font-weight: 400; }
.fp-opt { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--border); font-size: 15px; color: var(--text); cursor: pointer; text-transform: none; letter-spacing: 0; font-weight: 400; }
.fp-opt input { width: 20px; height: 20px; margin: 0; accent-color: var(--bleu); flex-shrink: 0; }
.fp-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.fp-note { font-size: 12px; color: var(--text-muted); margin-top: 8px; line-height: 1.45; }

/* ── Tablette et téléphone : menu de gauche en tiroir ───── */
@media (max-width: 960px) {
  html { -webkit-text-size-adjust: 100%; }
  html, body { overflow-x: hidden; }   /* aucun glissement horizontal de la page */
  body.nav-open { overflow: hidden; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 300;
    width: min(84vw, 300px);
    box-shadow: none;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .nav-overlay {
    display: block; position: fixed; inset: 0; background: rgba(0,20,40,.45);
    z-index: 250; opacity: 0; pointer-events: none; transition: opacity .25s;
  }
  body.nav-open .nav-overlay { opacity: 1; pointer-events: auto; }
  .nav-item { padding: 12px 12px; font-size: 14px; }

  .main { margin-left: 0; min-width: 0; }
  .topbar { padding: 0 16px; padding-top: env(safe-area-inset-top); height: auto; min-height: 58px; gap: 10px; }
  .topbar-left { gap: 10px; min-width: 0; }
  .topbar-title { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .breadcrumb, .topbar-date { display: none; }
  .acc-label, .acc-chev, .tb-config span { display: none; }
  .acc-btn { padding: 0; }
  .tb-config { width: 40px; padding: 0; justify-content: center; margin-left: 0; }
  .sidebar-header { height: auto; min-height: 64px; padding-top: env(safe-area-inset-top); }
  .content { padding: 20px 16px; }

  .tb-burger {
    display: inline-flex; align-items: center; justify-content: center; position: relative;
    width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border);
    background: #fff; color: var(--bleu); font-size: 18px; cursor: pointer; flex-shrink: 0;
  }

  /* Grilles à plusieurs colonnes : une seule colonne, sans débordement */
  .feed-grid, .analytics-grid, .m-stack { grid-template-columns: 1fr !important; }
  .feed-grid > *, .analytics-grid > *, .m-stack > *, .m-2col > *, .posts-feed > * { min-width: 0; }
  .compose-row { min-width: 0; }
  .compose-input { min-width: 0; flex: 1 1 auto; width: 100%; }
  img, canvas { max-width: 100%; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .m-2col { grid-template-columns: repeat(2, 1fr) !important; }

  /* Fil : bouton Filtres et pastilles à la place des deux rangées */
  .filters-desktop { display: none; }
  .filters-mobile { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 18px; }
  .fm-btn {
    display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 20px;
    border: 1.5px solid var(--bleu); background: #fff; color: var(--bleu); font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  }
  .fm-count { background: var(--rouge); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; }
  .fm-chip { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 17px; background: var(--bleu-l); color: var(--bleu); font-size: 13px; font-weight: 500; text-decoration: none; max-width: 100%; }
  .fm-chip span { font-size: 16px; line-height: 1; }
  .fm-hint { font-size: 12.5px; color: var(--text-muted); }
  #filterModal .modal-footer > * { flex: 1; padding: 12px; }

  /* Barres d'onglets et de filtres : défilement horizontal */
  .tabs, .filter-bar, .mod-toolbar {
    flex-wrap: nowrap !important; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; max-width: 100%;
  }
  .tabs::-webkit-scrollbar, .filter-bar::-webkit-scrollbar, .mod-toolbar::-webkit-scrollbar { display: none; }
  .tab, .filter-btn, .filter-pill, .filter-label { flex-shrink: 0; white-space: nowrap; }

  /* Tableaux larges : défilement dans leur cadre */
  .table-wrap { overflow-x: auto; }
  .table-wrap table { min-width: 640px; }

  /* Fenêtres : en bas de l'écran, pleine largeur */
  .modal-bg { align-items: flex-end; }
  .modal {
    width: 100% !important; max-width: 100% !important; max-height: 92vh; overflow-y: auto;
    border-radius: 18px 18px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
  }
  .modal-footer { position: sticky; bottom: -22px; background: #fff; padding-top: 12px; }
  .modal-footer button { flex: 1; }

  /* Menu du compte : pleine largeur sous la barre */
  .acc-menu .acc-panel { position: fixed; top: calc(62px + env(safe-area-inset-top)); left: 12px; right: 12px; min-width: 0; max-width: none; }
}

/* ── Téléphone ──────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Barre d'onglets du bas (fil, agenda, notifications, menu) */
  .bottom-nav {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
    background: #fff; border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bn-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 58px; font-size: 11px; color: var(--text-muted); text-decoration: none;
    background: none; border: none; font-family: inherit; cursor: pointer;
  }
  .bn-item.active { color: var(--bleu); font-weight: 700; }
  .bn-item.active .bn-ico { background: var(--bleu-l); border-radius: 999px; }
  .bn-ico { padding: 3px 14px; transition: background .15s; }
  .bn-ico { font-size: 20px; line-height: 1; position: relative; }
  .bn-badge, .tb-burger .bn-badge {
    position: absolute; top: -6px; right: 2px; background: var(--rouge); color: #fff;
    font-size: 9.5px; font-weight: 700; min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 8px; display: flex; align-items: center; justify-content: center; font-style: normal;
  }
  .main { padding-bottom: calc(58px + env(safe-area-inset-bottom)); }

  /* Barre du haut : recherche repliée, cloche dans la barre du bas */
  .tb-notif { display: none !important; }
  .tb-search-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
  }
  .topbar .search-input { display: none; }
  .topbar.search-open .search-input {
    display: block; position: absolute; left: 12px; right: 12px; top: calc(100% + 6px);
    width: auto; box-shadow: 0 8px 24px rgba(0,0,0,.18); background: #fff; color: var(--text); padding: 12px 14px; font-size: 16px;
  }
  .topbar { position: sticky; }

  .content { padding: 16px 12px; }
  .panel { padding: 16px; border-radius: 14px; }

  /* Fil */
  .hero-post { flex-direction: column; gap: 14px; padding: 20px 18px; border-radius: 16px; }
  .hero-title { font-size: 17px; }
  .hero-meta { flex-wrap: wrap; gap: 10px; }
  .hero-meta > div[style*="margin-left:auto"] { margin-left: 0 !important; }
  .post-card { border-radius: 14px; }
  .post-header { flex-wrap: wrap; }
  .post-tag { order: 3; margin-left: 0; }
  .post-footer { flex-wrap: wrap; gap: 4px; }
  .action-btn { min-height: 40px; }
  .compose-input { font-size: 15px; }
  .compose-btn { flex-shrink: 0; padding-left: 14px; padding-right: 14px; }

  /* Formulaires : 16 px pour éviter le zoom automatique d'iOS */
  .form-input, .form-select, .search-field, .filter-select, input[type=text], input[type=email], input[type=number], select, textarea { font-size: 16px !important; }

  /* Administration */
  .kpi-row { gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-val { font-size: 22px; }
  .users-toolbar > * { flex: 1 1 140px; }
  .search-field { width: 100% !important; }
  .mod-header { flex-wrap: wrap; }
  .mod-footer { gap: 6px; }
  .mod-footer button { flex: 1 1 auto; min-height: 40px; }
  .scope-banner { margin-left: 0; margin-right: 0; }

  /* Modération : filtres sur plusieurs lignes, onglets sans coupure du soulignement */
  .mod-toolbar { flex-wrap: wrap !important; overflow: visible; gap: 8px; }
  .mod-toolbar .filter-label { display: none; }
  .mod-toolbar .filter-pill { flex: 1 1 auto; text-align: center; }
  .tabs { padding-bottom: 2px; }

  /* Utilisateurs & rôles : une carte par utilisateur */
  .table-wrap:has(#users-table) { overflow: visible; background: none; border: none; border-radius: 0; }
  .table-wrap #users-table { min-width: 0; display: block; }
  #users-table thead { display: none; }
  #users-table tbody { display: block; }
  #users-table tr {
    display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; align-items: center;
    grid-template-areas: "user user" "role actions" "site status" "login login";
    background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 10px;
  }
  #users-table td { display: block; padding: 0 !important; border: none !important; min-width: 0; }
  #users-table td:nth-child(1) { display: none; }
  #users-table td:nth-child(2) { grid-area: user; }
  #users-table td:nth-child(3) { grid-area: role; }
  #users-table td:nth-child(4) { grid-area: site; }
  #users-table td:nth-child(5) { grid-area: status; justify-self: end; }
  #users-table td:nth-child(6) { grid-area: login; font-size: 12px !important; }
  #users-table td:nth-child(6)::before { content: 'Dernière connexion : '; }
  #users-table td:nth-child(7) { grid-area: actions; }
  #users-table td[colspan] { grid-column: 1 / -1; display: block; }
  #users-table .role-select { width: 100%; min-height: 40px; }
  #users-table .td-actions { display: flex; gap: 6px; }
  #users-table .td-actions .btn-sm { min-width: 40px; min-height: 40px; }
  #users-table .u-email { word-break: break-all; }

  /* Paramètres RSE : chaque ligne devient une carte */
  .table-scroll { overflow: visible; }
  .table-scroll .grid-cat, .table-scroll .grid-site { min-width: 0; }
  .grid-head { display: none !important; }
  .table-scroll .grid-row {
    display: flex !important; flex-wrap: wrap; align-items: center; gap: 10px;
    padding: 14px 12px; margin-bottom: 10px; border: 1px solid var(--border); border-radius: 12px; background: #fff;
  }
  .grid-cat.grid-row > :nth-child(2) { flex: 1 1 calc(100% - 66px); min-width: 0; }   /* nom : ligne avec la couleur */
  .grid-cat.grid-row > :nth-child(2) .form-input { width: 100%; box-sizing: border-box; }
  .grid-cat.grid-row > :nth-child(3), .grid-site.grid-row > :nth-child(2) { width: 84px; flex: 0 0 84px; }  /* ordre */
  .grid-site.grid-row > :nth-child(1) { flex: 1 1 100%; }            /* nom du site */
  .grid-row .usage { flex: 1 1 auto; }
  .grid-row .deleg { flex: 1 1 100%; order: 10; padding-top: 8px; border-top: 1px dashed var(--border); }
  .grid-row .row-del { order: 5; margin-left: auto; }
  .grid-row .switch::before { content: 'Actif'; font-size: 12px; color: var(--text-muted); margin-right: 6px; }
  .grid-row .switch { align-items: center; }
  .deleg-add select { max-width: none; flex: 1; }
  .deleg-add { flex: 1 1 100%; }
  .add-form [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .add-form .cat-color { width: 100%; }

  /* Agenda : calendrier compact, événements en pastilles */
  .cal-cell { min-height: 46px !important; padding: 4px !important; font-size: 12px; }
  .cal-ev {
    display: inline-block !important; width: 7px; height: 7px; padding: 0 !important; margin: 2px 2px 0 0 !important;
    border-radius: 50% !important; font-size: 0 !important; background: currentColor !important; vertical-align: top;
  }
  .cal-head { font-size: 10px !important; letter-spacing: 0 !important; }

  /* Agenda : en-tête du calendrier sur deux lignes */
  .cal-toolbar { flex-wrap: wrap; gap: 12px; padding: 16px !important; }
  .cal-nav { width: 100%; }
  .cal-nav .btn-primary { margin-left: auto; }

  /* Profil */
  .profile-hero { flex-direction: column !important; text-align: center; gap: 14px !important; padding: 22px 16px !important; }
  .profile-back { margin-left: 0 !important; }

  /* Page de connexion */
  .login-body { padding: 16px; align-items: flex-start; padding-top: calc(32px + env(safe-area-inset-top)); }
  .login-card { width: 100%; padding: 32px 20px; }
}
