:root {
  --bg: #f4f5f7; --card: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e2e5eb;
  --brand: #2554c7; --brand-ink: #fff; --brand-soft: #e8eefc;
  --good: #1a7f4b; --good-soft: #e3f4ea; --bad: #c0352b; --bad-soft: #fbe9e7;
  --warn: #9a6200; --warn-soft: #fdf3dc; --info: #1c63a6; --info-soft: #e3effa;
  --radius: 10px; --mono: ui-monospace, "Cascadia Code", Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .2em 0 .6em; }
h2 { font-size: 1.15rem; margin: 0 0 .6em; }
h3 { font-size: 1rem; margin: .8em 0 .4em; }
code { font-family: var(--mono); font-size: .92em; background: #f0f2f5; padding: 1px 5px; border-radius: 4px; }
code.big { font-size: 1.2em; padding: 3px 8px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.ok-text { color: var(--good); } .warn-text { color: var(--warn); } .danger-text { color: var(--bad); }

/* ---- Khung trang ---- */
.topbar { display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 56px; background: #1d2433; color: #fff; }
.topbar a { color: #dfe4ee; }
.brand { font-weight: 700; font-size: 1.1rem; color: #fff !important; }
.logo { display: inline-block; background: var(--brand); color: #fff; border-radius: 6px; padding: 0 6px; font-family: var(--mono); font-size: .9em; }
.topbar nav { display: flex; gap: 18px; flex: 1; }
.who { display: flex; align-items: center; gap: 14px; font-size: .9rem; }
.who form { margin: 0; }
button.link { background: none; border: 0; color: #aab3c5; cursor: pointer; font: inherit; padding: 0; }
button.link:hover { color: #fff; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 24px; }
.crumbs { color: var(--muted); font-size: .88rem; margin: 0 0 4px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.card.narrow { max-width: 460px; margin: 40px auto; }
.card.empty { text-align: center; color: var(--muted); padding: 40px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1, .page-head h2 { margin: 0; }
.btn-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn-row form { margin: 0; }

/* ---- Nút & form ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 500; cursor: pointer;
  text-decoration: none !important; white-space: nowrap; }
.btn:hover { background: #f3f5f9; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: #efc6c2; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn.wide { width: 100%; justify-content: flex-start; margin-bottom: 4px; }
input, select, textarea { font: inherit; color: inherit; padding: 8px 10px; border: 1px solid #cfd4dd; border-radius: 7px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=file] { border: 1px dashed #b7bfcc; padding: 14px; background: #fafbfc; }
textarea.code { font-family: var(--mono); font-size: 13px; tab-size: 2; }
label { display: block; font-weight: 500; }
label input, label select, label textarea { margin-top: 4px; font-weight: 400; }
label.check, label.radio { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin-right: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack > form { margin: 0; }
.row-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row-form > label { flex: 1 1 180px; }
.row-form > label.check { flex: 0 0 auto; padding-bottom: 8px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 0; }
legend { font-weight: 600; padding: 0 6px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
form.inline { display: flex; gap: 6px; }
form.inline select { padding: 4px 6px; }
.score-input { font-size: 1.6rem; font-weight: 700; text-align: center; }
.title-input { border-color: transparent; font-weight: 600; background: transparent; }
.title-input:hover, .title-input:focus { border-color: #cfd4dd; background: #fff; }

/* ---- Menu bật ra ---- */
details.pop { position: relative; }
details.pop > summary { list-style: none; }
details.pop > summary::-webkit-details-marker { display: none; }
details.pop[open] > .pop-body, details.pop[open] > form.pop-body { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; width: 290px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: 0 10px 30px rgba(20,30,50,.15); }
details.pop.right[open] > .pop-body, details.pop.right[open] > form.pop-body { left: auto; right: 0; }
details.card > summary { cursor: pointer; }
.desc { white-space: normal; margin-top: 8px; }

/* ---- Thông báo & nhãn ---- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--good-soft); color: var(--good); border: 1px solid #bfe3cd; }
.flash.bad { background: var(--bad-soft); color: var(--bad); border-color: #f0c8c3; }
.flash.warn { background: var(--warn-soft); color: var(--warn); border-color: #f2dca6; }
.flash.floating { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.12); transition: opacity .6s; }
.flash.fade { opacity: 0; pointer-events: none; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: #eef0f4; color: #4a5263; vertical-align: middle; }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.info { background: var(--info-soft); color: var(--info); }
.tag.muted { background: #f1f2f4; color: var(--muted); }
.tag.web { background: #fff0e6; color: #b4500f; }
.tag.sql { background: #ece8fd; color: #5b3fc4; }

/* ---- Bảng ---- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.tbl tr:hover td { background: #fafbfc; }
.tbl tr.dim td { opacity: .55; }
.tbl.compact td, .tbl.compact th { padding: 5px 8px; }
.tbl td.actions { text-align: right; white-space: nowrap; }
.tbl td.actions form { display: inline; }
.card > .tbl { margin: -4px 0; }
.card { overflow-x: auto; }
.card:has(details.pop[open]) { overflow: visible; }

/* ---- Lưới lớp, danh sách ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.class-card { display: block; color: var(--ink); transition: border-color .15s, transform .15s; margin: 0; }
.class-card:hover { border-color: var(--brand); text-decoration: none; transform: translateY(-2px); }
.class-name { font-size: 1.5rem; font-weight: 700; }
.stats { display: flex; gap: 16px; margin: 10px 0 8px; color: var(--muted); font-size: .9rem; }
.stats b { color: var(--ink); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.stat b { display: block; font-size: 1.3rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0; color: var(--ink); }
a.list-item:hover { border-color: var(--brand); text-decoration: none; }
.list-item.done { background: #fbfcfd; }
.list-item .grow { flex: 1; color: var(--ink); }
.li-title { font-weight: 600; }
.cred-box { border-color: #f2dca6; background: #fffdf6; }

/* ---- Đăng nhập ---- */
body.plain { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #1d2433, #2554c7); }
.login-box { background: #fff; width: min(380px, 92vw); padding: 32px; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-brand { font-size: 1.6rem; font-weight: 800; }
.login-box .btn { width: 100%; padding: 10px; }

/* ================= Trang soạn code ================= */
body.editor-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; background: #fff; }
.ed-top { display: flex; align-items: center; gap: 14px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: #fff; flex-wrap: wrap; }
.ed-title { flex: 1; display: flex; flex-direction: column; min-width: 180px; line-height: 1.3; }
.ed-top form { margin: 0; }
.ed-main { flex: 1; display: flex; min-height: 0; }
.ed-side { width: 300px; flex: 0 0 300px; border-right: 1px solid var(--line); padding: 14px; overflow-y: auto; background: #fafbfc; }
.ed-side.hidden { display: none; }
.ed-side .stack .btn { width: 100%; }
.ed-work { flex: 1; display: flex; min-width: 0; }
.ed-pane { flex: 1 1 50%; display: flex; flex-direction: column; min-width: 0; }
.ed-code { border-right: 1px solid var(--line); }
.ed-tabs { display: flex; align-items: center; gap: 4px; padding: 0 8px; height: 40px; border-bottom: 1px solid var(--line); background: #f6f7f9; flex: 0 0 auto; }
.ed-tab { border: 0; background: none; padding: 8px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; height: 40px; }
.ed-tab.active { color: var(--ink); border-bottom-color: var(--brand); }
.ed-label { font-weight: 600; color: var(--muted); padding: 0 6px; }
.ed-spacer { flex: 1; }
.ed-save-state { font-size: .8rem; color: var(--muted); padding-right: 4px; }
.ed-save-state.ok { color: var(--good); }
.ed-save-state.bad { color: var(--bad); }
.ed-editors { flex: 1; position: relative; min-height: 0; }
.ed-editor { position: absolute; inset: 0; display: none; }
.ed-editor.active { display: block; }
.ed-editor .CodeMirror { height: 100%; font-family: var(--mono); font-size: 14px; }
.ed-editor textarea.fallback { width: 100%; height: 100%; border: 0; border-radius: 0; font-family: var(--mono); font-size: 14px; resize: none; }
.preview { flex: 1; border: 0; width: 100%; background: #fff; }
.ed-out.maximized { position: fixed; inset: 0; z-index: 100; background: #fff; }
.sql-out, .schema-view { flex: 1; overflow: auto; padding: 12px 14px; }
.schema-view { position: absolute; inset: 0; }
.res-wrap { overflow-x: auto; }
table.res { border-collapse: collapse; font-family: var(--mono); font-size: 13px; margin-bottom: 4px; }
table.res th, table.res td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; }
table.res th { background: #f1f3f7; }
table.res td.null { color: var(--muted); font-style: italic; }
.sql-err { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 8px; font-family: var(--mono); font-size: 13px; white-space: pre-wrap; }
.schema-table { margin-bottom: 14px; }
.schema-table ul { margin: 4px 0 0; padding-left: 20px; }
.grade-box { background: var(--good-soft); border: 1px solid #bfe3cd; border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.grade-score { font-size: 2.2rem; font-weight: 800; color: var(--good); line-height: 1; }
.grade-score small { font-size: 1rem; color: var(--muted); }
.feedback { margin-top: 10px; }

@media (max-width: 900px) {
  .topbar { padding: 0 12px; gap: 12px; height: auto; min-height: 56px; flex-wrap: wrap; }
  .wrap { padding: 14px; }
  .ed-main { flex-direction: column; overflow-y: auto; }
  .ed-side { width: auto; flex: 0 0 auto; border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
  .ed-work { flex-direction: column; flex: 0 0 auto; }
  .ed-pane { flex: 0 0 auto; height: 60vh; }
  .ed-code { border-right: 0; border-bottom: 1px solid var(--line); }
}

@media print {
  .topbar, .foot, .btn, form, .crumbs, section.card { display: none !important; }
  .cred-box { border: 0; }
  body { background: #fff; }
}
