:root {
  --primary: #06b6d4;
  --primary-hover: #0891b2;
  --primary-light: rgba(6, 182, 212, 0.12);
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.05);

  --gender-male: #0284c7;
  --gender-female: #ec4899;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --card-bg: #111827;
    --border: #1f2937;
    --text: #f9fafb;
    --text-muted: #9ca3af;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    --primary-light: rgba(6, 182, 212, 0.18);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 24px 16px;
}

.app-container {
  max-width: 1320px;
  margin: 0 auto;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-back:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.header-icon {
  width: 48px;
  height: 48px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
}

.header-icon svg {
  width: 26px;
  height: 26px;
}

h1 {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Mode Switch Tabs */
.mode-tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.mode-tab {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.mode-tab.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.3);
}

/* Layout */
.main-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 24px;
}

@media (max-width: 960px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
}

/* Sidebar */
.sidebar-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.sidebar-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.badge-count {
  background: var(--primary-light);
  color: var(--primary);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
}

.hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

#roster-input {
  width: 100%;
  height: 380px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.6;
  resize: vertical;
  margin-bottom: 12px;
  outline: none;
}

#roster-input:focus {
  border-color: var(--primary);
}

.roster-actions {
  display: flex;
  gap: 8px;
}

/* Common Buttons */
button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 16px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: linear-gradient(135deg, #06b6d4, #0284c7);
  color: #ffffff;
}

.btn-primary:hover {
  opacity: 0.92;
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.3);
}

.btn-secondary {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(148, 163, 184, 0.1);
  border-color: var(--text-muted);
}

/* Controls */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
}

.ctrl-group label {
  font-weight: 600;
  color: var(--text-muted);
}

select, input[type="number"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.88rem;
  outline: none;
}

select:focus, input:focus {
  border-color: var(--primary);
}

.checkbox-ctrl label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text);
}

/* Views */
.mode-view {
  display: none;
}

.mode-view.active {
  display: block;
}

/* Groups Output */
.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.group-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.group-card.is-oversized {
  border: 2px dashed #f97316 !important;
  background: #fffbf5 !important;
  box-shadow: 0 4px 14px rgba(249, 115, 22, 0.15) !important;
}

.group-card:hover {
  border-color: rgba(99, 102, 241, 0.35);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
}

/* Staggered Card Reveal Animation */
@keyframes groupCardReveal {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.96);
  }
  60% {
    opacity: 1;
    transform: translateY(-2px) scale(1.01);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.group-card-animate {
  animation: groupCardReveal 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@media (prefers-reduced-motion: reduce) {
  .group-card-animate {
    animation: none !important;
  }
}

.group-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.group-header-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.group-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.group-gender-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 9999px;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid rgba(99, 102, 241, 0.2);
  white-space: nowrap;
}

.group-score-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 9999px;
  background: rgba(245, 158, 11, 0.15);
  color: #b45309;
  border: 1px solid rgba(245, 158, 11, 0.3);
  white-space: nowrap;
}

.member-score-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.74rem;
  font-weight: 600;
  color: #d97706;
  background: rgba(245, 158, 11, 0.12);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

.group-gender-chip .chip-item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.group-gender-chip .chip-sep {
  opacity: 0.45;
  font-size: 0.75rem;
}

.group-members {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.member-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  padding: 4px 8px;
  background: rgba(148, 163, 184, 0.06);
  border-radius: 6px;
}

