:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #d9dce1;
  --text: #24292f;
  --text-muted: #6b7280;
  --accent: #2f6feb;
  --accent-dark: #1d4ed8;
  --danger: #d33;
  --girl: #e69f00;
  --boy: #0072b2;
  --none: #9aa0a6;
  --adult: #8a63d1;
  --good: #2f9e44;
  --radius: 8px;
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button {
  font: inherit;
  cursor: pointer;
}

.btn {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  color: var(--text);
  display: inline-block;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: #eef1f6; border-color: #c5cad3; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: white;
  box-shadow: 0 1px 3px rgba(47, 111, 235, 0.35);
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover { background: #eef1f6; border-color: transparent; }
.btn.danger, .btn-ghost.danger { color: var(--danger); }

.icon-toggle-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 13px;
  flex-shrink: 0;
}
.icon-toggle-btn:hover {
  background: #eef1f6;
  border-color: var(--border);
  color: var(--text);
}

.menu-bar {
  position: relative;
  z-index: 5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.menu-bar.collapsed {
  display: none;
}
.menu-expand-btn {
  position: fixed;
  top: 0;
  right: 20px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 5px 14px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}
.menu-expand-btn[hidden] {
  display: none;
}
#renameSubgroupBtn[hidden],
#deleteSubgroupBtn[hidden] {
  display: none;
}
.menu-expand-btn:hover {
  background: #eef1f6;
  color: var(--text);
}

.interrogate-fab-wrap {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.interrogate-fab {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  padding: 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.interrogate-fab .btn-primary {
  border-radius: 999px;
  padding: 9px 14px;
  font-weight: 600;
}
.interrogate-fab .fab-reset {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.interrogate-fab .fab-reset.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent-dark);
}
.interrogate-fab .fab-reset:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.favorite-motif-indicator {
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.favorite-motif-indicator.bonus { background: var(--good); }
.favorite-motif-indicator.malus { background: var(--danger); }

.appbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.app-logo {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}
.appbar h1 {
  font-size: 18px;
  margin: 0 10px 0 0;
  white-space: nowrap;
  color: var(--accent-dark);
  letter-spacing: -0.2px;
}
.appbar-spacer {
  flex: 1;
}

.context-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px 3px 4px;
  border-radius: 999px;
  background: #eef1f6;
}
.context-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  padding: 0 6px;
  white-space: nowrap;
}
.context-select {
  font: inherit;
  font-weight: 600;
  max-width: 190px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}
.context-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.context-group .icon-toggle-btn {
  width: 26px;
  height: 26px;
  font-size: 12px;
}
.context-room {
  background: #f2ead8;
}
.context-room .context-label {
  color: #8a6d23;
}
.context-room .context-select {
  border-color: #d9c79a;
}

.menubar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.menu-dropdown {
  position: relative;
}
.menu-trigger {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 6px 12px;
  color: var(--text);
  white-space: nowrap;
}
.menu-trigger:hover {
  background: #eef1f6;
}
.menu-trigger[aria-expanded="true"] {
  background: #e4eafd;
  border-color: #c3d2f8;
  color: var(--accent-dark);
}
.menu-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  min-width: 240px;
  display: none;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
}
.menu-dropdown.open .menu-panel {
  display: flex;
}
.menu-item {
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 7px 10px;
  text-align: left;
  color: var(--text);
  white-space: nowrap;
}
.menu-item:hover {
  background: #eef1f6;
}
.menu-item.danger {
  color: var(--danger);
}
.menu-item:disabled,
.menu-row input:disabled,
.menu-row .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.menu-item:disabled:hover {
  background: transparent;
}
#roomLockLabel {
  font-weight: 600;
  color: var(--text);
}

/* Salle verrouillée : toutes les poignées et actions qui modifient la géométrie disparaissent,
   y compris celles rendues permanentes par body.touch-mode. Les badges de score, le bouton
   d'absence et le placement des élèves restent intacts. */
body.room-locked .room-handle,
body.room-locked .furniture-actions,
body.room-locked .furniture-handle,
body.room-locked .seat-remove {
  display: none;
}
/* Salle verrouillée : la bande grise de débordement n'a plus de raison d'être (rien ne peut plus
   être déplacé), le plan se limite aux murs et rogne ce qui les dépasse. */
