@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=Space+Mono:wght@400;700&display=swap');

:root {
  --bg: #f0f6ff;
  --surface: rgba(255,255,255,0.95);
  --surface-hover: rgba(240,246,255,0.95);
  --border: rgba(0, 100, 180, 0.12);
  --border-bright: rgba(0, 148, 220, 0.4);
  --text: #0c1a2e;
  --muted: #5a7a9a;
  --cyan: #0094d4;
  --cyan-dim: rgba(0, 148, 212, 0.1);
  --cyan-glow: rgba(0, 148, 212, 0.08);
  --purple: #7c3aed;
  --green: #059669;
  --red: #dc2626;
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Animated grid background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,148,212,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,148,212,0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  top: -40%;
  left: -20%;
  width: 80%;
  height: 80%;
  background: radial-gradient(ellipse, rgba(0, 148, 212, 0.08) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── Nav ─────────────────────────────────────────────── */
.v2-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 56px;
  background: rgba(240, 246, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.v2-nav .brand {
  font-family: 'Space Mono', monospace;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--cyan);
  text-shadow: 0 0 18px rgba(0, 212, 255, 0.5);
}

.v2-nav .nav-links {
  display: flex;
  gap: 6px;
  align-items: center;
}

.v2-nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}

.v2-nav a:hover,
.v2-nav a.active {
  color: var(--cyan);
  background: var(--cyan-dim);
}

/* ── Layout ──────────────────────────────────────────── */
.v2-layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: auto;
  gap: 0;
  min-height: calc(100vh - 56px);
}

/* ── Sidebar ─────────────────────────────────────────── */
.v2-sidebar {
  border-right: 1px solid var(--border);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: rgba(255, 255, 255, 0.6);
  overflow-y: auto;
  height: calc(100vh - 56px);
  position: sticky;
  top: 56px;
}

.sidebar-title {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--cyan);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-label {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.v2-select,
.v2-input {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
  -webkit-appearance: none;
  color-scheme: light;
}

.v2-select:focus,
.v2-input:focus {
  outline: none;
  border-color: var(--border-bright);
  box-shadow: 0 0 0 3px var(--cyan-glow);
}

.v2-select option {
  background: #f0f6ff;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 4px;
}

.btn-primary {
  padding: 11px 16px;
  background: var(--cyan);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: opacity 0.2s, box-shadow 0.2s;
  box-shadow: 0 0 18px rgba(0, 148, 212, 0.25);
}

.btn-primary:hover {
  opacity: 0.9;
  box-shadow: 0 0 28px rgba(0, 148, 212, 0.4);
}

.btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  padding: 10px 16px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--border-bright);
}

.status-bar {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 38px;
  word-break: break-all;
}

.status-bar.searching {
  color: var(--cyan);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Main content ────────────────────────────────────── */
.v2-main {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
}

/* ── Map ─────────────────────────────────────────────── */
.v2-map-section {
  position: relative;
  border-bottom: 1px solid var(--border);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(240, 246, 255, 0.6);
}

.section-title {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--cyan);
}

.section-badge {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--cyan-dim);
  color: var(--cyan);
  border: 1px solid var(--border-bright);
}

#v2-map {
  height: 420px;
  width: 100%;
}

/* Override Leaflet popup styling */
.leaflet-popup-content-wrapper {
  background: #ffffff !important;
  border: 1px solid var(--border-bright) !important;
  border-radius: 10px !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15) !important;
  color: var(--text) !important;
}

.leaflet-popup-tip {
  background: #ffffff !important;
}

.popup-address {
  font-weight: 600;
  font-size: 13px;
  color: var(--cyan);
  margin-bottom: 6px;
}

.popup-price {
  font-family: 'Space Mono', monospace;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.popup-details {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.popup-mls {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--purple);
  letter-spacing: 1px;
}

/* ── Results table ───────────────────────────────────── */
.v2-results-section {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(240, 246, 255, 0.6);
}

.btn-export {
  padding: 7px 14px;
  background: transparent;
  color: var(--cyan);
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  letter-spacing: 0.5px;
}

.btn-export:hover {
  background: var(--cyan-dim);
  box-shadow: 0 0 12px rgba(0, 148, 212, 0.2);
}

.btn-export:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.v2-table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 420px;
  flex: 1;
}

