/* ─── ImoRadar Design System ──────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #0a0f1c;
  --slate: #3d4663;
  --mist: #8892b0;
  --cloud: #e8ecf4;
  --snow: #f7f9fc;
  --white: #ffffff;
  --emerald: #10b981;
  --emerald-dark: #059669;
  --emerald-glow: rgba(16, 185, 129, 0.12);
  --coral: #f97066;
  --coral-bg: rgba(249, 112, 102, 0.1);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.1);
  --blue: #6366f1;
  --blue-bg: rgba(99, 102, 241, 0.1);
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(10,15,28,0.04);
  --shadow-md: 0 4px 16px rgba(10,15,28,0.06);
  --shadow-lg: 0 12px 40px rgba(10,15,28,0.08);
}

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background: var(--snow);
  line-height: 1.6;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-family: 'Space Grotesk', sans-serif;
  line-height: 1.15;
}

a { color: var(--emerald-dark); text-decoration: none; }
a:hover { color: var(--emerald); }

/* ─── App Nav ─────────────────────────────────────────────── */
.app-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0.875rem 1.5rem;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--cloud);
}
.app-nav .nav-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.app-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.35rem;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.app-logo .dot {
  width: 9px;
  height: 9px;
  background: var(--emerald);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--emerald-glow);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.nav-links a {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--slate);
  padding: 0.5rem 0.875rem;
  border-radius: 8px;
  transition: all 0.15s;
}
.nav-links a:hover, .nav-links a.active {
  color: var(--ink);
  background: var(--snow);
}
.nav-links a.active {
  color: var(--emerald-dark);
  background: var(--emerald-glow);
}
.nav-badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--emerald-dark);
  background: var(--emerald-glow);
  padding: 0.2rem 0.5rem;
  border-radius: 100px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ─── Layout ──────────────────────────────────────────────── */
.page-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}
.page-header {
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-header p {
  color: var(--mist);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

/* ─── Stats Bar ───────────────────────────────────────────── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--cloud);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: box-shadow 0.2s;
}
.stat-card:hover {
  box-shadow: var(--shadow-sm);
}
.stat-card .stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--mist);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}
.stat-card .stat-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.1;
}
.stat-card .stat-sub {
  font-size: 0.8rem;
  color: var(--mist);
  margin-top: 0.25rem;
}
.stat-card .stat-sub.positive { color: var(--emerald-dark); }
.stat-card .stat-sub.negative { color: var(--coral); }

/* ─── Toolbar ─────────────────────────────────────────────── */
.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  padding: 1rem 1.25rem;
  background: var(--white);
  border: 1px solid var(--cloud);
  border-radius: var(--radius);
}
.search-input {
  flex: 1;
  min-width: 200px;
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  font-family: inherit;
  border: 1px solid var(--cloud);
  border-radius: 8px;
  background: var(--snow);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus {
  border-color: var(--emerald);
  box-shadow: 0 0 0 3px var(--emerald-glow);
}
.search-input::placeholder { color: var(--mist); }

.filter-select {
  padding: 0.6rem 2rem 0.6rem 0.75rem;
  font-size: 0.825rem;
  font-family: inherit;
  border: 1px solid var(--cloud);
  border-radius: 8px;
  background: var(--snow) url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%238892b0' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e") no-repeat right 0.6rem center/10px;
  color: var(--ink);
  outline: none;
  cursor: pointer;
  appearance: none;
  transition: border-color 0.15s;
}
.filter-select:focus {
  border-color: var(--emerald);
  box-shadow: 0 0 0 3px var(--emerald-glow);
}

.filter-btn {
  padding: 0.6rem 1rem;
  font-size: 0.825rem;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid var(--cloud);
  border-radius: 8px;
  background: var(--white);
  color: var(--slate);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.filter-btn:hover {
  border-color: var(--emerald);
  color: var(--emerald-dark);
}
.filter-btn.active {
  background: var(--emerald-glow);
  border-color: var(--emerald);
  color: var(--emerald-dark);
}

.sort-select {
  padding: 0.6rem 2rem 0.6rem 0.75rem;
  font-size: 0.825rem;
  font-family: inherit;
  border: 1px solid var(--cloud);
  border-radius: 8px;
  background: var(--snow) url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%238892b0' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e") no-repeat right 0.6rem center/10px;
  color: var(--ink);
  outline: none;
  cursor: pointer;
  appearance: none;
}

/* ─── Property Grid ───────────────────────────────────────── */
.properties-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1rem;
}

.property-card {
  background: var(--white);
  border: 1px solid var(--cloud);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all 0.2s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}
.property-card:hover {
  box-shadow: var(--shadow-md);
  border-color: rgba(16, 185, 129, 0.25);
  transform: translateY(-2px);
}

.card-image {
  height: 140px;
  background: linear-gradient(135deg, var(--snow) 0%, var(--cloud) 100%);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card-image .placeholder-icon {
  font-size: 2.5rem;
  opacity: 0.3;
}
.card-badges {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  right: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}
.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  white-space: nowrap;
}
.badge-source {
  background: rgba(255,255,255,0.9);
  color: var(--slate);
  backdrop-filter: blur(8px);
}
.badge-drop {
  background: var(--emerald);
  color: white;
}
.badge-new {
  background: var(--amber);
  color: white;
}
.badge-stale {
  background: var(--coral-bg);
  color: var(--coral);
}

.card-body {
  padding: 1rem 1.25rem 1.25rem;
}
.card-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.25rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-location {
  font-size: 0.8rem;
  color: var(--mist);
  margin-bottom: 0.75rem;
}

.card-price-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.card-price {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--ink);
}
.card-original-price {
  font-size: 0.8rem;
  color: var(--mist);
  text-decoration: line-through;
}
.card-drop-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--emerald-dark);
  background: var(--emerald-glow);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

