/* ============================================================
   mobile.css — لایهٔ واکنش‌گرای موبایل (آخرین فایل CSS)
   چون بعد از style.css لود می‌شود، قانون «فایل آخر» اعمال می‌شود.
   ساختار: از بزرگ به کوچک — 1024 → 900 → 600 → 480
   ============================================================ */

@media (max-width: 1024px) {
  .container { padding: 0 20px; }
  .main-content { padding: 24px 20px; }
  .stat-row,
  [style*="grid-template-columns:repeat(4"] {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* ===== موبایل بزرگ / تبلت عمودی (900px) — شکست اصلی ===== */
@media (max-width: 900px) {
  .container { padding: 0 16px !important; }
  .section { padding: 36px 0 !important; }
  h1 { font-size: 24px !important; }
  h2 { font-size: 20px !important; }
  h3 { font-size: 17px !important; }

  /* ناوبار */
  .nav-links { display: none !important; }
  .nav-actions > .nav-ghost { display: none !important; }
  .mobile-menu-btn { display: flex !important; }
  .nav-btn { font-size: 13px !important; padding: 8px 12px !important; }
  .nav-logo img { height: 30px !important; }
  /* دکمه‌های داخل منوی کشویی باید دیده شوند */
  .mobile-drawer .nav-ghost,
  .mobile-drawer-inner .nav-ghost { display: block !important; }

  /* منو بالای همه‌چیز و تمام‌قد (وقتی به body منتقل شد) */
  .mobile-drawer.open { display: block !important; z-index: 99999 !important; }
  .mobile-drawer-inner { height: 100vh !important; max-width: 85% !important; }

  /* هیرو و جستجو */
  .hero { padding: 36px 0 44px !important; }
  .hero-title { font-size: 26px !important; line-height: 1.4 !important; }
  .hero-sub { font-size: 14px !important; }
  .search-box, .search-main-box { padding: 16px !important; margin: 0 !important; border-radius: 14px !important; }
  .search-main {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    align-items: stretch !important;
  }
  .search-main .sf-group { width: 100% !important; }
  .search-main .sf-select,
  .search-main .sf-input { width: 100% !important; box-sizing: border-box !important; }
  .btn-search, .btn-search-main { width: 100% !important; }

  /* dropdownهای جستجو وسط‌چین */
  .sf-select, .sf-input, select.form-ctrl, .search-box select, .search-main select {
    text-align: center !important; text-align-last: center !important; direction: rtl !important;
  }

  /* آمار هیرو */
  .hero-stats {
    display: grid !important; grid-template-columns: repeat(4, 1fr) !important;
    gap: 10px !important; padding: 24px 12px !important; border-top: none !important; text-align: center !important;
  }
  .hs-n { font-size: 22px !important; }
  .hs-l { font-size: 11px !important; line-height: 1.3 !important; }

  /* جستجوی پیشرفته */
  .adv-grid, .cascade-row { display: flex !important; flex-direction: column !important; gap: 10px !important; }
  .code-row { flex-direction: column !important; align-items: stretch !important; }

  /* گرید آگهی‌ها */
  .props-grid { grid-template-columns: 1fr 1fr !important; gap: 12px !important; }

  /* صفحهٔ جستجو */
  .search-layout { display: flex !important; flex-direction: column !important; }
  .filter-box { position: static !important; order: 2 !important; }

  /* جزئیات ملک */
  .detail-layout { display: flex !important; flex-direction: column !important; }
  .contact-sticky { position: static !important; }
  .gallery-main { height: 240px !important; }
  .d-specs { flex-wrap: wrap !important; gap: 8px !important; }

  /* فرم‌ها تک‌ستونه */
  .form-grid, .form-grid-2, .form-grid-3,
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns:repeat(2"],
  [style*="grid-template-columns:repeat(3"],
  [style*="grid-template-columns:1fr 1.4fr"],
  [style*="grid-template-columns:1.4fr 1fr"],
  [style*="grid-template-columns:1fr 300px"],
  [style*="grid-template-columns:1fr auto"] {
    display: flex !important; flex-direction: column !important; gap: 12px !important;
  }

  /* پنل: سایدبار کشویی */
  .sidebar {
    transform: translateX(100%) !important; transition: transform .3s ease !important;
    box-shadow: -4px 0 20px rgba(0,0,0,.2) !important;
  }
  .sidebar.open { transform: translateX(0) !important; }
  .main-content { margin-right: 0 !important; padding: 20px 16px !important; }
  .panel-sidebar { transform: translateX(100%) !important; transition: transform .3s ease !important; }
  .panel-sidebar.open { transform: translateX(0) !important; }
  .panel-main { margin-right: 0 !important; }
  .mobile-sidebar-btn, .mobile-panel-btn { display: flex !important; }
  .panel-header { flex-direction: column !important; gap: 12px !important; align-items: stretch !important; }
  .stat-row { grid-template-columns: 1fr 1fr !important; gap: 12px !important; }

  /* جدول‌های پنل: اسکرول افقی */
  .panel-content table, .main-content table, .card table {
    display: block !important; overflow-x: auto !important; white-space: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* کارت مشاوران */
  .advisors-grid { grid-template-columns: 1fr !important; }
  .advisor-card { flex-direction: column !important; }
  .advisor-photo { width: 100% !important; height: 200px !important; }

  /* لاگین */
  .login-page { display: block !important; min-height: 100vh !important; }
  .login-left { display: none !important; }
  .login-right { width: 100% !important; padding: 24px 16px !important; min-height: 100vh !important; display: flex !important; align-items: center !important; justify-content: center !important; }
  .login-card { width: 100% !important; max-width: 100% !important; }
  .tab-row { display: flex !important; flex-direction: row !important; gap: 8px !important; margin-bottom: 20px !important; }
  .tab-btn { flex: 1 !important; }

  /* کمیسیون */
  .type-grid { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
  .info-cards { display: flex !important; flex-direction: column !important; gap: 10px !important; }

  /* درباره ما / تماس */
  .contact-grid, .about-grid { display: flex !important; flex-direction: column !important; gap: 16px !important; }

  /* شعب / مناطق / علاقه‌مندی / اقامتگاه */
  .branches-grid { display: flex !important; flex-direction: column !important; gap: 14px !important; }
  .tree-regions { flex-wrap: wrap !important; }
  .wishlist-grid, .fav-grid { grid-template-columns: 1fr 1fr !important; }
  .acc-grid, #acc-form { display: flex !important; flex-direction: column !important; }

  /* فوتر */
  .footer-inner, .footer-grid { display: flex !important; flex-direction: column !important; gap: 20px !important; padding: 0 16px !important; }
  .footer-bottom { flex-direction: column !important; text-align: center !important; gap: 8px !important; }

  /* بنر تبلیغاتی */
  #ad-banner-wrap, .ad-banner-inner { flex-direction: column !important; align-items: flex-start !important; gap: 14px !important; padding: 16px !important; }
}

/* ===== موبایل متوسط (600px) ===== */
@media (max-width: 600px) {
  .props-grid { grid-template-columns: 1fr !important; }
  .wishlist-grid, .fav-grid { grid-template-columns: 1fr !important; }
  [style*="grid-template-columns:repeat(3"] { grid-template-columns: 1fr !important; }
  .hero-title { font-size: 23px !important; }
  .section { padding: 28px 0 !important; }
}

/* ===== موبایل کوچک (480px) ===== */
@media (max-width: 480px) {
  .container { padding: 0 12px !important; }
  .hero-stats { gap: 6px !important; padding: 20px 6px !important; }
  .hs-n { font-size: 19px !important; }
  .hs-l { font-size: 10px !important; }
  .stat-row, .perf-grid { grid-template-columns: 1fr 1fr !important; }
  .hero-title { font-size: 22px !important; }
  h1 { font-size: 22px !important; }
  .type-grid { grid-template-columns: 1fr 1fr !important; }
  .gallery-main { height: 200px !important; }
}

/* ===== لاگین OTP (500px) ===== */
@media (max-width: 500px) {
  .method-row { flex-direction: row !important; gap: 4px !important; }
  .method-btn { font-size: 12px !important; padding: 7px 6px !important; gap: 3px !important; }
  .otp-input { font-size: 18px !important; letter-spacing: .2em !important; }
  .tab-row { gap: 4px !important; }
  .tab-btn { font-size: 13px !important; padding: 9px 6px !important; }
}

/* ============================================================
   تقویت پنل‌ها در موبایل — مرحلهٔ ۱ (مشاور + مشترکِ همهٔ پنل‌ها)
   فقط CSS؛ هیچ HTMLی تغییر نمی‌کند. کاملاً برگشت‌پذیر.
   ============================================================ */
@media (max-width: 900px) {

  /* ── چیدمان‌های دوستونه/سه‌ستونهٔ پنل → تک‌ستون ──
     (داشبورد مشاور و مدیر از .grid-2 / .grid-3 استفاده می‌کنند) */
  .grid-2, .grid-3 {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }

  /* ── کارت‌های آمار پنل (مشاور: .stat-row / مدیر: .stat-cards) ── */
  .stat-row, .stat-cards {
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
  }
  .stat-mini, .stat-card {
    padding: 14px 16px !important;
  }
  .smv, .stat-val { font-size: 20px !important; }
  .stat-ico, .smi { width: 40px !important; height: 40px !important; font-size: 18px !important; }

  /* ── صفحهٔ گفتگوهای مشاور: دو ستون → روی‌هم (تک‌ستون) ── */
  .chat-wrap {
    grid-template-columns: 1fr !important;
    height: auto !important;
    min-height: 0 !important;
    gap: 14px !important;
  }
  .thread-list {
    max-height: 38vh !important;
    min-height: 200px !important;
  }
  .chat-area {
    height: 72vh !important;
    min-height: 440px !important;
  }

  /* ── جدول‌های پنل: اسکرول افقی روان داخل ظرف ──
     (به‌جای فشرده‌شدن، با انگشت چپ‌وراست اسکرول می‌شوند) */
  .tbl-scroll {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  .tbl-scroll table, .card table.table {
    min-width: 560px !important;
  }

  /* ── دکمه‌های اکشن داخل ردیف‌ها قابل‌لمس‌تر ── */
  .pend-actions .btn-xs, .acc-act { min-height: 34px !important; }

  /* ── عنوان پنل کمی کوچک‌تر تا در موبایل جا شود ── */
  .panel-title { font-size: 19px !important; }
}

/* موبایل کوچک: کارت‌های آمار تک‌ستون اگر خیلی تنگ شد */
@media (max-width: 380px) {
  .stat-row, .stat-cards { grid-template-columns: 1fr !important; }
}

/* ============================================================
   رفع «فقط در حالت چرخیده درست کار می‌کند» در پنل‌ها
   علت: سایدبار کشویی (off-canvas) و عناصر پهن، در حالت عمودی
   یک سرریز افقی می‌سازند که صفحه را جابه‌جا/پهن می‌کند.
   راه‌حل امن: جلوگیری از اسکرول افقیِ ناخواسته + مهارِ سایدبار.
   ============================================================ */
@media (max-width: 900px) {
  /* جلوی اسکرول/جابه‌جایی افقی کل صفحه را می‌گیرد (off-canvas را مهار می‌کند) */
  html { overflow-x: hidden !important; }

  /* اطمینان از اینکه سایدبارِ بسته کاملاً بیرون است و فضای افقی اشغال نمی‌کند */
  .sidebar {
    transform: translateX(100%) !important;
    width: 240px !important;
    max-width: 85vw !important;
  }
  .sidebar.open { transform: translateX(0) !important; }

  /* محتوای اصلی هرگز از عرض صفحه بیرون نزند */
  .main-content {
    margin-right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* هر عنصر شناورِ پایین‌چپ/راست (مثل پاپ‌آپ چت) داخل صفحه بماند */
  .chat-fab, .chat-panel { max-width: calc(100vw - 24px) !important; }
}

/* ============================================================
   رفع قطعیِ سرریز افقی پنل‌ها (داشبورد مشاور/مدیر و ...)
   علت ریشه‌ای: body با display:flex + main-content با flex:1
   و padding، عرض را از صفحه بزرگ‌تر می‌کرد و محتوا به چپ می‌زد.
   ============================================================ */
@media (max-width: 900px) {
  /* body دیگر فلکس نباشد تا main-content تمام‌عرض و مستقل شود */
  body {
    display: block !important;
    width: 100% !important;
    max-width: 100vw !important;
  }

  /* main-content کاملاً تمام‌عرض، با احتساب padding داخل عرض */
  .main-content {
    margin-right: 0 !important;
    margin-left: 0 !important;
    flex: none !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    padding: 20px 16px !important;
  }

  /* همهٔ کارت‌ها و گریدهای داخل پنل داخل عرض بمانند */
  .main-content .card,
  .main-content .stat-mini,
  .main-content .stat-card,
  .main-content .quote-box {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
}

/* ============================================================
   فاز ۱ — Design System ریسپانسیو سراسری (تکمیلی)
   افزوده روی نسخهٔ فعلی؛ فقط CSS، بدون تغییر HTML/منطق.
   سراسری: چون کلاس‌ها بین فرانت و همهٔ پنل‌ها مشترک‌اند.
   ============================================================ */

/* ── ۱) هدف‌های لمسی و ورودی‌ها (همهٔ صفحات) ── */
@media (max-width: 768px) {
  /* دکمه‌های اصلی/فرمی و لینک‌های دکمه‌ای: حداقل ارتفاع لمس */
  .btn, .btn-primary, .btn-outline, .btn-block, .btn-lg, .nav-btn,
  .tab-btn, .method-btn, .fc, .rem-btn, .sm-btn, .bl-view, .bl-cmp,
  input[type="submit"], input[type="button"], a.btn {
    min-height: 44px !important;
  }
  /* ورودی‌ها: راحت‌لمس + font-size 16px برای جلوگیری از زوم خودکار iOS */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select, textarea, .sf-input, .sf-select, .form-control, .form-ctrl {
    min-height: 44px !important;
    font-size: 16px !important;
  }
  textarea { min-height: 90px !important; }
  /* هیچ رسانه‌ای از عرض صفحه بیرون نزند */
  img, video, canvas, iframe { max-width: 100% !important; height: auto; }
}

/* ── ۲) مودال‌ها → Bottom-Sheet در موبایل ── */
@media (max-width: 640px) {
  .sm-overlay { align-items: flex-end !important; padding: 0 !important; }
  .sm-box {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 18px 18px 0 0 !important;
    max-height: 92vh !important;
    display: flex !important;
    flex-direction: column !important;
    animation: smSheet .28s cubic-bezier(.2,.7,.3,1) !important;
  }
  .sm-box::before {   /* دستگیرهٔ بالای شیت */
    content: ''; width: 40px; height: 4px; border-radius: 3px;
    background: #d8d8dc; margin: 9px auto 2px; flex-shrink: 0;
  }
  .sm-body { max-height: none !important; flex: 1 1 auto !important; overflow-y: auto !important; }
  @keyframes smSheet { from { transform: translateY(100%); } to { transform: none; } }
}

/* ── ۳) نمودارها و رسانه‌های پهن: مهار سرریز ── */
@media (max-width: 900px) {
  svg:not(.ico):not(.smi):not(.fld-ico) { max-width: 100% !important; }
  [class*="chart"], .chart-wrap, .chart-scroll { max-width: 100% !important; overflow-x: auto !important; }
}

/* ── ۴) ریزتنظیم تیتر/فاصله در بریک‌پوینت‌های کوچک ── */
@media (max-width: 640px) {
  .panel-title { font-size: 18px !important; }
  .sec-title, .card-title { font-size: 15px !important; }
  .card { padding: 16px !important; }
}
@media (max-width: 414px) {
  .container { padding: 0 12px !important; }
  h1 { font-size: 21px !important; }
}
@media (max-width: 390px) {
  .stat-row, .stat-cards, .grid-2, .grid-3 { gap: 10px !important; }
}
@media (max-width: 360px) {
  .props-grid, .wishlist-grid, .fav-grid,
  .stat-row, .stat-cards { grid-template-columns: 1fr !important; }
}
