:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --primary: #2f6bff;
  --primary-dark: #2557d6;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --success: #16a34a;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --shadow: 0 2px 12px rgba(30, 50, 90, .08);
}

* { box-sizing: border-box; }

/* hidden 属性优先于组件自身的 display 声明（如 .modal-overlay/.score-warn/.tab-panel） */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

/* ---------- SVG 图标（Lucide 风格，currentColor 跟随主题变量） ---------- */
.ic { display: inline-flex; align-items: center; color: inherit; flex: none; }
.ic svg { width: 18px; height: 18px; display: block; }
.ic-lg svg { width: 34px; height: 34px; }

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(120deg, #2f6bff, #5b8bff);
  color: #fff;
  padding: 16px 28px 0;
  box-shadow: var(--shadow);
}
.app-header h1 { margin: 0 0 12px; font-size: 22px; display: flex; align-items: center; gap: 10px; }
.app-header h1 .ic svg { width: 24px; height: 24px; }
.header-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; flex-wrap: wrap; }
.header-top h1 { margin: 0; }
.fs-btn {
  background: rgba(255,255,255,.16);
  color: #fff;
  border: 1px solid rgba(255,255,255,.35);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .2s;
  white-space: nowrap;
}
.fs-btn .ic svg { width: 16px; height: 16px; }
.fs-btn:hover { background: rgba(255,255,255,.32); }
.fs-btn.active { background: #fff; color: var(--primary-dark); border-color: #fff; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab-btn {
  background: rgba(255,255,255,.15);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 15px;
  display: inline-flex; align-items: center; gap: 7px;
  transition: background .2s;
}
.tab-btn .ic svg { width: 16px; height: 16px; }
.tab-btn:hover { background: rgba(255,255,255,.3); }
.tab-btn.active { background: var(--bg); color: var(--primary-dark); font-weight: 600; }
.status-bar { padding: 8px 0 0; }
#studentCount { font-size: 13px; opacity: .9; display: inline-flex; align-items: center; gap: 6px; }
#studentCount .ic svg { width: 15px; height: 15px; }

main { padding: 22px 28px 60px; max-width: 1180px; margin: 0 auto; }
/* 全屏时放宽内容区，利用多出的屏幕空间 */
:fullscreen main, :-webkit-full-screen main { max-width: 1680px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .25s; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to {opacity:1; transform:none;} }

/* ---------- Card ---------- */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-title h2 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 12px; line-height: 1.6; }

