/* public/css/mobile-searchbar.css
   =========================================================
   MOBILE UI, NAV, SHEETS, RESPONSIVE RULES
   Single source of truth for mobile behavior.
   z-index values must come from front.css:
     --z-mnav, --z-sheet-backdrop, --z-sheet
   ========================================================= */

:root{
  /* Safe areas */
  --m-safe-top: env(safe-area-inset-top, 0);
  --m-safe-bottom: env(safe-area-inset-bottom, 0);
  --m-safe-left: env(safe-area-inset-left, 0);
  --m-safe-right: env(safe-area-inset-right, 0);

  /* Sizes */
  --mnav-h: 56px;

  /* Design tokens (mobile) */
  --m-bg: #fff;
  --m-text: #111827;
  --m-muted: #6b7280;

  --m-border: #e5e7eb;
  --m-border-soft: #eef2f7;

  --m-card: #ffffff;
  --m-soft: #f8fafc;

  --m-radius-lg: 18px;
  --m-radius-md: 14px;
  --m-radius-sm: 12px;

  --m-shadow-sm: 0 8px 20px rgba(0,0,0,.06);
  --m-shadow-md: 0 -12px 30px rgba(0,0,0,.14);

  --m-primary: #1d4ed8;
  --m-ease: cubic-bezier(.2,.8,.2,1);

  /* searchbar sizes */
  --msb-h: 52px;
  --msb-pad: 10px;
}

/* ---------------------------------------------------------
   0) Visibility switches
--------------------------------------------------------- */
@media (max-width: 900px){
  .only-mobile{ display: block; }
  .only-desktop{ display: none; }
}
@media (min-width: 901px){
  .only-mobile{ display: none; }
}

