:root {
  color-scheme: light;
  --bg: #f7f9fb;
  --surface: #ffffff;
  --surface-strong: #f1f5f7;
  --text: #172026;
  --muted: #667782;
  --border: #d8e1e6;
  --teal: #0f766e;
  --teal-soft: #e0f2f1;
  --amber: #b7791f;
  --amber-soft: #fff3d6;
  --male: #0f766e;
  --male-soft: #dff3ef;
  --female: #9f5f13;
  --female-soft: #fff1d3;
  --danger: #b42318;
  --shadow: 0 14px 34px rgba(23, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar h2,
.panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar p,
.panel p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.workspace {
  min-width: 0;
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.topbar h2 {
  font-size: 26px;
  line-height: 1.15;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.file-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.primary-button,
.secondary-button {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.primary-button {
  border: 1px solid var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.primary-button:disabled {
  border-color: #b8c5cc;
  background: #b8c5cc;
  cursor: not-allowed;
}

.secondary-button {
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
}

.secondary-button:disabled {
  color: #93a1aa;
  cursor: not-allowed;
  opacity: 0.66;
}

.ghost-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.choice-modal {
  width: min(560px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

.choice-modal::backdrop {
  background: rgba(23, 32, 38, 0.42);
}

.choice-modal-card {
  display: grid;
  gap: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(23, 32, 38, 0.26);
  padding: 20px;
}

.choice-modal-card h3 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0;
}

.choice-modal-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.choice-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metrics article,
.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 16px;
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  letter-spacing: 0;
}

.panel {
  min-width: 0;
  margin-bottom: 14px;
  padding: 16px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.panel h3 {
  font-size: 17px;
}

.state-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 99px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.state-pill.running {
  background: var(--amber-soft);
  color: var(--amber);
}

.state-pill.complete {
  background: var(--teal-soft);
  color: var(--teal);
}

.state-pill.error {
  background: #fee4e2;
  color: var(--danger);
}

.progress-track {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-strong);
  margin-bottom: 14px;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--amber));
  transition: width 280ms ease;
}

.step-results {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 10px;
}

.step-card {
  min-height: 106px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.step-card.running {
  border-color: var(--amber);
  background: var(--amber-soft);
}

.step-card.complete {
  border-color: rgba(15, 118, 110, 0.38);
  background: var(--teal-soft);
}

.step-card h4 {
  margin: 0 0 8px;
  font-size: 13px;
}

.subprogress {
  display: grid;
  gap: 6px;
  margin: 0 0 8px;
}

.subprogress-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.subprogress-meta strong {
  color: var(--text);
}

.subprogress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.78);
}

.subprogress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--amber);
  transition: width 220ms ease;
}

.step-card dl {
  display: grid;
  gap: 4px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.step-card div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.step-card dt {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 650;
}

.step-variable {
  cursor: help;
}

.tooltip-mark {
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border: 1px solid currentColor;
  border-radius: 99px;
  font-size: 9px;
  line-height: 1;
  opacity: 0.72;
}

.step-variable::after {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 30;
  width: 230px;
  max-width: min(230px, calc(100vw - 48px));
  padding: 8px 10px;
  border: 1px solid rgba(23, 32, 38, 0.12);
  border-radius: 8px;
  background: #172026;
  box-shadow: 0 12px 28px rgba(23, 32, 38, 0.2);
  color: #ffffff;
  content: attr(data-tooltip);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  text-align: left;
  transform: translateY(4px);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.step-variable:hover::after,
.step-variable:focus::after,
.step-variable:focus-visible::after,
.step-variable.tooltip-open::after {
  opacity: 1;
  transform: translateY(0);
}

.step-card dd {
  margin: 0;
  color: var(--text);
  font-weight: 750;
  text-align: right;
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
  gap: 14px;
}

.table-wrap {
  overflow: auto;
  max-height: 420px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.allocation-guide {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.allocation-guide h4 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0;
}

.allocation-guide ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.allocation-guide li::marker {
  color: var(--teal);
  font-weight: 800;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  font-size: 12px;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-strong);
  color: #465661;
  font-weight: 800;
}

td {
  color: #26343c;
}

.empty-state,
.room-grid-empty {
  display: grid;
  place-items: center;
  min-height: 260px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  max-height: 620px;
  overflow: auto;
  padding-right: 4px;
}

.room-card {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
  text-align: left;
  cursor: pointer;
}

.room-card.male {
  border-color: rgba(15, 118, 110, 0.38);
}

.room-card.female {
  border-color: rgba(159, 95, 19, 0.38);
}

.room-card.selected {
  outline: 3px solid rgba(183, 121, 31, 0.28);
}

.room-card:hover {
  box-shadow: 0 10px 22px rgba(23, 32, 38, 0.12);
}

.room-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  color: #ffffff;
}

.room-card.male header {
  background: var(--male);
}

.room-card.female header {
  background: var(--female);
}

.room-card h4 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0;
}

.room-card header span {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 700;
  opacity: 0.86;
}

.room-card header strong {
  font-size: 12px;
}

.student-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
}

.student-block {
  min-height: 78px;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 8px;
  background: #ffffff;
}

.room-card.male .student-block {
  background: var(--male-soft);
}

.room-card.female .student-block {
  background: var(--female-soft);
}

.student-block span,
.student-block small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.student-block strong {
  display: block;
  margin: 5px 0 3px;
  color: var(--text);
  font-size: 18px;
}

.student-block.empty {
  border-style: dashed;
  background: #ffffff;
  opacity: 0.68;
}

.room-detail {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.room-detail-empty {
  display: grid;
  place-items: center;
  min-height: 100px;
  color: var(--muted);
  font-size: 13px;
}

.room-detail-header {
  margin-bottom: 10px;
}

.room-detail-header h4 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

.room-detail-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.survey-detail-table {
  max-height: 260px;
}

.processing-banner {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(680px, calc(100vw - 32px));
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 16px 34px rgba(23, 32, 38, 0.18);
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
  transform: translate(-50%, 76px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 240ms ease,
    transform 240ms ease;
}

.processing-banner.visible {
  animation: processingPulse 2.4s ease-in-out infinite;
  opacity: 1;
  transform: translate(-50%, 0);
}

.processing-banner strong {
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.processing-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 99px;
  background: var(--teal);
  box-shadow: 0 0 0 5px rgba(15, 118, 110, 0.12);
}

@keyframes processingPulse {
  0%,
  100% {
    filter: brightness(1);
  }

  50% {
    filter: brightness(0.92);
  }
}

@media (max-width: 1060px) {
  .workspace {
    min-width: 0;
    width: 100%;
  }

  .topbar,
  .actions {
    min-width: 0;
  }

  .topbar,
  .panel-header {
    flex-direction: column;
  }

  .actions {
    justify-content: flex-start;
  }

  .metrics,
  .step-results,
  .grid-two {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 16px;
  }

  .metrics strong {
    font-size: 22px;
  }

  .actions,
  .file-control,
  .primary-button,
  .secondary-button,
  .ghost-button {
    width: 100%;
  }

  .choice-modal-actions {
    flex-direction: column;
  }

  .processing-banner {
    bottom: 12px;
    justify-content: center;
    text-align: center;
  }
}
