:root {
  --topbar-content-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --topbar-h: calc(var(--topbar-content-h) + var(--safe-top));
  --bg: #0b0d10;
  --card: rgba(10, 14, 19, 0.94);
  --text: #f3f6fb;
  --muted: rgba(243, 246, 251, 0.72);
  --border: rgba(243, 246, 251, 0.14);
  --accent: #5aa9e6;
  --tap: 44px;
}

/* Leaflet base styles (trimmed out of the legacy LESS bundle). */
.leaflet-map-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-pane,
.leaflet-tile-container,
.leaflet-overlay-pane,
.leaflet-shadow-pane,
.leaflet-marker-pane,
.leaflet-popup-pane,
.leaflet-overlay-pane svg,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}
.leaflet-container {
  overflow: hidden;
  -ms-touch-action: none;
}
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}
.leaflet-marker-icon,
.leaflet-marker-shadow {
  display: block;
}
.leaflet-container img {
  max-width: none !important;
}
.leaflet-container img.leaflet-image-layer {
  max-width: 15000px !important;
}
.leaflet-tile {
  filter: inherit;
  visibility: hidden;
}
.leaflet-tile-loaded {
  visibility: inherit;
}
.leaflet-zoom-box {
  width: 0;
  height: 0;
}
.leaflet-overlay-pane svg {
  -moz-user-select: none;
}

.leaflet-tile-pane {
  z-index: 2;
}
.leaflet-objects-pane {
  z-index: 3;
}
.leaflet-overlay-pane {
  z-index: 4;
}
.leaflet-shadow-pane {
  z-index: 5;
}
.leaflet-marker-pane {
  z-index: 6;
}
.leaflet-popup-pane {
  z-index: 7;
}

.leaflet-control {
  position: relative;
  z-index: 7;
  pointer-events: auto;
}
.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}
.leaflet-top {
  top: calc(var(--topbar-h) + 10px);
}
.leaflet-right {
  right: 0;
}
.leaflet-bottom {
  bottom: 0;
}
.leaflet-left {
  left: 0;
}
.leaflet-control {
  float: left;
  clear: both;
}
.leaflet-right .leaflet-control {
  float: right;
}
.leaflet-top .leaflet-control {
  margin-top: 10px;
}
.leaflet-bottom .leaflet-control {
  margin-bottom: 10px;
}
.leaflet-left .leaflet-control {
  margin-left: 10px;
}
.leaflet-right .leaflet-control {
  margin-right: 10px;
}

.leaflet-fade-anim .leaflet-tile,
.leaflet-fade-anim .leaflet-popup {
  opacity: 0;
  transition: opacity 0.2s linear;
}
.leaflet-fade-anim .leaflet-tile-loaded,
.leaflet-fade-anim .leaflet-map-pane .leaflet-popup {
  opacity: 1;
}

.leaflet-zoom-anim .leaflet-zoom-animated {
  transition: transform 0.25s cubic-bezier(0, 0, 0.25, 1);
}
.leaflet-zoom-anim .leaflet-tile,
.leaflet-pan-anim .leaflet-tile,
.leaflet-touching .leaflet-zoom-animated {
  transition: none;
}
.leaflet-zoom-anim .leaflet-zoom-hide {
  visibility: hidden;
}

.leaflet-clickable {
  cursor: pointer;
}
.leaflet-container {
  cursor: -webkit-grab;
  cursor: -moz-grab;
}
.leaflet-popup-pane,
.leaflet-control {
  cursor: auto;
}
.leaflet-dragging .leaflet-container,
.leaflet-dragging .leaflet-clickable {
  cursor: move;
  cursor: -webkit-grabbing;
  cursor: -moz-grabbing;
}

.leaflet-container {
  background: #ddd;
  outline: 0;
  font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif;
}
.leaflet-container a {
  color: #0078a8;
}
.leaflet-container a.leaflet-active {
  outline: 2px solid orange;
}
.leaflet-zoom-box {
  border: 2px dotted #38f;
  background: rgba(255, 255, 255, 0.5);
}

.leaflet-bar {
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.65);
  border-radius: 4px;
}
.leaflet-bar a,
.leaflet-bar a:hover {
  background-color: #fff;
  border-bottom: 1px solid #ccc;
  width: 26px;
  height: 26px;
  line-height: 26px;
  display: block;
  text-align: center;
  text-decoration: none;
  color: black;
}
.leaflet-bar a:hover {
  background-color: #f4f4f4;
}
.leaflet-bar a:first-child {
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}
.leaflet-bar a:last-child {
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 4px;
  border-bottom: none;
}
.leaflet-bar a.leaflet-disabled {
  cursor: default;
  background-color: #f4f4f4;
  color: #bbb;
}

.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
  font: bold 18px "Lucida Console", Monaco, monospace;
  text-indent: 1px;
}
.leaflet-control-zoom-out {
  font-size: 20px;
}

