/* ============================================================
   البيت السعودي — Design System v1
   النظام التصميمي الرسمي للسلسلة
   ============================================================

   التوثيق: /design/01-design-system.md
   المراجع: /design/00-research-references.md
   الفلسفة: «صفحة مكتوبة بأناة في مجلس نجدي عند الفجر»

   هذا الملف هو المصدر الوحيد للتغيير البصري.
   تعديل لون/خط هنا = ينعكس في كل صفحات السلسلة.

   ============================================================ */

/* ============================================================
   1. COLOR SYSTEM
   لوحة «طين الديريّة» — 3 مستويات لكل لون
   ============================================================ */

:root {
  /* —— Sand (الرمل النجدي) —————————— backgrounds & dividers */
  --sand-50:   #FAF6EE;
  --sand-100:  #F5EFE4;
  --sand-200:  #EBE2D0;
  --sand-300:  #D4C4A0;
  --sand-400:  #B8A878;

  /* —— Clay (الطين) ————————————————— primary accent */
  --clay-300:  #C19078;
  --clay-500:  #A87C5C;
  --clay-700:  #8B5A3C;
  --clay-900:  #6B4A33;

  /* —— Olive (الزيتوني) ————————————— secondary accent */
  --olive-200: #E4E9D5;
  --olive-400: #A8B88A;
  --olive-600: #7A8C5A;
  --olive-800: #5C7548;

  /* —— Gold (الذهبي الديريّة) ———————— special accents */
  --gold-400:  #D4B570;
  --gold-600:  #B8924A;

  /* —— Ink (الحبر) ——————————————————— typography */
  --ink-900:   #2C2519;
  --ink-700:   #5C5043;
  --ink-500:   #8A7A5A;

  /* —— Functional ——————————————————— */
  --white:     #FAF7F0;
  --red-soft:  #C95151;
  --red-pale:  #F8DEDE;

  /* —— Semantic aliases ————————————— use these in code */
  --bg-page:        var(--sand-100);
  --bg-card:        var(--white);
  --bg-soft:        var(--sand-200);
  --bg-elevated:    var(--sand-50);
  --text-strong:    var(--clay-900);
  --text-body:      var(--ink-900);
  --text-muted:     var(--ink-700);
  --text-faded:     var(--ink-500);
  --accent-primary: var(--clay-500);
  --accent-deep:    var(--clay-900);
  --accent-secondary: var(--olive-600);
  --accent-gold:    var(--gold-600);
  --border-soft:    var(--sand-200);
  --border-deep:    var(--sand-300);

  /* —— Reflective palette «فجر الرياض» —— for tafkir/result screens */
  --fajr-bg:   #FAF4E8;
  --fajr-mid:  #C9B596;
  --fajr-warm: #D9A88C;
  --fajr-cool: #7892A8;
  --fajr-deep: #4A3826;

  /* —— Backward-compatible aliases (للكود القديم في year1, bayt) —— */
  --cream:        #F5EFE4;
  --cream-deep:   #EBE2D0;
  --sand:         #D4C4A0;
  --clay:         #A87C5C;
  --clay-deep:    #6B4A33;
  --olive:        #7A8C5A;
  --olive-light:  #A8B88A;
  --olive-pale:   #E4E9D5;
  --ink:          #2C2519;
  --ink-soft:     #5C5043;
  --gold:         #B8924A;
  --radius:       18px;
}

/* ============================================================
   2. TYPOGRAPHY
   ============================================================ */

:root {
  --font-display: 'Reem Kufi', 'IBM Plex Sans Arabic', sans-serif;
  --font-sans:    'IBM Plex Sans Arabic', 'Tajawal', sans-serif;
  --font-serif:   'Amiri', 'Reem Kufi', serif;
  --font-mono:    'Inter', 'JetBrains Mono', monospace;

  /* Type scale */
  --text-xs:    13px;
  --text-sm:    15px;
  --text-base:  16px;
  --text-lg:    18px;
  --text-xl:    22px;
  --text-2xl:   28px;
  --text-3xl:   36px;
  --text-4xl:   44px;

  /* Line heights */
  --leading-tight:  1.25;
  --leading-snug:   1.4;
  --leading-base:   1.7;
  --leading-relaxed: 1.85;

  /* Latin numbers in RTL context */
  --num-features: "lnum";
}

