/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --toolbar-h: 60px;
  --stats-h:   44px;
  --algo-h:    46px;
  --spe-h:     50px;
  --pool-w:    420px;
  --col-w:     310px;
  --radius:    6px;

  /* ── Charte Saint-Joseph de Tivoli ──
     Extraite du logo officiel ZEZE-6.png :
     - anneau extérieur : bleu marine institutionnel
     - cercle intérieur : or chaud / beige doré
  */
  --tivoli-navy:       #1A3569;   /* bleu marine principal */
  --tivoli-navy-light: #2A4F9A;   /* marine hover */
  --tivoli-navy-dark:  #0F2045;   /* marine profond */
  --tivoli-gold:       #C4A46B;   /* or/beige doré */
  --tivoli-gold-light: #E8D9B0;   /* or clair / crème */
  --tivoli-gold-pale:  #F7F1E3;   /* crème très clair */
  --tivoli-white:      #FFFFFF;

  /* Couleurs spécialités (inchangées) */
  --c-maths:  #4472C4;
  --c-pc:     #FFFF00;
  --c-svt:    #92D050;
  --c-ses:    #FF0000;
  --c-hggsp:  #FFC000;
  --c-amc:    #FF6699;
  --c-nsi:    #9966FF;
  --c-hlp:    #00B0F0;

  /* UI tokens */
  --bg:        var(--tivoli-gold-pale);
  --panel-bg:  #FFFFFF;
  --toolbar-bg: var(--tivoli-navy-dark);
  --stats-bg:  var(--tivoli-navy);
  --border:    #D6C9A8;
  --border-light: #EDE5D0;
  --text:      #1A2E4A;
  --text-muted: #6B7A8D;
  --accent:    var(--tivoli-gold);
  --shadow:    0 2px 8px rgba(26, 53, 105, .10);
  --shadow-lg: 0 6px 20px rgba(26, 53, 105, .14);
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   TOOLBAR
   ============================================================ */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--toolbar-h);
  padding: 0 16px;
  background: var(--tivoli-navy-dark);
  border-bottom: 3px solid var(--tivoli-gold);
  color: #fff;
  gap: 8px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(15, 32, 69, .4);
}

.tb-tools  { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.tb-right  { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.tb-import { display: flex; align-items: center; gap: 6px; }

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
  min-width: 0;
}
.app-logo {
  height: 42px;
  width: 42px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 2px var(--tivoli-gold);
  flex-shrink: 0;
}
.app-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 26px;
  font-weight: 600;
  font-style: italic;
  color: var(--tivoli-gold-light);
  letter-spacing: 1px;
  line-height: 1;
}
.app-title em {
  font-style: normal;
  color: var(--tivoli-gold);
  font-weight: 600;
}

.tb-niveau {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-right: 8px;
}
.niveau-link {
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: rgba(255, 255, 255, .65);
  border: 1px solid rgba(255, 255, 255, .2);
  transition: background .15s, color .15s, border-color .15s;
}
.niveau-link:hover {
  color: #fff;
  border-color: var(--tivoli-gold);
}
.niveau-link--active {
  color: var(--tivoli-navy-dark);
  background: var(--tivoli-gold);
  border-color: var(--tivoli-gold);
}

.file-label {
  font-size: 11px;
  color: #94a3b8;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.separator {
  width: 1px;
  height: 28px;
  background: rgba(196,164,107,.2);
  margin: 0 4px;
}

/* Boutons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: var(--radius);
  border: none;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: filter .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }
.btn:not(:disabled):hover { filter: brightness(1.1); }
.btn:not(:disabled):active { filter: brightness(.95); }

a.btn,
a.btn:hover,
a.btn:focus,
a.btn:visited {
  text-decoration: none;
}

.btn-import        { background: var(--tivoli-navy); color: var(--tivoli-gold-light); border: 1px solid rgba(196,164,107,.3); }
.btn-success       { background: var(--tivoli-gold); color: var(--tivoli-navy-dark); }
.btn-secondary     { background: var(--tivoli-navy-light); color: #fff; }
.btn-export        { background: var(--tivoli-navy); color: var(--tivoli-gold-light); border: 1px solid rgba(196,164,107,.3); }
.btn-danger-outline{ background: transparent; color: #B55A5A; border: 1px solid #B55A5A; }
.btn-danger-outline:not(:disabled):hover { background: #B55A5A18; }

.input-save {
  padding: 5px 9px;
  border-radius: var(--radius);
  border: 1px solid rgba(196,164,107,.3);
  background: rgba(255,255,255,.07);
  color: var(--tivoli-gold-light);
  font-size: 12px;
  width: 160px;
}
.input-save::placeholder { color: rgba(196,164,107,.5); }
.input-save:focus { outline: 1px solid var(--tivoli-gold); background: rgba(255,255,255,.1); }

.select-load {
  padding: 5px 9px;
  border-radius: var(--radius);
  border: 1px solid rgba(196,164,107,.3);
  background: rgba(255,255,255,.07);
  color: var(--tivoli-gold-light);
  font-size: 12px;
  cursor: pointer;
  max-width: 220px;
}
.select-load option { background: var(--tivoli-navy-dark); color: #fff; }

/* Bouton icône seule (déconnexion) */
.btn-icon-only {
  background: transparent;
  color: #B55A5A;
  border: 1px solid #B55A5A;
  padding: 5px 10px;
  font-size: 15px;
  line-height: 1;
}

/* ── Menus déroulants toolbar ── */
.tb-menu { position: relative; }

.btn-menu-trigger {
  background: var(--tivoli-navy-light);
  color: #fff;
  border: 1px solid rgba(196,164,107,.25);
}

.tb-menu-panel[hidden] { display: none; }

.tb-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--tivoli-navy-dark);
  border: 1px solid rgba(196,164,107,.45);
  border-radius: var(--radius);
  padding: 10px;
  min-width: 270px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 8px 28px rgba(15,32,69,.55);
}

.tb-menu-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.tb-menu-row .input-save  { flex: 1; width: auto; min-width: 0; }
.tb-menu-row .select-load { flex: 1; max-width: none; min-width: 0; }

.tb-menu-sep {
  height: 1px;
  background: rgba(196,164,107,.2);
  margin: 2px 0;
}

.btn-menu-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--tivoli-gold-light);
  border: none;
  justify-content: flex-start;
  padding: 7px 10px;
  font-size: 13px;
  border-radius: var(--radius);
  width: 100%;
  cursor: pointer;
  text-decoration: none;
}
.btn-menu-item:not([disabled]):hover { background: rgba(196,164,107,.12); filter: none; }
.btn-menu-item[disabled] { opacity: .4; cursor: not-allowed; pointer-events: none; }

