/* FindDestination — CSS thuần, mobile-first, không framework */
:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --accent: #1e8449;
  --danger: #c0392b;
  --border: #e5e7eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
}

.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: #14532d;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 1000;
}
.topnav .brand { color: #fff; font-weight: 700; text-decoration: none; }
.topnav nav a {
  color: #d1fae5;
  text-decoration: none;
  margin-left: 0.9rem;
  font-weight: 600;
}
.topnav nav a:hover { color: #fff; }

main { padding: 0.8rem; max-width: 1200px; margin: 0 auto; }
.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 1rem; }

/* Bộ lọc */
.searchbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.searchbar input[type="search"] {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--card);
  color: var(--text);
}
.searchbar button {
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.clearq { color: var(--danger); text-decoration: none; margin-left: 0.3rem; }
.clearq:hover { text-decoration: underline; }

.filterbox {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.8rem;
  margin-bottom: 0.8rem;
}
.filterbox summary { cursor: pointer; font-weight: 600; padding: 0.2rem 0; }
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.6rem;
  padding-top: 0.6rem;
}
.filters label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--muted); gap: 0.2rem; }
.filters label.checkbox { flex-direction: row; align-items: center; gap: 0.4rem; align-self: end; }
.filters input:not([type="checkbox"]), .filters select {
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  width: 100%;
}
.filters label.checkbox input { width: auto; flex: none; margin: 0; }
.filters button {
  align-self: end;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.meta { color: var(--muted); font-size: 0.85rem; margin: 0.4rem 0.2rem; }

/* Card grid */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0.8rem;
}
.card {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
  /* Bỏ qua layout/paint cho card ngoài viewport. contain-intrinsic-size giữ chỗ
     bằng chiều cao ước lượng nên thanh cuộn không nhảy; 'auto' cho trình duyệt
     nhớ kích thước thật sau lần render đầu. */
  content-visibility: auto;
  contain-intrinsic-size: auto 360px;
}
.card:hover { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); transform: translateY(-2px); }
.card.excluded { opacity: 0.62; }

