/* ============================================================
 * 成绩分析 · AI 辅助版  —— 样式表
 * 设计取向：白天在教室/办公室投影也看得清，信息密度高但不脏
 * ============================================================ */

:root {
  --ink: #2d3142;
  --ink-2: #4a4f57;
  --muted: #8a9099;
  --line: #e6e8ee;
  --line-2: #f1f3f7;
  --bg: #f6f7fa;
  --card: #ffffff;
  --brand: #2A6BA6;
  --brand-2: #942D97;
  --ok: #2f8f5b;
  --warn: #c9761b;
  --bad: #C1232B;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28, 32, 45, .04), 0 8px 24px -12px rgba(28, 32, 45, .16);
  --shadow-2: 0 1px 2px rgba(28, 32, 45, .05), 0 14px 34px -16px rgba(28, 32, 45, .22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--brand); }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1320px; margin: 0 auto; padding: 10px 18px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: linear-gradient(140deg, var(--brand), var(--brand-2));
  color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 15px; letter-spacing: -.5px;
  box-shadow: 0 4px 12px -4px rgba(42, 107, 166, .6);
}
.brand-txt b { display: block; font-size: 15px; line-height: 1.25; }
.brand-txt span { font-size: 11.5px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 13px; border-radius: 9px;
  border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  font-size: 13px; cursor: pointer; white-space: nowrap;
  transition: .16s ease; user-select: none;
}
.btn:hover { border-color: #cfd5de; background: #fafbfd; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: linear-gradient(140deg, var(--brand), #3580c0);
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 16px -8px rgba(42, 107, 166, .8);
}
.btn.primary:hover { filter: brightness(1.04); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eef1f6; color: var(--ink-2); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 7px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ---------- 参数条 ---------- */
.params {
  max-width: 1320px; margin: 0 auto; padding: 0 18px;
}
.params-panel {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px; padding: 14px 16px; margin-top: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 11.5px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.field input[type="text"], .field input[type="number"], .field select {
  height: 32px; padding: 0 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fbfcfe; min-width: 0;
}
.field input:focus, .field select:focus, .search:focus, textarea:focus {
  outline: 2px solid rgba(42, 107, 166, .18); border-color: var(--brand);
}
.hint { font-size: 11px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 20px; background: #f2f5fa;
  border: 1px solid var(--line); font-size: 12px;
}
.chip b { font-weight: 650; color: var(--ink); }
.chip input {
  width: 46px; height: 20px; border: 1px solid transparent; background: transparent;
  text-align: center; font-size: 12px; border-radius: 5px; color: var(--brand);
  font-weight: 700;
}
.chip input:hover { background: #fff; border-color: var(--line); }

/* ---------- 页签 ---------- */
.tabs {
  max-width: 1320px; margin: 14px auto 0; padding: 0 18px;
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; padding: 8px 14px 10px; border: none; background: none;
  color: var(--muted); font-size: 13.5px; font-weight: 600; cursor: pointer;
  white-space: nowrap; border-radius: 8px 8px 0 0;
}
.tab:hover { color: var(--ink-2); background: #eef1f6; }
.tab.active { color: var(--brand); }
.tab.active::after {
  content: ''; position: absolute; left: 12px; right: 12px; bottom: 0; height: 2.5px;
  background: var(--brand); border-radius: 2px;
}

/* ---------- 主体 ---------- */
main { max-width: 1320px; margin: 0 auto; padding: 16px 18px 80px; }
.panel { display: none; }
.panel.active { display: block; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; margin-bottom: 16px; overflow: hidden;
}
.card:last-child { margin-bottom: 0; }
.card-head {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin: -2px 0 12px;
}
.card-head h3 { font-size: 14.5px; }
.card-head .sub { font-size: 11.5px; color: var(--muted); }
.card-head .spacer { margin-left: auto; }

.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }

/* ---------- 指标卡 ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 10px; }
.kpi {
  padding: 11px 13px; border-radius: 11px; background: #fbfcfe;
  border: 1px solid var(--line-2);
}
.kpi .k { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 22px; font-weight: 720; letter-spacing: -.02em; line-height: 1.25; }
.kpi .v small { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.kpi .d { font-size: 11px; color: var(--muted); }
.kpi.up .v { color: var(--ok); }
.kpi.down .v { color: var(--bad); }

/* ---------- 表格 ---------- */
.table-wrap { overflow: auto; margin: 0 -18px; padding: 0 18px; }
.table-wrap.tight { margin: 0; padding: 0; }
table.tbl {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 12.5px; font-variant-numeric: tabular-nums;
}
table.tbl th, table.tbl td {
  padding: 7px 10px; text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--line-2);
}
table.tbl th {
  position: sticky; top: 0; z-index: 2; background: #f8f9fc;
  font-weight: 650; font-size: 11.5px; color: var(--ink-2);
  border-bottom: 1px solid var(--line);
  cursor: pointer; user-select: none;
}
table.tbl th.nosort { cursor: default; }
table.tbl th:hover { background: #eef1f7; }
table.tbl th .arrow { color: var(--brand); font-size: 9px; margin-left: 2px; }
table.tbl td.l, table.tbl th.l { text-align: left; }
table.tbl td.c, table.tbl th.c { text-align: center; }
table.tbl tbody tr:hover td { background: #f7f9fd; }
table.tbl tbody tr.total-row td { background: #f4f7fc; font-weight: 650; }
table.tbl tbody tr.clickable { cursor: pointer; }
.best { color: var(--ok); font-weight: 650; }
.worst { color: var(--bad); }
.dim { color: var(--muted); }

.pill {
  display: inline-block; padding: 1px 7px; border-radius: 20px;
  font-size: 11px; font-weight: 650; line-height: 1.6;
}
.pill.ok { background: #e8f6ee; color: #1f7a4a; }
.pill.warn { background: #fdf1e0; color: #a8611a; }
.pill.bad { background: #fdecec; color: #a81f26; }
.pill.info { background: #eaf2fb; color: #215d92; }
.pill.mute { background: #f0f2f6; color: #6c7380; }

/* ---------- 图表 ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 2px 0 8px; font-size: 11.5px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-item i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-tip {
  position: fixed; z-index: 999; pointer-events: none; opacity: 0;
  transition: opacity .12s ease; background: rgba(30, 34, 45, .93); color: #fff;
  padding: 6px 9px; border-radius: 7px; font-size: 11.5px; line-height: 1.5;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, .5); max-width: 240px;
}
.charts-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.rings { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.rings > * { flex: 1 1 150px; max-width: 210px; }

/* ---------- 导入区 ---------- */
.dropzone {
  border: 2px dashed #ccd4e0; border-radius: var(--radius);
  background: linear-gradient(#fbfcfe, #f7f9fc);
  padding: 34px 20px; text-align: center; cursor: pointer;
  transition: .18s ease;
}
.dropzone:hover, .dropzone.hot {
  border-color: var(--brand); background: #f0f6fd;
}
.dropzone .big { font-size: 15px; font-weight: 650; margin-bottom: 6px; }
.dropzone .sub { font-size: 12.5px; color: var(--muted); }
.dropzone .icon { font-size: 30px; margin-bottom: 8px; opacity: .75; }

/* ---------- 学生选择器 ---------- */
.student-pick { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search {
  height: 34px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 9px; background: #fbfcfe; min-width: 200px;
}
select.sel {
  height: 34px; padding: 0 10px; border: 1px solid var(--line);
  border-radius: 9px; background: #fbfcfe; max-width: 100%;
}

/* ---------- AI 面板 ---------- */
.ai-block { border-left: 3px solid var(--brand); padding: 2px 0 2px 13px; margin: 0 0 14px; }
.ai-block h4 { font-size: 13px; margin-bottom: 4px; }
.ai-block p { margin: 0 0 5px; color: var(--ink-2); font-size: 13px; }
.ai-block ul { margin: 4px 0 0; padding-left: 18px; color: var(--ink-2); font-size: 13px; }
.ai-block li { margin-bottom: 3px; }
.ai-block.warn { border-left-color: var(--warn); }
.ai-block.bad { border-left-color: var(--bad); }
.ai-block.ok { border-left-color: var(--ok); }

textarea.prompt {
  width: 100%; min-height: 210px; padding: 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fbfcfe;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.6; resize: vertical;
}

/* ---------- 空状态 ---------- */
.empty {
  text-align: center; padding: 42px 20px; color: var(--muted);
}
.empty .big { font-size: 30px; margin-bottom: 10px; opacity: .5; }

footer.foot {
  max-width: 1320px; margin: 0 auto; padding: 0 18px 30px;
  font-size: 11.5px; color: #a4aab4; display: flex; gap: 12px; flex-wrap: wrap;
}

/* ---------- 打印 ---------- */
#print-report { display: none; }
@media print {
  @page { size: A4; margin: 12mm 10mm; }
  body { background: #fff; font-size: 11px; }
  .topbar, .params, .tabs, main, footer.foot { display: none !important; }
  #print-report { display: block !important; }
  #print-report h1 { font-size: 19px; margin-bottom: 2px; }
  #print-report h2 {
    font-size: 13px; margin: 14px 0 6px; padding-bottom: 3px;
    border-bottom: 1.5px solid #2d3142;
  }
  #print-report table { width: 100%; border-collapse: collapse; font-size: 9.5px; }
  #print-report th, #print-report td { border: 1px solid #c9cdd6; padding: 3px 5px; text-align: right; }
  #print-report th { background: #f0f2f6; }
  #print-report td.l, #print-report th.l { text-align: left; }
  #print-report .pr-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  #print-report .pr-card { break-inside: avoid; margin-bottom: 8px; }
  #print-report .pr-meta { font-size: 10px; color: #555; margin-bottom: 8px; }
  .chart-tip { display: none !important; }
}

/* ---------- 平板/手机 ---------- */
@media (max-width: 860px) {
  main { padding: 12px 12px 70px; }
  .topbar-inner, .params, .tabs, footer.foot { padding-left: 12px; padding-right: 12px; }
  .card { padding: 13px 12px; border-radius: 12px; }
  .table-wrap { margin: 0 -12px; padding: 0 12px; }
  .brand-txt span { display: none; }
  .kpi .v { font-size: 19px; }
  .params-panel { grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; }
  .grid.c2, .grid.c3 { grid-template-columns: 1fr; }
}

/* ---------- 打印报告里的表格排版补充 ---------- */
#print-report table { table-layout: auto; }
#print-report th, #print-report td { white-space: nowrap; }
#print-report td.l { white-space: normal; }
#print-report h1, #print-report h2 { break-after: avoid; }
#print-report .pr-charts .chart { max-height: 190px; }

/* ---------- ECharts 容器与提示 ---------- */
.chart-ec { width: 100%; min-height: 160px; }
.chart-ec canvas { border-radius: 6px; }

.sa-toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 14px);
  background: rgba(30, 34, 45, .94); color: #fff; padding: 9px 16px;
  border-radius: 10px; font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 1200;
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, .6); max-width: 80vw;
}
.sa-toast.show { opacity: 1; transform: translate(-50%, 0); }
.sa-toast.warn { background: rgba(201, 118, 27, .96); }
