:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --line: #e3e7ef;
  --line-strong: #cfd6e4;
  --text: #1f2533;
  --muted: #6b7488;
  --accent: #2f6fed;
  --accent-soft: #e8f0ff;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 8px 24px rgba(20, 30, 60, .06);
  --radius: 12px;
  --today: #fff8e8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Helvetica Neue", Arial, sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand { flex: 1; min-width: 0; }

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand .meta {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  flex-shrink: 0;
}

.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

.segmented {
  display: inline-flex;
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px;
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.segmented button.active {
  background: #fff;
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(20, 30, 60, .12);
}

.ghost {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
}

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

.drawer {
  position: fixed;
  top: 47px;
  left: 0;
  bottom: 0;
  width: 292px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 4px 0 24px rgba(20, 30, 60, .08);
  transform: translateX(-100%);
  transition: transform .18s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.drawer.open { transform: none; }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}

.drawer-head strong { font-size: 13.5px; }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 14px 18px;
}

.drawer-section { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.drawer-section:last-child { border-bottom: 0; }

.drawer-section h3 {
  margin: 0 0 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .6px;
}

.drawer-section h3.with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.link-btn {
  border: 0;
  background: none;
  font: inherit;
  font-size: 11.5px;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
}

.link-btn:hover { text-decoration: underline; }

.drawer-foot { font-size: 12px; color: var(--muted); }

.drawer input[type="search"], .drawer select {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 7px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.drawer input[type="search"]:focus, .drawer select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, .12);
}

.grade-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.grade-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f7f9fc;
  color: var(--text);
  cursor: pointer;
}

.grade-item .n { font-size: 11px; color: var(--muted); }

.grade-item:hover { background: #eef4ff; }

.grade-item.on {
  background: var(--accent-soft);
  border-color: #b9d0fb;
  color: var(--accent);
  font-weight: 600;
}

.picker { position: relative; }

.picker-list {
  display: none;
  margin-top: 6px;
  max-height: 264px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(20, 30, 60, .08);
}

.picker-list.open { display: block; }

.picker-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 9px;
  font-size: 12.5px;
  cursor: pointer;
  border-bottom: 1px solid #f2f4f8;
}

.picker-item:last-child { border-bottom: 0; }

.picker-item:hover,
.picker-item.active { background: var(--accent-soft); }

.picker-item.on { font-weight: 600; color: var(--accent); }

.picker-item > span:first-child {
  white-space: nowrap;
  flex-shrink: 0;
}

.picker-item .info {
  flex: 1;
  min-width: 0;
  text-align: right;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.picker-empty {
  padding: 8px 9px;
  font-size: 12px;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  font: inherit;
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c, var(--muted));
}

.chip.on {
  color: var(--text);
  border-color: var(--c, var(--accent));
  background: color-mix(in srgb, var(--c, var(--accent)) 12%, #fff);
  font-weight: 600;
}

main {
  padding: 14px 16px 30px;
  transition: margin-left .18s ease;
}

body.drawer-open main { margin-left: 292px; }

@media (max-width: 900px) {
  body.drawer-open main { margin-left: 0; }
  .drawer { width: 86vw; max-width: 320px; }
  .brand .meta { display: none; }
}

.loading, .empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
}

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

table.tt {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  width: max-content;
  font-size: 13px;
}

table.tt th, table.tt td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 4px 6px;
  vertical-align: middle;
}

table.tt thead th {
  background: #eef2f9;
  color: #3c465c;
  font-weight: 600;
  text-align: center;
  position: sticky;
  z-index: 6;
  white-space: nowrap;
}

table.tt thead tr:first-child th { top: 0; height: 30px; }
table.tt thead tr:nth-child(2) th { top: 30px; height: 24px; font-weight: 500; font-size: 12px; }

table.tt th.sticky-1, table.tt td.sticky-1 {
  position: sticky;
  left: 0;
  z-index: 5;
  background: #fbfcfe;
  width: 78px;
  text-align: center;
  font-weight: 600;
}

table.tt thead th.sticky-1 { z-index: 8; background: #eef2f9; }

table.tt tbody tr:hover td { background: #f8fafc; }
table.tt tbody tr:hover td.sticky-1 { background: #eef4ff; }

table.tt td.slot {
  height: 36px;
  background: #fff;
  overflow-wrap: anywhere;
}

table.tt td.slot.today { background: var(--today); }
table.tt td.slot.empty { background: #fcfcfd; }

.cls-name {
  cursor: pointer;
  font-weight: 700;
}

.cls-name:hover { color: var(--accent); text-decoration: underline; }

.cell-box { line-height: 1.35; }

.cell-box + .cell-box { margin-top: 2px; padding-top: 2px; border-top: 1px dashed var(--line); }

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--c, var(--accent));
  background: color-mix(in srgb, var(--c, var(--accent)) 13%, #fff);
  border: 1px solid color-mix(in srgb, var(--c, var(--accent)) 30%, #fff);
  cursor: pointer;
  white-space: nowrap;
}

.badge:hover { background: color-mix(in srgb, var(--c, var(--accent)) 24%, #fff); }

.badge.link { cursor: pointer; --c: #6b7488; }

.cell-teacher {
  display: block;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.tt .cell-teacher {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.35;
}

.cell-loc {
  display: block;
  font-size: 10.5px;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-extra {
  display: inline-block;
  font-size: 10.5px;
  color: #9aa3b4;
  margin-right: 4px;
}

.cell-box.extra { opacity: .75; }

.cell-classes {
  font-size: 11.5px;
  color: var(--text);
}

.cell-classes .cls {
  display: inline-block;
  margin: 0 3px 0 0;
  padding: 0 4px;
  border-radius: 4px;
  background: #f0f3f9;
  color: #48526a;
  white-space: nowrap;
}

.cell-box.research .cell-subject { color: var(--muted); }

.dim { opacity: .3; }

.mark {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 4px;
}

td.conflict {
  background: var(--danger-soft);
  box-shadow: inset 3px 0 0 var(--danger);
}

table.class-table td.conflict {
  box-shadow: inset 3px 0 0 var(--danger);
}

.class-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.class-head h2 {
  margin: 0;
  font-size: 16px;
}

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

.class-grid {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
}

table.class-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 900px;
}

table.class-table th, table.class-table td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  vertical-align: top;
  height: 70px;
}

table.class-table thead th {
  background: #eef2f9;
  font-weight: 600;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 4;
}

table.class-table tbody th {
  background: #f6f8fc;
  width: 78px;
  text-align: center;
  font-weight: 600;
}

table.class-table td.today { background: var(--today); }

.cell-subject {
  font-weight: 700;
  font-size: 14px;
  color: var(--c, var(--text));
}

.cell-teacher {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.cell-loc {
  font-size: 11px;
  color: var(--accent);
  margin-top: 2px;
}

.cell-empty { color: #c9cfdb; font-size: 12px; }

.note {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.back-link {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

.back-link:hover { color: var(--accent); border-color: var(--accent); }

@media print {
  .topbar, .drawer { display: none; }
  .table-wrap, .class-grid { max-height: none; overflow: visible; box-shadow: none; }
  body { background: #fff; }
}