.v2-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

.v2-table thead th {
  position: sticky;
  top: 0;
  background: #e8f0fb;
  padding: 10px 14px;
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  text-align: left;
}

.v2-table tbody tr {
  transition: background 0.15s;
}

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

.v2-table tbody td {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid rgba(0, 100, 180, 0.08);
  white-space: nowrap;
}

.v2-table tbody td a {
  color: var(--cyan);
  text-decoration: none;
}

.v2-table tbody td a:hover {
  text-decoration: underline;
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 1px;
}

/* ── AI Suggestions ──────────────────────────────────── */
.v2-suggest-section {
  border-top: 1px solid var(--border);
}

.suggest-body {
  padding: 20px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.suggest-input-wrap {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.suggest-textarea {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  padding: 12px 14px;
  resize: vertical;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.suggest-textarea:focus {
  outline: none;
  border-color: rgba(123, 94, 167, 0.5);
  box-shadow: 0 0 0 3px rgba(123, 94, 167, 0.08);
}

.suggest-textarea::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.btn-suggest {
  flex-shrink: 0;
  padding: 11px 20px;
  background: linear-gradient(135deg, #7b5ea7, #5a4080);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, box-shadow 0.2s;
  box-shadow: 0 0 18px rgba(123, 94, 167, 0.3);
  white-space: nowrap;
}

.btn-suggest:hover {
  opacity: 0.9;
  box-shadow: 0 0 28px rgba(123, 94, 167, 0.5);
}

.btn-suggest:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.suggest-output {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.suggest-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: #7c3aed;
  letter-spacing: 1px;
  animation: pulse 1.4s ease-in-out infinite;
}

.suggest-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
  background: rgba(123, 94, 167, 0.05);
  border: 1px solid rgba(123, 94, 167, 0.15);
  border-radius: 10px;
  padding: 16px 18px;
  margin: 0;
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 768px) {
  html, body { font-size: 20px; }

  .sidebar-title { font-size: 16px; letter-spacing: 2px; }
  .filter-label { font-size: 16px; letter-spacing: 0.5px; text-transform: none; }
  .section-title { font-size: 16px; letter-spacing: 1px; }
  .section-badge { font-size: 14px; padding: 4px 12px; }
  .status-bar { font-size: 16px; }
  .empty-state { font-size: 16px; }

  .v2-nav .brand { font-size: 18px; }
  .v2-nav a { font-size: 16px; padding: 6px 12px; }

  .v2-table thead th { font-size: 15px; padding: 12px 14px; }
  .v2-table tbody td { font-size: 16px; padding: 14px; }

  .suggest-input-wrap {
    flex-direction: column;
  }

  .suggest-textarea {
    font-size: 16px; /* prevent iOS zoom */
    width: 100%;
  }

  .btn-suggest {
    width: 100%;
    padding: 15px;
    font-size: 16px;
  }

  .suggest-body { padding: 16px; }
  .suggest-text { font-size: 16px; line-height: 1.75; }
  .v2-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .v2-sidebar {
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 20px 16px;
    gap: 16px;
  }

  .filter-group { gap: 8px; }
  .v2-select, .v2-input { font-size: 16px; padding: 11px 12px; } /* prevent iOS zoom */

  .sidebar-actions {
    flex-direction: row;
  }

  .btn-primary, .btn-secondary {
    flex: 1;
    font-size: 15px;
    padding: 13px 16px;
  }

  #v2-map { height: 220px; }
  .map-placeholder { height: 220px; font-size: 11px; }

  .section-header { padding: 12px 16px; }
  .results-header { padding: 12px 16px; }

  .v2-table-wrap { max-height: 220px; }
  .v2-results-section { flex: none; }
  .v2-main { min-height: auto; }
  .v2-layout { min-height: auto; }

  .v2-nav { padding: 0 16px; }
}

@media (max-width: 420px) {
  .v2-nav .brand { display: none; }
  .sidebar-actions { flex-direction: column; }
}

/* ── Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,212,255,0.15); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,212,255,0.3); }

/* ── Map placeholder ─────────────────────────────────── */
.map-placeholder {
  height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 2px;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 20px,
    rgba(0,212,255,0.015) 20px,
    rgba(0,212,255,0.015) 21px
  );
}
