:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #5d6873;
  --line: #d9ded8;
  --accent: #196b5c;
  --accent-dark: #10483e;
  --accent-soft: #e2f0ec;
  --warning: #8b5e00;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body { min-height: 100%; }

:root {
  --site-nav-height: 64px;
  --site-nav-bg: #18453b;
  --site-nav-text: #fff;
  --site-nav-muted: rgb(255 255 255 / 72%);
}

.site-nav {
  position: relative;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--site-nav-height);
  padding: 0 24px;
  background: var(--site-nav-bg);
  color: var(--site-nav-text);
}

.site-nav-left,
.account-controls,
.desktop-nav,
.site-nav-link,
.account-button,
.nav-menu-button {
  display: flex;
  align-items: center;
}

.site-nav-left { gap: 14px; }

.site-logo {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
}

.site-logo img {
  display: block;
  width: auto;
  height: 34px;
}

.nav-icon-button,
.account-button {
  border: 0;
  color: inherit;
  cursor: pointer;
  font: inherit;
}

.nav-icon-button {
  justify-content: center;
  width: 28px;
  height: 36px;
  padding: 0;
  background: transparent;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(3, 4px);
  gap: 3px;
}

.app-grid span {
  width: 4px;
  height: 4px;
  border-radius: 1px;
  background: currentColor;
}

.desktop-nav {
  justify-content: flex-end;
  gap: 8px;
  margin-left: auto;
  margin-right: 18px;
}

.site-nav-link {
  min-height: 38px;
  padding: 0 10px;
  border-radius: 4px;
  color: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
}

.site-nav-link:hover,
.site-nav-link:focus-visible {
  background: rgb(255 255 255 / 12%);
  outline: 3px solid rgb(255 255 255 / 70%);
  outline-offset: 1px;
}

.account-controls { position: relative; }

.account-button {
  justify-content: center;
  gap: 7px;
  min-width: 64px;
  height: 36px;
  padding: 0 11px;
  border-radius: 999px;
  background: #b7b7b7;
  color: #fff;
  font-weight: 700;
}

.account-button:hover,
.account-button:focus-visible {
  outline: 3px solid rgb(255 255 255 / 78%);
  outline-offset: 2px;
}

.account-icon {
  position: relative;
  width: 14px;
  height: 12px;
  border: 1.5px solid currentColor;
  border-radius: 8px 8px 3px 3px;
  border-top-color: transparent;
}

.account-icon::before {
  position: absolute;
  top: -7px;
  left: 3px;
  width: 6px;
  height: 6px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  content: "";
}

.account-menu,
.nav-drawer {
  position: absolute;
  z-index: 1300;
  border: 1px solid rgb(0 0 0 / 14%);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 6px 18px rgb(0 0 0 / 22%);
  color: var(--text);
}

.account-menu {
  top: calc(100% + 8px);
  right: 0;
  min-width: 190px;
  padding: 6px 0;
}

.account-menu[hidden],
.nav-drawer[hidden] { display: none; }

