/* ============================================================
   منصة الالتزام السلوكي — نظام التصميم
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;800&display=swap');

:root {
  --blue: #2b7bb9;
  --green: #34a06e;
  --grad: linear-gradient(90deg, var(--blue) 0%, #2e8f92 50%, var(--green) 100%);
  --grad-soft: linear-gradient(135deg, rgba(43,123,185,.09), rgba(52,160,110,.09));
  --ink: #0d2b3e;
  --ink-2: #3c5a6d;
  --muted: #6c8496;
  --gold: #c9a227;
  --bg: #eef3f7;
  --card: #ffffff;
  --line: #dce6ee;
  --line-2: #eaf1f6;
  --ok: #17915f;
  --ok-bg: #e6f6ee;
  --warn: #b8860b;
  --warn-bg: #fdf4e0;
  --dan: #c0392b;
  --dan-bg: #fdeceb;
  --info-bg: #e9f2fa;
  --r: 16px;
  --r-sm: 10px;
  --sh: 0 2px 6px rgba(13, 43, 62, .06), 0 10px 30px rgba(13, 43, 62, .07);
  --sh-sm: 0 1px 3px rgba(13, 43, 62, .08);
  --fnt: 'Tajawal', 'Segoe UI', 'Dubai', Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--fnt);
  background: var(--bg);
  color: var(--ink);
  direction: rtl;
  line-height: 1.75;
  font-size: 15px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
:focus-visible { outline: 3px solid rgba(43,123,185,.4); outline-offset: 2px; border-radius: 6px; }

/* ---------- تخطيط ---------- */
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.wrap-sm { max-width: 820px; margin: 0 auto; padding: 0 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grow { flex: 1 1 220px; min-width: 0; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.hide { display: none !important; }
.spacer { flex: 1; }

/* ---------- الترويسة الرسمية ---------- */
.topbar { background: var(--grad); color: #fff; box-shadow: var(--sh-sm); position: sticky; top: 0; z-index: 40; }
.topbar .wrap { display: flex; align-items: center; gap: 14px; min-height: 68px; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 18px; }
.brand .logo {
  width: 42px; height: 42px; border-radius: 12px; background: rgba(255,255,255,.16);
  display: grid; place-items: center; font-size: 20px; backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,.25);
}
.brand small { display: block; font-size: 11.5px; font-weight: 500; opacity: .9; line-height: 1.3; }
.topbar a, .topbar button { color: #fff; }

/* ---------- بطاقات ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--sh-sm); padding: 20px; position: relative;
}
.card.pad-0 { padding: 0; overflow: hidden; }
.card h2, .card h3 { display: flex; align-items: center; gap: 9px; }
.card > h2 { font-size: 18px; margin-bottom: 4px; }
.card > h2 + .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }
.sec-title {
  display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 800;
  margin-bottom: 4px;
}
.sec-title .ic {
  width: 38px; height: 38px; border-radius: 11px; background: var(--grad-soft);
  display: grid; place-items: center; font-size: 19px; border: 1px solid var(--line);
}
.sec-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; }

/* ---------- أزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; border-radius: 11px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-weight: 700; cursor: pointer;
  transition: .16s; white-space: nowrap; font-size: 14.5px;
}
.btn:hover { border-color: var(--blue); color: var(--blue); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--grad); color: #fff; border: none; box-shadow: 0 4px 14px rgba(43,123,185,.28); }
.btn.primary:hover { color: #fff; filter: brightness(1.06); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.ok:hover { color: #fff; filter: brightness(1.08); }
.btn.dan { color: var(--dan); border-color: #f3c9c4; background: #fff; }
.btn.dan:hover { background: var(--dan); color: #fff; border-color: var(--dan); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--line-2); color: var(--ink); transform: none; }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 9px; }
.btn.lg { padding: 14px 30px; font-size: 16.5px; border-radius: 13px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- حقول ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 14px; }
.field > label .req { color: var(--dan); }
.field .hint { color: var(--muted); font-size: 12.5px; margin-top: 5px; }
.inp, select.inp, textarea.inp {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: 11px;
  background: #fbfdfe; transition: .16s; font-size: 15px;
}
.inp:focus { border-color: var(--blue); background: #fff; outline: none; box-shadow: 0 0 0 4px rgba(43,123,185,.12); }
.inp.err { border-color: var(--dan); background: #fff8f7; }
textarea.inp { min-height: 110px; resize: vertical; line-height: 1.85; }
select.inp { cursor: pointer; }
.inp-num { direction: ltr; text-align: center; letter-spacing: 3px; font-weight: 700; font-size: 18px; }

.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fbfdfe; transition: .16s; }
.check:hover { border-color: var(--blue); }
.check input { width: 20px; height: 20px; margin-top: 3px; accent-color: var(--green); flex: none; cursor: pointer; }
.check.on { border-color: var(--ok); background: var(--ok-bg); }
.check span { font-size: 14px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; background: #fbfdfe; }
.switch b { font-size: 14px; }
.switch .hint { color: var(--muted); font-size: 12px; font-weight: 400; }
.switch input { width: 20px; height: 20px; accent-color: var(--green); cursor: pointer; flex: none; }

/* ---------- شارات ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 11px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; white-space: nowrap;
}
.badge.signed { background: var(--ok-bg); color: var(--ok); }
.badge.paper { background: #eef2ff; color: #4054b2; }
.badge.viewed { background: var(--warn-bg); color: var(--warn); }
.badge.none { background: #f1f4f7; color: var(--muted); }
.badge.gold { background: #fdf6e3; color: #96751a; }

/* ---------- جداول ---------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: #fff; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
table.tbl th {
  background: #f4f8fb; text-align: right; padding: 12px 12px; font-weight: 800;
  border-bottom: 2px solid var(--line); color: var(--ink-2); font-size: 13px; white-space: nowrap;
  position: sticky; top: 0; z-index: 2;
}
table.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.tbl tbody tr:hover { background: #f8fbfd; }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl .num { direction: ltr; text-align: center; font-variant-numeric: tabular-nums; }
.tbl-empty { text-align: center; padding: 44px 20px; color: var(--muted); }

/* ---------- مؤشرات ---------- */
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 18px; position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px; background: var(--blue); }
.kpi.ok::before { background: var(--ok); }
.kpi.warn::before { background: var(--warn); }
.kpi.dan::before { background: var(--dan); }
.kpi .lbl { color: var(--muted); font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 32px; font-weight: 800; line-height: 1.25; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12.5px; color: var(--muted); }

.ring { display: grid; place-items: center; position: relative; }
.ring svg { transform: rotate(-90deg); }
.ring .mid { position: absolute; text-align: center; }
.ring .mid b { font-size: 30px; font-weight: 800; display: block; line-height: 1.1; }
.ring .mid small { color: var(--muted); font-size: 12px; }

.bar { height: 9px; background: var(--line-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--grad); border-radius: 999px; transition: width .5s; }

/* ---------- تنبيهات ---------- */
.alert { padding: 13px 16px; border-radius: 12px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; border: 1px solid transparent; }
.alert.info { background: var(--info-bg); color: #17527d; border-color: #cfe3f4; }
.alert.ok { background: var(--ok-bg); color: #0f6b45; border-color: #bfe6d3; }
.alert.warn { background: var(--warn-bg); color: #8a6508; border-color: #f0dcae; }
.alert.dan { background: var(--dan-bg); color: #a02c1e; border-color: #f3c9c4; }
.alert b { display: block; }

/* ---------- إشعار عائم ---------- */
#toast { position: fixed; inset-block-end: 22px; inset-inline: 0; display: grid; justify-items: center; gap: 8px; z-index: 200; pointer-events: none; padding: 0 14px; }
#toast .t {
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,.24); animation: tin .28s; max-width: 92vw; font-size: 14px;
}
#toast .t.ok { background: var(--ok); }
#toast .t.dan { background: var(--dan); }
@keyframes tin { from { opacity: 0; transform: translateY(14px); } }

/* ---------- نافذة ---------- */
.modal { position: fixed; inset: 0; background: rgba(10,30,44,.55); display: none; z-index: 150; padding: 20px; overflow: auto; backdrop-filter: blur(2px); }
.modal.open { display: grid; place-items: start center; }
.modal .box { background: #fff; border-radius: 18px; width: 100%; max-width: 680px; margin: 30px 0; box-shadow: 0 24px 70px rgba(0,0,0,.3); animation: min .24s; }
.modal .box.wide { max-width: 960px; }
@keyframes min { from { opacity: 0; transform: translateY(-16px); } }
.modal .hd { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal .hd h3 { font-size: 17px; flex: 1; }
.modal .bd { padding: 20px; }
.modal .ft { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: #fafcfd; border-radius: 0 0 18px 18px; }
.x { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; padding: 4px 8px; border-radius: 8px; }
.x:hover { background: var(--line-2); color: var(--dan); }

/* ---------- لوحة التوقيع ---------- */
.sigpad { border: 2px dashed var(--line); border-radius: 14px; background: #fcfdfe; position: relative; overflow: hidden; }
.sigpad.filled { border-style: solid; border-color: var(--ok); background: #fff; }
.sigpad canvas { display: block; width: 100%; height: 190px; touch-action: none; cursor: crosshair; }
.sigpad .ph {
  position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted);
  pointer-events: none; font-size: 14px; text-align: center; padding: 10px;
}
.sigpad.filled .ph { display: none; }
.sig-tools { display: flex; gap: 8px; margin-top: 8px; align-items: center; }

/* ---------- عام ---------- */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.b { font-weight: 700; }
.mono { direction: ltr; font-family: ui-monospace, Consolas, monospace; letter-spacing: .5px; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.mt-lg { margin-top: 24px; }
.mb { margin-bottom: 14px; }
.divider { height: 1px; background: var(--line); margin: 18px 0; border: none; }
.pill { background: var(--line-2); padding: 4px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }

/* ---------- شاشة الانتظار ---------- */
.loading { display: grid; place-items: center; padding: 60px 20px; gap: 14px; color: var(--muted); }
.spin { width: 38px; height: 38px; border: 3.5px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------- استجابة ---------- */
@media (max-width: 900px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 16px; border-radius: 14px; }
  .wrap, .wrap-sm { padding: 0 12px; }
  .brand { font-size: 15.5px; }
  .brand small { font-size: 10.5px; }
  .topbar .wrap { min-height: 60px; gap: 8px; }
  .sec-title { font-size: 17.5px; }
  .kpi .val { font-size: 26px; }
  .modal { padding: 0; }
  .modal .box { margin: 0; border-radius: 0; min-height: 100vh; }
  .modal .ft { border-radius: 0; position: sticky; bottom: 0; }
}

/* ============================================================
   الطباعة — وثيقة رسمية
   ============================================================ */
.doc {
  background: #fff; color: #000; padding: 18mm 16mm; max-width: 210mm; margin: 0 auto;
  font-size: 13.5px; line-height: 1.95;
}
/* الترويسة الرسمية: النص يميناً · شعار الوزارة في المنتصف · بيانات يساراً */
.doc .dochd { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  border-bottom: 2.5px solid var(--blue); padding-bottom: 10px; margin-bottom: 6px; }
.doc .dochd .l { font-size: 12.5px; font-weight: 700; line-height: 1.75; }
.doc .dochd .side-r { text-align: right; }
.doc .dochd .side-l { text-align: left; }
.doc .dochd .mid { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.doc .dochd .mid img { height: 64px; width: auto; display: block; }
.doc .dochd .mid img.school-logo { height: 40px; }
.doc .dochd img { height: 62px; width: auto; }
.doc .docttl { text-align: center; font-size: 19px; font-weight: 800; margin: 14px 0 4px; }
.doc .docsub { text-align: center; color: #555; font-size: 12.5px; margin-bottom: 14px; }
.doc table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 10px 0; }
.doc table th, .doc table td { border: 1px solid #9bb3c4; padding: 6px 8px; }
.doc table th { background: #eef4f9; font-weight: 800; }
.doc .sigrow { display: flex; gap: 24px; margin-top: 26px; }
.doc .sigbox { flex: 1; text-align: center; }
.doc .sigbox img { height: 66px; object-fit: contain; }
.doc .sigline { border-top: 1.4px solid #333; margin-top: 6px; padding-top: 5px; font-weight: 700; font-size: 12.5px; }
.doc .foot { margin-top: 24px; border-top: 1px solid #bbb; padding-top: 8px; font-size: 11px; color: #555; display: flex; justify-content: space-between; gap: 12px; }
.doc .stamp { border: 2px solid var(--ok); color: var(--ok); border-radius: 10px; padding: 6px 14px; font-weight: 800; display: inline-block; transform: rotate(-3deg); font-size: 13px; }

@media print {
  body { background: #fff; }
  .noprint, .topbar, #toast, .modal { display: none !important; }
  .doc { padding: 0; max-width: none; box-shadow: none; }
  .page-break { break-after: page; page-break-after: always; }
  table { break-inside: auto; }
  tr { break-inside: avoid; }
  thead { display: table-header-group; }
  a[href]::after { content: ''; }
}
@page { size: A4; margin: 12mm; }
