/* ===== CSS Variables & Reset ===== */
:root {
  /* Colors - Light mode */
  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-surface-hover: #f5f5f5;
  --color-text: #1a1a1a;
  --color-text-secondary: #6b7280;
  --color-text-muted: #9ca3af;
  --color-border: #e5e7eb;
  --color-border-strong: #d1d5db;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #dbeafe;
  --color-success: #059669;
  --color-success-light: #d1fae5;
  --color-error: #dc2626;
  --color-error-light: #fee2e2;
  --color-warning: #d97706;
  --color-warning-light: #fef3c7;
  /* Highlight for listings with >60% completeness */
  --color-complete-bg: #e8f5e9;
  --color-complete-border: #a5d6a7;

  /* Status colors */
  --color-for_sale: #2563eb;
  --color-for_rent: #7c3aed;
  --color-sold: #6b7280;
  --color-pending: #d97706;

  /* Type colors */
  --color-house: #059669;
  --color-condo: #2563eb;
  --color-land: #d97706;
  --color-commercial: #dc2626;
  --color-farm: #059669;
  --color-investment: #7c3aed;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Borders */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;

  /* Layout */
  --max-width: 1200px;
  --header-height: 64px;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #111827;
    --color-surface: #1f2937;
    --color-surface-hover: #374151;
    --color-text: #f9fafb;
    --color-text-secondary: #d1d5db;
    --color-text-muted: #9ca3af;
    --color-border: #374151;
    --color-border-strong: #4b5563;
    --color-primary: #3b82f6;
    --color-primary-hover: #60a5fa;
    --color-primary-light: #1e3a5f;
    --color-success-light: #064e3b;
    --color-error-light: #7f1d1d;
    --color-warning-light: #78350f;
    --color-complete-bg: #16361f;
    --color-complete-border: #2f6b43;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  }
}

[data-theme="dark"] {
  --color-bg: #111827;
  --color-surface: #1f2937;
  --color-surface-hover: #374151;
  --color-text: #f9fafb;
  --color-text-secondary: #d1d5db;
  --color-text-muted: #9ca3af;
  --color-border: #374151;
  --color-border-strong: #4b5563;
  --color-primary: #3b82f6;
  --color-primary-hover: #60a5fa;
  --color-primary-light: #1e3a5f;
  --color-success-light: #064e3b;
  --color-error-light: #7f1d1d;
  --color-warning-light: #78350f;
  --color-complete-bg: #16361f;
  --color-complete-border: #2f6b43;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

[data-theme="light"] {
  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-surface-hover: #f5f5f5;
  --color-text: #1a1a1a;
  --color-text-secondary: #6b7280;
  --color-text-muted: #9ca3af;
  --color-border: #e5e7eb;
  --color-border-strong: #d1d5db;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #dbeafe;
  --color-success-light: #d1fae5;
  --color-error-light: #fee2e2;
  --color-warning-light: #fef3c7;
  --color-complete-bg: #e8f5e9;
  --color-complete-border: #a5d6a7;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.15);
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* Focus visible */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  background: var(--color-primary);
  color: white;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  z-index: 1000;
  text-decoration: none;
}

.skip-link:focus {
  top: var(--space-md);
}

/* ===== Header & Navigation ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  height: var(--header-height);
  box-shadow: var(--shadow-sm);
}

.nav {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-md);
  height: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-xl);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--color-text);
  text-decoration: none;
  flex-shrink: 0;
}

.nav-brand:hover {
  text-decoration: none;
  color: var(--color-primary);
}

.brand-icon {
  font-size: 1.5rem;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  list-style: none;
  margin-left: auto;
}

/* Nav items styled as buttons (links + the logout submit button share this). */
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

.nav-btn:hover {
  color: var(--color-primary);
  border-color: var(--color-primary);
  background: var(--color-surface-hover);
  text-decoration: none;
}

.nav-btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Active page gets a filled, low-key highlight. */
.nav-btn.active {
  color: var(--color-primary);
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

/* Primary call-to-action (e.g. Register). */
.nav-btn-primary {
  color: #fff;
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.nav-btn-primary:hover {
  color: #fff;
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  box-shadow: var(--shadow-sm);
}

.nav-user {
  display: flex;
  align-items: center;
}

.nav-user .user-email {
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  display: inline-block;
}

.nav-form {
  display: inline;
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-sm);
}

.hamburger {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--color-text);
  position: relative;
  transition: background var(--transition-fast);
}

.hamburger::before,
.hamburger::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 2px;
  background: var(--color-text);
  left: 0;
  transition: transform var(--transition-fast);
}