.card-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.78rem;
  color: var(--slate);
}
.card-meta span {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--cloud);
  font-size: 0.75rem;
  color: var(--mist);
}
.card-footer .days {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.card-footer .changes {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.card-footer .changes.has-changes { color: var(--emerald-dark); }

/* ─── Results Info ────────────────────────────────────────── */
.results-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--mist);
}
.results-info .count {
  font-weight: 600;
  color: var(--ink);
}

/* ─── Pagination ──────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 2rem;
  padding-bottom: 2rem;
}
.pagination button {
  padding: 0.5rem 0.875rem;
  font-size: 0.825rem;
  font-family: inherit;
  border: 1px solid var(--cloud);
  border-radius: 8px;
  background: var(--white);
  color: var(--slate);
  cursor: pointer;
  transition: all 0.15s;
}
.pagination button:hover:not(:disabled) {
  border-color: var(--emerald);
  color: var(--emerald-dark);
}
.pagination button.active {
  background: var(--emerald);
  border-color: var(--emerald);
  color: white;
}
.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Empty State ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--mist);
}
.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}
.empty-state h3 {
  font-size: 1.1rem;
  color: var(--slate);
  margin-bottom: 0.5rem;
}

/* ─── Loading ─────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--mist);
  gap: 0.5rem;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--cloud);
  border-top-color: var(--emerald);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Property Detail ─────────────────────────────────────── */
.detail-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.5rem;
  align-items: start;
}
.detail-main {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.detail-card {
  background: var(--white);
  border: 1px solid var(--cloud);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
}
.detail-card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.detail-header {
  padding: 2rem;
}
.detail-header .breadcrumb {
  font-size: 0.8rem;
  color: var(--mist);
  margin-bottom: 1rem;
}
.detail-header .breadcrumb a { color: var(--emerald-dark); }
.detail-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}
.detail-header .location {
  font-size: 0.9rem;
  color: var(--mist);
  margin-bottom: 1.25rem;
}
.detail-header .tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.tag {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  background: var(--snow);
  color: var(--slate);
  border: 1px solid var(--cloud);
}
.tag.green { background: var(--emerald-glow); color: var(--emerald-dark); border-color: transparent; }
.tag.coral { background: var(--coral-bg); color: var(--coral); border-color: transparent; }
.tag.amber { background: var(--amber-bg); color: var(--amber); border-color: transparent; }

