:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1a1d23;
  --muted: #646b78;
  --border: #dde1e7;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --accent-soft: #e3ecfd;
  --ok: #15803d;
  --danger: #b91c1c;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #23272f;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #2e333c;
    --accent: #5b8cff;
    --accent-text: #0b1020;
    --accent-soft: #1e2a45;
    --ok: #4ade80;
    --danger: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input { font: inherit; color: inherit; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }

/* Menu chính */
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--accent); background: var(--accent-soft); }

@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; padding: 10px 16px; }
  .nav { order: 10; flex-basis: 100%; margin: 0 -4px; overflow-x: auto; }
  .nav a { flex: 1; text-align: center; }
}

/* ---------- Trang nội dung (Giới thiệu / Liên hệ) ---------- */
.page { max-width: 860px; }
.page h2 { font-size: 18px; margin: 32px 0 10px; }
.page p { margin: 0 0 12px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin: 8px 0 4px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat b { display: block; font-size: 26px; color: var(--accent); line-height: 1.2; }
.stat span { color: var(--muted); font-size: 13px; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.features .panel h3 { margin: 0 0 6px; font-size: 15px; }
.features .panel p { margin: 0; color: var(--muted); font-size: 14px; }
.contact-list { display: grid; gap: 0; padding: 0; }
.contact-row { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 12px; padding: 14px 22px; border-bottom: 1px solid var(--border); }
.contact-row:last-child { border-bottom: 0; }
.contact-row dt { color: var(--muted); font-size: 14px; }
.contact-row dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
@media (max-width: 500px) {
  .contact-row { grid-template-columns: 1fr; gap: 2px; }
}
.topbar .spacer { flex: 1; }
.user { color: var(--muted); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }

.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 48px; }
h1 { font-size: 24px; margin: 0 0 4px; }
.subtitle { color: var(--muted); margin: 0 0 24px; }

/* ---------- Danh sách khóa học ---------- */
.search { width: 100%; max-width: 360px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); margin-bottom: 20px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.card {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  transition: transform .15s, box-shadow .15s;
}
.card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.cover {
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: 700; color: var(--accent);
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title { font-weight: 600; font-size: 16px; margin: 0; }
.card-desc { color: var(--muted); font-size: 13px; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { color: var(--muted); font-size: 13px; margin-top: auto; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }

.empty { padding: 40px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }

/* ---------- Trang học ---------- */
.learn { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.player-wrap { background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; }
.player-wrap video { width: 100%; height: 100%; display: block; background: #000; }
.lesson-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 16px 0 6px; }
.lesson-head h1 { flex: 1; min-width: 200px; font-size: 20px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.controls select { padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.crumb { color: var(--muted); font-size: 14px; margin-bottom: 10px; }

.sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: calc(100vh - 100px);
  overflow: auto;
  position: sticky; top: 76px;
}
.sidebar-head { padding: 14px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.sidebar-head h2 { font-size: 16px; margin: 0 0 8px; }
.section-title { padding: 10px 16px 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
.lesson {
  display: flex; gap: 10px; align-items: flex-start;
  width: 100%; text-align: left;
  padding: 10px 16px;
  border: 0; border-bottom: 1px solid var(--border);
  background: transparent; cursor: pointer;
}
.lesson:hover { background: var(--surface-2); }
.lesson.active { background: var(--accent-soft); }
.lesson .num { flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); }
.lesson.done .num { background: var(--ok); color: #fff; }
.lesson.active .num { background: var(--accent); color: var(--accent-text); }
.lesson .t { flex: 1; font-size: 14px; }
.lesson.locked { cursor: not-allowed; color: var(--muted); }
.lesson.locked:hover { background: transparent; }
.lesson.locked .num { font-size: 11px; }

.notice {
  margin: 0; padding: 10px 16px;
  font-size: 13px; line-height: 1.45;
  border-bottom: 1px solid var(--border);
  background: var(--accent-soft); color: var(--text);
}
.notice.ok { background: color-mix(in srgb, var(--ok) 14%, var(--surface)); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 8px;
  background: var(--text); color: var(--bg);
  font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2);
  z-index: 50;
}
.lesson .s { display: block; color: var(--muted); font-size: 12px; }

/* ---------- Đăng nhập ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.login-box h1 { font-size: 22px; margin-bottom: 4px; }
.login-box label { display: block; font-size: 14px; margin: 16px 0 6px; }
.login-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.login-box input:focus, .search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login-box .btn { width: 100%; margin-top: 20px; padding: 11px; }
.error { color: var(--danger); font-size: 14px; margin-top: 12px; min-height: 1.2em; }

/* ---------- Quản trị ---------- */
.muted { color: var(--muted); }
.admin-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; }
.admin-head .subtitle { margin-bottom: 16px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; min-width: 640px; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.actions-col { text-align: right !important; white-space: nowrap; }
.actions-col .btn + .btn { margin-left: 6px; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 2px; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); font-size: 13px; }
.chip.warn { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--danger); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.admin { background: var(--accent-soft); color: var(--accent); }

.dialog { width: min(520px, calc(100% - 32px)); border: 1px solid var(--border); border-radius: 14px; padding: 24px; background: var(--surface); color: var(--text); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog h2 { margin: 0 0 4px; font-size: 18px; }
.dialog label:not(.check) { display: block; font-size: 14px; margin: 14px 0 6px; }
.dialog input:not([type=checkbox]), .dialog select { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.dialog input[readonly] { color: var(--muted); }
.hint { display: block; color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.course-pick { margin: 16px 0 0; padding: 10px 12px 12px; border: 1px solid var(--border); border-radius: 8px; max-height: 260px; overflow: auto; }
.course-pick legend { font-size: 14px; padding: 0 4px; }
.pick-tools { display: flex; gap: 12px; margin-bottom: 6px; }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-size: 13px; }
.check { display: flex; gap: 10px; align-items: center; padding: 6px 2px; cursor: pointer; font-size: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (max-width: 900px) {
  .learn { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .container { padding: 16px 16px 40px; }
  .player-wrap { border-radius: 0; margin: -16px -16px 0; }
}
