/* حلقات التحفيظ */
:root {
  --accent: #2257c4;
  --accent-d: #1a4499;
  --accent-50: #eef3fc;
  --accent-100: #dce7fa;
  --bg: #FAFAF8;
  --card: #ffffff;
  --line: #e6e4de;
  --line-2: #d9d6cf;
  --ink: #1d2433;
  --ink-2: #4a5266;
  --muted: #7a8094;
  --ok: #1f8a4c;
  --ok-50: #e8f5ed;
  --wait: #a2620b;
  --wait-50: #fdf3e3;
  --danger: #c23a3a;
  --danger-50: #fcecec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .05), 0 2px 8px rgba(20, 30, 60, .04);
  --font: "IBM Plex Sans Arabic", "Segoe UI", "Noto Sans Arabic", Tahoma, "Geeza Pro", "SF Arabic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 16px; line-height: 1.6;
  min-height: 100vh; display: flex; flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.35; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid rgba(34, 87, 196, .35); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* الشريط العلوي */
.topbar { position: sticky; top: 0; z-index: 30; background: rgba(255, 255, 255, .94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.topbar-in { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; gap: 8px; padding: 8px 20px; min-height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; font-size: 19px; min-height: 44px; margin-inline-end: auto; white-space: nowrap; }
.brand img { border-radius: 9px; border: 1px solid var(--line); }
.top-actions { display: flex; align-items: center; gap: 6px; }
.back { gap: 6px !important; padding: 0 12px !important; width: auto !important; font-weight: 600; color: var(--accent) !important; }
.back span[aria-hidden] { font-size: 20px; }
.ib-short { display: none; }

.wrap { width: 100%; max-width: 1240px; margin: 0 auto; padding: 20px 20px 32px; flex: 1; outline: none; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 14px 0 calc(14px + env(safe-area-inset-bottom)); }

/* الأزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; font-size: 16px; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
  background: var(--card); color: var(--ink);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-d); }
.btn.success { background: var(--ok); color: #fff; }
.btn.success:hover { background: #18703d; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: var(--card); border-color: var(--line-2); color: var(--ink); }
.btn.ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn.lg { min-height: 52px; padding: 0 22px; }
.btn.xl { min-height: 60px; padding: 0 30px; font-size: 18px; border-radius: 14px; box-shadow: 0 4px 14px rgba(34, 87, 196, .25); }
.btn.xl svg { width: 24px; height: 24px; }
.btn.sm { min-height: 44px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.sm svg { width: 18px; height: 18px; }
.btn.full { width: 100%; margin-top: 10px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--ink-2); font-size: 22px;
}
.icon-btn:hover { background: var(--accent-50); color: var(--accent); }
.icon-btn.danger-ic:hover { background: var(--danger-50); color: var(--danger); }

/* رأس الصفحة */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { padding: 4px 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 28px; }
.sub { margin: 4px 0 0; color: var(--ink-2); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.dot { color: var(--line-2); }
.head-btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* البحث */
.search { position: relative; display: flex; align-items: center; margin-bottom: 18px; }
.search svg { position: absolute; inset-inline-start: 14px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; min-height: 52px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--card);
  padding: 0 46px 0 14px; font-size: 16px; -webkit-appearance: none; appearance: none;
}
.search input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(34, 87, 196, .15); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .search { margin: 0; }
.grow { flex: 1 1 260px; }

/* الكروت */
.grid { display: grid; gap: 16px; }
.cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.students { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card {
  position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; transition: border-color .15s, box-shadow .15s;
}
.card:hover { border-color: var(--accent-100); box-shadow: 0 4px 18px rgba(34, 87, 196, .08); }
.card-link { position: absolute; inset: 0; border-radius: inherit; z-index: 1; }
.card-actions { position: absolute; top: 12px; inset-inline-end: 12px; display: flex; gap: 2px; z-index: 2; }
.card-actions.inline { position: static; }
.cc-top { display: flex; align-items: center; gap: 12px; padding-inline-end: 96px; margin-bottom: 16px; }
.cc-top h2 { font-size: 22px; }
.cc-mark { width: 48px; height: 48px; border-radius: 12px; background: var(--accent-50); color: var(--accent); display: grid; place-items: center; flex: none; }
.cc-mark svg { width: 26px; height: 26px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.stats div { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; min-width: 0; }
.stats dt { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.stats dt svg { width: 15px; height: 15px; }
.stats dd { margin: 2px 0 0; font-weight: 700; font-size: 16.5px; white-space: nowrap; }

.student-card { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px; }
.sc-head { display: flex; align-items: center; gap: 12px; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--accent-50); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 20px; flex: none; }
.sc-name { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; }
.sc-name h2 { font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.sc-task { margin: 0; color: var(--ink-2); font-size: 14.5px; min-height: 2.9em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sc-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line); padding-top: 8px; font-size: 13.5px; margin-top: auto; }
.sc-foot .card-actions { position: relative; z-index: 2; }

.pill { display: inline-flex; align-items: center; min-height: 26px; padding: 0 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: #f0efea; color: var(--ink-2); white-space: nowrap; }
.pill.ok { background: var(--ok-50); color: var(--ok); }
.pill.wait { background: var(--wait-50); color: var(--wait); }

.empty { grid-column: 1 / -1; text-align: center; color: var(--ink-2); background: var(--card); border: 1px dashed var(--line-2); border-radius: var(--radius); padding: 36px 20px; }
.empty svg { width: 40px; height: 40px; color: var(--accent); }
.empty p { margin: 8px 0 0; }

.results { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 18px; }
.results h3 { font-size: 16px; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.count { background: var(--accent-50); color: var(--accent); border-radius: 999px; padding: 0 9px; font-size: 13px; }
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 52px; padding: 0 12px; border-radius: 10px; color: var(--ink); }
.list-item:hover { background: var(--accent-50); }
.pad { padding: 8px 12px; margin: 0; }

.backup { margin-top: 28px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.backup h3 { font-size: 17px; }
.backup p { margin: 2px 0 0; color: var(--ink-2); font-size: 14.5px; }
.backup-btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* التنقل بين الطلاب */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.pager-count { font-weight: 700; color: var(--ink-2); background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 16px; }
.pager .btn span[aria-hidden] { font-size: 19px; }

/* جدول السجل */
.table-box {
  position: relative; overflow: auto; max-height: max(380px, calc(100vh - 330px)); max-height: max(380px, calc(100dvh - 330px));
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.log { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: 14.5px; }
.log th, .log td { border-bottom: 1px solid var(--line); border-inline-start: 1px solid var(--line); padding: 10px 12px; text-align: right; vertical-align: top; background: var(--card); }
.log tr > :first-child { border-inline-start: 0; }
.log thead th { position: sticky; z-index: 3; background: #f4f6fb; color: var(--ink); font-weight: 700; white-space: nowrap; vertical-align: middle; font-size: 14px; }
.log thead tr.h1 th { top: 0; height: 44px; }
.log thead tr.h2 th { top: 44px; }
.log thead th[rowspan] { top: 0; }
.log thead th.grp { text-align: center; }
.log thead .g-task { background: #e7eefb; color: var(--accent-d); }
.log thead .g-rec { background: #e9f4ee; color: #17663a; }
.log thead .t-rec { background: #f1f8f4; }
.log .sticky-col { position: sticky; right: 0; z-index: 2; min-width: 84px; text-align: center; font-weight: 700; box-shadow: -1px 0 0 var(--line); }
.log thead .sticky-col { z-index: 5; }
.log tbody th.sticky-col { background: #fbfbf9; }
.log td.txt { min-width: 210px; max-width: 280px; line-height: 1.55; }
.log td.t-rec { background: #fcfefd; }
.log tr.is-last td, .log tr.is-last th { background: #f7f9ff; }
.log tr.is-last td.t-rec { background: #f5fbf7; }
.status-cell { min-width: 150px; }
.status-cell .pill { display: flex; width: max-content; margin-bottom: 8px; }
.row-acts { white-space: nowrap; vertical-align: middle !important; }
.grade { display: inline-flex; align-items: center; min-height: 36px; margin-top: 6px; padding: 0 10px; border-radius: 8px; border: 1px dashed var(--line-2); background: transparent; font-size: 13px; color: var(--muted); position: relative; }
.grade::after { content: ""; position: absolute; inset: -4px; }
.grade.g0 { border: 0; background: var(--ok-50); color: var(--ok); font-weight: 700; }
.grade.g1 { border: 0; background: var(--accent-50); color: var(--accent); font-weight: 700; }
.grade.g2 { border: 0; background: #f2f0e8; color: #6b5d24; font-weight: 700; }
.grade.g3 { border: 0; background: var(--danger-50); color: var(--danger); font-weight: 700; }
.hint { color: var(--muted); font-size: 14px; margin: 12px 2px 0; }
.empty.big { padding: 48px 20px; }

/* الحوارات */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(18, 24, 40, .45); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .15s ease; }
.modal { background: var(--card); border-radius: 18px; width: 100%; max-width: 860px; max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); animation: pop .18s ease; }
.modal.small { max-width: 460px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 20px 12px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 20px; }
.modal-body { padding: 18px 20px; overflow: auto; -webkit-overflow-scrolling: touch; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-start; padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); flex-direction: row-reverse; }
.modal-foot .btn { min-width: 120px; }
.dlg-msg { margin: 0; font-size: 17px; color: var(--ink-2); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }

.fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fld > span { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.inp {
  width: 100%; min-height: 50px; border: 1px solid var(--line-2); border-radius: 11px; background: #fff; padding: 0 14px; font-size: 16px;
}
select.inp {
  -webkit-appearance: none; appearance: none; padding-left: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234a5266' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-size: 18px; background-position: left 12px center;
}
.inp:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(34, 87, 196, .15); }
.inp:disabled { background-color: #f4f3ef; color: var(--muted); }
input[type=date].inp { direction: rtl; text-align: right; }
.fld.ro output { min-height: 50px; display: flex; align-items: center; padding: 0 14px; border-radius: 11px; background: var(--bg); border: 1px solid var(--line); font-weight: 700; }
.err { color: var(--danger); font-weight: 600; margin: 10px 0 0; }

.entry { display: flex; flex-direction: column; gap: 14px; }
.entry-top { display: grid; grid-template-columns: 1fr 1.6fr 1fr; gap: 12px; }
.rec-box { background: #f3faf6; border: 1px solid #d5ebdd; border-radius: 12px; padding: 12px 14px; }
.rec-box h3 { font-size: 15px; color: #17663a; margin-bottom: 4px; }
.rec-box p { margin: 0; font-size: 14.5px; }
.rec-list { margin: 0; padding-inline-start: 18px; font-size: 14.5px; }
.cat { border: 1px solid var(--line); border-radius: 14px; padding: 6px 14px 14px; margin: 0; min-width: 0; }
.cat legend { font-weight: 700; font-size: 17px; padding: 0 8px; color: var(--accent-d); }
.cat-in { display: flex; flex-direction: column; gap: 12px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; background: #f1f0eb; border-radius: 12px; padding: 4px; }
.seg-b { flex: 1 1 0; min-width: 72px; min-height: 44px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.seg-b.on { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.pick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.preview { margin: 0; background: var(--accent-50); border: 1px solid var(--accent-100); color: var(--accent-d); border-radius: 10px; padding: 10px 12px; font-weight: 600; }
.preview.empty-p { background: #f7f7f4; border-color: var(--line); color: var(--muted); font-weight: 500; }

.opt-list { display: flex; flex-direction: column; gap: 6px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 54px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 16px; font-weight: 600; text-align: right; }
button.opt { justify-content: flex-start; }
.opt:hover { border-color: var(--accent); }
.opt-txt { display: flex; align-items: center; gap: 10px; }
.danger-txt { color: var(--danger); }
.switch { cursor: pointer; position: relative; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sw { width: 48px; height: 28px; border-radius: 999px; background: #d6d4cd; position: relative; transition: background .15s; flex: none; }
.sw::after { content: ""; position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: right .15s; }
.switch input:checked + .sw { background: var(--accent); }
.switch input:checked + .sw::after { right: 23px; }
.switch input:focus-visible + .sw { outline: 3px solid rgba(34, 87, 196, .35); outline-offset: 2px; }
.grade-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grade-opt { min-height: 56px; border-radius: 12px; border: 2px solid transparent; font-weight: 700; font-size: 17px; }
.grade-opt.g0 { background: var(--ok-50); color: var(--ok); }
.grade-opt.g1 { background: var(--accent-50); color: var(--accent); }
.grade-opt.g2 { background: #f2f0e8; color: #6b5d24; }
.grade-opt.g3 { background: var(--danger-50); color: var(--danger); }
.grade-opt.on { border-color: currentColor; }
.howto h3 { font-size: 16px; margin: 4px 0 6px; }
.howto ol { margin: 0 0 14px; padding-inline-start: 22px; }
.howto li { margin-bottom: 4px; }

.toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 80;
  background: #1d2433; color: #fff; border-radius: 12px; padding: 10px 12px 10px 16px; display: flex; align-items: center; gap: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); max-width: calc(100vw - 32px); font-size: 15px; animation: pop .18s ease;
}
.toast-act { min-height: 44px; border: 0; background: rgba(255, 255, 255, .14); color: #fff; border-radius: 9px; padding: 0 14px; font-weight: 700; white-space: nowrap; }

/* شاشات صغيرة */
@media (max-width: 720px) {
  .topbar-in { padding: 6px 12px; min-height: 58px; }
  .brand { font-size: 17px; }
  .brand img { width: 32px; height: 32px; }
  .ib-long { display: none; }
  .ib-short { display: inline; }
  .back-txt { display: none; }
  .wrap { padding: 14px 14px 24px; }
  .page-head h1 { font-size: 24px; }
  .page-head .head-btns, .page-head > .btn { width: 100%; }
  .head-btns .btn { flex: 1 1 0; }
  .cards, .students { grid-template-columns: 1fr; }
  .toolbar .btn { flex: 1 1 0; }
  .pager .btn { padding: 0 12px; font-size: 14.5px; }
  .modal-back { padding: 0; align-items: flex-end; }
  .modal { max-height: 94vh; max-height: 94dvh; border-radius: 18px 18px 0 0; }
  .modal.small { max-width: none; }
  .modal-body { padding: 14px; }
  .entry-top { grid-template-columns: 1fr 1fr; }
  .entry-top .fld:nth-child(2) { grid-column: 1 / -1; order: -1; }
  .pick-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .seg-b { min-width: 0; padding: 0 4px; }
  .modal-foot .btn { flex: 1 1 0; min-width: 0; }
  .table-box { max-height: max(380px, calc(100dvh - 300px)); }
  .stats dt { font-size: 12px; }
  .log td.txt { min-width: 180px; }
  .log .sticky-col { min-width: 64px; }
  .status-cell { min-width: 140px; }
  .backup-btns, .backup-btns .btn { width: 100%; }
}
@media (max-width: 380px) {
  .pager .btn span:not([aria-hidden]) { display: none; }
}
@media (min-width: 900px) {
  .pick-grid { grid-template-columns: repeat(4, 1fr); }
  .cat { padding-bottom: 12px; }
}
.date-wrap { position: relative; display: block; }
.date-show { display: flex; align-items: center; font-weight: 700; }
.date-wrap svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--accent); pointer-events: none; }
.date-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; margin: 0; -webkit-appearance: none; appearance: none; }
.date-wrap:focus-within .date-show { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 87, 196, .15); }
