/* ============================================================
   نظام التصميم الموحد - روافد
   Design System Tokens + Base Styles + Header/Footer
   ============================================================ */

/* ------------------------------------------------------------
   1. المتغيرات الثابتة (Design Tokens)
   ------------------------------------------------------------ */
:root,
[data-theme="light"] {
  /* الألوان الأساسية */
  --rawafid-primary: #1a2ac6;
  --rawafid-primary-dark: #14209e;
  --rawafid-primary-soft: #eff1ff;

  /* خلفيات */
  --rawafid-bg: #f4f6fb;
  --rawafid-surface: #ffffff;

  /* النصوص */
  --rawafid-text: #2d2d2d;
  --rawafid-text-muted: #666666;

  /* الحدود */
  --rawafid-border: #ccd1e0;

  /* حالات */
  --rawafid-success: #25d366;
  --rawafid-error: #e74c3c;
  --rawafid-accent: #ffcc00;

  /* أبيض صارم */
  --rawafid-white: #ffffff;

  /* الخطوط */
  --font-body: "IBM Plex Sans Arabic", "Thmanyah Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
  --font-heading: "Thmanyah Serif Text", "IBM Plex Sans Arabic", "Thmanyah Sans", system-ui, sans-serif;
  --font-mono: "Courier New", Consolas, "SF Mono", monospace;

  /* أوزان الخط */
  --font-light: 300;
  --font-regular: 400;
  --font-medium: 500;
  --font-bold: 700;
  --font-black: 900;

  /* مقاسات الخط */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem;

  /* التباعد */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* الزوايا */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* التخطيط */
  --nav-height: 70px;
  --container-max: 1100px;
  --container-wide: 1360px;
}

[data-theme="dark"] {
  --rawafid-primary: #7986cb;
  --rawafid-primary-dark: #5c6bc0;
  --rawafid-primary-soft: #282a36;

  --rawafid-bg: #121212;
  --rawafid-surface: #1e1e1e;

  --rawafid-text: #e0e0e0;
  --rawafid-text-muted: #a0a0a0;

  --rawafid-border: #333333;
}

/* ------------------------------------------------------------
   2. Reset بسيط وأساسيات
   ------------------------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--rawafid-text);
  background-color: var(--rawafid-bg);
  direction: rtl;
  min-height: 100vh;
  padding-top: var(--nav-height);
  -webkit-tap-highlight-color: transparent;
}

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

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

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

ul,
ol {
  list-style: none;
}

/* ------------------------------------------------------------
   3. تخطيط الصفحة
   ------------------------------------------------------------ */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-md);
}

.container--narrow {
  max-width: 800px;
}

.page-main {
  min-height: calc(100vh - var(--nav-height));
  padding-bottom: var(--space-xl);
}

.section {
  margin-top: var(--space-xl);
}

.section-title {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--rawafid-text);
  border-right: 4px solid var(--rawafid-primary);
  padding-right: var(--space-md);
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.section-title svg,
.section-title i {
  color: var(--rawafid-primary);
  width: 20px;
  height: 20px;
}

