/* ==========================================================================
   base.css — إعادة الضبط، الطباعة النصية، والأدوات المساعدة
   ========================================================================== */

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

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* تصحيح مهم: النسخة القديمة كانت تمنع التكبير عبر user-scalable=no
     في كل الصفحات، وهي مخالفة صريحة لمعيار WCAG 1.4.4. */
}

body {
  min-height: 100svh;
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  color: var(--text);
  background-color: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

button { background: none; border: none; padding: 0; cursor: pointer; }

a { color: var(--brand-strong); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--brand); }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: var(--leading-tight);
  text-wrap: balance;
}
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

p { text-wrap: pretty; }

ul, ol { padding: 0; list-style: none; }

table { border-collapse: collapse; border-spacing: 0; width: 100%; }

hr { border: none; border-top: 1px solid var(--border); margin: var(--sp-5) 0; }

::selection { background: var(--brand-soft); color: var(--text); }

/* --------------------------------------------------------------------------
   التركيز — كان معطّلاً تماماً في النسخة القديمة (outline:none في 6 مواضع
   دون أي بديل)، فيستحيل التنقّل بلوحة المفاتيح.
   -------------------------------------------------------------------------- */
:focus { outline: none; }

:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* --------------------------------------------------------------------------
   أشرطة التمرير
   -------------------------------------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

/* --------------------------------------------------------------------------
   احترام تفضيل تقليل الحركة — كان غائباً رغم 8 حركات لا نهائية
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   أدوات مساعدة
   ========================================================================== */

.hidden { display: none !important; }

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

/* رابط "تخطَّ إلى المحتوى" لمستخدمي لوحة المفاتيح */
.skip-link {
  position: absolute;
  inset-block-start: -100px;
  inset-inline-start: var(--sp-4);
  z-index: var(--z-toast);
  padding: var(--sp-3) var(--sp-5);
  background: var(--brand);
  color: var(--on-brand);
  border-radius: var(--r-md);
  font-weight: 700;
  transition: inset-block-start var(--dur-base) var(--ease-out);
}
.skip-link:focus-visible { inset-block-start: var(--sp-4); }

.stack     { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-sm  { display: flex; flex-direction: column; gap: var(--sp-2); }
.row       { display: flex; align-items: center; gap: var(--sp-3); }
.row-wrap  { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.spacer    { flex: 1 1 auto; }
.center    { display: flex; align-items: center; justify-content: center; }

.text-muted   { color: var(--text-2); }
.text-subtle  { color: var(--text-3); }
.text-sm      { font-size: var(--text-sm); }
.text-xs      { font-size: var(--text-xs); }
.text-center  { text-align: center; }
.text-start   { text-align: start; }
.text-end     { text-align: end; }
.nowrap       { white-space: nowrap; }
.truncate     { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.numeric      { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }
.ltr          { direction: ltr; unicode-bidi: isolate; }

.tone-ok      { color: var(--success); }
.tone-warning { color: var(--warning); }
.tone-caution { color: var(--accent); }
.tone-danger  { color: var(--danger); }
.tone-info    { color: var(--info); }
.tone-brand   { color: var(--brand); }

.mt-0 { margin-block-start: 0; }
.mt-2 { margin-block-start: var(--sp-2); }
.mt-4 { margin-block-start: var(--sp-4); }
.mt-6 { margin-block-start: var(--sp-6); }
.mb-2 { margin-block-end: var(--sp-2); }
.mb-4 { margin-block-end: var(--sp-4); }
.full { width: 100%; }

/* حركات مشتركة */
@keyframes fade-in     { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out    { from { opacity: 1; } to { opacity: 0; } }
@keyframes rise-in     { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes rise-in-sm  { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
@keyframes pop-in      { from { opacity: 0; transform: scale(0.96) translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes slide-start { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
@keyframes spin        { to { transform: rotate(360deg); } }
@keyframes shimmer     { to { background-position-x: -200%; } }
@keyframes soft-pulse  { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

.anim-rise { animation: rise-in var(--dur-slow) var(--ease-out) both; }
.anim-fade { animation: fade-in var(--dur-base) var(--ease-out) both; }

/* هيكل تحميل (Skeleton) */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
  color: transparent !important;
  user-select: none;
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
}
