:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --ink: #202124;
  --muted: #6d716f;
  --line: #deded8;
  --accent: #e54b4b;
  --blue: #2f6f9f;
  --green: #3b7c5a;
  --shadow: 0 10px 30px rgba(26, 28, 30, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  font-size: 19px;
  font-weight: 760;
}

.dataset-status {
  min-width: 120px;
  padding: 5px 8px;
  color: var(--muted);
  background: #f1f1ed;
  border-radius: 999px;
  font-size: 13px;
  text-align: right;
}

.dataset-status[data-health-status="fresh"] {
  color: #286544;
  background: #e8f4ec;
}

.dataset-status[data-health-status="degraded"] {
  color: #805b14;
  background: #fff3d7;
}

.dataset-status[data-health-status="stale"] {
  color: #8b3030;
  background: #fde8e8;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 12px;
  min-width: 0;
}

.topbar-link {
  min-height: 34px;
  padding: 7px 10px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 760;
}

.filters {
  position: sticky;
  top: 64px;
  z-index: 9;
  display: grid;
  grid-template-columns: repeat(7, minmax(118px, 1fr)) minmax(220px, 1.45fr);
  gap: 10px;
  padding: 14px 24px;
  background: rgba(247, 247, 245, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

input:focus,
select:focus {
  border-color: #222;
  box-shadow: 0 0 0 2px rgba(32, 33, 36, 0.08);
}

.list-view {
  display: grid;
  grid-template-columns: minmax(560px, 1fr) minmax(360px, 42vw);
  min-height: calc(100vh - 129px);
}

.list-view.map-hidden {
  grid-template-columns: minmax(0, 1fr);
}

.list-view.map-hidden .map-pane {
  display: none;
}

.results-pane {
  min-width: 0;
  padding: 22px 24px 40px;
}

.results-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.list-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
}

.results-head p,
.map-head span,
.detail-muted {
  color: var(--muted);
  font-size: 13px;
}

.sort-box {
  width: 160px;
}

.map-toggle-button,
.map-actions button {
  min-height: 34px;
  padding: 7px 10px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 760;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(242px, 1fr));
  gap: 18px;
}

.load-more-row {
  display: flex;
  grid-column: 1 / -1;
  justify-content: center;
  gap: 10px;
  padding: 12px 0 22px;
}

.load-more-button {
  min-height: 42px;
  padding: 9px 16px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  font: inherit;
  font-weight: 760;
}

.load-more-button:hover {
  background: #f7f7f2;
}

.load-more-button:disabled {
  cursor: default;
  opacity: 0.45;
  box-shadow: none;
}

.listing-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  cursor: pointer;
}

