:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --line: #d9ded7;
  --line-strong: #b8c2ba;
  --text: #1f2722;
  --muted: #67726c;
  --accent: #256f5d;
  --accent-soft: #e5f2ed;
  --warn: #a34a18;
  --bad: #b3261e;
  --good: #1f7a4d;
  --shadow: 0 14px 38px rgba(38, 54, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: 82px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 760;
}

.topbar p,
.class-head p {
  margin-top: 4px;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 10px;
}

button,
.button {
  min-height: 36px;
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.button:hover {
  border-color: var(--accent);
}

.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: calc(100vh - 82px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #fdfdfb;
  padding: 18px 14px;
}

.panel-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 8px 10px;
}

.class-list {
  display: grid;
  gap: 6px;
}

.class-item {
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  text-align: left;
}

.class-name {
  font-weight: 700;
}

.class-item.active {
  border-color: #9bc5b6;
  background: var(--accent-soft);
  color: #164c3f;
  font-weight: 700;
}

.class-count {
  color: var(--muted);
  font-size: 12px;
}

.class-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.risk-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 700;
}

.risk-pill.merged {
  background: #ffd9e2;
  color: #8a1836;
}

.excluded-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #e5e7eb;
  color: #5d6670;
  font-weight: 700;
}

.workspace {
  min-width: 0;
  padding: 22px 26px 28px;
}

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

h2 {
  font-size: 22px;
  font-weight: 760;
}

.status {
  min-width: 92px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}

.status.saving {
  color: var(--warn);
}

.status.saved {
  color: var(--good);
}

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

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  min-height: 74px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
}

.stat-value {
  margin-top: 4px;
  font-size: 23px;
  font-weight: 780;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.search {
  flex: 1;
}

.search input {
  width: 100%;
}

input,
select {
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

input {
  padding: 6px 9px;
}

select {
  padding: 5px 8px;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 302px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  height: 42px;
  padding: 6px 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--subject-head, #eef3ef);
  color: #2b3931;
  font-size: 12px;
  font-weight: 760;
}

th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: inherit;
}

th:first-child {
  z-index: 5;
}

tbody tr:nth-child(odd) td {
  background: var(--subject-head, #eef3ef);
}

tbody tr:nth-child(even) td {
  background: var(--subject-head, #eef3ef);
}

tbody tr:hover td {
  background: var(--subject-head, #eef3ef);
}

tbody tr.row-risk td:first-child {
  box-shadow: inset 4px 0 0 #b3261e;
}

tbody tr.row-excluded td {
  color: #69736d;
  opacity: 0.72;
}

tbody tr.row-excluded td:first-child {
  box-shadow: inset 4px 0 0 #8b949e;
}

td.identity {
  color: #26312b;
}

td.student-risk-name {
  color: #8f1d17;
  font-weight: 800;
}

.student-name-text {
  margin-right: 6px;
}

.name-tag {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 760;
  vertical-align: 1px;
}

.name-tag.merged {
  background: #ffd9e2;
  color: #8a1836;
}

td.number {
  text-align: right;
}

td.total {
  font-weight: 760;
}

.subject-identity {
  --subject-head: #e8eeea;
  --subject-odd: #ffffff;
  --subject-even: #f7f9f8;
  --subject-hover: #edf3ef;
}

.subject-theory {
  --subject-head: #dcebe6;
  --subject-odd: #f7fcfa;
  --subject-even: #edf7f4;
  --subject-hover: #e1f0ec;
}

.subject-typing {
  --subject-head: #efe4d2;
  --subject-odd: #fdf9f1;
  --subject-even: #f7eedf;
  --subject-hover: #efe1c9;
}

.subject-word {
  --subject-head: #dce8fb;
  --subject-odd: #f7fbff;
  --subject-even: #edf4ff;
  --subject-hover: #dfebfb;
}

.subject-excel {
  --subject-head: #e7efd9;
  --subject-odd: #fbfdf7;
  --subject-even: #f1f7e8;
  --subject-hover: #e6efd6;
}

.subject-ppt {
  --subject-head: #f8e6d8;
  --subject-odd: #fffaf6;
  --subject-even: #fdf0e7;
  --subject-hover: #f6e2d0;
}

.subject-bonus {
  --subject-head: #f9efd1;
  --subject-odd: #fffdf6;
  --subject-even: #fcf5dd;
  --subject-hover: #f5e9c5;
}

.subject-total {
  --subject-head: #d8e7ec;
  --subject-odd: #f6fbfd;
  --subject-even: #eaf4f7;
  --subject-hover: #dcecf1;
}

.subject-remarks {
  --subject-head: #e6e3dc;
  --subject-odd: #fbfaf7;
  --subject-even: #f3f1eb;
  --subject-hover: #ebe7de;
}

.grade-input {
  width: 76px;
  text-align: right;
  background: rgba(255, 255, 255, 0.74);
}

.text-input {
  width: 104px;
  background: rgba(255, 255, 255, 0.78);
}

td.cell-remarks .text-input {
  border-color: #8b949e;
  background: #f6f7f8;
  color: #374151;
  font-weight: 700;
}

td.cell-missing {
  /* Keep subject color; the input border identifies missing grades. */
}

td.cell-missing .grade-input {
  border-color: #c88719;
  background: #fff8df;
}

td.cell-theory-low {
  /* Keep subject color; the input border identifies low grades. */
}

td.cell-theory-low .grade-input {
  border-color: #b3261e;
  background: #fff1ef;
  color: #8f1d17;
  font-weight: 760;
}

td.cell-beginner-fail {

  box-shadow: inset 0 0 0 2px rgba(179, 38, 30, 0.32);
}

td.cell-beginner-fail .grade-input {
  border-color: #b3261e;
  background: #fff0ed;
  color: #8f1d17;
  font-weight: 760;
}

.grade-input.changed {
  border-color: var(--warn);
  background: #fff8ef;
}

.grade-input:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(37, 111, 93, 0.16);
}

.score-low {
  color: var(--bad);
}

.score-high {
  color: var(--good);
}

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

@media (max-width: 900px) {
  .topbar,
  .class-head,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    height: auto;
    padding: 18px;
  }

  .layout {
    display: block;
    min-height: auto;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .class-list {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }

  .workspace {
    padding: 18px;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-wrap {
    max-height: none;
  }
}

.summary-row > th,
.summary-row > td {
  position: sticky;
  top: 42px;
  z-index: 4;
  height: 62px;
  background: var(--subject-head, #eef3ef);
  text-align: center;
  font-size: 12px;
}

.summary-row > :first-child {
  left: 0;
  z-index: 5;
}

.summary-row strong {
  display: block;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.summary-hint {
  display: block;
  font-size: 12px;
  color: var(--text);
}
