:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --border: #ddd6c8;
  --text: #2b2a26;
  --text-muted: #6b6a63;
  --accent: #2f6b4f;
  --accent-dark: #204b38;
  --accent-soft: #e3efe8;
  --seen: #2f6b4f;
  --unseen: #c98a2c;
  --danger: #b3441f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  z-index: 100;
}
.skip-link:focus { left: 8px; top: 8px; }

.app-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px 24px;
  background: var(--accent-dark);
  color: #fff;
}
.app-header__title { display: flex; align-items: center; gap: 14px; }
.app-header__icon { font-size: 2.2rem; }
.app-header h1 { margin: 0; font-size: 1.3rem; }
.app-header__subtitle { margin: 2px 0 0; font-size: 0.85rem; opacity: 0.85; }
.app-header__stats { display: flex; gap: 18px; font-size: 0.85rem; flex-wrap: wrap; }
.app-header__stats strong { display: block; font-size: 1.15rem; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 24px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  border: none;
  background: transparent;
  padding: 10px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  color: var(--text-muted);
}
.tab:hover { background: var(--accent-soft); }
.tab.active {
  color: var(--accent-dark);
  font-weight: 600;
  background: var(--accent-soft);
}

main { padding: 20px 24px 60px; max-width: 1400px; margin: 0 auto; }
.view[hidden] { display: none; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.toolbar__field { display: flex; flex-direction: column; gap: 4px; font-size: 0.78rem; color: var(--text-muted); }
.toolbar__field select, .toolbar input[type="search"] {
  font-size: 0.9rem;
  padding: 7px 9px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
}
#search-input, #sightings-search { min-width: 220px; flex: 1 1 220px; }
.toolbar__checkbox { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; }
.toolbar__hint { font-size: 0.8rem; color: var(--text-muted); }

.btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn:hover { background: var(--accent-dark); }
.btn--ghost { background: transparent; color: var(--accent-dark); }
.btn--ghost:hover { background: var(--accent-soft); }
.btn--danger { border-color: var(--danger); background: transparent; color: var(--danger); }
.btn--danger:hover { background: #f8e6df; }
.btn--small { padding: 4px 10px; font-size: 0.78rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.file-btn { position: relative; cursor: pointer; }

.browse-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.2fr);
  gap: 18px;
  align-items: start;
}
@media (max-width: 860px) {
  .browse-layout { grid-template-columns: 1fr; }
}

.tree-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 6px 10px 12px;
  max-height: 76vh;
  overflow-y: auto;
}
.tree-summary { font-size: 0.82rem; color: var(--text-muted); padding: 4px 6px 8px; }

.tx-class > .tx-header { font-size: 1.02rem; font-weight: 700; }
.tx-order > .tx-header { font-size: 0.92rem; font-weight: 600; color: var(--accent-dark); }
.tx-family > .tx-header { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }

.tx-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  cursor: pointer;
  border-radius: 6px;
  user-select: none;
}
.tx-header:hover { background: var(--accent-soft); }
.tx-header__caret { display: inline-block; width: 12px; transition: transform 0.15s; font-size: 0.7rem; color: var(--text-muted); }
.tx-node.collapsed > .tx-header .tx-header__caret { transform: rotate(-90deg); }
.tx-node.collapsed > .tx-children { display: none; }
.tx-header__count { margin-left: auto; font-size: 0.75rem; color: var(--text-muted); font-weight: 400; }
.tx-children { padding-left: 16px; border-left: 1px dashed var(--border); margin-left: 8px; }

.species-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.86rem;
}
.species-row:hover, .species-row:focus { background: var(--accent-soft); outline: none; }
.species-row.selected { background: #d8ead9; }
.species-row__dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--unseen);
  flex-shrink: 0;
}
.species-row.seen .species-row__dot { background: var(--seen); }
.species-row__name { flex: 1; }
.species-row__badge { font-size: 0.68rem; color: var(--text-muted); border: 1px solid var(--border); border-radius: 10px; padding: 1px 7px; }

.detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: sticky;
  top: 12px;
  max-height: 76vh;
  overflow-y: auto;
}
.detail-placeholder { color: var(--text-muted); }
.detail-panel h2 { margin: 0 0 2px; }
.detail-meta { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 12px; }
.status-pill {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  margin-right: 6px;
}
.status-pill.vagrant, .status-pill.scarce { background: #f3e6d0; color: #7a5416; }
.status-pill.absent { background: #eee; color: #888; }
.status-pill.introduced { background: #e3e6f3; color: #35408a; }

.detail-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 4px;
}
.detail-links a {
  font-size: 0.78rem;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px;
  text-decoration: none;
}
.detail-links a:hover { background: #d8ead9; }
.detail-links__note { margin: 0 0 12px; }

.sighting-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 0.85rem;
}
.sighting-card__meta { color: var(--text-muted); font-size: 0.78rem; margin-bottom: 4px; }
.sighting-card__note { white-space: pre-wrap; }
.sighting-card__actions { margin-top: 6px; }
.sighting-card__actions button { font-size: 0.75rem; background: none; border: none; color: var(--danger); cursor: pointer; padding: 0; }

.detail-mini-map { height: 220px; border-radius: 8px; margin: 12px 0; border: 1px solid var(--border); }

.big-map { height: 62vh; border-radius: var(--radius); border: 1px solid var(--border); }
.map-footnote { font-size: 0.8rem; color: var(--text-muted); margin-top: 8px; }

.mini-map { height: 200px; border-radius: 8px; border: 1px solid var(--border); margin: 4px 0 10px; }

.sightings-list { display: flex; flex-direction: column; gap: 8px; }
.sightings-list .sighting-card { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }

.data-view { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card h2 { margin-top: 0; font-size: 1rem; }
.hint { font-size: 0.78rem; color: var(--text-muted); }

form label { display: flex; flex-direction: column; font-size: 0.8rem; gap: 4px; margin-bottom: 10px; color: var(--text-muted); }
form input, form select, form textarea {
  font-size: 0.9rem;
  padding: 7px 9px;
  border-radius: 7px;
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
}
.form-row { display: flex; gap: 10px; }
.form-row label { flex: 1; }

.inline-search { display: flex; gap: 8px; align-items: center; margin: 0 0 10px; }
.inline-search input { flex: 1; }

#claude-status-output {
  width: 100%;
  font-family: inherit;
  font-size: 0.78rem;
  margin-top: 8px;
  padding: 7px 9px;
  border-radius: 7px;
  border: 1px solid var(--border);
  resize: vertical;
}

.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,20,15,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #fff; border-radius: var(--radius); padding: 20px 22px;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal h2 { margin-top: 0; }
