:root {
  --bg: #f4f6fa; --card: #fff; --ink: #1b2333; --muted: #5d6b82; --line: #dde3ec;
  --brand: #1a56db; --brand-soft: #e8efff; --ok: #0f8a4b; --ok-soft: #e3f6ec; --warn: #b45309; --warn-soft: #fdf1e1; --bad: #c0262d; --bad-soft: #fde8e8;
  --ai: #7c3aed; --word: #1d4ed8; --excel: #15803d;
  --r: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Be Vietnam Pro', system-ui, -apple-system, Segoe UI, Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; } h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
.loading { padding: 60px; text-align: center; color: var(--muted); }
#topbar { background: #0f2a5c; color: #fff; display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 56px; position: sticky; top: 0; z-index: 20; }
#topbar .logo { font-weight: 700; color: #fff; display: flex; gap: 10px; align-items: center; white-space: nowrap; }
#topbar .logo span.badge { background: #fff; color: #0f2a5c; border-radius: 6px; padding: 1px 7px; font-size: 13px; }
#topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
#topbar nav a { color: #c9d6f2; padding: 6px 12px; border-radius: 6px; white-space: nowrap; }
#topbar nav a.on, #topbar nav a:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
#topbar .who { display: flex; align-items: center; gap: 10px; font-size: 14px; white-space: nowrap; }
#topbar .who img { width: 30px; height: 30px; border-radius: 50%; }
#topbar .who button { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 6px; padding: 4px 10px; cursor: pointer; }
main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 60px; }
main.wide { max-width: none; padding: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; display: inline-flex; gap: 6px; align-items: center; }
.btn:hover { border-color: #b8c3d6; text-decoration: none; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); } .btn.primary:hover { background: #1747b5; }
.btn.danger { color: var(--bad); border-color: #f1b8bb; } .btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--ink); }
textarea { width: 100%; min-height: 90px; resize: vertical; }
label { display: block; font-weight: 500; margin: 10px 0 4px; } label > input:not([type=checkbox]):not([type=radio]), label > select, label > textarea { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
label.inline { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; margin: 0 14px 0 0; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th, table.tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.tbl th { background: #f8fafc; font-weight: 600; color: var(--muted); font-size: 13px; position: sticky; top: 0; }
table.tbl tr:hover td { background: #fafbfd; }
.tbl-wrap { overflow-x: auto; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef1f6; color: var(--muted); white-space: nowrap; }
.pill.ai { background: #f1eafe; color: var(--ai); } .pill.word { background: #e7eefe; color: var(--word); } .pill.excel { background: #e5f5ea; color: var(--excel); }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.warn { background: var(--warn-soft); color: var(--warn); } .pill.bad { background: var(--bad-soft); color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.bigcode { font-family: ui-monospace, Menlo, monospace; font-size: 26px; letter-spacing: 4px; font-weight: 700; color: var(--brand); background: var(--brand-soft); padding: 4px 14px; border-radius: 8px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
#toast div { background: #1b2333; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 90vw; }
#toast div.err { background: var(--bad); } #toast div.warn { background: var(--warn); }
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: #fff; border-radius: 12px; padding: 22px; width: min(560px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-box.lg { width: min(900px, 100%); }
.row-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Đăng nhập */
.login { max-width: 460px; margin: 6vh auto; text-align: center; }
.login .hero { font-size: 44px; }
.login .gbtn { display: flex; justify-content: center; margin: 22px 0; min-height: 44px; }

/* Thi */
.exam-shell { display: grid; grid-template-columns: 250px 1fr; height: calc(100vh - 56px); }
.exam-side { background: #fff; border-right: 1px solid var(--line); overflow: auto; padding: 14px; }
.exam-side h4 { margin: 14px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.qnav { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.qnav button { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 0; cursor: pointer; font: inherit; font-size: 13px; }
.qnav button.done { background: var(--ok-soft); border-color: #9bd8b6; color: var(--ok); font-weight: 600; }
.qnav button.cur { outline: 2px solid var(--brand); }
.qnav.wide { grid-template-columns: 1fr; } .qnav.wide button { text-align: left; padding: 7px 10px; }
.exam-main { overflow: auto; padding: 18px 22px 80px; }
.exam-head { display: flex; align-items: center; gap: 16px; background: #fff; border-bottom: 1px solid var(--line); padding: 10px 18px; position: sticky; top: 0; z-index: 5; margin: -18px -22px 18px; }
.timer { font-family: ui-monospace, Menlo, monospace; font-size: 22px; font-weight: 700; background: #0f2a5c; color: #fff; padding: 4px 14px; border-radius: 8px; }
.timer.low { background: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .7; } }
.savestate { font-size: 13px; color: var(--muted); }
.q-title { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.stem { white-space: pre-wrap; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 10px 0 14px; }
.opts label { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 8px 0; cursor: pointer; background: #fff; }
.opts label:hover { border-color: #b8c3d6; } .opts input { margin-top: 4px; }
.opts label.picked { border-color: var(--brand); background: var(--brand-soft); }
.opts label.correct { border-color: var(--ok); background: var(--ok-soft); } .opts label.wrong { border-color: var(--bad); background: var(--bad-soft); }
.checklist { font-size: 13px; color: var(--muted); margin: 0 0 10px; padding-left: 20px; }
.details { list-style: none; padding: 0; margin: 8px 0; font-size: 14px; }
.details li { padding: 4px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; }
.details li .s { margin-left: auto; white-space: nowrap; font-weight: 600; }
.scorebig { font-size: 48px; font-weight: 700; color: var(--brand); }
.sec-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.sec-cards > div { border: 1px solid var(--line); border-radius: 10px; padding: 12px; text-align: center; }
.sec-cards b { display: block; font-size: 22px; }

/* Trình soạn thảo Word */
.word { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #e9ecf2; }
.w-toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 8px; background: #f8fafc; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 3; }
.w-toolbar button, .s-toolbar button { border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 4px 8px; cursor: pointer; font: inherit; font-size: 13px; min-width: 30px; }
.w-toolbar button:hover, .s-toolbar button:hover { background: #e7ecf4; border-color: var(--line); }
.w-toolbar select { padding: 3px 6px; font-size: 13px; border-radius: 6px; }
.sep { width: 1px; background: var(--line); margin: 2px 4px; align-self: stretch; }
.w-page-wrap { padding: 20px; max-height: 70vh; overflow: auto; }
.w-page { background: #fff; width: min(794px, 100%); min-height: 900px; margin: 0 auto; padding: 60px 64px; box-shadow: 0 2px 8px rgba(0,0,0,.15); font-family: Arial; font-size: 11pt; line-height: 1.15; color: #000; outline: none; }
.w-page p, .w-page h1, .w-page h2, .w-page h3 { margin: 0 0 6pt; }
.w-page h1 { font-size: 18pt; font-weight: bold; } .w-page h2 { font-size: 14pt; font-weight: bold; } .w-page h3 { font-size: 12pt; font-weight: bold; }
.w-page ul, .w-page ol { margin: 0 0 6pt; padding-left: 28px; }
.w-page table, .w-table { border-collapse: collapse; width: 100%; margin: 6pt 0; }
.w-page td, .w-page th { border: 1px solid #000; padding: 3pt 6pt; min-width: 40px; vertical-align: top; }
.w-status { font-size: 12px; color: var(--muted); padding: 4px 10px; background: #f8fafc; border-top: 1px solid var(--line); }
iframe.wordview { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: 8px; background: #e9ecf2; }

/* Bảng tính */
.sheet { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; outline: none; }
.s-toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 8px; background: #f8fafc; border-bottom: 1px solid var(--line); align-items: center; }
.s-hint { font-size: 12px; color: var(--muted); margin-left: 8px; }
.s-fbar { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.s-addr { width: 90px; text-align: center; font-family: ui-monospace, Menlo, monospace; font-size: 13px; border-right: 1px solid var(--line); padding: 6px; }
.s-fx { font-style: italic; color: var(--muted); padding: 0 10px; font-family: serif; }
.s-input { flex: 1; border: 0; border-radius: 0; font-family: ui-monospace, Menlo, monospace; font-size: 14px; padding: 7px 8px; outline: none; }
.s-grid-wrap { overflow: auto; max-height: 62vh; }
.s-grid { border-collapse: collapse; font-size: 13px; font-family: Calibri, Arial, sans-serif; user-select: none; }
.s-grid th { background: #f1f4f8; color: #4b5870; font-weight: 500; border: 1px solid #d5dbe5; padding: 2px 6px; min-width: 34px; position: sticky; top: 0; z-index: 1; }
.s-grid tbody th { position: sticky; left: 0; }
.s-grid td { border: 1px solid #e2e7ee; min-width: 96px; max-width: 220px; height: 24px; padding: 2px 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: cell; }
.s-grid td.num { text-align: right; } .s-grid td.b { font-weight: 700; } .s-grid td.err { color: var(--bad); } .s-grid td.f { color: #0b3b8c; }
.s-grid td.sel { background: #e8efff; } .s-grid td.anchor { outline: 2px solid var(--brand); outline-offset: -2px; background: #fff; }
.s-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; padding: 10px; }
.s-charts:empty { display: none; }
.s-chart { border: 1px solid var(--line); border-radius: 8px; padding: 8px; height: 280px; display: flex; flex-direction: column; }
.s-chart canvas { flex: 1; min-height: 0; }
.s-chart-h { display: flex; gap: 6px; align-items: center; font-size: 13px; } .s-chart-h button { margin-left: auto; border: 0; background: none; cursor: pointer; color: var(--bad); }

.pool-list { max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.pool-list label { font-weight: 400; display: flex; gap: 8px; margin: 4px 0; }
.items-tbl td { vertical-align: middle; }
.help { background: #f8fafc; border: 1px dashed var(--line); border-radius: 8px; padding: 10px 14px; font-size: 13px; color: var(--muted); }
.help code { color: var(--ink); }

@media (max-width: 860px) {
  .exam-shell { grid-template-columns: 1fr; height: auto; }
  .exam-side { border-right: 0; border-bottom: 1px solid var(--line); }
  .exam-main { padding: 12px 12px 80px; } .exam-head { margin: -12px -12px 12px; }
  .w-page { padding: 24px 20px; min-height: 600px; }
  #topbar .who span { display: none; }
  .sec-cards { grid-template-columns: 1fr; }
}
