/* ==========================================================
   الأساس: إعادة الضبط، الطباعة، والمكوّنات المشتركة
   ========================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-16);
  font-weight: 400;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* انتقال الوضع الداكن/الفاتح: 300ms على الألوان فقط */
.theme-anim, .theme-anim *, .theme-anim *::before {
  transition: background-color var(--t-theme) var(--ease), color var(--t-theme) var(--ease),
    border-color var(--t-theme) var(--ease), fill var(--t-theme) var(--ease), stroke var(--t-theme) var(--ease) !important;
}

/* ---------- الطباعة ---------- */
.display { font-family: var(--font-display); font-weight: 800; line-height: 1.25; letter-spacing: 0; }
.display-b { font-family: var(--font-display); font-weight: 700; line-height: 1.2; }
.t-12 { font-size: var(--fs-12); }
.t-14 { font-size: var(--fs-14); }
.t-16 { font-size: var(--fs-16); }
.t-20 { font-size: var(--fs-20); }
.t-28 { font-size: var(--fs-28); }
.t-44 { font-size: var(--fs-44); }
.w5 { font-weight: 500; }
.w7 { font-weight: 700; }
.c2 { color: var(--text-2); }
.c3 { color: var(--text-3); }
.c-up { color: var(--up); }
.c-down { color: var(--down); }
.c-gold { color: var(--gold); }

.section-title {
  font-size: var(--fs-14);
  font-weight: 500;
  color: var(--text-3);
  margin-bottom: var(--s-12);
}

/* ---------- الأيقونات والشارات ---------- */
.ic { width: 20px; height: 20px; flex: none; }
.ic.sm { width: 16px; height: 16px; }
.ic.lg { width: 24px; height: 24px; }
.badge { flex: none; overflow: visible; }
.badge *, .medal *, .gift-ph * { vector-effect: non-scaling-stroke; }
.badge { stroke-width: var(--bw, 1.5px); }
.champ { flex: none; }
.medal { overflow: visible; flex: none; }

/* لمعة الميدالية الأولى: تمر كل 6 ثوانٍ ببطء */
.shimmer-band { animation: shimmer 6s var(--ease) infinite; }
@keyframes shimmer {
  0%, 72% { transform: translateX(0) skewX(-20deg); }
  100% { transform: translateX(56px) skewX(-20deg); }
}

/* تبدّل الشارة عند الترقي */
.badge-swap { position: relative; display: inline-grid; }
.badge-swap > * { grid-area: 1 / 1; }
.badge-out { animation: badgeOut var(--t-panel) var(--ease) forwards; }
.badge-in { animation: badgeIn var(--t-panel) var(--ease) both; }
@keyframes badgeOut { to { opacity: 0; transform: rotate(-22.5deg) scale(0.9); } }
@keyframes badgeIn { from { opacity: 0; transform: rotate(22.5deg) scale(0.9); } }

/* ---------- الأزرار ---------- */
.btn {
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-8);
  min-height: 40px;
  padding: 0 var(--s-16);
  border-radius: var(--r-ctl);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-14);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--t-hover) var(--ease), border-color var(--t-hover) var(--ease), color var(--t-hover) var(--ease), opacity var(--t-ctl) var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--navy); color: #FFFFFF; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.btn.sun { background: var(--sun); color: #FFFFFF; border-color: var(--sun); }
.btn.sun:hover { background: var(--sun-ink); }
.btn.danger { color: var(--down); border-color: color-mix(in srgb, var(--down) 45%, var(--line-strong)); }
.btn.danger:hover { background: color-mix(in srgb, var(--down) 10%, var(--surface)); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.lg { min-height: var(--tap-min); font-size: var(--fs-16); padding: 0 var(--s-24); }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-ctl);
  color: var(--text-2);
  transition: background-color var(--t-hover) var(--ease), color var(--t-hover) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* حالة التركيز: حد ذهبي رفيع وواضح */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; border-radius: var(--r-ctl); }

/* ---------- الحقول ---------- */
.field { display: grid; gap: var(--s-8); }
.field > span { font-size: var(--fs-14); color: var(--text-2); }
.input, .select, textarea.input {
  width: 100%;
  min-height: 44px;
  padding: 0 var(--s-12);
  border-radius: var(--r-ctl);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-16);
  transition: border-color var(--t-hover) var(--ease);
}
textarea.input { padding: var(--s-12); min-height: 88px; resize: vertical; line-height: 1.5; }
.input::placeholder { color: var(--text-3); }
.input:hover, .select:hover { border-color: var(--text-3); }
.input:focus-visible, .select:focus-visible { outline: none; border-color: var(--sky); box-shadow: 0 0 0 3px var(--sky-tint); }
.input.num-in { text-align: center; direction: ltr; }
.select {
  appearance: none;
  padding-left: var(--s-32);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256' fill='%238C8174'><path d='M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z'/></svg>");
  background-repeat: no-repeat;
  background-size: 16px;
  background-position: left 12px center;
}

