:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --line: #e5e9f2;
  --text: #1c2434;
  --muted: #6b7689;
  --primary: #3b6ef6;
  --primary-soft: #eaf0ff;
  --male: #3b82f6;
  --female: #ec4899;
  --care: #f59e0b;
  --fixed: #10b981;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 22px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 11px;
  background: linear-gradient(135deg, #3b6ef6, #6d8dff);
  color: #fff; font-size: 20px; font-weight: 700;
  display: grid; place-items: center; box-shadow: 0 6px 16px rgba(59, 110, 246, .35);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 650; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 8px; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 9px; font-size: 13px; cursor: pointer;
  transition: .15s; font-family: inherit; position: relative;
}
.btn:active { transform: translateY(1px); }
/* 加载态：文字隐藏 + 居中转圈 */
.btn.busy { color: transparent !important; pointer-events: none; }
.btn.busy::after {
  content: ""; position: absolute; left: calc(50% - 7px); top: calc(50% - 7px);
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(28, 36, 52, .2); border-top-color: var(--muted);
  animation: spin .7s linear infinite;
}
.btn.busy.primary::after { border-color: rgba(255, 255, 255, .35); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn:hover { border-color: #cdd5e6; background: #fafbfe; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #2f5fe0; }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 5px 10px; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: #f6cfcf; }
.btn.danger:hover { background: #fef3f2; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover { background: #fff; border-color: var(--line); }
.fixed-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.fixed-row .tip { flex: 1; }
.fixed-row b { color: var(--fixed); }
.icon { border: 0; background: transparent; cursor: pointer; font-size: 15px; color: var(--muted); }

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px; min-width: 190px; display: none;
}
.menu-list.open { display: block; }
.menu-list button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 8px 10px; border-radius: 7px; font-size: 13px; cursor: pointer; font-family: inherit; color: var(--text);
}
.menu-list button:hover { background: var(--primary-soft); }
.menu-list button.danger { color: var(--danger); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }

/* ---------- 主布局 ---------- */
.layout {
  display: grid; grid-template-columns: 290px 1fr 290px; gap: 16px;
  padding: 16px 22px 32px; align-items: start;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; max-height: calc(100vh - 110px); overflow: auto;
}
.panel.side { position: sticky; top: 78px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 10px; }
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 650; }
.count {
  display: inline-block; min-width: 20px; text-align: center; font-size: 11px;
  background: var(--primary-soft); color: var(--primary); border-radius: 20px; padding: 1px 7px; margin-left: 4px;
}
.head-actions { display: flex; gap: 6px; }

/* ---------- 学生列表 ---------- */
.search { display: flex; gap: 6px; margin-bottom: 10px; }
.search input, .search select {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 13px;
  font-family: inherit; background: #fff; color: var(--text);
}
.search input { flex: 1; min-width: 0; }
.list { display: flex; flex-direction: column; gap: 6px; }
/* 名单作为候选栏：拖入高亮，提示可移出座位 */
.list.over {
  outline: 2px dashed var(--primary); outline-offset: 3px;
  border-radius: 10px; background: var(--primary-soft);
}
.drop-hint { margin-top: 8px; text-align: center; opacity: .85; }

