/**
 * Cardiff 5-Bed House Hunter
 * Builds on ../style.css tokens. Mobile first: one column, sticky search,
 * filters tucked behind a button on phones.
 */

.housing {
  --walk-green: #30d158;
  --walk-gold: #ffd60a;
  --walk-purple: #bf5af2;
  --walk-far: #8e8e93;
}

/* ==========================================================================
   Header
   ========================================================================== */
.app-header {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: calc(32px + var(--safe-top)) 0 24px;
}
.header-shader {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(70% 70% at 85% 20%, rgba(255, 122, 26, 0.3), transparent 70%),
    radial-gradient(60% 70% at 10% 80%, rgba(14, 116, 144, 0.45), transparent 70%),
    #000;
  -webkit-mask-image: linear-gradient(to bottom, #000 50%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 50%, transparent 100%);
}
.header-shader canvas { opacity: 0; transition: opacity 1200ms ease; }
.header-shader.shader-ready canvas { opacity: 1; }

.header-container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  padding: 5px 12px 5px 9px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.08);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  font-size: 13px;
  font-weight: 500;
}
.pulsing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 0 3px rgba(48, 209, 88, 0.25);
}

.main-title {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: clamp(30px, 4.6vw, 52px);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.035em;
}
.subtitle {
  max-width: 44ch;
  margin: 0 0 20px;
  font-size: clamp(15px, 1.4vw, 17px);
  line-height: 1.45;
  color: rgba(245, 245, 247, 0.78);
  text-wrap: pretty;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(14, 14, 18, 0.55);
  -webkit-backdrop-filter: saturate(160%) blur(20px);
  backdrop-filter: saturate(160%) blur(20px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 0 0 1px var(--border);
}
.stat-value {
  font-family: var(--font-display);
  font-size: clamp(19px, 2vw, 24px);
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.stat-priority .stat-value { color: var(--walk-green); }
.stat-label { font-size: 12px; color: var(--text-2); }

.header-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ==========================================================================
   Toolbar
   ========================================================================== */
.main-container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--gutter) 80px;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  gap: 12px;
  margin: 0 calc(var(--gutter) * -1);
  padding: calc(12px + var(--safe-top)) var(--gutter) 12px;
  background: rgba(0, 0, 0, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  transition: box-shadow 200ms ease, transform 300ms var(--ease-out);
}
.toolbar.stuck { box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08); }
.toolbar.tucked { transform: translateY(-100%); }

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

.search-box {
  position: relative;
  flex: 1;
  min-width: 0;
}
.search-icon {
  position: absolute;
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  height: 40px;
  padding: 0 40px 0 40px;
  border: 0;
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: box-shadow 150ms ease, background-color 150ms ease;
}
.search-box input::-webkit-search-cancel-button { display: none; }
.search-box input::placeholder { color: var(--text-3); }
.search-box input:focus { background: var(--surface-3); box-shadow: 0 0 0 3px rgba(41, 151, 255, 0.45); }

