:root {
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-border: #e0e4eb;
  --color-text: #1f2933;
  --color-muted: #6b7280;
  --color-primary: #2563eb;
  --color-pending: #d97706;
  --color-approved: #16a34a;
  --color-rejected: #dc2626;
  --color-shadow: rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

h1 { font-size: 1.25rem; margin: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.week-nav { display: flex; align-items: center; gap: 8px; }
.week-nav button { padding: 4px 10px; }

button {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.9rem;
}

button.primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

button.danger { color: var(--color-rejected); border-color: var(--color-rejected); }

button:disabled { opacity: 0.6; cursor: not-allowed; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 20px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.filters label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--color-muted); }
.filters select, .filters input { margin-top: 4px; min-width: 140px; }
.filters .search { display: flex; align-items: flex-end; gap: 6px; }

main { padding: 20px; }

.day-tabs { display: none; gap: 4px; margin-bottom: 12px; overflow-x: auto; }
.day-tabs button { white-space: nowrap; }

.timeline {
  display: flex;
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  overflow: hidden;
}

.timeline-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: 36px repeat(var(--slot-rows, 9), var(--slot-height, 60px));
  min-height: 600px;
  flex: 1;
  min-width: 0;
}

.timeline-axis {
  flex: 0 0 60px;
  display: grid;
  grid-template-rows: 36px repeat(var(--slot-rows, 9), var(--slot-height, 60px));
}

.timeline-cell {
  position: relative;
  border-left: 1px solid var(--color-border);
  min-height: 30px;
}

.timeline-cell.is-hour { min-height: 60px; }
.timeline-cell.is-half { min-height: 30px; }
.timeline-cell.is-lunch {
  background: repeating-linear-gradient(
    45deg,
    #f3f4f6,
    #f3f4f6 6px,
    #e5e7eb 6px,
    #e5e7eb 12px
  );
  cursor: not-allowed;
}
.timeline-cell.is-time-point { cursor: pointer; }
.timeline-cell.is-time-point:hover { background: rgba(37, 99, 235, 0.08); }
.timeline-cell.is-disabled { cursor: not-allowed; opacity: 0.6; }

.timeline-label {
  font-size: 0.75rem;
  color: var(--color-muted);
  text-align: right;
  padding: 4px 6px;
  border-bottom: 1px dashed var(--color-border);
  background: var(--color-bg);
}

.timeline-day-header {
  text-align: center;
  font-size: 0.85rem;
  padding: 6px 4px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
}

.timeline-day-column {
  position: relative;
  border-left: 1px solid var(--color-border);
  grid-row: 2 / span var(--slot-rows, 9);
}

.schedule-card {
  position: absolute;
  left: 4px;
  right: 4px;
  background: rgba(37, 99, 235, 0.1);
  border-left: 4px solid var(--color-primary);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.8rem;
  cursor: pointer;
  box-shadow: 0 1px 2px var(--color-shadow);
  overflow: hidden;
}

.schedule-card.is-pending { background: rgba(217, 119, 6, 0.15); border-left-color: var(--color-pending); }
.schedule-card.is-approved { background: rgba(22, 163, 74, 0.15); border-left-color: var(--color-approved); }
.schedule-card.is-rejected { background: rgba(220, 38, 38, 0.15); border-left-color: var(--color-rejected); }

.schedule-card .topic { font-weight: 600; }
.schedule-card .meta { color: var(--color-muted); font-size: 0.7rem; }

.drawer {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: flex;
  justify-content: flex-end;
  z-index: 10;
}

.drawer[hidden] { display: none; }

.drawer-panel {
  width: 380px;
  max-width: 100%;
  background: var(--color-surface);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.drawer-panel form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.drawer-panel label { display: flex; flex-direction: column; font-size: 0.85rem; gap: 4px; }
.drawer-panel label.full { grid-column: 1 / -1; }
.drawer-panel .actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
.drawer-panel .form-error { grid-column: 1 / -1; color: var(--color-rejected); }

.error { color: var(--color-rejected); font-size: 0.75rem; min-height: 1em; }

.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal[hidden] { display: none; }
.modal-panel { background: var(--color-surface); padding: 20px; border-radius: 8px; max-width: 360px; }

.toast { position: fixed; right: 20px; bottom: 20px; background: var(--color-text); color: #fff; padding: 10px 16px; border-radius: 6px; z-index: 30; }
.toast[hidden] { display: none; }

.state-message { padding: 40px; text-align: center; color: var(--color-muted); }

/* ---------- Teacher management ---------- */

.drawer.drawer-wide .drawer-panel { width: 520px; }

.drawer-header { display: flex; align-items: center; justify-content: space-between; }

.teacher-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border);
}
.teacher-toolbar label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--color-muted); gap: 4px; }
.teacher-toolbar .grow { flex: 1 1 220px; }
.teacher-toolbar .toolbar-actions { display: flex; gap: 8px; }
.teacher-toolbar input[type="search"] { width: 100%; padding: 6px 10px; border: 1px solid var(--color-border); border-radius: 6px; }

.teacher-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--color-bg);
  border-radius: 8px;
}
.teacher-form[hidden] { display: none; }
.teacher-form label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--color-muted); gap: 4px; }
.teacher-form label.full { grid-column: 1 / -1; }
.teacher-form input { padding: 6px 10px; border: 1px solid var(--color-border); border-radius: 6px; font-size: 0.9rem; }
.teacher-form .actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
.teacher-form .form-error { grid-column: 1 / -1; color: var(--color-rejected); font-size: 0.85rem; }

