/* ============================================================
   PY10 — نظام التصميم
   ============================================================ */
:root {
  --ink-900: #070b16;
  --ink-800: #0c1226;
  --ink-700: #121a33;
  --ink-600: #1a2445;
  --line: #22305a;
  --text: #e8ecf8;
  --muted: #9aa6c9;
  --accent: #5b7cfa;
  --accent-2: #9b6cf7;
  --accent-soft: rgba(91, 124, 250, .14);
  --ok: #34d39b;
  --warn: #f5b942;
  --bad: #f4616f;
  --radius-s: 8px;
  --radius: 14px;
  --radius-l: 20px;
  --shadow: 0 10px 30px rgba(3, 6, 18, .45);
  --shadow-s: 0 2px 10px rgba(3, 6, 18, .3);
  --font: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --bg: var(--ink-900);
  --surface: var(--ink-800);
  --surface-2: var(--ink-700);
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="light"] {
  --bg: #f2f4fb;
  --surface: #ffffff;
  --surface-2: #f7f9ff;
  --line: #dfe4f3;
  --text: #131a30;
  --muted: #5f6b8c;
  --accent-soft: rgba(91, 124, 250, .1);
  --shadow: 0 10px 28px rgba(20, 30, 70, .1);
  --shadow-s: 0 2px 8px rgba(20, 30, 70, .08);
}

*, *::before, *::after { box-sizing: inherit; }

/* العناصر المخفية تبقى مخفية مهما كان نوع العرض المعطى لها (مثل .btn) */
[hidden] { display: none !important; }

