/* ==========================================================
   10 - Scrollbars, responsive, chrome de la page Admin
   ========================================================== */

/* --- Scrollbar globale --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: var(--r-full);
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-3);
  background-clip: content-box;
}
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }

/* ==========================================================
   NAVIGATION MOBILE (barre d'onglets + tiroirs)
   Toujours position: fixed -> ne participe jamais a la grille
   .app, quelle que soit la largeur d'ecran. Visible uniquement
   sous 640px (voir bloc RESPONSIVE plus bas).
   ========================================================== */
.mobile-tabbar {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 150;
}
.mobile-sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 140;
  background: rgba(24,21,17,0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s;
}

/* ==========================================================
   RESPONSIVE
   ========================================================== */

/* Grande tablette : 900 - 1099px */
@media (max-width: 1099px) {
  .topbar-search-input { width: 220px; }
  .topbar-search:hover,
  .topbar-search:focus-within { width: 220px; }
  .subbar { padding: 0 24px; }
  .main { padding: 20px 24px 32px; }
  .month-heading { font-size: 22px; }
  .month-heading-current { font-size: 24px; }
}

/* Petite tablette / paysage : 750 - 899px */
@media (max-width: 899px) {
  .topbar-history-btn .btn-label { display: none; }
  .topbar-user-email  { display: none; }
  .topbar-user-role   { display: none; }
  .topbar-search-input { width: 180px; }
  .topbar-search:hover,
  .topbar-search:focus-within { width: 180px; }
  .subbar { padding: 0 20px; }
  .main { padding: 16px 20px 28px; }
  .topbar h1 { font-size: 23px; }
}

/* Paysage mobile / petite tablette : 640 - 749px */
@media (max-width: 749px) {
  .btn-label          { display: none; }
  .topbar-logo        { display: none; }
  .topbar-search-input { width: 150px; }
  .topbar-search:hover,
  .topbar-search:focus-within { width: 150px; }
  .subbar { padding: 0 16px; }
  .main { padding: 14px 16px 24px; }
  .filters-bar { gap: 5px; }
  .filter-pill { font-size: 11.5px; padding: 5px 11px; gap: 5px; }
  .toggle-all-btn { font-size: 11.5px; padding: 5px 11px; }
}