.btn-menu-full { width: 100%; justify-content: center; }

/* En-tête index (toolbar + stats + algo) */
#appHeader {
  position: relative;
  z-index: 100;
}

/* ============================================================
   BARRE DE STATS GLOBALE
   ============================================================ */
#statsBar {
  display: flex;
  align-items: center;
  height: var(--stats-h);
  padding: 0 16px;
  background: var(--tivoli-navy);
  color: var(--tivoli-gold-light);
  gap: 16px;
  position: fixed;
  top: var(--toolbar-h);
  left: 0; right: 0;
  z-index: 99;
  border-bottom: 1px solid rgba(196, 164, 107, .25);
}

.stat-bloc { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.stat-label { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 15px; font-weight: 700; color: #fff; }
.stat-sep   { color: #64748b; }

.spe-stats-row {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  flex: 1;
}
.spe-stats-row::-webkit-scrollbar { height: 3px; }
.spe-stats-row::-webkit-scrollbar-track { background: transparent; }
.spe-stats-row::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

.stat-spe {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #1e293b;
  border-radius: 4px;
  padding: 3px 7px;
  white-space: nowrap;
}
.stat-spe-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.stat-spe-name { font-size: 11px; color: #cbd5e1; }
.stat-spe-val  { font-size: 12px; font-weight: 700; color: #fff; }
.stat-spe-val.complete { color: #4ade80; }
.stat-spe-val.partial  { color: #fbbf24; }

/* ============================================================
   PANNEAU ALGORITHMES
   ============================================================ */
#algoPanel {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--algo-h);
  padding: 0 16px;
  background: var(--tivoli-gold-pale);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: calc(var(--toolbar-h) + var(--stats-h));
  left: 0; right: 0;
  z-index: 98;
  overflow: hidden;
}

.algo-divider {
  width: 1px;
  height: 26px;
  background: rgba(26, 53, 105, .18);
  flex-shrink: 0;
}

.algo-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
  flex-shrink: 0;
  font-weight: 600;
}

.algo-crew-total {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  background: rgba(26, 53, 105, .08);
  color: var(--tivoli-navy);
  border: 1px solid transparent;
}
.algo-crew-total.crew-total-ok  { background: rgba(34, 139, 84, .12);  color: #1c7a48; border-color: rgba(34, 139, 84, .35); }
.algo-crew-total.crew-total-bad { background: rgba(192, 57, 43, .12);  color: #b23a2e; border-color: rgba(192, 57, 43, .4); }

.btn-toggle-pool {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px 0 10px;
  background: var(--tivoli-navy);
  color: var(--tivoli-gold-light);
  border: 1px solid rgba(196, 164, 107, .4);
  border-radius: var(--radius);
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
  transition: background .15s, border-color .15s, box-shadow .15s, color .15s;
}
.btn-toggle-pool:hover {
  background: var(--tivoli-navy-light);
  border-color: var(--tivoli-gold);
  box-shadow: 0 2px 8px rgba(15, 32, 69, .18);
}
.btn-toggle-pool:active { transform: scale(.98); }
.btn-toggle-pool[aria-expanded="true"] {
  background: var(--tivoli-navy-dark);
  border-color: var(--tivoli-gold);
}
.pool-toggle-label { white-space: nowrap; }
.pool-toggle-icon {
  display: block;
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  margin-right: 1px;
  flex-shrink: 0;
  transition: transform .28s cubic-bezier(.4, 0, .2, 1);
}
.btn-toggle-pool[aria-expanded="true"] .pool-toggle-icon {
  transform: rotate(135deg);
  margin-right: 0;
  margin-left: 2px;
}
.btn-toggle-pool .pool-count-badge {
  min-width: 20px;
  height: 18px;
  padding: 0 5px;
  font-size: 10px;
  line-height: 1;
}

.btn-algo {
  background: var(--tivoli-navy);
  color: var(--tivoli-gold-light);
  border: 1px solid rgba(196, 164, 107, .3);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
  letter-spacing: .2px;
}
.btn-algo:not(:disabled):hover {
  background: var(--tivoli-gold);
  color: var(--tivoli-navy-dark);
  border-color: var(--tivoli-gold);
}
.btn-algo:disabled { opacity: .35; cursor: not-allowed; }

.btn-algo-secondary {
  background: rgba(26, 54, 93, .08);
  color: var(--tivoli-navy);
  border-color: rgba(26, 54, 93, .25);
}
.btn-algo-secondary:not(:disabled):hover {
  background: var(--tivoli-navy);
  color: var(--tivoli-gold-light);
  border-color: var(--tivoli-navy);
}

.algo-progress {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 8px;
}
.algo-progress.hidden { display: none; }

.algo-progress-bar-wrap {
  flex: 1;
  height: 6px;
  background: #1e293b;
  border-radius: 3px;
  overflow: hidden;
}
.algo-progress-bar {
  height: 6px;
  background: linear-gradient(90deg, #2563eb, #06b6d4);
  border-radius: 3px;
  width: 0%;
  transition: width .3s ease;
}
.algo-progress-msg {
  font-size: 11px;
  color: #93c5fd;
  white-space: nowrap;
  min-width: 200px;
}

/* ============================================================
   ZONE PRINCIPALE
   ============================================================ */
#main {
  display: flex;
  position: fixed;
  top: calc(var(--toolbar-h) + var(--stats-h) + var(--algo-h));
  left: 0; right: 0;
  bottom: var(--spe-h);
  overflow: hidden;
}

/* ── VIVIER ─────────────────────────────────────────────────── */
#poolPanel {
  width: var(--pool-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 2px solid var(--border);
  background: var(--panel-bg);
  overflow: hidden;
  transition: width .35s cubic-bezier(.4, 0, .2, 1), border-width .35s ease, opacity .25s ease;
  will-change: width;
}
#poolPanel.collapsed {
  width: 0;
  min-width: 0;
  border-right-width: 0;
  opacity: 0;
  pointer-events: none;
}

#poolHeader {
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  background: linear-gradient(180deg, var(--tivoli-navy) 0%, var(--tivoli-navy-dark) 100%);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.pool-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--tivoli-gold-light);
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: .4px;
  text-transform: uppercase;
  min-width: 0;
  flex-shrink: 0;
}
.pool-title-label { white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 18px;
  padding: 0 5px;
  background: var(--tivoli-gold);
  color: var(--tivoli-navy-dark);
  border-radius: 9px;
  font-size: 11px;
  font-weight: 700;
}

#filters {
  display: flex;
  gap: 4px;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.filter-genre {
  max-width: 64px;
  flex: none;
}
.filter-select {
  flex: 1;
  padding: 4px 6px;
  border: 1px solid rgba(196,164,107,.3);
  border-radius: var(--radius);
  font-size: 11px;
  background: rgba(255,255,255,.1);
  color: var(--tivoli-gold-light);
  cursor: pointer;
}
.filter-select option { background: var(--tivoli-navy-dark); color: #fff; }
.filter-input {
  flex: 1;
  padding: 4px 6px;
  border: 1px solid rgba(196,164,107,.3);
  border-radius: var(--radius);
  font-size: 11px;
  background: rgba(255,255,255,.1);
  color: var(--tivoli-gold-light);
}
.filter-input::placeholder { color: rgba(196,164,107,.5); }
.filter-input:focus, .filter-select:focus { outline: 1px solid var(--tivoli-gold); outline-offset: -1px; }

.btn-icon {
  padding: 4px 7px;
  background: transparent;
  border: 1px solid rgba(196,164,107,.3);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 11px;
  color: var(--tivoli-gold);
}
.btn-icon:hover { background: #B5555520; color: #B55555; border-color: #B55555; }

#poolList {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#poolList::-webkit-scrollbar { width: 5px; }
#poolList::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ── CLASSES ────────────────────────────────────────────────── */
#classesPanel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-x: auto;
  overflow-y: auto;
  padding: 8px;
}

#classesArea {
  display: flex;
  gap: 8px;
  min-width: max-content;
  align-items: flex-start;
}

.classe-column {
  width: var(--col-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.classe-header {
  padding: 8px 10px;
  background: var(--tivoli-gold-pale);
  border-bottom: 2px solid var(--border);
}

.classe-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.classe-nom {
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}

.classe-profil {
  font-size: 8px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--tivoli-navy);
  color: var(--tivoli-gold-light);
  white-space: nowrap;
  letter-spacing: .5px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.classe-count {
  font-size: 12px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
}
.count-ok      { background: #D8EAD8; color: #1A5C1A; }
.count-warning { background: var(--tivoli-gold-light); color: #6B4E0A; }
.count-danger  { background: #F0CECE; color: #7A2020; }

.classe-eq-count {
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  margin-left: 2px;
}

.classe-spe-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  min-height: 18px;
}
.spe-pill {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
}
.spe-pill--on-dark  { color: #ffffff; }
.spe-pill--on-light { color: #1a1a1a; }

.classe-pp-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  margin-bottom: 2px;
}
.classe-pp-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--tivoli-navy);
  flex-shrink: 0;
  letter-spacing: .03em;
}
.classe-pp-input {
  flex: 1;
  min-width: 0;
  font-size: 10px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
}
.classe-pp-input:focus {
  outline: none;
  border-color: var(--tivoli-gold);
  box-shadow: 0 0 0 2px rgba(196,164,107,.2);
}
.classe-pp-input::placeholder { color: #94a3b8; }

.classe-header-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}
.btn-add-eq {
  font-size: 10px;
  padding: 2px 8px;
  background: transparent;
  color: var(--tivoli-navy);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: .2px;
}
.btn-add-eq:hover { background: var(--tivoli-gold-light); border-color: var(--tivoli-gold); }

.classe-equipages {
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ── ÉQUIPAGES ──────────────────────────────────────────────── */
.equipage {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fafafa;
  flex-shrink: 0;
}

.equipage-header {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 5px;
  padding: 4px 7px;
  align-items: start;
  background: var(--tivoli-navy);
  border-bottom: 1px solid rgba(196,164,107,.2);
}

.equipage-drag-handle {
  cursor: grab;
  color: rgba(226,232,240,.55);
  font-size: 13px;
  line-height: 1;
  padding: 0 1px;
  flex-shrink: 0;
  user-select: none;
  grid-row: 1 / -1;
  align-self: center;
}
.equipage-drag-handle:hover { color: var(--tivoli-gold-light); }
.equipage-drag-handle:active { cursor: grabbing; }

.equipage-header-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.equipage-header-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  width: 100%;
}
.equipage-header-row2 {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-items: center;
  width: 100%;
}
.eq-hdr-field {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.eq-hdr-lbl {
  font-size: 8px;
  font-weight: 600;
  color: rgba(226, 232, 240, .55);
  text-transform: uppercase;
  letter-spacing: .35px;
  white-space: nowrap;
}
.eq-hdr-eff { margin-left: auto; }
.equipage-num {
  font-size: 11px;
  font-weight: 700;
  color: #e2e8f0;
  white-space: nowrap;
  min-width: 1.2em;
  text-align: center;
}

.eq-spe-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-items: center;
}
.equipage-nom   { font-size: 11px; font-weight: 700; color: #e2e8f0; white-space: nowrap; }
.equipage-count { font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 3px; white-space: nowrap; }
.eq-spe-pill    { font-size: 9px !important; padding: 1px 4px !important; }
.eq-jour-select {
  font-size: 9px;
  padding: 1px 2px;
  border: 1px solid rgba(196,164,107,.25);
  border-radius: 3px;
  background: rgba(255,255,255,.1);
  color: var(--tivoli-gold-light);
  cursor: pointer;
  flex-shrink: 0;
  min-width: 2.8em;
}
.eq-jour-select option { background: var(--tivoli-navy-dark); color: #fff; }

.eq-prof-ref-control {
  position: relative;
  width: 5.2em;
  flex-shrink: 0;
}
.eq-prof-ref-select,
.eq-prof-ref-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-size: 9px;
  font-weight: 600;
  padding: 2px 4px;
  border: 1px solid rgba(196, 164, 107, .25);
  border-radius: 3px;
  line-height: 1.25;
}
.eq-prof-ref-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath fill='%23c4a46b' d='M0 0l4 5 4-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 3px center;
  padding-right: 12px;
}
.eq-prof-ref-input {
  background: rgba(255, 255, 255, .1);
  color: var(--tivoli-gold-light);
}
.eq-prof-ref-input::placeholder { color: rgba(226, 232, 240, .45); }
.eq-prof-ref-select[hidden],
.eq-prof-ref-input[hidden] { display: none !important; }
.eq-prof-ref-select option { font-weight: 600; }
.eq-prof-ref-input:focus,
.eq-prof-ref-select:focus {
  outline: 1px solid var(--tivoli-gold);
  outline-offset: 0;
}

.drop-zone {
  counter-reset: line-num;
  min-height: 32px;
  padding: 3px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background .15s;
}
.drop-zone.sortable-over,
.drop-zone:empty { background: rgba(196,164,107,.08); }
.drop-zone:empty::after {
  content: 'Déposer ici';
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  font-size: 10px;
  color: #94a3b8;
  border: 1px dashed #cbd5e1;
  border-radius: 4px;
  width: 100%;
}

/* ── CARTES ÉLÈVES ──────────────────────────────────────────── */
.eleve-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 2px 3px 2px 18px;
  cursor: grab;
  user-select: none;
  transition: box-shadow .12s, transform .12s;
  position: relative;
  display: flex;
  align-items: center;
  gap: 3px;
  min-height: 20px;
}
.eleve-card::before {
  counter-increment: line-num;
  content: counter(line-num);
  font-size: 8px;
  color: #94a3b8;
  font-weight: 700;
  position: absolute;
  left: 2px;
  top: 2px;
  min-width: 12px;
}
.eleve-card:hover { box-shadow: 0 1px 6px rgba(0,0,0,.12); border-color: #94a3b8; }
.eleve-card.has-conflict { border-left: 3px solid #ef4444; }

.card-left {
  display: flex;
  align-items: flex-start;
  gap: 2px;
  flex: 1;
  min-width: 0;
  flex-shrink: 1;
}

/* Vivier : carte en colonne, hauteur naturelle (pas de flex-shrink) */
#poolList .eleve-card {
  flex-direction: column;
  align-items: flex-start;
  flex-shrink: 0;
}
#poolList .card-left {
  flex: unset;
  min-width: unset;
  width: 100%;
}
#poolList .genre-badge {
  align-self: flex-start;
}
#poolList .card-right {
  width: 100%;
}
.eleve-nom {
  font-size: 10px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
  overflow-wrap: break-word;
  line-height: 1.4;
}
.warn-icon { font-size: 10px; cursor: help; flex-shrink: 0; margin-top: 2px; }

.card-right {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  align-items: flex-start;
  flex-wrap: wrap;
  width: 160px; /* 3 × spe-badge(38px) + opt-badge + gaps */
}
body[data-niveau="term"] .card-right {
  width: 120px; /* 2 × spe-badge(38px) + opt-badge + gaps */
}

/* Badge genre G / F */
.genre-badge {
  font-size: 7px;
  font-weight: 800;
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  flex-shrink: 0;
  letter-spacing: 0;
  align-self: center;
}
.genre-badge.genre-g { background: #DBEAFE; color: #1D4ED8; }
.genre-badge.genre-f { background: #FCE7F3; color: #BE185D; }
.genre-badge.empty   { display: none; }

.orig-badge {
  font-size: 8px;
  color: var(--tivoli-navy);
  background: var(--tivoli-gold-light);
  border: 1px solid rgba(196,164,107,.4);
  padding: 1px 3px;
  border-radius: 3px;
  flex-shrink: 0;
  width: 40px;
  text-align: center;
  font-weight: 600;
}
.spe-badge {
  font-size: 8px;
  font-weight: 700;
  color: #fff;
  padding: 1px 2px;
  border-radius: 2px;
  letter-spacing: 0px;
  flex-shrink: 0;
  width: 38px;
  text-align: center;
}
.spe-badge.empty {
  background: transparent;
  border: none;
  padding: 1px 2px;
}
.spe-badge-clickable {
  cursor: pointer;
  transition: filter .12s, box-shadow .12s;
}
.spe-badge-clickable:hover {
  filter: brightness(0.93);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .18);
}
.opt-badge {
  font-size: 8px;
  font-weight: 600;
  color: #6b7280;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  padding: 1px 4px;
  border-radius: 2px;
  flex-shrink: 0;
  white-space: nowrap;
}
.opt-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  flex-shrink: 0;
  max-width: 88px;
  justify-content: flex-end;
}
.opt-badge.empty {
  display: none;
}
.orig-badge.empty {
  background: transparent;
  border: none;
  padding: 1px 3px;
}

/* SortableJS drag states */
.sortable-ghost   { opacity: .35; background: var(--tivoli-gold-light) !important; border: 1px dashed var(--tivoli-gold) !important; }
.sortable-chosen  { box-shadow: 0 4px 14px rgba(26,53,105,.2); z-index: 999; }
.sortable-drag    { transform: rotate(1.5deg); cursor: grabbing !important; }

.sortable-ghost-equipage   { opacity: .45; border: 1px dashed var(--tivoli-gold) !important; }
.sortable-chosen-equipage  { box-shadow: 0 6px 18px rgba(26,53,105,.25); z-index: 998; }
.sortable-drag-equipage    { cursor: grabbing !important; }
.classe-equipages.sortable-over { background: rgba(196,164,107,.06); border-radius: var(--radius); }

/* Pendant le drag d'équipage : les zones élèves ne captent plus la souris */
body.equipage-drag-active .drop-zone,
body.equipage-drag-active .eleve-card {
  pointer-events: none;
}
body.equipage-drag-active .classe-equipages {
  gap: 8px;
  transition: gap .15s;
}
body.equipage-drag-active .equipage-header {
  outline: 1px dashed rgba(196,164,107,.35);
  outline-offset: -1px;
}

/* ============================================================
   PANNEAU GROUPES DE SPÉS (bas de page)
   ============================================================ */
#speGroupPanel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--spe-h);
  background: var(--tivoli-navy-dark);
  border-top: 2px solid rgba(196,164,107,.3);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  overflow-x: auto;
  z-index: 98;
}
#speGroupPanel::-webkit-scrollbar { height: 3px; }
#speGroupPanel::-webkit-scrollbar-thumb { background: #475569; border-radius: 2px; }

#speGroupTitle {
  font-size: 10px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
  flex-shrink: 0;
}

#speGroupTable {
  display: flex;
  gap: 8px;
  align-items: center;
}

.spg-bloc {
  display: flex;
  align-items: center;
  gap: 3px;
  background: #0f172a;
  border-radius: 4px;
  padding: 3px 7px;
  white-space: nowrap;
}
.spg-spe-label {
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  min-width: 34px;
}
.spg-classes {
  display: flex;
  gap: 2px;
}
.spg-cell {
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 600;
  color: #fff;
  min-width: 22px;
  text-align: center;
}
.spg-cell.ok      { background: #166534; }
.spg-cell.light   { background: #14532d88; }
.spg-cell.zero    { background: #1e293b; color: #475569; }
.spg-cell.high    { background: #991b1b; }

/* ── Bouton d'édition (icône crayon, visible au survol) ───── */
.btn-edit-eleve {
  position: absolute;
  top: 2px;
  right: 3px;
  background: none;
  border: none;
  font-size: 9px;
  color: #94a3b8;
  cursor: pointer;
  padding: 1px 3px;
  border-radius: 2px;
  opacity: 0;
  transition: opacity .15s, background .1s;
  line-height: 1;
  z-index: 1;
}
.eleve-card:hover .btn-edit-eleve { opacity: 1; }
.btn-edit-eleve:hover { background: var(--tivoli-gold-light); color: var(--tivoli-navy); }

/* ============================================================
   POPUP ÉDITION ÉLÈVE
   ============================================================ */
.edit-popup {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.edit-popup[hidden] { display: none; }
.edit-popup-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 32, 69, .5);
}
.edit-popup-box {
  position: relative;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(15, 32, 69, .3);
  width: 300px;
  overflow: hidden;
}
.edit-student-box {
  width: min(420px, calc(100vw - 24px));
}
.edit-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--tivoli-navy);
  color: var(--tivoli-gold-light);
  font-weight: 700;
  font-size: 13px;
  gap: 8px;
}
.edit-popup-close {
  background: none;
  border: none;
  color: var(--tivoli-gold);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 5px;
  border-radius: 3px;
  flex-shrink: 0;
  line-height: 1;
}
.edit-popup-close:hover { background: rgba(196,164,107,.2); }
.edit-popup-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.edit-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.edit-row label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  width: 46px;
  flex-shrink: 0;
}
.edit-row select,
.edit-row input[type="text"] {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text);
  background: #fff;
}
.edit-row select:focus,
.edit-row input[type="text"]:focus {
  outline: 1px solid var(--tivoli-navy);
  outline-offset: -1px;
}
.edit-options-row { align-items: flex-start; }
.edit-options-row label { padding-top: 4px; }
.edit-options-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 120px;
  overflow-y: auto;
}
.edit-opt-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}
.edit-opt-check input { flex-shrink: 0; }
.edit-options-empty {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}
/* Bloc info profs dans la popup */
.edit-profs-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  background: var(--tivoli-gold-pale);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  min-height: 20px;
}
.edit-grp-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border-light);
}
.edit-grp-block:last-child {
  padding-bottom: 0;
  border-bottom: none;
}
.edit-grp-empty {
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
}
.edit-grp-info {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.edit-grp-info-main {
  flex-wrap: wrap;
  justify-content: space-between;
}
.edit-grp-info b { color: var(--text); }
.edit-eff-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  flex-shrink: 0;
  margin-left: auto;
}
.edit-eff-ok   { background: #D8EAD8; color: #1A5C1A; }
.edit-eff-high { background: var(--tivoli-gold-light); color: #6B4E0A; }
.edit-eff-over { background: #F0CECE; color: #7A2020; }

.edit-grp-siblings {
  font-size: 9px;
  color: var(--text-muted);
  line-height: 1.65;
  padding-left: 2px;
}
.edit-grp-siblings-label {
  font-weight: 700;
  color: var(--tivoli-navy);
  display: block;
  margin-bottom: 2px;
}
.edit-sib-grp {
  display: inline-block;
  margin: 0 5px 3px 0;
  padding: 2px 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .85);
  border: 1px solid var(--border-light);
  white-space: nowrap;
}
.edit-sib-grp em {
  font-style: normal;
  color: var(--text-muted);
  font-size: 8px;
  margin: 0 2px;
}
.edit-sib-grp b { font-weight: 700; color: var(--text); }
.edit-sib-grp.edit-eff-high { border-color: #d4a82a; background: #FDF8EC; }
.edit-sib-grp.edit-eff-over { border-color: #c44; background: #FDF0F0; }
.edit-sib-grp.edit-eff-over b { color: #7A2020; }
.edit-barrette {
  font-size: 9px;
  font-weight: 700;
  background: var(--tivoli-navy);
  color: var(--tivoli-gold-light);
  padding: 0 4px;
  border-radius: 2px;
}

.edit-barrette-warn {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  background: #FDF3E3;
  border: 1px solid #E8C56A;
  border-radius: var(--radius);
  font-size: 11px;
  color: #6B4E0A;
  line-height: 1.5;
}
.edit-barrette-warn[hidden] { display: none !important; }
.edit-barrette-warn-icon {
  flex-shrink: 0;
  font-size: 15px;
  line-height: 1.2;
}
.edit-barrette-warn-detail {
  font-size: 10px;
  font-family: ui-monospace, monospace;
  color: #8B6914;
}

.edit-popup-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-light);
  background: var(--tivoli-gold-pale);
}
.edit-popup-footer--triple {
  flex-wrap: wrap;
  justify-content: space-between;
}

/* ── Popup suggestions de placement ─────────────────────────── */
.placement-popup-box {
  width: min(520px, calc(100vw - 24px));
  max-height: min(88vh, 720px);
  display: flex;
  flex-direction: column;
}
.placement-popup-body {
  overflow-y: auto;
  max-height: calc(88vh - 120px);
  gap: 12px;
}
.place-profile {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 10px;
  background: var(--tivoli-gold-pale);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  font-size: 11px;
}
.place-profile-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.place-profile-label {
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 9px;
  letter-spacing: .04em;
  width: 52px;
  flex-shrink: 0;
}
.place-profile-val { color: var(--text); font-weight: 600; }
.place-profile-grps { font-weight: 500; font-family: ui-monospace, monospace; font-size: 10px; }

.place-section-title {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--tivoli-navy);
  text-transform: uppercase;
  letter-spacing: .03em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.place-section-count {
  font-size: 10px;
  font-weight: 700;
  background: var(--tivoli-navy);
  color: var(--tivoli-gold-light);
  padding: 1px 6px;
  border-radius: 8px;
}
.place-section-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.place-row {
  padding: 6px 8px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: #fafafa;
}
.place-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.place-row-loc {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}
.place-row-eff {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  background: #D8EAD8;
  color: #1A5C1A;
  flex-shrink: 0;
}
.place-row-eff.place-eff-low { background: var(--tivoli-gold-light); color: #6B4E0A; }
.place-row-eff.place-eff-full { background: #F0CECE; color: #7A2020; }
.place-row-detail {
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.45;
}
.place-row-warn, .place-row-hint {
  margin-top: 3px;
  font-size: 9px;
  font-weight: 600;
}
.place-row-warn { color: #7A2020; }
.place-row-hint { color: #6B4E0A; }

.place-tag {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
}
.place-tag-ok    { background: #D8EAD8; color: #1A5C1A; }
.place-tag-warn  { background: var(--tivoli-gold-light); color: #6B4E0A; }
.place-tag-info  { background: #D6E4F5; color: #1a3d6b; }
.place-tag-muted { background: #e2e8f0; color: #475569; }

.place-section-peers { border-top: 1px solid var(--border-light); padding-top: 8px; }
.place-peers-subtitle {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  margin: 6px 0 4px;
}
.place-peer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  font-size: 11px;
  padding: 3px 0;
  border-bottom: 1px solid var(--border-light);
}
.place-peer-row:last-child { border-bottom: none; }
.place-peer-nom { font-weight: 600; color: var(--text); }
.place-peer-place {
  font-size: 10px;
  color: var(--tivoli-navy);
  font-weight: 600;
}
.place-peer-extra {
  font-size: 9px;
  color: var(--text-muted);
  font-family: ui-monospace, monospace;
}
.place-empty {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 12px 0;
}

/* ── Popup élèves d'un groupe de spé ───────────────────────── */
.grp-peers-title-code {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}
.grp-peers-title-sub {
  font-size: 12px;
  font-weight: 600;
  color: var(--tivoli-gold-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.grp-peers-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: var(--tivoli-gold-pale);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 4px;
}
.grp-peers-meta {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}
.grp-peers-place { margin-top: 8px; }
.grp-peers-place-title {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--tivoli-navy);
  display: flex;
  align-items: center;
  gap: 6px;
}
.grp-peers-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-left: 4px;
}
.grp-peer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 3px;
}
.grp-peer-row--self {
  background: rgba(196, 164, 107, .22);
  font-weight: 700;
  outline: 1px solid rgba(196, 164, 107, .45);
}
.grp-peer-nom { color: var(--text); }

/* ============================================================
   HINT & EMPTY STATES
   ============================================================ */
.empty-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px 8px;
  font-size: 11px;
  color: var(--text-muted);
  height: 100%;
  flex: 1;
}

/* ============================================================
   NOTIFICATIONS
   ============================================================ */
#notifContainer {
  position: fixed;
  top: calc(var(--toolbar-h) + 8px);
  right: 12px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.notif {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 10px 9px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  box-shadow: var(--shadow-lg);
  animation: notif-in .2s ease;
  max-width: 300px;
}
.notif-persistent { max-width: min(520px, calc(100vw - 24px)); }
.notif-msg {
  flex: 1;
  min-width: 0;
  line-height: 1.45;
}
.notif-persistent .notif-msg {
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
  cursor: text;
}
.notif-close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin: -2px 0;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font-size: 14px;
  line-height: 1;
  opacity: .75;
  cursor: pointer;
}
.notif-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, .18);
}
@keyframes notif-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.notif-success { background: #2E7D5A; }
.notif-error   { background: #A03838; }
.notif-info    { background: var(--tivoli-navy); border: 1px solid var(--tivoli-gold); }
.notif-warning { background: #8B6A1A; }

/* ============================================================
   DRAWER — GROUPES DE SPÉS
   ============================================================ */
#groupsModal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
}
#groupsModal[hidden] { display: none; }

.groups-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 32, 69, .4);
}

.groups-modal-box {
  position: relative;
  background: #f8f6f0;
  width: 700px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  box-shadow: -6px 0 28px rgba(15, 32, 69, .22);
  animation: drawer-in .2s ease;
}
@keyframes drawer-in {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.groups-modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--tivoli-navy-dark);
  color: var(--tivoli-gold-light);
  border-bottom: 2px solid var(--tivoli-gold);
  flex-shrink: 0;
}
.groups-modal-title {
  font-weight: 700;
  font-size: 13px;
  flex: 1;
}
.groups-filter-spe {
  max-width: 130px;
  flex: none;
}

.groups-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
}
.groups-modal-body::-webkit-scrollbar { width: 5px; }
.groups-modal-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* Cartes groupe */
.grp-card {
  width: 218px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.grp-card-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 5px 8px 6px;
}
.grp-card-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  min-width: 0;
}
.grp-code {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .2px;
  white-space: nowrap;
  flex-shrink: 0;
}
.grp-prof-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-size: 10px;
  padding: 3px 5px;
  border-radius: 3px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, .15);
}
.grp-prof-input--on-dark {
  color: #fff;
  border-color: rgba(255, 255, 255, .25);
}
.grp-prof-input--on-dark::placeholder { color: rgba(255, 255, 255, .5); }
.grp-prof-input--on-light {
  color: #1a1a1a;
  border-color: rgba(0, 0, 0, .15);
  background: rgba(255, 255, 255, .55);
}
.grp-prof-input--on-light::placeholder { color: rgba(0, 0, 0, .4); }
.grp-prof-input:focus {
  outline: 1px solid var(--tivoli-gold);
  outline-offset: 0;
}
.grp-prof {
  font-size: 10px;
  flex: 1;
  opacity: .85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grp-meta {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}
.grp-barrette,
.grp-effectif {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  flex-shrink: 0;
  letter-spacing: .02em;
  line-height: 1.35;
}
.grp-effectif--warn {
  outline: 2px solid #fff;
  outline-offset: 1px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.grp-barrette {
  min-width: 1.1em;
  text-align: center;
  padding-left: 3px;
  padding-right: 3px;
}

/* Fond de carte sombre (Maths, SES…) → pastille claire */
.grp-badge-on-dark {
  background: rgba(255, 255, 255, 0.92);
  color: var(--tivoli-navy-dark);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
}

/* Fond de carte clair (PC, SVT, HLP…) → pastille sombre */
.grp-badge-on-light {
  background: rgba(15, 32, 69, 0.88);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.grp-card-body {
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.grp-student-row {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  padding: 1px 0;
  min-width: 0;
}
.grp-student-nom {
  flex: 1;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.grp-student-place {
  font-size: 9px;
  font-weight: 600;
  padding: 1px 4px;
  border-radius: 2px;
  white-space: nowrap;
  flex-shrink: 0;
}
.grp-student-place.placed { background: #D8EAD8; color: #1A5C1A; }
.grp-student-place.vivier { background: var(--tivoli-gold-light); color: #6B4E0A; }
.grp-empty {
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
  padding: 4px 0;
}

/* ============================================================
   DRAWER — SYNTHÈSE PAR PROF RÉFÉRENT (Terminale)
   ============================================================ */
#profRefModal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
}
#profRefModal[hidden] { display: none; }

.prof-ref-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 32, 69, .4);
}

.prof-ref-modal-box {
  position: relative;
  background: #f8f6f0;
  width: min(960px, 94vw);
  max-width: 94vw;
  display: flex;
  flex-direction: column;
  box-shadow: -6px 0 28px rgba(15, 32, 69, .22);
  animation: drawer-in .2s ease;
}

.prof-ref-modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--tivoli-navy-dark);
  color: var(--tivoli-gold-light);
  border-bottom: 2px solid var(--tivoli-gold);
  flex-shrink: 0;
}
.prof-ref-modal-title {
  font-weight: 700;
  font-size: 13px;
  flex: 1;
  min-width: 0;
}
.prof-ref-export-btn {
  flex-shrink: 0;
  font-size: 11px;
  padding: 5px 12px;
}

.prof-ref-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.prof-ref-modal-body::-webkit-scrollbar { width: 5px; }
.prof-ref-modal-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.prof-ref-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.prof-ref-stat {
  flex: 1 1 120px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  box-shadow: var(--shadow);
  text-align: center;
}
.prof-ref-stat-val {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--tivoli-navy);
  line-height: 1.2;
}
.prof-ref-stat-lbl {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.prof-ref-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}
.prof-ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.prof-ref-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--tivoli-navy);
  color: var(--tivoli-gold-light);
  font-weight: 600;
  text-align: left;
  padding: 8px 10px;
  white-space: nowrap;
}
.prof-ref-table td {
  padding: 7px 10px;
  border-top: 1px solid var(--border);
  vertical-align: top;
}
.prof-ref-row:nth-child(even) { background: #faf8f4; }
.prof-ref-row--warn { background: #fff8e6 !important; }
.prof-ref-td-prof { font-weight: 600; white-space: nowrap; }
.prof-ref-td-num { text-align: center; white-space: nowrap; }
.prof-ref-td-spes { min-width: 100px; }
.prof-ref-spes {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.prof-ref-spe-pill {
  font-size: 9px !important;
  padding: 1px 5px !important;
}
.prof-ref-td-eqs { min-width: 200px; }
.prof-ref-eq-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.prof-ref-eq-chip {
  display: inline-block;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 3px;
  background: var(--tivoli-gold-light);
  color: var(--tivoli-navy-dark);
  border: 1px solid rgba(196, 164, 107, .45);
  white-space: nowrap;
}
.prof-ref-eq-chip--muted {
  background: #eef1f5;
  color: var(--text-muted);
  border-color: var(--border);
}
.prof-ref-warn {
  display: inline-block;
  margin-left: 4px;
  font-size: 9px;
  font-weight: 700;
  color: #b45309;
}
.prof-ref-cap {
  display: block;
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 500;
}
.prof-ref-empty,
.prof-ref-empty-row {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 24px 12px;
}
.prof-ref-unassigned {
  background: #fff;
  border: 1px dashed #d4a574;
  border-radius: var(--radius);
  padding: 10px 12px;
}
.prof-ref-unassigned-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  color: #92400e;
}

.prof-ref-students-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.prof-ref-section-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--tivoli-navy);
}