.leaflet-control-layers {
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
  background: #fff;
  border-radius: 5px;
}
.leaflet-control-layers-toggle {
  background-image: url(images/layers.png);
  width: 36px;
  height: 36px;
}
.leaflet-retina .leaflet-control-layers-toggle {
  background-image: url(images/layers-2x.png);
  background-size: 26px 26px;
}
.leaflet-container .leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.7);
  margin: 0;
}
.leaflet-control-attribution {
  padding: 0 5px;
  color: #333;
  font-size: 11px;
}
.leaflet-control-attribution a {
  text-decoration: none;
}
.leaflet-control-attribution a:hover {
  text-decoration: underline;
}

.leaflet-popup {
  position: absolute;
  text-align: center;
}

.leaflet-div-icon {
  background: #fff;
  border: 1px solid #666;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none;
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Helvetica,
    Arial,
    "Apple Color Emoji",
    "Segoe UI Emoji";
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- Top bar */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  padding: var(--safe-top) calc(12px + var(--safe-right)) 0
    calc(12px + var(--safe-left));
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(10, 14, 18, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  z-index: 1000;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  flex: 0 0 auto;
}

.search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
}

.search input {
  width: 100%;
  height: 38px;
  /* 16px keeps iOS Safari from zooming the viewport on focus. */
  font-size: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 0 34px 0 12px;
  appearance: none;
  -webkit-appearance: none;
}

.search input::placeholder {
  color: rgba(243, 246, 251, 0.5);
}

.search input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.search input::-webkit-search-decoration,
.search input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-clear[hidden] {
  display: none;
}

.search-clear {
  position: absolute;
  right: 2px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}

.legend-toggle {
  flex: 0 0 auto;
  height: 38px;
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  cursor: pointer;
}

.legend-toggle[aria-expanded="true"] {
  background: rgba(90, 169, 230, 0.22);
  border-color: rgba(90, 169, 230, 0.5);
}

/* --------------------------------------------------------- Search results */

.search-results {
  position: fixed;
  top: var(--topbar-h);
  left: calc(8px + var(--safe-left));
  right: calc(8px + var(--safe-right));
  z-index: 1200;
  margin: 6px 0 0;
  padding: 6px;
  list-style: none;
  max-height: min(52vh, 420px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.search-results li + li {
  border-top: 1px solid rgba(243, 246, 251, 0.07);
}

.search-results button {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 9px 10px;
  text-align: left;
  font-size: 14px;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.search-results button:hover,
.search-results button[aria-selected="true"] {
  background: rgba(90, 169, 230, 0.18);
}

.search-results .result-sub {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.search-results .result-empty {
  padding: 12px 10px;
  font-size: 13px;
  color: var(--muted);
}

/* ------------------------------------------------- Legend / filter panel */

.legend-panel {
  position: fixed;
  top: var(--topbar-h);
  left: calc(8px + var(--safe-left));
  right: calc(8px + var(--safe-right));
  z-index: 1100;
  margin-top: 6px;
  padding: 12px;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.legend-hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.legend-item[aria-pressed="false"] {
  color: rgba(243, 246, 251, 0.42);
  background: transparent;
  border-style: dashed;
}

.legend-item[aria-pressed="false"] .dot {
  opacity: 0.3;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
  flex: 0 0 auto;
  outline: 1px solid rgba(255, 255, 255, 0.18);
  outline-offset: 1px;
}

/* Keep in step with CLASS_DEFS in public/js/app.js. */
.dot.residential {
  background: #377eb8;
}
.dot.commercial {
  background: #e41a1c;
}
.dot.agricultural {
  background: #4daf4a;
}
.dot.industrial {
  background: #984ea3;
}
.dot.exempt {
  background: #ff7f00;
}
.dot.other {
  background: #9aa3ad;
}

/* -------------------------------------------------------------- The map */

#map {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  background: #e8eaed;
}

.leaflet-container .leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.82);
  border-radius: 6px 0 0 0;
  padding: 2px 6px;
  font-size: 10px;
}

/*
 * Zoom and attribution sit bottom-right, clear of the top bar. --sheet-h is
 * kept in sync with the bottom sheet's height so the controls ride above it
 * instead of being buried underneath, which is what happened when the panel
 * and the zoom buttons both lived in the top-left corner.
 */
.leaflet-bottom {
  bottom: calc(var(--sheet-h, 0px) + var(--safe-bottom));
  transition: bottom 0.22s ease;
}

/* --sheet-w does the same job when the panel takes the right edge instead. */
.leaflet-bottom.leaflet-right {
  right: calc(var(--sheet-w, 0px) + var(--safe-right));
  transition: right 0.22s ease;
}

.leaflet-bottom.leaflet-left {
  left: var(--safe-left);
}

@media (prefers-reduced-motion: reduce) {
  .leaflet-bottom,
  .sheet {
    transition: none;
  }
}

.leaflet-bar a,
.leaflet-bar a:hover {
  width: var(--tap);
  height: var(--tap);
  line-height: var(--tap);
  font-size: 22px;
}

.leaflet-touch .leaflet-bar a {
  width: var(--tap);
  height: var(--tap);
  line-height: var(--tap);
}

/* ------------------------------------------------------ Status + hint */

.status {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 800;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 24px);
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text);
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
}

