/* ============================================================
   Foundation — reset، body، هرمية الخط، غلاف التطبيق، استراتيجية
   الحاويات، الأدوات المساعدة. لا مكوّنات هنا (components.css)
   ولا لغة الواجهة المرجعية (ui.css).
   Mobile-first: يُكتب لـ390px أولًا ثم يُتحقَّق 360→1440.
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* الحقل المركَّز لا يختفي خلف الشريط العلوي/السفلي عند التمرير التلقائي. */
  scroll-padding-top: calc(var(--topbar-height) + var(--safe-top) + var(--space-4));
  scroll-padding-bottom: calc(var(--bottomnav-height) + var(--safe-bottom) + 96px);
}

body {
  direction: rtl;
  text-align: right;
  font-family: var(--font-family);
  color: var(--color-text);
  font-size: var(--font-size-md);
  line-height: var(--line-height-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  background: var(--color-bg);
}

a {
  color: inherit;
  text-decoration: none;
}

img, svg {
  max-width: 100%;
  display: block;
}

button, input, select, textarea {
  font-family: inherit;
}

button {
  touch-action: manipulation;
}

/* داخل التطبيق فقط — الـLanding له إيقاعه الخاص في landing.css. */
:where(.app-main, .guest-card) :is(h1, h2, h3, p) {
  margin: 0;
}

[hidden] {
  display: none !important;
}

/* ---------- Typography hierarchy ----------
   الهرمية تُبنى بالحجم + الوزن + اللون + المسافة معًا (لا بالحجم وحده):
   page 24/700 · section 18/700 · row/card 16/600 · body 16/400
   · supporting 14/400 muted · meta 12/400 faint. */

.page-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--color-primary-deep);
  overflow-wrap: break-word;
}

/* عنوان قسم داخل بطاقة/نموذج/إعدادات (نفس مقاس .sec__title، بلا أيقونة). أقسام الصفحات تستعمل .sec. */
.section-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--color-primary-dark);
  margin: 0 0 var(--space-3);
}

.card-title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  overflow-wrap: break-word;
}

.body-text {
  font-size: var(--font-size-md);
  line-height: var(--line-height-normal);
}

.supporting-text {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  line-height: var(--line-height-normal);
}

.meta-text {
  font-size: var(--font-size-xs);
  color: var(--color-text-faint);
  line-height: var(--line-height-normal);
}

/* أرقام وتواريخ وهواتف: تبقى بترتيبها اللاتيني داخل السياق العربي
   (unicode-bidi: isolate يمنع تأثّرها بالنص المجاور)، وأرقام متساوية العرض
   حتى تصطف الأعمدة والنسب. */
.ltr {
  direction: ltr;
  unicode-bidi: isolate;
}

.num {
  font-variant-numeric: tabular-nums lining-nums;
}

/* ---------- App shell ---------- */

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* غلاف المحتوى (الشريط العلوي + الصفحة): عمود يملأ الارتفاع؛ الشريط الجانبي يجاوره على سطح المكتب (patterns.css). */
.app-shell__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-main {
  flex: 1;
  width: 100%;
  padding: var(--space-3) var(--gutter) calc(var(--bottomnav-height) + var(--safe-bottom) + var(--space-8));
}

.app-main > .container {
  margin: 0 auto;
}

/* بلا شريط سفلي (بوابة ولي الأمر): لا مساحة محجوزة له. */
.app-shell--no-bottomnav .app-main {
  padding-bottom: calc(var(--space-5) + var(--safe-bottom));
}

/* Container width variants — pick per page type via .container--* on the
   view() call's wrapping element (see components.css usage in templates).
   Same specificity (one class) as the default below, so source order
   decides — keep the default first, variants after. */
.container { max-width: var(--container-app); }
.container--reading  { max-width: var(--container-reading); }
.container--app      { max-width: var(--container-app); }
.container--dashboard{ max-width: var(--container-dashboard); }
.container--admin    { max-width: var(--container-admin); }
.container--detail   { max-width: var(--container-app); }
.container--wide     { max-width: none; }

@media (min-width: 1024px) {
  .container--detail { max-width: 1000px; }
}

.guest-shell {
  position: relative;
  overflow: hidden;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(var(--space-6), var(--safe-top)) var(--gutter) max(var(--space-6), var(--safe-bottom));
}

