/* ========== منصة تفوّق ١٢ — نظام الألوان والمكونات ========== */
:root {
  --bg: #f4f5f7;
  --bg-soft: #eceef2;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #1c2230;
  --text-2: #5b6474;
  --text-3: #8a93a3;
  --primary: #4f6bed;
  --primary-soft: #e8ecfd;
  --success: #16a34a;
  --success-soft: #e7f6ec;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warning: #e8a317;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 8px 32px rgba(16, 24, 40, 0.10);
  --radius: 18px;
  --font: 'IBM Plex Sans Arabic', 'Tajawal', system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f131a;
    --bg-soft: #151a23;
    --surface: #171c26;
    --surface-2: #1d2330;
    --border: #2a3140;
    --text: #e6e9ef;
    --text-2: #a3abba;
    --text-3: #6f7889;
    --primary: #7b91f5;
    --primary-soft: #232b48;
    --success: #34c472;
    --success-soft: #16301f;
    --danger: #f06363;
    --danger-soft: #3a1d1f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #0f131a;
  --bg-soft: #151a23;
  --surface: #171c26;
  --surface-2: #1d2330;
  --border: #2a3140;
  --text: #e6e9ef;
  --text-2: #a3abba;
  --text-3: #6f7889;
  --primary: #7b91f5;
  --primary-soft: #232b48;
  --success: #34c472;
  --success-soft: #16301f;
  --danger: #f06363;
  --danger-soft: #3a1d1f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background-color .25s, color .25s;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { flex-shrink: 0; }

/* ---------- الهيكل ---------- */
.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar .container { display: flex; align-items: center; gap: 12px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #8b5cf6); color: #fff; font-size: .95rem;
}
.brand small { display: block; font-weight: 500; font-size: .72rem; color: var(--text-3); line-height: 1.2; }
.spacer { flex: 1; }
main.container { padding-top: 28px; padding-bottom: 64px; }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 12px; padding: 10px 18px;
  font-weight: 600; font-size: .95rem; transition: transform .12s, background-color .2s, border-color .2s, opacity .2s;
  background: var(--primary); color: #fff;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.soft { background: var(--primary-soft); color: var(--primary); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.success { background: var(--success); }
.btn.sm { padding: 6px 12px; font-size: .85rem; border-radius: 10px; }
.btn.lg { padding: 14px 26px; font-size: 1.05rem; border-radius: 14px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn.sm { width: 32px; height: 32px; border-radius: 9px; }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 2px; }

/* ---------- البطاقات ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}

/* ---------- الصفحة الرئيسية ---------- */
.hero {
  position: relative; overflow: hidden; padding: 28px; margin-bottom: 32px;
  display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center;
}
.hero::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(600px 200px at 100% 0%, color-mix(in srgb, var(--primary) 14%, transparent), transparent),
              radial-gradient(400px 200px at 0% 100%, color-mix(in srgb, #8b5cf6 12%, transparent), transparent);
}
.hero > * { position: relative; }
.hero h1 { margin: 0 0 6px; font-size: 1.7rem; line-height: 1.35; }
.hero p { margin: 0; color: var(--text-2); }
.hero-stats { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 16px; min-width: 110px;
}
.stat b { display: block; font-size: 1.35rem; line-height: 1.3; }
.stat span { font-size: .8rem; color: var(--text-3); }
.ring {
  --p: 0; --c: var(--primary); position: relative; width: 120px; height: 120px; border-radius: 50%;
  display: grid; place-items: center; background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--bg-soft) 0);
}
.ring > div { width: 94px; height: 94px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; text-align: center; line-height: 1.2; }
.ring b { font-size: 1.5rem; display: block; }
.ring small { font-size: .72rem; color: var(--text-3); }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); font-weight: 600; font-size: inherit; }

.section-title { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-size: 1.15rem; }
.section-title .pill { font-weight: 500; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; margin-bottom: 36px; }

.subject-card {
  --c: var(--primary);
  display: flex; flex-direction: column; gap: 14px; padding: 20px; position: relative;
  transition: transform .18s, box-shadow .18s, border-color .18s;
}
.subject-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--c) 40%, var(--border)); }
.subject-head { display: flex; align-items: center; gap: 14px; }
.subject-icon {
  width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--c) 14%, var(--surface)); color: var(--c);
}
.subject-card h3 { margin: 0; font-size: 1.12rem; }
.subject-card p { margin: 0; font-size: .88rem; color: var(--text-2); }
.progress { height: 8px; border-radius: 99px; background: var(--bg-soft); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--c, var(--primary)); transition: width .5s ease; }
.card-foot { display: flex; justify-content: space-between; font-size: .8rem; color: var(--text-3); }

