@import url('/assets/fonts/fonts.css');

/* ============================================================
   منصة تِبيان — نظام التصميم
   ============================================================ */
:root {
  /* ألوان الهوية — مستمدة من ترويسة وزارة التعليم الرسمية */
  --g1: #3f9d6d;          /* أخضر الوزارة */
  --g2: #2e7fb8;          /* أزرق الوزارة */
  --grad: linear-gradient(105deg, var(--g2) 0%, #33929a 52%, var(--g1) 100%);
  --grad-r: linear-gradient(285deg, var(--g2) 0%, #33929a 52%, var(--g1) 100%);

  --ink: #0d2233;         /* نص أساسي */
  --ink-2: #3d5568;       /* نص ثانوي */
  --ink-3: #7b8fa1;       /* نص خافت */
  --line: #e3eaf1;
  --line-2: #d3dfe9;
  --bg: #f2f6fa;
  --card: #ffffff;
  --tint: #f6fafc;

  --ok: #17825c;  --ok-bg: #e6f6ee;
  --warn: #a9761b; --warn-bg: #fdf3e0;
  --dan: #b23b3b; --dan-bg: #fdecec;
  --info: #2e7fb8; --info-bg: #eaf3fa;
  --gold: #b8893a;

  --r: 16px;  --r-s: 11px;  --r-l: 24px;
  --sh-1: 0 1px 2px rgba(13,34,51,.05), 0 4px 14px rgba(13,34,51,.05);
  --sh-2: 0 2px 6px rgba(13,34,51,.07), 0 14px 38px rgba(13,34,51,.10);
  --sh-3: 0 30px 70px rgba(13,34,51,.18);

  --ui: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
  --disp: 'Aref Ruqaa', 'Amiri', serif;
  --serif: 'Amiri', 'Traditional Arabic', serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--ui); font-size: 15px; line-height: 1.75;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
body[dir], html[dir] { direction: rtl; }
a { color: var(--g2); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
::selection { background: #cfe8f7; }

/* شريط تمرير أنيق */
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #c9d7e2; border-radius: 20px; border: 3px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: #a9bccd; }

.mono { font-variant-numeric: tabular-nums; letter-spacing: .3px;
        font-family: 'IBM Plex Sans Arabic', ui-monospace, monospace; direction: ltr; unicode-bidi: embed; display: inline-block; }
.num { text-align: center; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden, [hidden] { display: none !important; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ============================================================
   الأزرار
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-size: 14.5px; font-weight: 600; line-height: 1;
  padding: 11px 20px; border-radius: 12px; border: 1.5px solid var(--line-2);
  background: #fff; color: var(--ink); cursor: pointer;
  transition: transform .12s ease, box-shadow .18s ease, background .18s ease, border-color .18s;
  white-space: nowrap; text-decoration: none !important;
}
.btn:hover { border-color: #b9cbdb; box-shadow: var(--sh-1); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled, .btn.off { opacity: .5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }
.btn.pri { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 6px 18px rgba(46,127,184,.28); }
.btn.pri:hover { box-shadow: 0 10px 26px rgba(46,127,184,.36); }
.btn.dark { background: #10394f; color: #fff; border-color: transparent; }
.btn.dan { color: var(--dan); border-color: #f0cccc; background: #fff; }
.btn.dan:hover { background: var(--dan-bg); }
.btn.ok { color: var(--ok); border-color: #bfe4d3; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: #eef3f8; box-shadow: none; }
.btn.sm { padding: 7px 13px; font-size: 13px; border-radius: 9px; }
.btn.xs { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn.lg { padding: 15px 30px; font-size: 16.5px; border-radius: 14px; }
.btn.block { width: 100%; }

/* ============================================================
   الحقول
   ============================================================ */
label.f { display: block; margin-bottom: 14px; }
label.f > span, .flabel {
  display: block; font-size: 13px; font-weight: 600; color: var(--ink-2);
  margin-bottom: 6px; letter-spacing: .1px;
}
input[type=text], input[type=password], input[type=tel], input[type=email],
input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; font-family: inherit; font-size: 14.5px; color: var(--ink);
  padding: 11px 14px; border: 1.5px solid var(--line-2); border-radius: 11px;
  background: #fff; transition: border-color .16s, box-shadow .16s; outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--g2); box-shadow: 0 0 0 4px rgba(46,127,184,.13);
}
input::placeholder, textarea::placeholder { color: #a9bac9; }
textarea { resize: vertical; min-height: 90px; line-height: 1.8; }
select { appearance: none; background-image:
  url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%237b8fa1' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 14px center; padding-left: 36px; cursor: pointer; }
input[disabled], select[disabled], textarea[disabled] { background: #f4f7fa; color: var(--ink-3); }
.f-hint { font-size: 12px; color: var(--ink-3); margin-top: 5px; }
.f-err { font-size: 12.5px; color: var(--dan); margin-top: 5px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
@media (max-width: 720px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

/* حقل بحث بأيقونة */
.search {
  position: relative; flex: 1; min-width: 200px;
}
.search input { padding-right: 40px; }
.search::before {
  content: ''; position: absolute; right: 14px; top: 50%; width: 15px; height: 15px;
  transform: translateY(-50%); pointer-events: none; opacity: .55;
  background: no-repeat center/contain
    url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%233d5568' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.2-3.2'/%3E%3C/svg%3E");
}

/* ============================================================
   البطاقات واللوحات
   ============================================================ */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--sh-1); padding: 20px 22px;
}
.card.pad0 { padding: 0; overflow: hidden; }
.card h3, .card h2 { margin: 0 0 14px; font-size: 17px; font-weight: 700; letter-spacing: -.2px; }
.card-hd {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px 20px; border-bottom: 1px solid var(--line); background: var(--tint);
}
.card-hd h3 { margin: 0; font-size: 16px; }
.card-bd { padding: 18px 20px; }

.sect-t {
  display: flex; align-items: center; gap: 10px; margin: 30px 0 14px;
  font-size: 15px; font-weight: 700; color: var(--ink-2);
}
.sect-t::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* ============================================================
   الشارات والحالات
   ============================================================ */
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700;
  padding: 4px 11px; border-radius: 999px; background: #eef3f8; color: var(--ink-2);
  border: 1px solid transparent; white-space: nowrap; line-height: 1.6;
}
.chip.signed { background: var(--ok-bg); color: var(--ok); border-color: #c7e8d8; }
.chip.paper  { background: #eef0fb; color: #4a51a8; border-color: #d3d7f2; }
.chip.viewed { background: var(--warn-bg); color: var(--warn); border-color: #f2ddb4; }
.chip.none   { background: #f0f3f6; color: #78899a; border-color: #dfe6ed; }
.chip.info   { background: var(--info-bg); color: var(--info); border-color: #cbe2f2; }
.chip.dan    { background: var(--dan-bg); color: var(--dan); border-color: #f3cfcf; }
.chip.gold   { background: #fbf3e3; color: var(--gold); border-color: #eeddba; }
.chip.dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ============================================================
   الجداول
   ============================================================ */
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th {
  text-align: right; font-weight: 700; font-size: 12.5px; color: var(--ink-2);
  background: var(--tint); padding: 11px 13px; border-bottom: 1.5px solid var(--line-2);
  position: sticky; top: 0; z-index: 2; white-space: nowrap;
}
table.t td { padding: 11px 13px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tbody tr:hover { background: #f8fbfd; }
table.t tbody tr:last-child td { border-bottom: none; }
table.t td.act { text-align: left; white-space: nowrap; }
.tbl-wrap { overflow: auto; max-height: 68vh; border-radius: var(--r); }

.empty { text-align: center; padding: 54px 20px; color: var(--ink-3); }
.empty .ic { font-size: 40px; opacity: .35; margin-bottom: 8px; }
.empty b { display: block; color: var(--ink-2); font-size: 15px; margin-bottom: 4px; }

/* ============================================================
   الإشعارات المنبثقة
   ============================================================ */
#toast { position: fixed; bottom: 22px; left: 22px; z-index: 9999; display: flex; flex-direction: column; gap: 9px; }
#toast .t {
  background: #10394f; color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600; box-shadow: var(--sh-2); max-width: 380px;
  animation: tin .28s cubic-bezier(.2,.9,.3,1.2);
}
#toast .t.ok { background: #16794f; }
#toast .t.dan { background: #a53434; }
#toast .t.warn { background: #96690f; }
@keyframes tin { from { opacity: 0; transform: translateY(14px) scale(.96); } }

/* ============================================================
   النافذة المنبثقة
   ============================================================ */
.modal-bg {
  position: fixed; inset: 0; background: rgba(9,26,38,.55); backdrop-filter: blur(4px);
  z-index: 900; display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px; overflow: auto; animation: fin .2s ease;
}
@keyframes fin { from { opacity: 0; } }
.modal {
  background: #fff; border-radius: var(--r-l); width: 100%; max-width: 620px;
  box-shadow: var(--sh-3); animation: min .28s cubic-bezier(.2,.9,.3,1.05); overflow: hidden;
}
.modal.wide { max-width: 980px; }
.modal.xwide { max-width: 1180px; }
@keyframes min { from { opacity: 0; transform: translateY(20px) scale(.98); } }
.modal-hd {
  display: flex; align-items: center; gap: 12px; padding: 17px 22px;
  border-bottom: 1px solid var(--line); background: var(--tint);
}
.modal-hd h3 { margin: 0; font-size: 17px; font-weight: 700; flex: 1; }
.modal-bd { padding: 22px; max-height: 74vh; overflow: auto; }
.modal-ft { padding: 15px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-start; background: var(--tint); }
.x {
  width: 32px; height: 32px; border-radius: 9px; border: none; background: transparent;
  font-size: 21px; color: var(--ink-3); cursor: pointer; line-height: 1;
}
.x:hover { background: #e8eef4; color: var(--ink); }

/* ============================================================
   لوحة التوقيع
   ============================================================ */
.sigpad {
  position: relative; border: 2px dashed var(--line-2); border-radius: 14px;
  background:
    repeating-linear-gradient(90deg, transparent 0 22px, #eef3f7 22px 23px),
    #fcfdfe;
  height: 190px; overflow: hidden; transition: border-color .2s, background .2s;
}
.sigpad.filled { border-style: solid; border-color: var(--g1); background: #fcfdfe; }
.sigpad canvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.sigpad .ph {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; color: #a9bac9; font-size: 14px; pointer-events: none;
  transition: opacity .2s;
}
.sigpad.filled .ph { opacity: 0; }
.sigpad .ph .ic { font-size: 26px; opacity: .6; }
.sig-img { max-height: 74px; }

/* ============================================================
   الترويسة الرسمية والوثائق المطبوعة
   الورقة A4 = ٢١٠ × ٢٩٧ مم · الهوامش ١٢ مم فيبقى ١٨٦ مم للمحتوى
   ============================================================ */
:root { --pg-w: 210mm; --pg-h: 297mm; --pg-m: 12mm; --pg-c: 186mm; }

.doc {
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
  background: #fff; color: #10222f; font-family: var(--ui);
  font-size: 12.5px; line-height: 1.85;
  width: var(--pg-w); min-height: var(--pg-h);
  padding: var(--pg-m); margin: 0 auto 16px;
  box-sizing: border-box; overflow-wrap: break-word;
}

/* ---------- الشريط العلوي الرسمي ---------- */
.lh {
  position: relative; display: flex; align-items: center; gap: 14px;
  background: url('/assets/hd-top.png') no-repeat center/100% 100%;
  border-radius: 4px 4px 12px 12px;
  padding: 9px 16px; min-height: 21mm; color: #fff;
}
.lh-logo { height: 15mm; width: auto; flex: none; }
.lh-txt { display: flex; flex-direction: column; justify-content: center; gap: 1px;
          font-size: 10.5px; line-height: 1.55; text-align: right; }
.lh-txt b { font-size: 12px; font-weight: 700; letter-spacing: -.1px; }
.lh-school { height: 13mm; width: auto; margin-right: auto; flex: none;
             background: rgba(255,255,255,.9); border-radius: 6px; padding: 3px; }
.lh-meta { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
           font-size: 10.5px; color: #4a6275; padding: 6px 4px 0; }

/* ---------- الشريط السفلي ---------- */
.lf { margin-top: auto; padding-top: 14px; }
.lf-txt { font-size: 10px; color: #7b8fa1; padding: 0 4px 5px; }
.lf-band { display: block; width: 100%; height: 7mm; object-fit: fill; border-radius: 12px 12px 4px 4px; }

/* ---------- عناوين ومحتوى ---------- */
.docttl { text-align: center; font-family: var(--disp); font-size: 23px; font-weight: 700;
          margin: 16px 0 4px; color: #0d2233; }
.docsub { text-align: center; font-size: 11.5px; color: #5b7183; margin-bottom: 16px; }

.doc table { width: 100%; border-collapse: collapse; margin: 11px 0; font-size: 11.5px;
             table-layout: auto; }
.doc table td.num, .doc table th.num { white-space: nowrap; padding-left: 4px; padding-right: 4px; }
.doc table th, .doc table td { border: 1px solid #c9d6e0; padding: 6px 8px; vertical-align: middle; }
.doc table th { background: #eef4f8; font-weight: 700; text-align: right; color: #24455c; }
.doc h4 { margin: 16px 0 7px; font-size: 14px; color: #14405a; }
.doc p { margin: 7px 0; text-align: justify; }
.doc .lead { background: #f6fafc; border-right: 4px solid var(--g1); border-radius: 8px;
             padding: 10px 13px; margin: 12px 0; }

/* ---------- خانات التوقيع والختم ---------- */
.sign-grid { display: grid; gap: 14px; margin-top: 22px;
             grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.sign-box { position: relative; text-align: center; border: 1px solid #d9e3eb;
            border-radius: 10px; padding: 10px 8px; min-height: 34mm;
            display: flex; flex-direction: column; justify-content: space-between; }
.sign-box .cap { font-size: 10.5px; color: #5b7183; }
.sign-box .ink { flex: 1; display: grid; place-items: center; min-height: 17mm; }
.sign-box .ink img { max-height: 17mm; max-width: 100%; }
.sign-box .nm { font-weight: 700; font-size: 12px; border-top: 1px dotted #cbd8e2; padding-top: 5px; }
.sign-box .stamp-img { position: absolute; left: 2px; bottom: 9mm; height: 19mm; opacity: .9;
                       pointer-events: none; mix-blend-mode: multiply; }
.doc .stamp { display: inline-block; border: 2.2px solid var(--ok); color: var(--ok);
              border-radius: 9px; padding: 4px 13px; font-weight: 800; font-size: 12px;
              transform: rotate(-3deg); letter-spacing: .4px; }

.docft { margin-top: 16px; padding-top: 8px; border-top: 1px solid #dbe4eb;
         font-size: 10px; color: #7b8fa1; display: flex; justify-content: space-between; gap: 12px; }

/* ---------- الطباعة ---------- */
@page { size: A4 portrait; margin: 12mm; }
@page landscape { size: A4 landscape; margin: 10mm; }

@media print {
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  .noprint { display: none !important; }
  /* الهوامش من @page — فلا تُضاف مرة أخرى داخل الوثيقة */
  .doc { width: auto !important; max-width: none !important; min-height: 0 !important;
         padding: 0 !important; margin: 0 !important; box-shadow: none !important;
         page-break-after: always; }
  .doc:last-child { page-break-after: auto; }
  table.t th { position: static; }
  /* الجداول الطويلة: ترويسة تتكرّر وصفوف لا تنكسر */
  .doc thead { display: table-header-group; }
  .doc tfoot { display: table-footer-group; }
  .doc tr, .sign-box, .doc h4 { page-break-inside: avoid; }
  .doc h4 { page-break-after: avoid; }
  .lh, .lf { page-break-inside: avoid; }
  .doc img { max-width: 100% !important; }
}

/* ============================================================
   حلقات النسب
   ============================================================ */
.ring { position: relative; width: 100%; aspect-ratio: 1; max-width: 128px; margin: 0 auto; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .val {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; font-weight: 800; font-size: 22px; letter-spacing: -.5px;
}
.ring .val small { font-size: 11px; font-weight: 600; color: var(--ink-3); letter-spacing: 0; }

/* أشرطة النسب */
.bar { height: 9px; border-radius: 20px; background: #eaf0f5; overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; transition: width .5s cubic-bezier(.3,.9,.3,1); }
.bar i.s { background: linear-gradient(90deg, #2ea373, #3fbd86); }
.bar i.v { background: linear-gradient(90deg, #d9a13a, #eab657); }
.bar i.n { background: #dfe6ed; }

/* ============================================================
   المؤشرات
   ============================================================ */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: 14px; }
.kpi {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px;
  box-shadow: var(--sh-1); position: relative; overflow: hidden;
}
.kpi::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--g2); }
.kpi.ok::before { background: var(--ok); }
.kpi.warn::before { background: #d9a13a; }
.kpi.dan::before { background: var(--dan); }
.kpi .lb { font-size: 12.5px; color: var(--ink-3); font-weight: 600; }
.kpi .vl { font-size: 30px; font-weight: 800; letter-spacing: -1px; line-height: 1.3; }
.kpi .sb { font-size: 11.5px; color: var(--ink-3); }

/* ============================================================
   مفتاح الإظهار (تظهر للمعلمات)
   ============================================================ */
.sw {
  width: 42px; height: 23px; border-radius: 999px; border: none; padding: 0;
  background: #d3dfe9; position: relative; cursor: pointer; transition: background .2s;
  display: inline-block; vertical-align: middle;
}
.sw i {
  position: absolute; top: 3px; right: 3px; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(13,34,51,.3); transition: transform .2s;
}
.sw.on { background: linear-gradient(90deg, #3f9d6d, #2e7fb8); }
.sw.on i { transform: translateX(-19px); }
.sw:disabled { opacity: .5; cursor: wait; }
.sw:hover:not(:disabled) { filter: brightness(1.06); }

/* صندوق تنبيه داخل الواجهة (ليس وثيقة مطبوعة) */
.lead-box {
  background: var(--tint); border: 1px solid var(--line); border-right: 4px solid var(--g1);
  border-radius: 10px; padding: 11px 14px; line-height: 1.9; font-size: 13.5px; color: var(--ink-2);
}
.lead-box b { color: var(--ink); }
