/* المهندس — نظام التصميم المشترك
   الخط وهوية الألوان مأخوذان من برنامج "المهندس لإدارة المولدة" للحفاظ على هوية بصرية موحدة بين برامج المهندس.
   برمجة وتطوير المهندس علي أحمد طه */

@font-face {
  font-family: "AlmuhandisAAT";
  src: url("/fonts/almuhandis-v2.woff") format("woff");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #f4efe2; --card: #ffffff; --tx: #1b2a24; --mut: #6b7a73;
  --pri: #0f4a38; --on: #ffffff; --bd: #e3dccb; --in: #f2f0e8;
  --ok: #15803d; --bad: #b91c1c; --warn: #b45309; --acc: #e7b84a;
  --radius-sm: 8px; --radius: 14px; --radius-lg: 20px;
  --shadow: 0 1px 2px rgba(27,42,36,.06), 0 8px 24px rgba(27,42,36,.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --card: #131d31; --tx: #e8eef7; --mut: #93a1b5;
    --pri: #34d399; --on: #06281c; --bd: #24324b; --in: #0e172a;
    --ok: #4ade80; --bad: #fb7185; --warn: #fbbf24; --acc: #e7b84a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --card: #131d31; --tx: #e8eef7; --mut: #93a1b5;
  --pri: #34d399; --on: #06281c; --bd: #24324b; --in: #0e172a;
  --ok: #4ade80; --bad: #fb7185; --warn: #fbbf24; --acc: #e7b84a;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* كل أيقونة SVG بحجم ثابت افتراضياً؛ بدونها تتمدد لملء الحاوية (كانت تظهر ضخمة في قائمة "المزيد") */
svg { width: 20px; height: 20px; flex-shrink: 0; }
.btn svg, .nav-link svg, .sidebar nav a svg { width: 20px; height: 20px; }
html { scroll-padding-top: var(--safe-top); }
body {
  margin: 0; background: var(--bg); color: var(--tx);
  font-family: "AlmuhandisAAT", "Cairo", Tahoma, system-ui, sans-serif;
  direction: rtl; min-height: 100%;
  padding-top: var(--safe-top); padding-bottom: var(--safe-bottom);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 800; line-height: 1.3; }
p { margin: 0 0 .6em; line-height: 1.7; }
a { color: var(--pri); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
::selection { background: var(--acc); color: #1b2a24; }

/* تخطيط */
.container { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.app-shell { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; padding: 20px 16px 96px; }
@media (min-width: 900px) { .app-main { padding: 28px 32px 32px; } }

.topbar {
  position: sticky; top: var(--safe-top); z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--bd); /* بلا ضبابية: ثقيلة على الهواتف */
}
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.topbar .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--acc); }
.spacer { flex: 1; }

/* الشريط الجانبي (حاسوب) والسفلي (موبايل) */
.sidebar {
  display: none; width: 240px; flex-shrink: 0; border-left: 1px solid var(--bd);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
/* الشريط الجانبي للشاشات الكبيرة بالماوس فقط؛ الهواتف واللوحيات باللمس تبقى بالشريط السفلي حتى بوضع "موقع سطح المكتب" */
@media (min-width: 900px) and (pointer: fine) { .sidebar { display: block; } .bottom-nav { display: none !important; } }
.sidebar nav a, .nav-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--tx); font-weight: 600; margin-bottom: 2px;
}
.sidebar nav a.active, .nav-link.active { background: var(--in); color: var(--pri); }
.sidebar nav a:hover { background: var(--in); }

.bottom-nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--bd); padding: 6px 4px calc(6px + var(--safe-bottom));
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--mut);
  flex: 1; padding: 6px 2px; border-radius: var(--radius-sm); font-weight: 700;
}
.bottom-nav a.active { color: var(--pri); }
.bottom-nav svg { width: 22px; height: 22px; }

/* بطاقات ومكونات */
.card {
  background: var(--card); border: 1px solid var(--bd); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }

.stat { padding: 16px; }
.stat .num { font-size: 28px; font-weight: 800; color: var(--pri); }
.stat .lbl { color: var(--mut); font-size: 13px; margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--bd); background: var(--card); color: var(--tx); border-radius: var(--radius-sm);
  padding: 10px 16px; font-weight: 700; font-size: 14.5px; transition: transform .05s ease, opacity .15s ease;
  min-height: 44px;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--pri); border-color: var(--pri); color: var(--on); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; min-width: 40px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 700; font-size: 13.5px; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--mut); margin-top: 4px; }
.field .err { font-size: 12.5px; color: var(--bad); margin-top: 4px; font-weight: 600; }
input[type=text], input[type=search], input[type=password], input[type=email], input[type=tel], input[type=number],
input[type=date], input[type=time], input[type=url], select, textarea {
  width: 100%; background: var(--in); border: 1px solid var(--bd); border-radius: var(--radius-sm);
  padding: 11px 12px; color: var(--tx); min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--pri); outline-offset: 1px;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.checkbox-row input { width: 18px; height: 18px; min-height: auto; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; background: var(--in); color: var(--mut); border: 1px solid var(--bd);
}
.badge-ok { background: color-mix(in srgb, var(--ok) 15%, var(--card)); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, var(--bd)); }
.badge-bad { background: color-mix(in srgb, var(--bad) 15%, var(--card)); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, var(--bd)); }
.badge-warn { background: color-mix(in srgb, var(--warn) 18%, var(--card)); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, var(--bd)); }
.badge-acc { background: color-mix(in srgb, var(--acc) 25%, var(--card)); color: #7a5a0f; border-color: color-mix(in srgb, var(--acc) 40%, var(--bd)); }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--bd); }
th { font-size: 12.5px; color: var(--mut); font-weight: 700; }
.table-wrap { overflow-x: auto; }

.empty { text-align: center; padding: 40px 16px; color: var(--mut); }
.empty .icon { font-size: 36px; margin-bottom: 10px; }
/* هيكل التحميل: نبض شفافية خفيف (رخيص على المعالج) بدل تدرّج متحرك يعيد الرسم باستمرار */
.skeleton { background: var(--in); border-radius: var(--radius-sm); animation: skel 1.4s ease-in-out infinite; }
@keyframes skel { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* نوافذ التأكيد والحوار */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,15,20,.5); display: flex; align-items: flex-end; justify-content: center; z-index: 100; }
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.modal {
  background: var(--card); border-radius: var(--radius-lg) var(--radius-lg) 0 0; width: 100%; max-width: 480px;
  padding: 20px; box-shadow: var(--shadow); max-height: 86vh; overflow-y: auto;
}
@media (min-width: 640px) { .modal { border-radius: var(--radius-lg); } }