.status[hidden] {
  display: none;
}

.spinner {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.status.is-error .spinner {
  display: none;
}

.status-retry {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: rgba(90, 169, 230, 0.24);
  border: 1px solid rgba(90, 169, 230, 0.5);
  border-radius: 999px;
  cursor: pointer;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
}

.hint {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(30px + var(--safe-bottom));
  z-index: 800;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - 24px);
  padding: 8px 6px 8px 14px;
  font-size: 13px;
  color: var(--text);
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
}

.hint[hidden] {
  display: none;
}

.hint button {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}

/* --------------------------------------------------- Detail bottom sheet */

.sheet {
  position: fixed;
  z-index: 900;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
  /* Phone-first: a bottom sheet pinned to the bottom edge. */
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 16px 16px 0 0;
  border-bottom: 0;
  height: 46vh;
  max-height: calc(100vh - var(--topbar-h) - 8px);
  padding-bottom: var(--safe-bottom);
  transition: height 0.22s ease, transform 0.22s ease;
}

.sheet[hidden] {
  display: none;
}

.sheet.is-full {
  height: calc(100vh - var(--topbar-h) - 8px);
}

.sheet.is-dragging {
  transition: none;
}

.sheet-grip {
  flex: 0 0 auto;
  height: 26px;
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
}

.sheet-grip-bar {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: rgba(243, 246, 251, 0.32);
}

.sheet-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.sheet-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.sheet-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 16px 20px;
}

#property h3 {
  margin: 0 8px 10px 0;
  padding-right: 40px;
  font-size: 18px;
  line-height: 1.25;
}

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin: 0 0 4px;
}

.fact {
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}

.fact dt {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(243, 246, 251, 0.55);
}

.fact dd {
  margin: 3px 0 0;
  font-size: 15px;
  font-weight: 600;
}

.lead {
  margin: 12px 0 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

/* ------------------------------------------------------- Sales history */

#saledata {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#saledata thead th {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  color: rgba(243, 246, 251, 0.86);
  font-weight: 600;
  white-space: nowrap;
}

#saledata tbody td {
  padding: 8px 6px;
  border-bottom: 1px solid rgba(243, 246, 251, 0.08);
  vertical-align: top;
  color: rgba(243, 246, 251, 0.82);
}

/* Wide layout uses the real Date and Price columns. */
#saledata tbody td.sale-headline {
  display: none;
}

/*
 * Narrow screens: five columns cannot fit, so each sale becomes its own
 * stacked block with the header text supplied by the data-label attribute.
 */
@media (max-width: 640px) {
  #saledata,
  #saledata tbody,
  #saledata tr,
  #saledata td {
    display: block;
    width: 100%;
  }

  #saledata thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  #saledata tbody tr {
    margin-bottom: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
  }

  #saledata tbody td {
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 10px;
    padding: 3px 0;
    border: 0;
  }

  #saledata tbody td::before {
    content: attr(data-label);
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(243, 246, 251, 0.5);
    padding-top: 2px;
  }

  /* Narrow layout folds date and price into a single headline instead. */
  #saledata tbody td.sale-headline {
    display: block;
    margin-bottom: 4px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
  }

  #saledata tbody td.sale-date,
  #saledata tbody td.sale-price {
    display: none;
  }
}

/* ----------------------------------------------------------- Desktop */

@media (min-width: 641px) {
  .sheet {
    left: calc(14px + var(--safe-left));
    right: auto;
    top: calc(var(--topbar-h) + 14px);
    bottom: auto;
    width: 420px;
    height: auto;
    max-height: calc(100vh - var(--topbar-h) - 28px);
    border-radius: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  }

  .sheet.is-full {
    height: auto;
  }

  .sheet-grip {
    display: none;
  }

  .sheet-body {
    padding-top: 14px;
  }

  .legend-panel,
  .search-results {
    left: auto;
    right: calc(14px + var(--safe-right));
    width: min(380px, calc(100vw - 28px));
  }
}

/*
 * Landscape phones are short: a bottom sheet would swallow the map, so the
 * details move to a side panel instead.
 */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  :root {
    --land-panel-w: min(360px, 60vw);
  }

  .sheet {
    left: auto;
    right: 0;
    top: var(--topbar-h);
    bottom: 0;
    width: var(--land-panel-w);
    height: auto;
    max-height: none;
    border-radius: 16px 0 0 0;
    padding-right: var(--safe-right);
  }

  .sheet.is-full {
    height: auto;
  }

  .sheet-grip {
    display: none;
  }

  .sheet-body {
    padding-top: 14px;
  }
}

/* Hover affordances only where a real pointer exists. */
@media (hover: hover) and (pointer: fine) {
  .legend-item:hover {
    border-color: rgba(255, 255, 255, 0.32);
  }

  .legend-toggle:hover,
  .status-retry:hover {
    border-color: rgba(255, 255, 255, 0.32);
  }
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
