:root {
  --bg: #0f1419;
  --panel: #161d27;
  --panel-2: #1c2633;
  --border: #2a3544;
  --text: #e8eef6;
  --muted: #93a4b8;
  --accent: #3db8a0;
  --accent-2: #e8b86d;
  --danger: #e07a7a;
  --shadow: 0 8px 28px rgba(0,0,0,.45);
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.hidden { display: none !important; }

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #18202b, #121820);
  z-index: 5;
}
.brand { display: flex; gap: .75rem; align-items: center; }
.brand-mark { color: var(--accent); font-size: 1.4rem; }
.brand h1 { margin: 0; font-size: 1.15rem; letter-spacing: .02em; }
.subtitle { margin: 0; color: var(--muted); font-size: .75rem; }
.search-wrap {
  display: flex; gap: .35rem; align-items: center;
  max-width: 520px; width: 100%; justify-self: center;
}
#search {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: .65rem 1rem;
  font-size: .95rem;
  outline: none;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(61,184,160,.2); }
.ghost {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; width: 2rem; height: 2rem; cursor: pointer;
}
.ghost:hover { color: var(--text); border-color: var(--muted); }
.stats { color: var(--muted); font-size: .78rem; text-align: right; white-space: nowrap; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  min-height: 0;
}
.panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-tabs { display: flex; gap: .25rem; padding: .6rem .6rem 0; }
.tab {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: .55rem .4rem;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-weight: 600;
}
.tab.active {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--border);
  border-bottom-color: var(--panel-2);
}
.panel-body {
  flex: 1;
  overflow: auto;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
}
.list { padding: .5rem; }
.empty { color: var(--muted); padding: 1.2rem; text-align: center; font-size: .9rem; }

.card {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: .65rem;
  padding: .55rem;
  margin-bottom: .45rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s;
}
.card:hover, .card.active { border-color: var(--accent); }
.card.active { box-shadow: inset 0 0 0 1px var(--accent); }
.card img, .thumb-ph {
  width: 72px; height: 72px;
  object-fit: cover;
  object-position: center;
  border-radius: 8px;
  background: #0b1016;
  display: block;
  image-orientation: from-image;
}
.thumb-ph {
  display: grid; place-items: center;
  color: var(--muted); font-size: .65rem; text-align: center; padding: .25rem;
}
.card h3 { margin: 0 0 .2rem; font-size: .92rem; line-height: 1.25; }
.card .meta { color: var(--muted); font-size: .75rem; line-height: 1.35; }
.badge {
  display: inline-block; margin-top: .3rem; padding: .1rem .4rem; border-radius: 999px;
  background: rgba(61,184,160,.15); color: var(--accent); font-size: .68rem; font-weight: 600;
}
.badge.warn { background: rgba(224,122,122,.15); color: var(--danger); }

.map-pane { position: relative; min-height: 0; }
#map { height: 100%; width: 100%; background: #0b1016; }
.leaflet-container { background: #0b1016; font: inherit; }

.detail {
  position: absolute; right: 12px; top: 12px;
  width: min(400px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow: auto;
  background: rgba(22,29,39,.96);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .9rem 1rem 1rem;
  z-index: 500;
}
.detail-close {
  float: right;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  width: 1.8rem; height: 1.8rem;
  cursor: pointer;
}
.detail h2 { margin: 0 1.8rem .35rem 0; font-size: 1.05rem; }
.detail .locality { color: var(--accent-2); font-size: .85rem; margin-bottom: .5rem; }
.specimen-block { border-top: 1px solid var(--border); padding: .65rem 0; }
.specimen-block h3 { margin: 0 0 .2rem; font-size: .95rem; }
.formula {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent); font-size: .85rem;
}
.notes { color: var(--muted); font-size: .8rem; margin: .25rem 0; }
.filenames { font-size: .72rem; color: var(--muted); word-break: break-all; }
.photo-strip { display: flex; gap: .4rem; flex-wrap: wrap; margin: .5rem 0 .75rem; }
.photo-strip button {
  padding: 0; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; cursor: pointer; background: #0b1016;
}
.photo-strip img {
  width: 88px; height: 88px;
  object-fit: cover; object-position: center;
  display: block;
  image-orientation: from-image;
}

.pin-icon {
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  width: 18px; height: 18px;
  box-shadow: 0 2px 6px rgba(0,0,0,.45);
  position: relative;
}
.pin-icon.multi { background: var(--accent-2); }
.pin-count {
  position: absolute; top: -8px; right: -10px;
  transform: rotate(45deg);
  background: #122; color: #fff;
  font-size: 10px; font-weight: 700;
  border-radius: 999px; min-width: 16px; height: 16px;
  line-height: 16px; text-align: center; padding: 0 3px;
}

.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 2000;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .5rem;
  padding: 1rem;
}
.lb-frame {
  margin: 0; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-width: 0;
}
#lb-img {
  max-width: 100%;
  max-height: calc(100vh - 5rem);
  width: auto; height: auto;
  object-fit: contain;
  image-orientation: from-image;
  border-radius: 6px;
}
#lb-caption { color: #c9d4e2; margin-top: .6rem; font-size: .85rem; text-align: center; }
.lb-close, .lb-nav {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
}
.lb-close {
  position: absolute; top: 12px; right: 12px;
  width: 2.4rem; height: 2.4rem; font-size: 1.1rem;
}
.lb-nav { width: 3rem; height: 3rem; font-size: 1.8rem; line-height: 1; }
.lb-nav:disabled { opacity: .3; cursor: default; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 42% 1fr; }
  .panel { border-right: none; border-bottom: 1px solid var(--border); }
  .topbar { grid-template-columns: 1fr; gap: .5rem; }
  .stats { text-align: left; }
}