.account-menu a,
.account-menu button,
.drawer-links a {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.account-menu a:hover,
.account-menu button:hover,
.drawer-links a:hover,
.account-menu a:focus-visible,
.account-menu button:focus-visible,
.drawer-links a:focus-visible {
  background: #eef4ef;
  outline: none;
}

.account-menu .account-heading {
  padding: 9px 16px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.nav-drawer {
  top: var(--site-nav-height);
  left: 16px;
  width: min(280px, calc(100vw - 32px));
  padding: 6px 0;
}

.nav-menu-button { display: flex; }

.map-shell {
  display: flex;
  isolation: isolate;
  width: 100%;
  height: calc(100% - var(--site-nav-height));
  min-height: 0;
  overflow: hidden;
}

.map-panel {
  position: relative;
  flex: 1 1 auto;
  order: 2;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#map.is-loading {
  opacity: 0;
}

.map-loading {
  position: absolute;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  background: #e7efe9;
  color: var(--muted);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.map-loading.is-overlay {
  background: rgb(231 239 233 / 82%);
  backdrop-filter: blur(2px);
}

.map-loading.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.map-loading p {
  margin: 0;
  font-weight: 700;
}

/* Inform without swallowing the next wheel, drag, or touch gesture. */
.map-background-loading {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 901;
  pointer-events: none;
  padding: 10px 14px;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 2px 10px rgb(0 0 0 / 18%);
  font-weight: 700;
}

.loading-mark {
  width: 34px;
  height: 34px;
  border: 4px solid rgb(25 107 92 / 20%);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

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

/* OpenLayers layout is bundled locally with the installed ol dependency. */
#map .ol-viewport { background: #eee; }
/* OpenLayers positions each Overlay in its own transformed wrapper. Stack
   those wrappers, not their children, so later markers cannot cover a popup. */
#map .room-marker-overlay { z-index: 10; }
#map .room-popup-overlay { z-index: 20; }
#map .ol-control { z-index: 30; }
#map .ol-zoom button {
  width: 30px;
  height: 30px;
  color: #1f2933;
  background: #fff;
}
#map .ol-attribution { font-size: 0.7rem; }
.room-marker {
  display: block;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #196b5c;
  box-shadow: 0 2px 8px rgb(0 0 0 / 35%);
  cursor: pointer;
}
.room-popup {
  position: relative;
  width: 280px;
  max-width: calc(100vw - 72px);
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 3px 14px rgb(0 0 0 / 40%);
}
.room-popup-content {
  max-height: min(360px, 50dvh);
  overflow: auto;
  line-height: 1.4;
}
.room-popup-close {
  position: absolute;
  top: 0;
  right: 3px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: #6b7280;
  font-size: 24px;
  cursor: pointer;
}
.footprint-status {
  position: absolute;
  bottom: 30px;
  left: 10px;
  max-width: calc(100% - 20px);
  padding: 5px;
  background: #fff;
  font-size: 0.8rem;
}

.directory-panel {
  position: relative;
  z-index: 1000;
  display: flex;
  order: 1;
  flex: 0 0 360px;
  flex-direction: column;
  gap: 14px;
  min-width: 320px;
  max-width: 420px;
  min-height: 0;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
}

.directory-header h1 {
  margin: 0 0 4px;
  font-size: 1.35rem;
  line-height: 1.2;
}

.directory-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.dataset-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f6f2;
}

.dataset-tab {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.dataset-tab:hover,
.dataset-tab:focus-visible {
  color: var(--accent-dark);
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.dataset-tab.is-active {
  background: #fff;
  color: var(--accent-dark);
  box-shadow: 0 1px 3px rgb(0 0 0 / 10%);
}

.search-label {
  font-weight: 700;
  font-size: 0.88rem;
}

#room-search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

#room-search:focus {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

.room-list {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.room-card {
  flex: 0 0 auto;
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.room-card:hover,
.room-card:focus-visible {
  border-color: var(--accent);
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.building-group {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.building-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 54px;
  padding: 12px 13px;
  border: 0;
  background: #fff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.building-group-toggle:hover,
.building-group-toggle:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.building-group-name {
  display: block;
  font-weight: 800;
  line-height: 1.25;
}

.building-group-count {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.building-group-icon {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--accent-dark);
  border-bottom: 2px solid var(--accent-dark);
  transform: rotate(45deg);
  transition: transform 160ms ease;
}

.building-group-toggle[aria-expanded="true"] .building-group-icon {
  transform: rotate(225deg);
}

.building-group-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 10px 10px;
  border-top: 1px solid var(--line);
  background: #f7f9f6;
}

.building-group-panel[hidden] {
  display: none;
}

.room-card.is-nested {
  border-radius: 6px;
  background: #fff;
}

.room-card-title {
  display: block;
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.25;
}

.room-id,
.popup-room-id {
  margin: -3px 0 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0;
}

.room-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
}

.badge.is-warning {
  background: transparent;
  color: var(--warning);
}

.badge.is-neutral {
  color: var(--text);
}

.room-card p,
.room-popup-content p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.room-card-detail strong {
  color: var(--text);
}

.room-popup-content h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.popup-detail strong { color: var(--text); }

.room-photo-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
  gap: 7px;
  margin: 8px 0 10px;
}

.room-photo-strip a {
  display: block;
  overflow: hidden;
  border-radius: 6px;
  background: #eef2ef;
}

.room-photo-strip a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.room-photo-strip img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

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

#map .ol-control button:focus-visible,
.room-marker:focus-visible,
.room-popup-close:focus-visible,
.room-popup a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (max-width: 760px) {
  html,
  body {
    height: 100%;
    min-height: 100%;
    overflow: hidden;
  }

  .map-shell {
    flex-direction: column;
    height: calc(100dvh - var(--site-nav-height));
    min-height: 0;
    overflow: hidden;
  }

  .map-panel {
    order: 2;
    flex: none;
    height: clamp(280px, 50dvh, 390px);
    min-height: 0;
    border: 1px solid var(--muted);
    border-radius: 6px;
    background: var(--panel);
  }

  .map-panel #map,
  .map-panel .map-loading {
    inset: 1px;
    border-radius: 5px;
  }

  .directory-panel {
    order: 1;
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    min-height: 0;
    border-right: 0;
    border-top: 1px solid var(--line);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .room-list {
    flex: none;
    overflow: visible;
  }

  .room-popup-content {
    max-width: min(280px, calc(100vw - 72px));
    max-height: min(160px, 26dvh);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 900px) {
  .desktop-nav { display: none; }
}

@media (min-width: 901px) {
  .nav-menu-button { display: none; }
}