/* تنبيهات */
.toast-host { position: fixed; bottom: calc(80px + var(--safe-bottom)); inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; pointer-events: none; }
@media (min-width: 900px) and (pointer: fine) { .toast-host { bottom: 20px; } }
.toast {
  pointer-events: auto; background: var(--tx); color: var(--bg); padding: 12px 18px; border-radius: 999px;
  font-weight: 700; font-size: 13.5px; box-shadow: var(--shadow); max-width: 90vw;
}
.toast-ok { background: var(--ok); color: #fff; }
.toast-bad { background: var(--bad); color: #fff; }

/* نبض الصف */
.pulse-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.pulse-ok { background: var(--ok); } .pulse-warn { background: var(--warn); } .pulse-bad { background: var(--bad); }

.muted { color: var(--mut); }
.center { text-align: center; }
.hidden { display: none !important; }
.mt-0 { margin-top: 0 !important; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chip-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.chip-tab { padding: 8px 16px; border-radius: 999px; background: var(--in); border: 1px solid var(--bd); font-weight: 700; font-size: 13.5px; white-space: nowrap; cursor: pointer; }
.chip-tab.active { background: var(--pri); color: var(--on); border-color: var(--pri); }

.offline-banner {
  background: var(--warn); color: #fff; text-align: center; font-size: 13px; font-weight: 700;
  padding: 8px 16px;
}

.app-footer {
  text-align: center; font-size: 12px; color: var(--mut); padding: 14px 16px;
  padding-bottom: calc(96px + var(--safe-bottom)); border-top: 1px solid var(--bd); margin-top: 8px;
}
.app-footer a { font-weight: 700; }
@media (min-width: 900px) and (pointer: fine) { .app-footer { padding-bottom: 18px; } }

.auth-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
.auth-foot { margin: 16px 0 0; font-size: 12px; line-height: 1.7; }
/* شاشات قصيرة: نضغط المسافات لتبقى الصفحة كلها داخل الشاشة بلا تمرير */
@media (max-height: 760px) {
  .auth-wrap { padding-top: 10px; padding-bottom: 10px; }
  .auth-logo { margin-bottom: 10px; }
  .auth-logo .brand-mark { width: 48px; height: 48px; }
  .auth-logo h1 { font-size: 21px; margin-top: 6px !important; }
  .auth-logo p { margin: 4px 0 0; font-size: 13px; }
  .auth-card .card { padding: 14px; }
  .auth-card .field { margin-bottom: 10px; }
  .auth-foot { margin-top: 10px; }
}
@media (max-height: 600px) { .auth-logo p { display: none; } .auth-logo .brand-mark { width: 40px; height: 40px; } }
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { text-align: center; margin-bottom: 20px; }
.auth-logo .mark { width: 56px; height: 56px; border-radius: 16px; background: var(--pri); color: var(--on); display: inline-flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 800; }
.auth-logo .brand-mark { width: 64px; height: 64px; display: inline-block; }
.sidebar .brand-mark { width: 34px; height: 34px; border-radius: 10px; display: block; }

/* طباعة بطاقات دخول الطلاب: تُطبع النافذة المفتوحة فقط */
@media print {
  body > *:not(.modal-backdrop) { display: none !important; }
  .modal-backdrop { position: static !important; background: none !important; display: block !important; padding: 0 !important; }
  .modal { box-shadow: none !important; max-height: none !important; width: 100% !important; border: 0 !important; }
  .no-print, .toast-host { display: none !important; }
  .table-wrap { max-height: none !important; overflow: visible !important; }
}

/* لا تمرير أفقي للصفحة أبداً؛ المحتوى العريض (جداول) يتمرر داخل حاويته فقط */
html, body { max-width: 100%; overflow-x: clip; }
.row.wrap, .card.row { flex-wrap: wrap; }
/* قوائم طويلة: لا يُرسم إلا ما يظهر على الشاشة (تمرير أسلس) */
#list > .card { content-visibility: auto; contain-intrinsic-size: auto 130px; }

/* اختيار ملف بنص عربي */
.file-pick { position: relative; display: flex; align-items: center; gap: 10px; border: 1px dashed var(--bd); border-radius: var(--radius); padding: 10px 12px; background: var(--in); cursor: pointer; min-height: 48px; }
.file-pick input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 0; }
.file-pick .file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* نماذج طويلة (تسجيل، انضمام ولي أمر): مسافات أصغر على الشاشات المتوسطة كي لا يطول التمرير بلا داعٍ */
@media (max-height: 960px) {
  .auth-wrap.dense { align-items: flex-start; padding-top: 12px; padding-bottom: 12px; }
  .auth-wrap.dense .auth-logo { margin-bottom: 8px; }
  .auth-wrap.dense .auth-logo .brand-mark { width: 44px; height: 44px; }
  .auth-wrap.dense .auth-logo h1 { font-size: 20px; margin-top: 4px !important; }
  .auth-wrap.dense .auth-card .card { padding: 14px; }
  .auth-wrap.dense .field { margin-bottom: 9px; }
}


/* ============================================================================
   التصميم v3: هوية المهندس (الأخضر الداكن والذهبي) بإحساس واجهات الهواتف الحديثة
   ============================================================================ */
:root { --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --tap: 44px; --glass: color-mix(in srgb, var(--bg) 78%, transparent); }
body { font-family: system-ui, -apple-system, "Segoe UI", Tahoma, "AlmuhandisAAT", sans-serif; font-size: 16px; }
h1, h2, h3, .brand, .bar-title { font-family: "AlmuhandisAAT", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif; }

/* عنوان كبير يصغر عند التمرير إلى الشريط العلوي */
.app-main > h2:first-child, .page-head h2 { font-size: 27px; letter-spacing: -.2px; margin-bottom: var(--s3); }
.bar-title { font-weight: 800; font-size: 16px; opacity: 0; transform: translateY(4px); transition: opacity .15s, transform .15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 50vw; }
body.scrolled .bar-title { opacity: 1; transform: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s3); }
.page-head h2 { margin: 0; }

/* الشريطان: زجاجي شبه شفاف حيث يدعمه الجهاز، ومصمت حيث لا يدعمه أو طُلب تقليل الشفافية */
.topbar, .bottom-nav { background: var(--card); }
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  @media (prefers-reduced-transparency: no-preference) {
    .topbar, .bottom-nav { background: var(--glass); -webkit-backdrop-filter: saturate(170%) blur(14px); backdrop-filter: saturate(170%) blur(14px); }
  }
}
.bottom-nav { border-top: 1px solid color-mix(in srgb, var(--bd) 70%, transparent); }
.bottom-nav a { position: relative; min-height: 52px; gap: 2px; font-size: 11px; }
.bottom-nav a.active { color: var(--pri); font-weight: 700; }
.bottom-nav a.active svg { stroke-width: 2.4; }

/* شارة غير المقروء */
.nav-count { position: absolute; top: 2px; inset-inline-start: calc(50% + 4px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--bad); color: #fff; font-size: 11px; font-weight: 800; line-height: 18px; text-align: center; box-shadow: 0 0 0 2px var(--card); }
#notifBtn, .sidebar nav a, .nav-link { position: relative; }
#notifBtn .nav-count { top: 0; inset-inline-start: auto; inset-inline-end: 0; }
.sidebar nav a .nav-count, .nav-link .nav-count { position: static; margin-inline-start: auto; box-shadow: none; }

/* قوائم مجمّعة مستديرة بفواصل رفيعة */
.list-group { background: var(--card); border: 1px solid var(--bd); border-radius: var(--radius); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: var(--s3); padding: 10px 14px; min-height: 60px; color: inherit; border-top: 1px solid var(--bd); }
.list-row:first-child { border-top: 0; }
.list-row:active { background: var(--in); }
.list-row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-top, .row-sub { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chev { color: var(--mut); font-size: 22px; line-height: 1; }
.avatar { width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--pri) 14%, var(--card)); color: var(--pri); font-weight: 800; font-size: 17px; }
.count { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--pri); color: var(--on); font-size: 12px; font-weight: 800; line-height: 22px; text-align: center; flex-shrink: 0; }
.role-tag { color: var(--mut); font-size: 11.5px; }
.tick { color: var(--mut); font-size: 11px; }
.tick.read { color: var(--acc); }

