/* CLB Toán Thầy Tùng — vở ô li, mực tím, bút đỏ chấm bài */
:root {
  --paper: #fafbfd;
  --grid: #e1e7f3;
  --surface: #ffffff;
  --text: #1f2335;
  --muted: #5c627a;
  --line: #d6dae6;
  --ink: #3c2e8f;          /* mực tím */
  --ink-soft: #ece9fb;
  --red: #c62f2b;          /* bút đỏ của thầy */
  --red-soft: #fbeceb;
  --amber: #8a5a00;
  --amber-soft: #fdf3dc;
  --green: #1d6b45;
  --green-soft: #e3f4ea;
  --radius: 10px;
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --hand: 'Patrick Hand', 'Comic Sans MS', cursive;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #15172a;
    --grid: #1f2338;
    --surface: #1c1f33;
    --text: #e6e8f2;
    --muted: #a3a8c0;
    --line: #2f3450;
    --ink: #b3a6ff;
    --ink-soft: #2a2550;
    --red: #ff7d72;
    --red-soft: #3a2026;
    --amber: #f2c46d;
    --amber-soft: #3a3020;
    --green: #7fd6a6;
    --green-soft: #1b3428;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background-color: var(--paper);
  /* lưới ô li */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  min-height: 100vh;
}
a { color: var(--ink); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.hidden { display: none !important; }

/* ---------- Điều khiển ---------- */
label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
  min-height: 44px;
}
textarea { min-height: 120px; resize: vertical; }
::placeholder { color: var(--muted); opacity: 0.6; letter-spacing: normal; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--ink-soft); }
.field { margin-bottom: 16px; }
.field .hint { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }

