:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f0;
  --ink: #17211f;
  --muted: #5d6a66;
  --line: #d9e0dd;
  --green: #1f7a4d;
  --green-dark: #135437;
  --blue: #245f8f;
  --amber: #c97a16;
  --red: #b2443c;
  --shadow: 0 12px 32px rgba(26, 38, 34, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

a {
  color: var(--blue);
}

button,
input,
select {
  font: inherit;
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px);
  background: #fbfcfc;
  border-bottom: 1px solid var(--line);
}

.kicker {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.6rem, 2.4vw, 2.45rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.source-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 22px;
  padding: 22px clamp(18px, 4vw, 48px) 48px;
}

.filters {
  align-self: start;
  position: sticky;
  top: 18px;
  display: grid;
  gap: 18px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.filter-block {
  display: grid;
  gap: 9px;
}

label,
.filter-heading {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
}

.search-box {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 9px;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.search-box svg {
  width: 18px;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
}

select {
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.chip.active {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 640;
  text-transform: none;
}

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

.results-area {
  min-width: 0;
}

.result-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

#activeFilters {
  color: var(--muted);
  margin-left: 8px;
}

.view-toggle {
  display: flex;
  gap: 6px;
}

.icon-button,
.close-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.icon-button svg,
.close-button svg {
  width: 18px;
  height: 18px;
}

.icon-button.active {
  color: #fff;
  border-color: var(--green-dark);
  background: var(--green-dark);
}

.species-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}

.species-card {
  appearance: none;
  display: grid;
  grid-template-rows: 170px auto;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(23, 33, 31, 0.03);
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.species-card:hover,
.species-row:hover {
  border-color: #aebbb6;
  box-shadow: var(--shadow);
}

.species-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--surface-2);
}

.species-body {
  display: grid;
  gap: 10px;
  padding: 13px;
}

.species-title {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.18;
}

.scientific {
  color: var(--muted);
  font-style: italic;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 680;
}

.tag.alert {
  background: #ffe6df;
  color: var(--red);
}

.tag.status-potential {
  background: #e7f0fb;
  color: var(--blue);
}

.tag.status-established {
  background: #e4f3ea;
  color: var(--green-dark);
}

.tag.status-early {
  background: #fff1d7;
  color: var(--amber);
}

.threat {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.results-area.table-mode .species-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.results-area.table-mode .species-card {
  grid-template-columns: 84px minmax(0, 1fr);
  grid-template-rows: auto;
}

.results-area.table-mode .species-image {
  min-height: 100%;
  aspect-ratio: 1;
}

.results-area.table-mode .species-body {
  grid-template-columns: minmax(190px, 1.1fr) minmax(180px, 0.8fr) minmax(210px, 1fr);
  align-items: center;
}

.results-area.table-mode .tag-row {
  align-content: center;
}

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

.detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 18, 17, 0.32);
  z-index: 20;
}

.detail-panel {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 30;
  width: min(760px, 100vw);
  overflow: auto;
  transform: translateX(100%);
  transition: transform 160ms ease;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.detail-panel.open {
  transform: translateX(0);
}

.close-button {
  position: sticky;
  top: 14px;
  left: calc(100% - 52px);
  z-index: 2;
  margin: 14px;
}

.detail-hero {
  display: grid;
  grid-template-columns: minmax(190px, 260px) minmax(0, 1fr);
  gap: 20px;
  padding: 0 24px 20px;
  border-bottom: 1px solid var(--line);
}

.detail-hero img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
}

.detail-hero h2 {
  margin: 0 0 6px;
  font-size: clamp(1.45rem, 3vw, 2.1rem);
  line-height: 1.12;
}

.detail-body {
  display: grid;
  gap: 22px;
  padding: 22px 24px 34px;
}

.summary-text {
  margin: 0;
  color: var(--ink);
  font-size: 1.04rem;
}

.section-grid {
  display: grid;
  gap: 12px;
}

.info-section {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.info-section h3 {
  margin: 0 0 6px;
  font-size: 0.98rem;
}

.info-section p {
  margin: 0;
  color: var(--muted);
}

.rich-detail {
  overflow-wrap: anywhere;
}

.rich-detail img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.rich-detail hr {
  border: 0;
  border-top: 1px solid var(--line);
}

.file-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.file-list a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
}

@media (max-width: 900px) {
  .topbar {
    align-items: start;
    flex-direction: column;
  }

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

  .filters {
    position: static;
  }

  .results-area.table-mode .species-body {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .topbar,
  .workspace {
    padding-left: 14px;
    padding-right: 14px;
  }

  .source-meta,
  .result-toolbar {
    align-items: start;
    flex-direction: column;
  }

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

  .detail-hero {
    grid-template-columns: 1fr;
    padding-left: 16px;
    padding-right: 16px;
  }

  .detail-body {
    padding-left: 16px;
    padding-right: 16px;
  }
}