.btn-clear {
  position: absolute;
  top: 50%;
  right: 8px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  transform: translateY(-50%);
  border-radius: 50%;
  color: var(--text);
}
.btn-clear::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: var(--text-3);
  z-index: -1;
}
.btn-clear { isolation: isolate; }
.btn-clear svg { color: #000; }

.btn-filters {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border-radius: 11px;
  background: var(--surface-2);
  font-size: 15px;
  font-weight: 500;
  transition: transform 120ms var(--ease-out), background-color 150ms ease;
}
.btn-filters:active { transform: scale(0.97); }
.btn-filters[aria-expanded="true"] { background: var(--surface-3); }
.filter-count {
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--accent-sky);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

/* Walk chips — horizontally scrollable on narrow screens */
.chip-toggle-group {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  margin: 0 calc(var(--gutter) * -1);
  padding: 0 var(--gutter);
}
.chip-toggle-group::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  min-height: 32px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  transition: transform 120ms var(--ease-out), background-color 200ms ease, color 200ms ease;
}
.chip:active { transform: scale(0.96); }
.chip.active { background: var(--text); color: #000; }
@media (hover: hover) and (pointer: fine) {
  .chip:not(.active):hover { background: var(--surface-3); color: var(--text); }
}

/* Filter panel — collapsed until asked for; animating the grid row lets height follow content */
.filter-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 300ms var(--ease-out);
}
.filter-panel.open { grid-template-rows: 1fr; }
.filter-panel-inner {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.2fr 1.2fr auto;
  align-items: end;
  gap: 16px;
  min-height: 0;
  overflow: hidden;
}
.filter-panel.open .filter-panel-inner { padding: 4px 0 8px; }
.filter-item { display: grid; gap: 6px; min-width: 0; }
.filter-item label, .slider-header { font-size: 13px; color: var(--text-2); }
.slider-header { display: flex; justify-content: space-between; gap: 8px; }
.slider-header strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.filter-item select {
  width: 100%;
  height: 40px;
  padding: 0 36px 0 12px;
  border: 0;
  border-radius: 10px;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a1a1a6' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--text);
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.filter-item select option { background: #1c1c1e; }

/* Range */
input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--surface-3); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--surface-3); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -10px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* iOS-style switch */
.switch-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.switch-container input { position: absolute; opacity: 0; pointer-events: none; }
.switch-label { font-size: 15px; color: var(--text); white-space: nowrap; }
.switch-slider {
  position: relative;
  flex-shrink: 0;
  width: 51px;
  height: 31px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  transition: background-color 200ms ease;
}
.switch-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
  transition: transform 250ms var(--ease-out);
}
.switch-container input:checked + .switch-slider { background: var(--accent-green); }
.switch-container input:checked + .switch-slider::after { transform: translateX(20px); }
.switch-container input:focus-visible + .switch-slider { outline: 2px solid var(--accent-sky); outline-offset: 2px; }

/* ==========================================================================
   Results
   ========================================================================== */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 20px 0 14px;
}
.results-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.legend-pills { display: flex; flex-wrap: wrap; gap: 12px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.pill-green .dot { background: var(--walk-green); }
.pill-gold .dot { background: var(--walk-gold); }
.pill-purple .dot { background: var(--walk-purple); }

.properties-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

/* ==========================================================================
   Property card
   ========================================================================== */
.property-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 18px;
  background: var(--bg-elevated);
  box-shadow: inset 0 0 0 1px var(--border);
  animation: card-in 400ms var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 35ms);
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
}
@media (hover: hover) and (pointer: fine) {
  .property-card { transition: box-shadow 250ms ease, transform 250ms var(--ease-out); }
  .property-card:hover { transform: translateY(-2px); box-shadow: inset 0 0 0 1px var(--border-strong), 0 20px 40px -24px rgba(0, 0, 0, 0.8); }
}

.card-media {
  position: relative;
  aspect-ratio: 3 / 2;
  background: #111114;
}
.card-img { width: 100%; height: 100%; object-fit: cover; }
.card-img-placeholder {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 16px;
  background:
    radial-gradient(80% 80% at 80% 0%, rgba(255, 122, 26, 0.18), transparent 70%),
    radial-gradient(80% 80% at 0% 100%, rgba(14, 116, 144, 0.25), transparent 70%),
    #111114;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-align: center;
  color: var(--text-2);
}

.badge-top-left, .badge-top-right {
  position: absolute;
  top: 10px;
  display: flex;
  gap: 4px;
}
.badge-top-left { left: 10px; }
.badge-top-right { right: 10px; flex-direction: column; align-items: flex-end; }

.badge-walk, .badge-recency, .badge-source {
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-walk { display: inline-flex; align-items: center; gap: 6px; }
.badge-walk::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--walk-far); }
.walk-5m::before { background: var(--walk-green); }
.walk-10m::before { background: var(--walk-gold); }
.walk-15m::before { background: var(--walk-purple); }
.badge-recency { color: var(--text-2); }
.badge-new { color: var(--walk-green); }
.badge-source { font-weight: 500; color: var(--text-2); }

.card-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px 14px;
}
.card-price-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.price-main {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}
.price-unit { font-size: 13px; font-weight: 500; color: var(--text-2); letter-spacing: -0.01em; }
.price-sub { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }

.bills-tag {
  align-self: flex-start;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: rgba(48, 209, 88, 0.14);
  color: var(--walk-green);
  font-size: 11px;
  font-weight: 600;
}
.bills-tag.no { background: var(--surface-2); color: var(--text-3); }

.card-title {
  display: -webkit-box;
  margin: 2px 0 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.spec-row { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--text-2); }