.prof-ref-details {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.prof-ref-details-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  list-style: none;
  background: #faf8f4;
  border-bottom: 1px solid transparent;
  font-size: 12px;
}
.prof-ref-details[open] .prof-ref-details-summary {
  border-bottom-color: var(--border);
}
.prof-ref-details-summary::-webkit-details-marker { display: none; }
.prof-ref-details-summary::before {
  content: '▸';
  font-size: 10px;
  color: var(--text-muted);
  transition: transform .15s;
}
.prof-ref-details[open] .prof-ref-details-summary::before {
  transform: rotate(90deg);
}
.prof-ref-details-meta {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
}
.prof-ref-details-body {
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.prof-ref-eq-details {
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  overflow: hidden;
}
.prof-ref-eq-details summary.prof-ref-eq-block-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  cursor: pointer;
  list-style: none;
  background: #f3f6fa;
  border-bottom: 1px solid transparent;
  font-size: 11px;
  font-weight: 700;
  color: var(--tivoli-navy);
  margin-bottom: 0;
}
.prof-ref-eq-details[open] summary.prof-ref-eq-block-title {
  border-bottom-color: var(--border);
}
.prof-ref-eq-details summary::-webkit-details-marker { display: none; }
.prof-ref-eq-details summary::before {
  content: '▸';
  font-size: 9px;
  color: var(--text-muted);
  transition: transform .15s;
  flex-shrink: 0;
}
.prof-ref-eq-details[open] summary::before {
  transform: rotate(90deg);
}
.prof-ref-eq-details .prof-ref-student-list {
  padding: 4px 8px 6px;
}
.prof-ref-unassigned .prof-ref-unassigned-title {
  margin: 0;
  color: #92400e;
}
.prof-ref-student-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.prof-ref-student-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 2px 0;
  min-width: 0;
}
.prof-ref-student-row--empty {
  color: var(--text-muted);
  font-style: italic;
}
.prof-ref-student-name {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}
.prof-ref-student-grp {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   MODAL — GESTION DES OPTIONS
   ============================================================ */
#optionsModal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#optionsModal[hidden] { display: none; }
.options-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 32, 69, .5);
}
.options-modal-box {
  position: relative;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(15, 32, 69, .3);
  width: 420px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: popup-in .15s ease;
}
@keyframes popup-in {
  from { opacity: 0; transform: scale(.96); }
  to   { opacity: 1; transform: scale(1); }
}
.options-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--tivoli-navy);
  color: var(--tivoli-gold-light);
  font-weight: 700;
  font-size: 13px;
  gap: 8px;
  flex-shrink: 0;
}
.options-modal-body {
  flex: 1;
  overflow-y: auto;
  max-height: 380px;
  padding: 8px 0;
}
.option-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border-light);
}
.option-row:last-child { border-bottom: none; }
.opt-code-cell {
  font-size: 11px;
  font-weight: 800;
  color: var(--tivoli-navy);
  width: 44px;
  flex-shrink: 0;
}
.opt-label-cell {
  flex: 1;
  font-size: 12px;
  color: var(--text);
}
.opt-label-input {
  flex: 1;
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--tivoli-navy);
  border-radius: 3px;
}
.btn-opt-edit, .btn-opt-save, .btn-opt-cancel, .btn-opt-del {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 5px;
  border-radius: 3px;
  line-height: 1;
  flex-shrink: 0;
}
.btn-opt-edit   { color: var(--tivoli-navy); }
.btn-opt-save   { color: #2E7D5A; }
.btn-opt-cancel { color: var(--text-muted); }
.btn-opt-del    { color: #A03838; }
.btn-opt-edit:hover, .btn-opt-save:hover, .btn-opt-cancel:hover, .btn-opt-del:hover {
  background: var(--tivoli-gold-light);
}
.options-modal-footer {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-light);
  background: var(--tivoli-gold-pale);
  flex-shrink: 0;
}
.options-modal-footer input {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
}
.options-modal-footer input:focus {
  outline: 1px solid var(--tivoli-navy);
  outline-offset: -1px;
}

/* ============================================================
   SCROLLBARS GLOBALES
   ============================================================ */
::-webkit-scrollbar       { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(160, 82, 45, .3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(160, 82, 45, .5); }

@media (max-width: 1600px) {
  :root { --col-w: 290px; }
}
@media (max-width: 1400px) {
  :root { --col-w: 270px; --pool-w: 380px; }
}
@media (max-width: 1024px) {
  :root {
    --col-w: 250px;
    --pool-w: 100%;
    --spe-h: 34px;
  }
  .input-save { width: 140px; }
  .select-load { max-width: 180px; }
  .file-label { max-width: 120px; }
  .algo-progress-msg { min-width: 140px; }

  /* ── App-page : layout plein-écran comme sur desktop ── */
  html.app-page,
  html:has(body.app-page) { overflow: hidden; height: 100svh; }
  body.app-page {
    overflow: hidden;
    height: 100svh;
    display: flex;
    flex-direction: column;
  }

  body.app-page #appHeader {
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 14px rgba(15, 32, 69, .25);
  }

  body.app-page #toolbar {
    position: relative;
    top: auto;
    height: auto;
    min-height: 0;
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 8px;
    overflow: visible;
  }
  body.app-page #toolbar .tb-tools {
    flex: 1 1 auto;
    min-width: 0;
  }
  body.app-page #toolbar .tb-right {
    flex-shrink: 0;
  }
  body.app-page #toolbar .btn {
    font-size: 12px;
    padding: 7px 11px;
    min-height: 36px;
  }
  body.app-page #toolbar .file-label {
    max-width: 140px;
  }
  .app-title { font-size: 20px; }
  .app-logo  { height: 36px; width: 36px; }

  body.app-page #statsBar {
    position: relative;
    top: auto;
    height: auto;
    min-height: var(--stats-h);
    padding: 8px 12px;
    gap: 10px;
    flex-wrap: wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  body.app-page .stat-label { color: #cbd5e1; }
  body.app-page #algoPanel {
    position: relative;
    top: auto;
    height: auto;
    min-height: 0;
    padding: 10px 12px;
    gap: 10px;
    flex-wrap: wrap;
    overflow: visible;
  }
  body.app-page .btn-algo {
    flex: 1 1 auto;
    min-height: 38px;
    font-size: 12px;
    justify-content: center;
  }
  .algo-label { font-size: 11px; }
  .algo-progress { flex: 1 1 100%; margin-left: 0; min-width: 0; }
  .algo-progress-msg { min-width: 0; flex: 1; white-space: normal; line-height: 1.35; }

  body.app-page #main {
    position: relative;
    top: auto;
    bottom: auto;
    flex: 1;
    min-height: 0;
    margin-bottom: var(--spe-h);
    overflow: hidden;
  }
  #main {
    flex-direction: column;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
  }
  #poolPanel {
    width: 100% !important;
    height: 34vh;
    max-height: 300px;
    min-height: 160px;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 2px solid var(--border);
    opacity: 1;
    pointer-events: auto;
    transition: height .35s cubic-bezier(.4, 0, .2, 1), min-height .35s ease, max-height .35s ease, border-width .35s ease, opacity .25s ease;
  }
  #poolPanel.collapsed {
    width: 100% !important;
    height: 0 !important;
    max-height: 0 !important;
    min-height: 0 !important;
    border-bottom-width: 0;
    opacity: 0;
    pointer-events: none;
  }
  #poolHeader { flex-wrap: wrap; gap: 6px; }
  .algo-divider { display: none; }
  #filters { flex: 1 1 100%; min-width: 0; }
  #classesPanel { flex: 1; min-height: 0; padding: 6px; overflow-x: auto; overflow-y: auto; }
  #classesArea { gap: 6px; }
  .card-right { width: auto; max-width: 100%; }

  #speGroupPanel { padding: 0 10px; gap: 8px; }
}

