/* ==========================================================================
   layout.css — هيكل الصفحات
   ========================================================================== */

.app {
  min-height: 100svh;
  display: flex; flex-direction: column;
  padding-block-end: calc(var(--dock-h) + var(--sp-6));
}

.container {
  width: 100%; max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: clamp(var(--sp-3), 2.5vw, var(--sp-8));
}

/* --------------------------------------------------------------------------
   الترويسة
   -------------------------------------------------------------------------- */
.topbar {
  position: sticky; inset-block-start: 0; z-index: var(--z-sticky);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  border-block-end: var(--border-w) solid var(--border);
}
.topbar__inner {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: 68px; padding-block: var(--sp-2);
}

.brand { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
/* الشعار الآن SVG يحمل قرصه الخاص — لا صندوق أبيض حوله (كان تأطيراً مزدوجاً). */
.brand__logo {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
}
.brand__logo img {
  width: 100%; height: 100%; object-fit: contain;
  border-radius: var(--r-full);
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.28));
}
.brand__text { min-width: 0; display: flex; flex-direction: column; }
.brand__name {
  display: block;
  font-family: var(--font-display); font-weight: 800;
  font-size: var(--text-lg); line-height: 1.15;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.brand__sub {
  display: block;
  font-size: var(--text-xs); color: var(--text-3); line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.topbar__actions { display: flex; align-items: center; gap: var(--sp-1); margin-inline-start: auto; }

.user-pill {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3) var(--sp-1) var(--sp-1);
  border-radius: var(--r-full);
  background: var(--surface-2); border: var(--border-w) solid var(--border);
  font-size: var(--text-xs); font-weight: 700; color: var(--text-2);
  max-width: 200px;
}
.user-pill__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 560px) { .user-pill__name { display: none; } }

/* --------------------------------------------------------------------------
   ترويسة الصفحة
   -------------------------------------------------------------------------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-4); flex-wrap: wrap;
  padding-block: var(--sp-6) var(--sp-4);
}
.page-head__title { font-size: var(--text-2xl); margin: 0; }
.page-head__sub { color: var(--text-2); font-size: var(--text-sm); margin-block-start: var(--sp-1); }
.page-head__actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   المحتوى
   -------------------------------------------------------------------------- */
.main { flex: 1 1 auto; display: flex; flex-direction: column; gap: var(--sp-5); }

.section { display: flex; flex-direction: column; gap: var(--sp-4); }
.section__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); flex-wrap: wrap;
}
.section__title {
  font-size: var(--text-lg); display: flex; align-items: center; gap: var(--sp-2);
}
.section__title svg { color: var(--brand); }

.grid-2 { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); } }

.grid-auto { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); }

/* شريط الأدوات (بحث + تاريخ) */
.toolbar {
  display: grid; gap: var(--sp-3);
  grid-template-columns: 1fr;
}
@media (min-width: 720px) {
  .toolbar { grid-template-columns: minmax(0, 1fr) 210px; align-items: end; }
}

.search-shell { position: relative; }

/* --------------------------------------------------------------------------
   شريط التنقّل السفلي
   -------------------------------------------------------------------------- */
.dock {
  position: fixed; inset-block-end: 0; inset-inline: 0; z-index: var(--z-dock);
  display: flex; justify-content: center;
  padding: var(--sp-2) var(--sp-3) calc(var(--sp-2) + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}
.dock__inner {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--sp-1);
  padding: var(--sp-2);
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(18px) saturate(170%);
  -webkit-backdrop-filter: blur(18px) saturate(170%);
  border: var(--border-w) solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.dock__inner::-webkit-scrollbar { display: none; }

.dock__btn {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; flex: none;
  min-width: 62px; min-height: 52px; padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-lg);
  color: var(--text-3); text-decoration: none;
  font-size: var(--text-2xs); font-weight: 700;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.dock__btn:hover { background: var(--surface-hover); color: var(--text); }
.dock__btn[aria-current='page'] { background: var(--brand-soft); color: var(--brand); }
.dock__btn svg { flex: none; }

/* --------------------------------------------------------------------------
   صفحة الدخول
   -------------------------------------------------------------------------- */
.gate {
  min-height: 100svh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--sp-6) var(--sp-4) var(--sp-10);
  gap: var(--sp-6);
  text-align: center;
  position: relative;
}
.gate__top { position: absolute; inset-block-start: var(--sp-4); inset-inline-end: var(--sp-4); display: flex; gap: var(--sp-2); }

.gate__hero { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }

/* لا صندوق ولا إطار — الشعار نفسه قرص متكامل، والهالة الخفيفة تبرزه فقط. */
.gate__logo {
  width: clamp(128px, 23vw, 172px); aspect-ratio: 1;
  display: grid; place-items: center;
}
.gate__logo img {
  width: 100%; height: 100%; object-fit: contain;
  border-radius: var(--r-full);
  filter: drop-shadow(0 10px 26px rgba(0, 0, 0, 0.34));
  animation: logo-breathe 5s var(--ease-out) infinite;
}
@keyframes logo-breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.028); }
}

