/* ==========================================================================
   Search page (loaded only on the search page; builds on main.css tokens)
   ========================================================================== */

.ag-sp-wrap { padding-bottom: 48px; }
.ag-sp-head { padding: 6px 0 16px; }
.ag-sp-head__title { margin: 0; font-size: clamp(22px, 3vw, 30px); font-weight: 900; line-height: 1.5; }
.ag-sp-head__sub { margin: 4px 0 0; color: var(--ag-muted); font-size: 14px; }

/* Top bar: deal type + keyword */
.ag-sp-top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 18px; }
.ag-seg { display: inline-flex; padding: 4px; gap: 2px; border-radius: 12px; background: #fff; border: 1px solid var(--ag-line); }
.ag-seg__opt { position: relative; cursor: pointer; }
.ag-seg__opt input { position: absolute; opacity: 0; pointer-events: none; }
.ag-seg__opt > span { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 16px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--ag-muted); transition: background .15s, color .15s; white-space: nowrap; }
.ag-seg__opt > span .ag-cnt { font-size: 12px; font-weight: 600; opacity: .75; }
.ag-seg__opt input:checked + span { background: var(--ag-brand); color: #fff; box-shadow: 0 2px 8px rgba(15, 138, 63, .3); }
.ag-seg__opt input:focus-visible + span { outline: 3px solid rgba(15, 138, 63, .45); }
.ag-seg__opt:hover input:not(:checked) + span { color: var(--ag-text); background: var(--ag-bg); }
.ag-seg--small { width: 100%; display: grid; grid-template-columns: repeat(5, 1fr); }
.ag-seg--small .ag-seg__opt > span { justify-content: center; padding: 0 6px; min-height: 36px; font-size: 13.5px; }

.ag-q { position: relative; flex: 1; min-width: 260px; display: flex; align-items: center; background: #fff; border: 1px solid var(--ag-line); border-radius: 12px; padding-inline-start: 42px; transition: border-color .15s, box-shadow .15s; }
.ag-q:focus-within { border-color: var(--ag-brand); box-shadow: 0 0 0 4px rgba(15, 138, 63, .12); }
.ag-q__icon { position: absolute; inset-inline-start: 14px; color: var(--ag-muted); width: 20px; height: 20px; }
.ag-q input { flex: 1; min-width: 0; height: 48px; border: 0; outline: 0; background: transparent; font-size: 15px; color: var(--ag-text); }
.ag-q__btn { height: 40px; margin: 4px; padding: 0 18px; border: 0; border-radius: 9px; background: var(--ag-brand); color: #fff; font-weight: 700; cursor: pointer; }
.ag-q__btn:hover { background: var(--ag-brand-dark); }

/* Two-column layout */
.ag-sp__layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 24px; align-items: start; }
.ag-sp__filters {
	position: sticky; top: calc(var(--ag-header-h) + 14px); max-height: calc(100vh - var(--ag-header-h) - 28px);
	display: flex; flex-direction: column; background: #fff; border: 1px solid var(--ag-line); border-radius: var(--ag-radius); overflow: hidden;
}
.admin-bar .ag-sp__filters { top: calc(var(--ag-header-h) + 46px); }
.ag-sheet__head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--ag-line); }
.ag-sheet__head strong { font-size: 16px; }
.ag-sheet__clear { margin-inline-start: auto; font-size: 13px; font-weight: 700; color: var(--ag-red) !important; text-decoration: none; }
.ag-sheet__close { display: none; width: 38px; height: 38px; border: 0; border-radius: 10px; background: var(--ag-bg); cursor: pointer; align-items: center; justify-content: center; }
.ag-sheet__body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 18px 18px; scrollbar-width: thin; }
.ag-sheet__foot { display: none; }

.ag-fs { border-bottom: 1px solid var(--ag-line); padding: 14px 0; }
.ag-fs:last-of-type { border-bottom: 0; }
.ag-fs > summary { display: flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; font-weight: 800; font-size: 14.5px; }
.ag-fs > summary small { color: var(--ag-muted); font-weight: 500; font-size: 12px; }
.ag-fs > summary::-webkit-details-marker { display: none; }
.ag-fs > summary::after { content: ""; margin-inline-start: auto; width: 8px; height: 8px; border: solid var(--ag-muted); border-width: 0 0 2px 2px; transform: rotate(-45deg); transition: transform .2s; }
.ag-fs[open] > summary::after { transform: rotate(135deg); }
.ag-fs > summary + * { margin-top: 12px; }