.gender-tag {
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.gender-male { background: rgba(2, 132, 199, 0.12); color: var(--gender-male); }
.gender-female { background: rgba(236, 72, 153, 0.12); color: var(--gender-female); }

/* Seating Output */
.chalkboard-podium {
  background: #1e293b;
  color: #f8fafc;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-bottom: 24px;
  border: 2px dashed #475569;
}

.seating-matrix {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.seating-row {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

.seating-export-area {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.seating-export-header {
  text-align: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
}

.seating-export-header h3 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 4px;
}

.seating-export-header p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.desk-block {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  min-width: 140px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.desk-header {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.seat-slot {
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: grab;
  user-select: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.seat-slot:active {
  cursor: grabbing;
}

.seat-slot.dragging {
  opacity: 0.45;
  transform: scale(0.96);
  border: 2px dashed var(--primary);
  background: var(--primary-light);
}

.seat-slot.drag-over {
  border: 2px dashed #0284c7;
  background: rgba(2, 132, 199, 0.15);
  transform: scale(1.04);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25);
}

.seat-slot.empty {
  color: var(--text-muted);
  font-style: italic;
  opacity: 0.75;
  border-style: dashed;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  background: var(--card-bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.app-footer {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* Toast Notification */
.toast-msg {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #f8fafc;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 9999;
  animation: toastFadeIn 0.25s ease-out;
}

@keyframes toastFadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media print {
  body {
    background: #ffffff;
    color: #000000;
    padding: 0;
  }
  .app-header .header-actions, .btn-back, .mode-tabs, .sidebar-card, .control-box, .app-footer {
    display: none !important;
  }
  .main-layout {
    display: block !important;
  }
  .seating-export-area, .card, .group-card, .desk-block {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    color: #000 !important;
    background: #fff !important;
  }
  .seat-slot {
    background: #fff !important;
    border-color: #ddd !important;
    color: #000 !important;
  }
  .chalkboard-podium {
    background: #f1f5f9 !important;
    color: #000 !important;
    border-color: #94a3b8 !important;
  }
}

/* Leader history is available with pointer, keyboard and touch focus. */
.member-item[data-student-id] { position: relative; }
.member-item.is-leader { outline: 2px solid #b7791f; outline-offset: -2px; }
.leader-history { white-space: nowrap; font-size: .85em; }
.leader-current { font-weight: 700; }
.member-item[data-leader-tooltip]:hover::after,
.member-item[data-leader-tooltip]:focus::after {
  content: attr(data-leader-tooltip);
  position: absolute;
  bottom: 100%;
  left: 0;
  z-index: 5;
  padding: .4rem .6rem;
  border-radius: .4rem;
  background: #1f2937;
  color: #fff;
  font-size: .85rem;
  pointer-events: none;
}

/* A4 Print Estimate & Scaling Options */
.print-estimate-panel {
  margin-bottom: 16px;
}
/* Trợ lý gợi ý in A4 tối ưu (Optimizer Advisor) */
.print-optimizer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: linear-gradient(135deg, #eef2ff 0%, #f0fdf4 100%);
  border: 1px solid #c7d2fe;
  border-radius: 10px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(79, 70, 229, 0.08);
}
.optimizer-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #312e81;
}
.optimizer-icon {
  font-size: 1.15rem;
  line-height: 1;
}
.optimizer-warning-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
  border-radius: 9999px;
  padding: 2px 8px;
  font-size: 0.74rem;
  font-weight: 700;
  margin-left: 6px;
}
.btn-optimize-a4 {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 7px 15px;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
}
.btn-optimize-a4:hover {
  background: linear-gradient(135deg, #4338ca 0%, #4f46e5 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.4);
}
.btn-optimize-a4:active {
  transform: translateY(0);
}
.group-oversize-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fdba74;
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: 700;
  margin-left: 6px;
}
.print-estimate {
  padding: 12px 16px;
  border: 1px solid #86b99a;
  border-radius: 10px;
  background: #effbf3;
  color: #185632;
  font-size: 0.92rem;
  line-height: 1.5;
}
.print-estimate[data-warning="true"] {
  background: #fff7ed;
  border-color: #e8ad63;
  color: #85430d;
}

/* Print Font Scaling Toolbar */
.print-scale-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}
.scale-label, .preview-bar-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: #334155;
}
.scale-btn-group {
  display: inline-flex;
  align-items: center;
  background: #e2e8f0;
  padding: 3px;
  border-radius: 8px;
  gap: 2px;
}
.btn-scale-opt {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-scale-opt:hover {
  color: #1e293b;
}
.btn-scale-opt.active {
  background: #ffffff;
  color: var(--primary, #4f46e5);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  font-weight: 700;
}
.btn-preview-a4 {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 7px 14px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-preview-a4:hover {
  background: #dbeafe;
  color: #1e40af;
  border-color: #93c5fd;
}
.btn-preview-a4 svg {
  flex-shrink: 0;
}

/* Print Scale Typography & Spacing (Screen & Print) */
/* Compact mode: fits 1 A4 page */
body .a4-groups[data-print-scale="compact"] .group-card,
#group-result[data-print-scale="compact"] .group-card {
  padding: 8px 12px !important;
  margin: 0 0 2mm !important;
  border-radius: 8px !important;
}
body .a4-groups[data-print-scale="compact"] .group-title,
#group-result[data-print-scale="compact"] .group-title {
  font-size: 0.92rem !important;
  font-weight: 800 !important;
}
body .a4-groups[data-print-scale="compact"] .group-members,
#group-result[data-print-scale="compact"] .group-members {
  gap: 3px !important;
}
body .a4-groups[data-print-scale="compact"] .member-item,
#group-result[data-print-scale="compact"] .member-item {
  font-size: 0.78rem !important;
  padding: 3px 6px !important;
}
body .a4-groups[data-print-scale="compact"] .leader-badge,
#group-result[data-print-scale="compact"] .leader-badge {
  font-size: 0.65rem !important;
  padding: 1px 4px !important;
}

/* Large mode: high visibility bulletin */
body .a4-groups[data-print-scale="large"] .group-card,
#group-result[data-print-scale="large"] .group-card {
  padding: 20px !important;
  margin: 0 0 6mm !important;
  border-radius: 14px !important;
}
body .a4-groups[data-print-scale="large"] .group-title,
#group-result[data-print-scale="large"] .group-title {
  font-size: 1.3rem !important;
  font-weight: 900 !important;
}
body .a4-groups[data-print-scale="large"] .group-members,
#group-result[data-print-scale="large"] .group-members {
  gap: 8px !important;
}
body .a4-groups[data-print-scale="large"] .member-item,
#group-result[data-print-scale="large"] .member-item {
  font-size: 1.05rem !important;
  padding: 8px 14px !important;
}
body .a4-groups[data-print-scale="large"] .leader-badge,
#group-result[data-print-scale="large"] .leader-badge {
  font-size: 0.8rem !important;
  padding: 3px 8px !important;
}

