/* ============================================================
   学员错题管理系统 · 样式
   不用框架：一套变量 + 手写组件，比引 Tailwind 好维护。
   ============================================================ */

:root {
  --blue: #2563eb;
  --blue-d: #1d4ed8;
  --bg: #f5f6f8;
  --panel: #fff;
  --line: #e5e7eb;
  --line-2: #d1d5db;
  --txt: #111827;
  --txt-2: #4b5563;
  --txt-3: #9ca3af;
  --ok: #059669;
  --warn: #d97706;
  --err: #dc2626;
  --r: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 8px 24px rgb(16 24 40 / 6%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font: 14px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }
.hidden { display: none !important; }

/* ---------------------------- 启动 / 登录 ---------------------------- */

.boot {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--txt-3);
}

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, #dbeafe 0%, transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 26px;
}

.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card .sub { margin: 0 0 20px; color: var(--txt-2); font-size: 13px; }

.tabs { display: flex; gap: 6px; margin-bottom: 18px; background: #f3f4f6; border-radius: 10px; padding: 4px; }
.tabs button {
  flex: 1; padding: 7px 0; border: 0; border-radius: 7px; background: transparent;
  color: var(--txt-2); cursor: pointer; font-weight: 500;
}
.tabs button.on { background: #fff; color: var(--txt); box-shadow: 0 1px 2px rgb(16 24 40 / 8%); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--txt-2); margin-bottom: 6px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="file"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 12%);
}
textarea { min-height: 78px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border: 1px solid var(--line-2); border-radius: 8px;
  background: #fff; color: var(--txt); cursor: pointer; font-weight: 500;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-d); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--txt-2); }
.btn.ghost:hover { background: #f3f4f6; }
.btn.danger { color: var(--err); border-color: #fecaca; background: #fff; }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .55; pointer-events: none; }

.err-line { color: var(--err); font-size: 13px; min-height: 20px; margin-top: 6px; }

/* ---------------------------- 骨架 ---------------------------- */

.app { display: grid; grid-template-columns: 232px 1fr; height: 100%; }

.side {
  background: #0f172a;
  color: #cbd5e1;
  display: flex; flex-direction: column;
  padding: 18px 12px;
  overflow: hidden;
}
.brand { padding: 4px 10px 18px; }
.brand b { display: block; color: #fff; font-size: 15px; letter-spacing: .2px; }
.brand span { display: block; margin-top: 3px; font-size: 11px; color: #64748b; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px;
  color: #cbd5e1; font-size: 13.5px; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav a i { width: 16px; text-align: center; font-style: normal; opacity: .75; font-size: 13px; }
.nav a:hover { background: #1e293b; color: #fff; }
.nav a.on { background: var(--blue); color: #fff; }
.nav a.on i { opacity: 1; }

.side-foot {
  margin-top: auto; padding: 12px 10px 4px;
  font-size: 11.5px; color: #64748b; line-height: 1.5;
  border-top: 1px solid #1e293b;
}

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 58px; flex: 0 0 58px;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar h2 { margin: 0; font-size: 16px; font-weight: 600; }
.spacer { flex: 1; }
.cls-pick select { min-width: 170px; padding: 7px 10px; }
.acct { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: #dbeafe; color: var(--blue-d); font-size: 12px; font-weight: 600;
}
.acct .mail { font-size: 12.5px; color: var(--txt-2); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.view { flex: 1; overflow: auto; padding: 20px; }

/* ---------------------------- 通用块 ---------------------------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px 18px;
}
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card-head .spacer { flex: 1; }

.empty {
  padding: 40px 16px; text-align: center; color: var(--txt-3); font-size: 13.5px;
}

.grid-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px 16px;
}
.stat b { display: block; font-size: 24px; font-weight: 650; letter-spacing: -.5px; }
.stat span { font-size: 12.5px; color: var(--txt-2); }

.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px; border-bottom: 1px solid #f1f2f4;
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 500; }
.row .s { font-size: 12px; color: var(--txt-3); }
.row .acts { display: flex; gap: 6px; opacity: .55; transition: opacity .15s; }
.row:hover .acts { opacity: 1; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; background: #eff6ff; color: var(--blue-d); border: 1px solid #dbeafe;
}
.tag.gray { background: #f3f4f6; color: var(--txt-2); border-color: var(--line); }
.tag.ok { background: #ecfdf5; color: var(--ok); border-color: #d1fae5; }
.tag.warn { background: #fffbeb; color: var(--warn); border-color: #fef3c7; }

/* ---------------------------- 表格 ---------------------------- */

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.tbl th { font-weight: 500; color: var(--txt-2); font-size: 12px; background: #fafbfc; }

/* ---------------------------- 错题网格 ---------------------------- */

.wgrid { overflow: auto; border: 1px solid var(--line); border-radius: var(--r); background: #fff; }
.wgrid table { border-collapse: separate; border-spacing: 0; font-size: 13px; }
.wgrid th, .wgrid td { border-right: 1px solid #f1f2f4; border-bottom: 1px solid #f1f2f4; }
.wgrid thead th {
  position: sticky; top: 0; z-index: 2;
  background: #fafbfc; font-weight: 500; font-size: 12px; color: var(--txt-2);
  padding: 8px 10px; white-space: nowrap;
}
.wgrid tbody th {
  position: sticky; left: 0; z-index: 1;
  background: #fff; text-align: left; font-weight: 500;
  padding: 8px 12px; white-space: nowrap; min-width: 110px;
}
.wgrid td { padding: 0; text-align: center; }
.wcell {
  width: 40px; height: 34px; border: 0; background: transparent;
  cursor: pointer; display: grid; place-items: center; color: transparent;
  transition: background .12s;
}
.wcell:hover { background: #f3f4f6; }
.wcell.on { background: #fef2f2; color: var(--err); font-weight: 700; }
.wcell.on::after { content: "✕"; }
.wgrid thead th.warn-head { background: #fef2f2; color: var(--err); }

/* ---------------------------- 题目缩略图 ---------------------------- */

.qgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.qcard { border: 1px solid var(--line); border-radius: var(--r); background: #fff; overflow: hidden; }
.qcard .hd {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-bottom: 1px solid var(--line); background: #fafbfc; font-size: 12.5px;
}
.qcard .hd b { color: var(--blue-d); }
.qcard img { display: block; width: 100%; height: auto; background: #fff; }

/* ---------------------------- 弹窗 ---------------------------- */

.modal-mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgb(15 23 42 / 45%);
  display: grid; place-items: center; padding: 20px;
  animation: fade .12s ease-out;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.modal {
  width: 100%; max-width: 440px;
  background: #fff; border-radius: 14px; box-shadow: 0 20px 50px rgb(15 23 42 / 25%);
  max-height: 88vh; display: flex; flex-direction: column;
}
.modal.wide { max-width: 720px; }
.modal-hd { padding: 18px 20px 0; font-weight: 600; font-size: 15px; }
.modal-body { padding: 14px 20px; overflow: auto; }
.modal-ft { padding: 0 20px 18px; display: flex; gap: 8px; justify-content: flex-end; }

/* ---------------------------- 进度 / toast ---------------------------- */

.progress { height: 6px; background: #eef1f5; border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--blue); transition: width .2s; }
.progress-txt { font-size: 12.5px; color: var(--txt-2); margin-top: 8px; min-height: 20px; }

.toast-wrap { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #111827; color: #fff; padding: 10px 14px; border-radius: 9px;
  font-size: 13px; box-shadow: 0 8px 24px rgb(15 23 42 / 25%);
  animation: slide .18s ease-out;
  max-width: 380px;
}
.toast.ok { background: #065f46; }
.toast.err { background: #991b1b; }
@keyframes slide { from { transform: translateY(8px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------------------------- 名单导入预览 ---------------------------- */

.im-preview {
  font-size: 12.5px;
  line-height: 1.65;
  border-radius: 8px;
  padding: 10px 12px;
  background: #f9fafb;
  border: 1px solid var(--line);
  color: var(--txt-2);
  word-break: break-word;
}
.im-preview.empty { color: var(--txt-3); }
.im-preview.good { background: #ecfdf5; border-color: #d1fae5; color: #065f46; }
.im-preview.bad { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.im-preview .s { color: inherit; opacity: .75; }

/* ---------------------------- 环境自检横幅 ---------------------------- */

.setup { padding: 12px 20px 0; }
.setup-in {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 14px 16px;
}
.setup-ic {
  flex: 0 0 auto;
  width: 24px; height: 24px; border-radius: 50%;
  background: #f59e0b; color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
}
.setup-tx { flex: 1; min-width: 0; }
.setup-tx b { font-size: 14px; }
.setup-tx p { margin: 4px 0 0; font-size: 13px; color: var(--txt-2); line-height: 1.6; }
.setup-tx ol { margin: 8px 0 0; padding-left: 20px; font-size: 13px; color: var(--txt-2); line-height: 1.7; }

/* ---------------------------- 手动框选 ---------------------------- */

.crop-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.crop-info { font-size: 12.5px; color: var(--txt-2); min-width: 78px; text-align: center; }
.crop-qno { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--txt-2); }
.crop-qno input { width: 72px; padding: 5px 8px; }

.crop-stage {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
}
.crop-stage canvas { display: block; width: 100%; height: auto; }

.crop-sel {
  position: absolute;
  display: none;
  border: 2px solid var(--blue);
  background: rgb(37 99 235 / 12%);
  pointer-events: none;
  border-radius: 2px;
}

.crop-hint { margin: 10px 0 0; font-size: 12.5px; color: var(--txt-3); }

/* ---------------------------- 打印（错题本） ---------------------------- */

@media print {
  .side, .topbar, .toast-wrap, .modal-mask { display: none !important; }
  .app { display: block; }
  .view { overflow: visible; padding: 0; }
  body { background: #fff; }

  /* ★ 从「预览」弹窗里打印时，要打的是弹窗里的错题本，不是背后那个列表页。
     之前把 .modal-mask 一并隐藏了，结果打印出来是列表 —— 这里翻过来：
     藏掉整个应用，只把弹窗摊平成正常文档流。 */
  body.printing-book .app { display: none !important; }
  body.printing-book .side,
  body.printing-book .topbar,
  body.printing-book .toast-wrap { display: none !important; }

  body.printing-book .modal-mask {
    display: block !important;
    position: static;
    inset: auto;
    background: none;
    padding: 0;
    animation: none;
  }
  body.printing-book .modal {
    max-width: none;
    width: auto;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
    display: block;
  }
  body.printing-book .modal-hd,
  body.printing-book .modal-ft { display: none !important; }
  body.printing-book .modal-body { overflow: visible; padding: 0; }

  /* 每题一块，别被切到两页上 */
  #bookRoot > div { break-inside: avoid; page-break-inside: avoid; }
  #bookRoot img { max-width: 100%; }
}