.listing-card:hover .card-title {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.thumb {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  background: #d9d8d0;
  border-radius: 8px;
}

.thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.thumb-placeholder {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: #686b68;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.7), rgba(255,255,255,0)),
    repeating-linear-gradient(45deg, #d7d6ce 0 12px, #ccccbe 12px 24px);
  font-weight: 720;
}

.badge-row {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.badge {
  max-width: 100%;
  padding: 5px 8px;
  overflow: hidden;
  color: #fff;
  background: rgba(30, 31, 32, 0.82);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge.ready {
  background: rgba(59, 124, 90, 0.9);
}

.card-body {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.card-title {
  overflow: hidden;
  font-size: 15px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-sub,
.card-dates {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-price {
  font-size: 14px;
  font-weight: 760;
}

.map-pane {
  position: sticky;
  top: 129px;
  height: calc(100vh - 129px);
  min-height: 480px;
  padding: 16px;
  border-left: 1px solid var(--line);
}

.map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 32px;
}

.map-head strong {
  flex: 0 0 auto;
}

.map-head span {
  flex: 1;
  text-align: right;
}

.map-actions {
  display: flex;
  gap: 6px;
}

.map-pane.map-expanded {
  position: fixed;
  z-index: 40;
  inset: 16px;
  top: 16px;
  height: auto;
  min-height: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

body.map-is-expanded {
  overflow: hidden;
}

body.lightbox-open {
  overflow: hidden;
}

.map-canvas {
  position: relative;
  height: calc(100% - 42px);
  min-height: 420px;
  overflow: hidden;
  background: #e7ebe5;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.42);
}

.map-canvas.fallback-map {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.82), rgba(255,255,255,0.42)),
    linear-gradient(135deg, #b7d8de, #e9e0c8 45%, #c7d8c0);
}

.map-canvas.fallback-map::before {
  position: absolute;
  inset: 13% 12% 16% 10%;
  content: "";
  opacity: 0.2;
  border: 1px solid #44524e;
  border-radius: 46% 42% 38% 45%;
  transform: rotate(-8deg);
}

.map-pin {
  position: absolute;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  color: #fff;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 999px;
  box-shadow: var(--shadow);
  cursor: default;
  font-size: 11px;
  font-weight: 800;
}

/* Critical MapLibre layout rules. The CDN stylesheet is still loaded, but these
   keep the map usable if the browser blocks or delays external CSS. */
.maplibregl-map {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 8px;
  font: inherit;
}

.maplibregl-canvas-container,
.maplibregl-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.maplibregl-canvas {
  outline: none;
}

.maplibregl-canvas-container.maplibregl-interactive,
.maplibregl-ctrl-group button {
  cursor: pointer;
}

.maplibregl-ctrl-top-left,
.maplibregl-ctrl-top-right,
.maplibregl-ctrl-bottom-left,
.maplibregl-ctrl-bottom-right {
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.maplibregl-ctrl-top-left {
  top: 10px;
  left: 10px;
}

.maplibregl-ctrl-top-right {
  top: 10px;
  right: 10px;
}

.maplibregl-ctrl-bottom-left {
  bottom: 10px;
  left: 10px;
}

.maplibregl-ctrl-bottom-right {
  right: 10px;
  bottom: 10px;
}

.maplibregl-ctrl {
  pointer-events: auto;
}

.maplibregl-ctrl-group {
  overflow: hidden;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(32, 33, 36, 0.18);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.maplibregl-ctrl-group button {
  display: block;
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  font-size: 18px;
  line-height: 30px;
}

.maplibregl-ctrl-group button:last-child {
  border-bottom: 0;
}

.maplibregl-ctrl-group button:hover {
  background: #f2f2ee;
}

.maplibregl-ctrl-attrib {
  padding: 2px 6px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.84);
  border-radius: 6px;
  font-size: 10px;
}

.maplibregl-ctrl-attrib a {
  color: var(--blue);
}

.detail-view {
  padding: 22px 24px 48px;
}

.hidden {
  display: none !important;
}

.detail-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.back-button {
  min-height: 38px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.detail-title {
  display: grid;
  gap: 6px;
}

.gallery {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  grid-auto-rows: clamp(150px, 16vw, 260px);
  gap: 8px;
  margin-bottom: 22px;
}

.gallery .thumb {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

.gallery .thumb:first-child {
  grid-row: span 2;
}

.gallery-button {
  padding: 0;
  border: 0;
  cursor: zoom-in;
}

.gallery-button:focus-visible {
  outline: 3px solid rgba(47, 111, 159, 0.45);
  outline-offset: 2px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 28px;
}

.detail-section {
  display: grid;
  gap: 12px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.detail-section h2 {
  font-size: 18px;
}

.original-message-section {
  margin-top: 26px;
}

.original-message {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.35;
}

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

.pill {
  padding: 7px 10px;
  background: #ecece6;
  border-radius: 999px;
  font-size: 13px;
}

.network-section {
  gap: 14px;
}

.network-context {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.network-context-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.network-context-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.facts {
  display: grid;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.fact {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.fact:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.fact span:first-child {
  color: var(--muted);
}

.lightbox {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 44px 72px;
  background: rgba(18, 19, 20, 0.92);
}

.lightbox img {
  max-width: min(1200px, 92vw);
  max-height: 88vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
}

.lightbox-close,
.lightbox-arrow {
  position: absolute;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  cursor: pointer;
}

.lightbox-close {
  top: 18px;
  right: 18px;
  min-height: 38px;
  padding: 8px 12px;
  font-weight: 760;
}

.lightbox-arrow {
  top: 50%;
  width: 46px;
  height: 58px;
  transform: translateY(-50%);
  font-size: 42px;
  line-height: 1;
}

.lightbox-arrow:disabled {
  opacity: 0.3;
  cursor: default;
}

.lightbox-prev {
  left: 18px;
}

.lightbox-next {
  right: 18px;
}

.lightbox-counter {
  position: absolute;
  bottom: 18px;
  left: 50%;
  padding: 6px 10px;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 760;
  transform: translateX(-50%);
}

.empty {
  padding: 48px 12px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

@media (max-width: 980px) {
  .filters {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-label {
    grid-column: 1 / -1;
  }

  .list-view {
    grid-template-columns: 1fr;
  }

  .map-pane {
    position: relative;
    top: auto;
    height: 420px;
    min-height: 420px;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .detail-grid,
  .gallery {
    grid-template-columns: 1fr;
  }

  .gallery .thumb:first-child {
    grid-row: auto;
  }
}

@media (max-width: 560px) {
  .topbar {
    height: auto;
    min-height: 58px;
    padding: 0 14px;
  }

  .brand {
    font-size: 17px;
  }

  .topbar-right {
    gap: 8px;
  }

  .dataset-status {
    min-width: 0;
    max-width: 118px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .filters,
  .results-pane,
  .detail-view {
    padding-right: 14px;
    padding-left: 14px;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .results-head,
  .detail-top {
    align-items: stretch;
    flex-direction: column;
  }

  .list-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .sort-box {
    width: 100%;
  }

  .cards {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .map-pane {
    height: 340px;
    min-height: 340px;
    padding: 12px;
  }

  .map-canvas {
    min-height: 280px;
  }

  .gallery {
    grid-auto-rows: 210px;
  }

  .facts {
    padding: 12px;
  }

  .lightbox {
    padding: 58px 12px;
  }

  .lightbox-arrow {
    top: auto;
    bottom: 16px;
    transform: none;
  }

  .lightbox-prev {
    left: 16px;
  }

  .lightbox-next {
    right: 16px;
  }
}