html { scroll-padding-top: env(safe-area-inset-top, 0px); }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.3; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; max-width: 68ch; }
small { color: var(--muted); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------- الهيكل */
.shell { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-inline-start: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.brand { display: block; padding: .3rem .4rem 1.2rem; }
.brand-mark {
  font-family: var(--mono);
  font-size: 1.5rem;
  letter-spacing: .06em;
  background: linear-gradient(105deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-mark b { font-weight: 500; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem .7rem;
  border-radius: var(--radius-s);
  color: var(--muted);
  font-size: .95rem;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--accent-soft); color: var(--text); font-weight: 500; }
.nav-ico { width: 1.2rem; text-align: center; opacity: .8; }

.badge {
  margin-inline-start: auto;
  background: var(--accent);
  color: #fff;
  font-size: .72rem;
  padding: .05rem .45rem;
  border-radius: 999px;
}

.sidebar-foot { border-top: 1px solid var(--line); padding-top: .9rem; display: grid; gap: .6rem; }
.who { display: flex; align-items: center; gap: .6rem; }
.who-text { display: grid; line-height: 1.25; overflow: hidden; }
.who-text b { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-text small { font-size: .75rem; }
.avatar {
  width: 36px; height: 36px; flex: none;
  border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 600; font-size: .85rem;
}

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: .8rem 1.4rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 30;
  backdrop-filter: blur(8px);
}

.crumbs { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); flex-wrap: wrap; }
.crumbs a:hover { color: var(--text); }
.crumbs .current { color: var(--text); font-weight: 500; }
.crumbs .sep { opacity: .45; display: inline-block; }
[dir="rtl"] .crumbs .sep { transform: scaleX(-1); }

.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: .5rem; }
.quick-search input {
  width: 230px; max-width: 40vw;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: .45rem .9rem; font-family: var(--font); font-size: .85rem;
}
.icon-btn {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 1rem;
}
.icon-btn:hover { background: var(--surface-2); }
.only-mobile { display: none; }

.content { padding: 1.5rem 1.4rem 3rem; flex: 1; }
.foot { padding: 1rem 1.4rem 2rem; color: var(--muted); font-size: .8rem; border-top: 1px solid var(--line); }

/* ---------------------------------------------- عناصر */
.page-head { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { color: var(--muted); margin: 0; }
.page-head .spacer { margin-inline-start: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.card + .card { margin-top: 1rem; }
.card-title { display: flex; align-items: center; gap: .6rem; margin-bottom: .9rem; }
.card-title h2 { margin: 0; }
.card-title a { margin-inline-start: auto; font-size: .85rem; color: var(--accent); }

.grid { display: grid; gap: 1rem; }
/* بدون هذا يرفض عنصر الشبكة أن يصغر عن أطول سطر بداخله فيتمدّد ويركب على جاره */
.grid > * { min-width: 0; }
.card, .stat, .video-card, .list-row { min-width: 0; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(min(125px, 100%), 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat .value { font-size: clamp(1.25rem, 2.2vw, 1.6rem); font-weight: 600; font-family: var(--mono); letter-spacing: -.02em; white-space: nowrap; text-align: start; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value .unit { font-size: .55em; color: var(--muted); margin-inline-start: .3em; font-weight: 500; }
.stat .sub { color: var(--muted); font-size: .75rem; }

/* أزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid transparent; border-radius: 10px;
  padding: .55rem 1rem; font: 500 .9rem/1.2 var(--font);
  cursor: pointer; transition: background .15s, border-color .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #4a6bf0; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn-danger:hover { background: rgba(244, 97, 111, .12); }
.btn-ok { background: var(--ok); color: #05261c; }
.btn-block { width: 100%; }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* نماذج */
.field { display: grid; gap: .35rem; margin-bottom: .9rem; }
.field label { font-size: .85rem; color: var(--muted); }
.field input, .field select, .field textarea, .input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .6rem .8rem;
  color: var(--text);
  font: 400 .95rem/1.5 var(--font);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: none; }
.field .help { font-size: .78rem; color: var(--muted); }
.field .error { color: var(--bad); font-size: .82rem; }
.form-error-inline { color: var(--bad); font-size: .88rem; margin: .6rem 0 0; min-height: 1.2em; }
.notice { border: 1px solid rgba(245, 185, 66, .45); background: rgba(245, 185, 66, .08); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.notice p { margin: 0 0 .6rem; }
.checkline { display: flex; align-items: center; gap: .5rem; }
.checkline input { width: auto; }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }

/* رسائل */
.messages { padding: .8rem 1.4rem 0; display: grid; gap: .5rem; }
.flash { padding: .65rem .9rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: .9rem; }
.flash-success { border-color: rgba(52, 211, 155, .5); }
.flash-error { border-color: rgba(244, 97, 111, .5); }
.flash-warning { border-color: rgba(245, 185, 66, .5); }

/* شارات الحالة */
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .75rem; padding: .18rem .55rem; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); background: var(--surface-2);
}
.chip-ok { color: var(--ok); border-color: rgba(52, 211, 155, .4); }
.chip-warn { color: var(--warn); border-color: rgba(245, 185, 66, .4); }
.chip-bad { color: var(--bad); border-color: rgba(244, 97, 111, .4); }
.chip-mono { font-family: var(--mono); }

/* أشرطة التقدّم */
.bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.bar-lg { height: 10px; }

/* جداول */
.table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: .7rem .9rem; text-align: start; border-bottom: 1px solid var(--line); font-size: .88rem; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.row-actions { display: flex; gap: .35rem; }

/* قوائم */
.list { display: grid; gap: .5rem; }
.list-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem .85rem; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface);
}
.list-row .grow { flex: 1; min-width: 0; }
.list-row > :not(.grow) { flex-shrink: 0; }
.list-row .grow b { display: block; font-weight: 500; }
.list-row .grow small { display: block; }
.trunc { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* بطاقات الفيديو */
.video-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
}
.video-card:hover { border-color: var(--accent); }
.thumb {
  aspect-ratio: 16 / 9; background: var(--surface-2); position: relative;
  display: grid; place-items: center; color: var(--muted);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .time {
  position: absolute; inset-block-end: .5rem; inset-inline-end: .5rem;
  background: rgba(7, 11, 22, .82); color: #fff;
  font-family: var(--mono); font-size: .72rem; padding: .1rem .4rem; border-radius: 6px;
}
.video-card .body { padding: .8rem .9rem; display: grid; gap: .4rem; flex: 1; }
.video-card .body h3 { margin: 0; font-size: .95rem; }
.video-card .meta { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* مشغّل */
.player { background: #000; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.player video { width: 100%; display: block; max-height: 72vh; background: #000; }
.player-side { display: grid; gap: .75rem; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .7rem; }
.meta-grid div { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: .55rem .7rem; }
.meta-grid span { display: block; color: var(--muted); font-size: .75rem; }
.meta-grid b { font-weight: 500; font-size: .9rem; }

/* منطقة الرفع */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius-l);
  padding: 2.2rem 1.2rem; text-align: center; background: var(--surface-2);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big { font-size: 1.05rem; font-weight: 500; }
.file-preview { display: grid; gap: .3rem; text-align: start; }
.upload-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; margin-top: .8rem; }
.upload-stats div { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: .5rem .7rem; }
.upload-stats span { display: block; font-size: .72rem; color: var(--muted); }
.upload-stats b { font-family: var(--mono); font-size: .9rem; font-weight: 500; }
.percent { font-family: var(--mono); font-size: 2rem; font-weight: 600; }

/* حالات فارغة */
.empty { text-align: center; padding: 3rem 1rem; border: 1px dashed var(--line); border-radius: var(--radius-l); background: var(--surface); }
.empty h2 { margin-bottom: .3rem; }
.empty p { margin: 0 auto .9rem; color: var(--muted); }

/* صفحة الدخول */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.auth-art {
  background: radial-gradient(1200px 600px at 80% 10%, rgba(155, 108, 247, .22), transparent 60%),
              radial-gradient(900px 500px at 10% 90%, rgba(91, 124, 250, .22), transparent 55%),
              var(--ink-900);
  color: #e8ecf8;
  padding: 3rem; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-art .logo { font-family: var(--mono); font-size: 3.2rem; letter-spacing: .04em; }
.auth-art .logo b { color: var(--accent); font-weight: 500; }
.auth-art .pitch { max-width: 34ch; font-size: 1.05rem; color: #b8c2e0; }
.auth-art ul { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; gap: .5rem; color: #b8c2e0; font-size: .9rem; }
.auth-art li::before { content: "—"; color: var(--accent); margin-inline-end: .5rem; }
.auth-form { display: grid; place-items: center; padding: 2rem; background: var(--bg); }
.auth-box { width: min(380px, 100%); }
.auth-box h1 { margin-bottom: .2rem; }
.auth-box .sub { color: var(--muted); margin-bottom: 1.5rem; }
.pw-wrap { position: relative; }
/* الخانة باتجاه ltr داخل صفحة rtl: نستخدم اتجاهات فعلية حتى لا يركب الزر فوق النص */
.pw-wrap input { padding-left: 4.5rem; }
[dir="ltr"] .pw-wrap input { padding-left: .8rem; padding-right: 4.5rem; }
[dir="ltr"] .pw-wrap button { left: auto; right: .6rem; }
.pw-wrap button {
  position: absolute; left: .6rem; right: auto; inset-block-start: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: .8rem;
}
.form-error { background: rgba(244, 97, 111, .1); border: 1px solid rgba(244, 97, 111, .45); color: var(--bad); border-radius: 10px; padding: .6rem .8rem; font-size: .88rem; margin-bottom: .9rem; }

/* حوار التأكيد */
dialog.modal {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 1.3rem;
  width: min(420px, 92vw); box-shadow: var(--shadow);
}
dialog.modal::backdrop { background: rgba(3, 6, 18, .6); }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-start; margin-top: 1.1rem; }

/* ترقيم الصفحات */
.pager { display: flex; gap: .4rem; justify-content: center; margin-top: 1.4rem; flex-wrap: wrap; }
.pager a, .pager span { padding: .35rem .7rem; border: 1px solid var(--line); border-radius: 8px; font-size: .85rem; }
.pager .on { background: var(--accent); border-color: var(--accent); color: #fff; }

.scrim { position: fixed; inset: 0; background: rgba(3, 6, 18, .55); z-index: 35; }

/* صفحة الخطأ */
.errorpage { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: 2rem; }
.errorpage .code { font-family: var(--mono); font-size: 4rem; color: var(--accent); }

/* ---------------------------------------------- استجابة */
@media (max-width: 1024px) {
  .shell { grid-template-columns: 1fr; }
  /* القائمة تنزلق من الحافة اليمنى (بداية الصفحة العربية). نستخدم اتجاهات فعلية
     لأن inset-inline-end في صفحة rtl تعني اليسار فتبقى القائمة نصف ظاهرة. */
  .sidebar {
    position: fixed; top: 0; bottom: 0; right: 0; left: auto; width: min(280px, 84vw); height: 100%;
    transform: translateX(105%); transition: transform .2s ease;
    padding-top: calc(1.25rem + env(safe-area-inset-top, 0px));
    visibility: hidden;
  }
  .sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow); visibility: visible; }
  [dir="ltr"] .sidebar { right: auto; left: 0; transform: translateX(-105%); }
  [dir="ltr"] .sidebar.is-open { transform: translateX(0); }
  .only-mobile { display: inline-grid; place-items: center; }
}

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 2rem 1.5rem; }
  .auth-art .logo { font-size: 2.4rem; }
  .auth-art ul { display: none; }
}

@media (max-width: 640px) {
  .content { padding: 1.1rem .9rem 2.5rem; }
  .topbar { padding: .65rem .9rem; }
  .quick-search { display: none; }
  .crumbs { font-size: .8rem; }
  h1 { font-size: 1.3rem; }
  .percent { font-size: 1.6rem; }
}

/* ---------------------------------------------- مكوّنات مضافة */
.section-gap { margin-top: 1rem; }
.muted { color: var(--muted); }
.link { color: var(--accent); }
.link:hover { text-decoration: underline; }
.input-search { width: 230px; max-width: 100%; }
.meta-chips { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.form-card { max-width: 680px; }
.check-label { color: var(--text) !important; font-size: .95rem !important; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; }
.filters .input { width: auto; min-width: 170px; }
.wrap-cell { white-space: normal !important; min-width: 220px; max-width: 420px; }
.progress-line { margin-bottom: .95rem; }
.progress-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .35rem; }
.progress-head .chip { margin-inline-start: auto; }
.list-row.is-current { border-color: var(--accent); background: var(--accent-soft); }
.tips { margin: 0; padding-inline-start: 1.1rem; color: var(--muted); font-size: .88rem; line-height: 1.9; }
.session-card p { margin-bottom: 0; }

.player-layout { grid-template-columns: minmax(0, 2.1fr) minmax(280px, 1fr); }
.upload-layout { grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr); }
@media (max-width: 1100px) {
  .player-layout, .upload-layout { grid-template-columns: minmax(0, 1fr); }
}

