:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #1c2630;
  --muted: #66727f;
  --line: #dde3e8;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #e0f2ef;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Kufi Arabic", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* مكان شريط التمرير محجوز دائماً ⇒ الصفحة لا تتحرك أفقياً حين يظهر بعد تحميل المحتوى (الكمبيوتر؛ الجوال شريطه فوق المحتوى فلا يتأثر) */
html { scrollbar-gutter: stable; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- الهيدر والتنقل ---------- */
/* الهيدر كاملاً (الشعار + القائمة) ثابت أعلى الشاشة. الجوال: يختفي عند التمرير للأسفل ويظهر للأعلى (hideOnScroll في common.js) */
body > header.app-hdr { position: sticky; top: 0; z-index: 50; transition: transform .2s ease; box-shadow: 0 2px 6px rgba(0, 0, 0, .12); }
body > header.app-hdr.hdr-hide { transform: translateY(-100%); box-shadow: none; }
body > header.app-hdr.hdr-ph { background: var(--primary); box-shadow: none; }
/* الكمبيوتر: أماكن محجوزة قبل وصول البيانات ⇒ لا يقفز ما تحتها. كل حجز يزول وحده حين يمتلئ مكانه
   (:empty / نص "جارٍ التحميل")، وما قد يبقى فارغاً يُحجز فقط حتى يمتلئ عنصر آخر في صفحته يُرسم معه */
@media screen and (min-width: 768px) {
  /* الهيدر قبل أي سكربت (main أول ما في الصفحة = لم يُرسم الهيدر بعد): 98 بشريط التنقل، 54 بدونه (المعلم والمشرف).
     padding على body لا margin على main: الهامش يعبر إلى body فيتحرك body نفسه حين يُرسم الهيدر */
  body:has(> main.page:first-child) { padding-top: 98px; background: linear-gradient(var(--primary) 54px, #0b5f58 54px 98px, var(--bg) 98px) no-repeat var(--bg); }
  body:has(> main#app.page:first-child, > main.page:first-child > #classBox, > main.page:first-child #range) { padding-top: 54px; background: linear-gradient(var(--primary) 54px, var(--bg) 54px) no-repeat var(--bg); }
  #dayNotice:empty { min-height: 62px; }                                   /* البوابة: شريط التاريخ */
  .stats:empty { min-height: 81px; }                                       /* البوابة وسجل اليوم: بطاقات الإحصاء */
  #recent:empty { min-height: 40px; }                                      /* البوابة: آخر المسجلين */
  #dLabel:not(:has(small)) { min-height: 39px; }                           /* ملخص اليوم: التاريخ */
  #out:has(> p.empty:only-child), main#app:has(> p.muted:only-child) { display: flow-root; min-height: 100vh; }
  main:has(#cand:empty) #notice:empty { min-height: 62px; }                /* مراجعة الغياب */
  .table-wrap:has(> #tbl:empty) { min-height: 100vh; }                     /* سجل اليوم، الطلاب: آخر ما في الصفحة */
  .table-wrap:has(> #cand:empty) { min-height: 123px; }                    /* مراجعة الغياب: ارتفاع الجدول بلا مقترحين */
  #top:empty { min-height: 94px; }                                         /* الجدول */
  #head:empty { min-height: 109px; }                                       /* المعلم: بطاقة الحصة */
  #invite:empty { min-height: 43px; }                                      /* الإدارة: رابط التسجيل */
  #modeHelp:empty, #paHelp:empty { min-height: 78px; }                     /* المواقيت */
  .table-wrap:has(#periods:empty) { min-height: 417px; }
  main:has(#days:empty) #breaks:empty { min-height: 46px; }
  #days:empty { min-height: 42px; }
  /* مراجعة الغياب: "حصص لم تُرصد" سطر واحد ثابت دائماً، والتفاصيل عند الضغط */
  #missingBox, #missingBox[hidden] { display: block !important; }
  #missingBox:not(.open) > :not(.ms-sum) { display: none; }
  #missingBox .ms-sum { display: block; width: 100%; padding: 0; border: 0; background: none; font: inherit; font-size: 15px; line-height: 24px;
    text-align: start; color: var(--muted); cursor: default; }
  #missingBox.has .ms-sum { color: var(--warn); font-weight: 700; cursor: pointer; }
  #missingBox.open .ms-sum { margin-bottom: 12px; }
}
.ms-sum { display: none; }
@media screen and (min-width: 768px) and (max-width: 1023px) { #top:empty { min-height: 113px; } }
@media (min-width: 701px) { html { scroll-padding-top: calc(var(--hdr-h, 0px) + 8px); } }
.topbar {
  background: var(--primary); color: var(--primary-ink);
}
.topbar-row { display: flex; align-items: center; gap: 10px; padding: 10px 16px; max-width: 1200px; margin: 0 auto; }
.top-logo { height: 34px; width: auto; background: #fff; border-radius: 8px; padding: 2px 6px; flex: none; }
.brand { font-weight: 700; font-size: 17px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { font-weight: 400; opacity: .85; font-size: 13px; margin-inline-start: 6px; }
.user-btn {
  background: rgba(255, 255, 255, .15); border: 0; color: inherit; border-radius: 999px;
  padding: 6px 12px; cursor: pointer; font-size: 14px; white-space: nowrap;
}
.nav { background: #0b5f58; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav-inner { display: flex; gap: 2px; padding: 0 8px; max-width: 1200px; margin: 0 auto; }
.nav a {
  color: rgba(255, 255, 255, .82); text-decoration: none; padding: 9px 14px; white-space: nowrap;
  font-size: 15px; border-bottom: 3px solid transparent;
}
.nav a.active { color: #fff; border-bottom-color: #5eead4; font-weight: 600; }

.page { max-width: 1200px; margin: 0 auto; padding: 16px; }
.page-narrow { max-width: 720px; }

/* ---------- عناصر عامة ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card h2, .card h3 { margin: 0 0 12px; font-size: 18px; }
.card h3 { font-size: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.mb0 { margin-bottom: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 15px;
  min-height: 42px; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.warn { background: var(--warn); color: #fff; border-color: var(--warn); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { min-height: 34px; padding: 5px 10px; font-size: 14px; }
.btn.lg { min-height: 52px; font-size: 17px; padding: 12px 22px; }
.btn.block { width: 100%; }

label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fff;
  min-height: 42px; font-size: 16px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.inline-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.inline-fields > * { min-width: 0; }
/* الآيفون (Safari): خانة التاريخ/الوقت لها عرض أدنى ثابت فتخرج من عمودها، والتاريخ الإنجليزي يُقلب في RTL ("Oct 2026 12") */
@supports (-webkit-touch-callout: none) {
  input[type=date], input[type=time] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%; direction: ltr; }
  input[type=date]::-webkit-date-and-time-value, input[type=time]::-webkit-date-and-time-value { text-align: right; }
}

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.present { background: var(--ok-soft); color: var(--ok); }
.badge.late { background: var(--warn-soft); color: var(--warn); }
.badge.absent { background: var(--bad-soft); color: var(--bad); }
.badge.excused { background: var(--info-soft); color: var(--info); }
.badge.dismissed { background: #ede9fe; color: #6d28d9; }
.badge.none { background: #eef1f4; color: var(--muted); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 16px;
  cursor: pointer; font-weight: 600; min-height: 42px; font-size: 15px;
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip .tick { color: var(--ok); margin-inline-start: 4px; }
.chip.active .tick { color: #a7f3d0; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat b { display: block; font-size: 26px; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 14px; }
.stat.ok b { color: var(--ok); } .stat.warn b { color: var(--warn); } .stat.bad b { color: var(--bad); } .stat.info b { color: var(--info); }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
th { background: var(--surface-2); font-weight: 700; font-size: 14px; white-space: nowrap; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfc; }
td.num, th.num { text-align: center; width: 1%; white-space: nowrap; }
td.zero { color: #b8c0c8; }
td.nmc { min-width: 170px; }
@media print { td.nmc { min-width: 0; } }
.cell-p { text-align: center; width: 44px; cursor: pointer; user-select: none; font-weight: 700; }
.cell-p.abs { background: var(--bad-soft); color: var(--bad); }
.cell-p.exc { background: var(--info-soft); color: var(--info); }
.cell-p.off { background: #f1f3f5; color: #aab3bb; cursor: default; }
.cell-p.dis { background: #f3effe; color: #8b5cf6; cursor: default; }

/* ---------- Toast + Modal ---------- */
#toasts { position: fixed; bottom: 16px; left: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); max-width: 520px; pointer-events: auto; animation: tin .2s ease-out; }
.toast.ok { background: var(--ok); } .toast.bad { background: var(--bad); } .toast.warn { background: var(--warn); }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }

.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 150; display: flex; align-items: flex-end; justify-content: center; padding: 0; }
.modal {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 16px 16px 0 0; padding: 18px 16px; box-shadow: 0 -10px 30px rgba(0, 0, 0, .2);
}
.modal h3 { margin: 0 0 12px; }
@media (min-width: 640px) {
  .modal-back { align-items: center; padding: 16px; }
  .modal { border-radius: 16px; }
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 16px; flex-wrap: wrap; }
/* قائمة المستخدم: أزرار متساوية في عمودين */
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.menu-grid .btn { width: 100%; min-height: 48px; padding: 10px 8px; }
.menu-grid .wide { grid-column: 1 / -1; }
.menu-grid .menu-label { grid-column: 1 / -1; font-size: 13px; font-weight: 700; color: var(--muted); margin: 4px 2px -4px; }
/* شريط "فعّل الإشعارات" في صفحة المعلم (pushNudge) */
.push-nudge { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
.push-nudge-btns { display: flex; gap: 8px; margin-inline-start: auto; }
.menu-grid .menu-sep { grid-column: 1 / -1; border-top: 1px solid var(--line, #e5e7eb); margin: 4px 0 0; }
.btn.danger-soft { background: var(--bad-soft); color: var(--bad); border-color: #fecaca; }
.btn.danger-soft:hover { background: #fecaca; }
.btn.primary-soft { background: var(--primary-soft); color: var(--primary); border-color: #b2dfd8; font-weight: 700; }
.btn.muted-btn { background: #eef1f4; color: var(--muted); border-color: #eef1f4; }
.btn.muted-btn:hover { background: #e2e7ec; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--info-soft); color: #1e3a8a; margin-bottom: 14px; }
.notice.warn { background: var(--warn-soft); color: #78350f; }
.notice.bad { background: var(--bad-soft); color: #7f1d1d; }
.notice.ok { background: var(--ok-soft); color: #14532d; }

/* ---------- شاشة المعلم: بطاقات الطلاب ---------- */
.period-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.period-num { background: var(--primary); color: #fff; border-radius: 12px; padding: 8px 14px; font-weight: 700; font-size: 18px; }
.countdown { font-variant-numeric: tabular-nums; }
.students-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.st {
  display: flex; align-items: center; gap: 10px; background: var(--surface); border: 2px solid var(--line);
  border-radius: 12px; padding: 10px 12px; cursor: pointer; user-select: none; min-height: 58px; text-align: right; width: 100%;
}
.st .n { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 13px; color: var(--muted); flex: none; }
.st .nm { flex: 1; font-weight: 600; font-size: 15px; line-height: 1.35; }
.st .tag { font-size: 12px; }
.st.abs { border-color: var(--bad); background: var(--bad-soft); }
.st.abs.exc { border-color: var(--info); background: var(--info-soft); }
.st.abs .n { background: var(--bad); color: #fff; }
.st.faded { opacity: .42; cursor: not-allowed; background: #eef1f4; }
.st.faded .nm { text-decoration: line-through; text-decoration-color: rgba(0, 0, 0, .25); }
.savebar {
  position: sticky; bottom: 0; z-index: 40; background: var(--surface); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 12px; margin: 16px -16px -16px;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, .06);
}

/* ---------- البوابة ---------- */
.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; max-height: 52vh; width: 100%; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; inset: 18% 22%; border: 3px solid rgba(94, 234, 212, .9); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .25); pointer-events: none; }
.scanner .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: #cbd5e1; text-align: center; padding: 16px; }
.scan-result { border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; font-size: 18px; font-weight: 700; display: flex; gap: 12px; align-items: center; min-height: 70px; }
.scan-result .big { font-size: 22px; }
.scan-result.present { background: var(--ok-soft); color: var(--ok); border: 2px solid var(--ok); }
.scan-result.late { background: var(--warn-soft); color: var(--warn); border: 2px solid var(--warn); }
.scan-result.already { background: var(--info-soft); color: var(--info); border: 2px solid var(--info); }
.scan-result.error { background: var(--bad-soft); color: var(--bad); border: 2px solid var(--bad); }
.scan-result.idle { background: var(--surface); color: var(--muted); border: 2px dashed var(--line); font-weight: 400; font-size: 16px; }
.gate-layout { display: grid; gap: 16px; }
@media (min-width: 900px) { .gate-layout { grid-template-columns: 1.1fr 1fr; align-items: start; } }

.search-results { border: 1px solid var(--line); border-radius: 10px; margin-top: 6px; max-height: 280px; overflow: auto; background: #fff; }
.search-results button { display: flex; width: 100%; gap: 8px; border: 0; background: none; padding: 10px 12px; text-align: right; cursor: pointer; border-bottom: 1px solid var(--line); align-items: center; }
.search-results button:hover { background: var(--surface-2); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

/* ---------- بطاقات QR ---------- */
.qr-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.qr-card { border: 1.5px dashed #94a3b8; border-radius: 10px; padding: 10px; text-align: center; background: #fff; break-inside: avoid; page-break-inside: avoid; }
.qr-card .school { font-size: 11px; color: var(--muted); }
.qr-card .nm { font-weight: 700; font-size: 13px; margin: 4px 0; min-height: 2.6em; line-height: 1.3; }
.qr-card svg { width: 130px; height: 130px; }
.qr-card .id { font-family: Consolas, monospace; font-size: 13px; letter-spacing: 1px; }
.qr-list td svg { width: 64px; height: 64px; display: block; }

/* ---------- الطباعة ---------- */
.print-only { display: none; }
@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; font-size: 12px; }
  body > header.app-hdr, .topbar, .nav, .no-print, #toasts, .savebar { display: none !important; }
  .print-only { display: block; }
  .page { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; margin-bottom: 10px; }
  .table-wrap { border: 0; overflow: visible; }
  th, td, tbody tr:last-child td { padding: 4px 6px; border: 1px solid #999; font-size: 11.5px; }
  th { position: static; background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .badge { padding: 0; background: none !important; color: #000 !important; }
  .page-break { page-break-after: always; break-after: page; }
  .qr-cards { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .qr-card svg { width: 110px; height: 110px; }
  tr { break-inside: avoid; }
}
.print-head { text-align: center; margin-bottom: 10px; }
.print-head .school-logo { height: 52px; width: auto; display: block; margin: 0 auto 4px; }
.qr-card .school-logo { height: 22px; width: auto; display: block; margin: 0 auto 2px; }
.print-head h2 { margin: 0; font-size: 18px; }
.print-head div { font-size: 13px; }

/* ---------- تسجيل الدخول ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #0f766e, #134e4a); }
.login-card { background: #fff; border-radius: 18px; padding: 28px 22px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.login-card .logo { width: 140px; height: auto; margin: 0 auto 12px; display: block; }

/* تسجيل المعلم */
.join-card { max-width: 440px; }
.join-chips { margin-bottom: 8px; }
.join-chips .chip { display: inline-flex; gap: 6px; align-items: center; color: var(--text); cursor: pointer; margin: 0; font-size: 15px; }
.join-chips .chip input { width: auto; }
.join-chips .chip.active { color: #fff; }
.mt-xs { margin-top: 4px; }

/* تثبيت التطبيق */
.install-btn { background: #fff; color: var(--primary); font-weight: 700; }
.install-steps { padding-inline-start: 22px; line-height: 1.9; margin: 8px 0 12px; }
.install-steps li { margin-bottom: 4px; }

@media (max-width: 600px) {
  .install-btn { padding: 6px 10px; font-size: 13px; }
  .page { padding: 12px; }
  .card { padding: 12px; }
  .students-grid { grid-template-columns: 1fr; }
  .savebar { margin: 12px -12px -12px; }
  th, td { padding: 7px 6px; font-size: 14px; }
}

/* شريط "يوجد تحديث" (التحديث التلقائي في common.js) */
.update-bar { position: fixed; bottom: 12px; left: 12px; right: 12px; z-index: 190; margin: 0 auto; max-width: 520px; display: block;
  background: var(--primary); color: #fff; border: 0; border-radius: 12px; padding: 12px 16px; font: inherit; font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); cursor: pointer; }
@media print { .update-bar { display: none !important; } }

/* كشف الطلاب المطبوع (students.html): خانات فارغة للكتابة */
.print-sheet { width: 100%; border-collapse: collapse; }
.print-sheet th, .print-sheet td { border: 1px solid #999; padding: 6px; height: 26px; }
.print-sheet td:nth-child(n+3) { min-width: 50px; }

/* ---------- إحساس التطبيق على الجوال (بلا أثر في الشكل) ---------- */
/* لا تكبير بضغطتين (التكبير بإصبعين يبقى)، ولا سحب تحديث عرضي */
*, *::before, *::after { touch-action: manipulation; }
html, body { overscroll-behavior-y: contain; }
/* الضغط الطويل على الأزرار والتبويبات وخانات الطلاب: لا تحديد نص ولا قائمة. الحقول والنصوص العادية كما هي */
button, .btn, .chip, .tabs, .m-tabbar, .m-tab, .m-row, .st, .cell-p { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* انتقال ناعم بين الصفحات (المتصفحات التي تدعمه فقط) */
@media (prefers-reduced-motion: no-preference) { @view-transition { navigation: auto; } }
/* iOS/Safari: بلا انتقال (الوميض الأبيض ظهر على الآيفون المثبّت رغم ثبات الهيدر). -webkit-touch-callout يدعمه WebKit على iOS فقط ⇒ أندرويد والكمبيوتر يبقى عندهما الانتقال */
@supports (-webkit-touch-callout: none) { @view-transition { navigation: none; } }
/* أثناء الانتقال: الهيدر والشريط السفلي لقطتان مستقلتان بلا تلاشٍ ⇒ يتلاشى المحتوى وحده (كان الهيدر يتلاشى مع الصفحة فتظهر الخلفية الفاتحة من خلاله لحظة).
   الإخفاء عند التمرير (transform) يبقى كما هو: الاسم لا يغيّر التخطيط */
body > header.app-hdr { view-transition-name: app-header; }
.m-tabbar { view-transition-name: app-nav; }
::view-transition-old(app-header), ::view-transition-new(app-header),
::view-transition-old(app-nav), ::view-transition-new(app-nav) { animation: none; }
/* حافة الشاشة العلوية (safe-area، viewport-fit=cover) بلون الهيدر ⇒ لا أبيض فيها ولو تأخر الرسم. بقية الصفحة --bg كما كانت */
:root { --hdr-bg: var(--primary); }
html, body { background: linear-gradient(var(--hdr-bg), var(--hdr-bg)) top / 100% env(safe-area-inset-top, 0px) no-repeat var(--bg); }
@media screen and (max-width: 767px) and (prefers-color-scheme: dark) { :root { --hdr-bg: #0b4f4a; } }
/* "الخادم غير متاح" (common.js netBar): فوق الصفحة بلا إزاحة لما تحته، ولا يحجب الضغط */
#netBar {
  position: fixed; top: env(safe-area-inset-top, 0); inset-inline: 0; z-index: 9000; pointer-events: none; text-align: center;
  background: #fef3c7; color: #92400e; border-bottom: 1px solid #fcd34d; font-size: 13px; font-weight: 700; padding: 3px 8px; line-height: 1.5;
}
#standbyBar {
  position: fixed; top: env(safe-area-inset-top, 0); inset-inline: 0; z-index: 9001; pointer-events: none; text-align: center;
  background: #b91c1c; color: #fff; font-size: 13px; font-weight: 700; padding: 3px 8px; line-height: 1.5;
}
@media print { #netBar, #standbyBar { display: none !important; } }

/* ---------- صورة المعلم (دائرة الهيدر + بجانب الاسم في متابعة الرصد وقائمة المستخدمين) ---------- */
.av {
  --av: #0f766e; position: relative; display: inline-grid; place-items: center; flex: none; vertical-align: middle;
  width: 30px; height: 30px; border-radius: 50%; overflow: hidden; background: var(--av); color: #fff; font-weight: 700; font-size: 14px; line-height: 1;
}
.av::before { content: attr(data-l); } /* الحرف من CSS ⇒ لا يدخل في نص الجدول (Excel) */
.av img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #fff; }
.av.sm { width: 20px; height: 20px; font-size: 11px; margin-inline-end: 4px; }
.av.lg { width: 40px; height: 40px; font-size: 18px; }
/* 34px = ارتفاع الشعار ⇒ الهيدر بنفس ارتفاعه (الحجز في app.css يعتمد عليه)؛ منطقة الضغط أوسع بلا تغيير في التخطيط */
.av-btn { position: relative; flex: none; display: inline-flex; padding: 2px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .35); cursor: pointer; }
.av-btn::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; }
.av-menu {
  position: fixed; z-index: 300; min-width: 200px; max-width: calc(100vw - 16px); padding: 6px; display: flex; flex-direction: column;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 28px rgba(16, 24, 40, .18);
}
.av-menu-hd { display: flex; align-items: center; gap: 10px; padding: 6px 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.av-menu-hd b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.av-menu button, .av-menu a {
  display: block; width: 100%; min-height: 44px; padding: 10px 12px; border: 0; border-radius: 8px; background: none; color: inherit;
  font: inherit; font-size: 15px; text-align: start; text-decoration: none; cursor: pointer;
}
.av-menu button:hover, .av-menu a:hover { background: var(--surface-2); }
.av-menu .av-out { color: var(--bad); }
@media print { .av, .av-menu { display: none !important; } }