.hamburger::before { top: -8px; }
.hamburger::after { top: 8px; }

.theme-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-sm);
  font-size: 1.25rem;
}

.theme-icon-light { display: none; }
.theme-icon-dark { display: inline; }

[data-theme="light"] .theme-icon-light { display: inline; }
[data-theme="light"] .theme-icon-dark { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-light { display: inline; }
  :root:not([data-theme="light"]) .theme-icon-dark { display: none; }
}

/* ===== Main Content ===== */
.main {
  flex: 1;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-xl) var(--space-md);
  width: 100%;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  color: white;
}

.btn-outline {
  background: transparent;
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

.btn-outline:hover {
  background: var(--color-surface-hover);
}

.btn-sm {
  padding: var(--space-xs) var(--space-md);
  font-size: 0.8125rem;
}

.btn-full {
  width: 100%;
}

.btn-favorite {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  padding: var(--space-sm) var(--space-xl);
}

.btn-favorite:hover {
  border-color: var(--color-error);
  color: var(--color-error);
}

.btn-favorite.favorited {
  border-color: var(--color-error);
  color: var(--color-error);
}

.btn-favorite.favorited .favorite-icon {
  color: var(--color-error);
}

.btn-login-prompt {
  opacity: 0.6;
  cursor: default;
}

/* ===== Card Favorite Heart Button ===== */
.card-fav-btn {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  border: none;
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  z-index: 2;
}

.card-fav-btn:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.card-fav-btn .fav-heart {
  font-size: 1rem;
  line-height: 1;
  color: var(--color-text-muted);
  transition: color 0.15s ease;
}

.card-fav-btn.favorited .fav-heart {
  color: var(--color-error);
}

/* Table view favorite button */
.td-fav {
  width: 40px;
  text-align: center;
}

.td-fav .card-fav-btn {
  position: static;
  box-shadow: none;
}

.td-fav .card-fav-btn:hover {
  box-shadow: none;
}

.btn-clear {
  margin-top: var(--space-sm);
}

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 2px var(--space-sm);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-status {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.badge-for_sale { background: var(--color-primary-light); color: var(--color-for_sale); }
.badge-for_rent { background: #f3e8ff; color: var(--color-for_rent); }
.badge-sold { background: #f3f4f6; color: var(--color-sold); }
.badge-pending { background: var(--color-warning-light); color: var(--color-pending); }

.badge-type {
  background: var(--color-surface-hover);
  color: var(--color-text-secondary);
}

.badge-house { color: var(--color-house); }
.badge-condo { color: var(--color-condo); }
.badge-land { color: var(--color-land); }
.badge-commercial { color: var(--color-commercial); }
.badge-farm { color: var(--color-farm); }
.badge-investment { color: var(--color-investment); }

/* ===== Alerts ===== */
.alert {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
}

.alert-success {
  background: var(--color-success-light);
  color: var(--color-success);
  border: 1px solid var(--color-success);
}

.alert-error {
  background: var(--color-error-light);
  color: var(--color-error);
  border: 1px solid var(--color-error);
}

/* ===== Hero ===== */
.hero {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
  margin-bottom: var(--space-2xl);
}

.hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: var(--space-md);
}

.hero-subtitle {
  font-size: 1.125rem;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xl);
}

/* ===== Stats Row ===== */
.stats-row {
  display: flex;
  justify-content: center;
  gap: var(--space-2xl);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}

.stat {
  text-align: center;
}

.stat-number {
  display: block;
  font-size: 2rem;
  font-weight: 800;
  color: var(--color-primary);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}

/* ===== Country Chips ===== */
.country-chips {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-sm);
  max-width: 28rem;
  margin: 0 auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--color-text);
  transition: all var(--transition-fast);
}

.chip:hover {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
  text-decoration: none;
}