.page-header {
  margin-top: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.page-title {
  font-family: var(--font-heading);
  font-size: var(--text-3xl);
  font-weight: var(--font-black);
  color: var(--rawafid-primary);
  line-height: 1.4;
}

.page-subtitle {
  color: var(--rawafid-text-muted);
  margin-top: var(--space-xs);
}

/* ------------------------------------------------------------
   4. مكونات مساعدة
   ------------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--rawafid-primary-soft);
  color: var(--rawafid-primary);
  border: 1px solid var(--rawafid-border);
  border-radius: 50px;
  padding: 4px 12px;
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 50px;
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  border: 1px solid var(--rawafid-border);
  background: var(--rawafid-surface);
  color: var(--rawafid-primary);
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.btn:hover {
  background: var(--rawafid-primary);
  color: var(--rawafid-white);
  border-color: var(--rawafid-primary);
}

.btn--primary {
  background: var(--rawafid-primary);
  color: var(--rawafid-white);
  border-color: var(--rawafid-primary);
}

.btn--primary:hover {
  background: var(--rawafid-primary-dark);
  border-color: var(--rawafid-primary-dark);
}

.card {
  background: var(--rawafid-surface);
  border: 1px solid var(--rawafid-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}

/* ------------------------------------------------------------
   5. الترويسة (تصميم مسطح - خلفية بيضاء)
   ------------------------------------------------------------ */
.site-header {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 1000;
  height: var(--nav-height);
  background-color: var(--rawafid-surface);
  color: var(--rawafid-text);
  border-bottom: 1px solid var(--rawafid-border);
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  height: 100%;
  max-width: var(--container-wide);
  margin-inline: auto;
  padding: 0 var(--space-lg);
}

.logo {
  display: flex;
  align-items: center;
  height: 100%;
  flex-shrink: 0;
}

.logo img {
  height: 34px;
  width: auto;
}

/* الشعار: أبيض دائماً */
.logo-light {
  display: block;
}

.logo-dark {
  display: none;
}

/* ------------------------------------------------------------
   5ب. الترويسة الزرقاء في الوضع النهاري
   ------------------------------------------------------------ */
html:not([data-theme="dark"]) .site-header {
  background-color: var(--rawafid-primary);
  border-bottom-color: var(--rawafid-primary-dark);
  color: var(--rawafid-white);
}

html:not([data-theme="dark"]) .nav-links a {
  color: var(--rawafid-white);
}

html:not([data-theme="dark"]) .nav-links a:hover,
html:not([data-theme="dark"]) .nav-links a:focus-visible {
  color: var(--rawafid-white);
  background-color: rgba(255, 255, 255, 0.16);
}

html:not([data-theme="dark"]) .nav-links a.active {
  color: var(--rawafid-white);
  border-bottom-color: var(--rawafid-white);
}

html:not([data-theme="dark"]) .icon-btn {
  color: var(--rawafid-white);
}

html:not([data-theme="dark"]) .icon-btn:hover,
html:not([data-theme="dark"]) .icon-btn:focus-visible {
  color: var(--rawafid-white);
  background-color: rgba(255, 255, 255, 0.16);
}

html:not([data-theme="dark"]) .menu-toggle {
  color: var(--rawafid-white);
}

html:not([data-theme="dark"]) .menu-toggle:hover,
html:not([data-theme="dark"]) .menu-toggle:focus-visible,
html:not([data-theme="dark"]) .menu-toggle[aria-expanded="true"] {
  color: var(--rawafid-white);
  background-color: rgba(255, 255, 255, 0.16);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.nav-links a {
  display: block;
  color: var(--rawafid-text);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border-bottom: 2px solid transparent;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.nav-links a:hover,
.nav-links a:focus-visible {
  color: var(--rawafid-primary);
  background-color: var(--rawafid-primary-soft);
}

.nav-links a.active {
  color: var(--rawafid-primary);
  border-bottom-color: var(--rawafid-primary);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex-shrink: 0;
}

.icon-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  color: var(--rawafid-text-muted);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  background-color: var(--rawafid-primary-soft);
  color: var(--rawafid-primary);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* زر تبديل المظهر (أيقونة واحدة ظاهرة دائماً) */
.theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

/* زر القائمة في الجوال */
.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  color: var(--rawafid-text);
  border-radius: var(--radius-sm);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.menu-toggle:hover,
.menu-toggle:focus-visible {
  background-color: var(--rawafid-primary-soft);
  color: var(--rawafid-primary);
}

.menu-toggle svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-toggle .icon-close {
  display: none;
}

.menu-toggle[aria-expanded="true"] {
  color: var(--rawafid-primary);
  background-color: var(--rawafid-primary-soft);
}

.menu-toggle[aria-expanded="true"] .icon-menu {
  display: none;
}

.menu-toggle[aria-expanded="true"] .icon-close {
  display: block;
}

/* طبقة التعتيم */
.nav-overlay {
  position: fixed;
  top: var(--nav-height);
  right: 0;
  left: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

/* ------------------------------------------------------------
   6. التذييل (تصميم مسطح - شبكة روابط نظيفة)
   ------------------------------------------------------------ */
.site-footer {
  width: 100%;
  margin-top: var(--space-2xl);
  color: var(--rawafid-text);
  background-color: var(--rawafid-surface);
  border-top: 1px solid var(--rawafid-border);
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: var(--space-xl);
  padding: var(--space-xl) 0 var(--space-lg);
}

.footer-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-width: 0;
}

.footer-logo {
  width: 160px;
  height: auto;
  margin-bottom: var(--space-xs);
}

.footer-desc {
  font-size: var(--text-sm);
  color: var(--rawafid-text-muted);
  line-height: 1.8;
  max-width: 340px;
}

.footer-col-title {
  font-size: var(--text-sm);
  font-weight: var(--font-black);
  color: var(--rawafid-text);
  padding-bottom: var(--space-xs);
  border-bottom: 2px solid var(--rawafid-primary);
  margin-bottom: var(--space-xs);
  align-self: flex-start;
}

.footer-col a:not(.whatsapp-btn) {
  font-size: var(--text-sm);
  color: var(--rawafid-text-muted);
  padding: 3px 0;
  transition: color 0.2s ease;
}

.footer-col a:not(.whatsapp-btn):hover,
.footer-col a:not(.whatsapp-btn):focus-visible {
  color: var(--rawafid-primary);
}

.whatsapp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background-color: var(--rawafid-success);
  color: var(--rawafid-white);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  align-self: flex-start;
  transition: background-color 0.2s ease;
}

.whatsapp-btn:hover,
.whatsapp-btn:focus-visible {
  background-color: #1fae57;
}

.whatsapp-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.footer-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-sm);
  padding: var(--space-md) 0;
  border-top: 1px solid var(--rawafid-border);
  font-size: var(--text-xs);
  color: var(--rawafid-text-muted);
}

.footer-bottom a {
  color: var(--rawafid-text-muted);
  font-weight: var(--font-bold);
  transition: color 0.2s ease;
}