/* A4 Print Layout and Measurement Container */
.a4-measure {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 186mm;
  visibility: hidden;
  pointer-events: none;
}
@page { size: A4 portrait; margin: 12mm; }

@media print {
  .app-header { display: none !important; }
  .app-container, .content-area, .result-container { max-width: none !important; margin: 0 !important; padding: 0 !important; overflow: visible !important; }
  .group-card { page-break-inside: avoid; break-inside: avoid; }
  .modal-overlay, #modal-print-preview, .print-estimate-panel, .print-scale-toolbar, .print-estimate, .a4-measure {
    display: none !important;
  }
  #group-result { width: 100% !important; }
  #group-result .group-card { margin-bottom: 4mm; }
  .a4-groups .groups-grid { display: block !important; height: auto !important; overflow: visible !important; }
}

/* A4 Print Preview Modal Styles */
.print-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.print-preview-card {
  background: #f1f5f9;
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  width: 100%;
  max-width: 960px;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
}
.print-preview-card .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
}
.print-preview-card .modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #0f172a;
}
.print-preview-card .modal-title-wrap h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
}
.print-preview-card .btn-modal-close {
  background: #f1f5f9;
  border: none;
  font-size: 1.1rem;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #64748b;
  transition: all 0.15s;
}
.print-preview-card .btn-modal-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  flex-wrap: wrap;
}
.preview-scale-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}
.preview-page-summary {
  font-size: 0.85rem;
  font-weight: 600;
  color: #475569;
}
.preview-actions .btn-print-now {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-weight: 700;
  font-size: 0.9rem;
}