/* Country name pushed to the left; count bubbles grouped on the right. */
.chip-name {
  margin-right: auto;
}

.chip-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: var(--space-xs, 0.25rem);
  padding: 0.1em 0.45em;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

/* High-completeness count (>75%) in green to distinguish from total. */
.chip-count-quality {
  background: var(--color-success, #16a34a);
}

.chip:hover .chip-count {
  background: rgba(255, 255, 255, 0.3);
}

/* ===== Sections ===== */
.section {
  margin-bottom: var(--space-2xl);
}

.section h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-lg);
}

.section-cta {
  text-align: center;
  margin-top: var(--space-xl);
}

/* ===== Listings Grid ===== */
.listings-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-lg);
}

/* ===== Listing Card ===== */
.listing-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--color-border);
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

/* Listings with >60% completeness get a light green background highlight. */
.listing-card.listing-complete {
  background: var(--color-complete-bg);
  border-color: var(--color-complete-border);
}

.listing-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-image {
  position: relative;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  background: var(--color-surface-hover);
}

.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-normal);
}

.listing-card:hover .card-image img {
  transform: scale(1.05);
}

.card-image-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

.placeholder-icon {
  font-size: 3rem;
  opacity: 0.3;
}

.card-body {
  padding: var(--space-md);
}

.card-badges {
  display: flex;
  gap: var(--space-xs);
  margin-bottom: var(--space-sm);
  flex-wrap: wrap;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: var(--space-sm);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-title a {
  color: var(--color-text);
}

.card-title a:hover {
  color: var(--color-primary);
}

.card-price {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: var(--space-sm);
}

.card-meta {
  display: flex;
  gap: var(--space-md);
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xs);
}

.card-updated {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* ===== Showcase Page ===== */
.showcase-page {
  min-height: 60vh;
}

.showcase-header {
  margin-bottom: var(--space-xl);
}

.showcase-header .page-title {
  margin-bottom: var(--space-sm);
}

.showcase-subtitle {
  font-size: 1.0625rem;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-md);
}

/* ===== Listings Page Layout ===== */
.listings-page {
  min-height: 60vh;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: var(--space-xl);
}

.listings-layout {
  /* removed — filters now sit below title as full-width collapsible panel */
}

.listings-content {
  margin-top: var(--space-md);
}

.listings-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-lg);
  flex-wrap: wrap;
  gap: var(--space-md);
}

.results-count {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}

.view-toggle {
  display: flex;
  gap: var(--space-xs);
}

.view-btn {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 1.125rem;
  transition: all var(--transition-fast);
}

.view-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.view-btn:hover:not(.active) {
  background: var(--color-surface-hover);
}

/* ===== Filters ===== */
.filters {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: max-height 0.3s ease;
}

/* Filter toggle button */
.filter-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.filter-toggle:hover {
  background: var(--color-surface-hover);
}

.filter-toggle-icon {
  display: inline-block;
  font-size: 0.75rem;
  transition: transform 0.3s ease;
}

.filter-toggle[aria-expanded="true"] .filter-toggle-icon {
  transform: rotate(90deg);
}

.filter-toggle-label {
  flex: 1;
  text-align: center;
  font-size: 1.875rem; /* ~2x the button's base size — prominent "Filters" label */
}

/* Active filter count badge */
.filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.375rem;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
}

.filter-badge:empty {
  display: none;
}

/* Collapsible filter panel */
.filter-panel {
  padding: var(--space-lg);
}

.filter-panel[hidden] {
  display: none;
}

.filters h2 {
  display: none;
}

/* Filter row — side-by-side layout */
.filter-row {
  display: flex;
  gap: var(--space-lg);
  flex-wrap: wrap;
}

/* Country checkboxes in a row */
.filter-group > .filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-md);
}

/* Half-width fieldset within a filter row */
.filter-group-half {
  flex: 1;
  min-width: 200px;
}

.filter-group {
  border: none;
  padding: 0;
  margin: 0 0 var(--space-lg);
}

.filter-group legend {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-sm);
}

/* Filter actions — buttons at bottom */
.filter-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

.filter-group select,
.filter-group input[type="number"] {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition-fast);
}

