/* ===== apt hunter — light theme ===== */

:root {
  --bg:        #ffffff;
  --surface:   #f5f5f7;   /* off-white panels / cards */
  --surface-2: #ebebed;   /* inset elements: score tracks, input bg */
  --border:    #e2e2e8;
  --text:      #111111;
  --text-2:    #60606a;
  --accent:    #6366f1;
  --score-high: #16a34a;
  --score-mid:  #d97706;
  --score-low:  #dc2626;
  --shadow:    0 8px 32px rgba(0,0,0,0.10), 0 1px 4px rgba(0,0,0,0.06);
  --shadow-sm: 0 2px 12px rgba(0,0,0,0.08);
  --radius:    16px;
  --radius-sm: 10px;
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
  --safe-right:  env(safe-area-inset-right,  0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%; width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overflow: hidden;
  overscroll-behavior: none;
}

button {
  font-family: 'DM Sans', inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  padding: 0;
}

a { color: inherit; text-decoration: none; }

/* ===== Map ===== */

#map {
  position: fixed;
  inset: 0;
  background: var(--bg);
  transition: bottom 0.28s cubic-bezier(0.34, 1.1, 0.64, 1);
}

.panel-open #map { bottom: 52vh; }

.maplibregl-ctrl-attrib,
.maplibregl-ctrl-bottom-right,
.maplibregl-ctrl-top-left,
.maplibregl-ctrl-top-right { display: none !important; }

.maplibregl-canvas { outline: none !important; }

/* ===== Loading bar ===== */

.loading-bar {
  position: fixed;
  top: var(--safe-top);
  left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, #6366f1, #22c55e);
  z-index: 100;
  transform: scaleX(0);
  transform-origin: left;
  opacity: 0;
  transition: opacity 0.2s;
}

.loading-bar.is-loading {
  transform: scaleX(0.75);
  opacity: 1;
  animation: loading-pulse 1.4s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ===== FABs ===== */

.fab {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  z-index: 10;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: bottom 0.28s cubic-bezier(0.34, 1.1, 0.64, 1), transform 0.15s, background 0.15s;
}

.fab:active { transform: scale(0.93); }
.fab-left { left:  calc(16px + var(--safe-left)); }
.fab-right { right: calc(16px + var(--safe-right)); }

.fab.active {
  background: #6366f1 !important;
  border-color: #6366f1 !important;
  color: #fff !important;
}

.panel-open .fab { bottom: calc(52vh + 12px); }

/* ===== Score pill ===== */

.score-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}

.score-pill--high { background: rgba(22,163,74,0.12); color: var(--score-high); }
.score-pill--mid  { background: rgba(217,119, 6,0.12); color: var(--score-mid); }
.score-pill--low  { background: rgba(220, 38,38,0.12); color: var(--score-low); }
.score-pill--none { background: var(--surface-2); color: var(--text-2); }

/* ===== Action buttons ===== */

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: 'DM Sans', inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, transform 0.1s;
}

.action-btn:active { transform: scale(0.95); }

.action-btn--favorite.is-active {
  background: rgba(217,119,6,0.1);
  color: var(--score-mid);
  border-color: rgba(217,119,6,0.25);
}

/* ===== Listing panel ===== */

.listing-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 52vh;
  z-index: 20;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.10);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.34, 1.1, 0.64, 1);
  will-change: transform;
}

.listing-panel.is-open { transform: translateY(0); }

.lp-handle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0 6px;
  cursor: grab;
  touch-action: none;
}

.lp-handle-bar {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: var(--border);
}

.lp-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: calc(12px + var(--safe-bottom));
}

/* Image strip */
.lp-gallery {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  padding: 0 14px 12px;
}

.lp-gallery::-webkit-scrollbar { display: none; }

.lp-gallery__img {
  width: 200px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  scroll-snap-align: start;
  background: var(--surface-2);
}

.lp-gallery__placeholder {
  width: 100%;
  height: 90px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--border);
  font-size: 32px;
  margin: 0 14px 12px;
}

/* Header row */
.lp-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 0 14px 6px;
}

.lp-price {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
}

.lp-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}

.lp-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: 'DM Sans', inherit;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.12s, transform 0.1s;
}

.lp-btn:active { transform: scale(0.95); }

.lp-btn--fav.is-active {
  background: rgba(217,119,6,0.1);
  color: var(--score-mid);
  border-color: rgba(217,119,6,0.3);
}

.lp-btn--dismiss:active {
  background: rgba(220,38,38,0.08);
}

/* Meta line */
.lp-meta {
  padding: 0 14px 8px;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.4;
}

.lp-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  padding: 0 14px 2px;
}

/* Divider */
.lp-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 14px;
}

/* Scores */
.lp-scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  padding: 0 14px 2px;
}

.lp-score-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.lp-score-label {
  font-size: 11px;
  color: var(--text-2);
  width: 58px;
  flex-shrink: 0;
}

.lp-score-track {
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}

.lp-score-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--score-high);
  transition: width 0.4s ease;
}

.lp-score-fill--mid { background: var(--score-mid); }
.lp-score-fill--low { background: var(--score-low); }

.lp-score-val {
  font-size: 11px;
  font-weight: 700;
  width: 22px;
  text-align: right;
  color: var(--text);
}

/* Tags */
.lp-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 6px 14px 2px;
}

.lp-tag {
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-2);
}