/* Geometric star-tile motif (public/assets/img/pattern-geometric.png) —
   same treatment as the landing page hero/footer, so the auth screens
   read as the same product. */
.guest-shell::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('/assets/img/pattern-geometric.png');
  background-repeat: repeat;
  background-size: 67.2px 38.4px;
  opacity: .06;
  pointer-events: none;
}

.guest-card {
  position: relative;
  width: 100%;
  max-width: 420px;
}

.guest-card--wide {
  max-width: var(--container-reading);
}

/* هوية مضغوطة: شعار + اسم المركز بحجم عنوان لا بحجم لافتة. */
.guest-back {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-2);
  color: var(--color-primary-deep);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  margin-bottom: var(--space-6);
}

.guest-back__logo {
  width: auto;
  height: 80px;
  object-fit: contain;
  flex-shrink: 0;
}

/* اسم التطبيق (+ الشعار النصي) تحت هوية المركز في الدخول: سطر هادئ، ويُخفى في النماذج الطويلة. */
.guest-app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  margin: calc(var(--space-4) * -1) 0 var(--space-6);
  color: var(--color-text-muted, var(--color-text-secondary));
  font-size: var(--font-size-sm);
  text-align: center;
}

.guest-app__tag {
  font-size: var(--font-size-xs, var(--font-size-sm));
  opacity: 0.85;
}

.guest-card--wide .guest-app {
  display: none;
}

/* النماذج الطويلة (تسجيل الطالب): صف أفقي صغير بدل لافتة عمودية،
   حتى يظهر أول حقل في الشاشة الأولى. */
.guest-card--wide .guest-back {
  flex-direction: row;
  justify-content: flex-start;
  gap: var(--space-3);
  font-size: var(--font-size-md);
  margin-bottom: var(--space-5);
}

.guest-card--wide .guest-back__logo {
  height: 52px;
}

/* ---------- TopBar ----------
   شريط علوي بلا حدّ عند أعلى الصفحة ولا blur: يندمج مع الخلفية، ويظهر الحدّ
   الرفيع (والعنوان) فقط عندما يمرّ المحتوى تحته (.is-scrolled من app.js).
   العنوان الكبير في الصفحة هو h1؛ عنوان الشريط يظهر بعد أن يغادر h1 الشاشة،
   فلا يتكرر الاسم مرتين. */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: calc(var(--topbar-height) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--color-bg);
  box-shadow: 0 1px 0 transparent;
  /* حافتان متساويتان + عنوان أوسط: العنوان في المنتصف الحقيقي مهما طال اسم "الرجوع". */
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-1);
  padding-inline: var(--space-2);
  transition: box-shadow var(--transition-base);
}

.topbar.is-scrolled {
  box-shadow: 0 1px 0 var(--color-hairline);
}

.topbar__side {
  display: flex;
  align-items: center;
  min-width: 0;
}

.topbar__side--end {
  justify-content: flex-end;
}

.topbar__title {
  line-height: var(--line-height-tight);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  max-width: 46vw;
  transition: opacity var(--transition-base);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--color-primary-dark);
}

/* JS وجد h1 في الصفحة: العنوان يبقى مخفيًا حتى يمرّ h1 تحت الشريط. */
.topbar--collapsible .topbar__title {
  opacity: 0;
}

.topbar--collapsible.is-titled .topbar__title {
  opacity: 1;
}

/* بوابة ولي الأمر: زر الحساب هو صورة/حرفا الاسم (لا شريط سفلي لوجهة واحدة). */
.topbar__account {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-target-min);
  height: var(--touch-target-min);
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: pointer;
}

.topbar__account .avatar {
  width: 36px;
  height: 36px;
  font-size: 14px;
  background: var(--color-primary);
  color: #fff;
}

/* مسار التنقل (Breadcrumbs) للشاشات العريضة فقط. */
.topbar__crumbs {
  display: none;
}

/* ---------- BottomNav ----------
   ثابت وهادئ: خلفية سطح أبيض، حدّ رفيع، أيقونة 24px، اسم 12px.
   الحالة النشطة = لون + وزن + خط مؤشّر رفيع في الأعلى (لا تعتمد على اللون وحده). */

