/* Round 41, 41.5: the all-listings map page (/map). Self-hosted fonts and our own classes only; the
   pin colours are defined once here (--pin-*) and used by the pins, clusters and legend alike
   (map.js keeps the same values for the circles Google draws). White text on each is >= 4.5:1, and
   the same colour as text on white is too (the "approximate" pin). No inline style in our markup. */
@font-face {
  font-display: swap;
  font-family: 'Chakra Petch';
  font-weight: 700;
  src: url("/fonts/ChakraPetch-Bold.ttf") format("truetype");
}
@font-face {
  font-display: swap;
  font-family: 'Sarabun';
  font-weight: 400;
  src: url("/fonts/Sarabun-Regular.ttf") format("truetype");
}
@font-face {
  font-display: swap;
  font-family: 'Sarabun';
  font-weight: 700;
  src: url("/fonts/Sarabun-Bold.ttf") format("truetype");
}

:root {
  --bg: #FAF6EF;
  --surface: #ffffff;
  --ink: #2A2420;
  --muted: #6D655E;
  --line: #E7DFD2;
  --brand: #185746;
  --pin-land: #8A5300;
  --pin-house: #1D5FA8;
  --pin-farm: #2E7D32;
  --pin-commercial: #8E2F8A;
  --pin-warehouse: #455A64;
  --pin-other: #185746;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: 'Sarabun', 'Leelawadee UI', 'Tahoma', sans-serif; font-size: 15px; line-height: 1.5; overflow-x: hidden; }
button, select { font: inherit; }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 3px solid rgba(24, 87, 70, 0.35); outline-offset: 2px; }
.icon-sprite { height: 0; overflow: hidden; position: absolute; width: 0; }
.tm-icon { fill: none; flex: 0 0 auto; height: 18px; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; width: 18px; }

/* one colour per kind of property */
.pin-land { --pin: var(--pin-land); }
.pin-house { --pin: var(--pin-house); }
.pin-farm { --pin: var(--pin-farm); }
.pin-commercial { --pin: var(--pin-commercial); }
.pin-warehouse { --pin: var(--pin-warehouse); }
.pin-other, .pin-mixed { --pin: var(--pin-other); }