/* المحادثة */
.thread-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s3); }
.thread-head .grow { display: flex; flex-direction: column; min-width: 0; }
.thread { display: flex; flex-direction: column; gap: 6px; padding-bottom: var(--s3); }
.day-sep { align-self: center; font-size: 11.5px; color: var(--mut); background: var(--in); border-radius: 999px; padding: 3px 10px; margin: 8px 0; }
.bubble-row { display: flex; justify-content: flex-start; }
.bubble-row.mine { justify-content: flex-end; }
.bubble { max-width: 82%; background: var(--card); border: 1px solid var(--bd); border-radius: 18px; border-start-start-radius: 6px; padding: 8px 12px; box-shadow: var(--shadow); }
.bubble-row.mine .bubble { background: var(--pri); color: var(--on); border-color: var(--pri); border-start-start-radius: 18px; border-start-end-radius: 6px; }
.bubble-row.mine .bubble .tick, .bubble-row.mine .bubble-meta { color: color-mix(in srgb, var(--on) 75%, transparent); }
.bubble-row.mine .tick.read { color: var(--acc); }
.bubble-text { white-space: pre-wrap; word-break: break-word; line-height: 1.6; }
.bubble-meta { font-size: 11px; color: var(--mut); margin-top: 2px; text-align: end; }
.msg-img { display: block; max-width: 220px; max-height: 260px; border-radius: 12px; margin-bottom: 4px; }
.msg-file { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, currentColor 10%, transparent); color: inherit; margin-bottom: 4px; max-width: 240px; }
.composer { position: sticky; bottom: calc(64px + var(--safe-bottom)); display: flex; align-items: center; gap: var(--s2); background: var(--glass); padding: 8px 0; }
.composer input { flex: 1; border-radius: 999px; }
.composer .attach { font-size: 18px; cursor: pointer; }
@media (min-width: 900px) and (pointer: fine) { .composer { bottom: 0; } }

/* زر الإنشاء السريع */
.fab { position: fixed; left: 16px; bottom: calc(76px + var(--safe-bottom)); width: 56px; height: 56px; border-radius: 50%; border: 0; z-index: 30;
  background: var(--pri); color: var(--on); font-size: 30px; line-height: 1; box-shadow: 0 6px 20px rgba(15,74,56,.35); cursor: pointer; }
.fab:active { transform: scale(.94); }
@media (min-width: 900px) and (pointer: fine) { .fab { bottom: 24px; } }

/* شريط "يتوفر تحديث" وأخطاء غير متوقعة */
.update-bar { position: fixed; inset-inline: 12px; bottom: calc(76px + var(--safe-bottom)); z-index: 60; display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  background: var(--tx); color: var(--bg); padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow); }
@media (min-width: 900px) and (pointer: fine) { .update-bar { bottom: 20px; max-width: 520px; margin-inline: auto; } }

/* النوافذ تنزلق من الأسفل على الهاتف (Sheets) */
@media (max-width: 640px), (pointer: coarse) {
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { width: 100%; max-width: 100%; border-radius: 22px 22px 0 0; padding-bottom: calc(18px + var(--safe-bottom)); max-height: 88vh; overflow-y: auto; animation: sheet-up .22s cubic-bezier(.2,.8,.2,1); }
  .modal::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--bd); margin: -6px auto 12px; }
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }

/* انتقال ناعم بين الشاشات */
#appMain.enter > * { animation: screen-in .18s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #appMain.enter > *, .modal, .bar-title { animation: none !important; transition: none !important; } }

/* أحجام لمس مريحة على أجهزة اللمس */
@media (pointer: coarse) {
  .btn, .btn-sm { min-height: var(--tap); }
  .btn-icon { min-width: var(--tap); min-height: var(--tap); }
  .nav-link { min-height: 48px; }
}

.section-title { font-size: 13px; font-weight: 700; color: var(--mut); margin: 6px 4px 8px; }
.list-row .unread { font-weight: 800; }
.list-row .grow small { display: block; }


/* ===== الإرشاد: بطاقة الترحيب والتلميحات والجولة ===== */
.tip { display: flex; align-items: center; gap: var(--s3); background: color-mix(in srgb, var(--acc) 16%, var(--card)); border: 1px solid color-mix(in srgb, var(--acc) 45%, var(--bd));
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: var(--s3); font-size: 14px; line-height: 1.6; }
.tip .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tip small { color: var(--mut); }
.tip-ic { font-size: 20px; }
.tip-x { border: 0; background: transparent; color: var(--mut); font-size: 22px; line-height: 1; min-width: 36px; min-height: 36px; cursor: pointer; border-radius: 50%; }
.tip.welcome { background: color-mix(in srgb, var(--pri) 10%, var(--card)); border-color: color-mix(in srgb, var(--pri) 35%, var(--bd)); }
.tour { text-align: center; padding: 6px 4px 2px; }
.tour-ic { font-size: 54px; margin: 6px 0 10px; }
.tour h3 { font-size: 21px; }
.tour p { min-height: 4.8em; }
.tour-dots { display: flex; justify-content: center; gap: 6px; margin: 6px 0 16px; }
.tour-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--bd); transition: width .2s; }
.tour-dots span.on { width: 20px; border-radius: 4px; background: var(--pri); }
.faq details { border-top: 1px solid var(--bd); padding: 12px 14px; }
.faq details:first-child { border-top: 0; }
.faq summary { cursor: pointer; font-weight: 700; list-style-position: inside; }
.faq details p { margin: 8px 0 0; }

/* ===== السحب الجانبي ===== */
.swipe-wrap { position: relative; overflow: hidden; border-top: 1px solid var(--bd); }
.swipe-wrap:first-child { border-top: 0; }
.swipe-wrap > .list-row { position: relative; z-index: 1; background: var(--card); border-top: 0; }
.swipe-actions { position: absolute; inset-block: 0; left: 0; display: flex; z-index: 0; }
.swipe-btn { border: 0; color: #fff; font-weight: 700; min-width: 84px; font-size: 14px; background: var(--mut); cursor: pointer; }
.swipe-btn.ok { background: var(--pri); color: var(--on); }
.swipe-btn.bad { background: var(--bad); }

/* ===== مجموعات الصف والمفاتيح ===== */
.avatar.group { background: color-mix(in srgb, var(--acc) 22%, var(--card)); color: var(--tx); font-size: 19px; }
.bubble .sender { font-size: 12px; font-weight: 800; color: var(--pri); margin-bottom: 2px; }
.bubble .sender.is-teacher { color: color-mix(in srgb, var(--acc) 70%, var(--tx)); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); cursor: pointer; }
input[type="checkbox"][role="switch"] { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--bd); position: relative; cursor: pointer; flex-shrink: 0; transition: background .2s; margin: 0; }
input[type="checkbox"][role="switch"]::after { content: ""; position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
input[type="checkbox"][role="switch"]:checked { background: var(--pri); }
input[type="checkbox"][role="switch"]:checked::after { transform: translateX(-20px); }
button.list-row { width: 100%; background: transparent; border: 0; border-top: 1px solid var(--bd); text-align: start; font: inherit; color: inherit; cursor: pointer; }
.list-group > button.list-row:first-child { border-top: 0; }
.list-row.danger strong { color: var(--bad); }
body:has(.fab) .app-footer { padding-left: 84px; }

/* ===== تحسين عام للشاشات الداخلية ===== */
.card { border-radius: 16px; border-color: color-mix(in srgb, var(--bd) 80%, transparent); box-shadow: 0 1px 2px rgba(27,42,36,.04); }
.field label { font-size: 13px; font-weight: 700; color: var(--mut); margin-bottom: 6px; display: block; }
.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .field select, .field textarea,
input[type="search"], input[type="text"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
  background: var(--in); border: 1px solid color-mix(in srgb, var(--bd) 70%, transparent); border-radius: 12px; padding: 11px 13px; min-height: 46px; width: 100%; transition: border-color .15s, box-shadow .15s, background .15s; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--pri); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pri) 20%, transparent); background: var(--card); }
