/* نظام الاختبارات — الأنماط
   الهوية: أخضر مزرق مؤسسي مع خلفيات فاتحة وبطاقات بيضاء بحدود ناعمة وأزرار بيضاوية،
   مستوحاة من إرشادات ألوان وخطوط منصة تعليمية حكومية (بدون استخدام أي شعار أو عنصر مسجّل).
   الخط: IBM Plex Sans Arabic (يُحمَّل من Google Fonts، وله بدائل آمنة). */

:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --ink: #1b2528;
  --muted: #5a6a71;
  --line: #dde5e9;
  --line-strong: #c5d1d7;
  --primary: #0b7f5e;
  --primary-dark: #086148;
  --primary-soft: #e6f4ee;
  --teal: #139fa9;
  --blue: #4b8fc4;
  --band: #e9f4f1;
  --mark: #cdeee1;
  --grad: linear-gradient(160deg, #4b8fc4 0%, #139fa9 40%, #09a566 100%);
  --red: #c23b2f;
  --red-soft: #fbeceb;
  --amber-soft: #fff6d6;
  --radius: 10px;
  --font: "IBM Plex Sans Arabic", "Noto Sans Arabic", "Segoe UI", Tahoma, "Geeza Pro", Arial, system-ui, sans-serif;
  --gutter: clamp(1rem, 3vw, 2rem);
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); line-height: 1.8; -webkit-text-size-adjust: 100%;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.4; margin: 0 0 .6rem; font-weight: 700; }
h2 { font-size: 1.25rem; margin-top: 2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1rem; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: embed; display: inline-block; }
.hl { background: linear-gradient(transparent 58%, var(--mark) 58%); padding: 0 .15em; }
[hidden] { display: none !important; }

