:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --ink: #1e2130;
  --muted: #6b7088;
  --brand: #6d28d9;
  --brand-2: #8b5cf6;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --line: #e5e7f0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(30, 33, 48, .06), 0 8px 24px rgba(30, 33, 48, .05);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Cairo", "Noto Kufi Arabic", system-ui, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
a { color: var(--brand); text-decoration: none; }

/* ---------- login ---------- */
.login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #6d28d982, #0f0f1e 70%);
  padding: 24px;
}
.login-card {
  background: var(--card); border-radius: 20px; padding: 40px 36px; width: 100%; max-width: 400px;
  box-shadow: 0 30px 60px rgba(0,0,0,.35);
}
.login-logo { font-size: 44px; text-align: center; }
.login-card h1 { font-size: 22px; text-align: center; margin-top: 8px; }
.login-card .muted { text-align: center; margin: 4px 0 22px; }
.login-card label { display: block; font-weight: 600; font-size: 13px; margin: 14px 0 6px; color: var(--muted); }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px;
  font-size: 15px; outline: none; transition: border .15s;
}
.login-card input:focus { border-color: var(--brand); }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; background: #151322; color: #e6e3f5; padding: 18px 14px;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 8px 10px 20px; }
.brand-ico { font-size: 22px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar nav a {
  color: #b6b1d6; padding: 11px 14px; border-radius: 10px; font-weight: 500; font-size: 14.5px;
  display: flex; align-items: center; gap: 9px; transition: background .15s, color .15s;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.09); padding-top: 14px; }
.teacher-info { font-size: 13px; padding: 4px 8px 12px; color: #b6b1d6; }
.main { flex: 1; min-width: 0; padding: 0 26px 40px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 0 18px; position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.topbar h2 { font-size: 20px; }
.topbar-actions { display: flex; gap: 8px; }

/* ---------- cards & grids ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px;
}
.card h3 { font-size: 16px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.stat { padding: 18px; }
.stat .num { font-size: 28px; font-weight: 800; margin-top: 6px; }
.stat .label { color: var(--muted); font-size: 13.5px; font-weight: 600; }
.stat .ico { font-size: 22px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1.5px solid transparent; border-radius: 10px; padding: 9px 16px; font-size: 14px;
  font-weight: 600; cursor: pointer; transition: opacity .12s, transform .06s; font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: #5b21b6; }
.btn-ghost { background: transparent; color: #b6b1d6; border-color: rgba(255,255,255,.25); }
.btn-ghost:hover { color: #fff; border-color: rgba(255,255,255,.5); }
.btn-light { background: #f0eeff; color: var(--brand); border-color: #e3deff; }
.btn-danger { background: #fef2f2; color: var(--bad); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-success { background: #f0fdf4; color: var(--ok); border-color: #bbf7d0; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 12.5px; font-weight: 700; white-space: nowrap; background: #fafaff; }
tr:hover td { background: #faf9ff; }

/* ---------- badges & status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; background: #eef2ff; color: var(--brand);
  border-radius: 30px; padding: 3px 11px; font-size: 12px; font-weight: 700;
}
.badge-warn { background: #fffbeb; color: var(--warn); }
.badge-ok { background: #f0fdf4; color: var(--ok); }
.badge-bad { background: #fef2f2; color: var(--bad); }
.badge-gray { background: #f1f5f9; color: var(--muted); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-inline-end: 6px; }
.dot-ok { background: var(--ok); }
.dot-bad { background: var(--bad); }
.dot-warn { background: var(--warn); }

/* ---------- forms ---------- */
label.field { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 5px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px;
  font-size: 14px; font-family: inherit; outline: none; background: #fff;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
textarea { resize: vertical; min-height: 90px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ---------- content tree ---------- */
.course-block { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.course-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: #fafaff;
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.course-head .titles { flex: 1; min-width: 200px; }
.course-head h4 { font-size: 16px; }
.course-head .sub { color: var(--muted); font-size: 12.5px; }
.section-block { margin: 10px 14px; border: 1px solid var(--line); border-radius: 12px; }
.section-head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; background: #f7f6ff; border-bottom: 1px solid var(--line); }
.chapter-row { padding: 9px 14px; border-bottom: 1px dashed var(--line); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lesson-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px 9px 10px;
  border-bottom: 1px solid var(--line); background: #fff; flex-wrap: wrap;
}
.lesson-row:last-child { border-bottom: none; }
.lesson-title { flex: 1; min-width: 180px; font-weight: 600; font-size: 14px; }
.lesson-meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 10px; align-items: center; }
.icon-btn {
  background: none; border: none; cursor: pointer; font-size: 16px; border-radius: 8px;
  padding: 4px 7px; transition: background .12s; line-height: 1;
}
.icon-btn:hover { background: #eeeaff; }
.icon-btn.danger:hover { background: #fee2e2; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10,8,20,.55); display: flex;
  align-items: flex-start; justify-content: center; z-index: 50; padding: 6vh 18px 18px; overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 640px;
  padding: 22px; box-shadow: 0 30px 70px rgba(0,0,0,.4); animation: pop .16s ease;
}
.modal.wide { max-width: 860px; }
.modal h3 { margin-bottom: 4px; }
.modal .close-x { float: left; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- toast ---------- */
#toast-root { position: fixed; bottom: 22px; right: 22px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #151322; color: #fff; border-radius: 10px; padding: 12px 18px; font-size: 14px;
  box-shadow: 0 12px 30px rgba(0,0,0,.3); animation: pop .18s ease; max-width: 340px;
}
.toast.ok { background: #14532d; }
.toast.err { background: #7f1d1d; }

/* ---------- misc ---------- */
.chip { display: inline-block; background: #f1f5f9; border-radius: 20px; padding: 2px 10px; font-size: 12px; margin: 2px; }
.progress-bar { height: 8px; background: #eef0f7; border-radius: 20px; overflow: hidden; min-width: 90px; }
.progress-bar > i { display: block; height: 100%; background: var(--brand); border-radius: 20px; }
.mono { font-family: ui-monospace, "Cascadia Code", monospace; font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 34px 10px; font-size: 14.5px; }
.empty .big { font-size: 34px; display: block; margin-bottom: 8px; }
.error-text { color: var(--bad); font-size: 13.5px; margin-top: 10px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 280px; }
.spread { justify-content: space-between; }
.pill-success { background:#dcfce7; color:#166534; border-radius:20px; padding:2px 10px; font-size:12px; font-weight:600; }
.pill-pending { background:#ffedd5; color:#9a3412; border-radius:20px; padding:2px 10px; font-size:12px; font-weight:600; }
.pill-fail { background:#fee2e2; color:#991b1b; border-radius:20px; padding:2px 10px; font-size:12px; font-weight:600; }

@media (max-width: 900px) {
  .sidebar { width: 72px; }
  .sidebar nav a span, .brand span:not(.brand-ico) { display: none; }
  .sidebar nav a { justify-content: center; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}