:root {
  --bg: #f5f7fb;
  --panel: #fff;
  --line: #dce3ee;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-soft: #e8f0ff;
  --danger: #dc2626;
  --ok: #059669;
}

* { box-sizing: border-box; }
.hidden { display: none !important; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "Microsoft YaHei", Arial, sans-serif;
}
button, input, textarea, select { font: inherit; }
button {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: white;
  border-radius: 4px;
  min-height: 34px;
  padding: 0 14px;
  cursor: pointer;
}
button.ghost {
  background: white;
  color: var(--primary);
}
button:disabled {
  cursor: not-allowed;
  opacity: .55;
}
.shell { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #f5f7fb 0%, #eef5ff 52%, #f8fafc 100%);
}
.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, .14);
}
.login-panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
}
.login-panel label {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}
.login-panel input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
}
.login-panel button {
  width: 100%;
  margin-top: 20px;
  min-height: 42px;
}
.login-error {
  min-height: 22px;
  margin-top: 12px;
  color: var(--danger);
}
.nav {
  background: #263445;
  color: #d6dde8;
  padding: 18px 12px;
}
.brand {
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  padding: 8px 10px 18px;
}
.nav-item {
  width: 100%;
  height: 42px;
  margin: 2px 0;
  text-align: left;
  background: transparent;
  border: 0;
  color: #d6dde8;
}
.nav-item.active,
.nav-item:hover { background: #1f6feb; color: #fff; }
.main { padding: 24px 32px; }
.view { display: none; }
.view.active { display: block; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}
.section-head h2 {
  margin: 0 0 6px;
  font-size: 24px;
}
.section-head p {
  margin: 0;
}
.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.toolbar {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 16px;
}
.paper-toolbar {
  align-items: flex-end;
  flex-wrap: wrap;
}
.filter-box,
.search-box {
  display: grid;
  gap: 6px;
}
.filter-box {
  width: min(220px, 100%);
}
.search-box {
  width: min(360px, 100%);
}
.filter-box span,
.search-box span {
  color: var(--muted);
  font-size: 14px;
}
.filter-box select,
.search-box input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
  background: #fff;
}
.paper-groups {
  display: grid;
  gap: 18px;
}
.paper-group h3 {
  margin: 0 0 10px;
  font-size: 18px;
}
.paper-card-list {
  display: grid;
  gap: 10px;
}
.paper-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.paper-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.paper-card h4 {
  margin: 0;
  font-size: 17px;
}
.paper-card-meta {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.6;
}
.paper-card-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.access-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 13px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--muted);
}
.access-badge.opened {
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: var(--ok);
}
.access-badge.unopened {
  border-color: #e5e7eb;
  background: #f9fafb;
  color: var(--muted);
}
.access-badge.expired {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--danger);
}
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
}
.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
}
.data-table th { color: var(--muted); font-weight: 600; background: #fafbfe; }
.data-table td:last-child { text-align: right; }
.exam-head { text-align: center; margin-bottom: 20px; }
.exam-head h1 { margin: 4px 0 12px; font-size: 28px; }
.meta { display: flex; justify-content: center; gap: 40px; color: var(--muted); }
.exam-layout { display: grid; grid-template-columns: 170px 1fr; gap: 18px; }
.exam-layout.no-nav { grid-template-columns: 1fr; }
.exam-layout.no-nav .question-nav { display: none; }
#exam-view,
.question-panel,
.question-card {
  overflow-anchor: none;
}
.question-nav {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 12px;
}
.qnav-btn {
  width: 42px;
  height: 34px;
  margin: 5px;
  padding: 0;
  background: white;
  color: var(--primary);
}
.qnav-btn.done { background: var(--ok); color: white; border-color: var(--ok); }
.qnav-btn.current { background: var(--primary); color: white; }
.qnav-btn.wrong { background: var(--danger); color: white; border-color: var(--danger); }
.question-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 22px;
}
.question-top { display: flex; justify-content: space-between; align-items: center; min-height: 36px; }
.question-top h3 { margin: 0 0 6px; }
.question-progress { color: var(--primary); font-weight: 700; }
.timer { color: var(--danger); font-weight: 700; min-width: 180px; text-align: right; overflow-anchor: none; }
.question-card {
  min-height: 280px;
  line-height: 1.9;
  padding: 20px 36px;
  border-top: 1px solid var(--line);
}
.question-title { font-size: 16px; margin-bottom: 14px; }
.question-title img,
.wrong-item img {
  max-width: 100%;
  height: auto;
}
.option {
  display: block;
  margin: 8px 0;
  cursor: pointer;
}
.option input { margin-right: 10px; }
.muted { color: var(--muted); }
.fill-list { display: grid; gap: 12px; max-width: 620px; }
.fill-item {
  display: grid;
  grid-template-columns: 76px 1fr;
  align-items: center;
  gap: 10px;
}
.fill-item input,
textarea[name="answer"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
  color: var(--text);
  background: #fff;
}
textarea[name="answer"] { resize: vertical; line-height: 1.7; }
.actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.wrong-list { display: grid; gap: 14px; }
.wrong-item {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px;
}
.result-ok { color: var(--ok); }
.result-bad { color: var(--danger); }
.profile-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.5fr);
  gap: 16px;
}
.profile-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 18px;
}
.profile-panel h3 {
  margin: 0 0 14px;
}
.paper-access-list {
  display: grid;
  gap: 6px;
  margin: 10px 0 14px;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat-grid div {
  border: 1px solid var(--line);
  background: #fafbfe;
  padding: 14px;
}
.stat-grid strong {
  display: block;
  font-size: 24px;
  margin-bottom: 4px;
}
.stat-grid span {
  color: var(--muted);
}
.admin-panel {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 18px;
}
.admin-panel h3 {
  margin: 0 0 14px;
}
.profile-form,
.admin-form {
  display: grid;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}
.profile-form {
  grid-template-columns: 1fr 1fr auto;
}
.admin-form {
  grid-template-columns: repeat(5, minmax(130px, 1fr)) auto;
}
.profile-form label,
.admin-form label {
  display: grid;
  gap: 6px;
}
.profile-form input,
.admin-form input:not([type="checkbox"]) {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 9px;
}
.admin-form select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 9px;
  background: #fff;
}
.check-line {
  display: flex !important;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}