.footer-bottom a:hover,
.footer-bottom a:focus-visible {
  color: var(--rawafid-primary);
}

.footer-dev {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.footer-dev-logo {
  height: 26px;
  width: auto;
  object-fit: contain;
}

/* ------------------------------------------------------------
   7. تصميم الجوال (قائمة جانبية مسطحة)
   ------------------------------------------------------------ */
@media (max-width: 768px) {
  :root {
    --nav-height: 60px;
  }

  .navbar {
    padding: 0 var(--space-md);
  }

  .logo img {
    height: 30px;
  }

  .menu-toggle {
    display: flex;
  }

  .nav-actions .theme-toggle {
    display: none;
  }

  .nav-links {
    position: fixed;
    top: var(--nav-height);
    right: 0;
    width: min(78%, 290px);
    height: calc(100vh - var(--nav-height));
    height: calc(100dvh - var(--nav-height));
    background-color: var(--rawafid-surface);
    border-left: 1px solid var(--rawafid-border);
    flex-direction: column;
    align-items: stretch;
    padding: var(--space-md) var(--space-sm);
    gap: var(--space-xs);
    overflow-y: auto;
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 0.28s ease, visibility 0.28s ease;
    z-index: 999;
  }

  .nav-links.is-open {
    transform: translateX(0);
    visibility: visible;
  }

  /* الوضع النهاري: القائمة الجانبية الزرقاء بهوية الموقع */
  html:not([data-theme="dark"]) .nav-links {
    background-color: var(--rawafid-primary);
    border-left-color: var(--rawafid-primary-dark);
  }

  html:not([data-theme="dark"]) .nav-links li {
    border-bottom-color: rgba(255, 255, 255, 0.18);
  }

  .nav-links li {
    border-bottom: 1px solid var(--rawafid-border);
  }

  .nav-links li:last-child {
    border-bottom: none;
  }

  .nav-links a {
    padding: 14px 12px;
    font-size: var(--text-base);
    border-bottom: none;
    border-radius: var(--radius-sm);
  }

  .nav-links a.active {
    color: var(--rawafid-primary);
    background-color: var(--rawafid-primary-soft);
    border-radius: var(--radius-sm);
  }

  .nav-links a:hover,
  .nav-links a:focus-visible {
    color: var(--rawafid-primary);
    background-color: var(--rawafid-primary-soft);
  }

  /* داخل القائمة الجانبية: نص أبيض على خلفية زرقاء في الوضع النهاري */
  html:not([data-theme="dark"]) .nav-links a {
    color: var(--rawafid-white);
  }

  html:not([data-theme="dark"]) .nav-links a.active,
  html:not([data-theme="dark"]) .nav-links a:hover,
  html:not([data-theme="dark"]) .nav-links a:focus-visible {
    color: var(--rawafid-white);
    background-color: rgba(255, 255, 255, 0.16);
  }

  html:not([data-theme="dark"]) .nav-links a.active {
    border-bottom-color: transparent;
  }

  html:not([data-theme="dark"]) .nav-links .theme-toggle-mobile {
    color: var(--rawafid-white);
  }

  html:not([data-theme="dark"]) .nav-links .theme-toggle-mobile:hover,
  html:not([data-theme="dark"]) .nav-links .theme-toggle-mobile:focus-visible {
    color: var(--rawafid-white);
    background-color: rgba(255, 255, 255, 0.16);
  }

  .nav-links .theme-toggle-mobile {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: 14px 12px;
    color: var(--rawafid-text);
    font-family: inherit;
    font-size: var(--text-base);
    font-weight: var(--font-bold);
    border-radius: var(--radius-sm);
    transition: background-color 0.2s ease, color 0.2s ease;
  }

  .nav-links .theme-toggle-mobile:hover,
  .nav-links .theme-toggle-mobile:focus-visible {
    color: var(--rawafid-primary);
    background-color: var(--rawafid-primary-soft);
  }

  .theme-toggle-mobile .icon-sun {
    display: none;
  }

  [data-theme="dark"] .theme-toggle-mobile .icon-moon {
    display: none;
  }

  [data-theme="dark"] .theme-toggle-mobile .icon-sun {
    display: block;
  }

  .nav-overlay.is-visible {
    opacity: 1;
    visibility: visible;
  }

  .footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg) var(--space-md);
    padding: var(--space-lg) 0 var(--space-md);
  }

  .footer-grid > .footer-col:first-child {
    grid-column: 1 / -1;
  }

  .footer-desc {
    max-width: none;
  }

  .footer-bottom {
    flex-direction: column;
    text-align: center;
  }
}

@media (min-width: 769px) {
  .nav-links .theme-toggle-mobile {
    display: none;
  }
}

/* ------------------------------------------------------------
   8. إعدادات الطباعة
   ------------------------------------------------------------ */
@media print {
  .site-header,
  .site-footer,
  .menu-toggle,
  .nav-actions {
    display: none !important;
  }

  body {
    padding-top: 0;
    background: var(--rawafid-white);
    color: #000;
  }

  .page-main {
    min-height: auto;
  }
}
