/**
 * mobile-polish.css — جلای تجربه موبایل
 * v1 — بعد از app.css لود شود
 */

:root {
  --mp-nav-h: 64px;
  --mp-nav-total: calc(var(--mp-nav-h) + env(safe-area-inset-bottom, 0px));
  --mp-tap: 44px;
}

/* ——— پایه: اسکرول و عرض ——— */
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  overflow-x: clip;
  overflow-y: auto !important;
  min-height: 100%;
  min-height: 100dvh;
  /* فضای منوی پایین — همیشه روی موبایل */
}
@media (max-width: 899px) {
  body {
    padding-bottom: calc(var(--mp-nav-total) + 12px) !important;
  }
  body.nav-open {
    overflow: hidden !important;
    /* فقط وقتی منو باز است قفل */
  }
  /* جلوگیری از قطع اسکرول توسط لایه‌های قدیمی */
  .site-main,
  main,
  .main-content,
  .page-wrap,
  .container {
    overflow: visible;
    max-width: 100%;
  }
}

/* ——— منوی پایین ——— */
@media (max-width: 899px) {
  .bottom-nav {
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    display: flex !important;
    height: auto !important;
    min-height: var(--mp-nav-total);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
  .bottom-nav a {
    min-height: var(--mp-tap);
    min-width: 0;
    flex: 1;
    padding: 8px 4px;
    font-size: 0.65rem;
    gap: 4px;
  }
  .bottom-nav a .ico {
    font-size: 1.2rem;
  }
  .bottom-nav a.primary-action {
    transform: translateY(-6px);
    box-shadow: 0 6px 16px rgba(13, 148, 136, 0.35);
  }
}

/* ——— نوار تماس/چت روی صفحه آگهی (بالای منوی پایین) ——— */
@media (max-width: 899px) {
  .asy-bottom-bar,
  .listing-sticky-bar,
  .asy-sticky-actions,
  .asy-contact-bar {
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: var(--mp-nav-total) !important;
    z-index: 85;
    margin: 0 !important;
    padding: 10px 12px !important;
    padding-bottom: 10px !important;
    background: var(--card, #fff);
    border-top: 1px solid var(--border, #e2e8f0);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
    display: flex;
    gap: 8px;
    align-items: center;
  }
  .asy-bottom-bar .btn,
  .listing-sticky-bar .btn,
  .asy-contact-bar .btn {
    flex: 1;
    min-height: var(--mp-tap);
    margin: 0;
  }
  body.has-listing-sticky .site-main,
  body.has-listing-sticky main,
  body.has-listing-sticky .main-content,
  body.has-listing-sticky .page-wrap,
  body.has-listing-sticky .asy-detail {
    padding-bottom: calc(var(--mp-nav-total) + 72px) !important;
  }
}

/* ——— چت / پیام‌ها ——— */
@media (max-width: 899px) {
  .chat-shell,
  .msg-thread-wrap,
  .messages-layout {
    padding-bottom: calc(var(--mp-nav-total) + 8px);
  }
  .chat-input-bar,
  .msg-composer,
  .conversation-compose {
    position: sticky;
    bottom: 0;
    z-index: 20;
    background: var(--card, #fff);
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border, #e2e8f0);
  }
  .chat-box,
  .msg-list {
    max-height: none;
    min-height: 40vh;
  }
}

/* ——— فرم‌ها و دکمه‌های ذخیره ——— */
@media (max-width: 899px) {
  .form-sticky-bar,
  .fw-actions,
  .sr-actions {
    position: sticky;
    bottom: calc(var(--mp-nav-total) + 4px);
    z-index: 40;
    background: var(--card, #fff);
    padding: 10px 12px;
    border-top: 1px solid var(--border, #e2e8f0);
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.05);
  }
  .form-sticky-bar .btn,
  .fw-actions .btn,
  .sr-actions .btn,
  button[type="submit"].btn {
    min-height: var(--mp-tap);
  }
  input.form-control,
  select.form-control,
  textarea.form-control {
    font-size: 16px !important; /* جلوگیری از زوم iOS */
    min-height: var(--mp-tap);
  }
  textarea.form-control {
    min-height: 96px;
  }
}

/* ——— کارت آگهی / فید ——— */
@media (max-width: 899px) {
  .asy-ad-card,
  .asy-feed .card {
    border-radius: 14px;
  }
  .asy-ads-list,
  .asy-feed {
    gap: 10px;
  }
  /* دو ستون فشرده در موبایل عریض */
  .asy-feed.grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ——— هدر موبایل ——— */
@media (max-width: 899px) {
  .header-mobile,
  .asy-topbar {
    padding-left: max(10px, env(safe-area-inset-left, 0px));
    padding-right: max(10px, env(safe-area-inset-right, 0px));
  }
  .hm-search-wrap input,
  .asy-search input {
    font-size: 16px !important;
    min-height: 40px;
  }
}

/* ——— اشتراک / شیت‌ها ——— */
@media (max-width: 899px) {
  .share-sheet-inner {
    margin-bottom: var(--mp-nav-total);
    max-height: min(70vh, 480px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ——— لمس: حذف تأخیر و هایلایت ——— */
@media (max-width: 899px) {
  a, button, .btn, .bottom-nav a {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
}

/* دسکتاپ: این فایل دخالت نکند روی منوی پایین */
@media (min-width: 900px) {
  .bottom-nav {
    /* قوانین اصلی app.css */
  }
}


/* ========== iOS / Safari compatibility ========== */
@supports (padding: max(0px)) {
  :root {
    --mp-nav-total: calc(
      var(--mp-nav-h) + max(
        env(safe-area-inset-bottom, 0px),
        constant(safe-area-inset-bottom)
      )
    );
  }
}

/* iOS قدیمی بدون dvh */
@supports not (height: 100dvh) {
  body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
  }
}

@media (max-width: 899px) {
  /* اسکرول نرم در شیت‌ها و لیست چت */
  .share-sheet-inner,
  .msg-list,
  .chat-box,
  .asy-drawer-panel,
  .mobile-nav-sheet {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* sticky با پیشوند وب‌کیت */
  .form-sticky-bar,
  .fw-actions,
  .sr-actions,
  .chat-input-bar,
  .msg-composer {
    position: -webkit-sticky;
    position: sticky;
  }

  /* fixed + safe area روی نوار پایین */
  .bottom-nav {
    padding-bottom: max(
      env(safe-area-inset-bottom, 0px),
      constant(safe-area-inset-bottom)
    );
  }

  /* جلوگیری از کشیدن کل صفحه هنگام اسکرول داخلی */
  .bottom-nav,
  .asy-bottom-bar,
  .listing-sticky-bar {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }

  /* input number بدون اسپینر مشکل‌ساز در بعضی iOS */
  input[type="number"] {
    -moz-appearance: textfield;
  }

  /* لینک tel/SMS */
  a[href^="tel:"],
  a[href^="sms:"] {
    cursor: pointer;
  }
}

/* کاهش حرکت برای کاربرانی که درخواست کرده‌اند */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  .bottom-nav a.primary-action {
    transform: none;
  }
}

/* ========== صفحه اول: شیت دسته زیبا ========== */
.cat-sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.cat-sheet[hidden] {
  display: none !important;
}
.cat-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.cat-sheet-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  max-height: min(78vh, 640px);
  background: var(--card, #fff);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  animation: catSheetUp 0.28s ease;
}
@keyframes catSheetUp {
  from { transform: translateY(100%); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}
.cat-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--border, #e2e8f0);
}
.cat-sheet-head strong {
  font-size: 1.05rem;
}
.cat-sheet-head button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border, #e2e8f0);
  background: var(--bg-2, #f1f5f9);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--text, #0f172a);
}
.cat-sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px 20px;
  flex: 1;
}
.cat-sheet-search-wrap {
  margin-bottom: 10px;
}
.cat-sheet-search-wrap input {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border, #e2e8f0);
  background: var(--bg-2, #f8fafc);
  padding: 10px 14px;
  font-size: 16px;
  font-family: inherit;
  box-sizing: border-box;
}
.cat-sheet-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: right;
  padding: 12px 10px;
  margin: 0 0 4px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  box-sizing: border-box;
}
.cat-sheet-item:hover,
.cat-sheet-item:active {
  background: var(--bg-2, #f1f5f9);
}
.cat-sheet-item .csi-ico {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--bg-2, #f1f5f9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.cat-sheet-item .csi-name {
  flex: 1;
  min-width: 0;
  line-height: 1.35;
  font-weight: 600;
}
.cat-sheet-item .csi-name small {
  display: block;
  font-weight: 500;
  font-size: 0.75rem;
  color: var(--muted, #64748b);
  margin-top: 2px;
}
.cat-sheet-item .csi-arrow {
  color: var(--muted, #94a3b8);
  font-size: 1.1rem;
}
.cat-sheet-all {
  background: rgba(13, 148, 136, 0.08) !important;
  border: 1px solid rgba(13, 148, 136, 0.2) !important;
  margin-bottom: 10px !important;
}
.cat-sheet-loading {
  text-align: center;
  padding: 28px 12px;
  color: var(--muted, #64748b);
  font-size: 0.9rem;
}
body.cat-sheet-open {
  overflow: hidden !important;
}

/* شبکه دسته صفحه اول — تمیزتر */
@media (max-width: 899px) {
  .asy-cats {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 12px 8px !important;
  }
  .asy-cat-ico {
    width: 54px !important;
    height: 54px !important;
    border-radius: 16px !important;
  }
  .asy-cat-name {
    font-size: 0.7rem !important;
    max-width: 76px !important;
  }
}