body.room-locked .board {
  background: transparent;
  border-color: transparent;
  overflow: hidden;
}
body.room-locked .seat {
  cursor: pointer;
}
body.room-locked .furniture,
body.room-locked .board-front {
  cursor: default;
}
.menu-sep {
  height: 1px;
  margin: 4px 2px;
  background: var(--border);
}
.menu-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
}
.menu-row label {
  color: var(--text-muted);
  font-size: 13px;
}
.menu-check {
  padding: 7px 10px;
  border-radius: 6px;
}
.menu-check:hover {
  background: #eef1f6;
}
#seatCountInput {
  width: 60px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chk-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}
.chk-label input {
  margin: 0;
}
.chk-label.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.roster {
  width: 260px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
  overflow: hidden;
}
.roster.collapsed {
  display: none;
}
.roster-expand-btn {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 6px 6px 0;
  padding: 12px 6px;
  cursor: pointer;
  color: var(--text-muted);
}
.roster-expand-btn:hover {
  background: #eef1f6;
  color: var(--text);
}
.roster-head {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
#studentSearch {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.roster-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 8px;
}
.bulk-subgroup-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
  font-size: 12px;
}
.bulk-subgroup-bar[hidden] {
  display: none;
}
.bulk-subgroup-bar select {
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
#bulkSelectToggleBtn[hidden] {
  display: none;
}
#bulkSelectToggleBtn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-dark);
}
.student-bulk-check {
  flex-shrink: 0;
}
.student-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
.student-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
}
.student-item:hover { background: #eef1f6; }
.student-item.selected {
  background: #e4edff;
  border-color: var(--accent);
}
.student-item.seated {
  opacity: 0.55;
}
.student-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--none);
}
.student-dot.F { background: var(--girl); }
/* Indice de forme redondant avec la couleur : la pastille des garçons est un carré à angles vifs,
   celle des filles un rond — la distinction reste lisible sans percevoir les couleurs, à
   condition que la pastille soit assez grande pour que la forme se lise (14 px). */