.spec-item + .spec-item::before { content: "\00b7"; margin-right: 10px; color: var(--text-3); }

.avail-notice { font-size: 13px; color: var(--text-2); }
.also-on { font-size: 12px; color: var(--text-3); }
.also-on a { color: var(--accent-sky); }
@media (hover: hover) and (pointer: fine) {
  .also-on a:hover { text-decoration: underline; text-underline-offset: 2px; }
}
.avail-notice strong { color: var(--text); font-weight: 600; }

.card-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: auto;
  padding-top: 6px;
}
.btn-view, .btn-share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 120ms var(--ease-out), background-color 150ms ease;
}
.btn-view { background: var(--text); color: #000; }
.btn-share { background: var(--surface-2); color: var(--text); }
.btn-view:active, .btn-share:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) {
  .btn-view:hover { background: #fff; }
  .btn-share:hover { background: var(--surface-3); }
}

.btn-load-more {
  display: flex;
  margin: 32px auto 0;
  min-height: 48px;
  padding: 0 24px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
  font-size: 15px;
  font-weight: 600;
  align-items: center;
  transition: transform 120ms var(--ease-out), background-color 150ms ease;
}
.btn-load-more:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) {
  .btn-load-more:hover { background: var(--surface-3); }
}

.empty-state {
  padding: 64px 24px;
  border-radius: 22px;
  background: var(--bg-elevated);
  box-shadow: inset 0 0 0 1px var(--border);
  text-align: center;
}
.empty-state h3 { margin: 0 0 8px; font-family: var(--font-display); font-size: 24px; letter-spacing: -0.02em; }
.empty-state p { margin: 0 auto 24px; max-width: 36ch; color: var(--text-2); }

/* Toast — enters and exits from the bottom edge */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  z-index: 200;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  background: rgba(40, 40, 44, 0.86);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 0 0 1px var(--border), 0 12px 32px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition: opacity 200ms ease, transform 300ms var(--ease-out);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 960px) {
  .filter-panel-inner { grid-template-columns: 1fr 1fr; }
  .properties-grid { gap: 12px; }
}

@media (max-width: 720px) {
  .app-header { padding: calc(20px + var(--safe-top)) 0 18px; }
  .main-title { font-size: 30px; }
  .subtitle { margin-bottom: 14px; font-size: 14px; }
  .stats-row { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
  .stat-card { padding: 8px 9px; border-radius: 12px; }
  .stat-value { font-size: 17px; }
  .stat-label { font-size: 10px; line-height: 1.25; }

  .filter-panel-inner { grid-template-columns: 1fr; gap: 14px; }

  .results-header { margin: 16px 0 12px; }
  .results-header h2 { font-size: 17px; }
  .legend-pills { gap: 10px; }

  /* Two cards per row: everything inside scales down to fit ~170px */
  .properties-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .property-card { border-radius: 14px; }
  .card-media { aspect-ratio: 4 / 3; }
  /* Walk badge on top, recency on the bottom edge so the two never collide at this width */
  .badge-top-left { top: 6px; left: 6px; }
  .badge-top-right { top: auto; right: 6px; bottom: 6px; }
  .badge-walk, .badge-recency, .badge-source { padding: 2px 7px; font-size: 10px; }
  .badge-source, .price-sub, .also-on { display: none; }
  .card-content { gap: 4px; padding: 10px; }
  .price-main { font-size: 18px; }
  .price-unit { font-size: 11px; }
  .bills-tag { padding: 1px 7px; font-size: 10px; }
  .card-title { font-size: 13px; }
  .spec-row, .avail-notice { font-size: 11px; }
  .spec-row { gap: 2px 6px; }
  .spec-item + .spec-item::before { margin-right: 6px; }
  .card-actions { gap: 6px; }
  .btn-view, .btn-share { min-height: 34px; padding: 0 10px; border-radius: 9px; font-size: 13px; }

  .footer-content { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .property-card { animation: card-fade 200ms ease both; animation-delay: 0ms; }
  @keyframes card-fade { from { opacity: 0; } }
  .filter-panel, .toolbar { transition: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .toolbar { background: #000; backdrop-filter: none; -webkit-backdrop-filter: none; }
  .stat-card, .badge-walk, .badge-recency, .badge-source, .toast { backdrop-filter: none; -webkit-backdrop-filter: none; background: #1c1c1e; }
}