/* Mobile : < 640px */
@media (max-width: 639px) {
  .app { grid-template-rows: auto auto 1fr; }

  /* Entete mobile : icone + titre cote a cote sur une meme ligne,
     puis icones de gestion, puis recherche. .topbar reste flex-wrap
     (pas flex-direction:column) pour que les icones de gestion (2-3
     boutons distincts dans le DOM) puissent se regrouper sur une
     meme ligne ; seule la recherche force un retour a la ligne via
     width:100%. */
  .topbar {
    flex-wrap: wrap;
    justify-content: center;
    height: auto;
    min-height: 56px;
    padding: 10px 14px 15px;
    row-gap: 5px;
    column-gap: 10px;
    text-align: center;
  }
  .topbar-icon {
    order: 1;
    justify-content: center;
    flex-shrink: 0;
  }
  .topbar-icon svg { width: 34px; height: 34px; }

  .topbar-title-block {
    order: 2;
    text-align: center;
    min-width: 0;
  }
  .topbar h1 {
    font-size: 26px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* "Ajouter" est deplace dans la barre d'onglets du bas */
  .topbar-add-btn { display: none; }

  /* Force un retour a la ligne : icone+titre restent seuls sur leur ligne,
     icones de gestion et recherche (ordre 3) partagent ensemble la
     suivante, quelle que soit la place disponible. */
  .topbar-linebreak { display: block; order: 2; flex-basis: 100%; height: 0; }

  /* Icones de gestion (Utilisateurs, Historique, Presentation, Profil/
     Deconnexion) : regroupees dans un bloc qui occupe la moitie gauche
     de la ligne, la recherche occupant l'autre moitie. */
  .topbar-mgmt-icons {
    order: 3;
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    width: calc(50% - 5px);
    box-sizing: border-box;
  }
  .topbar-history-btn { padding: 8px 11px; }
  .topbar-history-btn svg { width: 16px; height: 16px; }
  /* Le mode presentation est pense pour un affichage en reunion sur
     grand ecran : pas d'equivalent adapte au mobile, on retire l'acces. */
  #presentationToggleBtn { display: none; }
  .admin-pending-badge,
  .history-unseen-badge { min-width: 16px; height: 16px; font-size: 10px; }
  .topbar-user { border-left: none; padding-left: 0; margin-left: 0; gap: 0; }
  /* Lien profil invisible sur mobile (email/role masques) : le cacher
     completement evite qu'il conserve son propre padding et casse
     l'ecart regulier entre les icones de gestion. */
  .topbar-user-link { display: none; }
  .topbar-logout-btn { width: 32px; height: 32px; }
  .topbar-logout-btn i { font-size: 13px; }

  .topbar-search,
  .topbar-search:hover,
  .topbar-search:focus-within {
    order: 4;
    width: calc(50% - 5px);
    box-sizing: border-box;
    margin-left: 0;
    margin-right: 0;
  }
  .topbar-search svg { width: 17px; height: 17px; left: 16px; }
  .topbar-search-input,
  .topbar-search-input:focus {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 16px 10px 40px;
    font-size: 14px;
    opacity: 1;
  }

  /* Subbar desktop (filtres inline + toggle vue) remplacee par la barre
     d'onglets du bas : on la neutralise plutot que de la masquer, pour
     que #filterPillsInline (position: fixed) reste dans le DOM actif. */
  /* backdrop-filter cree un containing block pour les descendants
     position:fixed (#filterPillsInline) : sans ca, la feuille de
     filtres se positionnerait par rapport a .subbar au lieu du
     viewport reel. */
  /* z-index:90 sur .subbar (grid item) cree aussi un contexte d'empilement
     local : #filterPillsInline (z-index:145) restait plafonne a ce niveau
     90 face aux AUTRES enfants de .app (le fond assombri a z-index:140
     passait devant et interceptait les clics, meme si la feuille etait
     visible par transparence). z-index:auto laisse .subbar transparent
     a l'empilement, .filterPillsInline se compare alors directement aux
     autres enfants directs de .app comme prevu. */
  .subbar { min-height: 0; padding: 0; border-bottom: none; backdrop-filter: none; -webkit-backdrop-filter: none; z-index: auto; }
  .filters-bar { padding: 0; gap: 5px; }
  #filterDropdownBtn        { display: none; }
  .filters-bar-actions      { display: none; }

  .main { padding: 12px 12px calc(78px + env(safe-area-inset-bottom)); gap: 14px; }

  .filter-pill { font-size: 11px; padding: 4px 10px; gap: 4px; }
  .filter-pill-count { padding: 1px 6px; font-size: 10px; }
  .toggle-all-btn { font-size: 11px; padding: 4px 10px; margin-left: 0; }

  #cardsGrid { gap: 22px; }
  .month-heading         { font-size: 30px; gap: 10px; }
  .month-heading-current { font-size: 20px; }
  /* Avancement du mois : ferre a droite de la ligne (le trait degrade
     ::after est retire pour laisser la marge automatique pousser le
     bloc progress jusqu'au bord, et le libelle ne doit plus retourner
     a la ligne dans l'espace restreint du mobile). */
  .month-heading::after { display: none; }
  .month-progress { margin-left: auto; flex-shrink: 0; }
  .month-progress-label { white-space: nowrap; }
  /* Corps de card en grille : titre en pleine largeur sur la 1ere ligne,
     puis pastille de type (gauche) et bouton "En savoir +" (droite) cote
     a cote sur la 2eme ligne. Ne touche pas au HTML/desktop (les 3
     elements restent dans le DOM dans le meme ordre qu'avant, seule
     leur position visuelle change via grid-area). */
  .op-card-body {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "title title" "type cta";
    align-items: start;
    padding: 10px 18px;
    gap: 12px;
  }
  .op-card-name { font-size: 26px; grid-area: title; }

  /* Badge de type ("MAJEURE", "OPTIONNELLE"...) : ferre a gauche,
     meme taille que les pastilles "EN COURS" / "En savoir +" */
  .type-badges-row { grid-area: type; gap: 10px; justify-content: flex-start; }
  .type-badge { font-size: 10px; padding: 9px 20px; gap: 6px; }

  /* "EN COURS" quitte le flux pour se poser dans l'angle haut-droit
     de l'image (.op-card est le premier ancetre position:relative) ;
     "En savoir +" reste seul sur la meme ligne que la pastille de type,
     ferre a droite. */
  .op-card-badges-row { grid-area: cta; gap: 10px; margin: 0; justify-content: flex-end; }
  .op-card-status-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    font-size: 9px!important;
    padding: 7px 16px;
    letter-spacing: 0.08em;
    box-shadow: var(--shadow-md);
  }
  .op-card-read-more {
    font-size: 10px;
    padding: 9px 20px;
    letter-spacing: 0.08em;
  }

  /* Bloc "Conditions de l'offre" */
  .op-card-conditions {
    font-size: 10px;
    line-height: 1.2;
    padding: 10px 15px;
    margin: 10px 15px 15px;
  }
  .op-card-conditions-icon { width: 19px; height: 19px; font-size: 13px; }
  .op-card-conditions-label { font-size: 11.5px; }
  .op-card-comment { font-size: 13px; line-height: 1.55; }

  /* Pastilles de canaux (Mailing, Kit PLV, PLV A4, Emailing...) : meme
     taille que les pastilles "EN COURS" / "En savoir +" ci-dessus */
  .op-card-channels-top { padding: 0px 16px 10px; gap: 10px; justify-content: center; }
  .op-card-ch { font-size: 9px; padding: 10px;}

  /* Mini-gantt : etiquettes MAG/WEB et dates */
  .op-card-gantt { padding: 16px 16px 14px; gap: 10px; }
  .op-card-gantt-row { gap: 7px; }
  .gantt-row-lbl { font-size: 11px; padding: 5px 11px; }
  .gantt-row-date { font-size: 13px; line-height: 1.5; }
  .gantt-row-date .card-dt-time { font-size: 13px; }
  .op-card-gantt-months { font-size: 13px; }

  /* Bouton To Do List */
  .op-card-todo { padding: 12px 16px; }
  .op-card-todo-btn { font-size: 12px; padding: 15px 18px; min-height: 52px; gap: 10px; }
  .op-card-todo-btn svg { width: 20px; height: 20px; }
  .op-card-todo-count { font-size: 12px; }

  /* Liens (emailing, drive, documents...) */
  .op-card-links { padding: 13px 16px 15px; gap: 9px 16px; }
  .op-card-link-label { font-size: 13.5px; }
  .op-card-link-ici { font-size: 12.5px; padding: 4px 11px; }
  .op-card-link-copy { font-size: 12px; }

  /* Coordonnees (Vie du Reseau) */
  .op-card-coords { margin: 12px 16px; padding: 13px 14px; }
  .op-card-coords-row { font-size: 13.5px; }

  /* Modales plein ecran */
  .modal-panel {
    max-width: 100vw; width: 100vw;
    max-height: 100dvh; height: 100dvh;
    border-radius: 0;
  }
  .modal-panel-history {
    width: 100vw; max-width: 100vw;
    height: 88dvh; max-height: 88dvh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
  #historyModal { align-items: flex-end; }
  #historyModal .modal-panel-history { transform: translateY(100%); }
  #historyModal.open .modal-panel-history { transform: translateY(0); }

  /* Ligne d'un item d'historique : typo reduite pour que tout tienne sur
     une ligne (badge action, nom d'operation, DEBUT du pseudo, date). */
  .history-item { padding: 9px 14px; font-size: 11.5px; }
  .history-item-main { gap: 6px; }
  .history-action-badge { min-width: 0; font-size: 8px; padding: 3px 7px; }
  /* Le nom d'operation est plafonne (au lieu de se disputer l'espace a
     parts egales avec le pseudo) pour que le DEBUT du pseudo reste
     toujours visible, meme sur les operations au nom long. */
  .history-op-name { font-size: 12px; min-width: 0; max-width: 108px; flex: 0 1 108px; }
  .history-user { font-size: 9.5px; max-width: 60px; min-width: 22px; flex-shrink: 0; }
  .history-date { font-size: 9.5px; }

  /* Formulaire mobile */
  .edit-form { padding: 16px 16px 0; }
  .form-section-title { font-size: 11px; margin-top: 22px; margin-bottom: 10px; }

  .form-grid { grid-template-columns: 1fr; gap: 12px; }

  /* Inputs >= 16px : empeche le zoom iOS Safari */
  .form-field input,
  .form-field select,
  .form-field textarea { font-size: 16px; padding: 12px 14px; }

  .enseigne-check { min-height: 40px; padding: 0 15px; font-size: 13px; }

  /* Barre de boutons collante en bas de modale */
  .btn-row {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    margin-top: 16px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .btn-row > div:not(.save-toast) { display: none; }
  .btn-row .btn { flex: 1 1 calc(33% - 6px); min-height: 44px; font-size: 13px; }
  .btn-row .btn-create { flex: 1 1 100%; order: -1; min-height: 48px; font-size: 15px; }

  .modal-topbar { padding: 16px; }
  .modal-topbar-title { font-size: 15px; }
  #previewModal .modal-topbar-title { font-size: 19px; padding: 0 44px; }
  .modal-close-btn { width: 36px; height: 36px; }

  /* Timeline mobile : barre d'annees scrollable */
  .tl-year-bar { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tl-year-bar::-webkit-scrollbar { display: none; }
  .year-tab { flex-shrink: 0; }

  /* ========================================================
     Barre d'onglets mobile (facon app)
     ======================================================== */
  .mobile-tabbar {
    display: flex;
    background: var(--glass);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(28,25,20,0.05);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    gap: 2px;
  }
  .mtab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 50px;
    padding: 6px 2px;
    border: none;
    background: transparent;
    border-radius: var(--r-md);
    color: var(--t3);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: -0.006em;
    transition: color 0.18s, background 0.18s;
  }
  .mtab svg { width: 20px; height: 20px; }
  .mtab:active { background: var(--surface-3); }
  .mtab.active { color: var(--blue); background: var(--blue-soft); }
  .mtab-add { color: var(--magenta); }
  .mtab-add.active { color: var(--magenta-press); }

  /* Espace pour ne pas passer sous la barre d'onglets */
  .scroll-top-btn { bottom: calc(80px + env(safe-area-inset-bottom)); right: 16px; }

  /* ========================================================
     Tiroir "Mois" : la sidebar liste devient une feuille
     glissant depuis le bas, ouverte via l'onglet "Mois"
     ======================================================== */
  .mobile-sheet-backdrop { display: block; }
  .mobile-sheet-backdrop.open { opacity: 1; pointer-events: auto; }

  .main.main--list #listView { padding: 12px 0 0 12px; }
  .main.main--list #cardsGrid {
    padding-right: 12px;
    padding-bottom: calc(78px + env(safe-area-inset-bottom));
  }

  .main.main--list #listSidebarWrapper,
  #listSidebarWrapper {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    width: 100%;
    max-height: 78dvh;
    margin: 0;
    z-index: 145;
    background: var(--surface);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: var(--shadow-lg);
    /* padding-bottom couvre aussi la hauteur de la barre d'onglets (fixe,
       par-dessus la feuille) pour que le dernier contenu scrollable ne
       finisse pas cache dessous. */
    padding: 22px 16px calc(78px + env(safe-area-inset-bottom));
    overflow-y: auto;
    overflow-x: hidden;
    transform: translateY(110%);
    transition: transform 0.32s var(--ease-out);
  }
  /* Specificite egale (1,2,0) a la regle .main.main--list #listSidebarWrapper
     ci-dessus pour etre certain de gagner sur `transform`. */
  .main.main--list #listSidebarWrapper.lsb-open,
  #listSidebarWrapper.lsb-open { transform: translateY(0); }
  #listSidebarWrapper::before { display: none; }
  #listSidebarWrapper::after {
    content: '';
    position: absolute;
    top: 9px; left: 50%;
    transform: translateX(-50%);
    width: 36px; height: 4px;
    border-radius: var(--r-full);
    background: var(--border-2);
  }
  #listSidebarWrapper #yearTabs { justify-content: flex-start; }
  #listSidebarWrapper #yearTabs .year-tab { min-height: 34px; padding: 7px 13px; font-size: 12.5px; }
  #listSidebar { max-height: none; }
  .lsb-month { min-height: 44px; }
  /* La regle @media(max-width:749px) de 12-session-misc.css passe ces
     liens en flex-direction:row sans retour a la ligne (pensee pour
     l'ancienne sidebar 100% largeur au-dessus des cards) : ils debordaient
     de l'ecran. Sous 640px on les passe en grille 2 colonnes, qui tient
     dans la largeur de l'ecran quel que soit le nombre de liens.
     Selecteurs prefixes par #listSidebarWrapper pour etre surs de battre
     la regle @media(max-width:749px) ci-dessus (meme specificite sinon,
     et ce fichier est charge avant 12-session-misc.css). */
  #listSidebarWrapper .lsb-anim-links {
    display: grid;
    grid-template-columns: 1fr 1fr;
    flex-direction: row;
    gap: 8px;
    margin-top: 10px;
    width: 100%;
  }
  #listSidebarWrapper .lsb-anim-btn {
    flex: none;
    min-width: 0;
    font-size: 12.5px;
    padding: 12px 10px;
  }

  /* ========================================================
     Feuille "Filtres" : le panneau de filtres deroulant du
     desktop devient une feuille plein-largeur, ouverte via
     l'onglet "Filtres" (reutilise toggleFilterDropdown()).
     ======================================================== */
  .filter-pills-inline {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    max-width: none;
    width: 100%;
    z-index: 145;
    background: var(--surface);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: var(--shadow-lg);
    padding: 22px 16px calc(78px + env(safe-area-inset-bottom));
    max-height: 70dvh;
    overflow-y: auto;
    overflow-x: hidden;
    flex-wrap: wrap;
    opacity: 1;
    transform: translateY(110%);
    transition: transform 0.32s var(--ease-out);
  }
  .filter-pills-inline.open { transform: translateY(0); pointer-events: auto; }
  .filter-pills-inline.open.settled { flex-wrap: wrap; }
  .filter-pill { flex: 1 1 calc(50% - 4px); justify-content: center; min-height: 42px; }

  /* ========================================================
     Modale To Do List : textes et interrupteurs agrandis
     ======================================================== */
  .todo-edit-toggle { font-size: 15px; padding: 11px 18px; gap: 9px; }
  .todo-group-title { font-size: 13px; }
  .todo-group-count { font-size: 13.5px; }
  .todo-group-toggle { font-size: 12.5px; padding: 6px 13px; }
  .todo-group-header { padding: 11px 14px; }
  .todo-item { padding: 7px 10px; gap: 13px; }
  .todo-item-label { font-size: 15.5px; }
  .todo-item-by { font-size: 13px; }
  .todo-switch { width: 46px; height: 26px; padding: 3px; }
  .todo-switch-knob { width: 20px; height: 20px; }
  .todo-item input[type="checkbox"]:checked ~ .todo-switch .todo-switch-knob { transform: translateX(20px); }
  .todo-group-disabled-msg,
  .todo-group-empty { font-size: 13.5px; }
}