.student-dot.M {
  background: var(--boy);
  border-radius: 1px;
}
body.no-gender-colors .student-dot.F { background: var(--boy); }
body.no-gender-colors .student-dot.M { border-radius: 50%; }
.student-name {
  flex: 1;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.zone-badge {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: #eef1f6;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.score-badge {
  flex-shrink: 0;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  border: none;
  line-height: 1.5;
}
.score-badge.bonus { background: #e3f6e8; color: var(--good); }
.score-badge.malus { background: #fbe4e4; color: var(--danger); }
.score-badge.zero { background: #eef1f6; color: var(--text-muted); }

.student-actions {
  display: none;
  gap: 4px;
}
.student-item:hover .student-actions { display: flex; }
.score-actions {
  display: none;
  gap: 4px;
}
.student-item:hover .score-actions,
body.score-touch-mode .score-actions {
  display: flex;
}
.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 12px;
}
.icon-btn:hover { background: #dfe4ea; color: var(--text); }

.board-wrap {
  flex: 1;
  overflow: hidden;
  background: var(--bg);
  padding: 16px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.board-scale {
  position: relative;
  flex-shrink: 0;
}
.board {
  position: relative;
  /* Fond gris = hors de la salle de base : tout ce qui déborde ici a forcé le plan à s'agrandir. */
  background: #e3e6ec;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  transform-origin: top left;
}
/* La salle : murs en trait plein, redimensionnable par ses poignées. */
.board-room {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 0;
  background: var(--panel);
  border: 2px solid #8c93a1;
  border-radius: 2px;
}
.room-handle {
  position: absolute;
  z-index: 1;
  background: var(--panel);
  border: 2px solid #8c93a1;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.12s ease;
  touch-action: none;
}
.board-room:hover .room-handle,
body.touch-mode .room-handle {
  opacity: 1;
}
.room-handle-e {
  right: -7px;
  top: 50%;
  width: 12px;
  height: 34px;
  margin-top: -17px;
  cursor: ew-resize;
}
.room-handle-s {
  bottom: -7px;
  left: 50%;
  width: 34px;
  height: 12px;
  margin-left: -17px;
  cursor: ns-resize;
}
.room-handle-se {
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
}

/* Le tableau : déplaçable et redimensionnable comme un meuble (position et taille dans
   room.board). Au-dessus du mobilier (z-index 0), sous les sièges (z-index 2). */
.board-front {
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #333;
  color: white;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-radius: 4px;
  cursor: move;
  user-select: none;
  touch-action: none;
}
.board-front .furniture-handle {
  border-color: #333;
}

.seat {
  position: absolute;
  z-index: 2;
  width: 96px;
  height: 64px;
  background: var(--panel);
  border: 2px solid var(--none);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4px;
  font-size: 12.5px;
  line-height: 1.25;
  user-select: none;
  touch-action: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.seat.empty {
  color: var(--text-muted);
  font-style: italic;
  border-style: dashed;
}

/* Table double : deux .seat contigus dessinés comme un seul meuble, séparés par un trait. */
.seat.pair-l {
  border-right-width: 1px;
  border-right-style: dashed;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.seat.pair-r {
  border-left: none;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.furniture {
  position: absolute;
  z-index: 0;
  background: #f0ece3;
  border: 2px solid #b9a77f;
  border-radius: 6px;
  color: #6d5b33;
  font-size: 12px;
  user-select: none;
  touch-action: none;
  cursor: move;
}
/* Le contenu (icône + libellé) ne pivote jamais : pivoter un meuble échange seulement sa
   largeur et sa hauteur, le texte reste lisible dans le sens de lecture normal. */
/* Une porte est une ouverture dans le mur, pas un meuble en bois : elle reprend la couleur des
   murs (fond blanc, trait plein) pour se lire comme une interruption de la cloison. */
.furniture-porte {
  background: var(--panel);
  border-color: #8c93a1;
  color: #5b626e;
}
.furniture-porte .furniture-btn {
  border-color: #8c93a1;
  color: #5b626e;
}
.furniture-porte .furniture-handle {
  border-color: #8c93a1;
}

.furniture-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 2px;
  text-align: center;
  overflow: hidden;
}
.furniture-icon {
  font-size: 15px;
  line-height: 1;
}
.furniture-label {
  line-height: 1.15;
  word-break: break-word;
}
.furniture-label-input {
  font: inherit;
  width: 90%;
  min-width: 40px;
  padding: 1px 3px;
  border: 1px solid var(--accent);
  border-radius: 4px;
}
.furniture-actions {
  position: absolute;
  top: -11px;
  right: -6px;
  display: flex;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.furniture:hover .furniture-actions {
  opacity: 1;
  pointer-events: auto;
}
body.touch-mode .furniture-actions {
  opacity: 1;
  pointer-events: auto;
}
.furniture-btn {
  width: 20px;
  height: 20px;
  padding: 0;
  font-size: 11px;
  line-height: 1;
  background: var(--panel);
  border: 1px solid #b9a77f;
  border-radius: 50%;
  color: #6d5b33;
}
.furniture-btn:hover {
  background: #f5efe2;
}
.furniture-handle {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 12px;
  height: 12px;
  background: var(--panel);
  border: 2px solid #b9a77f;
  border-radius: 3px;
  cursor: nwse-resize;
  opacity: 0;
  pointer-events: none;
  touch-action: none;
}
.furniture:hover .furniture-handle,
.board-front:hover .furniture-handle {
  opacity: 1;
  pointer-events: auto;
}
body.touch-mode .furniture-handle {
  opacity: 1;
  pointer-events: auto;
}

.menu-section-label {
  padding: 4px 10px 2px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}
#fillOrderSelect {
  font: inherit;
  font-size: 13px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}
.seat.F { border-color: var(--girl); }
.seat.M { border-color: var(--boy); }
body.no-gender-colors .seat.F { border-color: var(--boy); }
.seat:active {
  cursor: grabbing;
  box-shadow: 0 4px 10px rgba(0,0,0,0.18);
}
.seat.seat-selected {
  box-shadow: 0 0 0 3px var(--accent), 0 4px 10px rgba(0,0,0,0.18);
  z-index: 2;
}
.seat-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.seat:hover .seat-remove,
body.touch-mode .seat-remove {
  opacity: 1;
  pointer-events: auto;
}
.seat-name {
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.seat-prenom {
  font-size: 14px;
  font-weight: 600;
}
.seat-nom {
  font-size: 10px;
  color: var(--text-muted);
}

.seat.absent {
  opacity: 0.6;
  background: repeating-linear-gradient(45deg, var(--panel), var(--panel) 6px, #f6dede 6px, #f6dede 12px);
  border-color: var(--danger);
  border-style: dashed;
}
.seat-absent-toggle {
  position: absolute;
  top: -8px;
  left: -8px;
  height: 16px;
  padding: 0 4px;
  border-radius: 4px;
  background: #fff;
  border: 1.5px solid #b9bfca;
  color: #8a91a0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.seat:hover .seat-absent-toggle,
body.touch-mode .seat-absent-toggle {
  opacity: 1;
  pointer-events: auto;
}
.seat.absent .seat-absent-toggle {
  background: #fff;
  border-color: #16181d;
  color: #16181d;
}
body.placement-locked .seat.empty,
body.placement-locked .seat.adult-seat {
  cursor: default;
}
/* Retour visuel du bonus rapide : le siège pulse brièvement après l'ajout du point. */
.seat.score-flash {
  animation: score-flash 0.7s ease;
}
@keyframes score-flash {
  0% { box-shadow: 0 0 0 0 rgba(34, 160, 90, 0.55); }
  40% { box-shadow: 0 0 0 10px rgba(34, 160, 90, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 160, 90, 0); }
}
.fav-motif {
  flex-shrink: 0;
  color: #b9bfca;
}
.fav-motif.is-fav {
  color: #c98a00;
}

.seat-score-badges {
  position: absolute;
  bottom: -8px;
  right: -8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.seat:hover .seat-score-badges,
body.touch-mode .seat-score-badges,
body.score-touch-mode .seat-score-badges {
  opacity: 1;
  pointer-events: auto;
}
.seat-score-badge {
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18);
}
.seat-absent-label {
  position: absolute;
  bottom: 4px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--danger);
  text-transform: uppercase;
  pointer-events: none;
}

.seat.adult-seat {
  color: var(--adult);
  font-style: italic;
  border-color: var(--adult);
  border-style: dashed;
  background: repeating-linear-gradient(45deg, var(--panel), var(--panel) 6px, #ede7fa 6px, #ede7fa 12px);
}
.seat-adult-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 600;
}
.seat-adult-of {
  font-size: 10px;
  font-style: normal;
  font-weight: 400;
  opacity: 0.85;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  align-items: center;
  justify-content: center;
  z-index: 50;
  display: none;
}
.modal-overlay:not([hidden]) {
  display: flex;
}
.modal {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  width: 340px;
  max-width: 90vw;
}
.modal.modal-wide {
  width: 480px;
}
.modal.modal-import {
  width: 720px;
  max-width: 92vw;
}
.modal h2 {
  margin-top: 0;
  font-size: 16px;
}
.modal label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin: 10px 0 4px;
}
.modal input, .modal select {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.modal input[type="checkbox"],
.modal input[type="radio"] {
  width: auto;
  padding: 0;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.modal-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin: 4px 0 12px;
}
.alert-overlay {
  z-index: 60;
}
.alert-modal p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-line;
}
.modal label.chk-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 10px 0;
}
.modal-envelope {
  text-align: center;
}
.envelope-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin: 14px 0 0;
}
.envelope-score-btn {
  margin: 12px auto 0;
  display: block;
}
.envelope-score-btn[hidden] {
  display: none;
}
.envelope-reset-btn {
  margin: 8px auto 0;
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}
.envelope-stage {
  position: relative;
  width: 220px;
  height: 230px;
  margin: 10px auto 0;
  cursor: pointer;
  user-select: none;
}

.animated-mail {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  height: 150px;
  width: 200px;
  transition: transform 0.4s;
}
.animated-mail.open {
  transform: translateX(-50%) translateY(50px);
}

.animated-mail .body {
  position: absolute;
  bottom: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 100px 200px;
  border-color: transparent transparent #e95f55 transparent;
  z-index: 2;
}

.animated-mail .top-fold {
  position: absolute;
  top: 50px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 50px 100px 0 100px;
  border-color: #cf4a43 transparent transparent transparent;
  transform-origin: 50% 0%;
  transition: transform 0.4s 0.4s, z-index 0.2s 0.4s;
  z-index: 2;
}
.animated-mail.open .top-fold {
  transition: transform 0.4s, z-index 0.2s;
  transform: rotateX(180deg);
  z-index: 0;
}

.animated-mail .back-fold {
  position: absolute;
  bottom: 0;
  width: 200px;
  height: 100px;
  background: #cf4a43;
  z-index: 0;
}

.animated-mail .left-fold {
  position: absolute;
  bottom: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 50px 0 50px 100px;
  border-color: transparent transparent transparent #e15349;
  z-index: 2;
}

.animated-mail .letter {
  position: absolute;
  left: 20px;
  bottom: 0;
  width: 160px;
  height: 60px;
  background: white;
  z-index: 1;
  overflow: hidden;
  transition: height 0.4s 0.2s;
}
.animated-mail.open .letter {
  height: 180px;
}

.letter-border {
  height: 10px;
  width: 100%;
  background: repeating-linear-gradient(-45deg, #cb5a5e, #cb5a5e 8px, transparent 8px, transparent 18px);
}
.letter-title {
  margin-top: 10px;
  margin-left: 5px;
  height: 10px;
  width: 40%;
  background: #cb5a5e;
}
.letter-context {
  margin-top: 10px;
  margin-left: 5px;
  height: 10px;
  width: 20%;
  background: #cb5a5e;
}
.letter-stamp {
  position: absolute;
  top: 12px;
  right: 12px;
  border-radius: 100%;
  height: 30px;
  width: 30px;
  background: #cb5a5e;
  opacity: 0.3;
}

.letter-name {
  position: absolute;
  left: 0;
  right: 0;
  top: 62px;
  padding: 0 10px;
  text-align: center;
}
.letter-name-first {
  font-weight: 700;
  font-size: 15px;
  color: #a8342f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.letter-name-last {
  margin-top: 3px;
  font-weight: 700;
  font-size: 14px;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shadow {
  position: absolute;
  left: 50%;
  top: 200px;
  width: 200px;
  height: 26px;
  transform: translateX(-50%);
  transition: width 0.4s;
  border-radius: 100%;
  background: radial-gradient(rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0));
}
.animated-mail.open ~ .shadow {
  width: 260px;
}
.constraint-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.constraint-form select {
  flex: 1;
  min-width: 120px;
  width: auto;
}
.constraint-form span {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.constraint-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}
.constraint-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

/* ---------- Bonus / Malus ---------- */

.score-popup-columns {
  display: flex;
  gap: 16px;
  margin-top: 4px;
}
.score-popup-col {
  flex: 1;
  min-width: 0;
}
.motif-col-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 8px;
}
.motif-col-title.bonus { color: var(--good); }
.motif-col-title.malus { color: var(--danger); }
.motif-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  padding: 7px 10px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 13px;
  text-align: left;
}
.motif-btn.bonus:hover { border-color: var(--good); background: #e3f6e8; }
.motif-btn.malus:hover { border-color: var(--danger); background: #fbe4e4; }
.motif-btn.is-fav { border-color: #c98a00; background: #fff6e0; }
.view-switch {
  display: inline-flex;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.view-switch-btn {
  padding: 6px 12px;
  border: none;
  background: var(--panel);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
}
.view-switch-btn + .view-switch-btn { border-left: 1px solid var(--border); }
.view-switch-btn.active { background: #fff6e0; color: #c98a00; font-weight: 700; }
.motif-points {
  font-weight: 700;
  color: var(--text-muted);
}

.score-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 280px;
  overflow-y: auto;
}
.score-history-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.score-history-date {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-muted);
  width: 110px;
}
.score-history-label { flex: 1; }
.score-history-points { font-weight: 700; }
.score-history-row.bonus .score-history-points { color: var(--good); }
.score-history-row.malus .score-history-points { color: var(--danger); }

.motif-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  max-height: 200px;
  overflow-y: auto;
}
.motif-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.motif-row-label {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.motif-row input.motif-points-input {
  width: 52px;
  flex-shrink: 0;
  padding: 4px 6px;
}
.motif-add-row {
  display: flex;
  gap: 6px;
}
.motif-add-row input[type="text"] {
  flex: 1;
  min-width: 0;
}
.motif-add-row input[type="number"] {
  width: 52px;
  flex-shrink: 0;
}
.bilan-sort-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.bilan-sort-row select {
  width: auto;
  flex: 1;
  min-width: 140px;
}
.bilan-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
}
.bilan-item {
  border-bottom: 1px solid var(--border);
  padding: 7px 4px;
}
.bilan-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.bilan-motif-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-bottom: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-alt);
}
.bilan-motif-filter-actions {
  display: flex;
  gap: 6px;
  flex-basis: 100%;
}
.bilan-motif-filter-actions .btn {
  padding: 3px 8px;
  font-size: 11px;
}
.bilan-motif-filter-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.bilan-motif-filter-item.bonus { background: #e3f6e8; color: var(--good); }
.bilan-motif-filter-item.malus { background: #fbe4e4; color: var(--danger); }
.bilan-motif-filter-item input { margin: 0; }
.bilan-matrix-wrap {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.bilan-matrix {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
}
.bilan-matrix th, .bilan-matrix td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}
.bilan-matrix th {
  position: sticky;
  top: 0;
  background: var(--bg-alt);
  font-weight: 700;
  z-index: 1;
}
.bilan-matrix th.bonus, .bilan-matrix td.bonus { color: var(--good); }
.bilan-matrix th.malus, .bilan-matrix td.malus { color: var(--danger); }
.bilan-matrix td.zero { color: var(--text-muted); }
.bilan-matrix td.bilan-name, .bilan-matrix th:nth-child(2), .bilan-matrix th:nth-child(3) {
  text-align: left;
}
.bilan-rank {
  flex-shrink: 0;
  width: 22px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: right;
}
.bilan-name {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Assistant d'import d'élèves ---------- */

.import-paste {
  width: 100%;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12.5px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
}
.import-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.import-file-name {
  font-size: 13px;
  color: var(--text-muted);
}
.import-options {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.import-sep-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
}
.import-options-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.import-sep-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  font-weight: 400;
  margin: 0;
}
.modal .import-sep-other-input {
  width: 32px;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: center;
}
.import-header-chk {
  margin-top: 10px;
}
.import-summary {
  font-size: 12px;
  color: var(--text-muted);
  margin: 12px 0 6px;
}
.import-preview-wrap {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.import-preview {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
}
.import-preview th {
  position: sticky;
  top: 0;
  background: #f7f8fa;
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 6px;
  text-align: left;
  min-width: 110px;
}
.import-preview td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.import-role-select {
  width: 100%;
  padding: 3px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
}
.import-col-header {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
}
.import-more-row {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: 6px;
}

/* ---------- Impression ---------- */

.print-area {
  display: none;
}

@media print {
  @page {
    size: landscape;
    margin: 12mm;
  }
  /* La taille effective de cette page nommée est injectée dynamiquement par
     buildPrintArea() (voir #printOrientationStyle dans js/app.js) — ne pas fixer
     `size` ici en dur, ce serait écrasé de toute façon et prêterait à confusion. */
  .print-page.use-alt-page {
    page: print-page-alt;
  }
  html, body {
    height: auto;
    overflow: visible;
    display: block;
    background: #fff;
  }
  body > *:not(.print-area) {
    display: none !important;
  }
  .print-area {
    display: block !important;
    background: #fff;
  }
  .print-page {
    background: #fff;
  }
  .print-page {
    page-break-after: always;
    position: relative;
  }
  .print-page:last-child {
    page-break-after: auto;
  }
  .print-page h2 {
    margin: 0 0 2px;
    font-size: 18px;
  }
  .print-meta {
    margin: 0 0 14px;
    font-size: 12px;
    color: #444;
  }
  .print-board-scale {
    position: relative;
  }
  .print-board {
    overflow: hidden;
    position: relative;
    border: 1px solid #999;
    transform-origin: top left;
  }
  .print-front {
    position: absolute;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid #000;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
  }
  .print-seat {
    position: absolute;
    /* Fond opaque : le mobilier est dessiné avant les sièges et transparaîtrait sinon. */
    background: #fff;
    width: 96px;
    height: 64px;
    border: 1.5px solid #000;
    border-radius: 6px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 12px;
    padding: 4px;
  }
  .print-seat.F {
    border-color: #a66c00;
  }
  .print-seat.M {
    border-color: #005b8f;
  }
  body.no-gender-colors .print-seat.F {
    border-color: #005b8f;
  }
  .print-seat.print-empty {
    border-style: dashed;
    color: #777;
    font-style: italic;
  }
  .print-seat.print-adult {
    border-style: dashed;
    border-color: #6b4fb0;
    color: #6b4fb0;
    font-style: italic;
    font-size: 10.5px;
  }
  .print-seat.pair-l {
    border-right-width: 0.75px;
    border-right-style: dashed;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }
  .print-seat.pair-r {
    border-left: none;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }
  .print-furniture {
    position: absolute;
    box-sizing: border-box;
    border: 1px solid #999;
    border-radius: 4px;
    background: #f2f2f2;
    color: #555;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2px;
    overflow: hidden;
  }
}