.preview-body {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  background: #cbd5e1;
}

/* Individual A4 Sheet in Preview */
.a4-sheet-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}
.a4-sheet-tag {
  font-size: 0.8rem;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.a4-preview-page {
  /* Standard A4 Aspect Ratio 1:1.4142 (210mm x 297mm) */
  width: 100%;
  max-width: 620px;
  aspect-ratio: 1 / 1.4142;
  background: #ffffff;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.25), 0 0 1px rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  padding: 5.7%; /* Proportional to 12mm margin on 210mm A4 width */
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
.a4-preview-page-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  overflow: hidden;
}
.a4-preview-page-content .group-card {
  box-shadow: none !important;
  border: 1px solid #cbd5e1 !important;
  background: #fff !important;
  margin: 0 0 4mm;
}
.a4-preview-page-footer {
  margin-top: auto;
  padding-top: 6px;
  border-top: 1px dashed #e2e8f0;
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: #94a3b8;
}

/* Measure and preview at physical print width; scale only the preview sheet. */
.a4-groups .group-card {
  animation: none !important;
  transform: none !important;
  flex-shrink: 0;
}
.a4-measure .group-card,
.a4-preview-page-content .group-card {
  margin: 0 0 4mm;
}
.a4-preview-page {
  width: 210mm;
  max-width: none;
  min-height: 297mm;
  aspect-ratio: auto;
  padding: 12mm;
  flex-shrink: 0;
  overflow: visible;
}
.a4-preview-page-content {
  display: block;
  height: auto;
  overflow: visible;
}

/* --- PRE-COMMIT GROUP BALANCE INSPECTOR MODAL & CONFETTI CANVAS --- */
.group-inspector-modal {
  position: fixed;
  inset: 0;
  z-index: 100000;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.group-inspector-card {
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.45);
  width: 100%;
  max-width: 1100px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.9);
}

.group-inspector-card .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.group-inspector-card .modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.group-inspector-card .modal-title-wrap h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.01em;
}

.group-inspector-card .modal-subtitle {
  margin: 3px 0 0;
  font-size: 0.8rem;
  color: #94a3b8;
}

.group-inspector-card .btn-modal-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  color: #e2e8f0;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.group-inspector-card .btn-modal-close:hover {
  background: rgba(239, 68, 68, 0.8);
  color: #ffffff;
  transform: scale(1.05);
}

/* Inspector Summary Bar */
.inspector-summary-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 24px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.inspector-metric-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #334155;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.inspector-metric-card .metric-val {
  font-weight: 800;
  color: #1e293b;
}

.inspector-metric-card.balance-badge-good {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}

.inspector-metric-card.balance-badge-good .metric-val {
  color: #047857;
}

.inspector-metric-card.balance-badge-warn {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

/* Swap Notice Bar */
.inspector-swap-prompt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 24px;
  background: #eff6ff;
  border-bottom: 1px solid #dbeafe;
  font-size: 0.82rem;
  color: #1e40af;
  font-weight: 500;
  flex-wrap: wrap;
}

.inspector-swap-prompt-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.inspector-swap-prompt .swap-icon {
  font-size: 1.1rem;
}

.inspector-swap-prompt.has-selection {
  background: #fef3c7;
  border-color: #fde68a;
  color: #92400e;
  animation: pulseSwapPrompt 1.8s infinite ease-in-out;
}

