:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e1e5ec;
  --text: #1c2430;
  --muted: #667085;
  --primary: #0b6e4f;
  --primary-hover: #095c42;
  --primary-soft: #e3f3ec;
  --danger: #c0362c;
  --danger-soft: #fdecea;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand img { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; }
.brand-name { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.container { max-width: 880px; margin: 0 auto; padding: 20px 16px 110px; }
.narrow { max-width: 520px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card + .card { margin-top: 16px; }
h1 { font-size: 24px; line-height: 1.3; margin: 0 0 6px; }
h2 { font-size: 19px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- Forms ---------- */
.field { margin-top: 16px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea.input { resize: vertical; min-height: 120px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: #f2c4bf; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 14px; border-radius: 8px; }

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
  margin-top: 14px;
}
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-info { background: var(--primary-soft); color: var(--primary); }

/* ---------- Exam picker ---------- */
.exam-option, .field label.exam-option {
  display: flex;
  font-weight: 400;
  font-size: 16px;
  margin-bottom: 0;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  margin-top: 10px;
}
.exam-option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.exam-option input { margin-top: 4px; accent-color: var(--primary); width: 18px; height: 18px; }
.exam-option .title { font-weight: 600; }

/* ---------- Taking the exam ---------- */
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 18px;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
}
.timer.warn { background: var(--warn-soft); color: var(--warn); }
.timer.danger { background: var(--danger-soft); color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

.progress { height: 4px; background: var(--border); }
.progress > div { height: 100%; background: var(--primary); transition: width .3s; }

.q-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.q-num { font-weight: 700; color: var(--primary); }
.badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
}
.q-text { font-size: 18px; font-weight: 500; margin: 14px 0 18px; white-space: pre-wrap; }

.opt {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  margin-top: 10px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.opt:hover { border-color: #b9c2cf; }
.opt .letter {
  flex: 0 0 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--border);
  font-weight: 700;
  font-size: 14px;
  background: var(--surface);
}
.opt.single .letter { border-radius: 50%; }
.opt.multi .letter { border-radius: 7px; }
.opt .opt-text { padding-top: 3px; white-space: pre-wrap; }
.opt.selected { border-color: var(--primary); background: var(--primary-soft); }
.opt.selected .letter { background: var(--primary); border-color: var(--primary); color: #fff; }

.bottom-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.bottom-inner .spacer { flex: 1; }

.grid-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 8px;
}
.grid-panel button {
  height: 44px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}
.grid-panel button.answered { background: var(--primary-soft); border-color: #9fd3bd; color: var(--primary); }
.grid-panel button.current { outline: 2.5px solid var(--primary); outline-offset: 1px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-bottom: 12px; flex-wrap: wrap; }
.legend span::before {
  content: '';
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: -1px;
  border: 1.5px solid var(--border);
}
.legend .l-done::before { background: var(--primary-soft); border-color: #9fd3bd; }

.save-status { font-size: 13px; color: var(--muted); }
.save-status.error { color: var(--danger); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 460px;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
}
.modal.wide { max-width: 640px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }

/* ---------- Result ---------- */
.result { text-align: center; padding: 34px 22px; }
.score-ring {
  width: 150px; height: 150px;
  margin: 18px auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--border) 0);
}
.score-ring > div {
  width: 124px; height: 124px;
  border-radius: 50%;
  background: var(--surface);
  display: grid;
  place-items: center;
  align-content: center;
}
.score-big { font-size: 40px; font-weight: 800; line-height: 1; }
.score-max { color: var(--muted); font-size: 15px; margin-top: 4px; }

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .card { padding: 18px; }
  h1 { font-size: 21px; }
  .q-text { font-size: 17px; }
  .bottom-inner .btn { padding: 11px 14px; }
  .hide-sm { display: none; }
}

/* ================= Trang quản trị ================= */
.admin .topbar-inner, .admin .container { max-width: 1180px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.tab {
  padding: 10px 14px;
  border: 0;
  background: none;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2.5px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .grow { flex: 1; }
.toolbar .input { width: auto; min-width: 180px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl th { background: var(--surface-2); font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .actions { white-space: nowrap; text-align: right; }
.tbl .actions .btn + .btn { margin-left: 6px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.pill { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.pill.green { background: var(--primary-soft); color: var(--primary); }
.pill.gray { background: #eef0f3; color: var(--muted); }
.pill.orange { background: var(--warn-soft); color: var(--warn); }
.pill.red { background: var(--danger-soft); color: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }

.bar { height: 10px; background: #eef0f3; border-radius: 99px; min-width: 120px; overflow: hidden; }
.bar > div { height: 100%; background: var(--primary); border-radius: 99px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row2 > *, .row2 .input { min-width: 0; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.q-preview { margin: 0; padding: 0; list-style: none; }
.q-preview li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.q-preview .opts { margin: 4px 0 0; padding-left: 18px; font-size: 14px; color: var(--muted); }
.q-preview .opts .ok { color: var(--primary); font-weight: 600; }
.errors { max-height: 180px; overflow: auto; margin: 0; padding-left: 20px; font-size: 14px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 24px 0 12px; }
.section-title h2 { margin: 0; }
.logo-preview { width: 72px; height: 72px; border: 1px dashed var(--border); border-radius: 10px; object-fit: contain; background: var(--surface-2); }

@media (max-width: 560px) {
  .row2 { grid-template-columns: 1fr; }
  .toolbar .input { min-width: 0; flex: 1; }
}
