:root {
  --bg: #06142c;
  --bg-deep: #041022;
  --panel: rgba(8, 36, 78, 0.72);
  --line: #3aa7ff;
  --line-dim: rgba(58, 167, 255, 0.35);
  --glow: rgba(46, 160, 255, 0.45);
  --text: #f4f8ff;
  --muted: #9cb6d8;
  --accent: #4ec3ff;
  --danger: #ff6b7a;
  --ok: #3ee0a2;
  --sidebar-w: 200px;
  --gap: 14px;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -10%, #123c68, transparent 60%),
    radial-gradient(800px 400px at 90% 110%, #0a2a5c, transparent 50%),
    var(--bg-deep);
  overflow: hidden;
}

.hidden { display: none !important; }

.glow-panel {
  background: linear-gradient(180deg, rgba(18, 62, 118, 0.55), rgba(7, 28, 62, 0.78));
  border: 1px solid var(--line-dim);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px rgba(80, 180, 255, 0.12), 0 0 22px rgba(30, 120, 220, 0.18) inset;
}

/* Login */
.login-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    linear-gradient(180deg, rgba(4, 16, 34, 0.55), rgba(4, 16, 34, 0.82)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cpath d='M0 80h160M80 0v160' stroke='%231a4a86' stroke-width='.4'/%3E%3C/svg%3E");
}
.login-card {
  width: 420px;
  padding: 36px 34px 28px;
  text-align: center;
}
.login-card h1 { font-size: 26px; letter-spacing: 2px; margin-bottom: 8px; }
.login-card p { color: var(--muted); margin-bottom: 28px; }
.login-card label {
  display: block; text-align: left; font-size: 13px; color: var(--muted); margin: 12px 0 6px;
}
.login-card input, .field input, .field select, textarea {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line-dim);
  background: rgba(4, 18, 42, 0.85);
  color: var(--text);
  border-radius: 8px;
  padding: 0 12px;
  outline: none;
}
textarea { height: 88px; padding: 10px 12px; resize: vertical; }
.login-card input:focus, .field input:focus, .field select:focus { border-color: var(--accent); }
.btn {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #1c6fd0, #0d4ea3);
  color: #fff;
  border-radius: 8px;
  height: 38px;
  padding: 0 14px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn-ghost {
  background: transparent;
  color: var(--text);
}
.btn-danger { background: linear-gradient(180deg, #b83a4a, #8a2230); border-color: #ff8a96; }
.login-submit { width: 100%; margin-top: 22px; height: 42px; font-size: 15px; }
.login-error { min-height: 22px; margin-top: 10px; color: var(--danger); font-size: 13px; }
.login-hint { margin-top: 16px; color: var(--muted); font-size: 12px; }
.quiz-entry { display: inline-block; margin-top: 14px; color: var(--accent); font-size: 14px; }

/* Shell */
.app-shell { height: 100%; display: grid; grid-template-rows: 72px 1fr; min-height: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: linear-gradient(180deg, #0a2148, #071830);
  border-bottom: 1px solid var(--line-dim);
  min-width: 0;
}
.title-banner {
  flex: 0 1 auto;
  min-width: 0;
  height: 48px;
  padding: 0 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: linear-gradient(180deg, #1a5fb8, #0d3c86);
  clip-path: polygon(16px 0, calc(100% - 16px) 0, 100% 50%, calc(100% - 16px) 100%, 16px 100%, 0 50%);
  font-size: 24px;
  letter-spacing: 2px;
  font-weight: 700;
  text-shadow: 0 0 12px rgba(120, 200, 255, 0.6);
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  flex-shrink: 0;
}
.top-actions button { background: none; border: 0; color: inherit; cursor: pointer; font-size: 14px; }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 0;
  height: 100%;
}
.sidebar {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(5, 18, 42, 0.7);
  border-right: 1px solid var(--line-dim);
  overflow: auto;
}
.nav-btn {
  height: 48px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(10, 40, 84, 0.45);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  flex-shrink: 0;
}
.nav-btn.active, .nav-btn:hover {
  background: linear-gradient(180deg, #1b6dcc, #0e4ca6);
  box-shadow: 0 0 16px var(--glow);
}
.content {
  padding: 16px 18px 20px;
  overflow: auto;
  min-width: 0;
  min-height: 0;
}
.page {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.section-title {
  font-size: 20px;
  letter-spacing: 1px;
  margin: 0;
  line-height: 1.3;
}
.page-note { color: var(--muted); font-size: 13px; margin: -4px 0 0; }

/* KPI */
.kpi-row {
  display: grid;
  gap: 12px;
  margin: 0;
}
.kpi-row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi-row-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  min-height: 88px;
  min-width: 0;
}
.kpi span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
  white-space: normal;
}
.kpi b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  max-width: 100%;
  height: 34px;
  padding: 0 14px;
  border-radius: 17px;
  background: #1570d2;
  box-shadow: 0 0 12px rgba(40, 150, 255, 0.45);
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Overview dashboard */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
  align-items: stretch;
}
.chart-panel,
.board-col {
  padding: 14px 16px;
  min-width: 0;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chart-panel h3,
.board-col h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  margin: 0;
  line-height: 1.3;
  flex-shrink: 0;
}
.chart-panel canvas,
#weakChart {
  display: block;
  width: 100% !important;
  height: 220px !important;
  max-width: 100%;
  flex: 0 0 auto;
}
.rank-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  max-height: 240px;
  padding-right: 2px;
}
.rank-item {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line-dim);
  border-radius: 10px;
  background: rgba(4, 20, 48, 0.55);
}
.rank-item b {
  width: 36px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #1570d2;
  font-size: 13px;
}
.rank-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  line-height: 1.3;
  word-break: break-word;
}
.rank-item small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  white-space: normal;
}
.weak-mini { display: none; }
.weak-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px solid rgba(58,167,255,0.12);
  font-size: 13px;
  line-height: 1.4;
}
.weak-row span {
  flex: 1;
  min-width: 0;
  white-space: normal;
  word-break: break-word;
}
.weak-row b { color: #ff8a6b; flex-shrink: 0; }

/* Filters */
.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 14px 16px !important;
  align-items: end;
}
.filter-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
}
.filter-grid input,
.filter-grid select {
  width: 100%;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line-dim);
  background: #071830;
  color: var(--text);
  padding: 0 10px;
  min-width: 0;
}
.filter-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  grid-column: 1 / -1;
  padding-top: 2px;
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin: 0;
}