@keyframes pulseSwapPrompt {
  0%, 100% { background: #fef3c7; }
  50% { background: #fde68a; }
}

.inspector-suggestion-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.inspector-smart-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  border: 1px solid #93c5fd;
  color: #1e3a8a;
  border-radius: 9999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(30, 58, 138, 0.08);
  animation: subtleGlow 2.5s infinite ease-in-out;
}

@keyframes subtleGlow {
  0%, 100% { box-shadow: 0 1px 3px rgba(30, 58, 138, 0.08); border-color: #93c5fd; }
  50% { box-shadow: 0 0 8px rgba(59, 130, 246, 0.35); border-color: #3b82f6; }
}

.btn-preview-smart-swap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #ffffff;
  color: #4f46e5;
  border: 1.5px solid #6366f1;
  border-radius: 9999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(99, 102, 241, 0.15);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-preview-smart-swap:hover {
  background: #eef2ff;
  border-color: #4338ca;
  color: #3730a3;
  transform: translateY(-1px);
}

.btn-preview-smart-swap:active {
  transform: translateY(0);
}

.btn-apply-smart-swap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: #ffffff;
  border: none;
  border-radius: 9999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-apply-smart-swap:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.4);
  background: linear-gradient(135deg, #4338ca 0%, #6d28d9 100%);
}

.btn-apply-smart-swap:active {
  transform: translateY(0);
}

/* Side-by-Side Visual Preview Before Swap Modal */
.swap-preview-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeInPreview 0.2s ease-out;
}

@keyframes fadeInPreview {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

.swap-preview-card {
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 20px 40px -10px rgba(15, 23, 42, 0.35), 0 0 0 1px rgba(15, 23, 42, 0.08);
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.swap-preview-header {
  padding: 16px 20px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.swap-preview-header-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preview-badge {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #4f46e5;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  padding: 2px 8px;
  border-radius: 9999px;
  width: fit-content;
}

.swap-preview-header-title h4 {
  margin: 0;
  font-size: 1.15rem;
  color: #0f172a;
  font-weight: 700;
}

.btn-preview-close {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #64748b;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-preview-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.swap-preview-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #f8fafc;
}

/* Comparison Metric Overview Banner */
.preview-metric-banner {
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.preview-metric-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.preview-metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
}

.preview-metric-val {
  font-size: 1rem;
  font-weight: 800;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 6px;
}

.preview-metric-improvement {
  color: #16a34a;
  background: #dcfce7;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 700;
}

/* Trajectory Narrative Summary Bar */
.preview-trajectory-narrative {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 8px 14px;
}

.trajectory-node {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.trajectory-role {
  color: #64748b;
  font-weight: 600;
  font-size: 0.78rem;
  background: #e2e8f0;
  padding: 2px 6px;
  border-radius: 4px;
}

.trajectory-name {
  color: #0f172a;
  font-weight: 700;
}

.trajectory-arrow-icon {
  font-weight: 800;
  color: #4f46e5;
  font-size: 1rem;
}

.trajectory-badge-status {
  font-size: 0.75rem;
  font-weight: 700;
  color: #4338ca;
  background: #e0e7ff;
  padding: 3px 10px;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Side-by-Side Comparison Grid */
.preview-compare-grid {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 14px;
}

/* Dynamic SVG Trajectory Overlay */
.preview-trajectory-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  overflow: visible;
}

.preview-trajectory-path {
  stroke-dasharray: 8 4;
  animation: trajectoryFlow 1.2s linear infinite;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.preview-trajectory-path.reduced-motion {
  stroke-dasharray: none;
  animation: none;
}

@keyframes trajectoryFlow {
  from {
    stroke-dashoffset: 24;
  }
  to {
    stroke-dashoffset: 0;
  }
}

.preview-arrow-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #6366f1;
  font-size: 1.6rem;
  font-weight: 800;
  z-index: 2;
}

.preview-arrow-stem {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: #ffffff;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.preview-arrow-subtext {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #64748b;
  letter-spacing: 0.5px;
}

.preview-col-card {
  background: #ffffff;
  border-radius: 12px;
  border: 1.5px solid #cbd5e1;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.preview-col-card.is-after {
  border-color: #6366f1;
  background: #faf5ff;
}

.preview-col-title {
  font-size: 0.88rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px dashed #e2e8f0;
  padding-bottom: 6px;
  color: #334155;
}

.preview-col-card.is-after .preview-col-title {
  color: #4f46e5;
  border-color: #e0e7ff;
}

.preview-group-roster {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preview-student-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #f1f5f9;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  color: #1e293b;
}

.preview-student-pill.highlight-swap {
  background: #fef08a;
  border: 1.5px solid #eab308;
  color: #854d0e;
  animation: swapPillPulse 1.5s infinite;
}

.preview-student-pill.highlight-new {
  background: #bbf7d0;
  border: 1.5px solid #22c55e;
  color: #15803d;
  font-weight: 700;
}

@keyframes swapPillPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

.preview-gender-tag {
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
}

.preview-gender-male {
  background: #dbeafe;
  color: #1d4ed8;
}

.preview-gender-female {
  background: #fce7f3;
  color: #be185d;
}

.swap-preview-footer {
  padding: 14px 20px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.preview-shortcuts-hint {
  font-size: 0.78rem;
  color: #64748b;
}

.preview-shortcuts-hint strong {
  background: #e2e8f0;
  padding: 1px 6px;
  border-radius: 4px;
  color: #0f172a;
}

/* Teacher Narration Live Subtitle Badge */
.preview-teacher-narration-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.86rem;
  line-height: 1.45;
  transition: all 0.25s ease;
}

.preview-teacher-narration-badge.is-info {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.preview-teacher-narration-badge.is-step {
  background: #eff6ff;
  border: 1.5px solid #93c5fd;
  color: #1e40af;
  animation: narrationStepPulse 1.2s infinite alternate;
}

.preview-teacher-narration-badge.is-success {
  background: #ecfdf5;
  border: 1.5px solid #6ee7b7;
  color: #065f46;
  font-weight: 600;
}

.preview-teacher-narration-badge .narration-icon {
  font-size: 1.15rem;
  flex-shrink: 0;
}

.preview-teacher-narration-badge .narration-text {
  flex: 1;
}

@keyframes narrationStepPulse {
  from { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.2); }
  to { box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15); }
}

/* Replay Speed Selector */
.replay-speed-selector {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e2e8f0;
  padding: 3px;
  border-radius: 8px;
}

.replay-speed-label {
  font-size: 0.76rem;
  font-weight: 700;
  color: #475569;
  padding: 0 4px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.btn-replay-speed {
  background: transparent;
  border: none;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  color: #475569;
  cursor: pointer;
  transition: all 0.18s ease;
  line-height: 1.2;
}

.btn-replay-speed:hover:not(.is-active) {
  background: rgba(255, 255, 255, 0.6);
  color: #0f172a;
}

.btn-replay-speed.is-active {
  background: #ffffff;
  color: #0284c7;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.swap-preview-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-preview-sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}

.btn-preview-sound-toggle.is-muted {
  opacity: 0.65;
  filter: grayscale(0.8);
}

.btn-preview-replay {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 0.88rem;
  color: #0369a1;
  background: #f0f9ff;
  border: 1.5px solid #7dd3fc;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-preview-replay:hover:not(:disabled) {
  background: #e0f2fe;
  border-color: #38bdf8;
  transform: translateY(-1px);
}

.btn-preview-replay:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Flying Ghost Avatar during Trajectory Simulation */
.trajectory-flying-ghost {
  position: absolute;
  z-index: 50;
  pointer-events: none;
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  color: #ffffff;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(56, 189, 248, 0.45), 0 2px 6px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  gap: 6px;
  will-change: transform, opacity;
  transform: translate(-50%, -50%);
  border: 2px solid #ffffff;
  animation: ghostGlow 1.2s infinite alternate;
}

@keyframes ghostGlow {
  from { box-shadow: 0 6px 14px rgba(56, 189, 248, 0.4), 0 0 10px rgba(99, 102, 241, 0.3); }
  to { box-shadow: 0 10px 24px rgba(56, 189, 248, 0.7), 0 0 18px rgba(99, 102, 241, 0.6); }
}

.preview-student-pill.replay-source-active {
  box-shadow: 0 0 0 3px #38bdf8;
  animation: pulseSource 0.6s infinite alternate;
}

.preview-student-pill.replay-target-active {
  box-shadow: 0 0 0 3px #22c55e;
  animation: pulseTarget 0.6s infinite alternate;
}

@keyframes pulseSource {
  from { transform: scale(1); opacity: 0.8; }
  to { transform: scale(1.05); opacity: 1; }
}

@keyframes pulseTarget {
  from { transform: scale(1); opacity: 0.8; }
  to { transform: scale(1.06); opacity: 1; }
}

.btn-preview-cancel {
  padding: 8px 16px;
  font-weight: 600;
  font-size: 0.88rem;
}

.btn-preview-confirm {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: #ffffff;
  padding: 8px 18px;
  font-weight: 700;
  font-size: 0.88rem;
  border-radius: 8px;
  border: none;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-preview-confirm:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
}

.btn-undo-smart-swap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #ffffff;
  color: #b45309;
  border: 1.5px solid #f59e0b;
  border-radius: 9999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(245, 158, 11, 0.15);
  transition: all 0.2s ease;
}

.btn-undo-smart-swap:hover {
  background: #fef3c7;
  color: #92400e;
  border-color: #d97706;
  transform: translateY(-1px);
}

.btn-undo-smart-swap:active {
  transform: translateY(0);
}

.inspector-diff-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  border-radius: 9999px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 600;
}

/* Inspector Body */
.inspector-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
  background: #f1f5f9;
}

.inspector-groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.inspector-group-col {
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid #cbd5e1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  transition: all 0.2s ease;
  overflow: hidden;
}

.inspector-group-col.drag-target {
  border: 2px dashed #3b82f6;
  background: #eff6ff;
  transform: scale(1.01);
}

.inspector-group-head {
  padding: 12px 14px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.inspector-group-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: #1e293b;
}

.inspector-group-stat {
  font-size: 0.76rem;
  font-weight: 700;
  color: #475569;
  background: #e2e8f0;
  padding: 3px 8px;
  border-radius: 9999px;
}

.inspector-member-list {
  padding: 10px;
  list-style: none;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 80px;
  flex: 1;
}

.inspector-member-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: grab;
  user-select: none;
  transition: all 0.15s ease;
}

.inspector-member-item:hover {
  border-color: #94a3b8;
  background: #f8fafc;
  transform: translateY(-1px);
}

.inspector-member-item:active {
  cursor: grabbing;
}

.inspector-member-item.dragging {
  opacity: 0.4;
  border: 2px dashed #6366f1;
  background: #eef2ff;
}

.inspector-member-item.drag-over {
  border: 2px dashed #0284c7;
  background: #e0f2fe;
}

.inspector-member-item.swap-selected {
  border: 2px solid #f59e0b;
  background: #fffbeb;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25);
  animation: bounceSelect 0.3s ease;
}

.inspector-member-item.swap-haptic-highlight {
  border: 2px solid #10b981;
  background: #ecfdf5;
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.35);
  animation: hapticPulse 0.8s ease-out;
}

@keyframes hapticPulse {
  0% { transform: scale(0.95); background: #a7f3d0; }
  35% { transform: scale(1.05); background: #d1fae5; box-shadow: 0 0 12px rgba(16, 185, 129, 0.5); }
  70% { transform: scale(0.98); }
  100% { transform: scale(1); background: #ecfdf5; }
}

@keyframes bounceSelect {
  0% { transform: scale(0.96); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

.inspector-member-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inspector-member-badges {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.btn-swap-cue {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  border-radius: 6px;
  color: #64748b;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-swap-cue:hover {
  background: #e0e7ff;
  border-color: #a5b4fc;
  color: #4f46e5;
}

/* Inspector Footer */
.inspector-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  gap: 16px;
  flex-wrap: wrap;
}

.inspector-footer-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: #64748b;
}

.status-indicator {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.inspector-footer-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.btn-commit-podium {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #059669 0%, #10b981 100%);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  padding: 9px 20px;
  font-size: 0.92rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-commit-podium:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.45);
  background: linear-gradient(135deg, #047857 0%, #059669 100%);
}

.btn-commit-podium:active {
  transform: translateY(0);
}

/* Confetti TV Podium Canvas */
.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 100001;
}

/* TV Podium Reveal Celebration Animation */
.podium-celebrate-overlay {
  animation: podiumGlowFlash 1s ease-out;
}

@keyframes podiumGlowFlash {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.8); }
  50% { box-shadow: 0 0 40px 10px rgba(16, 185, 129, 0.4); }
  100% { box-shadow: none; }
}

/* Single-step inspector history and feedback for suggested changes. */
.inspector-history {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  color: #334155;
}
.inspector-history button:disabled { opacity: .45; cursor: default; }
.inspector-member-item.swap-pulse { animation: inspectorSwapPulse .65s ease-in-out 2; }
@keyframes inspectorSwapPulse {
  50% { background: #dcfce7; box-shadow: inset 0 0 0 2px #16a34a; }
}
@media (prefers-reduced-motion: reduce) {
  .inspector-member-item.swap-pulse { animation: none; outline: 2px solid #16a34a; }
}

@media (max-width: 640px) {
  .preview-compare-grid { grid-template-columns: minmax(0, 1fr); }
  .preview-arrow-divider { transform: rotate(90deg); }
  .swap-preview-footer { flex-wrap: wrap; gap: 12px; }
  .preview-metric-banner { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  .swap-preview-backdrop, .preview-student-pill.highlight-swap { animation: none; }
}

/* Keep transfer summaries and long student names within the preview modal. */
.preview-trajectory-narrative, .trajectory-node { flex-wrap: wrap; }
.trajectory-node, .preview-col-card, .preview-student-pill > span { min-width: 0; }
.trajectory-name, .preview-student-pill > span { overflow-wrap: anywhere; }
.preview-student-pill.highlight-swap { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .preview-trajectory-path { animation: none; stroke-dasharray: none; }
}

/* Keep replay legible without motion for users who request it. */
@media (prefers-reduced-motion: reduce) {
  .trajectory-flying-ghost,
  .preview-student-pill.replay-source-active,
  .preview-student-pill.replay-target-active { animation: none; }
}

/* Replay controls remain usable with keyboard and reduced motion. */
.btn-replay-speed:focus-visible {
  outline: 2px solid #0369a1;
  outline-offset: 2px;
}

.preview-teacher-narration-badge .narration-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
  .preview-teacher-narration-badge.is-step { animation: none; }
  .preview-teacher-narration-badge,
  .btn-replay-speed { transition: none; }
}

/* Visual Summary Snapshot & Sharing Export Buttons */
#btn-export-inspector-snapshot,
#btn-copy-inspector-snapshot,
#btn-export-swap-snapshot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

#btn-export-inspector-snapshot:hover,
#btn-copy-inspector-snapshot:hover,
#btn-export-swap-snapshot:hover {
  background-color: #f1f5f9;
  border-color: #cbd5e1;
}

@media (max-width: 640px) {
  .inspector-footer-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}


/* Full-size snapshot surface, independent of modal and mobile scroll limits. */
.snapshot-export-stage {
  position: absolute;
  left: -20000px;
  top: 0;
  width: 1120px;
  padding: 32px;
  box-sizing: border-box;
  background: #fff;
  color: #172033;
}
.snapshot-export-stage * {
  animation: none !important;
  transition: none !important;
  max-height: none !important;
  overflow: visible !important;
}
.snapshot-export-stage .inspector-body { display: flex; flex-wrap: wrap; }
.snapshot-export-stage .inspector-group-card { flex: 1 1 280px; }
#btn-export-inspector-snapshot:disabled,
#btn-copy-inspector-snapshot:disabled,
#btn-export-swap-snapshot:disabled { opacity: .6; cursor: wait; }