/* ---------- الشريط العلوي ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: 0 1px 10px rgba(20, 60, 60, .05); position: sticky; top: 0; z-index: 20; }
.topbar-in { max-width: 84rem; margin-inline: auto; padding: .55rem var(--gutter); display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1rem; }
.brand { display: inline-flex; align-items: center; gap: .7rem; color: var(--ink); text-decoration: none; }
.logo-mark { height: 2.6rem; width: auto; flex: none; }
.logo-a { fill: var(--primary); }
.logo-b { fill: var(--teal); }
.brand-text { display: flex; flex-direction: column; line-height: 1.35; }
.brand-name { font-weight: 800; font-size: 1.05rem; color: #0f3d52; }
.brand-sub { font-size: .78rem; color: var(--muted); }
.nav { display: flex; flex-wrap: wrap; gap: 0 .4rem; }
.nav a, .nav button { color: var(--ink); text-decoration: none; padding: .55rem .55rem; font-size: .95rem; border-bottom: 3px solid transparent; font: inherit; background: none; border-top: 0; border-inline: 0; cursor: pointer; }
.nav a:hover, .nav button:hover { color: var(--primary); }
.nav a.is-active, .nav button.is-active { color: var(--primary); font-weight: 600; border-bottom-color: var(--primary); }
.topbar-user { margin-inline-start: auto; display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.who-name { font-weight: 600; font-size: .95rem; }
.who-role { color: var(--muted); font-size: .8rem; margin-inline-start: .3rem; }
@media (max-width: 1300px) { .who-role { display: none; } }
.topbar-user a { font-size: .9rem; }

.main { max-width: 84rem; width: 100%; margin-inline: auto; padding: 2rem var(--gutter) 4rem; flex: 1 0 auto; min-width: 0; }
.main-focus { max-width: none; padding: 0; }
.main-focus > .notice { max-width: 50rem; margin: 1rem auto 0; }
.page-title { font-size: 1.8rem; font-weight: 800; margin-bottom: 1.25rem; }
.site-footer { background: var(--grad); color: #fff; padding: 1rem var(--gutter); font-size: .9rem; text-align: center; }

/* ---------- عناصر عامة ---------- */
.notice { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.notice p:last-child { margin-bottom: 0; }
.notice-ok { background: var(--primary-soft); border-color: #b4dcca; color: #0a4d38; }
.notice-error { background: var(--red-soft); border-color: #efc2bd; color: #7d241c; }
.notice-info { background: var(--amber-soft); border-color: #ecd98a; color: #5c4a00; }

.btn {
  display: inline-block; font: inherit; cursor: pointer; text-decoration: none; text-align: center;
  background: var(--primary); color: #fff; border: 1.5px solid var(--primary);
  padding: .5rem 1.5rem; border-radius: 999px; font-weight: 600;
}
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); color: var(--primary-dark); }
.btn-danger { background: transparent; color: var(--red); border-color: #e3b1ac; }
.btn-danger:hover { background: var(--red-soft); color: var(--red); border-color: var(--red); }
.btn-small { padding: .15rem .85rem; font-size: .875rem; font-weight: 500; background: transparent; color: var(--primary); border-color: var(--line-strong); }
.btn-small:hover { background: var(--primary-soft); color: var(--primary-dark); border-color: var(--primary); }
.btn-small.btn-danger { color: var(--red); border-color: #e3b1ac; }
.btn-small.btn-danger:hover { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.linklike { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; text-decoration: underline; }
.inline-form { display: inline; margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }

.badge { display: inline-block; padding: .05rem .7rem; border-radius: 99px; font-size: .8rem; border: 1px solid var(--line-strong); background: var(--surface); }
.badge-ok { background: var(--primary-soft); border-color: #b4dcca; color: #0a4d38; }
.badge-off { background: var(--bg); color: var(--muted); }
.badge-warn { background: var(--amber-soft); border-color: #ecd98a; color: #5c4a00; }
.badge-bad { background: var(--red-soft); border-color: #efc2bd; color: #7d241c; }

/* أرقام اللوحة: بطاقات بيضاء بأرقام كبيرة خضراء */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: 1rem; margin: 0 0 2rem; }
.figure { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1rem; text-align: center; }
.figure b { display: block; font-size: 2.1rem; line-height: 1.3; font-weight: 700; color: var(--primary); }
.figure b span { background: none; padding: 0; }
.figure small { color: var(--ink); font-size: .92rem; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.tbl { width: 100%; border-collapse: collapse; font-size: .95rem; }
.tbl th { text-align: start; font-weight: 700; padding: .7rem .9rem; border-bottom: 1px solid var(--line-strong); white-space: nowrap; background: var(--band); }
.tbl td { padding: .65rem .9rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: #f6fbf9; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }

/* ---------- النماذج ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; margin-bottom: 1.5rem; }
.panel > h2:first-of-type, .panel > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem 1.25rem; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > span { font-weight: 600; font-size: .92rem; }
.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea {
  font: inherit; padding: .55rem .75rem; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink); width: 100%;
}
.field textarea { min-height: 7rem; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 3px solid #bfe6e0; border-color: var(--teal); }
.hint { color: var(--muted); font-size: .85rem; margin: 0; }
.check { display: flex; gap: .5rem; align-items: center; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--primary); }
.form-actions { margin-top: 1.25rem; display: flex; gap: .6rem; flex-wrap: wrap; }
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; margin-bottom: 1rem; }
.toolbar .field { min-width: 11rem; }
.toolbar .grow { flex: 1 1 14rem; }
details > summary { cursor: pointer; color: var(--primary); }

/* ---------- صفحات الدخول والتثبيت ---------- */
body.is-auth, body.is-focus.is-auth { background: var(--grad); }
body.is-auth { min-height: 100vh; }
.auth { flex: 1; display: grid; place-items: center; padding: 2rem var(--gutter); }
.auth-box { width: 100%; max-width: 30rem; }
.auth-wide { max-width: 40rem; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: .6rem; color: #fff; text-align: center; margin-bottom: 1.25rem; }
.auth-brand .logo-mark { height: 6rem; }
.auth-brand .logo-a, .auth-brand .logo-b { fill: #fff; }
.auth-brand .logo-b { fill-opacity: .8; }
.auth-brand .brand-text { align-items: center; }
.auth-brand .brand-name { font-size: 1.6rem; color: #fff; }
.auth-brand .brand-sub { font-size: .95rem; color: rgba(255,255,255,.9); }
.auth-card { background: var(--surface); border-radius: 14px; padding: 1.75rem 1.75rem 1.5rem; box-shadow: 0 8px 30px rgba(10, 60, 70, .18); }
.auth-card h1 { font-size: 1.5rem; font-weight: 800; }
.auth-card .panel { border: 0; padding: 0; margin: 1rem 0 0; }
.login-switch { margin: 1rem 0 0; font-size: .92rem; text-align: center; }
.portal { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.25rem; }
.portal a { display: flex; flex-direction: column; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem .75rem; text-align: center; }
.portal a:hover { border-color: var(--primary); box-shadow: 0 2px 10px rgba(11, 127, 94, .12); }
.portal .ic { width: 4.2rem; height: 4.2rem; border-radius: 50%; background: var(--primary-soft); display: grid; place-items: center; border: 2px solid var(--teal); }
.portal .ic svg { width: 2.2rem; height: 2.2rem; }
.portal b { font-size: 1.05rem; }
.portal span.d { color: var(--muted); font-size: .85rem; line-height: 1.6; }
@media (max-width: 480px) { .portal { grid-template-columns: 1fr; } }

/* ---------- بيانات الدخول (تظهر مرة واحدة) ---------- */
.creds { font-family: ui-monospace, Menlo, Consolas, monospace; direction: ltr; text-align: left; }
.creds-box { border: 2px solid var(--primary); background: #f3fbf7; border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1.5rem; }

/* ---------- محرّر الأسئلة ---------- */
.opt-row { display: grid; grid-template-columns: auto 1fr; gap: .75rem; align-items: start; padding: .75rem; border: 1px solid var(--line); border-radius: 8px; margin-bottom: .6rem; background: #fbfdfc; }
.opt-row .opt-body { display: flex; flex-direction: column; gap: .4rem; }
.opt-row img.thumb, .q-thumb { max-width: 9rem; max-height: 7rem; border: 1px solid var(--line); border-radius: 6px; display: block; }
.opt-correct { display: flex; flex-direction: column; align-items: center; gap: .15rem; font-size: .78rem; color: var(--muted); padding-top: .35rem; }
.opt-correct input { width: 1.2rem; height: 1.2rem; accent-color: var(--primary); }
.q-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.q-item { display: grid; grid-template-columns: 2.2rem 1fr auto; gap: .75rem; align-items: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; }
.q-num { font-weight: 800; color: var(--primary); }
.q-meta { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .35rem; }

/* ---------- ورقة الامتحان (شاشة الطالب أثناء الحل) ---------- */
body.is-focus { background: #eaf1f1; }
.exam-top {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: .75rem 1.5rem; align-items: center; justify-content: space-between;
  background: var(--surface); border-bottom: 1px solid var(--line-strong); padding: .6rem var(--gutter);
}
.exam-top h1 { font-size: 1.05rem; margin: 0; font-weight: 700; }
.timers { display: flex; gap: 1rem; align-items: center; }
.timer { text-align: center; line-height: 1.2; }
.timer small { display: block; color: var(--muted); font-size: .75rem; }
.timer b { font-size: 1.5rem; font-variant-numeric: tabular-nums; direction: ltr; display: inline-block; padding: 0 .6rem; border-radius: 999px; }
.timer.timer-main b { background: var(--primary-soft); color: var(--primary-dark); }
.timer.is-low b { background: var(--red); color: #fff; }
.paper-wrap { max-width: 50rem; margin: 1.5rem auto 4rem; padding: 0 1rem; width: 100%; }
.paper {
  background: #fff; border: 1px solid var(--line-strong); border-radius: 12px;
  padding: 1.75rem 2rem 1.75rem 1.5rem; position: relative; box-shadow: 0 2px 14px rgba(20, 70, 70, .07);
}
.paper::before { /* هامش الكراسة */
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 2.6rem; width: 2px; background: #a5d8cd;
}
.paper-inner { padding-inline-start: 3rem; }
.q-counter { color: var(--muted); font-size: .9rem; margin-bottom: .35rem; }
.q-body { font-size: 1.25rem; font-weight: 700; line-height: 1.9; margin-bottom: 1rem; white-space: pre-wrap; }
.q-image { max-width: 100%; max-height: 22rem; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 1.25rem; display: block; }
.choices { display: grid; gap: .6rem; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; cursor: pointer; margin: 0; }
.choice > span {
  display: flex; align-items: center; gap: .75rem; padding: .8rem 1rem; border: 2px solid var(--line-strong); border-radius: var(--radius);
  background: #fff; font-size: 1.05rem; min-height: 3.2rem;
}
.choice > span::before { content: ""; flex: none; width: 1.25rem; height: 1.25rem; border-radius: 50%; border: 2px solid var(--line-strong); background: #fff; }
.choice:hover > span { border-color: var(--teal); }
.choice input:checked + span { border-color: var(--primary); background: var(--primary-soft); font-weight: 700; }
.choice input:checked + span::before { border-color: var(--primary); background: radial-gradient(var(--primary) 45%, #fff 50%); }
.choice input:focus-visible + span { outline: 3px solid var(--teal); outline-offset: 2px; }
.choices-img { grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }
.choices-img .choice > span { flex-direction: column; align-items: stretch; padding: .6rem; text-align: center; }
.choices-img .choice > span::before { align-self: flex-start; }
.choices-img img { width: 100%; max-height: 13rem; object-fit: contain; border-radius: 6px; background: #f4f7f8; }
.exam-nav { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-top: 1.75rem; flex-wrap: wrap; }
.dots { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: 1.25rem; }
.dots .dot { width: 2.3rem; height: 2.3rem; padding: 0; font: inherit; font-size: .85rem; cursor: pointer; border: 1px solid var(--line-strong); border-radius: 50%; background: #fff; color: var(--ink); }
.dots .dot:hover { border-color: var(--primary); }
.dots .dot.is-answered { background: var(--primary-soft); border-color: #9fd2bd; }
.dots .dot.is-current { outline: 3px solid var(--teal); outline-offset: 1px; font-weight: 800; }

/* ---------- قائمة اختبارات الطالب ---------- */
.exam-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .8rem; }
.exam-row { display: grid; grid-template-columns: 1fr auto; gap: 1rem 2rem; align-items: center; padding: 1.1rem 1.3rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.exam-row h3 { font-size: 1.2rem; margin-bottom: .25rem; }
.exam-act { display: flex; flex-direction: column; align-items: flex-end; gap: .5rem; }
.exam-act form { margin: 0; }
@media (max-width: 640px) {
  .exam-row { grid-template-columns: 1fr; }
  .exam-act { align-items: center; flex-direction: row; flex-wrap: wrap; }
}

/* ---------- نتائج ومراجعة ---------- */
.score-big { font-size: 3.2rem; font-weight: 800; line-height: 1.3; color: var(--primary); }
.review-item { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 1rem 1.25rem; margin-bottom: .8rem; }
.review-item.ok { border-inline-start: 5px solid var(--primary); }
.review-item.bad { border-inline-start: 5px solid var(--red); }
.review-item.skip { border-inline-start: 5px solid var(--line-strong); }
.rv-opt { padding: .35rem .6rem; border-radius: 6px; margin: .25rem 0; display: flex; gap: .5rem; align-items: center; }
.rv-opt.is-correct { background: var(--primary-soft); }
.rv-opt.is-wrong { background: var(--red-soft); }
.rv-opt img { max-height: 5rem; border-radius: 4px; border: 1px solid var(--line); }

@media (max-width: 820px) {
  .topbar-user { margin-inline-start: 0; width: 100%; justify-content: space-between; }
}
@media (max-width: 560px) {
  .paper { padding: 1.25rem 1rem; }
  .paper::before { inset-inline-start: 1.6rem; }
  .paper-inner { padding-inline-start: 2rem; }
  .q-body { font-size: 1.1rem; }
  .timer b { font-size: 1.25rem; }
  .page-title { font-size: 1.5rem; }
}

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

@media print {
  body { background: #fff; }
  .topbar, .site-footer, .no-print, .form-actions, .notice-info { display: none !important; }
  .main { padding: 0; max-width: none; }
  .creds-box { border-color: #000; background: #fff; }
  .tbl th { background: #fff; }
}

/* ---------- التقرير الشامل ---------- */
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .75rem 1.5rem; margin: 0; }
.info-grid dt { color: var(--muted); font-size: .85rem; }
.info-grid dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.bar { height: .6rem; background: var(--line); border-radius: 99px; overflow: hidden; min-width: 8rem; margin-bottom: .2rem; }
.bar i { display: block; height: 100%; background: var(--grad); border-radius: 99px; }

/* الدرجة تُعرض دائمًا بصيغة «الحاصل / الكلي» من اليسار لليمين لتفادي الالتباس */
.sc { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------- الجداول على الجوال: تتحول إلى بطاقات (التسميات تُضاف من app.js) ---------- */
@media (max-width: 640px) {
  .table-wrap { border: 0; background: none; overflow: visible; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl thead { display: none; }
  .tbl tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .75rem; padding: .35rem 0; }
  .tbl tbody tr:hover { background: var(--surface); }
  .tbl td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; border: 0; padding: .35rem .9rem; text-align: start; }
  .tbl td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .85rem; flex: none; }
  .tbl td[colspan] { display: block; }
  .tbl td .actions { justify-content: flex-start; }
  .tbl td .bar { min-width: 6rem; }
}
