:root {
  --navy: #122b47;
  --blue: #2f6ba8;
  --cyan: #17b6e6;
  --green: #2e9e5b;
  --green-bg: #e7f5ec;
  --red: #c0392b;
  --red-bg: #fbeceb;
  --amber: #b7791f;
  --amber-bg: #fdf4e3;
  --text: #1e2a3a;
  --muted: #6b7785;
  --line: #d9e2ec;
  --tint: #eaf3fa;
  --bg: #f4f7fa;
  --card: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(18, 43, 71, 0.06), 0 2px 8px rgba(18, 43, 71, 0.05);
  font-family: "Segoe UI", Calibri, system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.5; }
a { color: var(--blue); }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.topbar { background: var(--navy); color: #fff; }
.topbar .inner { max-width: 960px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.topbar img { height: 34px; background: #fff; border-radius: 6px; padding: 3px 5px; }
.topbar .brand { font-weight: 700; font-size: 16px; line-height: 1.2; }
.topbar .brand small { display: block; font-weight: 400; font-size: 12px; color: #a9c4dd; }
.topbar .spacer { flex: 1; }
.topbar a, .topbar button.link { color: #d8e6f3; font-size: 14px; text-decoration: none; background: none; border: 0; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.topbar a:hover, .topbar button.link:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

main { max-width: 960px; margin: 0 auto; padding: 24px 16px 64px; }
main.narrow { max-width: 760px; }
h1 { font-size: 24px; margin: 0 0 6px; color: var(--navy); line-height: 1.25; }
h2 { font-size: 18px; margin: 28px 0 10px; color: var(--navy); }
.lead { color: var(--muted); margin: 0 0 20px; }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 14px; }
.card.accent { border-top: 4px solid var(--blue); }
.quiz-list { display: grid; gap: 14px; }
.quiz-item { display: flex; gap: 16px; align-items: center; }
.quiz-item .info { flex: 1; min-width: 0; }
.quiz-item h3 { margin: 0 0 4px; font-size: 17px; color: var(--navy); }
.quiz-item p { margin: 0; color: var(--muted); font-size: 14px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 13px; margin-top: 6px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: 14px;
  border-radius: 8px; border: 1px solid var(--blue); background: var(--blue); color: #fff; padding: 9px 16px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #255a8f; border-color: #255a8f; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.secondary { background: #fff; color: var(--blue); border-color: var(--line); }
.btn.secondary:hover { background: var(--tint); }
.btn.danger { background: #fff; color: var(--red); border-color: #efc9c5; }
.btn.danger:hover { background: var(--red-bg); }
.btn.small { padding: 5px 10px; font-size: 13px; font-weight: 600; }
.btn.big { padding: 12px 22px; font-size: 15px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-row.end { justify-content: flex-end; }

label.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.field > span em { color: var(--red); font-style: normal; }
input[type=text], input[type=password], input[type=number], textarea {
  width: 100%; font: inherit; color: var(--text); padding: 9px 11px; border: 1px solid #c6d3e0; border-radius: 8px; background: #fff; }
textarea { resize: vertical; min-height: 64px; }
input:focus, textarea:focus { outline: 2px solid rgba(47, 107, 168, 0.35); border-color: var(--blue); }
.hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
.error-text { color: var(--red); font-size: 14px; margin-top: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; font-size: 14px; }
.check input { width: 17px; height: 17px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

/* ---------- quiz answering ---------- */
.question { scroll-margin-top: 80px; }
.question .q-head { display: flex; gap: 10px; margin-bottom: 12px; }
.question .q-no { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--tint); color: var(--blue); font-weight: 700;
  font-size: 13px; display: flex; align-items: center; justify-content: center; }
.question .q-text { font-weight: 600; flex: 1; }
.question.missing { border-color: var(--red); box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.15); }
.question .missing-note { color: var(--red); font-size: 13px; margin-top: 8px; }
.option { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; margin-top: 8px; }
.option:hover { background: #f7fafd; }
.option input { margin: 3px 0 0; width: 17px; height: 17px; flex: none; accent-color: var(--blue); }
.option .letter { font-weight: 700; color: var(--muted); width: 16px; flex: none; }
.option:has(input:checked) { border-color: var(--blue); background: var(--tint); }
.progress { position: sticky; top: 0; z-index: 5; background: rgba(244, 247, 250, 0.95); backdrop-filter: blur(4px); padding: 10px 0; margin-bottom: 4px; }
.progress .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress .bar div { height: 100%; width: 0; background: var(--blue); transition: width 0.2s; }
.progress .label { font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.result { text-align: center; padding: 36px 20px; }
.result .score { font-size: 64px; font-weight: 800; line-height: 1; color: var(--navy); margin: 12px 0 4px; }
.result .status { display: inline-block; font-weight: 700; padding: 6px 16px; border-radius: 999px; margin: 10px 0 14px; }
.result .status.pass { background: var(--green-bg); color: var(--green); }
.result .status.fail { background: var(--red-bg); color: var(--red); }

/* ---------- badges & tables ---------- */
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.gray { background: #eef1f4; color: var(--muted); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { background: var(--navy); color: #fff; text-align: left; font-weight: 600; padding: 9px 12px; white-space: nowrap; }
td { padding: 9px 12px; border-top: 1px solid var(--line); vertical-align: top; }
tbody tr:nth-child(even) td { background: #f8fbfd; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: 4px; }
tr.detail td { background: #fbfcfe !important; padding: 14px 16px; }
.answer-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.answer-list li { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; font-size: 13px; }
.answer-list .muted { color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 8px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat .v { font-size: 26px; font-weight: 800; color: var(--navy); line-height: 1.1; }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.pct { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.pct .mini { width: 70px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.pct .mini div { height: 100%; background: var(--green); }
.pct .mini div.low { background: var(--amber); }

/* ---------- editor ---------- */
.page-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .back { font-size: 14px; text-decoration: none; display: inline-block; margin-bottom: 6px; }
.q-edit .q-edit-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.q-edit .q-edit-head strong { flex: 1; color: var(--navy); }
.opt-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.opt-row .key { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); flex: none; cursor: pointer; width: 74px; }
.opt-row .key input { accent-color: var(--green); width: 16px; height: 16px; }
.opt-row:has(.key input:checked) input[type=text] { border-color: var(--green); background: var(--green-bg); }
.opt-row .letter { font-weight: 700; color: var(--muted); width: 16px; flex: none; }
.icon-btn { flex: none; border: 1px solid var(--line); background: #fff; color: var(--muted); border-radius: 6px; height: 32px; padding: 0 10px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; }
.icon-btn:hover { background: var(--tint); color: var(--blue); }
.icon-btn:disabled { opacity: 0.4; cursor: default; background: #fff; }
.savebar { position: sticky; bottom: 0; background: rgba(244, 247, 250, 0.96); border-top: 1px solid var(--line); padding: 12px 0; margin-top: 18px; z-index: 5; }
.notice { background: var(--amber-bg); border: 1px solid #f0d9a8; color: #7a5310; border-radius: 8px; padding: 10px 14px; font-size: 14px; margin-bottom: 14px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 18px;
  border-radius: 8px; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); z-index: 50; max-width: calc(100% - 32px); }
.toast.error { background: var(--red); }

.login { max-width: 380px; margin: 60px auto; }

@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
  .quiz-item { flex-direction: column; align-items: stretch; }
  h1 { font-size: 21px; }
  .result .score { font-size: 52px; }
}

@media print {
  .topbar, .no-print, .btn, .savebar, td.actions, th.actions { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .stat, .table-wrap, .card { box-shadow: none; }
  th { background: #122b47 !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  tr { break-inside: avoid; }
}

fieldset { margin: 0; min-width: 0; }
.meta + .field { margin-top: 18px; }
.q-edit div.field { margin-bottom: 14px; }
.q-edit div.field > .btn { margin-top: 2px; }
@media (max-width: 720px) {
  td.actions { white-space: normal; text-align: left; }
  td.actions .btn { margin: 2px 4px 2px 0; }
  .opt-row .key { width: auto; }
}
@media (max-width: 520px) {
  .topbar .brand small { display: none; }
  .topbar .brand { font-size: 14px; }
  .topbar a, .topbar button.link { white-space: nowrap; padding: 6px 4px; }
  td .hint { word-break: break-all; }
}

.m-label { display: none; }
@media (max-width: 720px) {
  .quiz-table thead { display: none; }
  .quiz-table tr { display: grid; grid-template-columns: auto auto 1fr; gap: 6px 12px; align-items: center; padding: 12px 14px; border-top: 1px solid var(--line); }
  .quiz-table tbody tr:first-child { border-top: 0; }
  .quiz-table td { display: block; padding: 0; border: 0; background: none !important; text-align: left; }
  .quiz-table td:first-child, .quiz-table td.actions { grid-column: 1 / -1; }
  .quiz-table .m-label { display: inline; }
}