/* ==========================================================
   Page Admin - chrome
   ========================================================== */
body.admin-users-page {
  background: var(--page);
  height: auto;
  min-height: 100vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.admin-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 32px;
  height: 60px;
  background: var(--glass);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.admin-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  color: var(--t2);
  border-radius: var(--r-full);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -0.012em;
  text-decoration: none;
  box-shadow: var(--shadow-xs);
  transition: background .18s, border-color .18s, color .18s;
  flex-shrink: 0;
}
.admin-back-btn:hover { background: var(--surface-2); border-color: var(--border-3); color: var(--t1); }
.admin-back-btn svg { width: 14px; height: 14px; }

.admin-topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.028em;
  color: var(--t1);
  flex: 1;
}
.admin-topbar-title svg { width: 18px; height: 18px; color: var(--ink); flex-shrink: 0; }
.admin-topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--t3);
}
.admin-role-badge {
  background: var(--ink);
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: var(--r-full);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.admin-main {
  flex: 1;
  padding: 32px;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.admin-alert {
  padding: 13px 16px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.014em;
}
.admin-alert-success { background: var(--green-soft); color: var(--green); border: 1px solid color-mix(in srgb, var(--green) 20%, transparent); }
.admin-alert-error   { background: var(--red-soft);   color: var(--red);   border: 1px solid color-mix(in srgb, var(--red) 20%, transparent); }

.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.admin-card-header {
  padding: 17px 20px;
  border-bottom: 1px solid var(--border);
}
.admin-card-title {
  font-family: var(--display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.024em;
  color: var(--t1);
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}
.admin-count {
  background: var(--surface-3);
  color: var(--t3);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: var(--r-full);
}
