/* PropWatch shared theme. Light grey default, dark via [data-theme="dark"].
   Choice persists in localStorage; toggle button injected by theme.js. */

:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --text: #222222;
  --muted: #666666;
  --border: #dddddd;
  --link: #0b5fff;
  --badge-bg: #eeeeee;
  --badge-text: #222222;
  --badge-changed-bg: #fff3cd;
  --badge-changed-text: #664d03;
  --badge-watched-bg: #d4edda;
  --badge-watched-text: #0f5132;
  --badge-under-offer-bg: #f8d7da;
  --badge-under-offer-text: #842029;
  --badge-new-bg: #cce5ff;
  --badge-new-text: #084298;
  --error: #aa0000;
  --thumb-border: transparent;
  --thumb-active: #0ea800;
  --input-bg: #ffffff;
  --input-border: #bbbbbb;
}

[data-theme="dark"] {
  --bg: #16181d;
  --surface: #1f232b;
  --text: #e4e6eb;
  --muted: #9aa0aa;
  --border: #343a45;
  --link: #7aa5ff;
  --badge-bg: #343a45;
  --badge-text: #e4e6eb;
  --badge-changed-bg: #5a4a00;
  --badge-changed-text: #ffe69c;
  --badge-watched-bg: #0f5132;
  --badge-watched-text: #d1e7dd;
  --badge-under-offer-bg: #5c1a22;
  --badge-under-offer-text: #f8d7da;
  --badge-new-bg: #084298;
  --badge-new-text: #cfe2ff;
  --error: #ff8080;
  --thumb-active: #3ddc84;
  --input-bg: #262b34;
  --input-border: #4a5160;
}

body {
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--link); }
.muted { color: var(--muted); font-size: 0.85rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); }

input, select, button {
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  padding: 0.4rem;
}
button { cursor: pointer; }
button:hover { filter: brightness(0.94); }
[data-theme="dark"] button:hover { filter: brightness(1.25); }

.badge {
  display: inline-block; font-size: 0.75rem; padding: 0.1rem 0.4rem;
  border-radius: 4px; background: var(--badge-bg); color: var(--badge-text);
}
.badge.changed { background: var(--badge-changed-bg); color: var(--badge-changed-text); }
.badge.watched { background: var(--badge-watched-bg); color: var(--badge-watched-text); }
.badge.under_offer { background: var(--badge-under-offer-bg); color: var(--badge-under-offer-text); }
.badge.new { background: var(--badge-new-bg); color: var(--badge-new-text); }

#theme-toggle {
  font-size: 0.85rem;
  margin-left: 1rem;
}

/* Leaflet dark-mode: dim tiles slightly so the map doesn't glare. */
[data-theme="dark"] .leaflet-tile-pane { filter: brightness(0.85) saturate(0.9); }
[data-theme="dark"] .leaflet-container { background: #101216; }
[data-theme="dark"] .leaflet-popup-content-wrapper,
[data-theme="dark"] .leaflet-popup-tip,
[data-theme="dark"] .leaflet-control-layers,
[data-theme="dark"] .leaflet-bar a {
  background: var(--surface);
  color: var(--text);
}
.price-label {
  background: #fff; border: 1px solid #888; border-radius: 4px;
  padding: 1px 5px; font-size: 11px; font-weight: 600; white-space: nowrap;
  color: #111;
}
/* Gallery view: tall rows, photo strip + compressed details. */
.galrows { display: flex; flex-direction: column; gap: 0.75rem; }
.galrow {
  display: flex; gap: 0.75rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.6rem;
}
.galphotos { display: flex; gap: 0.35rem; flex: 0 0 46%; }
.galphotos a { flex: 1 1 0; min-width: 0; }
.galphotos img {
  width: 100%; height: 150px; object-fit: cover; border-radius: 4px;
  display: block;
}
.galinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.galaddr { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; font-weight: 600; }
.galaddr button.star { padding: 0.1rem 0.4rem; font-size: 0.9rem; }
.galprice { font-size: 1.15rem; font-weight: 700; }
.galdismiss { margin-top: auto; text-align: right; }

/* Detail-page photo grid (detail.html). */
.gallery { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.5rem; }
.gallery img {
  width: 110px; height: 82px; object-fit: cover; border-radius: 4px;
  cursor: zoom-in; border: 2px solid transparent;
}
img.main { cursor: zoom-in; }

/* Lightbox (see lightbox.js). */
#lightbox {
  display: none; position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.92);
  touch-action: pan-y;
}
#lightbox.open { display: block; }
#lb-img {
  position: absolute; inset: 0; margin: auto;
  max-width: 100%; max-height: calc(100% - 110px);
  object-fit: contain;
}
#lightbox button {
  position: absolute; z-index: 51;
  background: rgba(0, 0, 0, 0.55); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.6);
  font-size: 1.5rem; width: 48px; height: 48px; border-radius: 50%;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