/* زر تبديل اللغة */
.lang-switch { display: inline-flex; margin: 0; }
.lang-btn {
  min-width: 36px; height: 36px; padding: 0 .6rem;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  font: 600 .8rem/1 var(--font); letter-spacing: .04em; cursor: pointer;
}
.lang-btn:hover { background: var(--surface-2); border-color: var(--accent); }
.lang-btn[lang="ar"] { font-size: 1rem; }

/* صفحة الدخول */
.auth-form { position: relative; }
.auth-lang { position: absolute; top: calc(1.2rem + env(safe-area-inset-top, 0px)); inset-inline-end: 1.2rem; }
.auth-note { color: #8f9bbd; }
.auth-foot { margin-top: 1.2rem; font-size: .85rem; color: var(--muted); }
[dir="ltr"] .auth-art li::before { margin-inline-end: .5rem; }

/* ============================================================
   v4 — الفيديوهات، الحسابات، الأدوار، الأجهزة المختلفة
   ============================================================ */

/* ---------- الصور الشخصية */
.avatar { object-fit: cover; flex: none; }
img.avatar { background: var(--surface-2); }
.avatar-xs { width: 22px; height: 22px; border-radius: 7px; font-size: .62rem; }
.avatar-sm { width: 34px; height: 34px; border-radius: 10px; font-size: .78rem; }
.avatar-md { width: 38px; height: 38px; border-radius: 11px; font-size: .85rem; }
.avatar-lg { width: 64px; height: 64px; border-radius: 18px; font-size: 1.3rem; }
.avatar-xl { width: 104px; height: 104px; border-radius: 28px; font-size: 2rem; }
.person { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.person > span { display: grid; min-width: 0; }
.person small { color: var(--muted); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-lg h1 { margin: 0; }
.person-lg .meta-chips { margin-top: .35rem; }
.person-chip { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .55rem .2rem .25rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: .85rem; }
[dir="rtl"] .person-chip { padding: .2rem .25rem .2rem .55rem; }

/* ---------- القائمة الجانبية */
.nav-label { margin: 1rem .7rem .35rem; font-size: .7rem; letter-spacing: .08em; color: var(--muted); opacity: .75; }
.badge-warn { background: var(--warn); color: #2b1d00; }
a.who { border-radius: var(--radius-s); padding: .4rem; margin: -.4rem; transition: background .15s; }
a.who:hover, a.who.is-active { background: var(--surface-2); }

/* ---------- شارات وتنبيهات وتبويبات */
.chip-accent { color: var(--accent); border-color: rgba(91, 124, 250, .45); background: var(--accent-soft); }
.alert { border-radius: var(--radius); padding: .9rem 1.1rem; margin-bottom: 1rem; border: 1px solid var(--line); background: var(--surface); }
.alert p { margin: .4rem 0 .6rem; }
.alert-warn { border-color: rgba(245, 185, 66, .5); background: rgba(245, 185, 66, .07); }
.alert-people { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.list-row.is-alert { border-color: rgba(245, 185, 66, .5); }
.tabs { display: flex; gap: .25rem; margin: 0 0 1rem; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: .55rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-size: .9rem; }
.tabs a:hover { color: var(--text); }
.tabs a.is-on { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }
.info-note { margin-top: 1.2rem; padding: .75rem .9rem; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-size: .82rem; line-height: 1.7; }

/* ---------- حقول كلمة المرور: زر إظهار/إخفاء */
.pw-field { position: relative; display: block; }
.pw-field input { padding-inline-end: 2.9rem !important; }
.pw-toggle {
  position: absolute; inset-block: 0; inset-inline-end: .3rem; margin: auto 0;
  width: 2.3rem; height: 2.3rem; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer;
}
.pw-toggle:hover { color: var(--text); background: var(--surface); }
.pw-toggle svg { width: 20px; height: 20px; }
/* حقول ltr داخل صفحة rtl: الزر في آخر السطر الفعلي (اليسار في العربي) */
.pw-field input[dir="ltr"] { padding-inline-end: .8rem !important; }
[dir="rtl"] .pw-field input[dir="ltr"] { padding-left: 2.9rem !important; }
[dir="ltr"] .pw-field input[dir="ltr"] { padding-right: 2.9rem !important; }

/* ---------- الدخول و"نسيت كلمة المرور" */
.login-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin: -.2rem 0 1.1rem; flex-wrap: wrap; font-size: .9rem; }
.login-row .checkline { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; }
.auth-single { grid-template-columns: 1fr; }
.auth-logo { display: inline-block; font-family: var(--mono); font-size: 1.6rem; margin-bottom: 1.2rem; }
.auth-logo b { color: var(--accent); font-weight: 500; }
.done-mark { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: rgba(52, 211, 155, .14); color: var(--ok); font-size: 1.6rem; margin-bottom: 1rem; }

/* ---------- حسابي */
.account-layout { grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); align-items: start; }
.stack { display: grid; gap: 1rem; min-width: 0; }
.stack > .card + .card { margin-top: 0; }
.profile-card { text-align: center; }
.profile-head { display: grid; justify-items: center; gap: .8rem; padding: .6rem 0 1rem; }
.profile-id { display: grid; justify-items: center; gap: .35rem; }
.profile-id h2 { margin: 0; }
.facts { display: grid; gap: .5rem; margin: 0 0 .8rem; text-align: start; }
.facts div { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem .7rem; border-radius: 8px; background: var(--surface-2); font-size: .85rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
input[type="file"] { padding: .5rem; font-size: .85rem; }
input[type="file"]::file-selector-button {
  margin-inline-end: .7rem; padding: .4rem .8rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 500 .82rem var(--font); cursor: pointer;
}

/* ---------- الصور المصغّرة للفيديو */
.thumb { position: relative; aspect-ratio: 16 / 9; background: linear-gradient(135deg, #111a36, #1b1440); overflow: hidden; display: grid; place-items: center; border-radius: inherit; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb-ph { color: rgba(255, 255, 255, .35); font-size: 1.6rem; }
.thumb-part {
  position: absolute; inset-block-start: .45rem; inset-inline-start: .45rem;
  min-width: 1.6rem; height: 1.6rem; padding: 0 .4rem; border-radius: 7px;
  display: grid; place-items: center; background: rgba(7, 11, 22, .82); color: #fff;
  font: 600 .78rem var(--mono); backdrop-filter: blur(4px);
}
.thumb-done {
  position: absolute; inset-block-start: .45rem; inset-inline-end: .45rem;
  width: 1.6rem; height: 1.6rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--ok); color: #05261c; font-weight: 700; font-size: .8rem;
}
.thumb .time { inset-block-end: .5rem; }
.thumb-progress { position: absolute; inset-inline: 0; inset-block-end: 0; height: 4px; background: rgba(255, 255, 255, .18); }
.thumb-progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
[dir="rtl"] .thumb-progress span { margin-inline-start: 0; }
.thumb.is-watched .thumb-progress span { background: var(--ok); }
.thumb-play {
  position: absolute; width: 2.6rem; height: 2.6rem; border-radius: 50%;
  display: grid; place-items: center; background: rgba(91, 124, 250, .92); color: #fff;
  font-size: .9rem; opacity: 0; transform: scale(.85); transition: opacity .15s, transform .15s;
}
a:hover .thumb-play, a:focus-visible .thumb-play { opacity: 1; transform: scale(1); }

/* بطاقات قائمة الفيديوهات */
.grid-videos { grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr)); }
.video-card { transition: border-color .15s, transform .15s; }
.video-card:hover { transform: translateY(-2px); }
.video-card .thumb { border-radius: 0; }
.video-card .body { gap: .35rem; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.45; min-height: 2.9em; }
.part-label { color: var(--muted); font-size: .76rem; }

/* صفوف الأجزاء (صفحة الجلسة، لوحة العضو، جانب المشغّل) */
.part-list { display: grid; gap: .6rem; }
.part-row {
  display: grid; grid-template-columns: 148px minmax(0, 1fr); gap: .9rem; align-items: center;
  padding: .55rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  transition: border-color .15s, background .15s;
}
.part-row:hover { border-color: var(--accent); }
.part-row .thumb { border-radius: 10px; }
.part-info { display: grid; gap: .3rem; min-width: 0; }
.part-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.45; }
.part-list-compact .part-row { grid-template-columns: 112px minmax(0, 1fr); gap: .7rem; padding: .45rem; }
.part-list-compact .part-title { -webkit-line-clamp: 1; font-size: .9rem; }
.part-list-compact .meta-chips .chip { font-size: .7rem; }
.part-list-compact .is-current .part-row { border-color: var(--accent); background: var(--accent-soft); }

/* تابع المشاهدة */
.continue-card { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); gap: 1rem; align-items: center; }
.continue-card .thumb { border-radius: 12px; }
.continue-card .part-title { font-size: 1.05rem; }
.continue-card .btn { justify-self: start; margin-top: .3rem; }

/* ---------- الجداول تصبح بطاقات على الشاشات الصغيرة */
.cell-person { min-width: 220px; }
.cell-person .chip { margin-top: .35rem; }
.row-actions form { display: inline; }
/* تتحول لبطاقات حسب المساحة المتاحة للجدول نفسه (وليس عرض الشاشة)،
   فتعمل صحيحًا على الآيباد حيث تأخذ القائمة الجانبية جزءًا من العرض */
.table-wrap { container-type: inline-size; }
@container (max-width: 900px) {
  table.responsive { min-width: 0; }
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { padding: .8rem .9rem; border-bottom: 1px solid var(--line); }
  table.responsive tr:last-child { border-bottom: 0; }
  table.responsive td { border: 0; padding: .28rem 0; white-space: normal; display: flex; gap: .75rem; justify-content: space-between; align-items: center; }
  table.responsive td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .78rem; flex: none; }
  table.responsive td.cell-person { display: block; padding-bottom: .5rem; }
  table.responsive td.cell-person::before { display: none; }
  table.responsive td.cell-actions { padding-top: .6rem; }
  table.responsive .wrap-cell { max-width: none; min-width: 0; text-align: end; }
}
/* احتياط للمتصفحات القديمة */
@supports not (container-type: inline-size) {
  @media (max-width: 760px) {
  table.responsive { min-width: 0; }
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { padding: .8rem .9rem; border-bottom: 1px solid var(--line); }
  table.responsive tr:last-child { border-bottom: 0; }
  table.responsive td { border: 0; padding: .28rem 0; white-space: normal; display: flex; gap: .75rem; justify-content: space-between; align-items: center; }
  table.responsive td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .78rem; flex: none; }
  table.responsive td.cell-person { display: block; padding-bottom: .5rem; }
  table.responsive td.cell-person::before { display: none; }
  table.responsive td.cell-actions { padding-top: .6rem; }
  table.responsive .wrap-cell { max-width: none; min-width: 0; text-align: end; }
  }
}

