.visual-main {
  width: 100%;
  max-width: min(1600px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 1rem 1.25rem 5rem;
}

.visual-lead-section {
  margin-bottom: 1rem;
}

.visual-lead-heading {
  position: relative;
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  padding-right: 2rem;
}

.visual-lead-heading > a.hidden_show_button {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

.visual-lead-heading > a.hidden_show_button::after {
  padding-right: 0;
}

.visual-lead {
  margin-bottom: 0;
  color: #444;
}

.visual-toolbar {
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.visual-setup {
  margin-bottom: 0.75rem;
}

.visual-playback {
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.visual-main.playback-mode .visual-toolbar {
  display: none;
}

.visual-main.playback-mode .visual-playback {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1040;
  width: 100%;
  max-width: min(1600px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 0.75rem 1.25rem 1rem;
  border-radius: 0;
  border: none;
  border-top: 1px solid #dee2e6;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
  background: #fff;
}

.visual-main.playback-mode .visual-controls {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
  justify-content: center;
}

.visual-main.playback-mode .visual-controls .btn {
  min-width: 2.75rem;
  padding: 0.45rem 0.7rem;
}

.visual-main.playback-mode .visual-step-message {
  margin-top: 0.5rem;
  margin-bottom: 0;
  max-height: 4.5rem;
  overflow-y: auto;
  font-size: 0.9rem;
}

.visual-toolbar .form-row {
  flex-wrap: wrap;
}

.visual-action-buttons {
  flex: 0 0 auto;
  min-width: 0;
}

.visual-action-label {
  display: block;
  margin-bottom: 0;
  line-height: 1.5;
  visibility: hidden;
}

.visual-action-button-row {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 0.5rem;
  white-space: nowrap;
}

.visual-action-button-row .btn {
  margin: 0;
  flex: 0 0 auto;
}

.visual-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e9ecef;
}

.visual-step-counter {
  margin-left: 0.5rem;
  font-variant-numeric: tabular-nums;
  color: #555;
}

.visual-stage {
  padding: 1.25rem;
}

.visual-settings-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  background: #f4f6f8;
  border-radius: 6px;
  font-size: 0.9rem;
  color: #444;
}

.visual-settings-summary[hidden] {
  display: none !important;
}

.visual-settings-summary-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.visual-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 10rem minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.visual-panel {
  padding: 0.75rem;
  border-radius: 8px;
}

#studentPanel {
  background: #fff5f5;
  border: 1px solid #f0d4d4;
}

#schoolPanel {
  background: #f0f7ff;
  border: 1px solid #d4e6f5;
}

#studentPanel h3 {
  font-size: 1.05rem;
  margin-bottom: 0.75rem;
  color: #922b21;
}

#schoolPanel h3 {
  font-size: 1.05rem;
  margin-bottom: 0.75rem;
  color: #1a5276;
}

#studentPanel .pref-row {
  background: #fff;
  border-color: #e8c4c4;
}

#schoolPanel .pref-row {
  background: #fff;
  border-color: #c4d9eb;
}

.visual-connector-wrap {
  position: relative;
  min-height: 12rem;
  align-self: stretch;
}

.visual-connector {
  width: 100%;
  height: 100%;
  min-height: 12rem;
  overflow: visible;
  pointer-events: none;
}

.pref-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pref-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid #dde2ea;
  border-radius: 6px;
  background: #fafbfc;
  transition: background 0.15s, border-color 0.15s;
}

.pref-row.active-student {
  border-color: #c0392b;
  background: #fff5f5;
}

.pref-row.active-school {
  border-color: #2471a3;
  background: #f0f7ff;
}

.pref-row.matched-student {
  box-shadow: inset 3px 0 0 #c0392b;
}

.pref-row.matched-school {
  box-shadow: inset 3px 0 0 #2471a3;
}