.map-header { align-items: center; background: var(--brand); color: #fff; display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: space-between; padding: 10px max(16px, calc((100vw - 1400px) / 2)); }
.map-home { align-items: center; color: #fff; display: inline-flex; font-weight: 700; gap: 6px; min-height: 44px; text-decoration: none; }
.map-title { font-family: 'Chakra Petch', 'Sarabun', sans-serif; font-size: 20px; margin: 0; }
.map-main { display: grid; gap: 10px; margin: 0 auto; max-width: 1400px; padding: 12px 16px 24px; }
.map-toolbar { align-items: center; display: flex; flex-wrap: wrap; gap: 8px 16px; }
.map-district { align-items: center; display: inline-flex; font-weight: 700; gap: 8px; }
.map-district select { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; min-height: 44px; min-width: 150px; padding: 6px 10px; }
.map-summary { color: var(--ink); flex: 1 1 260px; margin: 0; }
.map-list-link { color: var(--brand); font-weight: 700; min-height: 44px; display: inline-flex; align-items: center; }
.map-notice { background: #fff4e0; border: 1px solid #e3c68f; border-radius: 8px; color: #6b4a12; font-weight: 700; margin: 0; padding: 10px 12px; }
.map-notice[hidden] { display: none; }

.map-view-toggle { display: none; gap: 8px; }
.map-view-button { background: var(--surface); border: 1px solid var(--brand); border-radius: 6px; color: var(--brand); cursor: pointer; flex: 1 1 0; font-weight: 700; min-height: 44px; }
.map-view-button[aria-pressed="true"] { background: var(--brand); color: #fff; }

.map-layout { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr) 360px; min-height: 0; }
.map-stage { border: 1px solid var(--line); border-radius: 10px; min-height: 520px; overflow: hidden; position: relative; }
.map-stage[hidden] { display: none; }
.map-canvas-wrap { position: relative; }
/* Round 42: its own stacking context, so nothing on the map (pins, clusters) can rise above our card. */
.map-canvas { height: calc(100vh - 190px); isolation: isolate; min-height: 520px; position: relative; width: 100%; z-index: 0; }
.map-off .map-layout { grid-template-columns: minmax(0, 1fr); }
.map-off .map-view-toggle { display: none; }

/* legend: colour + icon + name + count; a press hides/shows that kind */
.map-legend { background: rgba(255, 255, 255, 0.96); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); display: grid; gap: 4px; left: 10px; padding: 6px; position: absolute; top: 10px; z-index: 2; }
.map-legend-item { align-items: center; background: none; border: 1px solid transparent; border-radius: 6px; color: var(--ink); cursor: pointer; display: grid; gap: 8px; grid-template-columns: auto 1fr auto; min-height: 36px; padding: 2px 8px 2px 2px; text-align: left; }
.map-legend-item:hover { border-color: var(--line); }
.map-legend-swatch { align-items: center; background: var(--pin); border-radius: 50%; color: #fff; display: inline-flex; height: 28px; justify-content: center; width: 28px; }
.map-legend-swatch .tm-icon { height: 16px; width: 16px; }
.map-legend-count { font-weight: 700; }
.map-legend-item[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; }
.map-legend-item[aria-pressed="false"] .map-legend-swatch { background: #fff; border: 2px solid var(--pin); color: var(--pin); }
/* Round 42, 42.3: a kind with 0 listings on the map: faded, not pressable. */
.map-legend-item[aria-disabled="true"] { cursor: not-allowed; opacity: 0.45; text-decoration: none; }
.map-legend-item[aria-disabled="true"]:hover { border-color: transparent; }

/* price-label pins (the content of Google's AdvancedMarkerElement) */
.map-pin { align-items: center; background: var(--pin); border: 2px solid #fff; border-radius: 16px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); color: #fff; cursor: pointer; display: inline-flex; font-family: 'Chakra Petch', 'Sarabun', sans-serif; font-size: 13px; font-weight: 700; gap: 4px; line-height: 1; min-height: 32px; padding: 5px 10px 5px 7px; white-space: nowrap; }
.map-pin .tm-icon { height: 16px; width: 16px; }
.map-pin.is-approx { background: #fff; border: 2px dashed var(--pin); color: var(--pin); }
.map-pin-approx { font-family: 'Sarabun', sans-serif; font-size: 11px; font-weight: 700; }
.map-pin.is-selected { border-width: 4px; box-shadow: 0 0 0 2px var(--pin), 0 6px 14px rgba(0, 0, 0, 0.35); font-size: 15px; min-height: 40px; padding: 7px 13px 7px 9px; }
.map-pin.is-approx.is-selected { border-style: dashed; }
.map-cluster { align-items: center; background: var(--pin); border: 3px solid #fff; border-radius: 50%; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); color: #fff; cursor: pointer; display: inline-flex; font-family: 'Chakra Petch', 'Sarabun', sans-serif; font-size: 15px; font-weight: 700; height: 44px; justify-content: center; min-width: 44px; padding: 0 8px; }

/* the listing card (our DOM, not an InfoWindow). Round 42, 42.3: below 900px a sheet at the bottom
   of the map frame; from 900px it floats above the tapped pin inside a Google marker (.map-card-float),
   its tail pointing down at the pin. */
.map-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25); display: grid; grid-template-columns: 120px minmax(0, 1fr); overflow: hidden; position: relative; }
.map-canvas-wrap > .map-card { bottom: 12px; left: 12px; margin: 0 auto; max-width: 520px; position: absolute; right: 12px; z-index: 3; }
.map-card-float { display: grid; justify-items: center; pointer-events: none; transform: translateY(-46px); }
.map-card-float .map-card { pointer-events: auto; text-align: left; width: min(340px, 70vw); }
.map-card-tail { border-left: 11px solid transparent; border-right: 11px solid transparent; border-top: 11px solid var(--surface); filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.18)); height: 0; margin-top: -1px; width: 0; }
.map-card[hidden] { display: none; }
.map-card-close { background: rgba(255, 255, 255, 0.95); border: 1px solid var(--line); border-radius: 50%; cursor: pointer; font-size: 20px; height: 36px; line-height: 1; position: absolute; right: 6px; top: 6px; width: 36px; z-index: 1; }
.map-card-photo { height: 100%; min-height: 120px; object-fit: cover; width: 120px; }
.map-card-photo[hidden] { display: none; }
.map-card-photo[hidden] + .map-card-body { grid-column: 1 / -1; }
.map-card-body { display: grid; gap: 2px; min-width: 0; padding: 10px 44px 12px 12px; }
.map-card-meta { color: var(--muted); font-size: 13px; margin: 0; }
.map-card-title { font-size: 16px; line-height: 1.35; margin: 0; overflow-wrap: anywhere; }
.map-card-price { color: #AD502A; font-family: 'Chakra Petch', 'Sarabun', sans-serif; font-size: 18px; font-weight: 700; margin: 0; }
.map-card-note { color: #6b4a12; font-size: 12px; margin: 0; }
.map-card-note[hidden] { display: none; }
.map-card-link { align-items: center; background: var(--brand); border-radius: 6px; color: #fff; display: inline-flex; font-weight: 700; justify-content: center; justify-self: start; margin-top: 6px; min-height: 44px; padding: 8px 14px; text-decoration: none; }

/* the list (always there; the whole page when there is no map) */
.map-list { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; max-height: calc(100vh - 190px); min-width: 0; overflow-y: auto; padding: 10px; }
.map-off .map-list { max-height: none; }
.map-list-heading { font-size: 16px; margin: 0 0 8px; }
.map-list-items { display: grid; gap: 8px; list-style: none; margin: 0; padding: 0; }
.map-list-item { border: 1px solid var(--line); border-left: 5px solid var(--pin); border-radius: 8px; display: grid; gap: 6px; padding: 8px 10px; }
/* Round 42, 42.3: the listing whose card is open. */
.map-list-item.is-selected { background: #fbf7ef; border-color: var(--pin); box-shadow: inset 0 0 0 1px var(--pin); }
.map-list-link-item { color: var(--ink); display: grid; gap: 2px; min-width: 0; text-decoration: none; }
.map-list-link-item strong { overflow-wrap: anywhere; }
.map-list-type { align-items: center; color: var(--pin); display: inline-flex; font-size: 13px; font-weight: 700; gap: 4px; }
.map-list-meta { color: var(--muted); font-size: 13px; }
.map-list-show { background: #fff; border: 1px solid var(--brand); border-radius: 6px; color: var(--brand); cursor: pointer; font-weight: 700; justify-self: start; min-height: 44px; padding: 6px 12px; }
.map-list-empty { color: var(--muted); }

/* phones: map about 60vh, a map / list switch */
@media (max-width: 760px) {
  .map-view-toggle { display: flex; }
  .map-layout { grid-template-columns: minmax(0, 1fr); }
  .map-canvas { height: 60vh; min-height: 320px; }
  .map-stage { min-height: 0; }
  .map-list { max-height: none; }
  .map-layout[data-view="map"] .map-list { display: none; }
  .map-layout[data-view="list"] .map-stage { display: none; }
  .map-legend { border: 0; border-radius: 0; border-top: 1px solid var(--line); box-shadow: none; display: flex; flex-wrap: wrap; position: static; }
  .map-legend-item { grid-template-columns: auto auto auto; }
  .map-card { grid-template-columns: 96px minmax(0, 1fr); }
  .map-card-photo { width: 96px; }
}