.stu {
  display: flex; align-items: center; gap: 8px; padding: 8px 9px;
  border: 1px solid var(--line); border-radius: 10px; cursor: grab; background: #fff;
  transition: .12s;
}
.stu:hover { border-color: #b9c6ee; background: #fbfcff; }
.stu.dragging { opacity: .4; }
.stu.seated { background: #f7f9ff; }
.avatar {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  font-size: 12px; color: #fff; flex: 0 0 28px; font-weight: 600;
}
.avatar.M { background: var(--male); }
.avatar.F { background: var(--female); }
.stu-main { flex: 1; min-width: 0; }
.stu-name { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 5px; }
.stu-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
.tag { font-size: 10px; padding: 0 5px; border-radius: 5px; background: #eef2f8; color: var(--muted); }
.tag.care { background: #fff4e0; color: #b45309; }
.tag.fixed { background: #e7f7f1; color: #047857; }
.stu-seat { font-size: 11px; color: var(--primary); background: var(--primary-soft); padding: 1px 6px; border-radius: 5px; }
.stu-edit { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 4px; border-radius: 6px; }
.stu-edit:hover { background: #eef2f8; color: var(--text); }
.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 8px; }

/* ---------- 座位区 ---------- */
.stage {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; overflow: auto;
}
.podium {
  margin: 0 auto 18px; width: min(340px, 70%); text-align: center;
  background: linear-gradient(180deg, #eef2fb, #e3e9f7); border: 1px solid #dbe3f4;
  border-radius: 10px; padding: 9px; font-size: 13px; letter-spacing: 6px;
  color: #5b6884; font-weight: 600;
}
.grid-wrap { display: flex; justify-content: center; }
.grid { display: flex; flex-direction: column; gap: var(--gap, 8px); }
.grid-row { display: flex; gap: var(--gap, 8px); align-items: stretch; }
.aisle { width: 14px; flex: 0 0 14px; }

.seat {
  width: var(--seat-w, 92px); min-height: 58px; border-radius: 10px;
  border: 1px dashed #ced6e8; background: #fbfcfe;
  display: grid; place-items: center; padding: 4px; cursor: pointer; transition: .12s;
  position: relative;
}
.seat:hover { border-color: var(--primary); background: var(--primary-soft); }
.seat.over { border: 2px solid var(--primary); background: var(--primary-soft); }
.seat.disabled { background: repeating-linear-gradient(45deg, #f3f4f7, #f3f4f7 6px, #e9ebf1 6px, #e9ebf1 12px); border-style: solid; border-color: #dfe3ec; cursor: pointer; }
.seat.disabled::after { content: "停用"; font-size: 11px; color: #9aa3b5; }

.card {
  width: 100%; height: 100%; border-radius: 8px; padding: 5px 6px; cursor: grab;
  border: 1px solid transparent; background: #fff; box-shadow: 0 1px 3px rgba(16,24,40,.08);
  display: flex; flex-direction: column; justify-content: center; gap: 2px; position: relative;
  transition: transform .12s ease, box-shadow .12s ease;
}
.card.M { border-left: 3px solid var(--male); }
.card.F { border-left: 3px solid var(--female); }
.card.care { background: #fffaf0; }
.card.fixed { outline: 2px solid var(--fixed); outline-offset: 1px; }
.card:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(16,24,40,.14); }
.card.dragging { opacity: .4; }
.card-name { font-size: 13px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { font-size: 10px; color: var(--muted); text-align: center; }
.card-flag {
  position: absolute; top: -7px; font-size: 9px; line-height: 14px;
  padding: 0 5px; border-radius: 7px; color: #fff; font-weight: 600; letter-spacing: 1px;
}
.card-flag.care { right: -4px; background: var(--care); }
.card-flag.fixed { left: -4px; background: var(--fixed); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 18px; font-size: 12px; color: var(--muted); justify-content: center; }
.legend span { display: flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot.male { background: var(--male); }
.dot.female { background: var(--female); }
.dot.care { background: var(--care); }
.dot.fixed { background: var(--fixed); }
.dot.off { background: #dfe3ec; }
.legend .hint { color: #99a3b5; }

/* ---------- 表单 ---------- */
.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.form .row { display: flex; gap: 8px; }
.form .row label { flex: 1; min-width: 0; }
.form input, .form select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 9px;
  font-size: 13px; font-family: inherit; color: var(--text); background: #fff; width: 100%;
}
.form input:focus, textarea:focus, .search input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.switch { flex-direction: row !important; align-items: center; gap: 8px !important; cursor: pointer; }
.switch input { width: 16px; height: 16px; flex: 0 0 16px; }
.switch span { font-size: 13px; color: var(--text); }
.tip { font-size: 12px; color: var(--muted); margin: 0; line-height: 1.6; }
.rules { gap: 12px; }
.improve { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 9px; background: #fcfdff; }
.improve .tip { line-height: 1.6; }

.week-list { display: flex; flex-direction: column; gap: 5px; margin-top: 2px; }
.week-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 9px; font-size: 12px; background: #fff;
}
.week-item.cur { border-color: var(--primary); background: var(--primary-soft); }
.week-item .wname { font-weight: 600; flex: 0 0 auto; }
.week-item .wmeta { color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.week-item .wact { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 2px 5px; border-radius: 6px; font-size: 12px; }
.week-item .wact:hover { background: #eef2f8; color: var(--text); }
.week-item .wact.del:hover { background: #fdecec; color: var(--danger); }
.rule { border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: #fbfcfe; }
.rule-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rule-name { font-size: 13px; font-weight: 600; color: var(--text); }
.rule-desc { display: block; margin-top: 6px; font-size: 11px; color: var(--muted); line-height: 1.5; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button {
  border: 0; background: transparent; padding: 4px 8px; font-size: 11px; cursor: pointer;
  color: var(--muted); font-family: inherit; border-right: 1px solid var(--line); transition: .12s;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: #f2f5fb; }
.seg button.on { background: var(--primary); color: #fff; font-weight: 600; }
.seg button.on.off { background: #94a0b8; }
.seg button.on.off:hover { background: #8390ab; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { background: var(--primary-soft); color: var(--primary); border-radius: 20px; padding: 2px 8px; font-size: 12px; display: flex; gap: 5px; align-items: center; }
.chip b { cursor: pointer; font-weight: 400; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: #f8fafd; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 17px; font-weight: 700; }
.stat span { font-size: 11px; color: var(--muted); }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 14px; width: min(460px, 100%); padding: 18px; box-shadow: 0 20px 60px rgba(16,24,40,.25); max-height: 90vh; overflow: auto; animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-foot { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.spacer { flex: 1; }
.modal-card .tip { margin-bottom: 10px; }
textarea { resize: vertical; line-height: 1.7; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 10px);
  background: #1c2434; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13px; z-index: 100; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .22s ease, transform .22s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[hidden] { display: none; }

/* ---------- 可访问性 ---------- */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 260px 1fr; }
  .panel.side { grid-column: 1 / -1; position: static; max-height: none; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .panel { max-height: none; }
  .topbar { flex-wrap: wrap; }
}

/* ---------- 打印 ---------- */
@media print {
  body { background: #fff; }
  .topbar, .panel, .legend .hint, .podium { -webkit-print-color-adjust: exact; }
  .topbar, .panel, .toast, .modal, .stage-tools, .layout-editor, .le-podium-switch { display: none !important; }
  .layout { display: block; padding: 0; }
  .stage { border: 0; box-shadow: none; padding: 0; }
  .podium { display: block; }
  .seat { border-color: #999; }
  .legend { margin-top: 10px; }
}

/* ---------- 图形化布局编辑器（中间座位区） ---------- */
.stage-tools {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 8px 10px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fbfcff;
}
.stage-tools .tip { flex: 1; min-width: 140px; }
.layout-editor {
  --le-cell: 40px; overflow-x: auto; padding: 4px 0 10px;
  width: max-content; max-width: 100%; margin: 0 auto;
}
.le-podium { background: #e9eef7; border: 1px dashed #c2cee0; border-radius: 6px; text-align: center; color: #5b6b86; font-size: 12px; padding: 4px; margin-bottom: 8px; letter-spacing: 2px; }
.le-podium-switch { margin: 0 auto 12px; width: max-content; }
.le-row { display: flex; align-items: center; gap: 5px; margin-bottom: 5px; width: max-content; }
.le-rownum { width: 50px; min-width: 50px; height: 32px; border: 1px solid #d4dbe8; background: #f3f6fb; border-radius: 6px; font-size: 12px; color: #5b6b86; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.le-rownum:hover { background: #e6edf7; }
.le-rownum.le-addtop { background: #eafaf0; border-color: #bfe6cf; color: #1f9d55; }
.le-cell { width: var(--le-cell); height: var(--le-cell); min-width: var(--le-cell); border: 1px solid #d4dbe8; background: #fff; border-radius: 6px; cursor: pointer; font-size: 15px; color: #c0392b; display: flex; align-items: center; justify-content: center; padding: 0; }
.le-cell:hover { background: #eef3fb; }
.le-cell.off { background: #fdecec; border-color: #f3bcbc; }
.le-colnum { width: var(--le-cell); min-width: var(--le-cell); height: 32px; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #5b6b86; background: #f3f6fb; border: 1px solid #d4dbe8; border-radius: 6px; }
.le-gap { width: 18px; min-width: 18px; height: 32px; border: 1px dashed #b9c6da; border-radius: 5px; background: #f7fafd; color: #7a8aa5; font-size: 12px; cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center; font-family: inherit; }
.le-gap:hover { background: #eaf1fb; color: #3b6fb0; border-color: #9db4d8; }
.le-gap.on { background: #fff4e0; border: 1px solid #f0c981; color: #b9770a; font-weight: 600; }
.le-gap.on:hover { background: #ffe9c2; }
.le-gap.static { cursor: default; border-style: solid; border-color: transparent; background: transparent; }
.le-gap.static.on { background: linear-gradient(180deg, #fdf3df, #f7e3ba); border: 0; border-radius: 0; }
.le-add { width: 36px; min-width: 36px; height: 32px; border: 1px dashed #b9c6da; background: #f7fafd; border-radius: 6px; color: #3b6fb0; font-size: 13px; cursor: pointer; padding: 0; }
.le-add:hover { background: #eaf1fb; }
.le-del { width: 36px; min-width: 36px; height: 32px; border: 1px dashed #e3b4b4; background: #fdf3f3; border-radius: 6px; color: #c0392b; font-size: 13px; cursor: pointer; padding: 0; }
.le-del:hover { background: #fbe3e3; }