/* Tables */
.table-wrap {
  padding: 8px 10px;
  overflow: auto;
  max-height: calc(100vh - 320px);
  min-height: 240px;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: auto; }
th, td {
  padding: 10px 8px;
  border-bottom: 1px solid rgba(58, 167, 255, 0.18);
  text-align: left;
  vertical-align: middle;
  line-height: 1.35;
}
th {
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: rgba(7, 28, 62, 0.96);
  z-index: 1;
}
td { white-space: nowrap; }
td.wrap,
.record-grid .v { white-space: normal; word-break: break-word; }
tr:hover td { background: rgba(20, 70, 130, 0.25); }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.4;
}
.tag-on { background: rgba(62, 224, 162, 0.18); color: var(--ok); }
.tag-off { background: rgba(255, 107, 122, 0.18); color: var(--danger); }
.tag-exam { background: rgba(247, 191, 98, 0.16); color: #ffcd85; }
.tag-practice { background: rgba(72, 186, 248, 0.16); color: var(--accent); }
.row-actions {
  white-space: nowrap;
  min-width: 220px;
}
.row-actions button {
  height: 28px;
  font-size: 12px;
  margin: 2px 4px 2px 0;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--line-dim);
  background: rgba(12, 48, 96, 0.7);
  color: var(--text);
  cursor: pointer;
}
.row-actions button:hover { border-color: var(--accent); }