@media (max-width: 768px) {
  :root {
    --col-w: 240px;
    --stats-h: 44px;
    --algo-h: 52px;
  }

  .app-title { font-size: 18px; }
  .app-logo  { height: 32px; width: 32px; }

  /* ── Toolbar 2 lignes : brand+menus ligne 1, outils ligne 2 ── */
  body.app-page #toolbar .tb-tools {
    order: 3;
    flex: 1 1 100%;
  }
  body.app-page #toolbar .tb-right {
    order: 2;
  }

  /* ── Panneaux déroulants pleine largeur sous la bannière ── */
  .tb-menu { position: static; }
  .tb-menu-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 8px;
    right: 8px;
    width: auto;
    min-width: 0;
    max-width: none;
  }

  body.app-page #toolbar .file-label {
    flex: 1;
    max-width: none;
  }
  body.app-page #toolbar .btn-import {
    flex: 1 1 auto;
  }

  /* Modales & popups */
  .edit-popup { align-items: flex-end; padding: 0; }
  .edit-popup-box {
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
  }
  .edit-popup-body { overflow-y: auto; max-height: calc(92vh - 120px); }
  .edit-popup-footer,
  .edit-popup-footer--triple { flex-direction: column; align-items: stretch; }
  .edit-popup-footer .btn,
  .edit-popup-footer--triple .btn { width: 100%; justify-content: center; }

  #groupsModal { align-items: flex-end; }
  .groups-modal-box {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--radius) var(--radius) 0 0;
    animation: drawer-up .2s ease;
  }
  @keyframes drawer-up {
    from { transform: translateY(24px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
  }
  .groups-modal-header { flex-wrap: wrap; gap: 8px; }
  .groups-filter-spe { max-width: none; flex: 1; min-width: 120px; }
  .grp-card { width: calc(50% - 4px); min-width: 0; }

  .options-modal-box { width: calc(100vw - 16px); max-width: 100%; max-height: 92vh; }
  .options-modal-body { max-height: calc(92vh - 160px); }
  .options-modal-footer { flex-wrap: wrap; }
  .options-modal-footer input { flex: 1 1 calc(50% - 3px); min-width: 120px; }
  .option-row { flex-wrap: wrap; gap: 6px; }

  #notifContainer { left: 10px; right: 10px; top: 10px; }
  .notif { max-width: none; width: 100%; }
}

@media (max-width: 480px) {
  :root {
    --col-w: 240px;
    --stats-h: 42px;
    --algo-h: 48px;
    --spe-h: 32px;
  }

  .app-title { font-size: 18px; }

  body.app-page #toolbar {
    padding: 8px 10px;
  }

  #poolPanel {
    height: 30vh;
    min-height: 140px;
  }
  .btn-toggle-pool {
    height: 36px;
    padding: 0 10px;
    font-size: 10px;
  }
  .grp-card {
    width: 100%;
  }
  .options-modal-footer input {
    flex: 1 1 100%;
  }
}

/* Cibles tactiles plus grandes sur écran touch */
@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 36px;
    padding: 6px 11px;
  }
  .btn-sentiment {
    width: 44px;
    height: 40px;
  }
  .eleve-card {
    min-height: 32px;
    padding: 4px 3px 4px 20px;
  }
  .btn-edit-eleve {
    opacity: 1;
    min-width: 28px;
    min-height: 28px;
  }
  .btn-toggle-pool {
    min-height: 40px;
    height: 40px;
    padding: 0 12px;
  }
  .conseils-picker-item,
  .conseils-tab,
  .conseils-picker-tab {
    min-height: 44px;
  }
}
