:root {
  --bg: #f3f6f4; --card: #ffffff; --ink: #172420; --muted: #5b6c64; --line: #dde5e0;
  --brand: #0b6b45; --brand-dk: #07472e; --gold: #c9962b; --ok: #1f8a5b; --bad: #b3261e; --warn: #9a6700;
  --soft: #e6f2ec; --radius: 14px; --side: 250px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15.5px/1.55 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
p { margin: .4rem 0 .8rem; }
button { font-family: inherit; }

/* ---------- Đăng nhập ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(rgba(7,71,46,.78), rgba(7,71,46,.85)), url(/img/banner.svg) center/cover no-repeat; }
.auth { width: 100%; max-width: 420px; background: var(--card); border-radius: 18px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.auth .logo b { font-size: 1.2rem; }

/* ---------- Khung ứng dụng ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--side); background: var(--brand-dk); color: #fff; display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 30; transition: transform .2s; }
.side-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; border-bottom: 1px solid rgba(255,255,255,.12); }
.side-head small { color: rgba(255,255,255,.7); }
.menu { display: flex; flex-direction: column; padding: 10px 8px; gap: 2px; flex: 1; }
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: transparent; border: 0; color: rgba(255,255,255,.85);
  padding: 11px 12px; border-radius: 10px; font-size: .95rem; cursor: pointer; }
.menu button .n { width: 26px; height: 26px; border-radius: 8px; background: rgba(255,255,255,.12); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.menu button:hover { background: rgba(255,255,255,.08); }
.menu button.on { background: var(--brand); color: #fff; font-weight: 700; }
.menu button.on .n { background: var(--gold); color: #fff; }
.side-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.12); display: grid; gap: 10px; }
.lang { display: inline-flex; background: rgba(255,255,255,.12); border-radius: 999px; padding: 2px; justify-self: start; }
.lang button { background: transparent; border: 0; color: #fff; padding: 4px 10px; border-radius: 999px; font-size: .78rem; cursor: pointer; }
.foot-row { display: flex; align-items: center; gap: 8px; }
.btn-refresh { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 999px; border: 0; background: rgba(255,255,255,.12); color: #fff; cursor: pointer; }
.btn-refresh:hover { background: rgba(255,255,255,.22); }
.btn-refresh.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.lang button.on { background: #fff; color: var(--brand-dk); font-weight: 700; }
.backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 25; }

.content { flex: 1; margin-left: var(--side); min-width: 0; position: relative; isolation: isolate; }
.content::before { content: ""; position: fixed; inset: 0; left: var(--side); z-index: -1; pointer-events: none;
  background: url(/img/banner.svg) center/cover no-repeat; opacity: .14; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 8px 18px; min-height: 64px;
  background: rgba(255,255,255,.88); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.hamburger { display: none; background: transparent; border: 0; font-size: 1.4rem; cursor: pointer; }
.crumb { flex: 1; font-weight: 700; color: var(--brand-dk); }
.team-photo { height: 52px; border-radius: 8px; object-fit: cover; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.view { padding: 18px; max-width: 1080px; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .backdrop.on { display: block; }
  .content { margin-left: 0; } .content::before { left: 0; }
  .hamburger { display: block; }
  .team-photo { height: 42px; }
  .view { padding: 12px; }
}

/* ---------- Thành phần ---------- */
.card { background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card.click { cursor: pointer; } .card.click:hover { border-color: var(--brand); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); font-size: .9rem; }
.pill { display: inline-block; font-size: .74rem; padding: 2px 10px; border-radius: 999px; background: var(--soft); color: var(--brand); font-weight: 600; }
.pill.ok { background: #e3f3ec; color: var(--ok); } .pill.bad { background: #fbe9e7; color: var(--bad); } .pill.warn { background: #fff4d6; color: var(--warn); } .pill.gold { background: #fbf1dc; color: #8a6414; }
.btn { background: var(--brand); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px; font-size: .95rem; font-weight: 600; cursor: pointer; }
.btn.secondary { background: var(--soft); color: var(--brand-dk); }
.btn.gold { background: var(--gold); }
.btn.danger { background: var(--bad); }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
label { display: block; font-size: .88rem; color: var(--muted); margin: 10px 0 4px; }
input, textarea, select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); font-size: 1rem; font-family: inherit; }
textarea { min-height: 160px; resize: vertical; line-height: 1.5; }
.error { color: var(--bad); font-size: .9rem; margin-top: 6px; }
.notice { background: #fff4d6; border: 1px solid #f1d48a; color: #6b4b00; padding: 10px 12px; border-radius: 10px; margin: 8px 0; font-size: .92rem; }

.bi { display: grid; gap: 4px; }
.bi .en { color: var(--muted); font-style: italic; }
.lang-vi .bi .en { display: none; } .lang-en .bi .vi { display: none; }
.lang-en .bi .en { color: inherit; font-style: normal; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 760px) { .grid2, .grid3 { grid-template-columns: 1fr; } .grid4 { grid-template-columns: 1fr 1fr; } }
.tile { text-align: center; padding: 14px 8px; }
.tile b { display: block; font-size: 1.5rem; color: var(--brand-dk); }
.tile .muted { font-size: .8rem; }
.progress { height: 8px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--gold); border-radius: 999px; }

