/* =========================
   ROOT & THEME
========================= */
:root {
  --bg: 255 255 255;
  --fg: 0 0 0;

  --toolbar-w: 70px;
  --header-h: 60px;

  --radius: 6px;
  --radius-lg: 8px;

  --transition: 0.2s ease;
  --font: 500 15px "Segoe UI", sans-serif;

  color: rgb(var(--fg));
  background: #fff;
}

/* =========================
   RESET / BASE
========================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:where(html, body, #cesiumContainer) {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}

body {
  background: #00000040;
  font: var(--font);
}

:where(button, input) {
  font: inherit;
  color: inherit;
}

button {
  all: unset;
  cursor: pointer;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* =========================
   GENERIC UTILITIES
========================= */
.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

.panel {
  background: rgb(var(--bg) / 90%);
  border-radius: var(--radius);
}

.hidden {
  opacity: 0;
  pointer-events: none;
}

/* =========================
   CESIUM OVERRIDES
========================= */
.cesium-viewer-toolbar {
  display: none;
}

.cesium-credit-logoContainer img {
  width: 124px;
}

/* =========================
   LAYOUT
========================= */
body > header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding-left: 22px;
  background: #fff;
}

body > header h1 {
  font-size: 1em;
  font-weight: 600;
}

body > header > span {
  opacity: 0.6;
}

body > .wrapper {
  position: relative;
  height: calc(100% - var(--header-h));
  overflow: hidden;
}

/* =========================
   CONTROLS (TOP RIGHT)
========================= */
.controls {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 999;

  display: flex;
  flex-direction: column;
  align-items: center;
}

.controls > div {
  width: 40px;
  height: 36px;
  margin-top: 10px;
  margin-bottom: 5px;

  border-radius: var(--radius-lg);
  cursor: pointer;

  background: rgb(var(--bg) / 90%);
  display: flex;
  justify-content: center;
  align-items: center;
}

.controls svg {
  width: 18px;
  fill: rgb(var(--fg));
}

/* Compass */
#compass {
  width: 54px;
  height: 54px;
  padding: 14px;
  border-radius: 50%;
}

#compass > div {
  width: 100%;
  height: 100%;
  border-radius: 50%;

  background: rgb(var(--fg) / 15%);
  display: grid;
  place-items: center;
}

#compass svg {
  width: 22px;
}

#compass path:nth-child(2) {
  fill: rgb(var(--fg) / 50%);
}

/* =========================
   TOOLBAR (LEFT)
========================= */
.toolbar {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 900;

  padding: 20px 10px;

  display: flex;
  flex-direction: column;

  pointer-events: none;
}

.toolbar > div {
  margin-bottom: 8px;
  pointer-events: auto;
}

/* Buttons */
.toolbar button {
  position: relative;
  width: 46px;
  height: 46px;
}

.toolbar .icon {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);

  display: grid;
  place-items: center;

  background: #ffffffe6;
}

.toolbar .icon {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);

  display: grid;
  place-items: center;

  background: #ffffffe6;
}

.toolbar button:hover .icon,
.toolbar .legendIsOpen .icon {
  background: #fff;
}

/* =========================
   LEGEND TOOLBAR (LEFT)
========================= */
.legendtoolbar {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 900;

  padding: 20px 10px;

  display: flex;
  flex-direction: column;

  pointer-events: none;
}

.legendtoolbar > div {
  margin-bottom: 8px;
  pointer-events: auto;
}

/* Buttons */
.legendtoolbar button {
  position: relative;
  width: 46px;
  height: 46px;
}

.legendtoolbar .legendicon {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);

  display: grid;
  place-items: center;

  background: #ffffffe6;
}

.legendtoolbar .legendicon {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);

  display: grid;
  place-items: center;

  background: #ffffffe6;
}

.legendtoolbar button:hover .legendicon,
.legendtoolbar .legendIsOpen .legendicon {
  background: #fff;
}


/* =========================
   LEGEND PANEL
========================= */
.legend {
  position: absolute;
  top: 20px;
  left: var(--toolbar-w);
  width: 340px;

  background: #fffffff2;

  opacity: 0;
  pointer-events: none;
  transform: translateX(-20px);

  transition: var(--transition);
}