.filter-group select:focus,
.filter-group input[type="number"]:focus {
  border-color: var(--color-primary);
  outline: none;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) 0;
  cursor: pointer;
  font-size: 0.875rem;
}

.checkbox-label input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--color-primary);
}

.price-range {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.price-range-row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.price-range-row label {
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.price-range-row input {
  flex: 1;
  min-width: 0;
}

.features-row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  margin-bottom: var(--space-sm);
}

.features-row label {
  font-size: 0.875rem;
  min-width: 90px;
}

.features-row input {
  flex: 1;
  min-width: 0;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-lg);
  margin-top: var(--space-xl);
  padding: var(--space-lg) 0;
}

.page-link {
  padding: var(--space-sm) var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 500;
  transition: all var(--transition-fast);
}

.page-link:hover {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
  text-decoration: none;
}

.page-info {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}

/* Top pagination — inline with toolbar */
.pagination-top {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-md);
  margin: 0;
  padding: 0;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--color-text-secondary);
}

.empty-state p {
  font-size: 1.125rem;
  margin-bottom: var(--space-lg);
}

/* ===== Property Detail ===== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xl);
}

.breadcrumb a {
  color: var(--color-text-secondary);
}

.breadcrumb a:hover {
  color: var(--color-primary);
}

.breadcrumb-sep {
  color: var(--color-text-muted);
}

.breadcrumb-current {
  color: var(--color-text);
  font-weight: 500;
}

.property-header {
  margin-bottom: var(--space-xl);
}

/* Price + type/status badges share one row above the title */
.property-title-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-md);
}

.property-header h1 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 800;
  margin: var(--space-md) 0;
  line-height: 1.3;
}

.property-price {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
  margin: 0;
}

.property-actions {
  margin-bottom: var(--space-xl);
}

/* ===== Gallery ===== */
.gallery {
  margin-bottom: var(--space-xl);
}

.gallery-main {
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-md);
  background: var(--color-surface-hover);
}

.gallery-main img {
  width: 100%;
  height: auto;
  display: block;
}

.gallery-thumbs {
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  padding-bottom: var(--space-sm);
}

.gallery-thumb {
  flex-shrink: 0;
  width: 120px;
  height: 80px;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  background: none;
  padding: 0;
  opacity: 0.6;
  transition: all var(--transition-fast);
}

.gallery-thumb:hover,
.gallery-thumb.active {
  opacity: 1;
  border-color: var(--color-primary);
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ===== Property Info Grid ===== */
.property-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.info-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
}

.info-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
}

.info-card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-sm) var(--space-md);
}

.info-card dt {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}

.info-card dd {
  font-weight: 500;
}

/* Analysis card — very light green */
.info-card-analysis {
  background: #f0faf0;
  border-color: #c8e6c8;
}

.info-card-analysis h3 {
  border-bottom-color: #c8e6c8;
}

.price-cut {
  color: #d32f2f;
  font-weight: 600;
}

.price-increase {
  color: #2e7d32;
  font-weight: 600;
}

.data-flags {
  color: #e65100;
  font-style: italic;
  font-size: 0.85rem;
}

/* Combined Property Details card — Location subsection */
.details-location {
  margin-top: var(--space-md);
  padding-top: var(--space-sm);
  border-top: 1px dashed var(--color-border);
}

.details-location h4 {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-sm);
}

.details-location p {
  margin: 0 0 var(--space-xs, 4px);
}

.details-location .coords {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}

/* Analysis card — status transitions & keyword signals */
.status-transition {
  font-weight: 600;
}

.signal-flags {
  color: #1565c0;
  font-size: 0.875rem;
}

.description-text {
  line-height: 1.7;
  color: var(--color-text-secondary);
}

/* ===== Auth Pages ===== */
.auth-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 60vh;
}

.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  width: 100%;
  max-width: 400px;
}

.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: var(--space-xl);
  text-align: center;
}

.auth-form {
  margin-bottom: var(--space-lg);
}

.auth-link {
  text-align: center;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}

/* ===== Error Pages ===== */
.error-page {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
}

.error-page h1 {
  font-size: 4rem;
  font-weight: 800;
  color: var(--color-primary);
  margin-bottom: var(--space-md);
}