/* ─── Price Panel ─────────────────────────────────────────── */
.price-panel {
  position: sticky;
  top: 80px;
}
.price-current {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}
.price-original {
  font-size: 1rem;
  color: var(--mist);
  text-decoration: line-through;
  margin-top: 0.25rem;
}
.price-drop-info {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--emerald-dark);
  background: var(--emerald-glow);
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  margin-top: 0.75rem;
}
.price-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--cloud);
}
.price-detail-item {
  text-align: center;
  padding: 0.75rem;
  background: var(--snow);
  border-radius: 8px;
}
.price-detail-item .pd-value {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--ink);
}
.price-detail-item .pd-label {
  font-size: 0.7rem;
  color: var(--mist);
  margin-top: 0.15rem;
}
.idealista-link {
  display: block;
  text-align: center;
  margin-top: 1.25rem;
  padding: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--emerald-dark);
  background: var(--emerald-glow);
  border: 1px solid var(--emerald);
  border-radius: 10px;
  transition: all 0.15s;
}
.idealista-link:hover {
  background: var(--emerald);
  color: white;
}

/* ─── Chart ───────────────────────────────────────────────── */
.chart-container {
  position: relative;
  height: 280px;
  margin-top: 0.5rem;
}
.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ─── Price Timeline ──────────────────────────────────────── */
.price-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.timeline-event {
  display: flex;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--cloud);
  align-items: flex-start;
}
.timeline-event:last-child { border-bottom: none; }
.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cloud);
  margin-top: 0.35rem;
  flex-shrink: 0;
}
.timeline-dot.first { background: var(--mist); }
.timeline-dot.drop { background: var(--emerald); }
.timeline-dot.increase { background: var(--coral); }
.timeline-event-info {
  flex: 1;
}
.timeline-event-price {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
}
.timeline-event-change {
  font-size: 0.8rem;
  font-weight: 500;
  margin-left: 0.5rem;
}
.timeline-event-change.drop { color: var(--emerald-dark); }
.timeline-event-change.increase { color: var(--coral); }
.timeline-event-date {
  font-size: 0.78rem;
  color: var(--mist);
  margin-top: 0.1rem;
}

/* ─── Property Features ───────────────────────────────────── */
.features-grid-detail {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}
.feature-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--snow);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--slate);
}
.feature-item .f-icon {
  font-size: 1.1rem;
}
.feature-item strong {
  color: var(--ink);
  font-weight: 600;
}

/* ─── Similar Properties ──────────────────────────────────── */
.similar-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}
.similar-card {
  padding: 1rem;
  background: var(--snow);
  border: 1px solid var(--cloud);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: all 0.15s;
}
.similar-card:hover {
  border-color: var(--emerald);
  box-shadow: var(--shadow-sm);
}
.similar-card .sc-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.25rem;
  line-height: 1.3;
}
.similar-card .sc-meta {
  font-size: 0.75rem;
  color: var(--mist);
  margin-bottom: 0.5rem;
}
.similar-card .sc-price {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
}
.similar-card .sc-drop {
  font-size: 0.75rem;
  color: var(--emerald-dark);
  font-weight: 500;
}

/* ─── Back Link ───────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--mist);
  margin-bottom: 1rem;
}
.back-link:hover { color: var(--emerald-dark); }

/* ─── Mobile ──────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .detail-layout {
    grid-template-columns: 1fr;
  }
  .price-panel { position: static; }
}

@media (max-width: 768px) {
  .stats-bar {
    grid-template-columns: repeat(2, 1fr);
  }
  .properties-grid {
    grid-template-columns: 1fr;
  }
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar .search-input { min-width: auto; }
  .features-grid-detail {
    grid-template-columns: repeat(2, 1fr);
  }
  .similar-grid {
    grid-template-columns: 1fr;
  }
  .page-header h1 { font-size: 1.4rem; }
  .nav-links { display: none; }
}

@media (max-width: 480px) {
  .stats-bar { grid-template-columns: 1fr; }
  .features-grid-detail { grid-template-columns: 1fr; }
  .card-meta { flex-wrap: wrap; gap: 0.5rem; }
}
