:root {
  --bg: #f2e9d0;
  --surface: #faf5e8;
  --paper: #f9f3e4;
  --ink: #4a3826;
  --ink-muted: #7a6a4f;
  --border: #d9c9a3;
  --forest-50: #eef2e2;
  --forest-100: #d3e0c4;
  --forest-300: #7fb37f;
  --forest-500: #2f7d3a;
  --forest-700: #1c4d24;
  --forest-900: #10301a;
  --amber: #b8863b;
  --danger: #b3432f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(74, 56, 38, 0.1), 0 1px 2px rgba(74, 56, 38, 0.07);
  font-family: 'Lora', Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

a { color: var(--forest-700); }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 8px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-header .brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--forest-900);
  text-decoration: none;
  letter-spacing: 0.01em;
}

.site-nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.site-nav a {
  padding: 8px 14px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--ink-muted);
  font-size: 0.92rem;
  font-weight: 500;
}

.site-nav a:hover { background: var(--forest-50); color: var(--forest-900); }
.site-nav a.active { background: var(--forest-700); color: white; }

.lang-toggle {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink-muted);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  align-self: center;
}
.lang-toggle:hover { background: var(--forest-50); color: var(--forest-900); border-color: var(--forest-100); }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

h1 { font-size: 1.6rem; margin: 0 0 4px; color: var(--forest-900); }
h2 { font-size: 1.15rem; margin: 0 0 12px; color: var(--forest-900); }
.subtitle { color: var(--ink-muted); margin: 0 0 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 16px; }
/* .grid already spaces children via `gap` — the rule above is meant for stacked full-width
   cards (e.g. Trips/Import pages) and only cares about DOM order, so it was also matching
   card siblings that are actually side-by-side grid items, adding a stray top margin to every
   one but the first and throwing off their row height (first card's box grew to match the
   margin box of the others, reading visibly taller/shorter than its neighbors). */
.grid > .card + .card { margin-top: 0; }

.grid {
  display: grid;
  gap: 16px;
}

.photo-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.photo-tile {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: grab;
}

.photo-tile img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}

.photo-tile .meta {
  padding: 10px 12px;
  font-size: 0.85rem;
}

.photo-tile .meta .species { font-weight: 600; }
.photo-tile .meta .caption { color: var(--ink-muted); margin-top: 2px; }
.photo-tile.dragging { opacity: 0.4; }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--forest-100);
  color: var(--forest-900);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge.portfolio { background: var(--amber); color: white; }

.badge.status-safe { background: var(--forest-500); color: white; }
.badge.status-caution { background: var(--amber); color: white; }
.badge.status-danger { background: var(--danger); color: white; }
.badge.status-extinct { background: var(--ink); color: var(--paper); }
.badge.status-unknown { background: var(--border); color: var(--ink-muted); }

.species-name .name-primary { font-weight: 600; }
.species-name .name-scientific, .species-name .name-english { color: var(--ink-muted); font-style: italic; font-weight: 400; }
.species-name .name-english { font-style: normal; }

label { display: block; font-size: 0.85rem; font-weight: 600; margin: 12px 0 4px; color: var(--ink); }
label:first-child { margin-top: 0; }

input[type="text"], input[type="password"], input[type="email"], input[type="date"], input[type="number"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}

textarea { resize: vertical; min-height: 70px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; font-weight: 500; }

button, .btn, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--forest-700);
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

button:hover, .btn:hover { background: var(--forest-900); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-secondary:hover { background: var(--forest-50); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8f3324; }

.btn-small { padding: 5px 10px; font-size: 0.78rem; }

.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

.status-msg { margin: 12px 0; padding: 10px 14px; border-radius: 8px; font-size: 0.9rem; }
.status-msg.error { background: #f5e2da; color: var(--danger); }
.status-msg.success { background: var(--forest-50); color: var(--forest-700); }

.empty-state { color: var(--ink-muted); font-style: italic; padding: 20px 0; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--ink-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }

.tag-list { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tag-chip { font-size: 0.72rem; background: var(--forest-50); color: var(--forest-700); padding: 2px 8px; border-radius: 999px; }

.node text {
  font-size: 11px;
  fill: var(--paper);
  stroke: var(--ink-muted);
  stroke-width: 2.5px;
  stroke-linejoin: round;
  paint-order: stroke fill;
  opacity: 0.92;
}

.tree-legend { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--ink-muted); margin-bottom: 10px; }
.tree-legend .swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }

.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid #6b5540;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  max-width: 220px;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.1s;
}

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; align-items: end; }
.filters > div { min-width: 150px; }

