:root {
  --bg: #f2f5fb;
  --card: #ffffff;
  --text: #1e2633;
  --muted: #8a94a6;
  --line: #e5eaf3;
  --primary: #3b6cf6;
  --primary-dark: #2f58cc;
  --danger: #e5484d;
  --radius: 12px;
  --row-h: 64px;
  --time-col: 62px;
  --day-count: 7;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.logo { font-size: 18px; }

.week-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f7f9fd;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 6px;
}

.week-info {
  min-width: 128px;
  text-align: center;
  line-height: 1.15;
}

.week-label { font-weight: 600; font-size: 14px; }
.week-range { font-size: 11px; color: var(--muted); }

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  font-size: 18px;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s;
}

.icon-btn:hover { background: #e9eefb; }

.actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 9px;
  border: 1px solid transparent;
  padding: 7px 14px;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
}

button:active { transform: translateY(1px); }

.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}

.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

.ghost:hover { background: #f6f8fd; border-color: #d3dcef; }

.ghost.small { padding: 4px 10px; font-size: 12px; }

.danger {
  background: #fff;
  color: var(--danger);
  border-color: #f4c9ca;
}

.danger:hover { background: #fdf1f1; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  padding: 4px 6px;
  border-radius: 8px;
}

.switch:hover { background: #f2f5fb; }
.switch input { accent-color: var(--primary); width: 15px; height: 15px; }

/* ---------- 课表 ---------- */

.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 16px 40px;
}

.board {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  overflow-y: hidden;
}

.board-inner {
  display: grid;
  grid-template-columns: var(--time-col) 1fr;
  grid-template-rows: 44px 1fr;
  min-width: calc(var(--time-col) + var(--day-count) * 104px);
}

.corner {
  position: sticky;
  left: 0;
  z-index: 6;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.day-heads {
  display: grid;
  grid-template-columns: repeat(var(--day-count), minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.day-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 0;
  border-right: 1px solid var(--line);
  line-height: 1.2;
}

.day-head:last-child { border-right: none; }
.day-head .d-date { font-size: 10px; font-weight: 400; color: var(--muted); }
.day-head.is-today { color: var(--primary); }
.day-head.is-today .d-date { color: var(--primary); }

.period-col {
  position: sticky;
  left: 0;
  z-index: 5;
  background: var(--card);
  border-right: 1px solid var(--line);
}

.period-cell {
  height: var(--row-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  line-height: 1.1;
}

.period-cell .p-num { font-size: 12px; font-weight: 600; }
.period-cell .p-time { font-size: 9px; color: var(--muted); }

.grid-area {
  display: grid;
  grid-template-columns: repeat(var(--day-count), minmax(0, 1fr));
}

.day-col {
  position: relative;
  border-right: 1px solid var(--line);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--row-h) - 1px),
    var(--line) calc(var(--row-h) - 1px),
    var(--line) var(--row-h)
  );
}

.day-col:last-child { border-right: none; }

.day-col.is-weekend { background-color: #fcfdff; }
.day-col.is-today { background-color: #f5f8ff; }

/* 课程块 */

.course {
  position: absolute;
  padding: 2px;
  border: none;
  background: transparent;
  overflow: hidden;
  z-index: 2;
}

.course-inner {
  height: 100%;
  width: 100%;
  border-radius: 8px;
  border-left: 3px solid var(--c-border);
  background: var(--c-bg);
  color: var(--c-text);
  padding: 4px 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 1px;
  cursor: pointer;
  transition: box-shadow .12s, transform .12s;
}

.course-inner:hover {
  box-shadow: 0 2px 10px rgba(16, 24, 40, .14);
  transform: translateY(-1px);
}

.course-name {
  font-weight: 600;
  font-size: 12.5px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.course-meta {
  font-size: 10.5px;
  opacity: .82;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.course-weeks {
  font-size: 9.5px;
  opacity: .7;
  margin-top: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.course.is-other-week .course-inner { opacity: .38; }

/* ---------- 提示 ---------- */

.empty-hint {
  text-align: center;
  color: var(--muted);
  margin: 28px 0 0;
  font-size: 13px;
}

.empty-hint p { margin: 0 0 12px; }

.tip {
  text-align: center;
  color: #a7b0c0;
  font-size: 12px;
  margin: 14px 0 0;
  line-height: 1.6;
}

.hidden { display: none !important; }

/* ---------- 对话框 ---------- */

.dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  box-shadow: 0 20px 60px rgba(16, 24, 40, .22);
  color: var(--text);
}

.dialog::backdrop {
  background: rgba(18, 25, 38, .42);
  backdrop-filter: blur(2px);
}

.dialog form {
  padding: 20px;
  overflow-y: auto;
  max-height: calc(100vh - 40px);
}

.dialog h2 {
  margin: 0 0 16px;
  font-size: 17px;
}

.field { margin-bottom: 12px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #5b657a;
  margin-bottom: 5px;
}

.field label em { color: var(--danger); font-style: normal; }

.field input,
.field select,
.field textarea {
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid #d8e0ef;
  border-radius: 9px;
  background: #fbfcff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.field textarea {
  resize: vertical;
  min-height: 70px;
  line-height: 1.7;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 108, 246, .14);
  background: #fff;
}

.field input.invalid { border-color: var(--danger); }

.hint {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.5;
}

.err {
  display: block;
  font-size: 11px;
  color: var(--danger);
  margin-top: 4px;
  min-height: 0;
}

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 10px;
}

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

hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 16px 0;
}

.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform .12s;
}

.swatch:hover { transform: scale(1.12); }
.swatch.selected { border-color: #1e2633; box-shadow: 0 0 0 2px #fff inset; }

.dialog-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}

.spacer { flex: 1; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  background: #1e2633;
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 窄屏 ---------- */

@media (max-width: 720px) {
  .topbar-inner { padding: 8px 12px; gap: 8px; }
  .brand { font-size: 15px; }
  .actions { width: 100%; margin-left: 0; justify-content: space-between; }
  .actions .switch { order: 3; }
  .main { padding: 12px 8px 32px; }
  .board-inner { min-width: calc(var(--time-col) + var(--day-count) * 92px); }
  .week-info { min-width: 106px; }
}
