:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e3e6eb;
  --border-strong: #c7ccd4;
  --text: #1c1f24;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --male: #2563eb;
  --male-soft: #dbeafe;
  --female: #db2777;
  --female-soft: #fce7f3;
  --mixed: #6b7280;
  --mixed-soft: #e5e7eb;
  --good: #16a34a;
  --good-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.title h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}
.title .subtitle {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

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

.file-input {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 120ms;
}
.file-input:hover { border-color: var(--border-strong); }
.file-input input[type="file"] { display: none; }
.file-label {
  font-weight: 500;
  font-size: 13px;
}
.file-name {
  color: var(--text-muted);
  font-size: 12px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-input.has-file .file-name { color: var(--text); }

button {
  font: inherit;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 500;
  transition: background 120ms, border-color 120ms, color 120ms;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
button.primary {
  background: var(--accent);
  color: white;
}
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
button.ghost:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.messages {
  padding: 0 24px;
}
.message {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
}
.message.error { border-color: #fca5a5; background: var(--bad-soft); color: #991b1b; }
.message.warn { border-color: #fcd34d; background: var(--warn-soft); color: #92400e; }
.message.info { border-color: #93c5fd; background: var(--male-soft); color: #1e3a8a; }

.stats {
  display: flex;
  gap: 12px;
  padding: 12px 24px 0;
  flex-wrap: wrap;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  min-width: 110px;
  box-shadow: var(--shadow-sm);
}
.stat-value {
  font-size: 22px;
  font-weight: 600;
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

.board {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  padding: 20px 24px 40px;
  align-items: start;
}

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

.unassigned-pane, .rooms-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.unassigned-pane h2, .rooms-pane h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.count {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.filter input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface);
}
.filter input:focus {
  outline: none;
  border-color: var(--accent);
}

.unassigned-zone {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 200px;
  max-height: calc(100vh - 280px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-sm);
}

.rooms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.legend {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.dot-male { background: var(--male); }
.dot-female { background: var(--female); }
.dot-mixed { background: var(--mixed); }

.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.room {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color 120ms, box-shadow 120ms;
}
.room.gender-male { border-top: 3px solid var(--male); }
.room.gender-female { border-top: 3px solid var(--female); }
.room.gender-mixed { border-top: 3px solid var(--mixed); }

.room-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.room-title {
  font-weight: 600;
  font-size: 14px;
}
.room-meta {
  font-size: 12px;
  color: var(--text-muted);
}
.room-meta .full { color: var(--bad); font-weight: 500; }
.room-meta .open { color: var(--good); font-weight: 500; }

.room-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 60px;
}

.dropzone.drag-over {
  background: var(--male-soft);
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}
.dropzone.drag-invalid {
  background: var(--bad-soft);
  outline: 2px dashed var(--bad);
  outline-offset: -4px;
}

.empty-slot {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  background: var(--surface-2);
}

.student {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: grab;
  user-select: none;
  transition: border-color 120ms, box-shadow 120ms, transform 120ms;
}
.student:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.student.dragging {
  opacity: 0.4;
}
.student .name {
  flex: 1;
  font-weight: 500;
}
.student .badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 500;
}
.student.gender-male { border-left: 3px solid var(--male); }
.student.gender-female { border-left: 3px solid var(--female); }
.student.gender-mixed { border-left: 3px solid var(--mixed); }

.student .pref-badge {
  background: var(--mixed-soft);
  color: var(--text-muted);
}
.student.met-good .pref-badge {
  background: var(--good-soft);
  color: #166534;
}
.student.met-some .pref-badge {
  background: var(--warn-soft);
  color: #92400e;
}
.student.met-none-with-prefs .pref-badge {
  background: var(--bad-soft);
  color: #991b1b;
}

.student .menu-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 2px 6px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 4px;
}
.student .menu-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.empty-state {
  padding: 30px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty-state details { margin-top: 12px; text-align: left; }
.empty-state summary { cursor: pointer; color: var(--accent); }
.empty-state p { margin: 6px 0; }

.tooltip {
  position: fixed;
  z-index: 100;
  background: #1c1f24;
  color: white;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  pointer-events: none;
  max-width: 280px;
  box-shadow: var(--shadow);
  line-height: 1.5;
}
.tooltip .tip-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tip-good { color: #86efac; }
.tooltip .tip-miss { color: #fca5a5; }
.tooltip .tip-other { color: #d1d5db; }
.tooltip h4 { margin: 0 0 4px; font-size: 12px; font-weight: 600; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
}
.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 900px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.3);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.modal-header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-actions { display: flex; gap: 8px; }
.modal-body {
  padding: 16px 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.report-section { margin-bottom: 24px; }
.report-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.report-section .count {
  background: var(--bad-soft);
  color: #991b1b;
  font-size: 12px;
  font-weight: 500;
  padding: 1px 8px;
  border-radius: 999px;
}

.report-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.report-summary > div {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
}
.report-summary strong { font-size: 18px; font-weight: 600; }
.report-summary span { font-size: 12px; color: var(--text-muted); }

.report-success {
  background: var(--good-soft);
  color: #166534;
  border: 1px solid #86efac;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  margin: 0;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.report-table th, .report-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.report-table thead th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}
.report-table tbody tr:hover { background: var(--surface-2); }
.report-table .unplaced { color: var(--bad); font-weight: 500; }
.report-table .prefs-cell { font-size: 12px; line-height: 1.6; }

.pref-with { color: #166534; }
.pref-without { color: #991b1b; }
.pref-unknown { color: var(--text-muted); }
.pref-with em, .pref-without em, .pref-unknown em {
  font-style: normal;
  color: var(--text-muted);
  font-size: 11px;
}

.report-rooms {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.report-room {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.report-room.gender-male { border-left: 3px solid var(--male); }
.report-room.gender-female { border-left: 3px solid var(--female); }
.report-room.gender-mixed { border-left: 3px solid var(--mixed); }
.report-room h4 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.report-room .muted { font-weight: 400; color: var(--text-muted); font-size: 12px; }
.report-occupants {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.report-occupants .ok { color: var(--good); font-weight: 600; }
.report-occupants .bad { color: var(--bad); font-weight: 600; }
.report-occupants .neutral { color: var(--text-muted); }

button.danger {
  color: #991b1b;
  border-color: #fca5a5;
}
button.danger:hover:not(:disabled) {
  background: var(--bad-soft);
  border-color: var(--bad);
}
button.small {
  padding: 4px 10px;
  font-size: 12px;
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.rooms-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.room-header-actions {
  display: inline-flex;
  gap: 4px;
  margin-left: 8px;
}
.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 2px 6px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1;
}
.icon-btn:hover {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.student .edit-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 2px 4px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 100ms;
}
.student:hover .edit-btn { opacity: 1; }
.student .edit-btn:hover { background: var(--surface-2); color: var(--text); }

.edit-card {
  max-width: 560px;
}
.edit-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.edit-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.edit-form input,
.edit-form select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
.edit-form input:focus,
.edit-form select:focus {
  outline: none;
  border-color: var(--accent);
}
.edit-form .field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.edit-form .form-error {
  background: var(--bad-soft);
  color: #991b1b;
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
}
.edit-form .form-hint {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}
.prefs-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.prefs-group .pref-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(37, 99, 235, 0.15);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drop-overlay[hidden] { display: none; }
.drop-overlay-inner {
  background: var(--surface);
  border: 3px dashed var(--accent);
  border-radius: var(--radius);
  padding: 40px 60px;
  text-align: center;
  box-shadow: var(--shadow);
}
.drop-overlay-inner h2 {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 22px;
}
.drop-overlay-inner p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}
