/* =====================================================================
   تطبيق الترحيل والانصراف — واجهة الجوال
   مقاسات اللمس كبيرة عمداً: مسؤول الانصراف يستخدم الجهاز واقفاً في
   الساحة، بيد واحدة، وتحت ضوء الشمس. التباين مرفوع لنفس السبب.
   ===================================================================== */
:root {
  --blue: #0078dc;
  --blue-dark: #0063b8;
  --navy: #073863;
  --green: #2e7d32;
  --green-bg: #e8f5e9;
  --yellow: #f5fa50;
  --ink: #14232f;
  --muted: #5b6672;
  --line: #dde3e9;
  --bg: #f2f5f8;
  --card: #fff;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --warn: #a86b12;
  --warn-bg: #fdf3e0;
  --tap: 48px;
  --shadow: 0 1px 2px rgba(7,56,99,.07), 0 4px 14px rgba(7,56,99,.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; min-height: 100%;
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 16px; line-height: 1.55;
  /* الاتجاه من سمة dir على <html> — تضبطها وحدة اللغة */
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }

.muted { color: var(--muted); }
.tiny { font-size: 12.5px; }
.small { font-size: 14px; }
[hidden] { display: none !important; }

/* ---------- شريط الشبكة ---------- */
.netbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px; justify-content: center;
  padding: 7px 12px; font-size: 13.5px; font-weight: 600;
  background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid #eedcb8;
}
.netbar.off { background: var(--danger-bg); color: var(--danger); border-bottom-color: #f2c6c1; }
.netbar.ok { background: var(--green-bg); color: var(--green); border-bottom-color: #c5e5c7; }
.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; padding: 0; }

/* ---------- الدخول ---------- */
.screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
#login { background: linear-gradient(165deg, #e9f3fc 0%, #f2f5f8 60%, #eef7ee 100%); }
.login-card {
  width: min(400px, 100%); background: var(--card); border-radius: 16px;
  box-shadow: var(--shadow); padding: 30px 24px; text-align: center;
}
.login-card img { object-fit: contain; }
.login-card h1 { font-size: 21px; margin: 12px 0 2px; color: var(--navy); }
.login-card .sub { margin: 0 0 20px; color: var(--muted); font-size: 13.5px; }
.field { text-align: start; margin-bottom: 14px; }
label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 5px; }
input[type=text], input[type=password], input[type=tel], input[type=date],
input[type=time], input[type=search], input[type=number], select, textarea {
  width: 100%; padding: 12px; min-height: var(--tap);
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,120,220,.15);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 11px 18px; border: 1px solid transparent;
  border-radius: 10px; background: var(--blue); color: #fff; font-weight: 700;
  cursor: pointer; font-size: 15.5px;
}
.btn:active { background: var(--blue-dark); }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--navy); border-color: var(--line); }
.btn.danger { background: var(--danger); }
.btn.ok { background: var(--green); }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: 14px; border-radius: 8px; }

.msg { display: none; padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; text-align: start; }
.msg.on { display: block; }
.msg.err { background: var(--danger-bg); color: var(--danger); }
.msg.ok { background: var(--green-bg); color: var(--green); }

/* ---------- الهيكل ---------- */
#topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--navy); color: #fff;
}
#topbar .titles { flex: 1; min-width: 0; line-height: 1.25; }
#topbar .titles b { display: block; font-size: 16px; }
#topbar .titles span { color: #b8cde0 !important; }
.icon-btn {
  position: relative; width: var(--tap); height: var(--tap); flex: none;
  border: 0; background: rgba(255,255,255,.12); color: #fff;
  border-radius: 10px; font-size: 19px; cursor: pointer;
}
.dot {
  position: absolute; top: 6px; inset-inline-start: 6px;
  width: 9px; height: 9px; border-radius: 50%; background: var(--yellow);
}

#tabs { display: flex; gap: 6px; padding: 8px 10px; background: #fff; border-bottom: 1px solid var(--line); overflow-x: auto; }
#tabs button {
  flex: none; min-height: 40px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--navy);
  font-size: 14.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
#tabs button.on { background: var(--blue); border-color: var(--blue); color: #fff; }

main { padding: 12px 12px 90px; max-width: 900px; margin: 0 auto; }

