:root {
  color-scheme: light;
  --bg: #eef2f4;
  --bg-texture: #dfe8eb;
  --ink: #141b22;
  --muted: #62707d;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --line: #d3dde4;
  --accent: #1e747d;
  --accent-strong: #13535a;
  --gold: #b6811e;
  --rose: #bf5c55;
  --trade-bg: #fff4ca;
  --trade-text: #765313;
  --generic-bg: #ffe1dd;
  --generic-text: #88352f;
  --alt-bg: #e6f2f0;
  --alt-text: #2f6663;
  --alt-line: #9fc9c3;
  --ok-bg: #dcefdc;
  --ok-text: #176035;
  --bad-bg: #f8d7da;
  --bad-text: #8a1f2d;
  --credit-allocated-bg: #fff0bd;
  --credit-allocated-text: #805909;
  --credit-studying-bg: #d8f1f3;
  --credit-studying-text: #175e67;
  --credit-required-bg: #dff1d8;
  --credit-required-text: #326424;
  --shadow: 0 18px 45px rgba(30, 47, 57, 0.12);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101417;
  --bg-texture: #1a2328;
  --ink: #eef4f5;
  --muted: #9eadb6;
  --panel: #171d21;
  --panel-soft: #20282e;
  --line: #31404a;
  --accent: #62b8bf;
  --accent-strong: #8bd3d8;
  --gold: #e5bd6c;
  --rose: #ee9b94;
  --trade-bg: #463818;
  --trade-text: #ffe2a4;
  --generic-bg: #4a2529;
  --generic-text: #ffc2bc;
  --alt-bg: #243736;
  --alt-text: #b8ddd8;
  --alt-line: #547e78;
  --ok-bg: #173c2a;
  --ok-text: #9fe3b9;
  --bad-bg: #4b1f29;
  --bad-text: #ffb4bf;
  --credit-allocated-bg: #493b18;
  --credit-allocated-text: #ffdda0;
  --credit-studying-bg: #173d43;
  --credit-studying-text: #a7e6eb;
  --credit-required-bg: #213c22;
  --credit-required-text: #b6e99e;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, transparent 0 48%, var(--bg-texture) 48% 52%, transparent 52%) 0 0 / 28px 28px,
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.is-generating {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(12, 18, 22, 0.46);
  backdrop-filter: blur(5px);
}

.loading-overlay[hidden] {
  display: none;
}

.loading-panel {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(360px, 100%);
  padding: 28px 30px;
  border: 1px solid color-mix(in srgb, var(--accent) 34%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow: var(--shadow);
  text-align: center;
}

.loading-panel strong {
  font-size: 18px;
}

.loading-panel span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.loading-spinner {
  width: 54px;
  height: 54px;
  border: 5px solid color-mix(in srgb, var(--accent) 18%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.app-shell {
  width: min(1680px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.page-header,
.section-heading,
.section-actions,
.filter-row,
.actions,
.context-strip,
.toolbar,
.header-actions,
.button-row,
.legend-panel {
  display: flex;
  align-items: center;
  gap: 14px;
}

.page-header,
.section-heading,
.filter-row {
  justify-content: space-between;
}

.page-header {
  margin-bottom: 22px;
}

.header-actions {
  justify-content: flex-end;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.app-logo {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  object-fit: contain;
}

.section-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1.02;
}

h2 {
  font-size: 20px;
}

.version,
.section-heading > span,
.muted-text {
  color: var(--muted);
  font-size: 14px;
}

.hero-panel,
.panel,
.alert,
.context-strip,
.warning-list,
.legend-panel,
.metric {
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero-panel {
  padding: 20px;
}

.dashboard-tabs-panel {
  padding: 0;
  overflow: visible;
}

.dashboard-tab-list {
  display: flex;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px 0;
}

.dashboard-tab {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
  padding: 0 14px;
}

.dashboard-tab span {
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent-strong);
  font-size: 11px;
  padding: 3px 7px;
}

.dashboard-tab.is-active {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
}

.dashboard-tab:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.dashboard-tab-panel {
  padding: 16px;
}

.dashboard-tab-panel[hidden] {
  display: none;
}

.app-placeholder-panel {
  min-height: 168px;
  align-content: center;
}

.app-placeholder-panel h2 {
  color: var(--muted);
}

.cat-layout {
  display: grid;
  gap: 16px;
}

.cat-section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  padding: 16px;
}

.cat-input-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.cat-input-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.cat-input-card strong,
.cat-input-card span {
  display: block;
}

.cat-input-card > div:first-child span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.cat-inputs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.cat-number-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.cat-number-field input {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  font-size: 16px;
  font-weight: 900;
  padding: 8px 10px;
}

.cat-toolbar {
  display: grid;
  grid-template-columns:
    minmax(220px, 1fr)
    minmax(170px, 0.8fr)
    minmax(112px, 0.5fr)
    minmax(120px, auto)
    minmax(120px, auto);
}

.cat-table-scroll {
  max-height: 620px;
  min-height: 360px;
  position: relative;
  isolation: isolate;
}

.cat-result-table {
  min-width: 1320px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.cat-result-table.cat-hide-detail {
  min-width: 720px;
}

.cat-result-table [hidden],
.cat-result-table.cat-hide-detail .cat-detail-col {
  display: none;
}

.cat-result-table .cat-code-col {
  width: 132px;
  min-width: 132px;
}

.cat-result-table .cat-title-col {
  width: 300px;
  min-width: 300px;
}

.cat-result-table .cat-total-col,
.cat-result-table .cat-detail-col {
  width: 72px;
  min-width: 72px;
}

.cat-result-table th {
  white-space: normal;
}

.cat-result-table thead th {
  position: sticky;
  z-index: 20;
  background: var(--panel-soft);
  background-clip: padding-box;
}

.cat-result-table thead .cat-head-top {
  top: 0;
  height: 38px;
  z-index: 70;
}

.cat-result-table thead .cat-head-sub {
  top: 38px;
  height: 38px;
  z-index: 65;
}

.cat-result-table .cat-sticky-col {
  position: sticky;
  z-index: 12;
  background: var(--panel);
  box-shadow: 1px 0 0 var(--line);
  background-clip: padding-box;
}

.cat-result-table th.cat-sticky-col {
  z-index: 30;
  background: var(--panel-soft);
}

.cat-result-table thead th.cat-sticky-col {
  z-index: 80;
}

.cat-result-table tbody th.cat-sticky-col {
  z-index: 25;
}

.cat-result-table .cat-code-col.cat-sticky-col {
  left: 0;
}

.cat-result-table .cat-title-col.cat-sticky-col {
  left: 132px;
}

.cat-result-table th,
.cat-result-table td,
.cat-arrangement-table th,
.cat-arrangement-table td {
  padding: 7px 9px;
}

.cat-result-table thead th,
.cat-arrangement-table thead th {
  text-align: center;
}

.cat-result-table tbody th:first-child,
.cat-arrangement-table tbody td:first-child {
  font-weight: 900;
  white-space: nowrap;
}

.cat-result-table .number-cell {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.cat-result-table .number-cell.has-value {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent-strong);
  font-weight: 900;
}

.cat-count-button {
  position: relative;
  min-width: 34px;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, var(--panel));
  color: var(--accent-strong);
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  padding: 4px 9px;
}

.cat-count-button:hover,
.cat-count-button.is-open {
  background: var(--accent);
  color: #fff;
}

.cat-count-detail {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: 120;
  display: grid;
  min-width: 230px;
  max-width: 300px;
  transform: translateX(-50%);
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 40px rgba(8, 20, 30, 0.2);
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.cat-count-detail[hidden] {
  display: none;
}

.cat-count-detail span {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 10px;
  align-items: center;
}

.cat-count-detail strong {
  overflow-wrap: anywhere;
}

.cat-count-detail small {
  grid-column: 1;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.cat-count-detail b {
  grid-column: 2;
  grid-row: 1 / span 2;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, var(--panel-soft));
  color: var(--accent-strong);
  font-size: 12px;
  padding: 3px 8px;
}

.cat-arrangement-grid {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.cat-programme-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.tto-layout {
  display: grid;
  gap: 16px;
}

.tto-section {
  min-width: 0;
}

.tto-student-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.tto-slot-grid,
.tto-visual-grid {
  display: grid;
  grid-template-columns: 96px repeat(5, minmax(112px, 1fr));
  gap: 1px;
  margin-top: 16px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.tto-slot-corner,
.tto-slot-head,
.tto-slot-row-head,
.tto-slot-check,
.tto-visual-cell {
  min-height: 48px;
  background: var(--panel);
  padding: 9px 10px;
}

.tto-slot-corner,
.tto-slot-head,
.tto-slot-row-head,
.tto-visual-cell.is-head {
  display: grid;
  place-items: center;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.tto-slot-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.tto-slot-check span {
  overflow-wrap: anywhere;
}

.tto-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 0.45fr);
  gap: 10px;
}

.tto-module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  align-items: start;
  gap: 10px;
  margin-top: 14px;
}

.tto-module-card {
  display: grid;
  grid-template-rows: auto auto auto;
  align-self: start;
  align-content: start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  min-height: 154px;
  padding: 12px;
}

.tto-module-card[hidden] {
  display: none;
}

.tto-module-pick {
  display: flex;
  align-items: flex-start;
  gap: 9px;
}

.tto-module-pick strong,
.tto-module-pick small {
  display: block;
}

.tto-module-pick small {
  margin-top: 3px;
  color: var(--muted);
  font-weight: 800;
}

.tto-module-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  align-content: flex-start;
  gap: 6px;
}

.tto-module-meta span {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  line-height: 1.1;
  padding: 4px 8px;
}

.tto-pattern-list {
  display: grid;
  gap: 7px;
  max-height: 210px;
  margin-top: 8px;
  overflow: auto;
  padding-right: 4px;
}

.tto-pattern-item {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  padding: 8px;
}

.tto-pattern-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.tto-result-summary {
  margin-top: 12px;
  color: var(--muted);
  font-weight: 900;
}

.tto-result-layout {
  display: grid;
  gap: 14px;
}

.tto-result-scroll {
  max-height: 430px;
  min-height: 0;
}

.tto-result-table {
  min-width: 760px;
}

.tto-result-table th,
.tto-result-table td {
  white-space: normal;
}

.tto-result-table tbody tr {
  cursor: pointer;
}

.tto-result-table tbody tr.is-selected td {
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
}

.tto-visual-panel {
  margin-top: 0;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.tto-visual-panel h3 {
  margin: 0;
}

.tto-visual-grid {
  grid-template-columns: 92px repeat(5, minmax(150px, 1fr));
  font-size: 12px;
}

.tto-visual-cell {
  min-height: 86px;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.tto-visual-cell.is-free {
  background: var(--panel);
}

.tto-visual-cell.is-occupied {
  background: color-mix(in srgb, var(--bad) 12%, var(--panel));
  color: var(--bad);
  font-weight: 900;
}

.tto-visual-cell.is-assigned {
  font-weight: 900;
}

.tto-visual-cell.is-assigned.c1 {
  background: #dff5f2;
  color: #14635c;
}

.tto-visual-cell.is-assigned.c2 {
  background: #e7ecff;
  color: #314a9f;
}

.tto-visual-cell.is-assigned.c3 {
  background: #fff0d7;
  color: #8a5312;
}

.tto-visual-cell.is-assigned.c4 {
  background: #f0e7ff;
  color: #6640a8;
}

.tto-visual-cell.is-assigned.c5 {
  background: #e7f4dc;
  color: #386d1e;
}

.tto-visual-cell.is-assigned.c6 {
  background: #ffe5eb;
  color: #9a2945;
}

.tto-visual-cell.is-assigned.c7 {
  background: #dff0ff;
  color: #175f9b;
}

.tto-visual-cell.is-assigned.c8 {
  background: #f3eadf;
  color: #76502e;
}

.cat-programme-header {
  width: 100%;
}

.cat-programme-body {
  max-height: 420px;
  overflow: auto;
}

.cat-arrangement-table {
  min-width: 980px;
}

.cat-arrangement-table th span {
  display: block;
}

.cat-marker {
  display: inline-flex;
  min-width: 28px;
  justify-content: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  padding: 3px 7px;
}

.cat-marker.is-counted {
  background: color-mix(in srgb, var(--ok-text) 16%, transparent);
  color: var(--ok-text);
}

.cat-marker.is-display-only {
  background: color-mix(in srgb, var(--gold) 18%, transparent);
  color: var(--gold);
}

.account-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  max-width: 360px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: var(--shadow);
  padding: 4px 6px 4px 5px;
}

.account-icon {
  display: inline-grid;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 16%, var(--panel-soft));
  color: var(--accent-strong);
}

.account-icon svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.account-name {
  min-width: 0;
  max-width: 170px;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-action {
  min-height: 28px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  padding: 0 10px;
  white-space: nowrap;
}

.account-action:hover {
  background: var(--accent-strong);
}

.auth-system-error {
  max-width: 560px;
  margin: 40px auto 0;
  text-align: center;
}

.auth-system-error h2 {
  margin-bottom: 8px;
}

.auth-system-error p:last-child {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

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

.field,
.field-label,
.search-field,
.compact-field,
.remark-editor {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.search-field {
  flex: 1 1 360px;
}

.student-search-field {
  min-width: 0;
}

.compact-field {
  min-width: 0;
}

select,
input[type="file"],
input[type="number"],
input[type="search"],
textarea {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

.file-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.sample-button {
  min-height: 42px;
  white-space: nowrap;
}

.sample-button[hidden] {
  display: none;
}

textarea {
  min-height: 94px;
  resize: vertical;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.filter-row {
  display: grid;
  align-items: flex-start;
  justify-content: stretch;
  margin-top: 18px;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 8px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: var(--panel-soft);
  font-size: 14px;
  font-weight: 800;
}

.year-dropdown {
  position: relative;
}

.year-dropdown-button {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  padding: 10px 12px;
  text-align: left;
}

.year-dropdown-button::after {
  content: "⌄";
  float: right;
  color: var(--muted);
}

.year-dropdown-menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  left: 0;
  display: grid;
  width: 100%;
  min-width: 150px;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 8px;
}

.year-dropdown-menu[hidden] {
  display: none;
}

.mini-check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 7px;
  background: var(--panel-soft);
  font-size: 12px;
  font-weight: 900;
}

.actions {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.module-card-header {
  border: 0;
  cursor: pointer;
  font-weight: 900;
}

.primary-button {
  min-height: 42px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  padding: 0 18px;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.primary-button:disabled,
.ghost-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.ghost-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--ink);
  padding: 0 12px;
}

.ghost-button:hover,
.module-card-header:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.alert,
.warning-list {
  margin-top: 16px;
  padding: 14px 16px;
}

.alert {
  border-color: color-mix(in srgb, var(--bad-text) 42%, var(--line));
  background: var(--bad-bg);
  color: var(--bad-text);
  font-weight: 800;
}

.submit-status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.submit-status.is-error {
  color: var(--bad-text);
}

.warning-list {
  display: grid;
  gap: 6px;
  border-color: color-mix(in srgb, var(--gold) 42%, var(--line));
  color: var(--gold);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.metric {
  min-height: 98px;
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
}

.progress-metric {
  --progress-color: var(--accent);
  display: flex;
  align-items: center;
  gap: 14px;
}

.progress-metric.metric-on_track {
  --progress-color: #2f9d68;
}

.dark .progress-metric.metric-on_track {
  --progress-color: #70d99b;
}

.progress-metric strong {
  margin-top: 6px;
  font-size: 24px;
}

.progress-metric small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.progress-ring {
  display: grid;
  width: 74px;
  height: 74px;
  flex: 0 0 74px;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--panel) 0 58%, transparent 59%),
    conic-gradient(var(--progress-color) var(--progress), color-mix(in srgb, var(--line) 70%, transparent) 0);
}

.progress-ring span {
  color: var(--ink);
  font-size: 16px;
  font-weight: 900;
}

.context-strip,
.legend-panel {
  align-items: flex-start;
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 14px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
}

.credit-key {
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  padding: 2px 4px;
  font-weight: 900;
}

.credit-allocated {
  background: var(--credit-allocated-bg);
  color: var(--credit-allocated-text);
}

.credit-studying {
  background: var(--credit-studying-bg);
  color: var(--credit-studying-text);
}

.credit-required {
  background: var(--credit-required-bg);
  color: var(--credit-required-text);
}

.credit-divider {
  color: var(--muted);
  font-weight: 900;
}

.alt-toggle {
  min-height: 36px;
  align-items: center;
}

.toggle-field {
  min-width: 92px;
}

.results-layout {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

[data-student-section] {
  order: 2;
}

[data-module-section] {
  order: 3;
}

[data-todo-panel] {
  order: 0;
}

.results-layout > .legend-panel {
  order: 1;
  margin-top: 0;
}

.results-panel {
  min-width: 0;
  padding: 16px;
}

.toolbar {
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

[data-student-section] .toolbar {
  display: grid;
  grid-template-columns:
    minmax(160px, 1.3fr)
    minmax(102px, 0.7fr)
    minmax(132px, 0.9fr)
    minmax(100px, 0.65fr)
    minmax(104px, 0.7fr)
    minmax(158px, 1fr);
  position: sticky;
  top: 8px;
  z-index: 20;
  overflow: visible;
  background: color-mix(in srgb, var(--panel-soft) 94%, transparent);
  box-shadow: 0 10px 24px rgba(15, 30, 38, 0.08);
  backdrop-filter: blur(8px);
}

.button-row {
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.toolbar-action {
  display: grid;
  gap: 8px;
  align-items: flex-end;
  min-width: 0;
}

.export-menu {
  position: relative;
  width: 100%;
}

.export-menu > .primary-button {
  width: 100%;
}

.export-menu-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  z-index: 45;
  display: grid;
  min-width: 180px;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 8px;
}

.export-menu-panel[hidden] {
  display: none;
}

.export-menu-panel::before {
  position: absolute;
  bottom: -7px;
  right: 18px;
  width: 12px;
  height: 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  content: "";
  transform: rotate(45deg);
}

.export-menu-panel button {
  min-height: 34px;
  border: 0;
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
  padding: 0 10px;
  text-align: left;
}

.export-menu-panel button:hover {
  background: color-mix(in srgb, var(--accent) 10%, var(--panel-soft));
  color: var(--accent-strong);
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.todo-section-form,
.todo-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 8px;
  align-items: end;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.todo-form {
  grid-template-columns: minmax(260px, 1fr) auto;
  margin-top: 8px;
}

.todo-form textarea {
  min-height: 54px;
  max-height: 124px;
  resize: vertical;
}

.todo-section-form[hidden],
.todo-form[hidden] {
  display: none;
}

.todo-list {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.todo-programmes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.todo-programme {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.todo-programme-header {
  display: flex;
  width: 100%;
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  padding: 10px 12px;
  text-align: left;
}

.todo-session-title {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  background: transparent;
  color: inherit;
}

.todo-session-title span:first-child {
  font-size: 18px;
  font-weight: 900;
}

.todo-session-title span:last-child {
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 900;
  padding: 5px 9px;
  white-space: nowrap;
}

.todo-session-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.todo-programme-body {
  padding: 0 10px 10px;
}

.todo-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.todo-item.is-done {
  background: color-mix(in srgb, var(--ok-bg) 26%, var(--panel));
}

.todo-check {
  display: grid;
  place-items: center;
  min-height: 28px;
  cursor: pointer;
}

.todo-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.todo-content {
  display: grid;
  gap: 6px;
}

.todo-title-text {
  display: block;
  width: 100%;
  min-height: 24px;
  padding: 2px 0;
  overflow: hidden;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-weight: 900;
  line-height: 1.28;
  overflow-wrap: anywhere;
  resize: none;
  white-space: pre-wrap;
}

.todo-title-text[readonly]:focus {
  border-color: transparent;
  box-shadow: none;
  outline: none;
}

.todo-item.is-editing .todo-title-text {
  min-height: 54px;
  padding: 6px 8px;
  border-color: var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  resize: vertical;
}

.todo-item.is-done .todo-title-text {
  color: var(--muted);
  text-decoration: line-through;
}

.todo-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.danger-button {
  border-color: color-mix(in srgb, var(--bad-text) 36%, var(--line));
  color: var(--bad-text);
}

.icon-button {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
}

.module-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.module-card[hidden],
.student-row[hidden],
[data-section-body][hidden] {
  display: none;
}

.module-card-header {
  display: flex;
  width: 100%;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  padding: 13px 14px;
  text-align: left;
}

.module-heading {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.module-heading > span,
.module-heading > small {
  color: var(--muted);
  line-height: 1.3;
}

.module-heading > small {
  font-size: 11px;
  font-weight: 800;
}

.module-card.is-open .module-card-header {
  border-bottom-color: var(--line);
}

.module-code {
  font-size: 18px;
}

.module-count {
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent-strong);
  font-size: 12px;
  padding: 5px 9px;
  white-space: nowrap;
}

.module-card-body {
  max-height: 280px;
  overflow: auto;
  padding: 0;
}

.module-student-table {
  min-width: 0;
}

.module-student-table th {
  position: static;
  background: color-mix(in srgb, var(--accent) 10%, var(--panel-soft));
}

.module-student-table th,
.module-student-table td {
  padding: 8px 10px;
}

.table-scroll {
  width: 100%;
  max-height: calc(100vh - 190px);
  min-height: 360px;
  margin-top: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.student-table {
  min-width: 1360px;
  table-layout: fixed;
}

th,
td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

.student-table th,
.student-table td {
  padding: 6px 7px;
  font-size: 11px;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel-soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
}

.student-table thead {
  position: sticky;
  top: 0;
  z-index: 12;
}

.student-table thead th {
  position: static;
}

.student-table th {
  height: 36px;
  line-height: 1.15;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
}

.student-row.is-visible-even td {
  background: color-mix(in srgb, var(--panel-soft) 48%, transparent);
}

.name-cell,
.numeric {
  font-weight: 900;
}

.class-col,
.class-cell {
  width: 54px;
}

.id-col,
.id-cell {
  width: 86px;
}

.name-col,
.name-cell {
  width: 130px;
}

.join-col,
.join-cell {
  width: 58px;
}

.student-table .class-col,
.student-table .class-cell,
.student-table .id-col,
.student-table .id-cell,
.student-table .name-col,
.student-table .name-cell,
.student-table .join-col,
.student-table .join-cell {
  position: sticky;
  background: var(--panel);
}

.student-table .class-col,
.student-table .id-col,
.student-table .name-col,
.student-table .join-col {
  position: sticky;
  top: auto;
  z-index: 12;
  background: var(--panel-soft);
}

.student-table .class-cell,
.student-table .id-cell,
.student-table .name-cell,
.student-table .join-cell {
  z-index: 3;
}

.student-table .class-col,
.student-table .class-cell {
  left: 0;
}

.student-table .id-col,
.student-table .id-cell {
  left: 54px;
}

.student-table .name-col,
.student-table .name-cell {
  left: 140px;
}

.student-table .join-col,
.student-table .join-cell {
  left: 270px;
  box-shadow: 8px 0 14px rgba(15, 30, 38, 0.08);
}

.student-row.is-visible-even .class-cell,
.student-row.is-visible-even .id-cell,
.student-row.is-visible-even .name-cell,
.student-row.is-visible-even .join-cell {
  background: color-mix(in srgb, var(--panel-soft) 78%, var(--panel));
}

.credit-col,
.credit-cell {
  width: 104px;
}

.credit-col span {
  display: block;
}

.credit-group-col {
  padding: 5px 7px;
  text-align: center;
}

.credit-group-label {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
  font-size: 10px;
}

.credit-group-label .credit-key {
  padding: 2px 3px;
}

.student-table .credit-subheading {
  text-align: center;
}

.period-cell {
  width: 66px;
  min-width: 66px;
  max-width: 66px;
}

.period-heading {
  width: 66px;
  min-width: 66px;
  max-width: 66px;
  white-space: normal;
  word-break: break-word;
}

.period-heading span {
  display: block;
}

.module-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.module-chip-row + .module-chip-row {
  margin-top: 6px;
}

.module-chip,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 900;
  line-height: 1;
}

.trade-chip {
  background: var(--trade-bg);
  color: var(--trade-text);
}

.generic-chip {
  background: var(--generic-bg);
  color: var(--generic-text);
}

.module-chip {
  min-height: 18px;
  border: 0;
  padding: 4px 6px;
  font-size: 10px;
  text-align: left;
}

.module-chip[data-module-detail] {
  position: relative;
  cursor: pointer;
  font-family: inherit;
}

.alt-chip {
  border: 1px solid var(--alt-line);
  background: var(--alt-bg);
  color: var(--alt-text);
  box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--alt-line) 45%, transparent);
}

.module-chip[hidden] {
  display: none;
}

.module-chip.is-expanded {
  outline: 2px solid color-mix(in srgb, var(--accent) 46%, transparent);
  outline-offset: 1px;
}

.module-chip-detail,
.credit-chip-detail {
  position: absolute;
  top: calc(100% + 10px);
  left: -8px;
  z-index: 30;
  display: grid;
  width: 226px;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

.module-chip-detail[hidden],
.credit-chip-detail[hidden] {
  display: none;
}

.module-chip-detail::before,
.credit-chip-detail::before {
  position: absolute;
  top: -7px;
  left: 18px;
  width: 12px;
  height: 12px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: var(--panel);
  content: "";
  transform: rotate(45deg);
}

.module-chip-detail strong,
.credit-chip-detail strong {
  color: var(--accent-strong);
  font-size: 12px;
  line-height: 1.3;
}

.module-type-badge {
  justify-self: start;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  border-radius: 999px;
  padding: 3px 7px;
  background: color-mix(in srgb, var(--accent) 9%, var(--panel));
  color: var(--accent-strong);
  font-size: 10px;
  font-weight: 900;
}

.badge {
  min-width: 62px;
  min-height: 22px;
  border-radius: 7px;
  padding: 3px 5px;
}

.badge.ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.badge.bad {
  background: var(--bad-bg);
  color: var(--bad-text);
}

.credit-badge {
  position: relative;
  min-width: 82px;
  border: 0;
  padding: 5px 7px;
  cursor: pointer;
  font-family: inherit;
  font-size: 10px;
  white-space: nowrap;
}

.credit-badge.ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.credit-badge.bad {
  background: var(--bad-bg);
  color: var(--bad-text);
}

.credit-badge.is-expanded {
  outline: 2px solid color-mix(in srgb, var(--accent) 46%, transparent);
  outline-offset: 1px;
}

.credit-chip-detail {
  left: auto;
  right: -8px;
  width: 250px;
  cursor: default;
  text-align: left;
}

.credit-chip-detail::before {
  right: 20px;
  left: auto;
}

.credit-detail-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.credit-detail-module {
  display: grid;
  gap: 2px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}

.credit-detail-module b {
  color: var(--ink);
  font-size: 11px;
}

.credit-detail-module small {
  color: var(--muted);
  font-size: 10px;
}

.remark-cell {
  width: 260px;
  min-width: 240px;
  max-width: 340px;
}

.remark-col {
  width: 260px;
  min-width: 240px;
  max-width: 340px;
}

.student-status {
  display: block;
  width: fit-content;
  margin-top: 4px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ok-bg) 80%, transparent);
  color: var(--ok-text);
  padding: 3px 6px;
  font-size: 9px;
  font-weight: 900;
}

.student-status.defer-status {
  border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
  background: color-mix(in srgb, var(--gold) 14%, var(--panel));
  color: var(--gold);
}

.study-sequence-row td {
  position: sticky;
  top: var(--sequence-sticky-top, 38px);
  z-index: 5;
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
}

.study-sequence-row .name-cell,
.study-sequence-row .class-cell,
.study-sequence-row .id-cell,
.study-sequence-row .join-cell {
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
  color: var(--accent-strong);
  font-weight: 900;
  z-index: 11;
}

.student-table .period-cell.is-detail-open {
  position: relative;
  z-index: 25;
}

.student-table .credit-cell.is-detail-open {
  position: relative;
  z-index: 25;
}

.student-table .study-sequence-row .period-cell.is-detail-open {
  position: sticky;
}

.remark-cell textarea {
  min-height: 62px;
  padding: 7px 8px;
  font-size: 12px;
}

.copy-cell {
  cursor: copy;
}

.copy-cell:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

.copy-cell.is-copied {
  background: var(--ok-bg) !important;
  color: var(--ok-text);
  text-align: center;
}

.copy-cell.copy-failed {
  background: var(--bad-bg) !important;
  color: var(--bad-text);
}

.remark-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.save-state {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.save-state.is-ok {
  color: var(--ok-text);
}

.save-state.is-error {
  color: var(--bad-text);
}

code {
  color: var(--accent-strong);
}

.empty {
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

@media (max-width: 980px) {
  .app-shell {
    width: min(100% - 20px, 1680px);
    padding-top: 18px;
  }

  .page-header,
  .filter-row,
  .section-heading,
  .header-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .app-logo {
    width: 52px;
    height: 52px;
    flex-basis: 52px;
  }

  .form-grid,
  .summary-grid,
  .todo-section-form,
  .cat-toolbar {
    grid-template-columns: 1fr;
  }

  .todo-programmes {
    grid-template-columns: 1fr;
  }

  .todo-form {
    grid-template-columns: 1fr;
  }

  .todo-item {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .todo-actions {
    grid-column: 2;
  }

  .checks,
  .button-row {
    justify-content: flex-start;
  }

  .compact-field {
    flex: 1 1 180px;
  }

  [data-student-section] .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  [data-student-section] .toolbar {
    position: static;
  }
}