.pref-label {
  flex: 0 0 1.75rem;
  font-weight: 700;
  font-size: 0.9rem;
  padding-top: 0.15rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.pref-label-student {
  color: #c0392b;
}

.pref-label-school {
  color: #2471a3;
}

.pref-row-main {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
  min-width: 0;
}

.school-cap-section {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e9ecef;
}

.school-cap-toggle {
  padding-left: 0;
  font-size: 0.9rem;
}

.school-cap-panel {
  margin-top: 0.5rem;
}

.school-cap-hint {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: #666;
}

.school-cap-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}

.school-cap-input-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.school-cap-input-row label {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.school-cap-input {
  width: 5.5rem;
  min-width: 0;
}

.school-cap-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  font-size: 0.8rem;
}

.school-cap-label {
  color: #555;
  font-weight: 600;
  white-space: nowrap;
}

.cap-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.cap-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.65rem;
  height: 1.35rem;
  padding: 0 0.25rem;
  border: 1px dashed #b8c4d4;
  border-radius: 3px;
  background: #f8fafc;
  color: #8a96a8;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.cap-slot.filled {
  border-style: solid;
  border-color: #27ae60;
  background: #eafaf1;
  color: #1e8449;
  font-weight: 700;
}

.cap-slot.replaced {
  border-color: #c0392b;
  background: #fdecea;
  color: #922b21;
}

.pref-items {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  flex: 1;
  min-width: 0;
  min-height: 1.75rem;
  padding: 0.15rem;
  border-radius: 4px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.pref-items.drop-target {
  background: #eef6ff;
  outline: 1px dashed #2471a3;
}

.pref-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  flex: 0 0 auto;
  padding: 0.15rem 0.35rem;
  border: 1px solid #c8d0dc;
  border-radius: 4px;
  background: #fff;
  font-size: 0.85rem;
  cursor: grab;
  touch-action: none;
  -webkit-user-drag: element;
  user-select: none;
  font-variant-numeric: tabular-nums;
}

.pref-chip-student {
  border-color: #e8b4b0;
  background: #fff5f5;
  color: #922b21;
}

.pref-chip-school {
  border-color: #a8c5db;
  background: #eef6ff;
  color: #1a5276;
}

.pref-chip-label {
  line-height: 1.2;
}

.pref-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  border: none;
  border-radius: 2px;
  background: transparent;
  color: #888;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
}

.pref-chip-remove:hover {
  background: #fdecea;
  color: #c0392b;
}

.pref-excluded {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
  font-size: 0.78rem;
}

.pref-excluded-label {
  color: #777;
  white-space: nowrap;
}

.pref-excluded-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.4rem;
  border: 1px dashed #a8c5db;
  border-radius: 3px;
  background: #f4f8fc;
  color: #5d7f9d;
  font-size: 0.78rem;
  cursor: pointer;
}

.pref-excluded-chip:hover {
  border-style: solid;
  border-color: #2471a3;
  background: #eef6ff;
  color: #1a5276;
}

.pref-chip:active {
  cursor: grabbing;
}

.pref-chip.dragging {
  opacity: 0.45;
}

.pref-chip.highlight-propose {
  background: #fdecea;
  border-color: #c0392b;
  color: #922b21;
  font-weight: 700;
}

.pref-chip.highlight-held {
  background: #eaf2f8;
  border-color: #2471a3;
  color: #1a5276;
  font-weight: 700;
}

.pref-chip.tentative-match {
  outline: 2px solid #27ae60;
}

.visual-step-message {
  margin: 0.75rem 0 0;
  padding: 0.75rem 1rem;
  background: #f4f6f8;
  border-radius: 6px;
  line-height: 1.5;
  word-break: break-word;
}

.connector-line {
  fill: none;
}

.connector-line.tentative {
  stroke: #27ae60;
  stroke-width: 1.5;
  opacity: 0.75;
}

.connector-line.proposal {
  stroke: #222;
  stroke-width: 2.5;
}

.connector-line.final {
  stroke: #222;
  stroke-width: 1.5;
}

.connector-line.evicted {
  stroke: #c0392b;
  stroke-width: 1.5;
  opacity: 0.85;
}

@media (max-width: 768px) {
  .visual-columns {
    grid-template-columns: 1fr;
  }

  .visual-connector-wrap {
    min-height: 80px;
    order: 2;
  }
}