.block { margin: 12px 0; padding: 12px 14px; border-radius: 10px; border-left: 4px solid var(--brand); background: var(--soft); }
.block.why { border-left-color: var(--gold); background: #fbf4e4; }
.block.example { border-left-color: var(--ok); background: #eaf6f0; }
.block .tag { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; margin: 8px 0; background: #fff; }
th, td { border: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: top; }
th { background: var(--soft); }
.tablewrap { overflow-x: auto; }

.opt { display: block; width: 100%; text-align: left; background: #fff; border: 2px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; cursor: pointer; font-size: .98rem; color: var(--ink); }
.opt:hover { border-color: var(--brand); }
.opt.sel { border-color: var(--brand); background: var(--soft); }
.opt.correct { border-color: var(--ok); background: #e3f3ec; }
.opt.wrong { border-color: var(--bad); background: #fbe9e7; }
.opt.dim { opacity: .6; }
.opt .k { display: inline-block; width: 24px; font-weight: 700; color: var(--brand); }

details summary { cursor: pointer; font-weight: 600; color: var(--brand-dk); padding: 6px 0; }
.steps li { margin-bottom: 6px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: .9rem; z-index: 50; }
.offline { background: var(--warn); color: #fff; text-align: center; font-size: .8rem; padding: 4px; border-radius: 8px; margin-bottom: 10px; }

/* Thi mô phỏng */
.exam-bar { position: sticky; top: 64px; z-index: 5; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.25rem; color: var(--brand-dk); }
.timer.low { color: var(--bad); }
.qnav { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.qnav button { width: 34px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: .8rem; }
.qnav button.done { background: var(--soft); border-color: var(--brand); }
.qnav button.cur { background: var(--brand); color: #fff; }
.qnav button.flag { box-shadow: inset 0 -3px 0 var(--gold); }

/* Biểu đồ */
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: .82rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.news-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.news-item:last-child { border-bottom: 0; }
.tree .topic { margin-bottom: 10px; }
.tree .topic > summary { font-size: 1.02rem; padding: 10px 12px; background: var(--soft); border-radius: 10px; }
.tree .lesson { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.tree .lesson:hover { background: #fafcfb; }

/* Bài test ngắn: lưới thẻ câu hỏi (3–5 cột tuỳ độ rộng màn hình) */
.qgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin-top: 12px; }
.qcard { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff; cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-height: 120px; }
.qcard:hover { border-color: var(--brand); box-shadow: 0 2px 10px rgba(11,107,69,.12); }
.qcard.correct { background: #e3f5ec; border-color: #9fd6bb; }
.qcard.wrong { background: #fff1e0; border-color: #f2c27d; }
.qcard.correct .qhead b { color: var(--ok); } .qcard.wrong .qhead b { color: #b45f06; }
.qhead { align-items: flex-start; }
.qstats { display: grid; grid-template-columns: repeat(4, auto); gap: 2px 6px; text-align: center; font-size: .78rem; font-weight: 700; color: var(--ink); line-height: 1.15; }
.qstats i { display: block; font-style: normal; font-weight: 500; font-size: .62rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.qhead { display: flex; align-items: center; justify-content: space-between; gap: 6px; color: var(--brand-dk); }
.qtopic { font-size: .76rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.qtext { font-size: .9rem; line-height: 1.4; }
.qtext .bi > span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.lang-vi .qtext .bi > .en, .lang-en .qtext .bi > .vi { display: none; }
.lang-vi .qtext .bi > .vi, .lang-en .qtext .bi > .en { -webkit-line-clamp: 4; }
@media (min-width: 1500px) { .qgrid { grid-template-columns: repeat(5, 1fr); } }
@media (max-width: 480px) { .qgrid { grid-template-columns: 1fr 1fr; } .qcard { min-height: 0; } }

/* ---------- 6. Bảng ghi chú (cửa sổ nổi) ---------- */
.notebook { position: fixed; z-index: 60; display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0,0,0,.28); overflow: hidden; resize: both; min-width: 320px; min-height: 260px; max-width: 100vw; max-height: 100vh; }
.notebook.max { inset: 0 !important; width: auto !important; height: auto !important; border-radius: 0; resize: none; }
.notebook.min { height: auto !important; min-height: 0; resize: none; }
.notebook.min .nb-tabs, .notebook.min .nb-tools, .notebook.min .nb-editor { display: none; }
.nb-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 14px; background: var(--brand-dk); color: #fff; cursor: move; user-select: none; touch-action: none; }
.nb-status { font-size: .74rem; opacity: .85; } .nb-status.offline { color: #ffd27a; opacity: 1; }
.nb-win { width: 28px; height: 28px; border: 0; border-radius: 8px; background: rgba(255,255,255,.12); color: #fff; font-size: 1rem; cursor: pointer; line-height: 1; }
.nb-win:hover { background: rgba(255,255,255,.25); }
.nb-tabs { display: flex; gap: 4px; padding: 6px 8px 0; background: var(--soft); overflow-x: auto; flex-shrink: 0; }
.nb-tab { border: 1px solid var(--line); border-bottom: 0; background: #f7faf8; border-radius: 8px 8px 0 0; padding: 5px 12px; font-size: .82rem; cursor: pointer; white-space: nowrap; color: var(--muted); }
.nb-tab.on { background: #fff; color: var(--brand-dk); font-weight: 700; }
.nb-add { border: 0; background: var(--brand); color: #fff; width: 28px; height: 28px; border-radius: 8px; font-size: 1.1rem; font-weight: 700; cursor: pointer; align-self: center; margin-left: 4px; }
.nb-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); background: #fff; flex-shrink: 0; }
.nb-tools select { width: auto; padding: 4px 6px; font-size: .82rem; border-radius: 8px; }
.nb-b { min-width: 30px; height: 30px; border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; font-size: .9rem; color: var(--ink); }
.nb-b:hover { border-color: var(--brand); background: var(--soft); }
.nb-del:hover { border-color: var(--bad); background: #fbe9e7; }
.nb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }
.nb-colors { display: inline-flex; gap: 3px; }
.nb-sw { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0,0,0,.15); cursor: pointer; padding: 0; }
.nb-sw:hover { transform: scale(1.15); }
.nb-tbl { position: relative; }
.nb-pop { position: absolute; top: 36px; left: 0; z-index: 5; display: flex; gap: 8px; align-items: flex-end; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); white-space: nowrap; }
.nb-pop[hidden] { display: none; }
.nb-pop label { font-size: .75rem; color: var(--muted); display: grid; gap: 2px; }
.nb-pop input { width: 58px; padding: 4px 6px; }
.nb-editor { flex: 1; overflow: auto; padding: 14px 18px; outline: none; font-family: "Segoe UI", Arial, sans-serif; font-size: 15px; line-height: 1.55; }
.nb-editor:empty::before { content: attr(data-ph); color: var(--muted); }
.nb-editor ul, .nb-editor ol { padding-left: 26px; }
.nb-table { border-collapse: collapse; margin: 8px 0; min-width: 50%; }
.nb-table td, .nb-table th { border: 1px solid #b9c7c0; padding: 6px 8px; min-width: 60px; vertical-align: top; }
.nb-table th { background: var(--soft); font-weight: 700; }
.autosave-hint { font-size: .8rem; margin: 0 0 6px; }
@media (max-width: 760px) { .notebook:not(.min) { inset: 0 !important; width: auto !important; height: auto !important; border-radius: 0; resize: none; }
  .notebook.min { left: 0 !important; right: 0; bottom: 0; top: auto !important; width: auto !important; border-radius: 14px 14px 0 0; } }