/* اسم النظام تحت الشعار */
.gate__wordmark {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--brand);
  text-transform: none;
}

.gate__help {
  max-width: 460px; width: 100%;
  background: transparent; border-style: dashed;
}
.gate__help > summary { font-size: var(--text-sm); color: var(--text-3); font-weight: 600; }
.gate__help code {
  font-family: var(--font-mono); font-size: 0.9em;
  background: var(--surface-3); padding: 1px 6px; border-radius: var(--r-xs);
  direction: ltr; display: inline-block;
}
.gate__help p { margin: 0; line-height: var(--leading-loose); }

.gate__school {
  font-family: var(--font-display); font-weight: 800;
  font-size: var(--text-3xl); line-height: 1.1; margin: 0;
}
.gate__title {
  font-family: var(--font-body); font-weight: 500;
  font-size: var(--text-lg); color: var(--text-2);
  max-width: 32ch; margin: 0;
}
.gate__principal {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-size: var(--text-sm); font-weight: 700; color: var(--accent);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--r-full);
  background: var(--accent-soft);
  border: var(--border-w) solid color-mix(in srgb, var(--accent) 30%, transparent);
}

.gate__actions {
  display: grid; gap: var(--sp-3);
  width: 100%; max-width: 420px;
}

.gate-btn {
  display: flex; align-items: center; gap: var(--sp-4);
  width: 100%; min-height: 72px; padding: var(--sp-4) var(--sp-5);
  border-radius: var(--r-lg);
  background: var(--surface); color: var(--text);
  border: var(--border-w) solid var(--border);
  box-shadow: var(--shadow-md);
  text-align: start; cursor: pointer;
  transition: transform var(--dur-base) var(--ease-spring),
              border-color var(--dur-fast), box-shadow var(--dur-fast), background var(--dur-fast);
}
.gate-btn:hover { transform: translateY(-3px); border-color: var(--brand-border); box-shadow: var(--shadow-lg); }
.gate-btn:active { transform: translateY(-1px); }
.gate-btn__icon {
  width: 46px; height: 46px; flex: none; border-radius: var(--r-md);
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
}
.gate-btn__body { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; gap: 3px; }
.gate-btn__title {
  display: block;
  font-family: var(--font-display); font-weight: 800; font-size: var(--text-md);
  line-height: 1.3;
}
.gate-btn__desc {
  display: block;
  font-size: var(--text-xs); color: var(--text-3); line-height: 1.45;
}
.gate-btn__arrow { color: var(--text-3); flex: none; transition: transform var(--dur-base); }
.gate-btn:hover .gate-btn__arrow { transform: translateX(-4px); color: var(--brand); }

.gate-btn--subtle {
  min-height: 52px; background: transparent; box-shadow: none;
  border-style: dashed;
}
.gate-btn--subtle .gate-btn__icon { width: 34px; height: 34px; background: transparent; color: var(--text-3); }
.gate-btn--subtle .gate-btn__title { font-size: var(--text-sm); color: var(--text-2); }



/* --------------------------------------------------------------------------
   التذييل
   -------------------------------------------------------------------------- */
.credit {
  text-align: center; font-size: var(--text-md); font-weight: 600;
  letter-spacing: 0.02em; color: var(--text-2);
  padding-block: var(--sp-5);
  direction: ltr;
}

/* --------------------------------------------------------------------------
   الرسوم البيانية
   -------------------------------------------------------------------------- */
.chart-box {
  position: relative; width: 100%;
  height: clamp(240px, 34vh, 340px);
}
.chart-box--sm { height: 190px; }
.chart-legend {
  display: flex; gap: var(--sp-4); flex-wrap: wrap; justify-content: center;
  font-size: var(--text-xs); color: var(--text-2); margin-block-start: var(--sp-3);
}
.chart-legend__key { display: inline-flex; align-items: center; gap: var(--sp-2); }
.chart-legend__swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }

/* صف تحليل أسبوعي */
.week-row {
  display: grid; grid-template-columns: 1fr auto; gap: var(--sp-2) var(--sp-3);
  padding: var(--sp-3) 0;
  border-block-start: var(--border-w) solid var(--border);
}
.week-row:first-child { border-block-start: none; }
.week-row__label { font-size: var(--text-sm); font-weight: 700; }
.week-row__sub { font-size: var(--text-xs); color: var(--text-3); }
.week-row__value { font-weight: 800; font-variant-numeric: tabular-nums; text-align: end; }
.week-row__meter { grid-column: 1 / -1; }

