* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #1f2933;
}

body {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}

#sidebar {
  background: #f6f7f9;
  border-right: 1px solid #d8dde3;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#sidebar header {
  padding: 16px;
  border-bottom: 1px solid #e2e6eb;
  background: #ffffff;
  position: sticky;
  top: 0;
  z-index: 1;
}

#sidebar hgroup {
  margin: 0 0 8px;
}

#sidebar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

#release {
  margin: 2px 0 0;
  font-size: 12px;
  color: #5f6b76;
}

#sidebar .bulk {
  display: flex;
  gap: 8px;
}

#sidebar .bulk button {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
  background: #ffffff;
  border: 1px solid #cfd5db;
  border-radius: 4px;
  cursor: pointer;
}

#sidebar .bulk button:hover {
  background: #eef1f5;
}

#layer-list {
  flex: 1;
  padding: 8px 0;
}

.layer-group {
  padding: 8px 16px 4px;
}

.layer-group h2 {
  margin: 8px 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #5f6b76;
  font-weight: 600;
}

.layer-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  cursor: pointer;
}

.layer-row input { margin: 2px 0 0; }

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
  margin-top: 2px;
}

.layer-label-wrap {
  flex: 1;
  user-select: none;
}

.layer-row label {
  cursor: pointer;
  display: block;
}

.layer-desc {
  display: block;
  font-size: 11px;
  color: #5f6b76;
  line-height: 1.4;
  margin-top: 2px;
}

#sidebar footer {
  padding: 12px 16px;
  border-top: 1px solid #e2e6eb;
  font-size: 11px;
  color: #5f6b76;
}

#sidebar footer p { margin: 0 0 4px; }
#sidebar footer a { color: #4060a8; }

#map {
  width: 100%;
  height: 100%;
}

#inspector {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(90vw, 320px);
  background: #ffffff;
  border-left: 1px solid #d8dde3;
  box-shadow: -2px 0 16px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  z-index: 5;
}

body.inspector-open #inspector {
  transform: translateX(0);
}

#inspector header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid #e2e6eb;
}

#inspector h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #5f6b76;
}

#inspector-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: #5f6b76;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
}

#inspector-close:hover {
  background: #eef1f5;
  border-color: #cfd5db;
}

#inspector-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 16px;
  font-size: 12px;
}

/* Keep the map's right-edge controls clear of the open panel. */
.maplibregl-ctrl-top-right,
.maplibregl-ctrl-bottom-right {
  transition: transform 0.2s ease;
}

body.inspector-open .maplibregl-ctrl-top-right,
body.inspector-open .maplibregl-ctrl-bottom-right {
  transform: translateX(-320px);
}

.popup-title {
  font-weight: 600;
  font-size: 13px;
  margin: 0 0 6px;
}

.popup-layer {
  color: #5f6b76;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.popup-props {
  border-top: 1px solid #e2e6eb;
  padding-top: 6px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
}

.popup-props dt { color: #5f6b76; }
.popup-props dd { margin: 0; word-break: break-word; }

.popup-feature + .popup-feature {
  border-top: 1px solid #e2e6eb;
  margin-top: 10px;
  padding-top: 10px;
}

#sidebar-toggle { display: none; }
#sidebar-backdrop { display: none; }

@media (max-width: 640px) {
  body { grid-template-columns: 1fr; }

  #sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(85vw, 320px);
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 16px rgba(0, 0, 0, 0.2);
  }

  body.sidebar-open #sidebar { transform: translateX(0); }

  #sidebar header { padding-left: 60px; }

  body.sidebar-open #sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 9;
  }

  #sidebar-toggle {
    display: flex;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 11;
    width: 40px;
    height: 40px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    padding: 0;
    background: #ffffff;
    border: 1px solid #cfd5db;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    cursor: pointer;
  }

  #sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: #1f2933;
    border-radius: 1px;
  }

  /* On narrow screens the inspector becomes a bottom sheet. */
  #inspector {
    top: auto;
    left: 0;
    right: 0;
    width: auto;
    height: min(55vh, 360px);
    border-left: none;
    border-top: 1px solid #d8dde3;
    box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.15);
    transform: translateY(100%);
  }

  body.inspector-open #inspector {
    transform: translateY(0);
  }

  /* The bottom sheet doesn't cover the right edge, so leave controls put. */
  body.inspector-open .maplibregl-ctrl-top-right,
  body.inspector-open .maplibregl-ctrl-bottom-right {
    transform: none;
  }
}