/* Property type tiles */
.ag-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ag-tile { position: relative; cursor: pointer; }
.ag-tile input { position: absolute; opacity: 0; pointer-events: none; }
.ag-tile__in { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 12px 6px; border: 1.5px solid var(--ag-line); border-radius: 12px; text-align: center; font-size: 13px; font-weight: 700; transition: all .15s; }
.ag-tile__in .ag-icon { width: 24px; height: 24px; color: var(--ag-brand); }
.ag-tile__in .ag-cnt { font-size: 11.5px; color: var(--ag-muted); font-weight: 600; }
.ag-tile:hover .ag-tile__in { border-color: #b9dcc7; }
.ag-tile input:checked + .ag-tile__in { border-color: var(--ag-brand); background: var(--ag-brand-soft); color: var(--ag-brand-dark); }
.ag-tile input:focus-visible + .ag-tile__in { outline: 3px solid rgba(15, 138, 63, .45); }
.ag-tile.is-zero .ag-tile__in { opacity: .45; }

/* Checkbox rows */
.ag-checks { display: flex; flex-direction: column; gap: 2px; }
.ag-checks--cols { display: grid; grid-template-columns: 1fr 1fr; column-gap: 8px; }
.ag-check { position: relative; display: flex; align-items: center; gap: 9px; padding: 7px 4px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.ag-check:hover { background: var(--ag-bg); }
.ag-check input { position: absolute; opacity: 0; pointer-events: none; }
.ag-check__box { flex: none; width: 19px; height: 19px; border: 1.8px solid #b8c4be; border-radius: 6px; display: grid; place-items: center; transition: all .15s; background: #fff; }
.ag-check input:checked + .ag-check__box { background: var(--ag-brand); border-color: var(--ag-brand); }
.ag-check input:checked + .ag-check__box::after { content: ""; width: 9px; height: 5px; border: solid #fff; border-width: 0 0 2px 2px; transform: rotate(-45deg) translate(1px, -1px); }
.ag-check input:focus-visible + .ag-check__box { outline: 3px solid rgba(15, 138, 63, .45); outline-offset: 1px; }
.ag-check__label { flex: 1; min-width: 0; }
.ag-check .ag-cnt { font-size: 12px; color: var(--ag-muted); background: var(--ag-bg); border-radius: 6px; padding: 0 6px; }
.ag-check.is-zero { opacity: .42; cursor: default; }
.ag-check--d1 { padding-inline-start: 22px; }
.ag-check--d2 { padding-inline-start: 40px; }
.ag-check--d0 .ag-check__label { font-weight: 700; }
.ag-more-hidden { display: none; }
.is-expanded .ag-more-hidden { display: flex; }
.ag-showmore { margin-top: 6px; padding: 4px 0; border: 0; background: none; color: var(--ag-brand-dark); font-weight: 700; font-size: 13px; cursor: pointer; }

/* Ranges & presets */
.ag-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.ag-preset { padding: 6px 11px; border: 1px solid var(--ag-line); border-radius: 999px; background: #fff; font-size: 12.5px; font-weight: 600; color: var(--ag-text); cursor: pointer; }
.ag-preset:hover { border-color: var(--ag-brand); }
.ag-preset.is-on { background: var(--ag-brand-soft); border-color: var(--ag-brand); color: var(--ag-brand-dark); }
.ag-range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.ag-only-rent .ag-range { grid-template-columns: 1fr; }
.ag-field { display: flex; flex-direction: column; gap: 4px; }
.ag-field > span { font-size: 12px; color: var(--ag-muted); font-weight: 600; }
.ag-field input { width: 100%; height: 42px; padding: 0 10px; border: 1px solid var(--ag-line); border-radius: 10px; font-size: 14.5px; font-weight: 600; background: #fff; color: var(--ag-text); text-align: left; direction: ltr; }
.ag-field input::placeholder { text-align: right; direction: rtl; font-weight: 400; color: #9aa6a0; }
.ag-field input:focus { outline: 0; border-color: var(--ag-brand); box-shadow: 0 0 0 3px rgba(15, 138, 63, .12); }
.ag-field__words { min-height: 1.4em; font-size: 12px; color: var(--ag-brand-dark); font-weight: 700; }

/* Conditional sections */
.ag-sp:not([data-deal="رهن و اجاره"]) .ag-only-rent { display: none; }
.ag-sp[data-deal="رهن و اجاره"] .ag-only-sale { display: none; }
.ag-sp[data-land-only="1"] .ag-not-land { display: none; }
.ag-js .ag-nojs-only { display: none; }
.ag-nojs-only { margin-top: 14px; }

/* Results toolbar */
.ag-sp-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.ag-sp-toolbar__filters { display: none; position: relative; }
.ag-sp-toolbar__badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: var(--ag-brand); color: #fff; font-size: 11.5px; }
.ag-sp-toolbar__badge[hidden] { display: none; }
.ag-sort { position: relative; display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px; border: 1px solid var(--ag-line); border-radius: 10px; background: #fff; color: var(--ag-muted); }
.ag-sort select { border: 0; background: transparent; font-size: 13.5px; font-weight: 700; color: var(--ag-text); outline: none; cursor: pointer; padding-inline-end: 4px; }
.ag-view { display: inline-flex; margin-inline-start: auto; padding: 3px; border: 1px solid var(--ag-line); border-radius: 10px; background: #fff; }
.ag-view__btn { display: inline-flex; align-items: center; gap: 5px; height: 34px; padding: 0 12px; border: 0; border-radius: 8px; background: none; font-weight: 700; font-size: 13px; color: var(--ag-muted); cursor: pointer; }
.ag-view__btn.is-on { background: var(--ag-brand-soft); color: var(--ag-brand-dark); }

.ag-sr__head { margin-bottom: 14px; }
.ag-sr__count { margin: 0 0 8px; font-size: 15px; color: var(--ag-muted); }
.ag-sr__count strong { color: var(--ag-text); font-size: 19px; font-weight: 900; }
.ag-chips { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.ag-chips__item { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px 5px 12px; border-radius: 999px; background: var(--ag-brand-soft); color: var(--ag-brand-dark) !important; font-size: 13px; font-weight: 700; text-decoration: none; }
.ag-chips__item .ag-icon { width: 15px; height: 15px; padding: 2px; border-radius: 50%; background: rgba(10, 106, 48, .12); }
.ag-chips__item:hover .ag-icon { background: var(--ag-brand); color: #fff; }
.ag-chips__clear { display: inline-flex; align-items: center; padding: 5px 8px; font-size: 13px; font-weight: 700; color: var(--ag-red) !important; text-decoration: none; }

.ag-grid--search { grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 16px; }
.ag-sr__more { display: flex; justify-content: center; margin-top: 24px; }
.ag-sr__more-btn { min-width: 260px; }
.ag-sr__more-btn small { font-weight: 500; opacity: .8; }
.ag-sr__more-btn.is-loading { opacity: .7; pointer-events: none; }
.ag-sr__end { margin: 22px 0 0; text-align: center; color: var(--ag-muted); font-size: 13.5px; }

/* Loading state */
#ag-results { transition: opacity .15s; }
.ag-searching #ag-results { opacity: .5; }
.ag-sp__results { position: relative; min-width: 0; }
.ag-searching .ag-sp__results::before {
	content: ""; position: absolute; top: -6px; inset-inline: 0; height: 3px; border-radius: 3px;
	background: linear-gradient(90deg, transparent, var(--ag-brand), transparent); background-size: 50% 100%; background-repeat: no-repeat;
	animation: ag-bar 1s linear infinite;
}
@keyframes ag-bar { from { background-position: -50% 0; } to { background-position: 150% 0; } }

/* Empty state */
.ag-noresult { padding: 36px 24px; text-align: center; background: #fff; border: 1px dashed #cfd9d4; border-radius: var(--ag-radius); }
.ag-noresult__icon { display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--ag-brand-soft); color: var(--ag-brand); }
.ag-noresult__icon .ag-icon { width: 30px; height: 30px; }
.ag-noresult h2 { margin: 12px 0 6px; font-size: 19px; }
.ag-noresult p { margin: 6px 0; color: var(--ag-muted); }
.ag-noresult__tips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; list-style: none; margin: 12px 0; padding: 0; }
.ag-noresult__tips a { display: inline-block; padding: 8px 14px; border: 1px solid var(--ag-line); border-radius: 999px; text-decoration: none; font-size: 13.5px; color: var(--ag-text) !important; }
.ag-noresult__tips a:hover { border-color: var(--ag-brand); }
.ag-noresult__tips strong { color: var(--ag-brand-dark); }
.ag-noresult__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 14px; }

/* Map view */
.ag-mapview[hidden], #ag-results[hidden] { display: none; }
.ag-mapview__map { height: calc(100vh - var(--ag-header-h) - 120px); min-height: 440px; border-radius: var(--ag-radius); overflow: hidden; border: 1px solid var(--ag-line); background: #e8eee9; direction: ltr; }
.ag-mapview__note { margin: 8px 0 0; font-size: 13px; color: var(--ag-muted); }
.ag-pin { background: none; border: 0; }
.ag-pin span {
	position: relative; display: inline-block; transform: translate(-50%, -100%); padding: 3px 9px; white-space: nowrap; direction: rtl;
	background: #fff; border: 1.5px solid var(--ag-brand); border-radius: 999px; color: var(--ag-brand-dark);
	font: 800 12px/1.6 var(--ag-font); box-shadow: 0 3px 10px rgba(0, 0, 0, .18); cursor: pointer;
}
.ag-pin span::after { content: ""; position: absolute; left: 50%; bottom: -10px; margin-left: -5px; border: 5px solid transparent; border-top-color: var(--ag-brand); }
.ag-pin:hover { z-index: 1000 !important; }
.ag-pin:hover span { background: var(--ag-brand); color: #fff; }
.ag-cluster { background: none; border: 0; }
.ag-cluster span {
	display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
	background: rgba(15, 138, 63, .92); color: #fff; font: 800 14px/1 var(--ag-font);
	box-shadow: 0 0 0 6px rgba(15, 138, 63, .22), 0 4px 12px rgba(0, 0, 0, .2); cursor: pointer;
}
.ag-pop { display: flex; gap: 10px; align-items: center; direction: rtl; text-decoration: none; color: var(--ag-text) !important; font-family: var(--ag-font); }
.ag-pop img { width: 84px; height: 64px; object-fit: cover; border-radius: 8px; flex: none; }
.ag-pop__body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ag-pop__body strong { font-size: 13px; line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ag-pop__body span { font-size: 12.5px; color: var(--ag-brand-dark); font-weight: 700; }
.leaflet-popup-content { margin: 10px 12px; }

/* Tablet & mobile: filters become a bottom sheet */
@media (max-width: 1023px) {
	.ag-sp__layout { grid-template-columns: 1fr; }
	.ag-sp-toolbar { position: sticky; top: var(--ag-header-h); z-index: 20; margin-inline: -16px; padding: 10px 16px; background: rgba(245, 247, 246, .96); backdrop-filter: blur(6px); border-bottom: 1px solid var(--ag-line); }
	.ag-sp-toolbar__filters { display: inline-flex; }
	.ag-view__btn span { display: none; }
	.ag-sp__filters {
		position: fixed; inset: auto 0 0 0; top: auto; z-index: 120; max-height: none; height: min(88vh, 760px);
		border-radius: 20px 20px 0 0; border: 0; box-shadow: 0 -10px 40px rgba(0, 0, 0, .25);
		transform: translateY(105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); visibility: hidden;
	}
	.ag-sheet-open .ag-sp__filters { transform: none; visibility: visible; }
	.ag-sheet-open { overflow: hidden; }
	.ag-sheet__head { position: relative; padding-top: 22px; }
	.ag-sheet__head::before { content: ""; position: absolute; top: 8px; left: 50%; width: 42px; height: 4px; margin-left: -21px; border-radius: 4px; background: #d5ddd9; }
	.ag-sheet__close { display: inline-flex; }
	.ag-sheet__foot { display: block; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--ag-line); background: #fff; }
	.ag-sheet__foot .ag-btn { min-height: 50px; font-size: 15px; }
	.ag-sheet-backdrop { position: fixed; inset: 0; z-index: 110; background: rgba(5, 20, 12, .45); }
	.ag-sheet-backdrop[hidden] { display: none; }
	.ag-mapview__map { height: calc(100vh - var(--ag-header-h) - 190px); min-height: 360px; }
}
@media (max-width: 640px) {
	.ag-sp-top { gap: 10px; }
	.ag-sp-top .ag-seg { width: 100%; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
	.ag-sp-top .ag-seg__opt > span { justify-content: center; padding: 0 8px; }
	.ag-q { min-width: 0; width: 100%; }
	.ag-q__btn { display: none; }
	.ag-sort { flex: 1; min-width: 0; }
	.ag-sort select { width: 100%; }
	.ag-grid--search { grid-template-columns: 1fr; }
	.ag-sp-head__sub { display: none; }
	.ag-view-map .ag-appbar { display: none; }
}
