@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500;1,400&family=Source+Serif+4:opsz,wght@8..60,300;8..60,400&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green: #639922;
  --green-light: #EAF3DE;
  --green-mid: #C0DD97;
  --green-dark: #27500A;
  --border: rgba(0,0,0,0.1);
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --text-faint: #9b9b9b;
  --bg: #ffffff;
  --bg-soft: #f7f6f2;
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: 'Source Serif 4', Georgia, serif;
  color: var(--text);
  background: var(--bg-soft);
  min-height: 100vh;
}

/* Header */
.site-header {
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.logo {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 20px;
  font-weight: 400;
  flex-shrink: 0;
  color: var(--text);
}
.logo em { font-style: italic; color: var(--text-muted); }

.main-nav { display: flex; gap: 2px; margin-left: 1.5rem; }

@media (max-width: 768px) {
  .main-nav { display: none; }
}

.nav-link {
  font-size: 13px;
  padding: 5px 12px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius);
  transition: all 0.1s;
}
.nav-link:hover { background: var(--bg-soft); color: var(--text); }
.nav-link.active { color: var(--text); font-weight: 500; }

.search-box {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-soft);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 11px;
  margin-left: auto;
  min-width: 200px;
}
.search-box svg { color: var(--text-faint); flex-shrink: 0; }
.search-box input {
  border: none;
  background: none;
  font-size: 13px;
  font-family: 'Source Serif 4', serif;
  color: var(--text);
  width: 100%;
  outline: none;
}
.search-box input::placeholder { color: var(--text-faint); }

/* Layout */
.page-layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 768px) {
  .page-layout {
    grid-template-columns: 1fr;
    padding: 0.75rem;
  }
  .sidebar { display: none; }
  .species-grid { grid-template-columns: 1fr 1fr; }
}

/* Sidebar */
.sidebar {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 0;
  position: sticky;
  top: 70px;
}
.sidebar-section { margin-bottom: 1.25rem; }
.sidebar-section:last-child { margin-bottom: 0; }
.sidebar-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 0 1rem;
  margin-bottom: 0.4rem;
}
.filter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 1rem;
  cursor: pointer;
  transition: background 0.1s;
  border-left: 2px solid transparent;
  user-select: none;
}
.filter-item:hover { background: var(--bg-soft); }
.filter-item.active {
  border-left-color: var(--green);
  background: var(--green-light);
}
.filter-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.filter-item.active .filter-item-left { color: var(--text); }
.checkmark {
  width: 14px; height: 14px;
  border: 0.5px solid var(--border);
  border-radius: 3px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.filter-item.active .checkmark {
  background: var(--green);
  border-color: var(--green);
}
.checkmark svg { display: none; }
.filter-item.active .checkmark svg { display: block; }
.filter-count {
  font-size: 11px;
  color: var(--text-faint);
}
.filter-item.active .filter-count { color: var(--green); }
.sidebar-divider {
  border: none;
  border-top: 0.5px solid var(--border);
  margin: 0.75rem 0;
}

/* Main */
.main-content {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}
.main-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 1rem;
}
.section-title {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  font-weight: 400;
}
.section-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.sort-row {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}
.sort-label { font-size: 12px; color: var(--text-faint); }
.sort-select {
  font-size: 12px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  background: var(--bg);
  color: var(--text);
  font-family: 'Source Serif 4', serif;
  cursor: pointer;
  outline: none;
}

/* Active filter pills */
.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 1rem;
  min-height: 4px;
}
.filter-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 3px 8px 3px 10px;
  border-radius: 20px;
  background: var(--green-light);
  border: 0.5px solid var(--green-mid);
  color: var(--green-dark);
  cursor: pointer;
}
.filter-pill:hover { opacity: 0.8; }
.pill-x { font-size: 14px; line-height: 1; }

/* Species grid */
.species-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

@media (max-width: 768px) {
  .species-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
}

.species-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s;
}
.species-card:hover {
  border-color: rgba(0,0,0,0.25);
  transform: translateY(-1px);
}