/* ---------- صفحة المادة ---------- */
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: .9rem; margin-bottom: 16px; }
.back:hover { color: var(--text); }
.subject-banner { padding: 24px; display: flex; align-items: center; gap: 18px; margin-bottom: 28px; flex-wrap: wrap; }
.subject-banner .subject-icon { width: 64px; height: 64px; border-radius: 18px; }
.subject-banner h1 { margin: 0; font-size: 1.6rem; }
.subject-banner .grow { flex: 1; min-width: 200px; }

.unit { margin-bottom: 28px; }
.unit-title { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; margin: 0 0 14px; }
.unit-title .num {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: .85rem;
  background: color-mix(in srgb, var(--c) 14%, var(--surface)); color: var(--c);
}
.path { display: flex; flex-direction: column; gap: 12px; position: relative; padding-inline-start: 26px; }
.path::before {
  content: ''; position: absolute; inset-inline-start: 16px; top: 24px; bottom: 24px; width: 2px;
  background: repeating-linear-gradient(to bottom, var(--border) 0 6px, transparent 6px 12px);
}
.stage {
  display: flex; align-items: center; gap: 16px; padding: 14px 18px; position: relative;
  transition: transform .15s, border-color .15s; text-align: start; width: 100%; color: var(--text);
}
.stage:not(.locked):hover { transform: translateX(-4px); border-color: color-mix(in srgb, var(--c) 45%, var(--border)); }
.stage-node {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  margin-inline-start: -51px; border: 3px solid var(--bg); flex-shrink: 0;
  background: var(--c); color: #fff; box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 30%, transparent);
}
.stage.done .stage-node { background: var(--success); box-shadow: 0 0 0 2px color-mix(in srgb, var(--success) 30%, transparent); }
.stage.locked { opacity: .6; cursor: not-allowed; }
.stage.locked .stage-node { background: var(--surface-2); color: var(--text-3); box-shadow: 0 0 0 2px var(--border); }
.stage-info { flex: 1; min-width: 0; }
.stage-info b { display: block; font-size: 1rem; }
.stage-info small { color: var(--text-3); font-size: .82rem; }
.stars { display: inline-flex; gap: 2px; color: var(--border); }
.stars .on { color: var(--warning); }

