: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;
  --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;
  --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;
}

.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,
.auth-panel,
.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;
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding: 16px 18px;
}

.auth-panel h2 {
  margin: 4px 0;
}

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

.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 {
  flex: 0 1 300px;
}

.compact-field {
  flex: 0 0 170px;
}

select,
input[type="file"],
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;
}

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: 8;
  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);
}

.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 {
  display: flex;
  align-items: center;
  gap: 14px;
}

.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(--accent) 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;
}

.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: 1;
}

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

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

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

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

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

.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-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: 76vh;
  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: 1420px;
  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: nowrap;
}

tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--panel-soft) 48%, transparent);
}

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

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

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

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

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

.total-col,
.total-cell {
  width: 44px;
}

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

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

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

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

.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;
  padding: 4px 6px;
  font-size: 10px;
}

.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);
}

[data-alt-chip][hidden] {
  display: none;
}

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

.all-credit-cell .badge {
  min-width: 34px;
  min-height: 20px;
  padding: 3px 6px;
}

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

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

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

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

.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;
  }

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

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

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