:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #1c2333;
  --muted: #64708a;
  --border: #e2e6ef;
  --primary: #4f46e5;
  --primary-soft: #eef0ff;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1320;
    --surface: #171c2c;
    --text: #e6e9f2;
    --muted: #9aa3b8;
    --border: #2a3147;
    --primary: #818cf8;
    --primary-soft: #23284a;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
p { margin: 0 0 1rem; }

/* Layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
}
.brand { font-weight: 700; font-size: 1.2rem; padding: 0 10px 18px; }
.brand span { color: var(--primary); }
.nav a {
  display: block; padding: 9px 12px; border-radius: 8px; color: var(--text);
}
.nav a:hover { background: var(--primary-soft); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar .me { margin-top: auto; padding: 12px; border-top: 1px solid var(--border); font-size: .9rem; }
.sidebar .me small { color: var(--muted); display: block; text-transform: capitalize; }
main { padding: 28px 32px; max-width: 1100px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.muted { color: var(--muted); }

/* Components */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stats { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 24px; }
.stat .num { font-size: 1.8rem; font-weight: 700; }
.stat .label { color: var(--muted); font-size: .9rem; }
.course-card { display: flex; flex-direction: column; gap: 8px; }
.course-card .cover {
  height: 90px; border-radius: 8px; margin: -4px -4px 6px;
  display: flex; align-items: flex-end; padding: 10px; color: #fff; font-weight: 600;
}
.course-card .meta { color: var(--muted); font-size: .85rem; }
.course-card .actions { margin-top: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 99px;
  background: var(--primary-soft); color: var(--primary); font-weight: 600;
}
.badge.success { background: rgba(22,163,74,.12); color: var(--success); }
.badge.warn { background: rgba(217,119,6,.12); color: var(--warn); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-size: .9rem;
}
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.progress { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); transition: width .3s; }

/* Forms */
label { display: block; font-size: .85rem; font-weight: 600; margin: 12px 0 4px; }
input, textarea, select {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table-wrap { overflow-x: auto; }

/* Course player */
.player { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.lesson-list { padding: 8px; }
.lesson-list a {
  display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 8px; color: var(--text);
}
.lesson-list a:hover { background: var(--primary-soft); text-decoration: none; }
.lesson-list a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.check {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border);
  flex-shrink: 0; display: grid; place-items: center; font-size: .7rem; color: #fff;
}
.check.done { background: var(--success); border-color: var(--success); }
.lesson-body { white-space: pre-wrap; }
.video { aspect-ratio: 16/9; width: 100%; border: 0; border-radius: 8px; margin-bottom: 16px; background: #000; }

/* Quiz */
.question { margin-bottom: 18px; }
.option { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin: 6px 0; cursor: pointer; font-weight: 400; }
.option input { width: auto; }
.option.correct { border-color: var(--success); background: rgba(22,163,74,.08); }
.option.wrong { border-color: var(--danger); background: rgba(220,38,38,.08); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 420px; }
.demo-users { display: grid; gap: 8px; margin-top: 16px; }
.demo-users button { justify-content: space-between; }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-size: .9rem; z-index: 50;
}
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.mt { margin-top: 16px; }

/* Mobile */
.menu-btn { display: none; }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; margin-bottom: 12px; }
  main { padding: 16px; }
  .player { grid-template-columns: 1fr; }
}