.form-message {
  grid-column: 1 / -1;
  min-height: 20px;
}
.form-message.error { color: var(--danger); }
.form-message.ok { color: var(--ok); }
.admin-user-table {
  margin-top: 8px;
}
.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.row-actions .mini-select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  padding: 4px 8px;
  max-width: 180px;
}
.static-option {
  cursor: default;
}
.static-option.picked {
  color: var(--primary);
  font-weight: 700;
}
.answer-line,
.analysis {
  margin-top: 12px;
  line-height: 1.8;
}
.dialog.hidden { display: none; }
.dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, .46);
}
.dialog-panel {
  width: min(520px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 18px 52px rgba(15, 23, 42, .24);
}
.dialog-panel h2 {
  margin: 0 0 10px;
  font-size: 22px;
}
.mode-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}
.mode-actions button {
  height: auto;
  min-height: 72px;
  white-space: normal;
}

@media print {
  body { background: #fff; }
  .nav, .tabs, .toolbar, .question-nav, .actions, .exam-head .meta { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .view { display: none !important; }
  #exam-view { display: block !important; }
  .exam-layout { display: block; }
  .question-panel { border: 0; padding: 0; }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .nav {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 8px;
  }
  .brand { display: none; }
  .nav-item { min-width: 92px; text-align: center; }
  .main { padding: 16px; }
  .exam-layout { grid-template-columns: 1fr; }
  .section-head,
  .paper-card {
    grid-template-columns: 1fr;
  }
  .section-head {
    flex-direction: column;
  }
  .paper-card-actions {
    justify-content: stretch;
  }
  .paper-card-actions button {
    flex: 1;
  }
  .tabs { overflow-x: auto; }
  .tab { min-width: max-content; }
  .toolbar,
  .meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }
  .data-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
  .question-panel { padding: 14px; }
  .question-card { padding: 16px 0; }
  .question-top {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
  .actions { justify-content: stretch; }
  .actions button { flex: 1; }
  .mode-actions { grid-template-columns: 1fr; }
  .profile-grid,
  .stat-grid,
  .profile-form,
  .admin-form { grid-template-columns: 1fr; }
}
