/* ============ 基础 ============ */
* { box-sizing: border-box; }
/* hidden 属性要能压住 .badge 等元素上的 display 声明 */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
:root {
  --ink: #1b2430;
  --muted: #66748a;
  --line: #dbe3ee;
  --bg: #f5f7fb;
  --card: #ffffff;
  --brand: #123a6b;
  --brand-2: #1e5aa0;
  --brand-soft: #eef3fa;
  --ok: #16794a;
  --ok-soft: #e8f6ee;
  --warn: #a9531a;
  --warn-soft: #fdf1e6;
  --danger: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 35, 60, .04), 0 8px 24px rgba(20, 35, 60, .06);
}
body {
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: .2px; }

/* ============ 顶栏 ============ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 900px; margin: 0 auto; padding: 12px 18px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 15px; color: var(--brand); }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); letter-spacing: .4px; }
.topbar .spacer { flex: 1; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; padding: 3px 10px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ============ 布局 ============ */
.wrap { max-width: 900px; margin: 0 auto; padding: 22px 18px 90px; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px; margin-bottom: 18px;
}
.card.narrow { max-width: 460px; margin: 8vh auto; }
.card h2 { font-size: 17px; margin-bottom: 6px; }
.card .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.section-idx {
  width: 26px; height: 26px; flex: none; border-radius: 8px;
  background: var(--brand); color: #fff; font-size: 13px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.desc { color: var(--muted); font-size: 13.5px; margin: -4px 0 14px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }

/* ============ 表单 ============ */
label.field { display: block; margin-bottom: 16px; }
label.field > span.lbl { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.qtext { color: var(--ink); font-size: 14.5px; margin: 0 0 10px; }
.qtext b { color: var(--brand); }
input[type="text"], input[type="password"], textarea, select {
  width: 100%; font: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus, input[type="password"]:focus, textarea:focus, select:focus {
  border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(30, 90, 160, .12);
}
textarea { resize: vertical; min-height: 72px; line-height: 1.7; }
input::placeholder, textarea::placeholder { color: #9aa8bb; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.counter { font-size: 12px; color: var(--muted); text-align: right; margin-top: 3px; }

.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

/* ============ 表格 ============ */
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 9px 8px; text-align: left; vertical-align: middle; }
table.grid thead th {
  background: var(--brand-soft); color: var(--brand);
  font-size: 12.5px; font-weight: 650; border-bottom: 1px solid #cddcee;
}
table.grid thead th:first-child { border-top-left-radius: 8px; }
table.grid thead th:last-child { border-top-right-radius: 8px; }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid td.rowhead { font-weight: 600; font-size: 13.5px; width: 26%; color: #34435a; }
table.grid td input[type="text"] { padding: 6px 9px; font-size: 13.5px; }
table.grid td input[readonly], table.grid td textarea[readonly] { background: #f4f7fb; color: #4c5a70; }
table.grid td textarea { padding: 6px 9px; font-size: 13.5px; min-height: 52px; resize: vertical; }
input[readonly]:not([type="radio"]) { background: #f4f7fb; color: #4c5a70; }
table.grid tr:hover td { background: #fbfcfe; }

/* ============ 单选卡片 ============ */
.choice { display: grid; gap: 10px; }
.choice label {
  display: flex; gap: 10px; align-items: flex-start;
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.choice label:hover { border-color: #b9cbe2; background: #fbfdff; }
.choice input[type="radio"] { margin-top: 3px; accent-color: var(--brand); }
.choice input[type="radio"]:checked + div { font-weight: 600; }
.choice label:has(input:checked) { border-color: var(--brand-2); background: var(--brand-soft); }

/* ============ 附件 ============ */
.dropzone {
  border: 1.5px dashed #b9cbe2; border-radius: 10px;
  padding: 18px; text-align: center; color: var(--muted); font-size: 13.5px;
  background: #fbfdff; cursor: pointer; transition: .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--brand-2); background: var(--brand-soft); color: var(--brand); }
.filelist { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.filelist li {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; font-size: 13.5px;
  background: #fff;
}
.filelist .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filelist .fsize { color: var(--muted); font-size: 12px; }
.thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; border: 1px solid var(--line); background: #f0f4f9; }

/* ============ 按钮 ============ */
.btn {
  font: inherit; font-size: 14px; font-weight: 600;
  border-radius: 9px; padding: 9px 18px; border: 1px solid transparent;
  cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: #b9cbe2; background: #fbfdff; }
.btn.danger { background: #fff; border-color: #eccac7; color: var(--danger); }
.btn.danger:hover { background: #fdf3f2; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 5px 12px; font-size: 13px; border-radius: 7px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.footer-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  background: rgba(255,255,255,.95); border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.footer-inner {
  max-width: 900px; margin: 0 auto; padding: 10px 18px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.footer-inner .spacer { flex: 1; }
.save-state { font-size: 12.5px; color: var(--muted); }

/* ============ 提示 ============ */
.toast {
  position: fixed; left: 50%; bottom: 78px; transform: translateX(-50%) translateY(12px);
  background: #1f2a3a; color: #fff; font-size: 13.5px; padding: 9px 16px; border-radius: 9px;
  opacity: 0; pointer-events: none; transition: .22s; z-index: 60; max-width: 86vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #8d2a24; }

.notice { border-radius: 10px; padding: 12px 14px; font-size: 13.5px; margin-bottom: 16px; }
.notice.info { background: var(--brand-soft); color: var(--brand); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice ul { margin: 6px 0 0; padding-left: 20px; }

/* ============ 只读展示 ============ */
.ro-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.ro-table td { border-bottom: 1px solid var(--line); padding: 9px 8px; vertical-align: top; }
.ro-table td.k { width: 26%; font-weight: 600; color: #34435a; font-size: 13.5px; }
.ro-answer { white-space: pre-wrap; }
.score-pill { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--brand); }

/* ============ 空状态 ============ */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; font-size: 14px; }

/* ============ 响应式 ============ */
@media (max-width: 640px) {
  .wrap { padding: 14px 12px 96px; }
  .card { padding: 16px; border-radius: 10px; }
  .grid3 { grid-template-columns: 1fr; }
  table.grid thead { display: none; }
  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid tr {
    border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: #fff;
  }
  table.grid td { border: none; padding: 5px 2px; }
  table.grid td.rowhead { width: auto; padding-bottom: 6px; }
  table.grid td[data-label]::before {
    content: attr(data-label); display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px;
  }
  table.grid tr:hover td { background: transparent; }
  .footer-inner { padding: 8px 12px; }
}

/* ============ 后台 ============ */
body.admin { background: #eef2f8; }
body.admin .topbar-inner { max-width: none; padding: 10px 20px; }
.admin-layout {
  display: grid; grid-template-columns: 320px 1fr; gap: 0;
  height: calc(100vh - 57px);
}
.side {
  border-right: 1px solid var(--line); background: #fff;
  display: flex; flex-direction: column; min-height: 0;
}
.side-head { padding: 14px; border-bottom: 1px solid var(--line); }
.stats { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.stat {
  flex: 1; min-width: 62px; background: var(--brand-soft); border-radius: 9px;
  padding: 7px 9px; text-align: center;
}
.stat b { display: block; font-size: 17px; color: var(--brand); font-variant-numeric: tabular-nums; line-height: 1.3; }
.stat span { font-size: 11.5px; color: var(--muted); }
.filter-row { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 12.5px; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--muted); cursor: pointer;
}
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.stu-list { list-style: none; margin: 0; padding: 6px; overflow: auto; flex: 1; }
.stu-list li {
  padding: 9px 11px; border-radius: 9px; cursor: pointer; margin-bottom: 2px;
  display: flex; align-items: center; gap: 9px;
}
.stu-list li:hover { background: #f4f7fc; }
.stu-list li.active { background: var(--brand-soft); }
.stu-list .nm { font-weight: 600; font-size: 14px; }
.stu-list .meta { font-size: 12px; color: var(--muted); }
.stu-list .grow { flex: 1; min-width: 0; }
.stu-list .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: #c7d3e2; }
.stu-list .dot.submitted { background: #d99a2b; }
.stu-list .dot.graded { background: #2f9e63; }
.stu-list .dot.returned { background: #b3261e; }
.stu-list .sc { font-size: 12.5px; font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; }

.main { overflow: auto; padding: 18px; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.main > .card, .main > #detailBody { width: 100%; max-width: 1020px; }
.main > .empty { flex: 1; display: flex; align-items: center; justify-content: center; }
.main .card { box-shadow: var(--shadow); }

.detail-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.detail-head h2 { font-size: 19px; }
.detail-head .meta { color: var(--muted); font-size: 13px; margin-top: 3px; }
.detail-head .spacer { flex: 1; }

.ans-block { margin-bottom: 16px; }
.ans-block .q { font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.ans-block .a {
  background: #fbfcfe; border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 13px; white-space: pre-wrap; font-size: 14px; line-height: 1.75; min-height: 22px;
}
.ans-block .a.empty-a { color: #a3b0c2; font-style: normal; }

.grade-panel { position: static; }
.rubric-row { display: grid; grid-template-columns: 1fr 92px; gap: 10px; align-items: center; padding: 6px 0; }
.rubric-row .rl { font-size: 14px; }
.rubric-row .rl small { color: var(--muted); font-size: 12px; }
.total-line {
  display: flex; align-items: baseline; gap: 8px; margin-top: 10px; padding-top: 10px;
  border-top: 1px dashed var(--line);
}
.total-line b { font-size: 24px; color: var(--brand); font-variant-numeric: tabular-nums; }

.thumbs { display: flex; gap: 10px; flex-wrap: wrap; }
.thumbs a { display: block; }
.thumbs img {
  width: 140px; height: 100px; object-fit: contain; border-radius: 8px;
  border: 1px solid var(--line); background: #f4f7fb;
}

@media (max-width: 860px) {
  .admin-layout { grid-template-columns: 1fr; height: auto; }
  .side { border-right: none; border-bottom: 1px solid var(--line); }
  .stu-list { max-height: 42vh; }
  .main { padding: 12px; }
}