/* ---------- تخطيطات حسب الجهاز */
/* أجهزة لوحية وحواسيب صغيرة */
@media (max-width: 1100px) {
  .account-layout { grid-template-columns: minmax(0, 1fr); }
  .profile-card { text-align: start; }
  .profile-head { grid-auto-flow: column; justify-content: start; justify-items: start; align-items: center; padding: 0 0 .8rem; }
  .profile-id { justify-items: start; }
}
/* هواتف */
@media (max-width: 640px) {
  .page-head .spacer { width: 100%; }
  .page-head .spacer .input-search { width: 100%; }
  .page-head .spacer form[role="search"] { flex: 1 1 100%; }
  .part-row { grid-template-columns: 112px minmax(0, 1fr); gap: .7rem; }
  .part-title { -webkit-line-clamp: 2; font-size: .92rem; }
  .part-row .meta-chips .chip { font-size: .7rem; padding: .12rem .45rem; }
  .continue-card { grid-template-columns: minmax(0, 1fr); }
  .grid-videos { grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); }
  .avatar-xl { width: 72px; height: 72px; border-radius: 20px; font-size: 1.5rem; }
  .person-lg { align-items: flex-start; }
  .alert-people { flex-direction: column; align-items: flex-start; }
  .form-actions .btn { flex: 1 1 auto; }
  .tabs a { padding: .5rem .7rem; }
}
/* شاشات كبيرة جدًا */
@media (min-width: 1600px) {
  .content { max-width: 1480px; width: 100%; margin-inline: auto; }
}

