/**
 * responsive.css — استجابة وتوافق الشاشات لمنصة لَقْطة
 */

/* ==========================================================================
   1. تحسينات الهواتف والشاشات الصغيرة (<= 767px)
   ========================================================================== */
@media (max-width: 767px) {
  :root {
    --header-height: 60px;
  }

  .container {
    padding-inline: var(--space-sm);
  }

  .header-brand .header-logo {
    height: 32px;
  }

  .header-location-btn {
    display: none; /* يتم دمج اختيار المحافظة في شريط البحث وقائمة الهاتف */
  }

  .header-actions .btn-post-ad {
    display: none; /* يتوفر كزر مركزي مميز في شريط التنقل السفلي */
  }

  .finder-section {
    padding-block: var(--space-md);
  }

  .finder-title {
    font-size: var(--text-xl);
  }

  .finder-subtitle {
    font-size: var(--text-xs);
  }

  .finder-card {
    border-radius: var(--radius-md);
  }

  .finder-group {
    padding: var(--space-xs) var(--space-sm);
    border-bottom: 1px solid var(--color-border);
  }

  .finder-group:last-of-type {
    border-bottom: none;
  }

  .finder-submit-btn {
    width: 100%;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
  }

  /* تفاصيل الإعلان: شريط التواصل الثابت على الهاتف */
  .mobile-contact-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: var(--space-xs) var(--space-md);
    padding-bottom: calc(var(--space-xs) + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 16px rgba(34, 42, 39, 0.08);
    z-index: 60;
    gap: var(--space-xs);
  }

  .has-mobile-contact-bar {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* شبكة الإعلانات على الهواتف */
  .listings-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-sm);
  }

  /* على الهواتف متوسطة الحجم (390px+) نجعلها بطاقات مزدوجة مريحة */
  @media (min-width: 440px) {
    .listings-grid {
      grid-template-columns: repeat(2, 1fr);
      gap: var(--space-xs);
    }
  }

  /* المحادثات على الهاتف: إظهار إما القائمة أو المحادثة الحالية */
  .chat-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height) - var(--mobile-nav-height));
  }

  .chat-layout.in-thread .chat-sidebar {
    display: none;
  }

  .chat-layout:not(.in-thread) .chat-main {
    display: none;
  }

  /* صفحات الإدارة والحساب */
  .account-layout {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
  }
}

/* ==========================================================================
   2. الأجهزة اللوحية والمكتبية (>= 768px)
   ========================================================================== */
@media (min-width: 768px) {
  .mobile-contact-bar {
    display: none !important;
  }

  .listings-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: var(--space-xl);
    align-items: start;
  }

  .listings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
  }

  .chat-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    overflow: hidden;
    height: 700px;
    background: var(--color-surface);
  }

  .chat-sidebar {
    border-inline-end: 1px solid var(--color-border);
  }

  .listing-detail-layout {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: var(--space-xl);
    align-items: start;
  }
}

/* ==========================================================================
   3. الشاشات الكبيرة والمكتبية الواسعة (>= 1024px)
   ========================================================================== */
@media (min-width: 1024px) {
  .listings-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .categories-grid {
    grid-template-columns: repeat(8, 1fr);
  }
}

@media (min-width: 1280px) {
  .listings-grid.no-sidebar {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ==========================================================================
   4. حماية شاملة من التمرير الأفقي غير المقصود
   ========================================================================== */
body, html {
  max-width: 100vw;
  overflow-x: hidden;
}

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

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
