:root {
  --bg: #ffffff;
  --fg: #222222;
  --muted: #6b7280;
  --border: #e5e7eb;

  /* Per-category accent colors (active button background + border) */
  --cat-carpenter_bee:      #edb254;
  --cat-no_see_um_mosquito: #75c7c9;
  --cat-wasp:               #7d9e2d;
  --cat-bed_bug:            #75c7c9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

#controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  overflow-x: auto;
}

#logo {
  height: 40px;
  width: 40px;
  flex: 0 0 auto;
  margin-right: 8px;
  user-select: none;
}

.cat-btn {
  font: inherit;
  font-family: "Lato", sans-serif;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: #fff;
  color: #222;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.cat-btn:hover { background: #f9fafb; }

/* Active state: solid pill filled with the category's accent color */
.cat-btn.is-active {
  color: #222;
  border-color: transparent;
}
.cat-btn[data-category="carpenter_bee"].is-active {
  background: var(--cat-carpenter_bee);
  border-color: var(--cat-carpenter_bee);
}
.cat-btn[data-category="no_see_um_mosquito"].is-active {
  background: var(--cat-no_see_um_mosquito);
  border-color: var(--cat-no_see_um_mosquito);
}
.cat-btn[data-category="wasp"].is-active {
  background: var(--cat-wasp);
  border-color: var(--cat-wasp);
}
.cat-btn[data-category="bed_bug"].is-active {
  background: var(--cat-bed_bug);
  border-color: var(--cat-bed_bug);
}

.cat-btn:focus-visible { outline: 2px solid #222; outline-offset: 2px; }

/* ----- Time controls row (year buttons + month slider) ----- */
#timeControls {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

#yearButtons {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
  overflow-x: auto;
}

.year-btn,
.month-btn {
  font: inherit;
  font-family: "Lato", sans-serif;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: #fff;
  color: #222;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease;
}
.year-btn:hover,
.month-btn:hover { background: #f9fafb; }
.year-btn.is-active,
.month-btn.is-active {
  background: #222;
  border-color: #222;
  color: #fff;
}
.year-btn:focus-visible,
.month-btn:focus-visible { outline: 2px solid #222; outline-offset: 2px; }

#sliderRow {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
}
#sliderWrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 160px;
  /* Inner padding so the slider thumb (9px radius) doesn't get clipped at the edges. */
  padding: 0 9px;
}
#monthTicks {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  user-select: none;
}
#monthTicks span {
  flex: 1 1 0;
  text-align: center;
}
#monthSlider {
  flex: 1 1 auto;
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  margin: 6px 0 2px;
}
#monthSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #222;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  cursor: grab;
}
#monthSlider::-webkit-slider-thumb:active { cursor: grabbing; }
#monthSlider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #222;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  cursor: grab;
}
#monthSlider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px rgba(34,34,34,0.25); }

/* When "All" mode is active, mute the slider thumb so it's visually subordinate. */
#monthSlider.is-muted::-webkit-slider-thumb {
  background: var(--muted);
  opacity: 0.55;
}
#monthSlider.is-muted::-moz-range-thumb {
  background: var(--muted);
  opacity: 0.55;
}

#periodLabel {
  font-size: 13px;
  font-weight: 700;
  color: #222;
  white-space: nowrap;
  min-width: 110px;
  text-align: right;
  flex: 0 0 auto;
}

#map {
  flex: 1 1 auto;
  width: 100%;
  background: #f3f4f6;
}

#legend {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--fg);
  background: var(--bg);
}
#legend-text {
  font-size: 13px;
  color: var(--fg);
  margin-right: auto;
  flex: 0 1 auto;
}
#legend-text strong { font-weight: 700; }
#legend-context { color: var(--muted); }
#legend-scale {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.legend-edge {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  text-align: center;
}
#legend-gradient {
  display: inline-block;
  height: 12px;
  width: 220px;
  border-radius: 4px;
  background: linear-gradient(to right, #2c7bb6 0%, #abd9e9 25%, #ffffbf 50%, #fdae61 75%, #d7191c 100%);
  border: 1px solid var(--border);
}

/* Stack year row + slider row vertically on narrow viewports (mobile / narrow iframes) */
@media (max-width: 640px) {
  #timeControls {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  #yearButtons { flex-wrap: nowrap; }
  #sliderRow   { width: 100%; }
}

/* Compact mode for very narrow iframes */
@media (max-width: 480px) {
  #controls    { padding: 8px 10px; gap: 6px; }
  #logo        { height: 32px; width: 32px; margin-right: 4px; }
  .cat-btn     { padding: 6px 12px; font-size: 13px; }
  #timeControls { padding: 8px 10px; }
  .year-btn,
  .month-btn   { padding: 4px 10px; font-size: 12px; }
  #periodLabel { font-size: 12px; min-width: 0; text-align: left; }
  #monthTicks  { font-size: 9px; }
  #legend      { font-size: 11px; padding: 8px 10px; gap: 10px; flex-wrap: wrap; }
  #legend-text { font-size: 12px; flex: 1 1 100%; margin-right: 0; }
  #legend-gradient { width: 140px; }
}