/* ============================================================
   3. SPACING (4px grid)
   ============================================================ */

:root {
  --space-0:  0;
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-7:  32px;
  --space-8:  40px;
  --space-9:  56px;
  --space-10: 72px;
}

/* ============================================================
   4. RADII
   ============================================================ */

:root {
  --radius-xs:   6px;
  --radius-sm:   10px;
  --radius-md:   14px;
  --radius-lg:   18px;
  --radius-xl:   22px;
  --radius-pill: 999px;
}

/* ============================================================
   5. SHADOWS (محدودة opacity ≤ 0.14)
   ============================================================ */

:root {
  --shadow-sm:    0 2px 8px rgba(107, 74, 51, 0.06);
  --shadow-md:    0 8px 24px rgba(107, 74, 51, 0.10);
  --shadow-lg:    0 16px 40px rgba(107, 74, 51, 0.14);
  --shadow-hover: 0 12px 32px rgba(107, 74, 51, 0.12);
}

/* ============================================================
   6. MOTION
   ============================================================ */

:root {
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s ease;
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================
   7. RESET & GLOBALS
   ============================================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-base);
  color: var(--text-body);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;

  /* النقش الخلفي - Architect pattern من Hero Patterns بـopacity ضئيلة */
  background-image:
    radial-gradient(ellipse at top left, rgba(168, 124, 92, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(122, 140, 90, 0.05) 0%, transparent 50%);
  background-attachment: fixed;
}

/* Latin numerals in RTL — مهم لاختبارنا */
.num,
.counter-value,
.meta-item,
time,
[data-num] {
  font-feature-settings: var(--num-features);
  unicode-bidi: plaintext;
}

/* Serif & Display font helpers */
.font-display { font-family: var(--font-display); }
.font-serif   { font-family: var(--font-serif); }
.font-mono    { font-family: var(--font-mono); font-feature-settings: var(--num-features); }

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--text-strong);
  font-weight: 700;
  line-height: var(--leading-tight);
  letter-spacing: -0.3px;
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); font-family: var(--font-sans); /* h3 smaller, use sans */ }
h4 { font-size: var(--text-lg); font-family: var(--font-sans); }

a { color: var(--accent-primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--accent-deep); }

/* Focus rings */
:focus-visible {
  outline: 2px solid var(--clay-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================================
   8. COMPONENT LIBRARY
   ============================================================ */

/* ——— Container ——— */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}
.container-wide   { max-width: 1100px; }
.container-narrow { max-width: 560px; }

/* ——— Card ——— */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base), transform var(--transition-base);
}
.card-hover:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

/* ——— Button ——— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--transition-base);
  text-decoration: none;
  line-height: 1;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: var(--clay-900);
  color: var(--white);
}
.btn-primary:hover {
  background: var(--clay-700);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--clay-900);
  border: 1.5px solid var(--clay-500);
}
.btn-secondary:hover {
  background: var(--sand-200);
  border-color: var(--clay-900);
}

.btn-ghost {
  background: transparent;
  color: var(--clay-900);
  padding: 8px 14px;
}
.btn-ghost:hover { background: var(--sand-200); }

.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* ——— Badge ——— */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--sand-200);
  color: var(--clay-900);
  line-height: 1;
}
.badge-olive { background: var(--olive-200); color: var(--olive-800); }
.badge-gold  { background: rgba(184, 146, 74, 0.15); color: var(--gold-600); }
.badge-warn  { background: var(--red-pale); color: var(--red-soft); }

/* ——— Pill (meta info) ——— */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  color: var(--text-muted);
}
.pill svg { width: 12px; height: 12px; }