/* Phân trang */
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin: 1.2rem 0 0.4rem;
}
.pager .pg {
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}
.pager .pg.num { min-width: 2.2rem; text-align: center; }
.pager .pg.current { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.pager .pg.disabled { opacity: 0.4; }
.pager .gap { color: var(--muted); padding: 0 0.15rem; }

.thumb { position: relative; aspect-ratio: 4 / 3; background: #e2e8f0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .noimg { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); }

.badge {
  position: absolute;
  top: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
}
.badge.new { left: 8px; background: var(--danger); }
.badge.score { right: 8px; background: var(--accent); }
/* Badge giảm giá (Phase 3) — xanh lá = tin vui, đặt dưới badge score, không đè MỚI */
.badge.drop { top: 36px; right: 8px; background: var(--accent); }
.badge.inline { position: static; background: var(--danger); }
/* Badge nghi giá mồi / sai danh mục — vàng cảnh báo, góc dưới phải */
.badge.suspect { top: auto; bottom: 8px; right: 8px; background: #b45309; }

/* Badge nguồn tin — màu khác nhau theo nguồn (Phase 2) */
.badge.src { top: auto; bottom: 8px; left: 8px; }
.badge.src.inline { position: static; font-size: 0.72rem; vertical-align: middle; }
.src-chotot { background: #e67e22; }
.src-batdongsan { background: #c0392b; }
.src-homedy { background: #2980b9; }
.src-mogi { background: #8e44ad; }
.src-onehousing { background: #16a085; }

/* Badge "🔁 N nguồn" — tin trùng gộp từ nhiều nguồn */
.badge.dup { top: auto; bottom: 8px; right: 8px; background: #34495e; }

/* Danh sách tin trùng ở nguồn khác (trang chi tiết) */
.dup-list { margin: 0.4rem 0 0.8rem; padding-left: 1.1rem; }
.dup-list li { margin: 0.3rem 0; font-size: 0.92rem; }

/* Ghi chú vị trí ước lượng (geo_precision != exact) */
.geo-note { color: #b45309; font-size: 0.85rem; }

/* Khối tóm tắt giảm giá + số ngày rao (trang chi tiết, Phase 3) */
.price-drop-summary { margin: 0.6rem 0; }
.price-drop-summary p { margin: 0.25rem 0; font-size: 0.92rem; }
.price-drop-summary .drop-line { color: var(--accent); font-weight: 600; }
.price-drop-summary .rise-line { color: var(--danger); }
.price-drop-summary .days-on-market { color: var(--muted); }

.card .body { padding: 0.6rem 0.75rem 0.8rem; }
.card h3 {
  margin: 0 0 0.3rem;
  font-size: 0.98rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.price { color: var(--danger); font-weight: 700; margin: 0.15rem 0; }
.price.big { font-size: 1.25rem; }
.attrs { color: var(--muted); font-size: 0.85rem; margin: 0.15rem 0; }
.reason { color: var(--danger); font-size: 0.8rem; margin: 0.3rem 0 0; }
.reason.big { font-size: 0.95rem; background: #fdecea; padding: 0.5rem 0.7rem; border-radius: 8px; }
/* Cảnh báo nghi giá mồi — vàng, chữ nâu sẫm */
.reason.big.warn { color: #7c2d12; background: #fef3c7; }
.empty { color: var(--muted); padding: 2rem 0.5rem; }

/* Bản đồ */
#map { height: calc(100vh - 160px); min-height: 380px; border-radius: 12px; }
.map-legend { margin-top: 0.5rem; }

/* Trang chi tiết */
.detail { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; }
.detail h2 { margin-top: 0; font-size: 1.15rem; }
.gallery {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.8rem;
}
.gallery img { height: 220px; border-radius: 8px; flex: 0 0 auto; max-width: 90vw; object-fit: cover; cursor: zoom-in; }

/* Lightbox xem ảnh phóng to — full màn hình, nút đè lên ảnh */
body.noscroll { overflow: hidden; }
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(238, 239, 241, 0.99);
}
.lightbox[hidden] { display: none; }
#lb-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.lb-counter {
  position: absolute;
  top: 12px;
  left: 14px;
  z-index: 3;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.85);
  padding: 4px 10px;
  border-radius: 999px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.15);
}
.lb-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 4;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.18);
}
/* Vùng bấm chuyển ảnh: dải dọc cao full màn hình, rộng 30% mỗi bên, đè lên ảnh */
.lb-nav {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 3;
  width: 30%;
  min-width: 90px;
  max-width: 340px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 0 14px;
}
.lb-nav[hidden] { display: none; }
.lb-prev { left: 0; justify-content: flex-start; }
.lb-next { right: 0; justify-content: flex-end; }
/* Trên thiết bị cảm ứng: ẩn nút mũi tên vì đã vuốt trái/phải được, tránh che ảnh khi zoom xem chi tiết */
@media (hover: none) and (pointer: coarse) {
  .lb-nav { display: none; }
}
.lb-arrow {
  width: 54px;
  height: 54px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  line-height: 1;
}
.lb-nav:hover .lb-arrow, .lb-close:hover { background: #fff; }
/* Chạm/bấm nút chuyển hoặc đóng ảnh: bỏ vệt chữ nhật (tap-highlight của mobile +
   outline focus bao quanh cả vùng nút to). Giữ vòng focus gọn cho bàn phím. */
.lb-nav, .lb-close { -webkit-tap-highlight-color: transparent; }
.lb-nav:focus, .lb-close:focus { outline: none; }
.lb-nav:focus-visible .lb-arrow,
.lb-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

table.info { border-collapse: collapse; width: 100%; margin: 0.6rem 0; }
table.info th, table.info td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.92rem; vertical-align: top; }
table.info th { color: var(--muted); font-weight: 600; white-space: nowrap; width: 1%; }

.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0.8rem 0; }
.btn {
  display: inline-block;
  padding: 0.55rem 0.9rem;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
}
.btn:hover { filter: brightness(1.08); }

/* Nút lên đầu trang — nổi góc dưới phải, chỉ hiện khi đã cuộn quá 1 màn hình.
   z-index 900: dưới topnav (1000) và lightbox (2000) → lightbox che nút khi mở ảnh. */
.to-top {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 900;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  /* opacity + visibility (không phải display/hidden) để fade được, đồng thời
     khi ẩn thì không bấm được và không nằm trong tab order. */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.to-top.show { opacity: 1; visibility: visible; }
.to-top:hover { filter: brightness(1.08); }
.to-top:focus { outline: none; }
.to-top:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .to-top { transition: none; }
}

@media (max-width: 480px) {
  .topnav { flex-wrap: wrap; }
  .gallery img { height: 170px; }
}