/* ============================================================
   النجوم وغرفة الأسئلة
   ============================================================ */
:root { --star: #f7c948; --gold: #f7c948; --silver: #c9d2e3; --bronze: #d59264; }

.star-icon { color: var(--star); filter: drop-shadow(0 1px 4px rgba(247, 201, 72, .35)); }
.star-lg { font-size: 1.3rem; }
.chip-star { color: var(--star); border-color: rgba(247, 201, 72, .4); background: rgba(247, 201, 72, .08); font-family: var(--mono); font-weight: 600; }
.my-stars-chip { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem; border-radius: 999px; border: 1px solid rgba(247, 201, 72, .45); background: rgba(247, 201, 72, .1); color: var(--star); font-weight: 600; }
.stat-star { display: block; transition: border-color .15s, transform .15s; }
.stat-star:hover { border-color: var(--star); transform: translateY(-2px); }

/* ---------- غرفة الأسئلة */
.room { display: grid; gap: 1.2rem; justify-items: center; }
.room-stage {
  width: 100%; min-height: 320px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--radius-l); padding: 2rem 1.2rem;
  background: radial-gradient(900px 300px at 50% 0%, var(--accent-soft), transparent 70%), var(--surface);
}
.room-idle { text-align: center; color: var(--muted); }
.room-idle .dice { font-size: 3.4rem; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-10px) rotate(6deg); } }
.room-student { text-align: center; display: grid; justify-items: center; gap: .5rem; }
.room-avatar {
  width: 128px; height: 128px; border-radius: 34px; overflow: hidden;
  display: grid; place-items: center; font-size: 2.6rem; font-weight: 600; color: #fff;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 40px rgba(91, 124, 250, .35);
}
.room-avatar img { width: 100%; height: 100%; object-fit: cover; }
.room-name { font-size: clamp(1.6rem, 5vw, 2.6rem); margin: .3rem 0 0; }
.room-score { font-size: 1.15rem; margin: 0; font-family: var(--mono); }
.room-status { color: var(--muted); margin: .2rem 0 0; min-height: 1.5em; font-size: .95rem; }
.room-status.is-good { color: var(--ok); font-weight: 600; }
.room-status.is-bad { color: var(--bad); }
.room-student.is-rolling .room-name { opacity: .75; }
.room-student.is-rolling .room-avatar { animation: shake .3s linear infinite; }
@keyframes shake { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
.room-student.is-awarded .room-avatar { animation: pop .8s ease; box-shadow: 0 12px 44px rgba(247, 201, 72, .55); }
@keyframes pop { 0% { transform: scale(1); } 35% { transform: scale(1.12); } 100% { transform: scale(1); } }
.room-actions { display: grid; gap: .7rem; width: min(560px, 100%); }
.room-answer { display: grid; grid-template-columns: 1.4fr 1fr; gap: .7rem; }
.btn-xl { padding: 1rem 1.4rem; font-size: 1.05rem; border-radius: 14px; }
.room-round { display: flex; align-items: center; gap: .8rem; color: var(--muted); font-size: .85rem; flex-wrap: wrap; justify-content: center; }

/* ---------- منصّة التتويج */
.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; align-items: end; margin-bottom: .2rem; }
.podium-slot {
  display: grid; justify-items: center; gap: .4rem; text-align: center; min-width: 0;
  padding: 1.1rem .7rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
}
/* الأول دائمًا في الوسط، والثاني والثالث على جانبيه حسب اتجاه القراءة */
.podium-slot.pos-1 { border-color: rgba(247, 201, 72, .5); background: linear-gradient(180deg, rgba(247, 201, 72, .12), var(--surface)); padding-block: 1.6rem; order: 2; }
.podium-slot.pos-2 { order: 1; }
.podium-slot.pos-3 { order: 3; }
[dir="rtl"] .podium-slot.pos-2 { order: 3; }
[dir="rtl"] .podium-slot.pos-3 { order: 1; }
.podium-slot.is-me { outline: 2px solid var(--accent); outline-offset: 2px; }
.podium-medal { font-size: 1.6rem; }
.podium-name { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.podium-stars { font-family: var(--mono); font-weight: 600; color: var(--star); }

/* ---------- قائمة الترتيب */
.rank-list { display: grid; gap: .45rem; }
.rank-row { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); min-width: 0; }
.rank-row > :not(.grow) { flex: none; }
.rank-row .grow { flex: 1 1 auto; min-width: 0; }
.rank-row .grow b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row.is-me { border-color: var(--accent); background: var(--accent-soft); }
.rank-no { width: 2rem; text-align: center; font-family: var(--mono); font-weight: 600; color: var(--muted); flex: none; }
.rank-no.rank-1 { color: var(--gold); }
.rank-no.rank-2 { color: var(--silver); }
.rank-no.rank-3 { color: var(--bronze); }

