:root {
  --bg: #f4f6f2;
  --card: #ffffff;
  --ink: #1d2a22;
  --muted: #5d6b62;
  --line: #dfe5dc;
  --brand: #1f5f3f;
  --brand-2: #2f7d52;
  --accent: #e9f3ec;
  --warn: #b3261e;
  --up: #2e7d32;
  --down: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 4px 16px rgba(20, 40, 30, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--brand-2); }
h1, h2 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.05rem; font-weight: 650; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: #fff; padding: 8px 12px; z-index: 2000; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
:focus-visible { outline: 3px solid #f2b705; outline-offset: 2px; }

/* header */
.hero { background: linear-gradient(120deg, #173f2c, #2f7d52); color: #fff; }
.hero-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 22px; padding-bottom: 22px; flex-wrap: wrap; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); letter-spacing: -.01em; }
.lead { margin: 6px 0 0; opacity: .92; max-width: 60ch; }
.hero a { color: #fff; }
.cta { display: inline-block; background: #fff; color: var(--brand) !important; font-weight: 650; text-decoration: none; padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow); }
.cta:hover { background: var(--accent); }

/* controls */
.controls { position: sticky; top: 0; z-index: 1000; background: rgba(255, 255, 255, .96); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px); }
.controls-inner { display: flex; align-items: center; gap: 12px; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
.period { display: flex; align-items: center; gap: 4px; }
select, input[type=search] { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; }
#periodSelect { font-weight: 600; min-width: 13rem; }
.iconbtn { font: inherit; font-size: 1.3rem; line-height: 1; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.iconbtn:disabled { opacity: .35; cursor: default; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 2px; flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font: inherit; font-size: .88rem; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px 4px 6px; cursor: pointer; }
.chip img { width: 22px; height: 22px; }
.chip .dot { width: 22px; height: 22px; border-radius: 50%; display: inline-block; }
.chip .sw { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.chip[aria-pressed=true] { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip[aria-pressed=true] img { filter: invert(1); }

/* layout */
main { padding-top: 18px; padding-bottom: 32px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
main > *, .controls-inner > * { min-width: 0; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card > h2, .card-head { margin-bottom: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.grid-map { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.error { background: #fdecea; color: var(--warn); padding: 12px 16px; border-radius: var(--radius); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; }
.kpi-label { color: var(--muted); font-size: .85rem; }
.kpi-value { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: .82rem; color: var(--muted); min-height: 1.2em; }
.kpi-delta .up { color: var(--up); font-weight: 600; }
.kpi-delta .down { color: var(--down); font-weight: 600; }

/* segmented */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: .85rem; border: 0; background: #fff; padding: 6px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed=true] { background: var(--brand); color: #fff; }

/* map */
.map-opts { display: flex; gap: 16px; flex-wrap: wrap; font-size: .88rem; margin-bottom: 8px; }
.map-opts input:disabled + * , .map-opts label:has(input:disabled) { opacity: .5; }
#mapBox { position: relative; }
#map { height: 460px; border-radius: 8px; background: #e8ece6; }
#map .leaflet-tile-pane { filter: grayscale(.85) brightness(1.06) contrast(.9); }
.mapfull { position: absolute; top: 10px; right: 10px; z-index: 500; width: 34px; height: 34px; border-radius: 6px; border: 2px solid rgba(0,0,0,.2); background: #fff; cursor: pointer; font-size: 1.1rem; }
#mapBox.full { position: fixed; inset: 0; z-index: 3000; background: #fff; }
#mapBox.full #map { height: 100vh; border-radius: 0; }
.dlabel { background: rgba(255,255,255,.9); border: 0; box-shadow: 0 1px 3px rgba(0,0,0,.25); font-weight: 700; padding: 2px 6px; text-align: center; line-height: 1.2; }
.dlabel small { display: block; font-weight: 500; color: var(--muted); }
.dlabel::before { display: none; }
.legend { background: rgba(255,255,255,.95); padding: 8px 10px; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.2); font-size: .78rem; line-height: 1.5; }
.legend i { display: inline-block; width: 14px; height: 12px; margin-right: 6px; vertical-align: -1px; border: 1px solid rgba(0,0,0,.15); }
.legend .pt { border-radius: 50%; width: 10px; height: 10px; }
.popup-sp { display: flex; gap: 8px; align-items: center; }
.popup-sp img { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; }

/* tables */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.num { text-align: right; }
th button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
th[aria-sort=descending] button::after { content: " ▼"; font-size: .7em; }
th[aria-sort=ascending] button::after { content: " ▲"; font-size: .7em; }
.districts tbody tr { cursor: pointer; }
.districts tbody tr:hover { background: var(--accent); }
.districts tr.sel { background: #d6eadb; }
.districts tfoot td { font-weight: 700; border-bottom: 0; }
.districts .parts { display: block; font-size: .75rem; color: var(--muted); max-width: 22ch; }
.species td.ph { width: 56px; }
.species img { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--accent); display: block; }
.species .sci { color: var(--muted); font-style: italic; font-size: .85rem; }
.species td a { text-decoration: none; color: var(--ink); font-weight: 600; }
.species td a:hover { text-decoration: underline; }
.species td.zero { color: #b9c2bb; }
.species td.hl { background: #f3f9f4; font-weight: 650; }
.badge { display: inline-block; font-size: .7rem; font-weight: 650; border-radius: 4px; padding: 0 5px; margin-left: 4px; vertical-align: 1px; }
.badge.new { background: #e3f1ff; color: #0b5cad; }
.badge.intro { background: #fdecea; color: var(--warn); }
.table-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.table-tools input[type=search] { width: 280px; max-width: 100%; }
.check { font-size: .88rem; white-space: nowrap; }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.btn { font: inherit; border: 1px solid var(--brand); color: var(--brand); background: #fff; border-radius: 8px; padding: 7px 14px; cursor: pointer; }
.btn:hover { background: var(--accent); }

/* highlights */
ol, ul { margin: 0; padding: 0; list-style: none; }
.topspecies li { display: flex; gap: 12px; align-items: center; padding: 6px 0; }
.topspecies li + li { border-top: 1px solid var(--line); }
.topspecies img { width: 76px; height: 76px; border-radius: 10px; object-fit: cover; flex: none; background: var(--accent); }
.topspecies .rank { font-size: 1.3rem; font-weight: 700; color: var(--brand-2); width: 1.2em; flex: none; }
.topspecies a { font-weight: 650; text-decoration: none; color: var(--ink); }
.topspecies .sci { display: block; font-style: italic; color: var(--muted); font-size: .85rem; }
.topspecies .cnt { display: block; font-size: .85rem; }
.observers li { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.observers img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--accent); flex: none; }
.observers a { text-decoration: none; color: var(--ink); font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.observers .cnt { font-variant-numeric: tabular-nums; color: var(--muted); }
.newspecies { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.newspecies a { display: block; text-decoration: none; color: var(--ink); font-size: .72rem; line-height: 1.2; }
.newspecies img { width: 100%; aspect-ratio: 1; border-radius: 8px; object-fit: cover; display: block; margin-bottom: 3px; background: var(--accent); }
.empty { color: var(--muted); font-size: .9rem; }

/* chart */
.chart-box { position: relative; height: 340px; }

/* footer */
.foot { background: #fff; border-top: 1px solid var(--line); padding: 24px 0 32px; font-size: .9rem; }
.foot h2 { margin-bottom: 8px; }
.foot ul { list-style: disc; padding-left: 20px; }
.foot li { margin: 4px 0; max-width: 95ch; }

/* responsive */
@media (max-width: 1000px) {
  .grid-map { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-3 > :last-child { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  body { font-size: 14px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 1.5rem; }
  .grid-3 { grid-template-columns: 1fr; }
  #map { height: 360px; }
  .chart-box { height: 280px; }
  .controls-inner { gap: 8px; }
  .chips { flex-basis: 100%; width: 100%; }
  .seg button { padding: 6px 8px; }
  .legend { font-size: .7rem; padding: 6px 8px; }
  .districts .parts { display: none; }
  .districts th, .districts td { padding: 7px 5px; }
  #periodSelect { min-width: 0; flex: 1; }
  .period { flex: 1; }
  .hero-inner { padding-top: 16px; padding-bottom: 16px; }
  .species th:nth-child(n+4), .species td:nth-child(n+4) { display: none; }
  .species.dist th:nth-child(n+4), .species.dist td:nth-child(n+4) { display: none; }
  .species.dist th.hl, .species.dist td.hl { display: table-cell; }
}
