* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; background: #f4f6f5; color: #222; }
button { background: #2e7d5b; color: #fff; border: 0; border-radius: 8px; padding: 9px 18px; cursor: pointer; font-size: 14px; }
button.ghost { background: #fff; color: #2e7d5b; border: 1px solid #2e7d5b; }
button.mini { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
button.mini.danger { background: #d9534f; }
button.mini.danger.ghost { background: #fff; color: #d9534f; border: 1px solid #d9534f; }
input, select, textarea { border: 1px solid #d6dedb; border-radius: 8px; padding: 9px 12px; font-size: 14px; outline: none; width: 100%; }
input.tiny { width: 64px; padding: 4px 6px; }
textarea { min-height: 76px; resize: vertical; }

.empty-page { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; }
.empty-page h3 { margin: 0; color: #7a8b84; font-weight: 500; }

.login-wrap { height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { width: 320px; background: #fff; padding: 32px; border-radius: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.06); }
.login-box h2 { margin: 0 0 20px; text-align: center; color: #2e7d5b; }
.login-box input { margin-bottom: 14px; }
.login-box button { width: 100%; }
.err { color: #d9534f; font-size: 13px; min-height: 18px; text-align: center; }

.layout { display: flex; min-height: 100vh; }
.side { width: 200px; background: #23463a; color: #dfe9e5; display: flex; flex-direction: column; }
.brand { padding: 20px; font-size: 16px; font-weight: 600; color: #fff; border-bottom: 1px solid #33564a; }
.menu { flex: 1; padding: 12px 0; }
.mi { padding: 12px 22px; cursor: pointer; font-size: 14px; }
.mi:hover { background: #2c5849; }
.mi.on { background: #2e7d5b; color: #fff; font-weight: 600; }
.side-foot { padding: 14px; border-top: 1px solid #33564a; }
.side-foot select { margin-bottom: 10px; }

.main { flex: 1; padding: 20px 26px; overflow: auto; }
.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.top h3 { margin: 0; }
.ops { display: flex; gap: 10px; align-items: center; }
.code { font-size: 13px; color: #2e7d5b; background: #eaf3ef; padding: 4px 10px; border-radius: 12px; }

.cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 16px; }
.card { background: #fff; border-radius: 12px; padding: 16px; }
.card .k { color: #7a8b84; font-size: 13px; }
.card .v { font-size: 26px; font-weight: 700; color: #2e7d5b; margin-top: 4px; }

.panel { background: #fff; border-radius: 12px; padding: 18px; margin-bottom: 16px; }
.panel h4 { margin: 0 0 14px; font-size: 15px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart { height: 260px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 8px; border-bottom: 1px solid #eef2f0; text-align: left; }
th { color: #7a8b84; font-weight: 500; }
td.clip { max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.bar-label { width: 150px; color: #555; }
.bar { flex: 1; background: #eef2f0; border-radius: 6px; height: 12px; overflow: hidden; }
.bar i { display: block; height: 100%; background: #e08b3c; }
.bar-val { width: 48px; text-align: right; color: #888; }

/* 筛选栏 */
.filter-bar {
  display: grid;
  grid-template-columns: minmax(160px, 1.4fr) minmax(140px, 1fr) minmax(120px, 0.9fr) auto;
  gap: 12px 14px;
  align-items: end;
}
.filter-actions { display: flex; gap: 8px; }
.filter-bar .lbl { margin-bottom: 6px; }

/* 表格单元格 */
.nowrap { white-space: nowrap; }
.q-cell { min-width: 130px; color: #444; }

/* 作答内容：默认两行截断，可展开看全文 */
.answer-cell { min-width: 220px; max-width: 460px; vertical-align: top; }
.answer-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  overflow: hidden;
  line-height: 1.6;
  color: #333;
  word-break: break-word;
  white-space: pre-wrap;
}
.answer-text.open {
  display: block;
  -webkit-line-clamp: unset;
  line-clamp: unset;
  max-height: 340px;
  overflow-y: auto;
}
.expand-btn {
  color: #2e7d5b;
  font-size: 12px;
  cursor: pointer;
  display: inline-block;
  margin-top: 4px;
  text-decoration: none;
}
.expand-btn:hover { text-decoration: underline; }
.answer-extra {
  margin-top: 8px;
  padding: 8px 10px;
  background: #f7faf9;
  border-radius: 6px;
  font-size: 12px;
  color: #555;
  line-height: 1.6;
  white-space: pre-wrap;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: #fdecec; color: #d9534f; padding: 4px 12px; border-radius: 14px; font-size: 13px; }
.chip.dark { background: #eceef0; color: #55606b; }
.row-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.row-head h4 { margin: 0; }
.unsub-row { border-top: 1px solid #eef2f0; padding: 12px 0; }
.unsub-row:first-of-type { border-top: 0; }
.unsub-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.unsub-title { font-size: 14px; font-weight: 500; flex: 1; }
.unsub-all { margin-top: 16px; padding-top: 14px; border-top: 2px dashed #e0e6e3; }
.unsub-all .lbl { margin-right: 6px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; margin-left: 6px; }
.badge.ok { background: #eaf3ef; color: #2e7d5b; }
.badge.warn { background: #fdecec; color: #d9534f; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.lbl { font-size: 13px; color: #555; font-weight: 500; }
.lbl em { color: #d9534f; font-style: normal; margin-left: 2px; }
.field .hint { font-size: 12px; color: #9aa8a3; }
.suffix-input { display: flex; align-items: center; gap: 6px; }
.suffix-input input { flex: 1; }
.suffix { color: #9aa8a3; font-size: 13px; }

/* 「单条添加学生」表单：姓名 + 学号 + 按钮 一行 */
.add-stu { grid-template-columns: 1fr 1fr auto; align-items: end; }
.add-stu-btn { height: 40px; white-space: nowrap; }
.btns { display: flex; gap: 10px; margin-bottom: 14px; }
.btns input { width: 200px; }
.tip { color: #7a8b84; font-size: 13px; margin-top: 10px; }
.empty { color: #9aa8a3; font-size: 13px; }
.hint { font-size: 13px; color: #7a8b84; line-height: 1.7; margin: 0 0 12px; }
.hint b { color: #2e7d5b; }
.err-list {
  margin: 10px 0 0; padding-left: 20px;
  color: #d9534f; font-size: 12px; line-height: 1.8;
  max-height: 140px; overflow-y: auto;
}

/* ==================== 移动端适配（≤768px）==================== */
@media (max-width: 768px) {
  /* 侧栏改为顶部横向导航 + 吸顶 */
  .layout { flex-direction: column; }
  .side {
    width: 100%;
    flex-direction: column;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
  }
  /* 隐藏品牌标题，把「班级选择」放最上面，顶栏更紧凑 */
  .brand { display: none; }
  .side-foot {
    order: 1;
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 10px 16px;
    border-top: 0;
  }
  .side-foot select { margin-bottom: 0; flex: 1; }
  .side-foot button { white-space: nowrap; }
  .menu {
    order: 2;
    display: flex;
    flex: none;
    padding: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid #33564a;
  }
  .mi { padding: 11px 16px; white-space: nowrap; border-bottom: 3px solid transparent; }
  .mi:hover { background: transparent; }
  .mi.on { background: transparent; color: #7fd1ad; border-bottom-color: #7fd1ad; }

  /* 主区域 */
  .main { padding: 14px 12px calc(32px + env(safe-area-inset-bottom)); overflow: visible; }

  /* 顶部标题栏：换行，操作按钮自动包裹 */
  .top { flex-direction: column; align-items: flex-start; gap: 10px; }
  .top h3 { font-size: 17px; }
  .ops { width: 100%; flex-wrap: wrap; gap: 8px; }

  /* KPI 卡片：5 列 → 2 列 */
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card { padding: 12px; }
  .card .k { font-size: 12px; }
  .card .v { font-size: 22px; }

  /* 双栏 → 单栏 */
  .two { grid-template-columns: 1fr; }
  .chart { height: 220px; }

  /* 面板与表格：横向滚动，避免挤压变形 */
  .panel { padding: 14px 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 520px; font-size: 13px; }
  th, td { padding: 8px 6px; }
  td.clip { max-width: 160px; }

  /* 表单：单列，输入框撑满 */
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .add-stu { grid-template-columns: 1fr; }
  .add-stu-btn { width: 100%; }
  .btns { flex-wrap: wrap; }
  .btns input { width: 100%; }
  .btns button { width: 100%; }

  /* iOS 聚焦输入框时字号 <16px 会自动放大页面，统一设 16px 规避 */
  input, select, textarea { font-size: 16px; }
  input.tiny { width: 56px; }

  /* 条形图标签收窄 */
  .bar-label { width: 96px; font-size: 12px; }
  .bar-val { width: 40px; font-size: 12px; }

  /* 筛选栏：手机上一行一个 */
  .filter-bar { grid-template-columns: 1fr; }
  .filter-actions button { flex: 1; }

  /* 手机上答案列放宽，减少滚动 */
  .answer-cell { min-width: 200px; max-width: 280px; }
  .answer-text.open { max-height: none; }

  /* 登录框自适应 */
  .login-box { width: min(320px, 88vw); padding: 24px; }

  button { padding: 10px 16px; }
}

/* 超小屏（≤380px）：KPI 卡片再缩一档 */
@media (max-width: 380px) {
  .cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .card .v { font-size: 20px; }
  .mi { padding: 10px 12px; font-size: 13px; }
}