.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.photo-tile .location { color: var(--ink-muted); font-size: 0.78rem; margin-top: 2px; }
.photo-tile img { cursor: zoom-in; }

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 11, 0.94);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-img-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: zoom-in;
  touch-action: none;
}

.lightbox-img-wrap.zoomed { cursor: grab; }
.lightbox-img-wrap.dragging { cursor: grabbing; }

.lightbox-img {
  max-width: 90vw;
  max-height: 82vh;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}

.lightbox-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px;
  pointer-events: none;
}

.lightbox-caption {
  color: white;
  font-size: 0.9rem;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  max-width: 70vw;
}

.lightbox-caption .species { font-weight: 700; font-size: 1.05rem; }
.lightbox-caption .meta { opacity: 0.85; margin-top: 2px; }

.lightbox-controls { display: flex; gap: 8px; pointer-events: auto; }

.lightbox-btn {
  background: rgba(255,255,255,0.12);
  color: white;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-btn:hover { background: rgba(255,255,255,0.22); }

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.12);
  color: white;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-nav:hover { background: rgba(255,255,255,0.22); }
.lightbox-nav.prev { left: 18px; }
.lightbox-nav.next { right: 18px; }

.stats-hero-row { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: 16px; }

.hero-stat, .ring-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
  background: linear-gradient(160deg, var(--surface) 0%, var(--paper) 100%);
  position: relative;
  overflow: hidden;
}

.hero-stat::before, .ring-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% -10%, var(--forest-50) 0%, transparent 60%);
  pointer-events: none;
}

.hero-value { font-size: 3rem; font-weight: 700; color: var(--forest-700); line-height: 1; letter-spacing: -0.01em; }
.hero-label { color: var(--ink-muted); font-size: 0.9rem; margin-top: 8px; font-weight: 500; }

.section-eyebrow { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-muted); margin-bottom: 10px; }

.ring-wrap { position: relative; width: 120px; height: 120px; }

.ring-svg { width: 100%; height: 100%; transform: rotate(-90deg); }

.ring-track {
  fill: none;
  stroke: var(--forest-50);
  stroke-width: 10;
}

.ring-progress {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 1.1s cubic-bezier(0.22, 1, 0.36, 1);
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-pct { font-size: 1.3rem; font-weight: 700; color: var(--forest-900); }
.ring-label { color: var(--ink-muted); font-size: 0.9rem; margin-top: 12px; font-weight: 500; }

.bar-card { padding: 22px 24px; }
.bar-header { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 12px; }
.bar-count { color: var(--ink-muted); font-weight: 500; font-size: 0.88rem; }

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: var(--forest-50);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--forest-300), var(--forest-700));
  transition: width 1.1s cubic-bezier(0.22, 1, 0.36, 1);
}

.family-group { margin-bottom: 22px; }
.family-header {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.species-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.species-row:last-child { border-bottom: none; }
.species-row .species-main { flex: 1 1 240px; min-width: 200px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.species-row .species-flags { display: flex; gap: 16px; align-items: center; flex: 0 0 auto; }
.species-row .flag { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 0.66rem; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.species-row .species-actions { display: flex; gap: 6px; align-items: center; flex: 0 0 auto; margin-left: auto; }
.species-row .species-edit-form { flex: 1 1 100%; }

.breadcrumb { display: flex; flex-wrap: wrap; gap: 4px; font-size: 0.85rem; color: var(--ink-muted); margin-bottom: 10px; }
.breadcrumb .sep { opacity: 0.5; }

.quiz-card { padding: 18px 20px; }
.quiz-question { font-weight: 600; margin-bottom: 10px; }
.quiz-answer { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }

.lightbox-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.6);
  font-size: 0.76rem;
  pointer-events: none;
}