/* Quiz */
.quiz-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.quiz-link { display: inline-flex; align-items: center; text-decoration: none; }
.quiz-panel { display: grid; gap: 12px; }
.quiz-panel .toolbar { align-items: end; }
.quiz-search.field { width: min(230px, 100%); margin: 0; }
.quiz-field.field { width: min(140px, 100%); margin: 0; }
.quiz-count { color: var(--muted); font-size: 13px; align-self: center; }
.quiz-question-code { display: block; color: var(--muted); margin-bottom: 4px; }
.quiz-question-prompt { min-width: 190px; }
.quiz-question-answer { min-width: 120px; }
.quiz-question-explanation { min-width: 200px; }
.quiz-question-brief {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.quiz-empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.quiz-dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  margin: auto;
  padding: 20px;
  color: var(--text);
  background-color: #0a2349;
}
.quiz-dialog::backdrop { background: rgba(2, 10, 24, 0.7); }
.quiz-dialog h3 { margin-bottom: 14px; }
.quiz-dialog textarea, .quiz-dialog select { margin-bottom: 12px; }
.quiz-dialog textarea:focus { border-color: var(--accent); }
.quiz-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 8px; }
.quiz-question-dialog { width: min(680px, calc(100% - 32px)); }
.quiz-question-dialog textarea { min-height: 108px; font: inherit; }
.quiz-question-dialog .quiz-options textarea { min-height: 50px; height: 50px; margin-bottom: 0; }
.quiz-question-metadata { margin: 0 0 12px; overflow-wrap: anywhere; }
.quiz-multiple-answers { margin: 0 0 12px; padding: 8px 12px; border: 1px solid var(--line-dim); border-radius: 8px; }
.quiz-multiple-answers legend { padding-inline: 4px; font-size: 12px; color: var(--muted); }
.quiz-choices { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.quiz-choices label { display: flex; align-items: center; font-size: 14px; }
.quiz-enabled { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.quiz-dialog button:disabled { opacity: 0.65; cursor: default; }
.exam-dialog { width: min(680px, calc(100% - 32px)); }
.exam-result-dialog { width: min(840px, calc(100% - 32px)); }
.exam-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 8px 12px; }
.exam-fields input[type="datetime-local"] { color-scheme: dark; }
.exam-counts { margin: 0 0 14px; padding: 10px; border: 1px solid var(--line-dim); border-radius: 8px; }
.exam-counts legend { padding-inline: 5px; font-size: 14px; }
.exam-counts .field { margin: 0; }
.exam-counts .quiz-count { margin: 10px 0 0; }
.exam-class-hint { margin: 0 0 14px; }
.exam-table-title { min-width: 175px; }
.exam-table-rules { min-width: 195px; }
.exam-table-actions .btn { margin: 2px; }
.exam-table-title small, .exam-cell-note { display: block; color: var(--muted); margin-top: 4px; }
.exam-confirm-text { margin: 0; color: var(--muted); line-height: 1.6; }
.exam-detail-profile { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); gap: 12px; }
.exam-detail-profile dt { margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.exam-detail-profile dd { margin: 0; overflow-wrap: anywhere; }
.exam-review-list { padding-left: 25px; }
.exam-review-list li { padding: 8px 0; border-bottom: 1px solid var(--line-dim); }
.exam-review-list p { margin: 4px 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Analysis */
.analysis-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(360px, 1.05fr);
  gap: var(--gap);
  align-items: stretch;
  min-height: 420px;
}
.analysis-grid .board-col,
.analysis-grid .detail-panel {
  min-height: 420px;
  max-height: calc(100vh - 360px);
}
.table-scroll {
  overflow: auto;
  flex: 1;
  min-height: 0;
}
.detail-panel {
  padding: 14px 16px;
  overflow: auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.detail-empty {
  color: var(--muted);
  text-align: center;
  padding: 48px 16px;
  font-size: 14px;
  line-height: 1.6;
  margin: auto 0;
}
.detail-profile {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.detail-profile .chip {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-dim);
  background: rgba(12, 48, 96, 0.45);
  min-width: 0;
}
.detail-profile .chip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}
.detail-profile .chip b {
  display: block;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
  white-space: normal;
}
.sub-title {
  margin: 12px 0 8px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
}
#growthChart {
  width: 100% !important;
  height: 160px !important;
  display: block;
  margin-bottom: 8px;
}
.record-card {
  border: 1px solid var(--line-dim);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: rgba(8, 36, 78, 0.45);
}
.record-card h4 {
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--accent);
  line-height: 1.4;
  white-space: normal;
  word-break: break-word;
}
.record-grid {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 6px 10px;
  font-size: 13px;
}
.record-grid .k { color: var(--muted); }
.record-grid .v { color: var(--text); }

#studentTable tr,
#analysisPeople tr { cursor: pointer; }
#studentTable tr.active td,
#analysisPeople tr.active td { background: rgba(30, 110, 200, 0.35); }

/* Modal */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 20px;
}
.modal {
  width: min(520px, 100%);
  padding: 20px;
  max-height: calc(100vh - 40px);
  overflow: auto;
}
.modal-wide { width: min(840px, 100%); }
.modal h3 { margin-bottom: 14px; font-size: 18px; }
.field { margin-bottom: 10px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.report-body { color: var(--text); line-height: 1.7; font-size: 14px; }
.report-body h4 { margin: 12px 0 6px; color: var(--accent); }
.report-body ul { padding-left: 18px; }
.report-body li { margin: 4px 0; word-break: break-word; }

.lab-status {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 10px;
  border: 1px solid var(--line-dim);
  white-space: nowrap;
}
.lab-status.on { color: var(--ok); border-color: var(--ok); }
.lab-status.off { color: var(--danger); border-color: var(--danger); }
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #0d3a7a;
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 8px;
  z-index: 30;
  max-width: min(360px, calc(100vw - 40px));
  line-height: 1.4;
}

@media print {
  body * { visibility: hidden; }
  #scoreModal, #scoreModal *, #reportModal, #reportModal * { visibility: visible; }
  #scoreModal, #reportModal {
    position: fixed; inset: 0; background: #fff; color: #000;
  }
  .modal-actions { display: none !important; }
}

@media (max-width: 1280px) {
  .kpi-row-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-row-4,
  .filter-grid,
  .dash-grid,
  .analysis-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .title-banner { font-size: 20px; padding: 0 28px; }
  .analysis-grid .board-col,
  .analysis-grid .detail-panel { max-height: none; min-height: 320px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: 0;
    border-bottom: 1px solid var(--line-dim);
  }
  .nav-btn { flex: 1 1 140px; height: 42px; font-size: 14px; }
  .kpi-row-5,
  .kpi-row-4,
  .filter-grid,
  .dash-grid,
  .analysis-grid,
  .detail-profile { grid-template-columns: 1fr; }
  .title-banner { font-size: 16px; padding: 0 22px; height: 42px; }
}