#lb-close { top: 12px; right: 12px; }
#lb-prev { left: 8px; top: 40%; }
#lb-next { right: 8px; top: 40%; }
#lb-count {
  position: absolute; bottom: 64px; width: 100%; text-align: center;
  color: #fff; font-size: 0.9rem;
}
#lb-thumbs {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; gap: 4px; overflow-x: auto; padding: 6px 8px 10px;
  justify-content: center;
}
#lb-thumbs img {
  width: 52px; height: 40px; object-fit: cover; border-radius: 3px;
  opacity: 0.55; flex: 0 0 auto; cursor: pointer;
}
#lb-thumbs img.active { opacity: 1; outline: 2px solid #fff; }

/* ---- Mobile (≤720px): cards instead of tables, touch targets, tidy nav ---- */

@media (max-width: 720px) {
  body { font-size: 15px; }

  header { flex-wrap: wrap; gap: 0.25rem 0.75rem; }
  header h1 { font-size: 1.25rem; margin: 0.25rem 0; }
  nav { display: flex; flex-wrap: wrap; gap: 0.1rem 0.75rem; }
  nav a { margin-left: 0; padding: 0.5rem 0.1rem; }
  #theme-toggle { margin-left: 0; padding: 0.5rem 0.6rem; }

  input, select, button { font-size: 16px; /* no iOS zoom-on-focus */ }
  button { min-height: 40px; }

  /* Filters collapse behind a toggle (checkbox hack, no JS). */
  .filters-toggle { display: inline-block; margin: 0.5rem 0; }
  form.filters { display: none; }
  #filters-check { display: none; }
  #filters-check:checked ~ form.filters { display: flex; }
  .filters input, .filters select { flex: 1 1 40%; min-width: 0; }

  /* Listings table -> stacked cards. */
  table.listings thead { display: none; }
  table.listings, table.listings tbody, table.listings tr, table.listings td {
    display: block; width: 100%; box-sizing: border-box;
  }
  table.listings tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
  }
  table.listings td { border: 0; padding: 0.15rem 0; }
  .cell-photo img.thumb { width: 100%; height: 180px; }
  .cell-price { font-size: 1.1rem; font-weight: 700; }
  .cell-beds::before { content: "Bed/bath/car: "; color: var(--muted); }
  table.listings td.cell-type, table.listings td.cell-seen { display: none; }
  .cell-dom::before { content: "On market: "; color: var(--muted); }
  .rowactions button {
    min-width: 48px; min-height: 44px; font-size: 1.1rem;
  }
  /* Gallery view on mobile: stack info below, photos scroll sideways. */
  .galrow { flex-direction: column; }
  .galphotos { flex: none; overflow-x: auto; padding-bottom: 0.25rem; }
  .galphotos a { flex: 0 0 62%; }
  .galphotos img { height: 170px; }
  table.listings td.cell-dismiss { text-align: right; margin-top: 0.5rem; }
  table.listings td.cell-dismiss button { min-width: 48px; min-height: 44px; }

  /* Detail page gallery scrolls horizontally. */
  .gallery { display: flex; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.25rem; }
  .gallery img { width: 140px; height: 105px; flex: 0 0 auto; }
  img.main { max-height: 300px; }
  .actions { display: flex; }
  .actions button { flex: 1; }
}

/* Desktop: filters toggle hidden, filters always visible. */
@media (min-width: 721px) {
  .filters-toggle, #filters-check { display: none; }
}
