/* sidebar layout sticky v18
   Desktop only: .classifieds-filters is pinned while its grid column stays reserved.
   Mobile bottom sheet remains untouched.
*/

@media (min-width: 901px) {
  :root {
    --admin-page-max-width: 1480px;
    --admin-page-desktop-pad: 28px;
    --admin-filter-width: clamp(260px, 22vw, 304px);
    --admin-filter-right: max(
      var(--admin-page-desktop-pad),
      calc((100vw - var(--admin-page-max-width)) / 2 + var(--admin-page-desktop-pad))
    );
    --admin-filter-top: var(--header-height, 76px);
  }

  html,
  body {
    height: auto !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }

  .page-shell,
  .tab-panel,
  #propertiesTab,
  .classifieds-results {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  /* The sticky container. The filter must stay INSIDE this grid, not fixed to viewport. */
  .classifieds-layout {
    position: relative !important;
    display: grid !important;
    grid-template-columns: var(--admin-filter-width) minmax(0, 1fr) !important;
    gap: 24px !important;
    align-items: stretch !important;
    overflow: visible !important;
    min-height: calc(100dvh - var(--admin-filter-top)) !important;
    height: 100% !important;
    max-height: none !important;
    min-width: 0 !important;
  }

  .classifieds-layout > .classifieds-filters,
  .classifieds-layout .classifieds-filters {
    position: fixed !important;
    inset: auto !important;
    top: var(--admin-filter-top) !important;
    right: var(--admin-filter-right) !important;
    left: auto !important;
    bottom: auto !important;
    transform: none !important;
    align-self: stretch !important;
    z-index: 25 !important;
    width: var(--admin-filter-width) !important;
    min-width: 0 !important;
    max-width: var(--admin-filter-width) !important;
    height: calc(100dvh - var(--admin-filter-top)) !important;
    max-height: calc(100dvh - var(--admin-filter-top)) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain !important;
    scrollbar-gutter: stable !important;
    box-sizing: border-box !important;
    padding-top: 0 !important;
    padding-bottom: 106px !important;
  }

  .classifieds-layout > .classifieds-results,
  .classifieds-layout .classifieds-results {
    grid-column: 2 !important;
    min-width: 0 !important;
    width: 100% !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .classifieds-filters,
  .classifieds-filters * {
    box-sizing: border-box !important;
    max-width: 100% !important;
  }

  .sidebar-filter-search-box {
    position: sticky !important;
    bottom: -58px !important;
    z-index: 31 !important;
    display: block !important;
    margin: 14px -2px 0 !important;
    padding: 14px 2px 4px !important;
    background: linear-gradient(to top, #fff 78%, rgba(255,255,255,0)) !important;
  }

  .sidebar-filter-search-button {
    width: 100% !important;
    min-height: 46px !important;
    border: 0 !important;
    border-radius: 8px !important;
    background: #111827 !important;
    color: #fff !important;
    font-weight: 900 !important;
    cursor: pointer !important;
    box-shadow: 0 10px 24px rgba(17, 24, 39, .18) !important;
  }

  .sidebar-filter-search-button.is-dirty {
    background: #0f766e !important;
  }

  /* The demand button stays pinned at bottom of the filter scroll area. */
  .sidebar-demand-box-v17 {
    position: sticky !important;
    bottom: 0 !important;
    z-index: 30 !important;
    display: block !important;
    margin: 0 -2px 0 !important;
    padding: 14px 2px 2px !important;
    background: linear-gradient(to top, #fff 72%, rgba(255,255,255,0)) !important;
  }

  .sidebar-demand-button-v17 {
    width: 100% !important;
    box-shadow: 0 10px 28px rgba(159, 29, 38, .20) !important;
  }
}

@media (max-width: 900px) {
  /* Keep mobile behavior from responsive-mobile v4 and mobile controls. */
  .sidebar-filter-search-box {
    display: block !important;
    margin: 16px 0 8px !important;
  }

  .sidebar-filter-search-button {
    width: 100% !important;
    min-height: 46px !important;
    border: 0 !important;
    border-radius: 8px !important;
    background: #111827 !important;
    color: #fff !important;
    font-weight: 900 !important;
  }

  .sidebar-filter-search-button.is-dirty {
    background: #0f766e !important;
  }

  /* The demand button follows the search button in the mobile filter sheet. */
  .sidebar-demand-box-v17 {
    display: block !important;
    position: static !important;
    margin: 0 0 12px !important;
    padding: 0 !important;
    background: none !important;
  }

  .sidebar-demand-button-v17 {
    width: 100% !important;
    min-height: 46px !important;
  }
}

/* Demand modal/button styles copied here so v18 works even if v17 CSS is absent. */
.demand-modal-v17[hidden],
.sidebar-demand-box-v17[hidden] { display: none !important; }

.demand-modal-v17 {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 18px;
  direction: rtl;
}
.demand-modal-backdrop-v17 {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .48);
  backdrop-filter: blur(3px);
}
.demand-modal-card-v17 {
  position: relative;
  z-index: 1;
  width: min(460px, 100%);
  max-height: min(720px, calc(100vh - 32px));
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 18px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, .22);
  padding: 18px;
}
.demand-modal-head-v17 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid #eef2f7;
  padding-bottom: 12px;
}
.demand-modal-head-v17 h3 { margin: 0; font-size: 18px; line-height: 1.8; color: #111827; }
.demand-modal-close-v17 {
  width: 38px;
  height: 38px;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  background: #fff;
  color: #111827;
  font-size: 24px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.demand-form-v17 { display: grid; gap: 12px; }
.demand-gender-v17 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.demand-check-v17 {
  min-height: 44px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  color: #111827;
  background: #fff;
  font-weight: 800;
}
.demand-check-v17 input { width: 18px !important; height: 18px !important; min-height: 0 !important; }
.demand-form-v17 label:not(.demand-check-v17) {
  display: grid;
  gap: 6px;
  color: #6b7280;
  font-size: 12px;
  font-weight: 800;
}
.demand-form-v17 input,
.demand-form-v17 textarea {
  width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #fff;
  color: #111827;
  padding: 10px 12px;
  min-height: 42px;
  outline: none;
}
.demand-form-v17 textarea { min-height: 82px; resize: vertical; line-height: 1.9; }
.demand-form-v17 input:focus,
.demand-form-v17 textarea:focus { border-color: #9f1d26; box-shadow: 0 0 0 3px rgba(159, 29, 38, .10); }
.demand-actions-v17 { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding-top: 4px; }
.demand-submit-v17,
.sidebar-demand-button-v17 {
  border: 1px solid #9f1d26;
  background: #9f1d26;
  color: #fff;
  border-radius: 12px;
  min-height: 44px;
  padding: 0 16px;
  font-weight: 900;
  cursor: pointer;
}
.demand-submit-v17:hover,
.sidebar-demand-button-v17:hover { background: #801720; }
.demand-cancel-v17 {
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #111827;
  border-radius: 12px;
  min-height: 44px;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}
.demand-message-v17 { min-height: 24px; font-size: 12px; line-height: 1.9; color: #64748b; }
.demand-message-v17.error { color: #b42318; }
.demand-message-v17.success { color: #087443; }

@media (max-width: 900px) {
  .demand-modal-v17 { align-items: end; place-items: end center; padding: 10px; }
  .demand-modal-card-v17 { width: 100%; max-height: calc(100vh - 20px); border-radius: 18px 18px 12px 12px; }
}
