:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --surface-3: #e3e7f3;
  --border: #e2e5ee;
  --text: #151a26;
  --muted: #677085;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eceeff;
  --accent-text: #ffffff;
  --success: #0f9d58;
  --success-soft: #e5f6ec;
  --warning: #b86e00;
  --warning-soft: #fff3dc;
  --danger: #d92d20;
  --danger-soft: #fdeceb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 2px 6px rgba(16, 24, 40, .05);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, .18);
  --radius: 12px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Tahoma, sans-serif;
  --mono: "Cascadia Mono", Consolas, ui-monospace, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1016;
    --surface: #161922;
    --surface-2: #1d212d;
    --surface-3: #262b3a;
    --border: #282d3b;
    --text: #e8eaf0;
    --muted: #98a0b3;
    --accent: #7b7fff;
    --accent-hover: #9396ff;
    --accent-soft: #23254d;
    --accent-text: #0e1016;
    --success: #3ccf7e;
    --success-soft: #11281b;
    --warning: #f2b544;
    --warning-soft: #2b2311;
    --danger: #f47067;
    --danger-soft: #2e1614;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 620; }
h3 { font-size: 14px; font-weight: 620; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.icon { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.hidden { display: none !important; }
[dir="auto"] { unicode-bidi: plaintext; }
/* Persian/Arabic text keeps its own direction but lines up with the LTR layout. */
[dir="auto"]:not(input):not(textarea) { text-align: left; }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; font-weight: 700; font-size: 17px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.brand-mark svg { width: 16px; height: 16px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 9px; color: var(--muted); font-weight: 520; }
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-badge { margin-left: auto; background: var(--accent); color: var(--accent-text); font-size: 11px; font-weight: 650; padding: 1px 7px; border-radius: 99px; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding: 14px 10px 0; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.sidebar-user { min-width: 0; }
.sidebar-user div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { padding: 28px 36px 60px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 240px; }
.page-head p { color: var(--muted); margin-top: 4px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.back .icon { width: 15px; height: 15px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 16px; overflow-x: auto; gap: 2px; }
  .brand { padding: 0 10px 0 0; }
  .brand span, .nav-link span, .sidebar-user { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .main { padding: 20px 16px 48px; }
}

/* ---------- Buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); font-weight: 560; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.icon-only { width: 32px; padding: 0; height: 32px; }
.btn.lg { height: 42px; padding: 0 20px; font-size: 15px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-weight: 580; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; }
.input, .select, .textarea { width: 100%; height: 38px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); outline: none; transition: border-color .12s, box-shadow .12s; }
.textarea { height: auto; min-height: 80px; padding: 9px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.search { position: relative; }
.search .icon { position: absolute; left: 11px; top: 10px; width: 17px; height: 17px; color: var(--muted); }
.search .input { padding-left: 36px; }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input[type="checkbox"] { appearance: none; width: 36px; height: 20px; border-radius: 99px; background: var(--border); position: relative; cursor: pointer; transition: background .15s; margin: 0; flex: none; }
.switch input[type="checkbox"]::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input[type="checkbox"]:checked { background: var(--accent); }
.switch input[type="checkbox"]:checked::after { transform: translateX(16px); }
input[type="range"] { accent-color: var(--accent); width: 100%; }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-body { padding: 20px; }
.card-body.flush { padding: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.stat-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.stat-value { font-size: 22px; font-weight: 680; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 12.5px; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 20px; }
@media (max-width: 1080px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.copy-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 3px 4px 3px 10px; font-family: var(--mono); font-size: 13px; white-space: nowrap; }
.copy-chip button { border: 0; background: transparent; cursor: pointer; color: var(--muted); display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; }
.copy-chip button:hover { background: var(--border); color: var(--text); }
.copy-chip .icon { width: 14px; height: 14px; }

/* ---------- Courses ---------- */
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.course-card { overflow: hidden; display: flex; flex-direction: column; color: inherit; transition: transform .12s, box-shadow .12s; }
.course-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.cover { aspect-ratio: 16 / 9; background: linear-gradient(135deg, var(--accent), #8b5cf6); display: grid; place-items: center; color: rgba(255,255,255,.85); position: relative; overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.cover .icon { width: 36px; height: 36px; }
.course-card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; }
.course-card .meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 12px; flex-wrap: wrap; }
.new-card { border: 2px dashed var(--border); background: transparent; box-shadow: none; display: grid; place-items: center; min-height: 220px; color: var(--muted); cursor: pointer; font-weight: 580; gap: 8px; }
.new-card:hover { border-color: var(--accent); color: var(--accent); }

.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center; cursor: pointer; transition: border-color .12s, background .12s; background: var(--surface); }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin: 0 auto 10px; }
.dropzone h3 { font-size: 15px; }

.lesson { display: grid; grid-template-columns: 22px 34px 96px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.lesson:last-child { border-bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }
.lesson.dragging { opacity: .45; }
.lesson.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.lesson.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.grip { cursor: grab; color: var(--muted); display: grid; place-items: center; }
.lesson-num { width: 30px; height: 30px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-weight: 650; font-size: 13px; color: var(--muted); }
.thumb { width: 96px; aspect-ratio: 16/9; border-radius: 7px; background: var(--surface-2); overflow: hidden; display: grid; place-items: center; color: var(--muted); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.lesson-title { font-weight: 580; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lesson-meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; align-items: center; }
.lesson-actions { display: flex; gap: 4px; }
@media (max-width: 700px) {
  .lesson { grid-template-columns: 30px minmax(0, 1fr) auto; }
  .lesson .grip, .lesson .thumb { display: none; }
}

.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; min-width: 120px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.progress.indeterminate > div { width: 35% !important; animation: slide 1.1s infinite ease-in-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

.upload-item { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.upload-item:last-child { border-bottom: 0; }

/* ---------- Detail / key-value ---------- */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 18px 24px; }
.kv .k { color: var(--muted); font-size: 12px; margin-bottom: 3px; }
.kv .v { font-weight: 580; }
.key-hero { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 18px 20px; background: var(--accent-soft); border-radius: var(--radius); }
.key-hero .key { font-family: var(--mono); font-size: 20px; font-weight: 650; letter-spacing: .03em; color: var(--accent); word-break: break-all; }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: 0; }
.feed .dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--muted); }
.feed .dot .icon { width: 15px; height: 15px; }
.feed .dot.success { background: var(--success-soft); color: var(--success); }
.feed .dot.danger { background: var(--danger-soft); color: var(--danger); }
.feed .dot.accent { background: var(--accent-soft); color: var(--accent); }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .big-icon { width: 56px; height: 56px; border-radius: 16px; background: var(--surface-2); display: grid; place-items: center; margin: 0 auto 14px; }
.empty .big-icon .icon { width: 26px; height: 26px; }
.empty h3 { color: var(--text); font-size: 16px; margin-bottom: 4px; }
.empty .btn { margin-top: 16px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 32px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 560; font-size: 13px; color: var(--muted); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.callout { display: flex; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); font-size: 13px; }
.callout .icon { color: var(--accent); margin-top: 1px; }
.callout.warning { background: var(--warning-soft); }
.callout.warning .icon { color: var(--warning); }
.callout.danger { background: var(--danger-soft); }
.callout.danger .icon { color: var(--danger); }

pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; margin: 0; white-space: pre; }

.spinner { width: 22px; height: 22px; border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 80px; }

/* ---------- Course picker in license form ---------- */
.course-pick { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.course-pick-item { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.course-pick-item:last-child { border-bottom: 0; }
.course-pick-item.on { background: var(--accent-soft); }
.course-pick-item label.head { display: flex; gap: 10px; align-items: center; cursor: pointer; font-weight: 580; }
.course-pick-item .range { margin: 10px 0 2px 26px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.course-pick-item .range .input { max-width: 220px; height: 34px; }

.form-section { display: flex; flex-direction: column; gap: 14px; }
.form-section + .form-section { border-top: 1px solid var(--border); padding-top: 20px; }
.form-section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }

.wm-preview { position: relative; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: linear-gradient(135deg, #1f2937, #0f172a); }
.wm-preview .wm { position: absolute; color: #fff; font-weight: 600; white-space: nowrap; text-shadow: 0 0 2px rgba(0,0,0,.8); transition: all .6s ease; }
.wm-preview .play { position: absolute; inset: 0; display: grid; place-items: center; color: rgba(255,255,255,.25); }
.wm-preview .play .icon { width: 44px; height: 44px; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 12, 20, .55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 520px; box-shadow: var(--shadow-lg); animation: pop .18s ease-out; border: 1px solid var(--border); }
.modal.lg { max-width: 760px; }
.modal.xl { max-width: 960px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; font-size: 17px; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 16px 16px; }
.modal video, .modal audio { width: 100%; display: block; border-radius: 10px; background: #000; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ---------- Toasts ---------- */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 520; animation: pop .2s; max-width: 380px; }
.toast.error { background: var(--danger); color: #fff; }
.toast .icon { width: 17px; height: 17px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: linear-gradient(145deg, #312e81, #4f46e5 55%, #7c3aed); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side h1 { font-size: 34px; max-width: 460px; }
.auth-side ul { list-style: none; padding: 0; margin: 28px 0 0; display: flex; flex-direction: column; gap: 14px; }
.auth-side li { display: flex; gap: 12px; align-items: center; opacity: .92; }
.auth-side li .icon { background: rgba(255,255,255,.15); border-radius: 8px; padding: 6px; width: 30px; height: 30px; }
.auth-form { display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.auth-card .btn { width: 100%; }
@media (max-width: 860px) { .auth { grid-template-columns: 1fr; } .auth-side { display: none; } }
