:root {
  color-scheme: light;
  --ink: #15211d;
  --muted: #5a6a65;
  --line: #c7d7d2;
  --surface: #ffffff;
  --surface-soft: #f1f7f4;
  --surface-warm: #fff3df;
  --green: #1f6f5b;
  --green-dark: #0f4538;
  --ochre: #be7327;
  --rust: #af482d;
  --blue: #2d688f;
  --plum: #6c4f6c;
  --shadow: 0 18px 52px rgba(13, 32, 27, 0.32);
  --glass: rgba(248, 253, 251, 0.9);
  --glass-strong: rgba(255, 255, 255, 0.96);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at 18% 15%, rgba(40, 109, 89, 0.22), transparent 38%),
    radial-gradient(circle at 82% 88%, rgba(191, 120, 35, 0.18), transparent 35%),
    #0d1b17;
  color: var(--ink);
  font-family:
    "Manrope",
    "Segoe UI",
    system-ui,
    sans-serif;
  letter-spacing: 0;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.app-shell,
.workspace {
  width: 100%;
  height: 100%;
}

.workspace {
  position: relative;
  overflow: hidden;
}

.map-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #dbe5df;
}

.map {
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: #dbe5df;
}

.leaflet-container {
  width: 100%;
  height: 100%;
  font: inherit;
}

.leaflet-tile,
.leaflet-tile-container img {
  max-width: none !important;
  max-height: none !important;
}

.leaflet-top.leaflet-left .leaflet-control-zoom {
  margin-top: 14px;
  margin-left: calc(14px + min(420px, calc(100vw - 28px)) + 12px);
}

.sidebar {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 600;
  width: min(420px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  border: 1px solid rgba(14, 58, 48, 0.22);
  border-radius: 10px;
  padding: 14px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.species-detail-section {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 700;
  width: min(460px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  overflow: auto;
  border: 1px solid rgba(14, 58, 48, 0.24);
  border-radius: 10px;
  padding: 14px;
  background: var(--glass-strong);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.species-detail-section.is-hidden,
.workspace.detail-is-hidden .species-detail-section {
  display: none;
}

.panel-header {
  width: 100%;
  margin: 0;
}

.panel-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
}

.panel-title-copy {
  min-width: 0;
}

.panel-title-row h1 {
  margin-bottom: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 13px;
  color: var(--green-dark);
  font-family:
    "Space Grotesk",
    "Manrope",
    sans-serif;
  font-size: 1.55rem;
  line-height: 1.05;
}

h2 {
  margin-bottom: 0;
  font-size: 0.95rem;
  line-height: 1.2;
}

h3 {
  margin-bottom: 4px;
  font-size: 1rem;
  line-height: 1.2;
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-card {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: rgba(255, 255, 255, 0.82);
}

.stat-value {
  display: block;
  color: var(--green-dark);
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1;
}

.stat-label {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.25;
}

.control-section,
.trail-summary,
.species-section {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.86);
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.search-input,
.select-input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.search-input:focus,
.select-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 111, 91, 0.14);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.detail-close-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.detail-close-button:hover,
.detail-close-button:focus-visible {
  border-color: var(--green);
  color: var(--green-dark);
  outline: none;
}

.mini-count {
  display: inline-grid;
  min-width: 32px;
  height: 24px;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-warm);
  color: #7a3e12;
  font-size: 0.77rem;
  font-weight: 800;
}

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

.trail-button {
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  color: var(--ink);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.trail-button:hover,
.trail-button.is-active {
  border-color: var(--green);
  background: #eaf6f1;
}

.trail-button strong {
  display: block;
  margin-bottom: 5px;
  color: var(--green-dark);
}

.trail-button span {
  color: var(--muted);
  font-size: 0.8rem;
}

.quick-actions {
  display: flex;
  gap: 6px;
}

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

.layer-toggle {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.layer-toggle span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.color-input {
  width: 34px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
  background: #fff;
}

.text-button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--green-dark);
  background: #fff;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 800;
}

.text-button:hover {
  border-color: var(--green);
}

.toolbar {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
}

.icon-button:hover,
.icon-button:focus-visible,
.icon-button.is-active {
  border-color: var(--green);
  color: var(--green-dark);
  outline: none;
}

.icon-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.icon-button svg {
  width: 17px;
  height: 17px;
}

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

.group-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.group-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
}

.swatch {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--group-color, var(--green));
}

.group-toggle .group-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 800;
}

.group-toggle .group-total {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.76rem;
}

.trail-summary {
  padding: 12px;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}

.summary-grid div {
  min-height: 50px;
  border: 1px solid #e4e9ee;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.summary-grid .wide {
  grid-column: 1 / -1;
}

dt {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 4px 0 0;
  font-size: 0.93rem;
  font-weight: 800;
}

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

.group-count-card {
  display: grid;
  min-height: 68px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--group-color, var(--green));
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.group-count-card:hover {
  border-color: var(--green);
  background: #edf7f3;
}