.teacher-state { padding: 16px; text-align: center; color: var(--color-muted); font-size: 0.9rem; }

.teacher-list { display: flex; flex-direction: column; gap: 6px; }
.teacher-row {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 1.4fr 1.2fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  font-size: 0.85rem;
}
.teacher-row .teacher-name { font-weight: 600; }
.teacher-row .teacher-actions { display: flex; justify-content: flex-end; }

@media (max-width: 720px) {
  .day-tabs { display: flex; }
  .timeline-axis { display: none; }
  .timeline-grid { grid-template-columns: 1fr; }
  .timeline-day-header, .timeline-day-column[data-day]:not([data-active="true"]) { display: none; }
  .timeline-day-column[data-active="true"] { display: block; }
  .drawer-panel { width: 100%; }
  .drawer.drawer-wide .drawer-panel { width: 100%; }
  .teacher-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "name name"
      "phone email"
      "specialty specialty"
      "actions actions";
  }
  .teacher-row .teacher-name { grid-area: name; }
  .teacher-row .teacher-cell:nth-of-type(2) { grid-area: phone; }
  .teacher-row .teacher-cell:nth-of-type(3) { grid-area: email; }
  .teacher-row .teacher-cell:nth-of-type(4) { grid-area: specialty; }
  .teacher-row .teacher-actions { grid-area: actions; justify-content: flex-end; }
  .teacher-form { grid-template-columns: 1fr; }
}

/* ---------- Class management ---------- */

.class-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border);
}
.class-toolbar label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--color-muted); gap: 4px; }
.class-toolbar .grow { flex: 1 1 220px; }
.class-toolbar .toolbar-actions { display: flex; gap: 8px; }
.class-toolbar input[type="search"] { width: 100%; padding: 6px 10px; border: 1px solid var(--color-border); border-radius: 6px; }

.class-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--color-bg);
  border-radius: 8px;
}
.class-form[hidden] { display: none; }
.class-form label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--color-muted); gap: 4px; }
.class-form label.full { grid-column: 1 / -1; }
.class-form input, .class-form select { padding: 6px 10px; border: 1px solid var(--color-border); border-radius: 6px; font-size: 0.9rem; background: var(--color-surface); }
.class-form .actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
.class-form .form-error { grid-column: 1 / -1; color: var(--color-rejected); font-size: 0.85rem; }

.class-state { padding: 16px; text-align: center; color: var(--color-muted); font-size: 0.9rem; }

.class-list { display: flex; flex-direction: column; gap: 6px; }
.class-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr 1.4fr 0.8fr 0.8fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  font-size: 0.85rem;
}
.class-row .class-name { font-weight: 600; }
.class-row .class-actions { display: flex; gap: 6px; justify-content: flex-end; }
.class-row .class-meta { color: var(--color-muted); font-size: 0.75rem; }

.class-status { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; }
.class-status.is-on { background: rgba(22, 163, 74, 0.15); color: var(--color-approved); }
.class-status.is-off { background: rgba(107, 114, 128, 0.15); color: var(--color-muted); }

@media (max-width: 720px) {
  .class-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "name name"
      "course teacher"
      "classroom classroom"
      "dates dates"
      "max status"
      "actions actions";
  }
  .class-row .class-name { grid-area: name; }
  .class-row .class-cell:nth-of-type(2) { grid-area: course; }
  .class-row .class-cell:nth-of-type(3) { grid-area: teacher; }
  .class-row .class-cell:nth-of-type(4) { grid-area: classroom; }
  .class-row .class-cell:nth-of-type(5) { grid-area: dates; }
  .class-row .class-cell:nth-of-type(6) { grid-area: max; }
  .class-row .class-cell:nth-of-type(7) { grid-area: status; }
  .class-row .class-actions { grid-area: actions; }
  .class-form { grid-template-columns: 1fr; }
}

/* ---------- Classroom management ---------- */

.classroom-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border);
}
.classroom-toolbar label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--color-muted); gap: 4px; }
.classroom-toolbar .grow { flex: 1 1 220px; }
.classroom-toolbar .toolbar-actions { display: flex; gap: 8px; }
.classroom-toolbar input[type="search"] { width: 100%; padding: 6px 10px; border: 1px solid var(--color-border); border-radius: 6px; }

.classroom-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--color-bg);
  border-radius: 8px;
}
.classroom-form[hidden] { display: none; }
.classroom-form label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--color-muted); gap: 4px; }
.classroom-form label.full { grid-column: 1 / -1; }
.classroom-form input { padding: 6px 10px; border: 1px solid var(--color-border); border-radius: 6px; font-size: 0.9rem; }
.classroom-form .actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
.classroom-form .form-error { grid-column: 1 / -1; color: var(--color-rejected); font-size: 0.85rem; }

.classroom-state { padding: 16px; text-align: center; color: var(--color-muted); font-size: 0.9rem; }

.classroom-list { display: flex; flex-direction: column; gap: 6px; }
.classroom-row {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 1.6fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  font-size: 0.85rem;
}
.classroom-row .classroom-name { font-weight: 600; }
.classroom-row .classroom-actions { display: flex; justify-content: flex-end; }

@media (max-width: 720px) {
  .classroom-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "name name"
      "capacity location"
      "actions actions";
  }
  .classroom-row .classroom-name { grid-area: name; }
  .classroom-row .classroom-cell:nth-of-type(2) { grid-area: capacity; }
  .classroom-row .classroom-cell:nth-of-type(3) { grid-area: location; }
  .classroom-row .classroom-actions { grid-area: actions; justify-content: flex-end; }
  .classroom-form { grid-template-columns: 1fr; }
}