@media (max-width: 640px) {
  .room-answer { grid-template-columns: 1fr; }
  .room-stage { min-height: 260px; padding: 1.4rem .9rem; }
  .room-avatar { width: 96px; height: 96px; border-radius: 26px; font-size: 2rem; }
  .podium { gap: .4rem; }
  .podium-slot { padding: .8rem .35rem; gap: .25rem; }
  .podium-slot.pos-1 { padding-block: 1.1rem; }
  .podium .avatar-lg { width: 48px; height: 48px; border-radius: 14px; font-size: 1rem; }
  .podium-medal { font-size: 1.2rem; }
  .podium-name { font-size: .8rem; }
  .podium-stars { font-size: .85rem; }
  .my-stars-chip { padding: .4rem .8rem; font-size: .88rem; }
  .rank-no { width: 1.5rem; }
}

/* ---------- لوحة المشاركين في الاختيار العشوائي */
.pool-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: .5rem; }
.pool-item { display: flex; align-items: center; gap: .6rem; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); min-width: 0; }
.pool-item > :not(.grow) { flex: none; }
.pool-item .grow { flex: 1 1 auto; min-width: 0; display: grid; }
.pool-item .grow small { color: var(--muted); font-size: .75rem; }
.pool-item.is-off { opacity: .55; }
.pool-item.is-off .grow small { color: var(--warn); }