/* ---------- Buttons ---------- */
.btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .2s;
}
.btn .ic svg { width: 16px; height: 16px; }
.btn:hover { background: var(--primary-dark); }
.btn.ghost { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn.ghost:hover { background: #eef3ff; }
.btn.primary { background: var(--success); }
.btn.primary:hover { background: #128a3f; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- File drop ---------- */
.file-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; border: 2px dashed var(--primary); border-radius: 12px;
  padding: 34px; color: var(--primary); cursor: pointer; background: #f7faff;
  transition: background .2s, border-color .2s; text-align: center;
}
.file-drop:hover, .file-drop.dragover { background: #eaf1ff; border-color: var(--primary-dark); }
.file-name { font-size: 13px; color: var(--muted); }

/* ---------- 历史名单 ---------- */
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex; align-items: stretch; gap: 8px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
  transition: border-color .2s, box-shadow .2s;
}
.history-item:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(47, 107, 255, .12); }
.hi-main {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px;
  background: none; border: none; cursor: pointer; padding: 10px 12px;
  font: inherit; color: inherit; text-align: left; border-radius: 10px;
}
.hi-main:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.hi-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hi-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.hi-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--muted); background: #f4f6fb; border-radius: 999px; padding: 1px 8px;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hi-tag .ic svg { width: 13px; height: 13px; }
.hi-actions { display: flex; align-items: center; gap: 6px; padding-right: 10px; }
.hi-btn {
  border: 1px solid var(--primary); background: #fff; color: var(--primary);
  border-radius: 6px; padding: 4px 10px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.hi-btn:hover { background: #eef3ff; }
.hi-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.hi-btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.hi-del { border: none; background: none; color: var(--muted); cursor: pointer; padding: 4px; display: inline-flex; border-radius: 6px; }
.hi-del .ic svg { width: 16px; height: 16px; }
.hi-del:hover { color: var(--danger); background: var(--danger-bg); }

/* ---------- Mapping ---------- */
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-bottom: 14px; }
.map-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: #fbfcff; }
.map-item .col-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; word-break: break-all; }
.map-item .sample { color: var(--muted); font-size: 12px; margin-bottom: 6px; max-height: 18px; overflow: hidden; }
.map-item select { width: 100%; padding: 5px; border-radius: 6px; border: 1px solid var(--border); }
.preview-wrap { overflow-x: auto; max-height: 260px; border: 1px solid var(--border); border-radius: 8px; }
.preview-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.preview-table th, .preview-table td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; white-space: nowrap; }
.preview-table th { background: #eef3ff; position: sticky; top: 0; }

/* ---------- Checks (科目过滤 / 分组字段) ---------- */
.checks { display: flex; flex-wrap: wrap; gap: 10px; }
.checks label { display: flex; align-items: center; gap: 5px; background: #f1f5ff; padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 14px; border: 1px solid transparent; }
.checks label:has(input:checked) { border-color: var(--primary); background: #e3edff; }
.checks label.disabled { opacity: .45; cursor: not-allowed; }
.filter-label { color: var(--muted); margin-right: 8px; }

/* ---------- 分值区间设置 ---------- */
.cfg-wrap { margin-top: 14px; border-top: 1px dashed var(--border); padding-top: 12px; }
.cfg-title { font-size: 13px; color: var(--muted); margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.cfg-rows { display: flex; flex-wrap: wrap; gap: 10px; }
.cfg-row { display: flex; align-items: center; gap: 6px; background: #f8faff; border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px; font-size: 13px; color: var(--muted); }
.cfg-row .cfg-sub { font-weight: 600; color: var(--text); }
.cfg-row input { width: 58px; text-align: center; padding: 4px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; color: var(--text); }
.cfg-row input:focus { outline: none; border-color: var(--primary); }

/* ---------- 分组与筛选 ---------- */
.group-fields { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.filter-selects { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; }
.filter-sel { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.filter-sel .fs-label { color: var(--muted); }
.filter-sel select { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--primary); color: var(--primary-dark); background: #f7faff; font-size: 14px; outline: none; max-width: 240px; }
.filter-status {
  text-align: center; margin-bottom: 14px; background: #eef3ff; border: 1px solid #d6e2ff;
  color: var(--primary-dark); padding: 9px 14px; border-radius: 10px; font-size: 14px;
  display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
}
.filter-status .ic svg { width: 16px; height: 16px; }

/* ---------- 录入模式切换 ---------- */
.mode-switch {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: 10px; padding: 10px 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.mode-switch .ms-label { font-weight: 600; color: var(--text); font-size: 14px; }
.mode-switch .ms-opt {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 6px 14px; border-radius: 20px; font-size: 14px;
  border: 1px solid var(--border); background: #f8faff; color: var(--muted); transition: all .15s;
}
.mode-switch .ms-opt .ic svg { width: 16px; height: 16px; }
.mode-switch .ms-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.mode-switch .ms-opt:has(input:checked) {
  border-color: var(--primary); background: var(--primary); color: #fff;
}
.mode-switch .ms-hint { font-size: 13px; color: var(--muted); flex: 1 1 100%; }
@media (min-width: 860px) { .mode-switch .ms-hint { flex: 0 1 auto; } }

/* ---------- Search ---------- */
.entry-main { position: relative; }
.search-box { position: relative; max-width: 520px; margin: 0 auto 18px; }
.search-row { display: flex; flex-direction: column; gap: 4px; }
.search-wrap { position: relative; }
.search-ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-input {
  width: 100%; padding: 14px 18px 14px 44px; font-size: 18px;
  border: 2px solid var(--primary); border-radius: 12px; outline: none;
}
.search-input:focus { box-shadow: 0 0 0 3px rgba(47,107,255,.15); }
.kbd-tip { font-size: 12px; color: var(--muted); text-align: center; display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.kbd-tip .ic svg { width: 14px; height: 14px; }
.candidates {
  position: absolute; left: 0; right: 0; top: 100%; margin: 4px 0 0; padding: 0;
  list-style: none; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); max-height: 300px; overflow-y: auto; z-index: 30;
}
.candidates li { padding: 10px 16px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.candidates li .c-name { font-weight: 600; }
.candidates li .c-meta { color: var(--muted); font-size: 13px; }
.candidates li.active, .candidates li:hover { background: #eaf1ff; }
.candidates li mark { background: transparent; color: var(--primary); font-weight: 700; }
.candidates .empty { color: var(--muted); justify-content: center; cursor: default; }

/* ---------- Current student ---------- */
.current-student { text-align: center; margin-bottom: 14px; min-height: 30px; }
.current-student .placeholder { color: var(--muted); }
.cs-card { display: inline-flex; gap: 18px; align-items: center; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 10px 20px; box-shadow: var(--shadow); flex-wrap: wrap; }
.cs-card .cs-name { font-size: 22px; font-weight: 700; color: var(--primary-dark); }
.cs-card .cs-tag { font-size: 13px; color: var(--muted); }

/* ---------- Score form ---------- */
.score-form { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; margin: 8px 0 20px; }
.score-field { display: flex; flex-direction: column; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; min-width: 140px; }
.score-field label { font-size: 14px; color: var(--muted); }
.score-field input {
  width: 110px; font-size: 26px; text-align: center; padding: 8px;
  border: 2px solid var(--border); border-radius: 10px; outline: none;
}
.score-field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,107,255,.15); }
.score-field input.invalid { border-color: var(--danger); background: var(--danger-bg); box-shadow: 0 0 0 3px rgba(220,38,38,.12); }
.score-warn { display: flex; flex-direction: column; align-items: center; gap: 5px; color: var(--danger); font-size: 12px; min-height: 0; }
.score-warn .w-line { display: flex; align-items: center; gap: 4px; }
.score-warn .ic svg { width: 13px; height: 13px; }
.score-warn button {
  background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger);
  border-radius: 6px; padding: 2px 10px; font-size: 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
}
.score-warn button:hover { background: #fde2e2; }

.entry-nav { display: flex; align-items: center; justify-content: center; gap: 20px; margin-top: 10px; flex-wrap: wrap; }
.progress { color: var(--muted); font-size: 14px; display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.progress .pending, .progress .done {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 999px; padding: 2px 10px; font-size: 13px;
}
.progress .pending { color: #b45309; background: #fff7ed; border: 1px solid #fed7aa; }
.progress .done { color: var(--success); background: #f0fdf4; border: 1px solid #bbf7d0; }
.progress .ic svg { width: 14px; height: 14px; }

/* ---------- Data table ---------- */
.table-wrap { overflow-x: auto; }
.data-table { border-collapse: collapse; width: 100%; font-size: 14px; }
.data-table th, .data-table td { border: 1px solid var(--border); padding: 7px 10px; text-align: center; white-space: nowrap; }
.data-table th { background: #eef3ff; position: sticky; top: 0; }
/* 表头可直接改名（数据总览与导出同步生效） */
.th-wrap { padding: 4px 6px; min-width: 96px; }
.th-edit {
  width: 100%; min-width: 64px; text-align: center; font: inherit; font-weight: 600; color: inherit;
  background: transparent; border: 1px dashed transparent; border-radius: 6px; padding: 3px 4px; cursor: text;
}
.th-edit:hover { border-color: #b9ccff; background: #fff; }
.th-edit:focus { outline: none; border: 1px solid var(--primary); background: #fff; }
.data-table tbody tr:nth-child(even) { background: #fafbff; }
.data-table td.editable { cursor: text; }
.data-table td input { width: 70px; text-align: center; border: 1px solid var(--border); border-radius: 6px; padding: 3px; }
.data-table td input.invalid { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); }
.data-table .row-idx { color: var(--muted); }

/* ---------- Modal（Sheet 选择） ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center; z-index: 90; padding: 16px;
}
.modal { background: #fff; border-radius: 14px; padding: 20px 22px; width: min(460px, 94vw); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.modal-x { background: none; border: none; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px; }
.modal-x:hover { background: #f1f5f9; color: var(--text); }
.sheet-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 14px; max-height: 46vh; overflow-y: auto; }
.sheet-item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; cursor: pointer; transition: border-color .15s, background .15s; }
.sheet-item:hover { background: #f7faff; }
.sheet-item:has(input:checked) { border-color: var(--primary); background: #eef3ff; }
.sheet-item .s-name { font-weight: 600; }
.sheet-item .s-rows { color: var(--muted); font-size: 12px; margin-left: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- 页脚 & 赞赏（请喝一杯奶茶） ---------- */
.app-footer {
  max-width: 1180px; margin: 0 auto; padding: 0 28px 44px;
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
}
.foot-text { color: var(--muted); font-size: 13px; }
.btn.coffee { background: #fff7ed; color: #b45309; border: 1px solid #fed7aa; }
.btn.coffee:hover { background: #ffedd5; border-color: #fdba74; }
.btn.coffee .ic svg { width: 17px; height: 17px; }
.modal-coffee { width: min(380px, 94vw); }
.qr-wrap { display: flex; justify-content: center; margin: 6px 0 16px; }
.qr-wrap img { max-width: 100%; max-height: 60vh; border-radius: 10px; border: 1px solid var(--border); display: block; }
.qr-missing {
  color: var(--danger); font-size: 13px; text-align: center; line-height: 1.7;
  background: var(--danger-bg); border: 1px dashed #fecaca; border-radius: 10px; padding: 22px 14px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1f2937; color: #fff; padding: 12px 22px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: all .3s; z-index: 100; font-size: 14px;
  display: flex; align-items: center; gap: 8px; max-width: 92vw;
}
.toast .ic svg { width: 16px; height: 16px; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ---------- 响应式 ---------- */
@media (max-width: 640px) {
  .app-header { padding: 12px 14px 0; }
  main { padding: 14px 12px 50px; }
  .card { padding: 14px; }
  .search-input { font-size: 16px; padding: 12px 14px 12px 40px; }
  .score-field { min-width: 46%; }
  .score-field input { width: 100%; }
  .cfg-row { width: 100%; justify-content: space-between; }
}
