/* ============== 基础重置 ============== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft Yahei", sans-serif;
  background: #f3f4f6;
  color: #111827;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============== 顶栏 (PC) ============== */
.app-header {
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 10px 28px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand { font-size: 17px; font-weight: 700; color: #1f2937; white-space: nowrap; }
.tabs { display: flex; gap: 2px; flex: 1; }
.tabs button {
  background: transparent; border: 0; padding: 9px 13px;
  font-size: 14px; color: #6b7280; cursor: pointer;
  border-radius: 6px; transition: 0.15s;
  display: inline-flex; align-items: center; gap: 4px;
}
.tabs button:hover { background: #f3f4f6; color: #1f2937; }
.tabs button.active { background: #2563eb; color: #fff; font-weight: 600; }

/* 手机端元素默认隐藏 */
.hamburger, .current-tab-mobile { display: none; }

/* ============== 主内容 ============== */
main { padding: 24px 28px; max-width: 1400px; margin: 0 auto; }

.card {
  background: #fff; border-radius: 10px; padding: 22px 24px;
  margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.card h2 {
  font-size: 17px; margin-bottom: 14px; color: #1f2937;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card h2 .sub { font-size: 12px; color: #9ca3af; font-weight: normal; }
.card-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* ============== 按钮 ============== */
button.btn {
  background: #2563eb; color: #fff; border: 0; padding: 9px 18px;
  border-radius: 6px; cursor: pointer; font-size: 14px;
  transition: 0.15s; white-space: nowrap;
}
button.btn:hover { background: #1d4ed8; }
button.btn:disabled { background: #9ca3af; cursor: not-allowed; }
button.btn-secondary { background: #e5e7eb; color: #1f2937; }
button.btn-secondary:hover { background: #d1d5db; }
button.btn-danger { background: #dc2626; }
button.btn-danger:hover { background: #b91c1c; }
button.btn-success { background: #16a34a; }
button.btn-success:hover { background: #15803d; }

input, select, textarea {
  padding: 8px 11px; border: 1px solid #d1d5db; border-radius: 6px;
  font-size: 14px; background: #fff; min-height: 36px;
}
input:focus, select:focus, textarea:focus {
  outline: 0; border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

/* ============== 表格 ============== */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  background: #f9fafb; padding: 11px 10px; text-align: left;
  color: #6b7280; font-weight: 600; border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid #f3f4f6; }
tr:hover td { background: #f9fafb; }

/* ============== 统计卡片 ============== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; margin-bottom: 16px;
}
.stat {
  background: #fff; border-radius: 10px; padding: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.stat .label { font-size: 12px; color: #6b7280; margin-bottom: 6px; }
.stat .value { font-size: 26px; font-weight: 700; color: #1f2937; line-height: 1.1; }

/* ============== 徽章 ============== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-M { background: #dbeafe; color: #1e40af; }
.badge-F { background: #fce7f3; color: #be185d; }
.badge-dorm { background: #fef3c7; color: #92400e; }
.badge-rus { background: #ede9fe; color: #6d28d9; }
.badge-prob { background: #fee2e2; color: #b91c1c; }
.badge-leave { background: #e5e7eb; color: #4b5563; }
.badge-rel { background: #fbbf24; color: #78350f; }
.badge-locked { background: #d1d5db; color: #374151; }

/* ============== 模态框 ============== */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal {
  background: #fff; border-radius: 12px; padding: 24px;
  max-width: 800px; max-height: 85vh; overflow: auto; width: 100%;
}
.modal h3 { font-size: 17px; margin-bottom: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* ============== Toast ============== */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  padding: 12px 20px; border-radius: 8px; color: #fff;
  background: #1f2937; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 9999; opacity: 0; transition: 0.25s;
  pointer-events: none; font-size: 14px;
  max-width: calc(100vw - 48px);
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast:not(.show) { transform: translateY(20px); }
#toast.success { background: #16a34a; }
#toast.error { background: #dc2626; }

/* ============== 分班结果页 ============== */
.class-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 14px;
}
.class-card {
  background: #f9fafb; border-radius: 8px; padding: 14px;
  border: 1px solid #e5e7eb;
}
.class-card h4 {
  font-size: 15px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.class-card .stats-mini {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px;
  font-size: 12px; color: #4b5563;
}
.class-card .stats-mini .item {
  padding: 3px 7px; background: #fff; border-radius: 4px;
  border: 1px solid #e5e7eb; white-space: nowrap;
}
.class-card ul { list-style: none; max-height: 260px; overflow: auto; min-height: 30px; }

.layer-section { margin-bottom: 28px; }
.layer-section h3 {
  font-size: 15px; margin-bottom: 12px; color: #1f2937;
  padding: 7px 14px; background: #ddd6fe;
  border-radius: 6px; display: inline-block;
}

/* 拖拽学生行 */
.draggable {
  padding: 8px 10px; border-radius: 4px; background: #fff;
  margin-bottom: 5px; cursor: grab; font-size: 13px;
  border: 1px solid #e5e7eb;
  display: flex; align-items: center; gap: 6px;
  transition: 0.1s;
}
.draggable:hover { background: #f3f4f6; border-color: #93c5fd; }
.draggable:active { cursor: grabbing; }
.draggable.locked { background: #fef3c7; cursor: not-allowed; border-color: #fbbf24; }
.draggable.has-rel { border-left: 3px solid #f59e0b; background: #fffbeb; }
.draggable .stu-name { font-weight: 600; }
.draggable .attrs { display: inline-flex; gap: 3px; }
.draggable .lock-btn {
  background: transparent; border: 0; padding: 2px 5px;
  cursor: pointer; font-size: 11px; margin-left: auto; opacity: 0.4;
}
.draggable .lock-btn:hover { opacity: 1; }
.draggable .lock-btn.on { opacity: 1; color: #f59e0b; }

.drop-target { transition: background 0.15s; }
.drop-target.dragover { background: #d1fae5; box-shadow: inset 0 0 0 2px #16a34a; }

.recommend-list { list-style: none; padding: 0; }
.recommend-list li {
  padding: 12px; border: 1px solid #e5e7eb; border-radius: 6px;
  margin-bottom: 6px; display: flex; justify-content: space-between;
  align-items: center; gap: 12px; transition: 0.15s; flex-wrap: wrap;
}
.recommend-list li:hover { background: #f9fafb; border-color: #93c5fd; }

table.balance-cell { border-collapse: collapse; }
table.balance-cell td.max { background: #d1fae5; font-weight: 700; }
table.balance-cell td.min { background: #fee2e2; font-weight: 700; }

/* 雷达图网格: 6 列 (PC) → 4 列 (中屏) → 2 列 (小屏) */
.radar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 14px;
}
.radar-cell {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  transition: 0.15s;
}
.radar-cell:hover { box-shadow: 0 4px 8px rgba(0,0,0,0.06); border-color: #93c5fd; }
.radar-title {
  font-size: 13px; font-weight: 600;
  margin-bottom: 4px; color: #374151;
  display: flex; align-items: center; justify-content: space-between;
}
.radar-title .avg-score {
  font-size: 16px; color: #2563eb; font-weight: 700;
}
.radar-title .n-stu {
  font-size: 11px; color: #9ca3af; font-weight: normal;
}
.radar-canvas-wrap {
  display: flex; justify-content: center;
  margin: 4px 0;
}
.radar-canvas-wrap canvas { display: block; }
.radar-summary {
  font-size: 11px; color: #6b7280;
  margin-top: 4px; line-height: 1.6;
}
.radar-summary span { margin-right: 6px; }
.radar-subjects {
  margin-top: 6px; padding-top: 6px;
  border-top: 1px dashed #e5e7eb;
  font-size: 11px; color: #6b7280;
  line-height: 1.6;
}
.radar-subjects span { margin-right: 6px; }

/* ====================================================================
   响应式: 平板 (<= 1024px)
   ==================================================================== */
@media (max-width: 1024px) {
  main { padding: 20px 20px; }
  .app-header { padding: 9px 20px; gap: 14px; }
  .tabs button { padding: 8px 11px; font-size: 13px; }
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .stat .value { font-size: 22px; }
  .radar-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}

/* ====================================================================
   响应式: 手机 (<= 768px)
   ==================================================================== */
@media (max-width: 768px) {
  /* 顶栏改造: hamburger + 品牌 + 当前 tab 名 */
  .app-header { padding: 9px 12px; gap: 8px; }
  .hamburger {
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: 0; font-size: 22px;
    color: #1f2937; cursor: pointer; padding: 6px 10px;
    border-radius: 6px; min-width: 40px; min-height: 40px;
    -webkit-tap-highlight-color: transparent;
  }
  .hamburger:active { background: #f3f4f6; }
  .brand { font-size: 14px; flex: 0 0 auto; }
  .current-tab-mobile {
    display: block; flex: 1; text-align: right;
    font-size: 14px; color: #2563eb; font-weight: 700;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    padding-left: 8px;
  }

  /* 隐藏水平 tab，改为下拉菜单 */
  .tabs {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 200;
    display: none; align-items: flex-start;
    padding-top: 56px; flex-direction: column;
  }
  body.menu-open .tabs { display: flex; }
  .tabs::before {
    content: ''; position: fixed; top: 0; left: 0; right: 0;
    height: 56px; background: #fff;
    border-bottom: 1px solid #e5e7eb; z-index: 1;
  }
  .tabs button {
    width: 100%; text-align: left; padding: 14px 20px;
    font-size: 16px; color: #1f2937; border-radius: 0;
    background: #fff; border-bottom: 1px solid #f3f4f6;
    position: relative; z-index: 2;
    justify-content: flex-start;
  }
  .tabs button:active { background: #eff6ff; }
  .tabs button.active {
    background: #eff6ff; color: #2563eb; font-weight: 600;
  }
  .tabs button.active::after {
    content: '✓'; position: absolute; right: 20px;
    color: #2563eb; font-weight: 700;
  }

  /* 主内容 */
  main { padding: 12px 10px; }
  .card { padding: 14px 14px; border-radius: 8px; margin-bottom: 12px; }
  .card h2 { font-size: 15px; margin-bottom: 10px; gap: 6px; }
  .card h2 .sub { font-size: 11px; }

  /* 按钮加大触摸区 */
  button.btn { padding: 11px 18px; font-size: 15px; min-height: 42px; }
  input, select, textarea { font-size: 16px; padding: 10px 12px; min-height: 42px; }

  /* 表格转卡片模式 (class="responsive") */
  table.responsive { border: 0; }
  table.responsive thead { display: none; }
  table.responsive tr {
    display: block; margin-bottom: 10px; padding: 10px 12px;
    background: #f9fafb; border-radius: 6px;
    border: 1px solid #e5e7eb;
  }
  table.responsive tr:hover { background: #f3f4f6; }
  table.responsive td {
    display: flex; justify-content: space-between; align-items: center;
    padding: 5px 0; border: 0;
  }
  table.responsive td::before {
    content: attr(data-label); font-size: 12px; color: #6b7280;
    font-weight: 600; margin-right: 12px;
  }
  table.responsive td:last-child { padding-bottom: 0; }

  /* 统计卡片 */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px; }
  .stat .label { font-size: 11px; }
  .stat .value { font-size: 22px; }

  /* 模态框 */
  .modal { padding: 18px; max-height: 90vh; }
  .modal h3 { font-size: 16px; }

  /* Toast */
  #toast {
    left: 12px; right: 12px; bottom: 12px;
    text-align: center; font-size: 14px;
  }

  /* 分班结果: 单列堆叠 */
  .class-grid { grid-template-columns: 1fr; gap: 10px; }
  .class-card { padding: 12px; }
  .class-card ul { max-height: 200px; }

  .layer-section h3 { font-size: 14px; padding: 6px 10px; }
  .draggable { font-size: 13px; padding: 9px 10px; }

  /* 雷达图: 单列 */
  .radar-grid { grid-template-columns: 1fr; gap: 10px; }
  .radar-cell { padding: 12px !important; }
  .radar-canvas-wrap { margin: 6px 0; }
  .radar-summary { font-size: 12px !important; }
  .radar-subjects { font-size: 12px !important; }
}

/* 超窄屏 (<= 380px) */
@media (max-width: 380px) {
  .brand { font-size: 12px; }
  .current-tab-mobile { font-size: 13px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 20px; }
  .draggable .attrs { display: none; }
  .draggable .stu-name { font-size: 13px; }
}

/* ============== Plan 切换器 (PC) ============== */
.plan-switcher {
  display: flex; align-items: center; gap: 6px;
  margin-left: 8px; padding: 4px 10px;
  background: #f9fafb; border-radius: 8px;
  border: 1px solid #e5e7eb;
}
.plan-label {
  font-size: 12px; color: #6b7280; font-weight: 600;
  white-space: nowrap;
}
.plan-select {
  padding: 5px 8px; border: 1px solid #d1d5db; border-radius: 6px;
  font-size: 13px; background: #fff; min-width: 160px; max-width: 260px;
  cursor: pointer;
}
.plan-select:focus { border-color: #2563eb; }

.btn-mini {
  background: #2563eb; color: #fff; border: 0; padding: 5px 10px;
  border-radius: 5px; cursor: pointer; font-size: 12px; font-weight: 600;
  white-space: nowrap;
}
.btn-mini:hover { background: #1d4ed8; }
.btn-mini:disabled { background: #d1d5db; cursor: not-allowed; }
.btn-mini.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-mini.btn-danger:hover { background: #fecaca; }

/* ============== Modal 通用 ============== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: #fff; border-radius: 12px; padding: 24px;
  max-width: 480px; width: 100%; max-height: 90vh; overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-card h3 {
  font-size: 18px; margin-bottom: 8px; color: #1f2937;
}
.modal-hint {
  font-size: 13px; color: #6b7280; margin-bottom: 16px; line-height: 1.5;
}
.modal-card label {
  display: block; font-size: 13px; color: #374151; font-weight: 600;
  margin-bottom: 12px;
}
.modal-card input {
  display: block; width: 100%; margin-top: 4px;
  font-weight: normal; color: #111827;
}
.modal-row {
  display: flex; gap: 12px; margin-bottom: 12px;
}
.modal-row label { flex: 1; margin-bottom: 0; }
.modal-row input { width: 100%; }
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px;
}
.delete-target {
  background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
  padding: 10px 14px; border-radius: 6px; font-size: 13px; font-weight: 600;
  margin-bottom: 12px;
}
.modal-confirm input {
  font-weight: normal;
  border-color: #fca5a5;
}

/* ============== 平板 (≤1024px) ============== */
@media (max-width: 1024px) {
  .app-header { padding: 8px 16px; gap: 12px; }
  .brand { font-size: 15px; }
  .plan-switcher { padding: 3px 6px; }
  .plan-select { min-width: 120px; font-size: 12px; }
  .btn-mini { padding: 4px 8px; font-size: 11px; }
  .tabs button { padding: 8px 10px; font-size: 13px; }
}

/* ============== 手机 (≤768px) ============== */
@media (max-width: 768px) {
  .app-header {
    padding: 8px 12px; gap: 8px;
    flex-wrap: wrap;
  }
  .hamburger {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; background: transparent; border: 0;
    font-size: 20px; color: #1f2937; cursor: pointer;
  }
  .brand { font-size: 14px; }
  .plan-switcher {
    order: 99; width: 100%; margin: 4px 0 0 0; padding: 6px 8px;
    margin-left: 0;
  }
  .plan-select { flex: 1; min-width: 0; font-size: 13px; }
  .current-tab-mobile {
    display: block; font-size: 13px; color: #2563eb; font-weight: 600;
    flex: 1; text-align: right;
  }
  .tabs {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: #fff; flex-direction: column;
    border-bottom: 1px solid #e5e7eb; padding: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  }
  body.menu-open .tabs { display: flex; }
  body.menu-open .tabs button {
    width: 100%; justify-content: flex-start; padding: 12px 14px;
    border-radius: 6px;
  }
  body.menu-open .tabs button.active { background: #eff6ff; color: #2563eb; }

  .modal-card { padding: 18px; max-width: 100%; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }
}

/* ============== 学生管理增强样式 ============== */
/* 标签 chip */
.chip {
  background: #fff;
  border: 1.5px solid #d1d5db;
  color: #374151;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.15s;
  white-space: nowrap;
}
.chip:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}
.chip-active {
  background: #2563eb !important;
  color: #fff !important;
  border-color: #2563eb !important;
}

/* 开关 */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}
.switch input { display: none; }
.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #d1d5db;
  transition: 0.2s;
  border-radius: 26px;
}
.switch .slider:before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .slider {
  background-color: #2563eb;
}
.switch input:checked + .slider:before {
  transform: translateX(22px);
}

/* 大 modal */
.modal-large {
  max-width: 600px;
  width: 92%;
}
@media (max-width: 768px) {
  .modal-large {
    width: 96%;
    max-height: 88vh;
  }
  .toolbar { gap: 4px !important; }
  .toolbar input, .toolbar button { font-size: 13px !important; padding: 7px 10px !important; }
}