button, .btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 9px 16px;
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--ink); }
button:focus-visible, .btn:focus-visible, a:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
button.primary, .btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
label.btn { margin-bottom: 0; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .primary { color: #15172a; } }
button.primary:hover, .btn.primary:hover { filter: brightness(1.1); }
button.danger { color: var(--red); }
button.danger:hover { border-color: var(--red); }
button.link { border: none; background: none; padding: 4px 6px; min-height: 0; color: var(--ink); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

.notice { padding: 10px 14px; border-radius: 8px; font-size: 0.92rem; margin-bottom: 14px; }
.notice.error { background: var(--red-soft); color: var(--red); }
.notice.ok { background: var(--green-soft); color: var(--green); }
.notice.warn { background: var(--amber-soft); color: var(--amber); }

/* ---------- Trang tra cứu học sinh ---------- */
.student-page { max-width: 600px; margin: 0 auto; padding: 40px 16px 64px; }
.masthead { margin-bottom: 28px; }
.masthead h1 { color: var(--ink); font-size: 1.85rem; }
.masthead p { color: var(--muted); margin-top: 2px; }

.sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.code-input { text-transform: uppercase; letter-spacing: 0.12em; font-weight: 600; font-size: 1.15rem; }
.pin-input { letter-spacing: 0.3em; font-weight: 600; font-size: 1.15rem; }
.login-help { margin-top: 18px; font-size: 0.88rem; color: var(--muted); }
#turnstile { margin-bottom: 16px; min-height: 0; }

.profile { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.profile h2 { font-size: 1.4rem; }
.tag { display: inline-block; font-size: 0.8rem; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--ink-soft); color: var(--ink); }
.tag.gray { background: var(--grid); color: var(--muted); }
.tag.red { background: var(--red-soft); color: var(--red); }
.tag.amber { background: var(--amber-soft); color: var(--amber); }
.tag.green { background: var(--green-soft); color: var(--green); }

.results { list-style: none; margin: 0; padding: 0; }
.result {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 16px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.result:first-child { padding-top: 4px; }
.result:last-child { border-bottom: none; }
.result .title { font-weight: 600; }
.result .meta { font-size: 0.85rem; color: var(--muted); }
/* điểm như thầy chấm bằng bút đỏ */
.mark {
  grid-row: span 2;
  align-self: center;
  font-family: var(--hand);
  color: var(--red);
  font-size: 2.1rem;
  line-height: 1;
  min-width: 64px;
  height: 64px;
  padding: 0 12px;
  display: grid;
  place-items: center;
  border: 2px solid var(--red);
  border-radius: 50% 46% 52% 48% / 48% 52% 46% 50%;
  transform: rotate(-4deg);
}
.mark small { font-size: 0.9rem; display: block; margin-top: -4px; opacity: 0.8; }
.mark.text { font-size: 1.25rem; }
.comment {
  grid-column: 1 / -1;
  font-family: var(--hand);
  color: var(--red);
  font-size: 1.2rem;
  line-height: 1.35;
  margin-top: 6px;
}
.empty { text-align: center; padding: 28px 8px; color: var(--muted); }

/* ---------- Phiếu kết quả từng bài (hạng, điểm, biểu đồ từng câu, nhận xét) ---------- */
.cards { list-style: none; margin: 0; padding: 0; }
.card { padding: 22px 0; border-bottom: 1px solid var(--line); }
.card:first-child { padding-top: 4px; }
.card:last-child { border-bottom: none; }
.card-head { display: flex; align-items: flex-start; gap: 16px; }
.card-title { flex: 1; min-width: 0; }
.card-title h3 { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; }
.rank { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink); margin-bottom: 2px; }
.rank .of { font-weight: 500; letter-spacing: 0.02em; text-transform: none; color: var(--muted); }
.rating { color: var(--ink); font-weight: 600; font-size: 0.95rem; margin-top: 2px; }
/* điểm tổng: bút đỏ của thầy */
.score { text-align: right; font-family: var(--hand); color: var(--red); line-height: 1; white-space: nowrap; }
.score .big { font-size: 2.8rem; font-weight: 700; }
.score .den { font-size: 1.1rem; color: var(--muted); margin-left: 2px; }
.score.text { font-size: 1.6rem; align-self: center; }
.bars { display: flex; gap: 6px; margin: 18px 0 4px; align-items: flex-end; }
.bar { flex: 1; min-width: 0; text-align: center; font-size: 0.78rem; color: var(--muted); }
.bar .val { font-variant-numeric: tabular-nums; margin-bottom: 3px; color: var(--text); }
.bar .track { height: 96px; background: var(--ink-soft); border-radius: 4px; display: flex; align-items: flex-end; overflow: hidden; }
.bar .fill { width: 100%; background: var(--ink); border-radius: 4px 4px 0 0; min-height: 0; }
.bar .lbl { margin-top: 5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fb { margin-top: 14px; }
.fb h4 { font-size: 0.78rem; letter-spacing: 0.16em; text-transform: uppercase; margin: 0 0 4px; }
.fb.good h4 { color: var(--green); }
.fb.bad h4 { color: var(--red); }
.fb.note h4 { color: var(--ink); }
.fb p, .fb li { font-size: 1rem; line-height: 1.5; }
.fb ul { margin: 0; padding-left: 20px; }
.fb li { margin-bottom: 4px; }
.fb li::marker { color: var(--red); }
.card .meta { margin-top: 12px; font-size: 0.85rem; color: var(--muted); }

/* ---------- Quản trị: điểm thành phần ---------- */
.parts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.parts-grid .part { margin: 0; font-weight: 400; }
.parts-grid .part span { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.parts-grid .part input { padding: 6px 8px; min-height: 36px; text-align: center; }
.panel-lite { border: 1px dashed var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 0 0 14px; }
label.check input { width: auto; min-height: 0; margin: 0; }
td.clip { max-width: 360px; }
td.parts-compact { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 0.82rem; color: var(--muted); }

/* ---------- Khung quản trị ---------- */
.admin-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.sidebar .brand { font-weight: 700; color: var(--ink); padding: 0 10px 18px; font-size: 1.05rem; line-height: 1.3; }
.sidebar nav a {
  display: block;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  margin-bottom: 2px;
}
.sidebar nav a:hover { background: var(--grid); }
.sidebar nav a.active { background: var(--ink-soft); color: var(--ink); font-weight: 600; }
.sidebar .who { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 0.88rem; }
.main { padding: 28px 32px 64px; min-width: 0; max-width: 1200px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 1.45rem; }
.crumb { font-size: 0.88rem; margin-bottom: 6px; }
.crumb a { text-decoration: none; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.panel > h2 { margin-bottom: 14px; font-size: 1.08rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); background: var(--paper); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--paper); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.code, .code { font-weight: 600; letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }
tr.err td { background: var(--red-soft); }
tr.warn td { background: var(--amber-soft); }
td .issues { margin: 4px 0 0; padding-left: 18px; font-size: 0.84rem; }
td .issues li.e { color: var(--red); }
td .issues li.w { color: var(--amber); }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(20, 22, 40, 0.45); }
dialog .dlg-body { padding: 22px; overflow: auto; max-height: calc(100vh - 140px); }
dialog .dlg-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
dialog h2 { margin-bottom: 14px; }
dialog.wide { width: min(1000px, calc(100vw - 32px)); }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.92rem;
  z-index: 100;
  max-width: calc(100vw - 32px);
}

.center-card { max-width: 420px; margin: 10vh auto 0; padding: 0 16px; }
.center-card h1 { color: var(--ink); margin-bottom: 4px; }
.center-card .sub { color: var(--muted); margin-bottom: 20px; }

/* ---------- Phiếu PIN để in ---------- */
.slips { display: none; }
@media print {
  body { background: #fff; }
  body.printing > *:not(.slips) { display: none !important; }
  body.printing .slips { display: grid !important; grid-template-columns: 1fr 1fr; gap: 0; }
  .slip { border: 1px dashed #888; padding: 14px 16px; break-inside: avoid; font-family: var(--font); color: #000; }
  .slip .club { font-weight: 700; }
  .slip .big { font-size: 20px; font-weight: 700; letter-spacing: 0.08em; }
}

/* ---------- Di động ---------- */
@media (max-width: 860px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--line); padding: 12px 16px; }
  .sidebar .brand { padding: 0 0 8px; }
  .sidebar nav { display: flex; gap: 4px; overflow-x: auto; }
  .sidebar nav a { white-space: nowrap; }
  .sidebar .who { display: flex; gap: 10px; align-items: center; padding: 8px 0 0; margin-top: 8px; }
  .main { padding: 20px 16px 48px; }
  .table-wrap table { min-width: 600px; }
}
@media (max-width: 480px) {
  .student-page { padding-top: 28px; }
  .sheet { padding: 18px; }
  .mark { min-width: 56px; height: 56px; font-size: 1.8rem; }
  .bars { gap: 3px; }
  .bar { font-size: 0.68rem; }
  .bar .track { height: 80px; }
  .score .big { font-size: 2.3rem; }
  .card-title h3 { font-size: 1.15rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