/* Description */
.lp-desc {
  padding: 4px 14px;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Notes */
.lp-notes-label {
  padding: 8px 14px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
}

.lp-notes {
  margin: 0 14px;
  width: calc(100% - 28px);
  min-height: 60px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'DM Sans', inherit;
  font-size: 13px;
  padding: 8px 10px;
  resize: none;
}

.lp-notes:focus { outline: none; border-color: var(--accent); }
.lp-notes::placeholder { color: var(--border); }

/* Dates */
.lp-dates {
  padding: 8px 14px 4px;
  font-size: 11px;
  color: var(--border);
}

/* Loading skeleton */
.lp-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-2);
  font-size: 14px;
}

/* ===== Filter panel ===== */

.filter-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.10);
  padding: 0 20px calc(20px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.34, 1.1, 0.64, 1);
  max-height: 80vh;
  overflow-y: auto;
}

.filter-panel.is-open { transform: translateY(0); }

.filter-panel__handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 10px;
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.filter-panel__title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.filter-panel__reset {
  font-size: 13px;
  color: var(--text-2);
  text-decoration: underline;
  font-family: 'DM Sans', inherit;
  cursor: pointer;
}

.filter-row { margin-bottom: 18px; }

.filter-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}

.filter-label span { color: var(--text); font-weight: 700; }

.range-slider {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  accent-color: var(--accent);
  cursor: pointer;
}

/* Dual-handle price slider */
.dual-range {
  position: relative;
  height: 32px;
  display: flex;
  align-items: center;
  margin-top: 4px;
}

.dual-range__track {
  position: absolute;
  left: 0; right: 0;
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
}

.dual-range__fill {
  position: absolute;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

.dual-range__thumb {
  position: absolute;
  width: 100%;
  height: 4px;
  background: transparent;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  border: none;
}

.dual-range__thumb::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: all;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  cursor: pointer;
}

.dual-range__thumb::-moz-range-thumb {
  pointer-events: all;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  cursor: pointer;
}

/* AI prompt */
.ai-prompt {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: 'DM Sans', inherit;
  padding: 8px 10px;
  resize: none;
  line-height: 1.5;
  margin-top: 6px;
}

.ai-prompt::placeholder { color: var(--border); }
.ai-prompt:focus { outline: none; border-color: var(--accent); }

.ai-prompt-note {
  font-size: 11px;
  color: var(--text-2);
  margin-top: 4px;
}

/* Pills */
.pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--text-2);
  background: var(--bg);
  cursor: pointer;
  font-family: 'DM Sans', inherit;
  transition: background 0.12s, color 0.12s;
}

.pill.active {
  background: rgba(99,102,241,0.1);
  color: var(--accent);
  border-color: rgba(99,102,241,0.3);
}

/* Toggles */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.toggle-label { font-size: 14px; color: var(--text); }

.toggle {
  position: relative;
  width: 44px; height: 26px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--surface-2);
  border-radius: 13px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

.filter-footer {
  padding: 14px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  position: sticky;
  bottom: 0;
  background: var(--surface);
}

.btn-apply {
  width: 100%;
  padding: 13px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  font-family: 'DM Sans', inherit;
  border: 0;
  cursor: pointer;
  transition: opacity 0.12s;
}

.btn-apply:active { opacity: 0.8; }

/* ===== Sheet backdrop (card stack) ===== */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 29;
  background: rgba(0,0,0,0.35);
  opacity: 0;
  transition: opacity 0.25s;
}

.sheet-backdrop.is-open { opacity: 1; }

/* ===== Bottom sheet (card stack) ===== */

.bottom-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  height: 88vh;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.34, 1.1, 0.64, 1);
  will-change: transform;
}

.bottom-sheet.is-open { transform: translateY(0); }

.sheet-handle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0 6px;
  cursor: grab;
}

.sheet-handle__bar {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: var(--border);
}

.sheet-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(32px + var(--safe-bottom));
  overscroll-behavior: contain;
}

/* ===== Card stack view ===== */

.card-stack-view {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.card-stack-view.is-open { transform: translateX(0); }

.stack-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.stack-header__title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.stack-header__close {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  border: 0;
  cursor: pointer;
}

.stack-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(20px + var(--safe-bottom));
}

.stack-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  overflow: hidden;
  transition: transform 0.2s ease, opacity 0.2s ease;
  will-change: transform;
  color: var(--text);
}

.stack-card.dismissing {
  transform: translateX(-110%) rotate(-5deg) !important;
  opacity: 0;
}

.stack-card.favoriting {
  transform: translateX(110%) rotate(5deg) !important;
  opacity: 0;
}

.stack-card__thumb {
  width: 100%; height: 160px;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
}

.stack-card__thumb-placeholder {
  width: 100%; height: 160px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--border);
  font-size: 40px;
}

.stack-card__body { padding: 12px 14px 14px; }

.stack-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.stack-card__price {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.stack-card__address {
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 6px;
}

.stack-card__snippet {
  font-size: 13px;
  color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 12px;
  line-height: 1.45;
}

.stack-card__actions { display: flex; gap: 8px; }

.stack-action-btn {
  flex: 1;
  padding: 9px 6px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  font-family: 'DM Sans', inherit;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
  transition: background 0.12s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.stack-action-btn:active { transform: scale(0.96); }

.stack-action-btn--dismiss {
  color: var(--score-low);
  border-color: rgba(220,38,38,0.2);
  background: rgba(220,38,38,0.05);
}

.stack-action-btn--favorite {
  color: var(--score-mid);
  border-color: rgba(217,119,6,0.25);
  background: rgba(217,119,6,0.06);
}

.stack-action-btn--favorite.is-active {
  background: rgba(217,119,6,0.15);
}

.stack-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--text-2);
  gap: 12px;
  text-align: center;
  padding: 32px;
}

.stack-empty__icon { font-size: 48px; }
.stack-empty__title { font-size: 18px; font-weight: 700; color: var(--text); }
.stack-empty__sub { font-size: 14px; }