.bottom-nav {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  z-index: 20;
  height: calc(var(--bottomnav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--color-surface);
  display: flex;
  transition: transform var(--transition-base);
  box-shadow: 0 -1px 0 var(--color-hairline), 0 -10px 24px -18px color-mix(in srgb, var(--palette-forest-dark) 30%, transparent);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding-top: 4px;
}

.bottom-nav__item {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 2px;
  font-weight: var(--font-weight-medium);
  line-height: 1.3;
  border: none;
  background: none;
  font-family: inherit;
  cursor: pointer;
  gap: 3px;
  font-size: var(--font-size-meta);
  color: var(--color-text-muted);
}

.bottom-nav__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.bottom-nav__item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 24px;
  height: 3px;
  margin-left: -12px;
  border-radius: 0 0 3px 3px;
  background: var(--color-primary);
  transform: scaleX(0);
  transition: transform var(--transition-base);
  display: none;
}

.bottom-nav__item.is-active {
  color: var(--color-primary-dark);
  font-weight: var(--font-weight-bold);
}

.bottom-nav__item.is-active::before {
  transform: scaleX(1);
}

.bottom-nav__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 44px;
  height: 30px;
  border-radius: var(--radius-pill);
  transition: background-color var(--transition-base), color var(--transition-base);
}

.bottom-nav__item.is-active svg {
  stroke-width: 2.1;
}

.bottom-nav__item:active .bottom-nav__icon {
  opacity: 0.55;
}

/* لوحة المفاتيح مفتوحة: الشريط السفلي لا يأكل مساحة الكتابة. */
.kb-open .bottom-nav {
  transform: translateY(100%);
}

/* ---------- Utilities ---------- */

.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.mb-0 { margin-bottom: 0 !important; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mt-7 { margin-top: var(--space-7); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mb-6 { margin-bottom: var(--space-6); }
.flex-1 { flex: 1; min-width: 0; }
.inline-block { display: inline-block; }

.stack { display: flex; flex-direction: column; }
.stack > * + * { margin-top: var(--space-3); }

.cluster {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.cluster--between {
  justify-content: space-between;
}

.cluster--wrap {
  flex-wrap: wrap;
}

.min-w-0 { min-width: 0; }

.skip-link {
  position: absolute;
  right: var(--space-3);
  top: -60px;
  background: var(--color-primary-deep);
  color: #fff;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  z-index: 100;
  transition: top var(--transition-fast);
  font-weight: var(--font-weight-bold);
}

.skip-link:focus {
  top: var(--space-3);
}

.js .no-js-only {
  display: none !important;
}

.js-only {
  display: none !important;
}

.js .js-only {
  display: flex !important;
}

/* صفوف إضافية تُكشف بلمسة "عرض المزيد" (بدون JS تظهر كلها). */
.js [data-more]:not(.is-shown) {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Motion ----------
   لا حركة دخول للصفحة: التنقل يجب أن يبدو فوريًا. الحركة فقط حيث تفيد
   (ورقة "المزيد"، الرسائل، حالات الضغط) وبين 120 و220ms. */

@keyframes app-fade-down {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Hover feedback (pointer devices only) ----------
   Touch already gets :active feedback throughout; add :hover strictly for
   mice/trackpads so desktop use of the admin panel doesn't feel dead, and
   avoid sticky-hover-after-tap on touch by gating with (hover: hover). */

@media (hover: hover) and (pointer: fine) {

  .bottom-nav__item:not(.is-active):hover {
    color: var(--color-text);
  }
}

/* ---------- Focus visibility (accessibility) ---------- */

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---------- Wider screens: same app, more breathing room ---------- */

@media (min-width: 480px) {
  .app-main {
    padding-inline: var(--space-5);
  }
}

@media (min-width: 768px) {
  .app-main {
    padding: var(--space-5) var(--space-7) calc(var(--bottomnav-height) + var(--safe-bottom) + var(--space-7));
  }

  .page-title {
    font-size: 1.75rem;
  }
}

@media (min-width: 1024px) {
  .app-main {
    padding-inline: var(--space-8);
  }
}

/* شريط التنقل السفلي على الشاشات العريضة: قرص وسطي بعرض معقول لا شريط بعرض 1440px. */
@media (min-width: 768px) {
  .bottom-nav {
    width: min(560px, 100%);
    margin-inline: auto;
    border-radius: var(--radius-surface) var(--radius-surface) 0 0;
    box-shadow: 0 -1px 0 var(--color-hairline), 0 -8px 24px -12px color-mix(in srgb, var(--palette-charcoal-dark) 16%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