.error-page p {
  font-size: 1.125rem;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xl);
}

/* ===== Footer ===== */
.site-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: var(--space-xl) var(--space-md);
  margin-top: auto;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  text-align: center;
}

.footer-inner p {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}

.footer-note {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
}

/* ===== Listings Table View ===== */
.listings-table-container {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.listings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.listings-table thead {
  background: var(--color-surface-hover);
  position: sticky;
  top: 0;
  z-index: 1;
}

.listings-table th {
  padding: var(--space-md) var(--space-sm);
  text-align: left;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  white-space: nowrap;
  border-bottom: 2px solid var(--color-border);
}

.listings-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast);
}

.listings-table th.sortable:hover {
  color: var(--color-primary);
}

.listings-table th.sort-asc::after {
  content: ' ▲';
  font-size: 0.7em;
}

.listings-table th.sort-desc::after {
  content: ' ▼';
  font-size: 0.7em;
}

.listings-table td {
  padding: var(--space-sm) var(--space-sm);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.listings-table tbody tr {
  transition: background var(--transition-fast);
}

.listings-table tbody tr.listing-complete {
  background: var(--color-complete-bg);
}

.listings-table tbody tr:hover {
  background: var(--color-surface-hover);
}

.listings-table tbody tr:last-child td {
  border-bottom: none;
}

.td-title {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Listing completeness column: a thin fill bar + percentage label. */
.td-completeness {
  min-width: 72px;
  white-space: nowrap;
}

.completeness-meter {
  display: block;
  height: 4px;
  border-radius: 2px;
  margin-bottom: 3px;
  background: linear-gradient(
    to right,
    var(--color-success) var(--pct, 0%),
    var(--color-border) var(--pct, 0%)
  );
}

.completeness-pct {
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}

.td-title a {
  color: var(--color-text);
  text-decoration: none;
  font-weight: 500;
}

.td-title a:hover {
  color: var(--color-primary);
}

.td-price {
  font-weight: 600;
  white-space: nowrap;
  color: var(--color-text);
}

.td-numeric {
  text-align: center;
}

/* Scrape-history table (property detail page only) — tighter than the grid table */
.property-history-table {
  font-size: 0.8125rem;
}
.property-history-table th {
  padding: 0.4rem var(--space-sm);
  font-size: 0.72rem;
}
.property-history-table td {
  padding: 0.4rem var(--space-sm);
}

.td-date {
  white-space: nowrap;
  color: var(--color-text-secondary);
  font-size: 0.8rem;
}

.td-age {
  white-space: nowrap;
  color: var(--color-text-secondary);
  font-size: 0.8rem;
}

/* Table thumbnail column */
.td-thumb {
  width: 48px;
  padding: 4px;
}

.td-thumb img {
  width: 48px;
  height: 32px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  display: block;
}

.td-thumb a {
  display: block;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .listings-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .nav-links {
    display: none;
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: var(--color-surface);
    flex-direction: column;
    padding: var(--space-md);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
  }

  .nav-links.open {
    display: flex;
    gap: var(--space-xs);
  }

  /* Stacked buttons read better full-width in the mobile drawer. */
  .nav-links li,
  .nav-form,
  .nav-links .nav-btn {
    width: 100%;
  }

  .nav-links .nav-btn {
    justify-content: center;
  }

  .nav-toggle {
    display: block;
  }

  .theme-toggle {
    display: block;
  }

  .listings-grid {
    grid-template-columns: 1fr;
  }

  .filter-row {
    flex-direction: column;
  }

  .stats-row {
    gap: var(--space-lg);
  }
}

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

  .property-info-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== Deltas (price changes) ===== */
.delta-cell {
  font-weight: 600;
  white-space: nowrap;
}

.delta-up {
  color: var(--color-error);
}

.delta-down {
  color: var(--color-success);
}

.delta-count {
  font-weight: 400;
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
}

.td-prev {
  color: var(--color-text-secondary);
}

/* Direction toggle links styled like the grid/table view buttons */
.view-btn[href] {
  text-decoration: none;
  color: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
}

/* ===== Print ===== */
@media print {
  .site-header,
  .site-footer,
  .filters,
  .property-actions {
    display: none;
  }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