.switch { width: 44px; height: 26px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; padding: 0; position: relative; transition: background .15s, border-color .15s; }
.switch span { position: absolute; inset-block: 3px; inset-inline-start: 3px; width: 18px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch.is-on { background: var(--accent-soft); border-color: var(--accent); }
.switch.is-on span { background: var(--accent); transform: translateX(18px); }
[dir="rtl"] .switch.is-on span { transform: translateX(-18px); }
.switch:disabled { opacity: .6; cursor: wait; }

/* حذف النجوم (للمالك) */
.btn-del { width: 32px; height: 32px; font-size: .9rem; border-color: transparent; color: var(--muted); }
.btn-del:hover { color: var(--bad); border-color: rgba(244, 97, 111, .45); background: rgba(244, 97, 111, .1); }
.bulk-card { border-color: rgba(244, 97, 111, .4); }
.bulk-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.bulk-form .input { width: 110px; }

/* ---------- عدّاد تعديل النجوم في لوحة النجوم (المالك) */
.stepper { display: inline-flex; align-items: center; gap: .3rem; flex: none; }
.step-btn {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: 600 1.05rem/1 var(--font); cursor: pointer; transition: background .15s, border-color .15s, color .15s;
}
.step-btn:hover { background: var(--surface); }
.step-plus:hover { color: var(--ok); border-color: rgba(52, 211, 155, .5); }
.step-minus:hover { color: var(--bad); border-color: rgba(244, 97, 111, .5); }
.step-btn:disabled { opacity: .5; cursor: wait; }
.star-value { min-width: 62px; justify-content: center; text-align: center; }
.rank-row { transition: background .25s, border-color .25s; }
.rank-row.is-updated { border-color: var(--star); background: rgba(247, 201, 72, .1); }
.rank-row.is-shake { animation: shake .3s linear 2; border-color: var(--bad); }
@media (max-width: 420px) {
  .step-btn { width: 34px; height: 34px; }
  .star-value { min-width: 54px; padding-inline: .4rem; }
  .rank-row { gap: .45rem; padding: .5rem .45rem; }
}
