:root {
  --bg: #f4f6f8; --surface: #ffffff; --surface-2: #f0f3f6; --text: #16202a; --muted: #5d6b79;
  --line: #e3e6ea; --accent: #c2410c; --accent-ink: #ffffff; --accent-soft: #ffedd5;
  --danger: #b42318; --danger-soft: #fde8e6; --warn: #92400e; --warn-soft: #fef0d0;
  --ok: #166534; --ok-soft: #dcf5e4; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.06);
  --radius: 12px;
  --font: "IBM Plex Sans Arabic", "Segoe UI", "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma, system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151b; --surface: #17202a; --surface-2: #1e2935; --text: #e8eef4; --muted: #9aa9b8;
    --line: #2b3946; --accent: #fb923c; --accent-ink: #1f0f02; --accent-soft: #3a1e0a;
    --danger: #ff8a80; --danger-soft: #3b1a18; --warn: #fbbf4a; --warn-soft: #3a2b0c;
    --ok: #6ee7a0; --ok-soft: #12301f; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.6 var(--font); }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.ltr { direction: ltr; unicode-bidi: embed; text-align: left; display: inline-block; }
.num { font-variant-numeric: tabular-nums; }

/* layout */
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: #2b3137; display: grid; place-items: center; overflow: hidden; flex: none; }
.brand-mark img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.32); display: block; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; }

/* sidebar layout */
:root { --side-w: 268px; --side-bg: #1c2126; --side-bg-2: #252b31; --side-text: #c6ccd3; --side-muted: #7f8892; --side-line: rgba(255,255,255,.07); --brand-or: #ff7a1a; }
.layout { min-height: 100vh; }
.sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--side-w); z-index: 40; display: flex; flex-direction: column;
  background: radial-gradient(120% 60% at 100% 0%, rgba(255,122,26,.16), transparent 60%), var(--side-bg); color: var(--side-text);
  border-inline-end: 1px solid var(--side-line); }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 18px 14px; }