/* ---------- الاختبار ---------- */
.quiz-wrap { max-width: 760px; margin: 0 auto; }
.quiz-top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.quiz-top .progress { flex: 1; height: 10px; }
.quiz-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: var(--text-2); font-size: .9rem; gap: 8px; flex-wrap: wrap; }
.q-card { padding: 28px; margin-bottom: 16px; }
.q-card.enter { animation: rise .3s ease; }
.q-num { font-size: .82rem; font-weight: 700; color: var(--c); margin-bottom: 8px; }
.q-text { font-size: 1.25rem; font-weight: 600; margin: 0 0 22px; line-height: 1.8; }
.options { display: grid; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 14px; text-align: start;
  background: var(--surface-2); border: 2px solid var(--border); transition: border-color .15s, background-color .15s;
  width: 100%; font-size: 1.02rem;
}
.option:hover:not(:disabled) { border-color: color-mix(in srgb, var(--c) 55%, var(--border)); background: color-mix(in srgb, var(--c) 6%, var(--surface-2)); }
.option:disabled { cursor: default; }
.option .key {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; font-size: .9rem;
  background: var(--surface); border: 1px solid var(--border); flex-shrink: 0;
}
.option .txt { flex: 1; text-align: start; }
.option.correct { border-color: var(--success); background: var(--success-soft); }
.option.correct .key { background: var(--success); color: #fff; border-color: var(--success); }
.option.wrong { border-color: var(--danger); background: var(--danger-soft); animation: shake .35s; }
.option.wrong .key { background: var(--danger); color: #fff; border-color: var(--danger); }
.option.dim { opacity: .55; }
.feedback { display: flex; gap: 12px; padding: 14px 16px; border-radius: 14px; margin-top: 16px; animation: rise .25s ease; }
.feedback.ok { background: var(--success-soft); color: var(--success); }
.feedback.bad { background: var(--danger-soft); color: var(--danger); }
.feedback p { margin: 2px 0 0; color: var(--text); font-size: .93rem; }
.quiz-actions { display: flex; justify-content: flex-end; gap: 10px; }
.kbd-hint { font-size: .78rem; color: var(--text-3); text-align: center; margin-top: 14px; }

.result { padding: 32px 24px; text-align: center; animation: rise .35s ease; }
.result .ring { margin: 0 auto 16px; width: 150px; height: 150px; }
.result .ring > div { width: 118px; height: 118px; }
.result .ring b { font-size: 2rem; }
.result h2 { margin: 6px 0; font-size: 1.5rem; }
.result-stars { margin: 6px 0 10px; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }
.review { margin-top: 24px; }
.review h3 { font-size: 1.05rem; margin: 0 0 12px; }
.review-item { padding: 16px; margin-bottom: 10px; }
.review-item p { margin: 0 0 8px; font-weight: 600; }
.review-item .ans { font-size: .9rem; display: flex; gap: 6px; align-items: center; }
.review-item .ans.bad { color: var(--danger); }
.review-item .ans.ok { color: var(--success); }
.review-item .why { font-size: .85rem; color: var(--text-2); margin-top: 6px; }

/* ---------- نوافذ ونماذج ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(10, 14, 22, .45); backdrop-filter: blur(4px); animation: fade .2s;
}
.modal { width: 100%; max-width: 420px; padding: 26px; animation: rise .25s ease; }
.modal h2 { margin: 0 0 6px; font-size: 1.3rem; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: .85rem; font-weight: 600; color: var(--text-2); }
.input {
  width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
textarea.input { resize: vertical; min-height: 70px; line-height: 1.6; }
input[type='color'].input { padding: 4px; height: 44px; cursor: pointer; }

.toast-wrap { position: fixed; bottom: 20px; inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 60; pointer-events: none; padding: 0 16px; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-size: .92rem;
  box-shadow: var(--shadow-lg); animation: rise .25s ease; max-width: 100%;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }

.empty { text-align: center; padding: 48px 16px; color: var(--text-3); }
.loader { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite; margin: 60px auto; }

/* ---------- لوحة التحكم ---------- */
.admin-layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 20px; align-items: start; }
.sidebar { padding: 14px; position: sticky; top: 84px; }
.side-label { font-size: .75rem; font-weight: 700; color: var(--text-3); padding: 10px 10px 6px; }
.side-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 11px;
  border: 0; background: none; text-align: start; font-size: .94rem;
}
.side-item:hover { background: var(--surface-2); }
.side-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.side-item .dot { --c: var(--primary); width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 15%, var(--surface)); color: var(--c); }
.side-item .count { margin-inline-start: auto; font-size: .75rem; color: var(--text-3); }
.side-sep { height: 1px; background: var(--border); margin: 8px 0; }
.panel { padding: 22px; margin-bottom: 16px; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 1.2rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }
.unit-box { border: 1px solid var(--border); border-radius: 14px; margin-bottom: 12px; background: var(--surface-2); }
.unit-box-head { display: flex; align-items: center; gap: 8px; padding: 12px; }
.unit-box-head .input { background: var(--surface); font-weight: 600; }
.lesson-row { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px dashed var(--border); }
.lesson-row .input { background: var(--surface); padding: 8px 12px; }
.lesson-row .pill { white-space: nowrap; }
.unit-box-foot { padding: 8px 12px 12px; border-top: 1px dashed var(--border); }
.q-edit { padding: 18px; margin-bottom: 12px; }
.q-edit-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.q-edit-head b { font-size: .9rem; color: var(--text-2); }
.opt-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.opt-row input[type='radio'] { width: 20px; height: 20px; accent-color: var(--success); flex-shrink: 0; cursor: pointer; }
.opt-row.is-correct .input { border-color: var(--success); background: var(--success-soft); }
.savebar {
  position: sticky; bottom: 16px; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 12px 16px; flex-wrap: wrap;
  margin-top: 16px; border-radius: 16px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); animation: rise .25s;
}
.savebar .btn.ghost { color: var(--bg); border-color: color-mix(in srgb, var(--bg) 30%, transparent); background: transparent; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-3); font-weight: 600; font-size: .8rem; }
.login-wrap { min-height: calc(100vh - 64px); display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; padding: 32px; }
.login-card .brand-mark { width: 52px; height: 52px; border-radius: 15px; margin-bottom: 14px; }
.error-text { color: var(--danger); font-size: .88rem; min-height: 1.4em; margin: 0 0 8px; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: .88rem; color: var(--text-3); margin-bottom: 12px; flex-wrap: wrap; }
.crumbs button { background: none; border: 0; padding: 0; color: var(--primary); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }

/* ---------- حركات ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- الشاشات الصغيرة ---------- */
@media (max-width: 860px) {
  .admin-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}
@media (max-width: 600px) {
  .hero { grid-template-columns: 1fr; padding: 22px; }
  .hero .ring { display: none; }
  .hero h1 { font-size: 1.35rem; }
  .q-card { padding: 20px; }
  .q-text { font-size: 1.1rem; }
  .brand small { display: none; }
  .grid { grid-template-columns: 1fr; }
  .lesson-row { flex-wrap: wrap; }
  .lesson-row .input { flex-basis: 100%; }
}

bdi[dir='ltr'] { unicode-bidi: isolate; direction: ltr; }
