:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef3f5;
  --line: #d9e1e5;
  --line-strong: #b7c5cc;
  --text: #172026;
  --muted: #65747d;
  --accent: #176b87;
  --accent-2: #2f7d57;
  --blue: #2559c7;
  --amber: #b7791f;
  --red: #b42318;
  --shadow: 0 18px 42px rgba(21, 31, 36, 0.11);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button,
label.tool-button {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

.app-shell {
  width: 100%;
  max-width: 100vw;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  overflow-x: hidden;
}

.sidebar {
  min-width: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.side-section {
  display: grid;
  gap: 8px;
}

.section-label,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.segmented button,
.target-button,
.secondary-button,
.tool-button,
.primary-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 36px;
}

.segmented button {
  min-width: 0;
  padding: 0 4px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segmented button.is-active {
  color: var(--accent);
  background: var(--surface);
  border-color: var(--line);
}

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

.target-button {
  min-width: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
}

.target-button small {
  color: var(--muted);
}

.target-button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.target-button.is-active {
  background: #e7f3f6;
  border-color: #afd5df;
  color: #0f4f64;
}

.status-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-top: auto;
  background: var(--surface);
}

.status-box dl {
  margin: 0;
  display: grid;
  gap: 8px;
}

.status-box dl div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.status-box dt,
.status-box dd {
  margin: 0;
}

.status-box dt {
  color: var(--muted);
}

.status-box dd {
  font-weight: 800;
}

.plan-link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.main {
  width: 100%;
  min-width: 0;
  max-width: 100vw;
  overflow-x: hidden;
  padding: 22px;
  display: grid;
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
  margin-bottom: 0;
}

h2 {
  font-size: 16px;
  margin-bottom: 0;
}

.toolbar,
.board-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tool-button,
.secondary-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  text-decoration: none;
  font-weight: 800;
}

.tool-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.tool-button:hover,
.secondary-button:hover {
  border-color: var(--line-strong);
}

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

.secondary-button {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.import-strip {
  min-height: 72px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #eef7f7;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.import-strip strong,
.import-strip span {
  display: block;
}

.import-strip span {
  color: var(--muted);
  margin-top: 2px;
}

.import-strip.is-dragging {
  border-color: var(--accent);
  background: #e3f4f0;
}

.workspace {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 16px;
  align-items: start;
}

.board-panel,
.rail-panel {
  min-width: 0;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.board-panel {
  min-width: 0;
  overflow: hidden;
}

.board-header {
  min-height: 76px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.board-header p {
  color: var(--muted);
  margin-bottom: 0;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: auto;
}

.timetable {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  table-layout: fixed;
}

.timetable th,
.timetable td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.timetable th {
  height: 44px;
  background: #f8fafb;
  color: #384850;
  font-size: 13px;
}

.timetable th:first-child,
.period-cell {
  width: 88px;
}

.period-cell {
  background: #f8fafb;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
  font-size: 13px;
}

.slot {
  min-height: 104px;
  padding: 7px;
  background: #fff;
  vertical-align: top;
}

.slot.is-over {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
  background: #f0faf8;
}

.slot.empty {
  background-image: linear-gradient(135deg, rgba(23, 107, 135, 0.05) 25%, transparent 25%);
  background-size: 10px 10px;
}

.lesson-card,
.pool-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  background: #fbfdff;
  padding: 8px;
  min-height: 76px;
  display: grid;
  gap: 5px;
  cursor: grab;
}

.lesson-card:active,
.pool-card:active {
  cursor: grabbing;
}

.lesson-card.is-locked {
  border-left-color: #6d7680;
  background: #f7f8f9;
}

.lesson-card.has-conflict {
  border-color: #efb5ad;
  border-left-color: var(--red);
  background: #fff7f5;
}

.lesson-card.has-warning {
  border-left-color: var(--amber);
  background: #fffaf0;
}

.lesson-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-weight: 900;
}

.lesson-title button {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  display: grid;
  place-items: center;
  padding: 0;
}

.lesson-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 6px;
  border-radius: 6px;
  color: #39444b;
  background: #ecf1f3;
  font-size: 12px;
  font-weight: 800;
}

.badge.conflict {
  background: #fde8e3;
  color: var(--red);
}

.badge.warning {
  background: #fff1ca;
  color: #805400;
}

.right-rail {
  display: grid;
  gap: 12px;
}

.rail-panel {
  padding: 12px;
}

.rail-panel.compact {
  box-shadow: none;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-head span {
  min-width: 28px;
  min-height: 24px;
  padding: 2px 7px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

.lesson-pool,
.conflict-list {
  display: grid;
  gap: 8px;
  max-height: 334px;
  overflow: auto;
  padding-right: 2px;
}

.pool-card {
  border-left-color: var(--accent-2);
}

.pool-card small {
  color: var(--muted);
}

.empty-state {
  min-height: 76px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 10px;
}

.conflict-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #fff;
  display: grid;
  gap: 4px;
}

.conflict-item.hard {
  border-color: #efb5ad;
  background: #fff7f5;
}

.conflict-item.soft {
  border-color: #ecd393;
  background: #fffaf0;
}

.conflict-item strong {
  font-size: 13px;
}

.conflict-item span {
  color: var(--muted);
  font-size: 12px;
}

.version-list {
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  display: grid;
  gap: 5px;
}

.version-list button {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 800;
  padding: 0;
}

.import-dialog {
  width: min(680px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(15, 24, 29, 0.28);
}

.import-dialog::backdrop {
  background: rgba(12, 20, 24, 0.42);
}

.import-dialog form {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.icon-button {
  width: 34px;
  height: 34px;
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--line);
  font-size: 22px;
  line-height: 1;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}

textarea {
  width: 100%;
  resize: vertical;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 10px;
  color: var(--text);
  background: #fbfcfd;
  line-height: 1.45;
}

.dialog-actions {
  justify-content: end;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  pointer-events: none;
  background: #172026;
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 20;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1160px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .right-rail {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .lesson-pool,
  .conflict-list {
    max-height: 260px;
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: 100vw;
    max-width: 100vw;
    grid-template-columns: 1fr;
  }

  .sidebar {
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar,
  .board-header,
  .import-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar,
  .board-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .topbar,
  .import-strip,
  .workspace,
  .board-panel,
  .right-rail {
    width: 100%;
    max-width: 100%;
  }

  .timetable {
    width: 820px;
    max-width: none;
  }

  .right-rail {
    grid-template-columns: 1fr;
  }

  .status-box dl div {
    max-width: 100%;
  }
}

@media (max-width: 560px) {
  .main {
    padding: 14px;
  }

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

  .tool-button,
  .secondary-button,
  .primary-button {
    width: 100%;
  }
}
