:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #1d2321;
  --muted: #5d6763;
  --border: #dde2df;
  --accent: #2f7a4f;
  --accent-text: #ffffff;
  --hover: #eef3f0;
  --radius: 8px;
  --header-h: 3.25rem;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131715;
    --surface: #1b201e;
    --text: #e4e9e6;
    --muted: #9aa5a0;
    --border: #2c3431;
    --accent: #5cbf86;
    --accent-text: #0d130f;
    --hover: #232a27;
  }
}

* { box-sizing: border-box; }

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

body {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

/* ---- header ---- */

.site-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 650; color: var(--text); text-decoration: none; }

.badge {
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.75rem;
  font-weight: 600;
}

.site-header nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Section tabs: full header height, active one underlined. */
.site-header .tabs { align-self: stretch; gap: 0.25rem; margin-left: 1rem; }

.tabs a {
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
}

.tabs a:hover { color: var(--text); background: var(--hover); }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }

.site-header .whoami { margin-left: auto; }
.site-header .tabs + .account { margin-left: auto; }
.account a[aria-current="page"] { font-weight: 600; }

.logout { display: flex; align-items: center; gap: 0.5rem; margin: 0; }
.whoami {
  padding-left: 0.75rem;
  border-left: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ---- generic pages ---- */

/* Document-style pages scroll the whole window, not an inner container. */
body:has(> .page) { height: auto; min-height: 100dvh; grid-template-rows: var(--header-h) auto; }
body:has(> .page) .site-header { position: sticky; top: 0; z-index: 10; }

.page {
  padding: 1.5rem 1rem 2rem;
  width: 100%;
  max-width: 80rem;
  margin: 0 auto;
}

.page-narrow { max-width: 26rem; }
.page h1 { margin: 0; font-size: 1.35rem; }

.card {
  display: grid;
  gap: 1rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.strong { font-weight: 600; }
.italic { font-style: italic; }
.nowrap { white-space: nowrap; }
.card p { margin: 0; }

.alert {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  background: #fdecea;
  color: #8a1c12;
}

.field input {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}

.button {
  padding: 0.55rem 1rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.button:hover { filter: brightness(1.08); }

a.button { display: inline-block; text-decoration: none; }

.button-outline {
  background: none;
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.button-outline:hover { filter: none; background: var(--hover); }

/* ---- landing page ---- */

/* align-content: start keeps the sections packed at the top instead of spreading over tall windows. */
.page-prose { max-width: 52rem; display: grid; align-content: start; gap: 1.5rem; }
.page-prose h2 { margin: 0; font-size: 1.2rem; }
.page-prose h3 { margin: 0; font-size: 1rem; }

/* Body text sits directly on the page background, like the hero. */
.prose { display: grid; gap: 0.75rem; font-size: 1rem; line-height: 1.6; }
.prose p { margin: 0; }
/* 0.75rem inside a section, 1.5rem (gap + margin) before each new heading. */
.prose h2:not(:first-child) { margin-top: 0.75rem; }
.prose .steps { line-height: 1.45; }

.hero { display: grid; gap: 0.75rem; padding-top: 0.5rem; }
.hero h1 { font-size: 1.9rem; line-height: 1.2; }
.lead { margin: 0; font-size: 1rem; line-height: 1.6; max-width: 40rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.5rem; }

.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; }
.steps .card { gap: 0.4rem; padding: 1.25rem; }

/* ---- findings list ---- */

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.filters { display: flex; align-items: end; gap: 0.5rem; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  text-decoration: none;
}

a.chip:hover { background: var(--hover); }
.chip .count { font-size: 0.8rem; color: var(--muted); }
.chip-active { border-color: var(--accent); font-weight: 600; padding-right: 0.3rem; }
.chip-active .count { font-weight: 400; }

.chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  color: var(--muted);
}

.chip-remove:hover { background: var(--hover); color: var(--text); }

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.findings-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

.findings-table th,
.findings-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.findings-table th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.findings-table tbody tr:last-child td { border-bottom: 0; }
.findings-table tbody tr:hover { background: var(--hover); }
.findings-table .note { max-width: 20rem; color: var(--muted); }

.thumb {
  display: block;
  width: 3.5rem;
  height: 3.5rem;
  object-fit: cover;
  border-radius: 6px;
  background: var(--border);
}

.status-pill {
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-pending { background: #fff3cd; color: #7a5b00; }
.status-approved { background: #dcf3e4; color: #1e6a3e; }
.status-rejected { background: #fbe0dd; color: #8a1c12; }

.moderate { display: flex; gap: 0.35rem; }
.icon-button {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-button:hover { background: var(--border); }
.icon-approve { color: #1e8a4c; }
.icon-reject { color: #b3261e; }
.icon-return { color: var(--muted); }
.icon-return:hover { color: var(--text); }

.pager { display: flex; gap: 1.5rem; margin-top: 1rem; }

@media (prefers-color-scheme: dark) {
  .alert, .status-rejected { background: #3d1d19; color: #f2b8b0; }
  .status-pending { background: #3a3014; color: #f1d98a; }
  .status-approved { background: #183326; color: #9fdcb7; }
  .icon-approve { color: #5cc98a; }
  .icon-reject { color: #f2766b; }
}

/* ---- map page ---- */

.map-layout {
  display: grid;
  grid-template-columns: minmax(18rem, 24rem) 1fr;
  grid-template-areas: "sidebar map";
  min-height: 0;
}

.sidebar {
  grid-area: sidebar;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 0.75rem;
  min-height: 0;
  padding: 1rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
}


.field { display: grid; gap: 0.25rem; font-size: 0.85rem; color: var(--muted); }

.field select {
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}

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

.findings {
  list-style: none;
  margin: 0 -0.5rem;
  padding: 0;
  overflow-y: auto;
  min-height: 0;
}

.finding {
  display: grid;
  grid-template-columns: 4rem 1fr;
  gap: 0.75rem;
  align-items: center;
  width: 100%;
  padding: 0.5rem;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.finding:hover, .finding:focus-visible { background: var(--hover); outline: none; }

.finding img {
  width: 4rem;
  height: 4rem;
  object-fit: cover;
  border-radius: 6px;
  background: var(--border);
}

.finding-text { display: grid; gap: 0.1rem; min-width: 0; }

.finding-name {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.finding-meta { font-size: 0.8rem; color: var(--muted); }

.swatch {
  flex: none;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.25);
}

.map { grid-area: map; min-height: 0; }

/* ---- popup ---- */

.popup { display: grid; gap: 0.35rem; width: 220px; }
.popup img { width: 100%; height: auto; border-radius: 6px; }
.popup-title { font-weight: 650; font-size: 0.95rem; }
.popup-latin { font-style: italic; color: #5d6763; }
.popup-meta { font-size: 0.8rem; color: #5d6763; }
.popup-note { margin: 0; font-size: 0.85rem; }
.popup-species { font-size: 0.85rem; }

/* ---- species pages ---- */

.species-layout {
  display: grid;
  grid-template-columns: minmax(16rem, 20rem) 1fr;
  min-height: 0;
}

.species-menu {
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 0.5rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.species-menu ul { list-style: none; margin: 0; padding: 0; }

.species-menu a {
  display: grid;
  gap: 0.05rem;
  padding: 0.45rem 0.5rem;
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
}

.species-menu a:hover, .species-menu a:focus-visible { background: var(--hover); outline: none; }
.species-menu a[aria-current="page"] { background: color-mix(in srgb, var(--accent) 15%, var(--surface)); }

.species-detail { min-height: 0; overflow-y: auto; padding: 1.5rem 1rem 2rem; }

.species-card { display: grid; gap: 1rem; max-width: 48rem; margin: 0 auto; }
.species-card h2 { margin: 0; font-size: 1.5rem; }
.species-card header p { margin: 0.15rem 0 0; }

.species-image {
  display: block;
  width: 100%;
  max-height: 32rem;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--border);
}

.species-figure { display: grid; gap: 0.4rem; margin: 0; }

.species-image-missing {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  max-height: 20rem;
  color: var(--muted);
  border: 1px dashed var(--muted);
  background: none;
}

.species-description { display: grid; gap: 0.75rem; font-size: 1rem; line-height: 1.6; }
.species-description p { margin: 0; }

/* ---- small screens: map on top, list below, page scrolls ---- */

@media (max-width: 720px) {
  body { height: auto; min-height: 100dvh; }

  /* Tabs move to their own full-width row under the brand. */
  body, body:has(> .page) { grid-template-rows: auto 1fr; }
  .site-header { flex-wrap: wrap; row-gap: 0; padding-top: 0.6rem; }
  .site-header .tabs { order: 1; flex: 1 0 100%; height: 2.75rem; margin: 0.4rem -1rem 0; padding: 0 0.25rem; }
  .tabs a { flex: 1; justify-content: center; }
  .site-header .whoami, .site-header .account { margin-left: auto; }
  .site-header .whoami + .account { margin-left: 0; }

  .map-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 60dvh auto;
    grid-template-areas: "map" "sidebar";
  }

  .sidebar { border-right: 0; border-top: 1px solid var(--border); }
  .findings { overflow: visible; }

  .species-layout { grid-template-columns: 1fr; }
  .species-menu { border-right: 0; border-bottom: 1px solid var(--border); max-height: 40dvh; }
}