/* مفتاح تبديل (switch) */
.switch { display: inline-flex; align-items: center; gap: var(--s-12); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  position: relative;
  width: 40px;
  height: 24px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  transition: background-color var(--t-ctl) var(--ease), border-color var(--t-ctl) var(--ease);
  flex: none;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform var(--t-ctl) var(--ease), background-color var(--t-ctl) var(--ease);
}
.switch input:checked + .track { background: var(--sky); border-color: var(--sky); }
.switch input:checked + .track::after { transform: translateX(-16px); background: #FFFFFF; }
.switch input:focus-visible + .track { outline: 2px solid var(--sky); outline-offset: 2px; }

/* أزرار مقسّمة (segmented) — تستعمل لمفتاح الشهري/الكلي والحضور */
.seg {
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
}
.seg button {
  position: relative;
  z-index: 1;
  min-height: 36px;
  padding: 0 var(--s-24);
  border-radius: 9px;
  font-size: var(--fs-14);
  font-weight: 500;
  color: var(--text-2);
  transition: color var(--t-ctl) var(--ease);
}
.seg button:hover { color: var(--text-2); }
.seg button[aria-pressed="true"] { color: var(--navy); font-weight: 700; }
.seg .thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(11, 61, 107, 0.12);
  transition: transform var(--t-ctl) var(--ease), width var(--t-ctl) var(--ease);
}

/* شريط تقدم رفيع 4px */
.bar { height: 6px; border-radius: var(--r-pill); background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--sky); transition: width 900ms var(--ease); }
.bar.gold > i { background: var(--sun); }

/* شارة صغيرة (pill) */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-4);
  height: 24px;
  padding: 0 var(--s-8);
  border-radius: var(--r-pill);
  border: 1px solid var(--line-strong);
  font-size: var(--fs-12);
  color: var(--text-2);
  white-space: nowrap;
}
.pill.gold { border-color: transparent; background: var(--sun-tint); color: var(--sun-ink); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
}

/* ---------- الحالات: تحميل، فارغ، خطأ ---------- */
.skel {
  background: var(--surface-2);
  border-radius: var(--r-ctl);
  animation: skel 1.6s var(--ease) infinite;
}
@keyframes skel { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.state {
  display: grid;
  justify-items: center;
  gap: var(--s-12);
  padding: var(--s-48) var(--s-24);
  text-align: center;
  color: var(--text-2);
}
.state .ic { width: 32px; height: 32px; color: var(--text-3); }
.state p { max-width: 36ch; font-size: var(--fs-14); }
.state strong { color: var(--text); font-weight: 500; font-size: var(--fs-16); }

/* شريط عدم الاتصال */
.offline {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-8);
  min-height: 40px;
  padding: var(--s-8) var(--s-16);
  background: var(--surface-2);
  border-top: 1px solid var(--line-strong);
  color: var(--text-2);
  font-size: var(--fs-14);
  transform: translateY(8px);
  opacity: 0;
  visibility: hidden;
  transition: transform var(--t-ctl) var(--ease), opacity var(--t-ctl) var(--ease), visibility var(--t-ctl);
}
.offline.show { transform: none; opacity: 1; visibility: visible; }

/* ---------- الإشعارات (toast) ---------- */
.toasts {
  position: fixed;
  z-index: 1200;
  bottom: var(--s-24);
  inset-inline: 0;
  display: grid;
  justify-items: center;
  gap: var(--s-8);
  pointer-events: none;
  padding: 0 var(--s-16);
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--s-12);
  min-height: 48px;
  max-width: 520px;
  padding: var(--s-8) var(--s-8) var(--s-8) var(--s-16);
  padding-inline-start: var(--s-16);
  border-radius: var(--r-card);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-14);
  animation: toastIn var(--t-ctl) var(--ease);
}
.toast.err { border-color: color-mix(in srgb, var(--down) 55%, var(--line-strong)); }
.toast.err .ic { color: var(--down); }
.toast.ok .ic { color: var(--up); }
.toast .btn { min-height: 32px; padding: 0 var(--s-12); }
.toast.out { animation: toastOut var(--t-ctl) var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ---------- النوافذ: اللوحة الجانبية والحوار ---------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--scrim);
  opacity: 0;
  transition: opacity var(--t-panel) var(--ease);
}
.scrim.open { opacity: 1; }
.drawer {
  position: fixed;
  z-index: 1001;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(440px, 100vw);
  background: var(--surface);
  border-right: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop);
  transform: translateX(-100%);
  transition: transform var(--t-panel) var(--ease);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer.open { transform: none; }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-12);
  min-height: var(--header-h);
  padding: 0 var(--s-16) 0 var(--s-12);
  padding-inline: var(--s-24) var(--s-12);
  border-bottom: 1px solid var(--line);
}
.drawer-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; }

.modal {
  position: fixed;
  z-index: 1001;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--s-16);
  pointer-events: none;
}
.modal > .panel {
  pointer-events: auto;
  width: min(480px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-pop);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--t-ctl) var(--ease), transform var(--t-ctl) var(--ease);
}
.modal.open > .panel { opacity: 1; transform: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-12); padding: var(--s-16) var(--s-24); border-bottom: 1px solid var(--line); }
.panel-body { padding: var(--s-24); display: grid; gap: var(--s-16); }
.panel-foot { display: flex; gap: var(--s-8); justify-content: flex-start; padding: var(--s-16) var(--s-24); border-top: 1px solid var(--line); }

/* ---------- الاحتفال: الحلقة الذهبية والقصاصات ---------- */
.celebrate-ring {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
  border: 3px solid var(--yellow);
  pointer-events: none;
  animation: ring 1400ms var(--ease) forwards;
}
@keyframes ring {
  from { transform: scale(0.6); opacity: 0.9; }
  to { transform: scale(2.6); opacity: 0; }
}
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 1500; }

/* ---------- احترام تقليل الحركة: كل الحركة تتحول إلى تلاشٍ بسيط ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-property: opacity, background-color, color, border-color !important;
  }
  .drawer { transform: none; opacity: 0; pointer-events: none; transition: opacity var(--t-panel) var(--ease) !important; }
  .drawer.open { opacity: 1; pointer-events: auto; }
  .shimmer-band { display: none; }
}