.btn { border-radius: 12px; font-weight: 700; }
.btn-sm { border-radius: 10px; }
.badge { border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; }
.badge-ok { background: color-mix(in srgb, var(--ok) 12%, var(--card)); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.badge-warn { background: color-mix(in srgb, var(--warn) 12%, var(--card)); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.badge-acc { background: color-mix(in srgb, var(--acc) 18%, var(--card)); border-color: color-mix(in srgb, var(--acc) 50%, transparent); }
/* تبويبات مقسّمة على طريقة الهواتف الحديثة */
.chip-tabs { display: flex; gap: 2px; background: var(--in); border-radius: 12px; padding: 3px; overflow-x: auto; scrollbar-width: none; margin-bottom: var(--s3); }
.chip-tabs::-webkit-scrollbar { display: none; }
.chip-tabs > * { flex: 1 0 auto; text-align: center; border: 0 !important; border-radius: 10px !important; background: transparent !important; color: var(--mut) !important; font-weight: 700; min-height: 36px; padding: 6px 12px; white-space: nowrap; }
.chip-tabs > .active, .chip-tabs > [aria-selected="true"], .chip-tabs > .btn-primary { background: var(--card) !important; color: var(--tx) !important; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.stat { text-align: start; }
.stat .num { font-size: 28px; font-weight: 800; color: var(--pri); }
.stat .lbl { font-size: 13px; color: var(--mut); }
.table-wrap { border-radius: 14px; border: 1px solid var(--bd); background: var(--card); }
.table-wrap th { font-size: 12px; color: var(--mut); font-weight: 700; }
.empty .icon { font-size: 44px; }
/* النماذج الطويلة (تسجيل، انضمام ولي أمر): حقول أقصر قليلاً كي لا يطول التمرير */
.auth-wrap.dense .field input:not([type="checkbox"]), .auth-wrap.dense .field select { min-height: 42px; padding-block: 8px; }

/* ===== مزايا المراسلة الاحترافية ===== */
.bubble { cursor: pointer; }
.bubble.deleted { background: transparent !important; border-style: dashed !important; color: var(--mut) !important; box-shadow: none; cursor: default; }
.bubble.deleted .bubble-text { font-style: italic; }
.quote { display: block; width: 100%; text-align: start; border: 0; border-inline-start: 3px solid var(--acc); background: color-mix(in srgb, currentColor 8%, transparent);
  color: inherit; opacity: .9; border-radius: 8px; padding: 5px 8px; margin-bottom: 5px; font: inherit; font-size: 13px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-audio { display: block; width: 230px; max-width: 100%; height: 40px; margin-bottom: 2px; }
.voice-len { font-size: 12px; opacity: .8; }
.reply-bar, .rec-bar, .pin-bar { display: flex; align-items: center; gap: var(--s2); background: var(--card); border: 1px solid var(--bd); border-radius: 12px; padding: 6px 10px; margin-bottom: 6px; }
.reply-bar { border-inline-start: 3px solid var(--acc); font-size: 13px; }
.pin-bar { width: 100%; font: inherit; color: inherit; text-align: start; cursor: pointer; border-inline-start: 3px solid var(--pri); font-size: 13.5px; position: sticky; top: calc(56px + var(--safe-top)); z-index: 2; }
.rec-bar { position: sticky; bottom: calc(64px + var(--safe-bottom)); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); animation: rec-blink 1s infinite; }
@keyframes rec-blink { 50% { opacity: .25; } }
.bubble-row.flash .bubble { outline: 3px solid var(--acc); outline-offset: 2px; transition: outline-color .3s; }
.announce { display: flex; align-items: center; gap: var(--s2); margin: 10px 16px 0; padding: 10px 12px; border-radius: var(--radius); font-size: 14px;
  background: color-mix(in srgb, var(--pri) 10%, var(--card)); border: 1px solid color-mix(in srgb, var(--pri) 35%, var(--bd)); }
.announce.warn { background: color-mix(in srgb, var(--warn) 14%, var(--card)); border-color: color-mix(in srgb, var(--warn) 45%, var(--bd)); }
.announce .grow { flex: 1; }
@media (min-width: 900px) { .announce { margin: 14px 32px 0; } }
@media (prefers-reduced-motion: reduce) { .rec-dot { animation: none; } }

/* ===== الإرسال الفوري: فقاعات قيد الإرسال، التقدّم، الفشل ===== */
#pendingBox { padding-bottom: 0; }
.bubble-row.pending .bubble { opacity: .92; }
.bubble-row.failed .bubble { outline: 2px solid var(--bad); outline-offset: 1px; }
.up-progress { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.up-progress progress { flex: 1; height: 6px; accent-color: var(--acc); }
.linkish { border: 0; background: transparent; color: inherit; text-decoration: underline; font: inherit; font-size: 12px; cursor: pointer; padding: 0 2px; min-height: 0; }
.pstate { font-size: 11.5px; }

/* ============================================================================
   iOS: قياسات وألوان واجهة الآيفون (نقطة iOS = بكسل CSS)
   شريط التنقل 44 · شريط التبويبات 49 (أيقونة 25، نص 10) · نص 17 · عنوان كبير 34 · صفوف 44 · زوايا 10 · فقاعات 18
   ============================================================================ */
:root {
  --ios-bg: #F2F2F7; --ios-card: #FFFFFF; --ios-sep: rgba(60,60,67,.29); --ios-label2: #6C6C70; --ios-fill: rgba(118,118,128,.12);
  --ios-incoming: #E9E9EB; --ios-tab-inactive: #8E8E93;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --ios-bg: #000000; --ios-card: #1C1C1E; --ios-sep: rgba(84,84,88,.65); --ios-label2: #98989F; --ios-fill: rgba(118,118,128,.24); --ios-incoming: #26252A; --ios-tab-inactive: #8E8E93; } }
:root[data-theme="dark"] { --ios-bg: #000000; --ios-card: #1C1C1E; --ios-sep: rgba(84,84,88,.65); --ios-label2: #98989F; --ios-fill: rgba(118,118,128,.24); --ios-incoming: #26252A; }
.app-shell { --bg: var(--ios-bg); --card: var(--ios-card); --bd: var(--ios-sep); --mut: var(--ios-label2); --in: var(--ios-fill); background: var(--ios-bg); font-size: 17px; line-height: 1.35; }
body:has(.app-shell) { background: var(--ios-bg); }

/* شريط التنقل العلوي: 44 */
.app-shell .topbar { min-height: 44px; height: calc(44px + var(--safe-top)); padding-top: var(--safe-top); padding-inline: 16px; border-bottom: .5px solid var(--ios-sep); }
.app-shell .topbar .brand { font-size: 17px; font-weight: 700; }
.app-shell .topbar .btn-icon { min-width: 44px; min-height: 44px; padding: 0; color: var(--pri); }
.app-shell .topbar .btn-icon svg { width: 24px; height: 24px; }
.app-shell .topbar > .muted { font-size: 15px; color: var(--ios-label2); }

/* العنوان الكبير: 34 عريض (بلا تباعد أحرف حتى لا يتقطع الخط العربي) */
.app-main > h2:first-child, .page-head h2 { font-size: 34px; line-height: 41px; font-weight: 800; letter-spacing: 0; margin-bottom: 8px; }
.section-title { font-size: 13px; font-weight: 400; color: var(--ios-label2); margin: 22px 16px 7px; }
.app-main h3 { font-size: 20px; }

/* شريط التبويبات: 49 + منطقة الأمان، أيقونة 25، نص 10 */
.app-shell .bottom-nav { height: calc(49px + var(--safe-bottom)); padding-bottom: var(--safe-bottom); border-top: .5px solid var(--ios-sep); }
.app-shell .bottom-nav a, .app-shell .bottom-nav button { min-height: 49px; height: 49px; padding: 4px 0 0; gap: 2px; font-size: 10px; font-weight: 500; color: var(--ios-tab-inactive); justify-content: flex-start; }
.app-shell .bottom-nav svg { width: 25px; height: 25px; }
.app-shell .bottom-nav a.active, .app-shell .bottom-nav button.active { color: var(--pri); font-weight: 600; }
.app-shell .bottom-nav .nav-count { top: 1px; }

/* القوائم المجمّعة: زوايا 10، صفوف 44، فواصل رفيعة تبدأ من بعد الأيقونة */
.list-group { border-radius: 10px; border: 0; background: var(--ios-card); }
.list-row { min-height: 44px; padding: 8px 16px; border-top: 0; position: relative; }
.list-row + .list-row::before, .swipe-wrap + .swipe-wrap > .list-row::before, button.list-row + button.list-row::before, a.list-row + button.list-row::before, button.list-row + a.list-row::before {
  content: ""; position: absolute; top: 0; inset-inline-start: 62px; inset-inline-end: 0; border-top: .5px solid var(--ios-sep); }
.list-row:not(:has(.avatar)) + .list-row:not(:has(.avatar))::before { inset-inline-start: 16px; }
.swipe-wrap { border-top: 0; }
.list-row strong { font-size: 17px; font-weight: 400; }
.list-row small { font-size: 15px; }
.list-row .row-top strong { font-weight: 600; }
.chev { color: #C4C4C7; font-size: 20px; }
.avatar { width: 40px; height: 40px; font-size: 17px; }
.card { border-radius: 10px; border: 0; box-shadow: none; background: var(--ios-card); }
.btn { border-radius: 10px; min-height: 44px; font-size: 17px; font-weight: 600; }
.btn-sm { min-height: 34px; font-size: 15px; border-radius: 8px; padding: 6px 14px; }
.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .field select, .field textarea,
.app-shell input[type="search"], .app-shell input[type="text"], .app-shell select, .app-shell textarea { border-radius: 10px; border: 0; background: var(--ios-fill); min-height: 44px; font-size: 17px; }
.chip-tabs { border-radius: 9px; padding: 2px; background: var(--ios-fill); }
.chip-tabs > * { min-height: 28px; border-radius: 7px !important; font-size: 13px; font-weight: 600; padding: 4px 10px; }
.badge { font-size: 12px; }
input[type="checkbox"][role="switch"] { width: 51px; height: 31px; }
input[type="checkbox"][role="switch"]::after { width: 27px; height: 27px; top: 2px; right: 2px; }
input[type="checkbox"][role="switch"]:checked { background: #34C759; }
input[type="checkbox"][role="switch"]:checked::after { transform: translateX(-20px); }

/* النوافذ المنزلقة: زوايا 10 كبطاقات iOS، والمقبض 36×5 */
@media (max-width: 640px), (pointer: coarse) {
  .modal { border-radius: 10px 10px 0 0; background: var(--ios-bg); }
  .modal::before { width: 36px; height: 5px; border-radius: 2.5px; background: rgba(127,127,127,.4); }
}

/* ===== المحادثة على طريقة iMessage ===== */
body[data-screen="chat"] .app-shell .topbar, body[data-screen="chat"] .bottom-nav, body[data-screen="chat"] .fab,
body[data-screen="chat"] .app-footer, body[data-screen="chat"] .announce, body[data-screen="chat"] #offlineBanner:not(.hidden) ~ x { display: none !important; }
body[data-screen="chat"] .app-shell { background: var(--ios-card); }
body[data-screen="chat"] .app-main { padding: 0 0 calc(64px + var(--safe-bottom)); }
.ios-nav { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 88px 1fr 88px; align-items: center; min-height: 44px;
  padding: calc(4px + var(--safe-top)) 8px 6px; margin: 0; border-bottom: .5px solid var(--ios-sep); background: var(--ios-card); }
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { @media (prefers-reduced-transparency: no-preference) {
  .ios-nav, .composer-dock { background: color-mix(in srgb, var(--ios-card) 82%, transparent); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); } } }
.nav-back { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; color: var(--pri); }
.nav-back svg { width: 26px; height: 26px; stroke-width: 2.4; }
.nav-center { display: flex; flex-direction: column; align-items: center; min-width: 0; line-height: 1.2; }
.nav-center .avatar.sm { width: 36px; height: 36px; font-size: 15px; margin-bottom: 2px; }
.nav-center strong { font-size: 13px; font-weight: 600; max-width: 100%; }
.nav-center small { font-size: 11px; max-width: 100%; }
.nav-actions { display: flex; justify-content: flex-end; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; background: transparent; color: var(--pri); cursor: pointer; padding: 0; border-radius: 50%; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.sm { width: 32px; height: 32px; color: var(--ios-label2); }
.search-field { display: flex; align-items: center; gap: 6px; margin: 8px 16px; padding: 0 8px; height: 36px; border-radius: 10px; background: var(--ios-fill); color: var(--ios-label2); }
.search-field svg { width: 17px; height: 17px; }
.search-field input { border: 0 !important; background: transparent !important; min-height: 34px !important; padding: 0 !important; font-size: 17px; }
.search-field.hidden { display: none; }
body[data-screen="chat"] .switch-row.card, body[data-screen="chat"] #pinBar:not(:empty) { margin: 8px 16px 0; }
.pin-bar { border-radius: 10px; border: 0; background: var(--ios-fill); top: calc(56px + var(--safe-top)); }

.thread { gap: 0; padding: 8px 12px 6px; }
.day-sep { background: transparent; font-size: 11px; font-weight: 600; color: var(--ios-label2); margin: 14px 0 6px; padding: 0; }
.bubble-row { flex-direction: column; align-items: flex-start; margin-top: 8px; }
.bubble-row.mine { align-items: flex-end; }
.bubble-row.mine + .bubble-row.mine, .bubble-row:not(.mine) + .bubble-row:not(.mine) { margin-top: 2px; }
.bubble { position: relative; max-width: 75%; border: 0; box-shadow: none; border-radius: 18px; padding: 7px 12px; font-size: 17px; line-height: 22px;
  background: var(--ios-incoming); color: var(--tx); }
.bubble-row.mine .bubble { background: var(--pri); color: var(--on); border-radius: 18px; }
.bubble-text { line-height: 22px; }
/* الذيل: آخر فقاعة في كل مجموعة متتالية */
.bubble-row .bubble::before, .bubble-row .bubble::after { content: ""; position: absolute; bottom: 0; height: 20px; }
.bubble-row:not(.mine) .bubble::before { inset-inline-start: -7px; width: 20px; background: var(--ios-incoming); border-end-end-radius: 16px 14px; }
.bubble-row:not(.mine) .bubble::after { inset-inline-start: -26px; width: 26px; background: var(--ios-card); border-end-end-radius: 10px; }
.bubble-row.mine .bubble::before { inset-inline-end: -7px; width: 20px; background: var(--pri); border-end-start-radius: 16px 14px; }
.bubble-row.mine .bubble::after { inset-inline-end: -26px; width: 26px; background: var(--ios-card); border-end-start-radius: 10px; }
.bubble-row.mine:has(+ .bubble-row.mine) .bubble::before, .bubble-row.mine:has(+ .bubble-row.mine) .bubble::after,
.bubble-row:not(.mine):has(+ .bubble-row:not(.mine)) .bubble::before, .bubble-row:not(.mine):has(+ .bubble-row:not(.mine)) .bubble::after,
.bubble.deleted::before, .bubble.deleted::after { display: none; }
/* الوقت والحالة تحت آخر رسالة في المجموعة فقط */
.bubble-meta { font-size: 11px; color: var(--ios-label2); margin: 3px 6px 0; text-align: inherit; }
.bubble-row.mine:has(+ .bubble-row.mine) > .bubble-meta, .bubble-row:not(.mine):has(+ .bubble-row:not(.mine)) > .bubble-meta { display: none; }
.bubble-row.mine .bubble-meta, .bubble-row.mine .bubble .tick { color: var(--ios-label2); }
.bubble-row.mine .tick.read { color: var(--pri); font-weight: 600; }
.bubble .sender { font-size: 12px; margin-bottom: 1px; }
.bubble-row:not(.mine) .bubble .sender { color: var(--ios-label2); }
.quote { border-radius: 12px; border-inline-start-width: 3px; font-size: 15px; margin: 1px -4px 5px; }
.bubble.deleted { border: 1px solid var(--ios-sep) !important; }
.msg-img { border-radius: 12px; max-width: 240px; margin: -2px -6px 2px; }

/* شريط الكتابة: (+) دائري 30 · حقل مستدير 36 بحدّ رفيع · ميكروفون داخله · سهم إرسال دائري 30 يظهر عند الكتابة */
.composer-dock { position: fixed; inset-inline: 0; bottom: 0; z-index: 30; padding: 6px 8px calc(6px + var(--safe-bottom)); border-top: .5px solid var(--ios-sep); background: var(--ios-card); }
@media (min-width: 900px) and (pointer: fine) { .composer-dock { position: sticky; } }
.composer { position: static; display: flex; align-items: flex-end; gap: 8px; padding: 0; background: transparent; }
.plus-btn { flex: 0 0 32px; width: 32px; height: 32px; margin-bottom: 2px; border-radius: 50%; background: var(--ios-fill); color: var(--ios-label2); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.plus-btn svg { width: 18px; height: 18px; }
.field-pill { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 2px; min-height: 36px; border: 1px solid var(--ios-sep); border-radius: 18px; padding-inline: 12px 3px; background: var(--ios-card); }
.field-pill input { flex: 1 1 auto; min-width: 0 !important; width: auto !important; border: 0 !important; background: transparent !important; min-height: 34px !important; padding: 0 !important; font-size: 17px; box-shadow: none !important; }
.field-pill .mic { width: 30px; height: 30px; color: var(--ios-label2); }
.field-pill .mic svg { width: 21px; height: 21px; }
.send-btn { flex: 0 0 30px; width: 30px; height: 30px; padding: 0; border: 0; background: transparent; color: var(--pri); cursor: pointer; display: inline-flex; min-height: 0; }
.send-btn svg { width: 30px; height: 30px; }
.field-pill:not(.has-text) .send-btn { display: none; }
.field-pill.has-text .mic { display: none; }
.reply-bar { border-radius: 10px; border: 0; background: var(--ios-fill); margin-bottom: 6px; color: var(--ios-label2); }
.reply-bar svg { width: 18px; height: 18px; flex-shrink: 0; }
.rec-bar { position: static; border: 0; background: transparent; margin: 0; padding: 4px 4px; }

/* قائمة السياق (الضغط على رسالة): بطاقة iOS، النص في البداية والأيقونة في الطرف */
.ctx-menu { border-radius: 13px; overflow: hidden; background: var(--ios-card); }
.ctx-item { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 44px; padding: 0 16px; border: 0; background: transparent; font: inherit; font-size: 17px; color: var(--tx); cursor: pointer; }
.ctx-item + .ctx-item { border-top: .5px solid var(--ios-sep); }
.ctx-item svg { width: 22px; height: 22px; }
.ctx-item.danger { color: #FF3B30; }
/* الصور والصوت بلا خلفية فقاعة (كما في iMessage) */
.bubble:has(> a > .msg-img):not(:has(.bubble-text)), .bubble:has(> .msg-img):not(:has(.bubble-text)) { background: transparent !important; padding: 0; }
.bubble:has(> a > .msg-img):not(:has(.bubble-text))::before, .bubble:has(> a > .msg-img):not(:has(.bubble-text))::after,
.bubble:has(> .msg-img):not(:has(.bubble-text))::before, .bubble:has(> .msg-img):not(:has(.bubble-text))::after { display: none; }
.bubble:has(> a > .msg-img):not(:has(.bubble-text)) .msg-img, .bubble:has(> .msg-img):not(:has(.bubble-text)) .msg-img { margin: 0; border-radius: 18px; max-width: min(240px, 70vw); }

.chat-credit { text-align: center; font-size: 11px; color: var(--ios-label2); margin: 10px 16px 0; }

/* ============================================================================
   التصميم الزجاجي: بطاقات شفافة فوق خلفية متدرجة ناعمة، وضبابية قوية على الأشرطة والنوافذ وشريط الكتابة.
   يعود تلقائياً للأسطح المصمتة عند "تقليل الشفافية" أو على الأجهزة التي لا تدعم الضبابية.
   ============================================================================ */
:root { --glass-card: rgba(255,255,255,.66); --glass-line: rgba(255,255,255,.72); --glass-bar: rgba(250,250,252,.62); --glass-sheet: rgba(244,244,248,.78);
  --glass-shadow: 0 10px 30px rgba(16,46,36,.08), 0 1px 0 rgba(255,255,255,.65) inset; --ios-card-solid: #FFFFFF;
  --glass-bg: radial-gradient(900px 520px at 110% -8%, rgba(15,74,56,.20), transparent 62%), radial-gradient(760px 520px at -12% 28%, rgba(231,184,74,.24), transparent 62%),
    radial-gradient(820px 620px at 55% 115%, rgba(52,199,89,.16), transparent 64%), linear-gradient(180deg, #F3F5F4 0%, #ECEFF1 100%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --glass-card: rgba(30,30,34,.55); --glass-line: rgba(255,255,255,.08); --glass-bar: rgba(18,18,20,.62); --glass-sheet: rgba(28,28,30,.80);
  --glass-shadow: 0 10px 30px rgba(0,0,0,.35), 0 1px 0 rgba(255,255,255,.05) inset; --ios-card-solid: #1C1C1E;
  --glass-bg: radial-gradient(900px 520px at 110% -8%, rgba(52,211,153,.18), transparent 62%), radial-gradient(760px 520px at -12% 28%, rgba(231,184,74,.12), transparent 62%),
    radial-gradient(820px 620px at 55% 115%, rgba(40,90,160,.18), transparent 64%), linear-gradient(180deg, #050607 0%, #0B0D10 100%); } }
:root[data-theme="dark"] { --glass-card: rgba(30,30,34,.55); --glass-line: rgba(255,255,255,.08); --glass-bar: rgba(18,18,20,.62); --glass-sheet: rgba(28,28,30,.80);
  --glass-shadow: 0 10px 30px rgba(0,0,0,.35), 0 1px 0 rgba(255,255,255,.05) inset; --ios-card-solid: #1C1C1E;
  --glass-bg: radial-gradient(900px 520px at 110% -8%, rgba(52,211,153,.18), transparent 62%), radial-gradient(760px 520px at -12% 28%, rgba(231,184,74,.12), transparent 62%),
    radial-gradient(820px 620px at 55% 115%, rgba(40,90,160,.18), transparent 64%), linear-gradient(180deg, #050607 0%, #0B0D10 100%); }
/* الخلفية ثابتة في طبقة مستقلة (لا تعيد الرسم أثناء التمرير، فلا ثقل على الهواتف) */
body:has(.app-shell)::before { content: ""; position: fixed; inset: 0; z-index: -1; background: var(--glass-bg); pointer-events: none; }
body:has(.app-shell), .app-shell, body[data-screen="chat"] .app-shell { background: transparent; }
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { @media (prefers-reduced-transparency: no-preference) {
  .app-shell .card, .app-shell .list-group, .app-shell .stat, .tip, .announce, .ctx-menu, .tapback {
    background: var(--glass-card); border: 1px solid var(--glass-line); box-shadow: var(--glass-shadow);
    -webkit-backdrop-filter: blur(16px) saturate(170%); backdrop-filter: blur(16px) saturate(170%); }
  .app-shell .topbar, .app-shell .bottom-nav, .ios-nav, .composer-dock { background: var(--glass-bar); -webkit-backdrop-filter: blur(26px) saturate(190%); backdrop-filter: blur(26px) saturate(190%); }
  .modal { background: var(--glass-sheet) !important; -webkit-backdrop-filter: blur(34px) saturate(190%); backdrop-filter: blur(34px) saturate(190%); border: 1px solid var(--glass-line); }
  .modal-backdrop { background: rgba(0,0,0,.28); }
  .bubble-row:not(.mine) .bubble { background: rgba(255,255,255,.80); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
  :root[data-theme="dark"] .bubble-row:not(.mine) .bubble { background: rgba(58,58,62,.72); }
  .field-pill { background: rgba(255,255,255,.55); border-color: var(--glass-line); }
  .btn-primary { background: linear-gradient(180deg, color-mix(in srgb, var(--pri) 88%, #fff) 0%, var(--pri) 100%); box-shadow: 0 6px 16px color-mix(in srgb, var(--pri) 30%, transparent); }
  .fab { box-shadow: 0 10px 28px color-mix(in srgb, var(--pri) 45%, transparent), 0 1px 0 rgba(255,255,255,.35) inset; }
} }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bubble-row:not(.mine) .bubble { background: rgba(58,58,62,.72); } }
.swipe-wrap > .list-row { background: var(--ios-card-solid); }

/* ذيل الفقاعة بشكل مقصوص (يعمل فوق أي خلفية شفافة، بلا قناع بلون الخلفية) */
.bubble-row .bubble::after { display: none !important; }
.bubble-row .bubble::before { content: ""; position: absolute; bottom: 0; width: 16px; height: 18px; background: inherit; border-radius: 0 !important;
  clip-path: path('M0 0 L0 18 L16 18 C9.5 17.2 3.6 12.5 3 0 Z'); }
.bubble-row:not(.mine) .bubble::before { inset-inline-start: -10px; transform: none; }
.bubble-row.mine .bubble::before { inset-inline-end: -10px; transform: scaleX(-1); }

/* التفاعلات (Tapback) */
.tapback { display: flex; justify-content: space-between; gap: 2px; padding: 6px 8px; border-radius: 26px; margin-bottom: 10px; }
.tapback .tb { border: 0; background: transparent; font-size: 26px; line-height: 1; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; transition: transform .12s; }
.tapback .tb:active { transform: scale(1.25); }
.tapback .tb.on { background: color-mix(in srgb, var(--pri) 18%, transparent); }
.reacts { display: flex; gap: 4px; margin-top: -6px; z-index: 1; position: relative; }
.react { font-size: 13px; padding: 1px 7px; border-radius: 12px; background: var(--ios-card-solid); border: 1px solid var(--ios-sep); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.react.mine { border-color: var(--pri); }

/* لوحة الإيموجي */
.emoji-btn { width: 30px; height: 30px; color: var(--ios-label2); }
.emoji-btn svg { width: 22px; height: 22px; }
.emoji-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.emoji-tabs button { flex: 1; border: 0; background: transparent; font-size: 22px; height: 40px; border-radius: 10px; cursor: pointer; }
.emoji-tabs button.on { background: var(--ios-fill); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; max-height: 42vh; overflow-y: auto; }
.emoji-grid .em { border: 0; background: transparent; font-size: 28px; height: 44px; border-radius: 10px; cursor: pointer; line-height: 1; }
.emoji-grid .em:active { background: var(--ios-fill); }

/* الفيديو داخل المحادثة */
.msg-video { display: block; max-width: min(260px, 70vw); max-height: 340px; border-radius: 16px; background: #000; }
.bubble:has(> .msg-video):not(:has(.bubble-text)) { background: transparent !important; padding: 0; }
.bubble:has(> .msg-video):not(:has(.bubble-text))::before { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .field-pill { background: rgba(255,255,255,.07); } }
:root[data-theme="dark"] .field-pill { background: rgba(255,255,255,.07); }

/* ===== الصور الشخصية ===== */
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.avatar:has(img) { background: transparent; overflow: hidden; }
.chat-note { text-align: center; font-size: 12px; color: var(--ios-label2); margin: 6px 16px 0; }
.wa-btn { background: #25D366 !important; color: #fff !important; border: 0 !important; }

/* ===== وضع الحماية ===== */
#appMain.protected { position: relative; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#appMain.protected .watermark { position: fixed; inset: 0; pointer-events: none; z-index: 25; background-repeat: repeat; }
body.privacy-blur #appMain.protected .thread, body.privacy-blur #appMain.protected #pendingBox { filter: blur(18px); }

/* ===== تقارير PDF (صفحة A4) ===== */
.rep-tools { display: flex; gap: 8px; justify-content: space-between; margin-bottom: 12px; }
.report-sheet { background: #fff; color: #1d1d1f; border-radius: 12px; padding: 28px 26px; box-shadow: 0 6px 24px rgba(0,0,0,.08); font-size: 14px; line-height: 1.6; max-width: 820px; margin: 0 auto; }
.rep-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 3px solid #0f4a38; padding-bottom: 10px; margin-bottom: 14px; }
.rep-brand { font-size: 24px; font-weight: 900; color: #0f4a38; }
.rep-head .muted { color: #555; }
.rep-title { font-size: 18px; font-weight: 800; color: #0f4a38; }
.rep-name { font-size: 20px; }
.rep-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 14px 0; }
.rep-kpis div { border: 1px solid #e3e6e4; border-radius: 10px; padding: 10px; text-align: center; background: #f7faf8; }
.rep-kpis b { display: block; font-size: 20px; color: #0f4a38; }
.rep-kpis span { font-size: 12px; color: #555; }
.rep-alert { background: #fff6e5; border: 1px solid #f0c36d; border-radius: 10px; padding: 8px 12px; margin: 8px 0 14px; }
.report-sheet h3 { font-size: 16px; color: #0f4a38; margin: 18px 0 8px; }
.rep-chart { width: 100%; height: auto; margin-bottom: 6px; }
.rep-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rep-table th, .rep-table td { border: 1px solid #e3e6e4; padding: 6px 8px; text-align: start; }
.rep-table thead th { background: #0f4a38; color: #fff; }
.rep-table tr.flag td { background: #fff6e5; }
.rep-sign { display: flex; justify-content: space-between; margin-top: 34px; color: #333; }
.rep-foot { display: flex; justify-content: space-between; margin-top: 22px; padding-top: 8px; border-top: 1px solid #e3e6e4; font-size: 11px; color: #666; }
@media print {
  @page { size: A4; margin: 12mm; }
  body, body:has(.app-shell) { background: #fff !important; }
  body:has(.app-shell)::before, .topbar, .bottom-nav, .sidebar, .fab, .app-footer, .announce, .no-print, .update-bar, #toasts { display: none !important; }
  .app-main { padding: 0 !important; margin: 0 !important; max-width: none !important; }
  .report-sheet { box-shadow: none; border-radius: 0; padding: 0; max-width: none; }
  .rep-table thead th, .rep-kpis div, .rep-alert, .rep-table tr.flag td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rep-table tr { break-inside: avoid; }
}

/* ===== الاختبارات ===== */
.qcard { margin-bottom: 10px; }
.qcard .qkind { min-height: 36px; padding: 4px 10px; font-size: 14px; }
.opt-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.opt-row input[type="radio"] { width: 22px; height: 22px; flex: 0 0 22px; accent-color: var(--pri); }
.opt-row .qopt { flex: 1; }
.opt-row.choice { padding: 10px 12px; border-radius: 12px; background: var(--ios-fill); cursor: pointer; }
.opt-row.choice:has(input:checked) { background: color-mix(in srgb, var(--pri) 16%, transparent); outline: 2px solid var(--pri); }
.quiz-bar { position: sticky; top: calc(44px + var(--safe-top)); z-index: 15; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; margin: 0 0 12px; border-radius: 12px; background: var(--glass-bar, var(--card)); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); border: 1px solid var(--ios-sep); }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 20px; color: var(--pri); }
.timer.urgent { color: var(--bad); animation: rec-blink 1s infinite; }
.qitem { margin-bottom: 10px; }
.qitem .short { margin-top: 8px; }
.meter { height: 6px; border-radius: 3px; background: var(--ios-fill); margin: 6px 0 2px; overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 3px; }
.text-bad { color: var(--bad) !important; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* ===== التقييم ===== */
.rate-card { margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px; }
.stars { display: flex; gap: 4px; direction: ltr; justify-content: flex-end; }
.star { border: 0; background: transparent; font-size: 34px; line-height: 1; color: #C7C7CC; cursor: pointer; padding: 2px; min-width: 44px; min-height: 44px; }
.star.on { color: #FFB800; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { border: 1px solid var(--ios-sep); background: transparent; color: var(--tx); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; min-height: 34px; }
.tag.on { background: color-mix(in srgb, var(--pri) 15%, transparent); border-color: var(--pri); }
.tag.bad.on { background: color-mix(in srgb, var(--bad) 14%, transparent); border-color: var(--bad); }

/* ===== الملف الشخصي وبطاقة الأثر ===== */
.avatar.xl { width: 96px; height: 96px; font-size: 38px; margin: 0 auto; }
.profile-head { padding: 20px 16px; }
.impact { margin-bottom: 14px; background: linear-gradient(135deg, color-mix(in srgb, var(--pri) 14%, var(--card)), color-mix(in srgb, var(--acc) 18%, var(--card))) !important; }
.impact-title { font-weight: 800; margin-bottom: 8px; }
.impact-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.impact-row b { display: block; font-size: 24px; color: var(--pri); }
.impact-row span { font-size: 12px; color: var(--ios-label2); }
.ds-load { border: 1px dashed var(--ios-sep); cursor: pointer; font: inherit; }
/* لا تداخل: مساحة سفلية تكفي زر "+" وشريط التبويبات */
body:has(.fab) .app-main { padding-bottom: calc(150px + var(--safe-bottom)); }

#pushCard { margin: 10px 16px 0; }
@media (min-width: 900px) { #pushCard { margin: 14px 32px 0; } }
body[data-screen="chat"] #pushCard { display: none; }

/* ===== سهم الرجوع + عناوين أقسام النماذج ===== */
.topbar-back { flex: 0 0 auto; margin-inline-end: 2px; color: var(--pri); }
.topbar-back svg { width: 24px; height: 24px; stroke-width: 2.4; }
.topbar-back.hidden { display: none !important; }
.page-back { position: fixed; top: calc(env(safe-area-inset-top, 0px) + 10px); inset-inline-start: 10px; z-index: 60; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--card, #fff); color: var(--pri, var(--blue, #0f4a38)); border: 1px solid var(--bd, var(--line, rgba(0,0,0,.14))); box-shadow: 0 2px 10px rgba(0,0,0,.14); text-decoration: none; -webkit-tap-highlight-color: transparent; }
.page-back svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.form-sec { font-weight: 800; color: var(--pri); font-size: 14px; margin: 16px 0 8px; padding-top: 12px; border-top: 1px dashed var(--bd); }
.form-sec.first { margin-top: 4px; padding-top: 0; border-top: 0; }
@media print { .page-back, .topbar-back { display: none !important; } }


/* إصلاح تداخل الاسم والأزرار في الشريط العلوي على الشاشات الضيقة */
.app-shell .topbar {
  display:flex; align-items:center; gap:clamp(3px,1.2vw,9px);
  min-width:0; max-width:100%; overflow:hidden;
}
.app-shell .topbar .brand {
  flex:0 1 auto; min-width:0; max-width:clamp(96px,27vw,190px);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.app-shell .topbar .brand .dot { flex:0 0 10px; }
.app-shell .topbar .btn-icon {
  flex:0 0 40px; width:40px; min-width:40px; max-width:40px;
}
.app-shell .topbar .bar-title {
  flex:0 1 auto; min-width:0; max-width:22vw;
  overflow:hidden; text-overflow:ellipsis;
}
.app-shell .topbar .spacer { flex:1 1 4px; min-width:0; }
.app-shell .topbar > .muted {
  display:block; flex:0 1 auto; min-width:0;
  max-width:clamp(68px,22vw,150px);
  overflow:hidden; white-space:nowrap; text-overflow:ellipsis;
  text-align:start; line-height:1.25;
}
.app-shell .app-footer {
  display:flex; align-items:center; justify-content:center;
  flex-wrap:wrap; gap:4px 8px; text-align:center;
  padding:16px 12px calc(16px + var(--safe-bottom));
  min-width:0; overflow-wrap:anywhere;
}
.app-shell .app-footer > * { min-width:0; max-width:100%; }
@media (max-width:380px) {
  .app-shell .topbar { gap:2px; padding-inline:8px; }
  .app-shell .topbar .btn-icon { flex-basis:36px; width:36px; min-width:36px; max-width:36px; }
  .app-shell .topbar .brand { max-width:25vw; }
  .app-shell .topbar > .muted { max-width:18vw; font-size:11px !important; }
}