.side-brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.side-brand .brand-mark { width: 42px; height: 42px; border-radius: 12px; box-shadow: 0 8px 22px rgba(255,122,26,.28), inset 0 0 0 1px rgba(255,255,255,.08); }
.side-brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.side-brand-text b { direction: ltr; color: #fff; letter-spacing: .14em; font-size: .92rem; font-weight: 800; text-align: right; }
.side-brand-text .b-or { color: var(--brand-or); }
.side-brand-text small { color: var(--side-muted); font-size: .76rem; }
.side-nav { flex: 1; overflow-y: auto; padding: 6px 12px 12px; scrollbar-width: thin; scrollbar-color: #3a424a transparent; }
.side-group + .side-group { margin-top: 14px; }
.side-label { font-size: .72rem; font-weight: 700; color: var(--side-muted); padding: 6px 12px; }
.side-nav a { position: relative; display: flex; align-items: center; gap: 12px; padding: 8px 10px; margin: 2px 0; border-radius: 12px;
  color: var(--side-text); text-decoration: none; font-weight: 600; font-size: .93rem; transition: background .15s, color .15s; }
.side-nav a:hover { background: var(--side-bg-2); color: #fff; }
.side-nav a.active { background: linear-gradient(270deg, rgba(255,122,26,.22), rgba(255,122,26,.06)); color: #fff; }
.side-ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: rgba(255,255,255,.04); color: #9aa3ad; flex: none; transition: background .15s, color .15s; }
.side-nav a:hover .side-ic { color: #fff; }
.side-nav a.active .side-ic { background: var(--brand-or); color: #fff; box-shadow: 0 6px 16px rgba(255,122,26,.35); }
.side-text { flex: 1; min-width: 0; }
.side-nav .nav-badge { margin: 0; }
.side-foot { padding: 12px; border-top: 1px solid var(--side-line); display: grid; gap: 8px; }
.side-link { display: flex; align-items: center; gap: 8px; padding: 6px 12px; color: var(--side-muted); text-decoration: none; font-size: .84rem; border-radius: 10px; }
.side-link:hover { color: #fff; background: var(--side-bg-2); }
.user-card { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; background: var(--side-bg-2); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; flex: none;
  background: linear-gradient(135deg, #ff7a1a, #c2410c); }
.user-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.user-meta b { color: #fff; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { color: var(--side-muted); font-size: .76rem; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; border: 0; cursor: pointer; background: transparent; color: inherit; flex: none; }
.icon-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.icon-btn:focus-visible, .side-nav a:focus-visible, .side-link:focus-visible { outline: 2px solid var(--brand-or); outline-offset: 2px; }
.user-card .icon-btn { color: var(--side-muted); }
.user-card .icon-btn:hover { color: #ff9a52; background: rgba(255,122,26,.12); }
.side-close { display: none; }
.content { margin-inline-start: var(--side-w); min-width: 0; }
.mobilebar { display: none; }
.scrim { display: none; }
main { max-width: 1200px; margin: 0 auto; padding: 28px 28px 60px; }

@media (max-width: 960px) {
  .content { margin-inline-start: 0; }
  .sidebar { transform: translateX(100%); transition: transform .25s ease; }
  body.drawer-open .sidebar { transform: none; box-shadow: -20px 0 60px rgba(0,0,0,.35); }
  body.drawer-open { overflow: hidden; }
  .side-close { display: grid; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(15,18,22,.5); opacity: 0; pointer-events: none; transition: opacity .25s; }
  body.drawer-open .scrim { opacity: 1; pointer-events: auto; }
  .mobilebar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30; padding: 10px 14px;
    background: var(--side-bg); color: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.15); }
  .mobilebar .brand-mark { width: 32px; height: 32px; border-radius: 9px; }
  main { padding: 18px 16px 60px; }
}
@media (prefers-reduced-motion: reduce) { .sidebar, .scrim { transition: none; } }
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.crumbs { font-size: .85rem; margin-bottom: 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.link { display: block; color: inherit; text-decoration: none; transition: border-color .15s, transform .15s; }
.card.link:hover { border-color: var(--accent); transform: translateY(-1px); }
.card h3 { margin-bottom: 4px; }

/* buttons & fields */
.btn { font: inherit; font-weight: 600; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 7px 14px; border-radius: 9px; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 3px 10px; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
label.field { display: block; margin-bottom: 12px; }
label.field > span.lbl { display: block; font-weight: 600; margin-bottom: 4px; font-size: .9rem; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 3px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
textarea { min-height: 110px; resize: vertical; }
.form-grid { display: grid; gap: 0 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.inline-check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 16px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }

/* table */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 12px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: var(--surface-2); font-size: .82rem; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: end; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: .78rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 12px; }

/* states */
.empty, .loading { text-align: center; color: var(--muted); padding: 36px 12px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; margin-inline-end: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; background: var(--warn-soft); color: var(--warn); border: 1px solid currentColor; }
.alert.bad { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; min-width: 80px; }
.progress > i { display: block; height: 100%; background: var(--accent); }
.pw { font-family: ui-monospace, Consolas, monospace; direction: ltr; unicode-bidi: embed; display: inline-block; user-select: all; background: var(--surface-2); padding: 1px 8px; border-radius: 6px; }
pre.box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; max-height: 260px; overflow: auto; direction: ltr; text-align: left; }
.codes-box { columns: 3 140px; }

/* quiz */
.q-card { margin-bottom: 10px; }
.opt { padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); margin-top: 6px; display: flex; gap: 8px; align-items: center; }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.chosen { border-color: var(--accent); }
.opt.chosen.wrong { border-color: var(--danger); background: var(--danger-soft); }
.essay-ans { white-space: pre-wrap; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; margin-top: 6px; }
.opt-edit { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }

/* modal & toast */
dialog.modal { padding: 0; color: var(--text); background: var(--surface); border-radius: 14px; width: min(640px, calc(100vw - 24px)); max-height: 92vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.35); border: 1px solid var(--line); }
dialog.modal.wide { width: min(860px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(8,12,16,.55); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-start; flex-wrap: wrap; }
.x { border: 0; background: transparent; color: var(--muted); font-size: 1.4rem; cursor: pointer; line-height: 1; }
.toasts { position: fixed; bottom: 16px; inset-inline-start: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 600; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@media (prefers-color-scheme: dark) { .toast.ok { color: #04140a; } .toast.error { color: #1a0604; } }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); }
.login-card .brand-mark { width: 44px; height: 44px; font-size: 1.3rem; border-radius: 12px; margin-bottom: 12px; }

@media (max-width: 640px) {
  .userbox .name { display: none; }
  main { padding-top: 14px; }
  th, td { padding: 8px; }
}
@media print { .sidebar, .mobilebar, .scrim, .no-print, .toasts { display: none !important; } body { background: #fff; } }
.stat { text-align: center; }
.stat-n { font-size: 2rem; font-weight: 800; color: var(--accent); }

/* dashboard & chart */
.tiles { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.stat.warn .stat-n { color: var(--warn); }
.stat-n { font-size: 1.8rem; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child { border-bottom: 0; }
:root { --c1: #ff7a1a; --c2: #2b3137; }
@media (prefers-color-scheme: dark) { :root { --c1: #fb923c; --c2: #cbd5e1; } }
.chart { margin: 0; }
.chart figcaption { font-weight: 700; margin-bottom: 6px; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-tick { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart-bar.s1, .sw.s1 { fill: var(--c1); background: var(--c1); }
.chart-bar.s2, .sw.s2 { fill: var(--c2); background: var(--c2); }
.chart-legend { display: flex; gap: 14px; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; }
.chart-data { margin-top: 8px; font-size: .85rem; }
.chart-data summary { cursor: pointer; color: var(--muted); }

/* nav badge, thumbnails, misc */
.nav-badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-inline-start: 6px; border-radius: 99px; background: var(--danger); color: #fff; font-size: .72rem; text-align: center; line-height: 18px; }
.nav-badge[hidden] { display: none; }
.q-thumb { max-width: 160px; max-height: 110px; border-radius: 8px; border: 1px solid var(--line); object-fit: contain; background: var(--surface-2); display: block; margin: 6px 0; }
.ans-img { max-width: 220px; max-height: 180px; border-radius: 8px; border: 1px solid var(--line); object-fit: contain; background: var(--surface-2); display: block; min-width: 40px; min-height: 40px; }
.q-card.hard { border-color: var(--danger); }
.progress.bad > i { background: var(--danger); }
.note { margin-bottom: 10px; }

/* platform catalog */
.catalog-settings { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr) minmax(280px, 420px); align-items: center; margin-bottom: 18px; }
.catalog-settings h2 { margin-bottom: 2px; }
.catalog-settings p { margin: 0; }
@media (max-width: 720px) { .catalog-settings { grid-template-columns: 1fr; } }
.cat-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.cat-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; transition: border-color .15s, transform .15s; }
.cat-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.cat-card.is-hidden .cat-cover { filter: grayscale(.85); opacity: .7; }
.cat-cover { position: relative; aspect-ratio: 16 / 9; background: linear-gradient(135deg, #2b3137, #7a2e06 70%, #ff7a1a); display: grid; place-items: center; }
.cat-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cat-cover-ph { font-size: 2.6rem; font-weight: 800; color: rgba(255,255,255,.85); }
.cat-chip { position: absolute; top: 10px; inset-inline-start: 10px; background: rgba(20,24,28,.72); color: #fff; font-size: .75rem; font-weight: 600; padding: 3px 10px; border-radius: 99px; backdrop-filter: blur(4px); }
.cat-body { padding: 14px 16px 16px; display: grid; gap: 10px; }
.cat-body h3 { margin: 0 0 2px; font-size: 1.02rem; }
.cat-price { font-weight: 800; color: var(--accent); font-size: 1.05rem; }
.cat-stats { gap: 12px; }
.cat-thumb { width: 160px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.switch { position: relative; display: inline-flex; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-ui { width: 42px; height: 24px; border-radius: 99px; background: var(--line); position: relative; transition: background .2s; }
.switch-ui::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: inset-inline-start .2s; }
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { inset-inline-start: 21px; }
.switch input:focus-visible + .switch-ui { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.link .course-cover { display: block; width: calc(100% + 32px); margin: -16px -16px 12px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius) var(--radius) 0 0; border-bottom: 1px solid var(--line); }
.ad-card .ad-img { position: relative; aspect-ratio: 16 / 7; border-radius: 12px; overflow: hidden; background: var(--line); }
.ad-card .ad-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ad-card .ad-title { position: absolute; inset-inline: 0; bottom: 0; padding: 22px 12px 10px; color: #fff; font-weight: 800; background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.nivex-credit { margin: 12px 0 0; text-align: center; font-size: .78rem; color: var(--muted); }
.nivex-credit a { color: var(--accent); font-weight: 700; }
.side-foot .nivex-credit { margin: 0; color: var(--side-muted); }
.side-foot .nivex-credit a { color: var(--brand-or); }
.lesson-picker { max-height: 260px; overflow-y: auto; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg, #f6f7f9); }
.lesson-picker[hidden] { display: none; }
.lesson-pick { display: flex; align-items: center; gap: 8px; padding: 6px 2px; cursor: pointer; }
.filter-box { margin-bottom: 14px; }
.filter-box input { width: 100%; max-width: 420px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font: inherit; }
.filter-box input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