/* ---------- بطاقات ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card > h3 { margin: 0 0 10px; font-size: 15.5px; color: var(--navy); }
.card.flat { box-shadow: none; }

.stat-row { display: flex; gap: 8px; margin-bottom: 12px; }
.stat {
  flex: 1; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; text-align: center;
}
.stat b { display: block; font-size: 23px; color: var(--navy); line-height: 1.15; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.warn { background: var(--warn-bg); border-color: #eedcb8; }
.stat.warn b { color: var(--warn); }
.stat.ok { background: var(--green-bg); border-color: #c5e5c7; }
.stat.ok b { color: var(--green); }

/* ---------- الرمز اليومي ---------- */
.code-card {
  background: linear-gradient(150deg, var(--navy), #0a4f8a);
  color: #fff; border-radius: 16px; padding: 20px; text-align: center; margin-bottom: 14px;
}
.code-card .label { font-size: 13px; opacity: .85; }
.code-card .code {
  font-size: 46px; font-weight: 800; letter-spacing: 10px;
  direction: ltr; margin: 6px 0 4px; font-variant-numeric: tabular-nums;
}
.code-card .note { font-size: 12.5px; opacity: .85; }

/* ---------- الطابور والقوائم ---------- */
.queue-item, .student-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; margin-bottom: 8px; width: 100%; text-align: start; cursor: pointer;
}
.queue-item .grow, .student-row .grow { flex: 1; min-width: 0; }
.queue-item b, .student-row b { display: block; font-size: 15.5px; }
.queue-item.pressed, .student-row.sel { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(0,120,220,.15); }
.student-row.done { background: #f7faf7; border-color: #cfe5cf; }
.student-row.gone { background: #f8f9fa; opacity: .75; }
/* شاشة المعلّم: المستدعى يجب أن يُلتقط بلمحة وسط حصة، لا بقراءة الحالة */
.student-row.calledNow { background: #eaf4fd; border-color: var(--blue); box-shadow: 0 0 0 2px rgba(0,120,220,.12); }

.check {
  width: 26px; height: 26px; flex: none; border-radius: 7px;
  border: 2px solid var(--line); display: grid; place-items: center;
  font-size: 15px; color: #fff; background: #fff;
}
.check.on { background: var(--blue); border-color: var(--blue); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.ok { background: var(--green-bg); color: var(--green); }
.pill.wait { background: #eef2f6; color: var(--muted); }
.pill.called { background: #eaf4fd; color: var(--blue-dark); }
.pill.bad { background: var(--danger-bg); color: var(--danger); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }

.empty { padding: 30px 16px; text-align: center; color: var(--muted); }

/* شريط الإجراءات الثابت أسفل الشاشة */
.actionbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 25;
  display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(7,56,99,.06);
}
.actionbar .btn { flex: 1; }

/* ---------- درج ونافذة ---------- */
.drawer { position: fixed; inset: 0; z-index: 60; background: rgba(7,56,99,.4); display: grid; }
.drawer-card {
  background: #fff; width: min(320px, 86%); height: 100%; padding: 16px;
  box-shadow: var(--shadow); overflow-y: auto;
}
.drawer .who { padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.row-btn {
  display: block; width: 100%; text-align: start; min-height: var(--tap);
  padding: 11px 12px; margin-bottom: 6px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; cursor: pointer; font-size: 15px;
}
.row-btn.danger { color: var(--danger); border-color: #f2c6c1; }

.sheet-back { position: fixed; inset: 0; z-index: 70; background: rgba(7,56,99,.45); display: grid; align-items: end; }
.sheet {
  background: #fff; width: 100%; max-height: 90vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom);
}
.sheet h3 { margin: 0; padding: 16px 18px 12px; font-size: 17px; color: var(--navy); }
.sheet-body { padding: 0 18px 12px; }
.sheet-foot { display: flex; gap: 8px; padding: 12px 18px 18px; }
.sheet-foot .btn { flex: 1; }
@media (min-width: 620px) {
  .sheet-back { align-items: center; justify-items: center; }
  .sheet { width: min(520px, 92%); border-radius: 16px; }
}

/* حقل الرمز — أرقام كبيرة متباعدة */
.code-input {
  width: 100%; text-align: center; font-size: 30px; letter-spacing: 12px;
  direction: ltr; font-weight: 700; padding: 14px; font-variant-numeric: tabular-nums;
}

#toast { position: fixed; inset-inline: 12px; bottom: 78px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
/* التنبيه لا يحجب أزرار الورقة المفتوحة: يُرفع لأعلى الشاشة عند فتحها */
.sheet-back:not([hidden]) ~ #toast { bottom: auto; top: 12px; }
#toast div {
  background: var(--navy); color: #fff; padding: 12px 15px; border-radius: 12px;
  box-shadow: var(--shadow); font-size: 14.5px;
}
#toast div.err { background: var(--danger); }
#toast div.ok { background: var(--green); }

.steps { counter-reset: s; padding: 0; margin: 8px 0; list-style: none; }
.steps li {
  counter-increment: s; position: relative; padding-inline-start: 34px; margin-bottom: 10px; font-size: 14.5px;
}
.steps li::before {
  content: counter(s); position: absolute; inset-inline-start: 0; top: 1px;
  width: 24px; height: 24px; border-radius: 50%; background: var(--blue); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}

/* ---------------- مبدّل اللغة ---------------- */
.lang-row { display: flex; justify-content: center; margin: 10px 0 14px; }
.lang-select {
  appearance: auto; font: inherit; font-size: 13px;
  padding: 7px 10px; border-radius: 9px;
  border: 1px solid var(--line); background: #fff; color: inherit;
  min-height: 38px; cursor: pointer;
}
#drawerLang { margin: 4px 0 10px; }
#drawerLang .lang-select { width: 100%; min-height: var(--tap); }

/* ---------------- دعوة فتح الجلسة ----------------
   المرحلة التي لم تُفتح جلستها هي الحالة الوحيدة في هذه القائمة التي
   تنتظر فعلاً من المستخدم، فتُعطى لون فعل لا لون حالة. مقاسها بمقاس
   اللمس: الصف كله قابل للضغط، لكن الإصبع يذهب إلى ما يبدو زرّاً. */
.cta-open {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 38px; padding: 0 16px; border-radius: 10px;
  background: var(--green); color: #fff;
  font-size: 14px; font-weight: 700; white-space: nowrap;
  box-shadow: 0 1px 2px rgba(46,125,50,.25);
}
.queue-item:active .cta-open { background: #256428; }
.cta-open.off { background: #eef1f4; color: var(--muted); box-shadow: none; }