.legendIsOpen .legend {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

/* =========================
   TOOLTIP
========================= */
.tooltip {
  position: absolute;
  inset: 0 auto 0 calc(100% - 10px);
  padding-top: 15px;
  width: 110px;
  text-align: center;

  background: #fff;
  border-radius: 0 var(--radius) var(--radius) 0;

  opacity: 0;
  pointer-events: none;
  transform: translateX(-15px);

  transition: transform var(--transition), opacity var(--transition);
}

body:not(.noTooltip) 
.legendToggle:not(.legendIsOpen) > button:hover .tooltip {
  opacity: 1;
  transform: translateX(0);
}

/* =========================
   LEGEND TOOLTIP
========================= */
.legendtooltip {
  position: absolute;
  inset: 0 auto 0 calc(100% - 10px);
  padding-top: 15px;
  width: 110px;
  text-align: center;

  background: #fff;
  border-radius: 0 var(--radius) var(--radius) 0;

  opacity: 0;
  pointer-events: none;
  transform: translateX(-15px);

  transition: transform var(--transition), opacity var(--transition);
}

body:not(.noTooltip) 
.legendToggle:not(.legendIsOpen) > button:hover .tooltip {
  opacity: 1;
  transform: translateX(0);
}

/* =========================
    SLIDE-IN PANEL
========================= */
.info-panel {
  position: absolute;
  right: 20px;
  top: 150px;
  width: 280px;

  background: rgba(255,255,255,0.95);
  border-radius: 10px;
  padding: 12px;

  z-index: 1000;
  transition: transform 0.25s ease, opacity 0.25s ease;

  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.info-panel.hidden {
  transform: translateX(120%);
  opacity: 0;
  pointer-events: none;
}

.info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.info-header button {
  cursor: pointer;
  background: none;
  border: none;
  font-size: 16px;
}

/* =========================================
   BUILDINGS PANEL
========================================= */

#buildingsPanel .legend {
  width: 320px;
  height: 70vh;

  background: rgba(255,255,255,0.95);
  border-radius: 10px;
  padding: 14px;

  display: flex;
  flex-direction: column;

  overflow: hidden;
}

/* search */

.sidebar-header {
  padding: 14px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}

.sidebar-header input {
  width: 100%;
  padding: 14px;

  border: none;
  border-radius: 8px;

  background: rgba(0,0,0,0.05);

  outline: none;
}

/* list */

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* rows */

.building-item {
  position: relative;

  padding: 14px 16px;
  border-radius: 8px;

  background: rgba(255,255,255,0.03);

  cursor: pointer;

  transition:
    background 0.2s ease,
    transform 0.2s ease;
}

.building-item:hover {
  background: rgba(0,0,0,0.05);
  transform: translateX(4px);
}

/* =========================
   RESPONSIVE
========================= */
@media (max-width: 981px) {
  :root {
    --header-h: 52px;
  }

  .controls {
    top: 10px;
    right: 5px;
    transform: scale(0.9);
    transform-origin: top right;
  }

  .tooltip {
    display: none;
  }

  .toolbar {
    padding: 10px 5px;
  }

  .toolbar button {
    transform: scale(0.9);
  }

  .legend {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    border-radius: var(--radius);
  }
}

/* =========================
   LEGEND BOX
========================= */

.legend-box {
  top: 80px; /* under toolbar icons */
  left: var(--toolbar-w);
  width: 220px;

  padding: 14px;
  border-radius: 10px;

  display: flex;
  flex-direction: column;
  gap: 10px;

  background: rgba(255,255,255,0.95);

  opacity: 0;
  pointer-events: none;
  transform: translateX(-10px);

  transition: 0.2s ease;
}

.legendToggle.legendIsOpen .legend-box {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.legend-icon svg {
  width: 22px;
  height: 22px;
  display: block;
  color: #333;
}

/* legend rows */
.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

/* colored dots */
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.dot.red { background: #D57667; }
.dot.blue { background: #019CD7; }
.dot.green { background: #4AA271; }