.group-count-card span {
  overflow: hidden;
  font-size: 0.8rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-count-card strong {
  color: var(--green-dark);
  font-size: 1.3rem;
  line-height: 1;
}

.group-count-card small {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.species-list {
  display: grid;
  gap: 10px;
  max-height: 34dvh;
  overflow: auto;
  padding-right: 2px;
}

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

.group-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  border: 0;
  border-left: 5px solid var(--group-color, var(--green));
  padding: 10px 12px;
  background: #edf4f1;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.group-panel-header[aria-expanded="true"] {
  background: #e6f2ec;
}

.group-panel-header:hover {
  background: #e6f2ec;
}

.group-panel-text {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.group-panel-title {
  min-width: 0;
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-panel-count {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

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

.group-panel.is-open .group-panel-chevron {
  transform: rotate(225deg);
}

.species-compact-list {
  display: none;
  max-height: 300px;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.species-compact-list.is-open {
  display: grid;
}

.species-row {
  display: grid;
  width: 100%;
  min-height: 50px;
  border: 0;
  border-bottom: 1px solid #edf1f4;
  padding: 9px 12px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.species-row:hover,
.species-row.is-active {
  background: #fff8ed;
}

.species-row.is-active {
  box-shadow: inset 4px 0 0 var(--ochre);
}

.species-row span {
  overflow-wrap: anywhere;
  font-size: 0.88rem;
  font-weight: 800;
}

.species-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.76rem;
  font-style: italic;
  overflow-wrap: anywhere;
}

.species-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.species-card-detail {
  box-shadow: 0 10px 24px rgba(31, 41, 51, 0.08);
}

.species-media {
  display: grid;
  min-height: 220px;
  place-items: center;
  padding: 10px;
  background: #edf1f3;
}

.species-media img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 360px;
  border-radius: 6px;
  object-fit: contain;
}

.species-no-photo {
  display: grid;
  min-height: 120px;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
}

.species-body {
  padding: 13px;
}

.species-title-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.species-scientific {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  font-style: italic;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  background: #eef2f5;
  color: var(--ink);
  font-size: 0.74rem;
  font-weight: 800;
}

.chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--group-color, var(--green));
}

.species-meta {
  display: grid;
  gap: 6px;
  margin: 12px 0;
}

.species-description,
.species-note {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 0.88rem;
  line-height: 1.45;
}

.species-note {
  border-left: 4px solid var(--ochre);
  padding: 9px 10px;
  background: var(--surface-warm);
  color: #603813;
}

.meta-row {
  display: grid;
  grid-template-columns: 114px minmax(0, 1fr);
  gap: 10px;
  color: var(--ink);
  font-size: 0.83rem;
}

.meta-row span:first-child {
  color: var(--muted);
  font-weight: 800;
}

.resource-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--green-dark);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 800;
}

.resource-link:hover {
  border-color: var(--green);
  background: #edf7f3;
}

.audio-player {
  width: 100%;
  height: 34px;
  margin-top: 10px;
}

.sound-button {
  min-height: 32px;
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 900;
}

.sound-button:hover {
  background: var(--green-dark);
}

.sound-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.sound-status {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.3;
}

.media-tools {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.media-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-soft);
}

.media-panel-title {
  display: block;
  margin-bottom: 6px;
  color: var(--green-dark);
  font-size: 0.82rem;
  font-weight: 900;
}

.media-panel-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
}

.pending-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px dashed var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  background: #fff;
  font-size: 0.8rem;
  font-weight: 800;
}

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

.map-status {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 500;
  max-width: min(360px, calc(100% - 28px));
  border: 1px solid rgba(31, 41, 51, 0.12);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  box-shadow: 0 10px 24px rgba(31, 41, 51, 0.14);
  font-size: 0.82rem;
  font-weight: 800;
}

.map-status.is-hidden {
  display: none;
}

.trail-marker {
  display: grid;
  width: 74px;
  height: 74px;
  place-items: center;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  box-shadow: 0 12px 26px rgba(31, 41, 51, 0.35);
}

.trail-marker.is-muted {
  opacity: 0.55;
  filter: grayscale(0.35);
}

.trail-marker strong {
  display: block;
  font-size: 1.05rem;
  line-height: 1;
  text-align: center;
}

.trail-marker span {
  display: block;
  margin-top: 3px;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}

.leaflet-popup-content-wrapper {
  border-radius: 8px;
}

.popup-title {
  margin: 0 0 8px;
  color: var(--green-dark);
  font-size: 1rem;
}

.popup-grid {
  display: grid;
  gap: 6px;
  margin: 8px 0 10px;
  font-size: 0.82rem;
}

.popup-button {
  width: 100%;
  min-height: 32px;
  border: 0;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.popup-button:hover {
  background: var(--green-dark);
}

@media (max-width: 1100px) {
  .sidebar {
    width: min(400px, calc(100% - 28px));
  }

  .leaflet-top.leaflet-left .leaflet-control-zoom {
    margin-left: calc(14px + min(400px, calc(100vw - 28px)) + 12px);
  }

  .species-detail-section {
    width: min(430px, calc(100% - 28px));
  }
}

@media (max-width: 900px) {
  body {
    overflow: hidden;
  }

  .sidebar {
    left: 10px;
    right: 10px;
    top: auto;
    bottom: 10px;
    width: auto;
    max-height: 46dvh;
    padding: 12px;
    gap: 10px;
  }

  .species-detail-section {
    left: 10px;
    right: 10px;
    top: 10px;
    width: auto;
    max-height: 58dvh;
    padding: 12px;
  }

  .map-status {
    top: 10px;
    left: 10px;
    bottom: auto;
    max-width: calc(100% - 20px);
  }

  h1 {
    font-size: 1.35rem;
  }

  .toolbar {
    max-width: 114px;
  }

  .trail-grid,
  .group-grid,
  .stat-row,
  .breakdown {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .summary-grid .wide {
    grid-column: auto;
  }

  .species-list {
    max-height: 24dvh;
  }

  .species-compact-list {
    max-height: none;
    overflow: visible;
  }

  .leaflet-top.leaflet-left .leaflet-control-zoom {
    margin-top: 10px;
    margin-left: 10px;
  }

  .workspace:not(.detail-is-hidden) .leaflet-control-zoom {
    opacity: 0;
    pointer-events: none;
  }
}

@media (max-width: 560px) {
  .sidebar,
  .species-detail-section {
    border-radius: 10px;
  }

  .meta-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .group-panel-title {
    white-space: normal;
  }
}