/* Conservation status badge */
.card-status {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  font-family: 'Source Serif 4', serif;
  border: 1.5px solid rgba(255,255,255,0.6);
  color: #fff;
  text-transform: uppercase;
}
.status-S { background: #3a8c3f; }
.status-D { background: #d4870a; }
.status-T { background: #b8860b; }
.status-E { background: #c0392b; }

.card-img {
  width: 100%;
  aspect-ratio: 3/2;
  background: var(--bg-soft);
  position: relative;
  overflow: hidden;
  display: block;
}
.card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
}
.card-category-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 9px;
  padding: 2px 7px;
  border-radius: 10px;
  font-family: 'Source Serif 4', serif;
}
.badge-Birds { background: rgba(234,243,222,0.92); color: #27500A; border: 0.5px solid #97C459; }
.badge-Plants { background: rgba(230,241,251,0.92); color: #0C447C; border: 0.5px solid #B5D4F4; }
.badge-Mammals { background: rgba(250,238,218,0.92); color: #633806; border: 0.5px solid #FAC775; }
.badge-Insects { background: rgba(251,234,240,0.92); color: #4B1528; border: 0.5px solid #F4C0D1; }
.badge-Reptiles { background: rgba(241,239,232,0.92); color: #444441; border: 0.5px solid #D3D1C7; }
.card-locations {
  position: absolute;
  bottom: 5px;
  right: 5px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.card-loc-pill {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 10px;
  background: rgba(0,0,0,0.42);
  color: #fff;
}
.card-info { padding: 8px 10px 10px; }
.card-name {
  font-size: 13px;
  font-weight: 500;
  font-family: 'Playfair Display', serif;
  font-style: italic;
  margin-bottom: 1px;
  line-height: 1.3;
}
.card-latin {
  font-size: 10.5px;
  color: var(--text-faint);
  font-style: italic;
  margin-bottom: 5px;
}
.card-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.card-tag {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 10px;
  border: 0.5px solid var(--border);
  color: var(--text-faint);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 14px;
}
.empty-state button {
  margin-top: 0.75rem;
  padding: 6px 16px;
  font-size: 13px;
  font-family: 'Source Serif 4', serif;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  color: var(--text);
}
.empty-state button:hover { background: var(--bg-soft); }

/* Detail overlay */
.detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
}
.detail-panel {
  background: var(--bg);
  border-radius: var(--radius-lg);
  max-width: 720px;
  width: 100%;
  padding: 1.5rem;
  position: relative;
}
.detail-back {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  margin-bottom: 1.25rem;
  font-family: 'Source Serif 4', serif;
  transition: color 0.1s;
  padding: 0;
}
.detail-back:hover { color: var(--text); }
.detail-hero {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 2rem;
  margin-bottom: 0.5rem;
  align-items: start;
}
.detail-img-wrap {
  width: 100%;
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  background: var(--bg-soft);
  position: relative;
}
.detail-img-wrap img {
  display: none !important;
}
.detail-img-placeholder { color: var(--text-faint); }
.detail-name {
  font-family: 'Playfair Display', serif;
  font-size: 26px;
  font-weight: 400;
  line-height: 1.2;
  margin-bottom: 3px;
}
.detail-latin {
  font-size: 13px;
  font-style: italic;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 0.75rem;
}
.detail-tag {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  border: 0.5px solid var(--border);
  color: var(--text-muted);
  background: var(--bg-soft);
}
.detail-tag.green {
  background: var(--green-light);
  border-color: var(--green-mid);
  color: var(--green-dark);
}
.detail-locations { margin-bottom: 0.75rem; }
.detail-loc-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 5px;
}
.detail-loc-pills { display: flex; gap: 5px; flex-wrap: wrap; }
.detail-loc-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--green-light);
  border: 0.5px solid var(--green-mid);
  color: var(--green-dark);
}
.detail-stats {
  background: var(--bg-soft);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 12.5px;
}
.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--text-muted); }
.stat-value { color: var(--text); text-align: right; }
.detail-body { border-top: 0.5px solid var(--border); padding-top: 1.25rem; }
.detail-section { margin-bottom: 1.25rem; }
.detail-h3 {
  font-family: 'Playfair Display', serif;
  font-size: 16px;
  font-weight: 400;
  margin-bottom: 0.5rem;
  padding-bottom: 4px;
  border-bottom: 0.5px solid var(--border);
}
.detail-section p {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .page-layout { padding-bottom: 70px; }
}

/* === LIGHTBOX === */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox-overlay img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 4px;
  cursor: default;
}
.lightbox-close {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: 0.5px solid rgba(255,255,255,0.3);
  color: #fff;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  z-index: 501;
}
.lightbox-close:hover { background: rgba(255,255,255,0.25); }
.lightbox-caption {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  font-family: 'Source Serif 4', serif;
  font-style: italic;
  text-align: center;
  pointer-events: none;
}
.fullscreen-btn {
  position: absolute;
  bottom: 6px;
  left: 6px;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: rgba(0,0,0,0.45);
  border: 0.5px solid rgba(255,255,255,0.25);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 2;
}

.mobile-nav { display: none; }

.card-img:hover .fullscreen-btn { opacity: 1; }
.detail-img-wrap .fullscreen-btn { opacity: 0.6; }
.detail-img-wrap:hover .fullscreen-btn { opacity: 1; }

/* === DARK MODE === */
[data-theme="dark"] {
  --bg: #1a1a1a;
  --bg-soft: #111111;
  --border: rgba(255,255,255,0.1);
  --text: #e8e6e0;
  --text-muted: #9b9996;
  --text-faint: #6b6866;
  --green: #7dc455;
  --green-light: #1a2e10;
  --green-mid: #2d5a1b;
  --green-dark: #9dd470;
  --radius: 8px;
  --radius-lg: 12px;
}
[data-theme="dark"] .site-header { background: #1a1a1a; }
[data-theme="dark"] .about-card,
[data-theme="dark"] .cat-card,
[data-theme="dark"] .main-content,
[data-theme="dark"] .sidebar,
[data-theme="dark"] .filter-panel,
[data-theme="dark"] .notes-main,
[data-theme="dark"] .sidebar-section,
[data-theme="dark"] .species-card,
[data-theme="dark"] .detail-panel,
[data-theme="dark"] .admin-sidebar,
[data-theme="dark"] .admin-editor,
[data-theme="dark"] .dashboard-card { background: #222222; }
[data-theme="dark"] .birds-bg { background: #1a2e10; }
[data-theme="dark"] .mammals-bg { background: #2e1e05; }
[data-theme="dark"] .reptiles-bg { background: #0a1e30; }
[data-theme="dark"] .amphibians-bg { background: #1e1e1e; }
[data-theme="dark"] .mobile-nav { background: #1a1a1a; }
[data-theme="dark"] .editor-body { background: #222222; color: #e8e6e0; }
[data-theme="dark"] .form-input { background: #2a2a2a; color: #e8e6e0; border-color: rgba(255,255,255,0.1); }
[data-theme="dark"] .lightbox-overlay { background: rgba(0,0,0,0.96); }

/* Dark mode toggle */
.theme-toggle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0.5px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}

/* === CAROUSEL === */
.carousel-wrap {
  position: relative;
  width: 100%;
  border-radius: var(--radius-lg);
  background: var(--bg-soft);
  border: 0.5px solid var(--border);
}
.carousel-img {
  width: 100%;
  aspect-ratio: 3/2;
  object-fit: contain;
  display: block;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.detail-img-wrap .carousel-img {
  display: block !important;
  width: 100%;
  aspect-ratio: 3/2;
  object-fit: contain;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.carousel-btn {
  position: absolute;
  top: calc(50% - 16px);
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0,0,0,0.45);
  border: 0.5px solid rgba(255,255,255,0.3);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  z-index: 2;
}
.carousel-btn:hover { background: rgba(0,0,0,0.7); }
.carousel-btn.prev { left: 8px; }
.carousel-btn.next { right: 8px; }
.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 8px 0;
  background: var(--bg-soft);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.carousel-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.carousel-dot.active { background: var(--green); }

.detail-img-wrap.carousel-wrap {
  background: transparent;
  border: none;
  overflow: hidden;
}

.carousel-dots-fixed {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 4px 0 1rem;
  width: 400px;
  grid-column: 1;
  margin-top: 0;
}