/* ---------------------------------------------------------
   1) Mobile base patches
--------------------------------------------------------- */
@media (max-width: 900px){

  /* prevent iOS zoom on focus */
  input, select, textarea, .dv-input{ font-size: 16px !important; }

  body.site-body{
    padding-bottom: calc(var(--mnav-h) + var(--m-safe-bottom) + 10px);
    background: var(--m-bg);
    color: var(--m-text);
    margin: 0;
  }

  /* حذف هر فاصله‌ی اضافی بالای صفحه تا هدر کل صفحه را بگیرد */
  main#content,
  .container,
  .page,
  .page-grid{
    margin-top: 0 !important;
    padding-top: 0 !important;
  }

  .container{
    padding-inline: 12px;
  }

  .page-grid{
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .cat-sidebar{ display: none !important; }

  .ad-grid{
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .card{
    padding: 10px;
    border-radius: var(--m-radius-md);
  }
}

@media (max-width: 360px){
  .ad-grid{ grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------
   2) Split scroll (mobile)
--------------------------------------------------------- */
@media (max-width: 900px){
  body.has-split-scroll{ overflow: auto !important; }

  .split-scroll{
    height: auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 8px;
  }

  .split-scroll__panel{ display: none !important; }
  .split-scroll .filters{ display: none !important; }

  .split-scroll .ad-grid{
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
}

/* ---------------------------------------------------------
   3) Shared form controls (mobile)
--------------------------------------------------------- */
@media (max-width: 900px){
  .m-input,
  .fs-body input,
  .fs-body select,
  .cs-search input{
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--m-border);
    border-radius: var(--m-radius-md);
    background: var(--m-bg);
    color: var(--m-text);
    outline: none;
  }

  .m-input:focus,
  .fs-body input:focus,
  .fs-body select:focus,
  .cs-search input:focus{
    border-color: rgba(29,78,216,.45);
    box-shadow: 0 0 0 3px rgba(29,78,216,.14);
  }

  .m-btn,
  .fs-close,
  .cs-back, .cs-close,
  .msb-back, .msb-clear, .msb-submit{
    -webkit-tap-highlight-color: transparent;
  }
}
/* ---------------------------------------------------------
   4) Mobile Searchbar (msb) , Divar like header
   نکته: فقط همین یک بلاک msb را نگه دار
   هدف: حذف فضای اضافی اطراف هدر + استفاده از کل عرض صفحه
--------------------------------------------------------- */
@media (max-width: 900px){

  .msb{
    position: sticky;
    top: 0;
    z-index: var(--z-mnav, 50);

    background: #fff;

    /* فاصله‌ی چپ/راست تقریبا صفر */
    padding: 4px 0;
    padding-top: calc(4px + var(--m-safe-top));

  }

  /* اگر msb داخل .container است و اون 12px padding دارد، خنثی کن */
  .container .msb{
    margin-inline: -12px;
        background: #f2f2f2;

  }

  .msb-row{
    width: 96%;
    display: flex;
    align-items: center;
    gap: 6px;
    direction: rtl;
  }

  .msb-back{
    width: 32px;
    height: 32px;
    border: 0;
    background: transparent;
    color: #4b5563;
    display: grid;
    place-items: center;
    border-radius: 8px;
    flex: 0 0 auto;
  }
  .msb-back:active{ background: rgba(17,24,39,.06); }

  .msb-form{ flex: 1; min-width: 0; }

  .msb-combo{
    height: 39px;
    display: flex;
    flex-direction: row-reverse;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0;
    direction: rtl;

    /* ظاهر */
    background: #ffffff;
    border: 1px solid #a4a4a4; /* نوار خاکستری باریک دورش */
    border-radius: 4px;

    /* مهم: کشیده شدن در عرض */
    flex: 1;
    min-width: 0;

    transition: border-color .2s ease, box-shadow .2s ease;
  }

  /* وقتی فوکوس داخلش هست، فقط دور کادر بهتر بشه (نه سفید شدن کلش) */
  .msb-combo:focus-within{
    border-color: #d1d5db;
    box-shadow: 0 2px 6px rgba(0,0,0,.05);
  }

  .msb-city{
    display: inline-flex;
    flex-direction: row-reverse;
    align-items: center;
    gap: 6px;

    height: 100%;
    max-width: 45%;
    min-width: 72px;

    padding-inline: 6px;
    color: #646464;
    text-decoration: none;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .msb-city-ico{ color: #9ca3af; flex: 0 0 auto; }

  .msb-city-txt{
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .msb-city-chv{ opacity: .6; flex: 0 0 auto; }

  .msb-divider{
    width: 1px;
    height: 18px;
    background: #d1d5db;
    margin: 0 2px;
    flex: 0 0 auto;
  }

  .msb-input{
    flex: 1;
    min-width: 0;
    height: 100%;

    border: 0 !important;
    outline: 0;

    /* پیشفرض شفاف، فقط خود input موقع فوکوس سفید میشه */
    background: transparent;
    padding: 0 6px;

    color: #111827;
    font-size: 14px !important;
    transition: background .15s ease;
  }

  .msb-input:focus{
    background: #fff; /* فقط داخل input سفید */
  }

  .msb-input::placeholder{
    color: #9ca3af;
    font-size: 13px;
  }

  .msb-input::-webkit-search-cancel-button{
    -webkit-appearance: none;
    appearance: none;
  }

  .msb-submit,
  .msb-clear{
    width: 30px;
    height: 100%;
    border: 0;
    background: transparent;
    color: #9ca3af;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
  }

  .msb-clear{
    color: #6b7280;
    display: none;
  }

  .msb.has-text .msb-submit{ display: none; }
  .msb.has-text .msb-clear{ display: grid; }
}

@media (min-width: 901px){
  .msb{ display: none; }
}


/* ---------------------------------------------------------
   5) Mobile categories grid (mcats) , clean, no underline
--------------------------------------------------------- */
.mcats{
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

@media (max-width: 360px){
  .mcats{ grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.mcats__item{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;

  padding: 12px 8px;

  text-decoration: none !important;
  color: var(--m-text);

  background: var(--m-card);
  border: 1px solid var(--m-border-soft);
  border-radius: var(--m-radius-md);

  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}

.mcats__item *{
  text-decoration: none !important;
}

.mcats__item:active{
  transform: scale(.985);
  border-color: var(--m-border);
  box-shadow: 0 0 0 3px rgba(0,0,0,.03);
}

.mcats__icon{
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--m-soft);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.mcats__icon img{
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.mcats__label{
  display: block;
  font-size: 13px;
  font-weight: 800;
  text-align: center;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  color: rgba(17,24,39,.78);
}

/* ---------------------------------------------------------
   6) Mobile chips
--------------------------------------------------------- */
.mchips{
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0;

  scrollbar-width: none;
  -ms-overflow-style: none;
}
.mchips::-webkit-scrollbar{ display: none; }

.kt-chip{
  display: inline-flex;
  align-items: center;
  gap: 6px;

  padding: 7px 12px;
  border-radius: 999px;

  border: 1px solid var(--m-border);
  background: var(--m-bg);
  color: var(--m-text);

  white-space: nowrap;
  font-size: 13px;
}
.kt-chip--ghost{ background: var(--m-soft); }

@media (max-width: 400px){
  .kt-chip{ font-size: 12px; padding: 6px 10px; }
}

/* ---------------------------------------------------------
   7) Bottom Mobile Nav (mnav)
--------------------------------------------------------- */
.mnav{
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-mnav, 50);

  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  border-top: 1px solid rgba(229,231,235,.9);

  padding: 4px var(--m-safe-right) calc(6px + var(--m-safe-bottom)) var(--m-safe-left);
  height: calc(var(--mnav-h) + var(--m-safe-bottom));

  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 4px;

  box-shadow: 0 -6px 24px rgba(0,0,0,0.06);
  -webkit-tap-highlight-color: transparent;
}

.mnav__item{
  flex: 1;
  min-width: 0;
  text-align: center;
  text-decoration: none;
  color: var(--m-text);

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;

  padding: 7px 0;
  border-radius: 12px;

  font-size: 12px;
  line-height: 1.2;
}

.mnav__icon{ font-size: 18px; line-height: 1; }
.mnav__label{ font-size: 11px; line-height: 1; color: var(--m-muted); }

.mnav__item.is-active{
  color: var(--m-primary);
  font-weight: 900;
}
.mnav__item.is-active .mnav__label{ color: var(--m-primary); }

@media (max-width: 400px){
  .mnav__label{ font-size: 10px; }
}

/* ---------------------------------------------------------
   8) Sheets (shared base)
--------------------------------------------------------- */
.fs-wrap[hidden],
.cs-wrap[hidden],
.cs-backdrop[hidden],
.sheet[aria-hidden="true"]{ display: none !important; }

.fs-wrap,
.sheet{
  position: fixed;
  inset: 0;
}

/* shared backdrop */
.fs-backdrop,
.cs-backdrop,
.sheet__backdrop{
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;

  background: rgba(0, 0, 0, 0.42);
  z-index: var(--z-sheet-backdrop, 60);
}

/* shared panel */
.fs-box,
.cs-wrap,
.sheet__panel{
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;

  background: var(--m-bg);
  z-index: var(--z-sheet, 70);

  border-top-left-radius: var(--m-radius-lg);
  border-top-right-radius: var(--m-radius-lg);

  box-shadow: var(--m-shadow-md);
  padding-bottom: var(--m-safe-bottom);

  outline: none;
}

/* size differences */
.fs-box{ max-height: 78vh; overflow: auto; }
.cs-wrap{ max-height: 85vh; overflow: hidden; display: flex; flex-direction: column; }
.sheet__panel{ max-height: 88vh; }

/* ---------------------------------------------------------
   9) Filters sheet (fs-*)
--------------------------------------------------------- */
.fs-header{
  display: flex;
  align-items: center;
  justify-content: center;

  padding: 10px 12px;
  border-bottom: 1px solid var(--m-border);

  position: sticky;
  top: 0;
  background: var(--m-bg);
}

.fs-close{
  position: absolute;
  inset-inline-start: 10px;

  width: 34px;
  height: 34px;

  border: 1px solid var(--m-border);
  background: var(--m-bg);
  border-radius: 12px;
}

.fs-body{
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fs-row{
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.fs-footer{
  position: sticky;
  bottom: 0;
  background: var(--m-bg);
  border-top: 1px solid var(--m-border);
  padding: 10px 12px;
}

/* ---------------------------------------------------------
   10) Category sheet (cs-*)
--------------------------------------------------------- */
.cs-wrap{
  transform: translateY(100%);
  transition: transform .28s var(--m-ease);
  will-change: transform;
}
.cs-wrap.is-open{ transform: translateY(0); }

.cs-handle{
  width: 40px;
  height: 4px;
  background: #e5e7eb;
  border-radius: 999px;
  margin: 10px auto 6px;
  flex-shrink: 0;
}

.cs-header{
  display: flex;
  align-items: center;
  justify-content: space-between;

  padding: 0 10px 10px;
  border-bottom: 1px solid var(--m-border-soft);
}

.cs-title{ font-weight: 900; font-size: 1rem; color: var(--m-text); }

.cs-back, .cs-close{
  border: none;
  background: transparent;
  padding: 8px;
  cursor: pointer;
  color: var(--m-muted);
}

.cs-search{ padding: 10px; }
.cs-search input{ background: var(--m-soft); border-color: var(--m-border); }

.cs-list{
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.cs-item{
  display: flex;
  align-items: center;
  gap: 10px;

  padding: 12px 14px;
  border-bottom: 1px solid rgba(0,0,0,.04);
  cursor: pointer;
}

.cs-item:active{ background: rgba(0,0,0,.04); }
.cs-item-txt{ flex: 1; font-size: .95rem; color: var(--m-text); }
.cs-arrow{ color: #cbd5e1; }
.cs-all-link{ color: var(--m-primary); font-weight: 800; }

/* ---------------------------------------------------------
   11) Sell sheet (sheet-*)
--------------------------------------------------------- */
.sheet__handle{
  width: 40px;
  height: 5px;
  border-radius: 999px;
  background: #e5e7eb;
  margin: 8px auto;
}

.sheet__header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 4px 12px;
  border-bottom: 1px solid rgba(0,0,0,.04);
}

.sheet__title{
  font-size: .95rem;
  margin: 0;
  font-weight: 900;
  color: var(--m-text);
}

.sheet__spacer{ width: 28px; }

.sheet__body{ padding: .25rem .75rem .75rem; }
.sheet__footer{ padding: .5rem .75rem .25rem; }

.sheet-actions{
  display: grid;
  gap: .5rem;
}

.btn-block{ width: 100%; }

.safe-bottom{
  height: calc(8px + var(--m-safe-bottom));
}

/* ---------------------------------------------------------
   12) Legacy m-cat-grid (optional)
--------------------------------------------------------- */
.m-cat-grid-wrapper{
  padding: 10px 12px;
  background: var(--m-bg);
  margin-bottom: 8px;
  border-bottom: 1px solid var(--m-border);
}

.m-cat-title{
  font-weight: 900;
  margin-bottom: 10px;
  font-size: .9rem;
  color: var(--m-text);
}

.m-cat-grid{
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 10px;
  text-align: center;
}

.m-cat-item{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.m-cat-icon{
  width: 44px;
  height: 44px;
  background: var(--m-soft);
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 20px;
}

.m-cat-icon img{
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.m-cat-item span{
  font-size: 12px;
  color: var(--m-muted);
  line-height: 1.2;
}
