:root {
  --panel-bg: #f8faf8;
  --panel-border: #d3ddd4;
  --text: #1f2923;
  --muted: #627068;
  --map-bg: #d9e2dd;
  --accent: #155b73;
  --button-bg: #ffffff;
  --button-hover: #eef5f3;
  --shadow: 0 10px 28px rgb(37 48 42 / 12%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell,
#map {
  height: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--map-bg);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  position: relative;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  height: 100vh;
  padding: 22px 20px 16px;
  overflow-y: auto;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}

.sidebar-header h1 {
  margin: 4px 0 8px;
  font-size: 26px;
  line-height: 1.08;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.summary {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.control-section {
  display: grid;
  gap: 10px;
}

.control-section h2 {
  margin: 0;
  font-size: 13px;
  line-height: 1;
  letter-spacing: 0;
  text-transform: uppercase;
  color: #3a4740;
}

.layer-list {
  display: grid;
  gap: 8px;
}

.layer-toggle {
  display: grid;
  grid-template-columns: 18px 18px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  min-height: 36px;
  padding: 8px 9px;
  background: #ffffff;
  border: 1px solid #dce4de;
  border-radius: 8px;
}

.layer-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.swatch {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-radius: 4px;
  background: var(--swatch-bg, color-mix(in srgb, currentColor 28%, transparent));
}

.swatch-dot {
  border-radius: 999px;
  background: currentColor;
}

.swatch-hatch {
  --swatch-bg:
    repeating-linear-gradient(
      135deg,
      transparent 0 4px,
      currentColor 4px 7px,
      transparent 7px 12px
    ),
    #faf1e0;
}

.swatch-multicolor {
  border-color: #4f5965;
  --swatch-bg:
    linear-gradient(
      135deg,
      #faf1e0 0 17%,
      #ebc94b 17% 34%,
      #e87347 34% 50%,
      #03568c 50% 66%,
      #6f98e8 66% 83%,
      #7ed69a 83% 100%
    );
}

.layer-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.25;
}

.layer-count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

button {
  min-height: 36px;
  border: 1px solid #cdd9d2;
  border-radius: 8px;
  background: var(--button-bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

button:hover {
  background: var(--button-hover);
}

.legend-section {
  padding-bottom: 8px;
}

#legend {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.legend-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  color: #303b35;
  font-size: 13px;
  line-height: 1.25;
}

.legend-line {
  height: 0;
  border-top: 3px solid currentColor;
}

.legend-dot {
  width: 12px;
  height: 12px;
  margin-left: 3px;
  border-radius: 999px;
  background: currentColor;
}

.sidebar-footer {
  margin-top: auto;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.map-panel {
  min-width: 0;
  height: 100vh;
}

.leaflet-container {
  font: inherit;
}

.leaflet-pane,
.leaflet-map-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-pane > svg path,
.leaflet-tile-container {
  pointer-events: none;
}

.leaflet-pane > svg path.leaflet-interactive {
  pointer-events: auto;
  cursor: pointer;
}

.leaflet-popup-content {
  min-width: 220px;
  margin: 14px 16px;
  color: var(--text);
  font-size: 13px;
}

.popup-title {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.2;
}

.popup-table {
  width: 100%;
  border-collapse: collapse;
}

.popup-table th,
.popup-table td {
  padding: 4px 0;
  vertical-align: top;
  border-top: 1px solid #e4eae6;
  text-align: left;
}

.popup-table th {
  width: 42%;
  padding-right: 12px;
  color: var(--muted);
  font-weight: 600;
}

.popup-card h3 {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.2;
}

.popup-card table {
  width: 100%;
  border-collapse: collapse;
}

.popup-card th,
.popup-card td {
  padding: 4px 0;
  vertical-align: top;
  border-top: 1px solid #e4eae6;
  text-align: left;
}

.popup-card th {
  width: 42%;
  padding-right: 12px;
  color: var(--muted);
  font-weight: 600;
}

.loading-mask {
  filter: grayscale(0.4);
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 38vh) minmax(0, 1fr);
  }

  .sidebar {
    order: 2;
    height: 62vh;
    padding: 16px;
    border-top: 1px solid var(--panel-border);
    border-right: 0;
  }

  .map-panel {
    order: 1;
    height: 38vh;
  }

  .sidebar-header h1 {
    font-size: 22px;
  }
}
