/* ============================================================
   📐 التخطيط العام — نبراسي v6
   نهج Mobile-First مع دعم كامل لـ RTL عبر Logical Properties
   ============================================================ */

/* ─────────────────────── إعادة الضبط الأساسية ─────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  direction: rtl;
  min-height: 100vh;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* منع التمرير الأفقي العرضي */
  overflow-x: hidden;
}

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

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  /* إصلاح زر iOS */
  -webkit-appearance: none;
  appearance: none;
}

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

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.3;
}

/* ─────────────────────── مساعدات Utility ─────────────────────── */
.hidden   { display: none !important; }
.sr-only  {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ─────────────────────── حلقة التركيز (Focus Ring) ─────────────────────── */
:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
  border-radius: var(--radius-sm);
}

/* ─────────────────────── حاوية التطبيق ─────────────────────── */
.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column; /* جوال: عمودي */
  position: relative;
}

/* ─────────────────────── منطقة العرض الرئيسية ─────────────────────── */
.view {
  flex: 1;
  width: 100%;
  padding: var(--space-4);
  /* مسافة إضافية أسفل المحتوى لتجنب التداخل مع الشريط السفلي */
  padding-bottom: calc(var(--bottom-nav-height) + var(--space-6) + env(safe-area-inset-bottom, 0px));
  /* انتقال ظهور الصفحة */
  animation: viewFadeIn 0.3s ease both;
}

@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─────────────────────── رأس الصفحة الثابت ─────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: rgba(247, 244, 237, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-4);
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* يمتد بالكامل ضمن .app-shell */
}

/* ─────────────────────── شبكة المحتوى ─────────────────────── */
/* Mobile-First: عمود واحد ثم يتوسع */
.content-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  margin-top: var(--space-5);
}

@media (min-width: 560px) {
  .content-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 900px) {
  .content-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ─────────────────────── تخطيط التابلت والكمبيوتر ─────────────────────── */
@media (min-width: 768px) {
  .app-shell {
    flex-direction: row;
    align-items: stretch;
  }

  /* .app-header يمتد أفقياً فوق منطقة المحتوى فقط (بجانب الشريط الجانبي) */
  .app-header {
    /* إعادة تموضعه ضمن عمود المحتوى — يتم عبر flex-column على .main-column */
  }

  .view {
    padding: var(--space-5) var(--space-6);
    padding-bottom: var(--space-7);
  }
}

@media (min-width: 1024px) {
  .view {
    padding: var(--space-6) var(--space-7);
  }
}

/* ─────────────────────── عمود المحتوى الرئيسي ─────────────────────── */
/* يُلف الـ header + main view ضمن عمود واحد بجانب الشريط الجانبي */
.main-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* منع تجاوز المحتوى */
  overflow-x: hidden;
}

/* ─────────────────────── المنطقة المعيشية (Live Region) ─────────────────────── */
#nav-announcer {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

/* ─────────────────────── تسجيل الدخول ─────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background:
    radial-gradient(circle at 30% 20%, rgba(201,162,75,0.14), transparent 55%),
    radial-gradient(circle at 80% 80%, rgba(27,75,67,0.12),  transparent 55%),
    var(--color-bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
}

/* ─────────────────────── الشات / الرسائل ─────────────────────── */
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4) 0;
  max-height: 55vh;
  overflow-y: auto;
  scroll-behavior: smooth;
}