/* ——— Quote Block (آيات وأحاديث) ——— */
.quote-block {
  background: var(--sand-50);
  padding: var(--space-4) var(--space-5);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  line-height: var(--leading-relaxed);
  color: var(--text-strong);
  margin: var(--space-4) 0;
}
.quote-block.is-ayah    { border-right: 3px solid var(--gold-600); }
.quote-block.is-hadith  { border-right: 3px solid var(--olive-600); }
.quote-block .quote-source {
  display: block;
  margin-top: var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 500;
}

/* ——— Input ——— */
.input {
  display: block;
  width: 100%;
  background: var(--bg-card);
  border: 1.5px solid var(--border-deep);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text-body);
  transition: all var(--transition-base);
}
.input:focus {
  outline: none;
  border-color: var(--clay-500);
  box-shadow: var(--shadow-sm);
}

/* ——— Modal ——— */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(44, 37, 25, 0.55);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  animation: fade-in var(--transition-base);
}
.modal {
  background: var(--sand-100);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slide-up var(--transition-slow);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   9. الفرجة النجدية (Najdi Parapet Divider)
   بديل عن <hr> — silhouette مبسط لشرفات البيوت النجدية
   ============================================================ */

.najdi-divider {
  display: block;
  height: 18px;
  margin: var(--space-7) auto;
  max-width: 200px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 18' fill='none'><path d='M0 17 L0 11 L10 11 L15 4 L20 11 L40 11 L45 4 L50 11 L70 11 L75 4 L80 11 L100 11 L105 0 L110 11 L130 11 L135 4 L140 11 L160 11 L165 4 L170 11 L180 11 L190 11 L200 11 L200 17 Z' fill='%23D4C4A0'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  opacity: 0.7;
}

.najdi-divider-sm {
  max-width: 120px;
  height: 14px;
  margin: var(--space-5) auto;
}

/* ============================================================
   10. شريط الفوتر الموحّد
   ============================================================ */

.site-footer-strip {
  text-align: center;
  padding: var(--space-5) var(--space-4);
  font-size: var(--text-xs);
  color: var(--text-muted);
  border-top: 1px solid var(--border-soft);
  margin-top: var(--space-7);
}
.site-footer-strip a {
  color: var(--accent-primary);
  margin: 0 var(--space-2);
  transition: color var(--transition-fast);
}
.site-footer-strip a:hover { color: var(--clay-900); text-decoration: underline; }
.site-footer-strip .sep { color: var(--sand-300); margin: 0 var(--space-1); }

/* ============================================================
   11. RESPONSIVE
   ============================================================ */

@media (max-width: 480px) {
  body { font-size: var(--text-sm); }
  h1 { font-size: var(--text-2xl); }
  h2 { font-size: var(--text-xl); }
  .container { padding: 0 var(--space-3); }
  .card { padding: var(--space-4); }
  .modal { padding: var(--space-5); border-radius: var(--radius-lg); }
}

@media (min-width: 1024px) {
  body { font-size: var(--text-base); }
  h1 { font-size: var(--text-4xl); }
}

/* ============================================================
   12. PRINT (PDF reports)
   ============================================================ */

@media print {
  @page {
    size: A4;
    margin: 18mm 14mm 22mm;
    @bottom-center {
      content: "البيت السعودي · صفحة " counter(page) " من " counter(pages);
      font-family: 'IBM Plex Sans Arabic', sans-serif;
      font-size: 9pt;
      color: #8a7a5a;
      padding-top: 4mm;
      border-top: 0.5pt solid #d4c4a0;
    }
  }
  html, body { background: #fff !important; }
  body {
    font-size: 11pt;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    background-image: none;
  }
  .no-print,
  .btn-back,
  .nav-bar,
  .result-cta-bar,
  .app-footer,
  .site-footer-strip { display: none !important; }
  .card {
    box-shadow: none !important;
    border: 0.7pt solid #e0d5bc !important;
    page-break-inside: avoid;
  }
  .najdi-divider { opacity: 0.5; }
  a[href]:after { content: ""; }
  .quote-block { page-break-inside: avoid; }
}