/* عنصر أخصائي */
.spec-row {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%; padding: var(--sp-3);
  border-radius: var(--r-md); text-align: start;
  transition: background var(--dur-fast);
  cursor: pointer;
}
.spec-row:hover { background: var(--surface-2); }
.spec-row__body { flex: 1 1 auto; min-width: 0; }
.spec-row__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.spec-row__name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* بطاقة البطل */
.hero-card {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg,
              color-mix(in srgb, var(--accent) 16%, var(--surface)),
              var(--surface) 65%);
  border: var(--border-w) solid color-mix(in srgb, var(--accent) 34%, transparent);
  border-radius: var(--r-lg); padding: var(--sp-5);
  display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap;
}
.hero-card__medal {
  width: 58px; height: 58px; border-radius: var(--r-full); flex: none;
  display: grid; place-items: center; font-size: 1.7rem;
  background: var(--accent-soft); border: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
.hero-card__body { flex: 1 1 240px; min-width: 0; }
.hero-card__kicker { font-size: var(--text-xs); font-weight: 800; color: var(--accent); letter-spacing: 0.5px; }
.hero-card__name { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 800; margin-block: 2px; }
.hero-card__desc { font-size: var(--text-sm); color: var(--text-2); }

/* --------------------------------------------------------------------------
   صفوف التواصل
   -------------------------------------------------------------------------- */
.contact-row {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-3);
  border-radius: var(--r-md); background: var(--surface-2);
  border: var(--border-w) solid var(--border);
}
.contact-row__body { flex: 1 1 180px; min-width: 0; }
.contact-row__name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-row__meta { font-size: var(--text-xs); color: var(--text-3); }
.contact-row__phone { width: 160px; direction: ltr; text-align: center; font-variant-numeric: tabular-nums; }
.contact-row__actions { display: flex; gap: var(--sp-2); }

/* --------------------------------------------------------------------------
   منطقة الرفع
   -------------------------------------------------------------------------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-5);
  border: 2px dashed var(--border-strong); border-radius: var(--r-lg);
  background: var(--surface-2); text-align: center;
  cursor: pointer;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.dropzone:hover, .dropzone.is-over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone__icon { color: var(--brand); }
.dropzone__title { font-weight: 700; }
.dropzone__hint { font-size: var(--text-xs); color: var(--text-3); }

/* معاينة صورة */
.asset {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3); border-radius: var(--r-md);
  background: var(--surface-2); border: var(--border-w) solid var(--border);
}
.asset__preview {
  width: 84px; height: 84px; flex: none; border-radius: var(--r-sm);
  background: #fff; border: var(--border-w) solid var(--border);
  display: grid; place-items: center; overflow: hidden; padding: 4px;
}
.asset__preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.asset__preview.is-empty { background: var(--surface-3); color: var(--text-3); font-size: var(--text-2xs); }
.asset__body { flex: 1 1 auto; min-width: 0; }
.asset__name { font-weight: 700; font-size: var(--text-sm); }
.asset__meta { font-size: var(--text-xs); color: var(--text-3); }
.asset__actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-block-start: var(--sp-2); }

/* --------------------------------------------------------------------------
   شاشة التحميل
   -------------------------------------------------------------------------- */
.boot {
  position: fixed; inset: 0; z-index: var(--z-toast);
  display: grid; place-items: center; gap: var(--sp-4);
  background: var(--bg); background-image: var(--bg-gradient);
  transition: opacity var(--dur-slow) var(--ease-out);
}
.boot.is-done { opacity: 0; pointer-events: none; }
.boot__inner { display: flex; flex-direction: column; align-items: center; gap: var(--sp-4); }
.boot__logo { width: 78px; height: 78px; opacity: 0.9; animation: soft-pulse 1.8s ease-in-out infinite; }
.boot__text { font-size: var(--text-sm); color: var(--text-3); }

/* --------------------------------------------------------------------------
   تعديلات الشاشات الصغيرة
   -------------------------------------------------------------------------- */
@media (max-width: 620px) {
  :root { --dock-h: 66px; }
  .topbar__inner { min-height: 60px; }
  .brand__logo { width: 40px; height: 40px; }
  .brand__name { font-size: var(--text-md); }
  .brand__sub { display: none; }
  .page-head { padding-block: var(--sp-4) var(--sp-3); }
  .card { padding: var(--sp-4); }
  .modal { padding: 0; align-items: flex-end; }
  .modal__panel {
    max-width: 100%; max-height: 92svh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    animation: rise-in var(--dur-slow) var(--ease-out);
  }
  .modal__footer .btn { max-width: none; }
  .dock__btn { min-width: 54px; }
  .contact-row__phone { width: 100%; }
}

@media (max-width: 400px) {
  .dock__btn span { display: none; }
  .dock__btn { min-width: 46px; min-height: 46px; }
}
