/* ==========================================================================
   ArborGeo – campus tree survey and geotagging
   White theme. Plex Sans for the interface, Source Serif for species names.
   ========================================================================== */

:root {
  /* Accent: forest green */
  --accent: #1D6F4A;
  --accent-hover: #175A3B;
  --accent-ink: #0F4A30;
  --accent-tint: #EAF3EE;
  --accent-line: #BBD7C6;

  /* Neutrals */
  --white: #FFFFFF;
  --canvas: #F5F7F9;
  --muted-bg: #F0F3F5;
  --ink: #1F2933;
  --ink-2: #52606D;
  --ink-3: #66727F;
  --line: #E4E7EB;
  --line-strong: #CBD2D9;

  /* Status */
  --warn-tint: #FEF3E2;
  --warn-ink: #8A4B0B;
  --danger: #B42318;
  --danger-tint: #FEF3F2;

  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', 'Noto Sans Tamil', 'Tamil Sangam MN', sans-serif;
  --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;

  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  --float-shadow: 0 6px 20px rgba(31, 41, 51, 0.14), 0 0 0 1px rgba(31, 41, 51, 0.06);

  --topbar-h: 60px;
  --panel-w: 420px;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
[hidden] { display: none !important; }

html { height: 100%; }
body {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
ul { list-style: none; }
img { display: block; max-width: 100%; }
h1, h2, h3 { font-weight: 600; line-height: 1.25; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 5000;
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: var(--r-md);
  transition: top 0.15s;
}
.skip-link:focus { top: 12px; }

.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 14px; height: 14px; }
.i-lg { width: 28px; height: 28px; stroke-width: 1.5; }

/* Scientific names are set in italic serif, per botanical convention */
.sci, i.sci { font-family: var(--font-serif); font-style: italic; }
.sci-roman { font-style: normal; }
.tamil { font-family: 'Noto Sans Tamil', var(--font-sans); }
.num { font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border-radius: var(--r-md); border: 1px solid transparent;
  font-weight: 500; font-size: 14px; white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; gap: 6px; }
.btn-icon { width: 36px; padding: 0; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--white); border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:hover { background: var(--canvas); border-color: #B8C1CC; }
.btn-quiet { color: var(--ink-2); }
.btn-quiet:hover { background: var(--muted-bg); color: var(--ink); }
.btn-danger-quiet { color: var(--danger); }
.btn-danger-quiet:hover { background: var(--danger-tint); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.link-btn { color: var(--accent); font-weight: 500; font-size: 13px; border-radius: var(--r-sm); padding: 2px 4px; }
.link-btn:hover { text-decoration: underline; }

.icon-inline {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; margin-left: 4px; vertical-align: middle;
  color: var(--ink-3); border-radius: var(--r-sm);
}
.icon-inline:hover { background: var(--muted-bg); color: var(--ink); }
.icon-inline .i { width: 15px; height: 15px; }

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
  flex: none; height: var(--topbar-h);
  display: flex; align-items: stretch; gap: 32px;
  padding: 0 20px;
  background: var(--white); border-bottom: 1px solid var(--line);
  position: relative; z-index: 1100;
}
.brand { display: flex; align-items: center; gap: 12px; flex: none; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-text h1 { font-size: 16px; letter-spacing: -0.01em; }
.brand-text p { font-size: 12px; color: var(--ink-3); line-height: 1.3; }

.view-tabs { display: flex; align-items: stretch; gap: 4px; }
.view-tab {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  padding: 0 14px; font-weight: 500; color: var(--ink-2);
  transition: color 0.15s;
}
.view-tab:hover { color: var(--ink); }
.view-tab.is-active { color: var(--accent-ink); }
.view-tab.is-active::after {
  content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px;
  background: var(--accent); border-radius: 2px 2px 0 0;
}

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); width: 280px;
  background: var(--white); border-radius: var(--r-lg); box-shadow: var(--float-shadow);
  padding: 6px; z-index: 1200;
}
.menu-note { padding: 6px 10px 8px; font-size: 12px; color: var(--ink-3); }
.menu-panel button {
  width: 100%; display: flex; align-items: flex-start; gap: 12px; text-align: left;
  padding: 8px 10px; border-radius: var(--r-md); color: var(--ink);
}
.menu-panel button:hover, .menu-panel button:focus-visible { background: var(--canvas); outline-offset: -2px; }
.menu-panel button .i { margin-top: 2px; color: var(--ink-2); }
.menu-panel button span { display: flex; flex-direction: column; font-weight: 500; }
.menu-panel button small { font-weight: 400; font-size: 12px; color: var(--ink-3); }
.menu-panel hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }

/* ==========================================================================
   Filter bar
   ========================================================================== */
.filterbar {
  flex: none; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--white); border-bottom: 1px solid var(--line);
  position: relative; z-index: 1000;
}
.search {
  position: relative; display: flex; align-items: center;
  flex: 0 1 320px; min-width: 200px;
  height: 36px; padding: 0 10px; gap: 8px;
  border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--white);
  color: var(--ink-3);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(29, 111, 74, 0.16); }
.search input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--ink);
}
.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search kbd {
  font-family: var(--font-sans); font-size: 11px; line-height: 1;
  padding: 3px 6px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink-3); background: var(--canvas);
}
.search:focus-within kbd { display: none; }

.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.select {
  position: relative; display: inline-flex; align-items: center;
  height: 36px; border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--white);
  transition: border-color 0.15s, background-color 0.15s;
}
.select select {
  appearance: none; -webkit-appearance: none; height: 100%; max-width: 210px;
  padding: 0 32px 0 12px; border: 0; background: transparent; outline: 0; cursor: pointer;
  text-overflow: ellipsis;
}
.select .i { position: absolute; right: 10px; pointer-events: none; color: var(--ink-3); }
.select:hover { border-color: #B8C1CC; }
.select:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(29, 111, 74, 0.16); }
.select.is-set { border-color: var(--accent); background: var(--accent-tint); color: var(--accent-ink); font-weight: 500; }
.select.is-set .i { color: var(--accent); }

.sort-group { display: flex; align-items: center; gap: 6px; }

.filter-summary { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: 13px; }
.filter-summary p { display: flex; align-items: center; }
.filter-summary strong { color: var(--ink); font-weight: 600; }
.filter-summary .sep { width: 1px; height: 14px; background: var(--line-strong); margin: 0 10px; }

/* ==========================================================================
   Views
   ========================================================================== */
.app-content { flex: 1; min-height: 0; position: relative; }
.view { display: none; position: absolute; inset: 0; }
.view.is-active { display: block; }
#viewMap.is-active { display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w); }
.page { height: 100%; overflow: auto; padding: 24px; }
.page-narrow { max-width: 1160px; margin: 0 auto; }
#viewDashboard { overflow: auto; }
#viewDashboard .page { height: auto; min-height: 100%; }

/* ---- Map ---- */
.map-wrap { position: relative; min-width: 0; min-height: 0; background: #E9EDF0; }
#map { position: absolute; inset: 0; z-index: 1; background: #E9EDF0; font-family: var(--font-sans); }

.layer-switch {
  position: absolute; top: 12px; right: 12px; z-index: 800;
  display: flex; padding: 3px; gap: 2px;
  background: var(--white); border-radius: var(--r-md); box-shadow: var(--float-shadow);
}
.layer-switch button {
  height: 28px; padding: 0 12px; border-radius: 6px; font-size: 13px; font-weight: 500; color: var(--ink-2);
}
.layer-switch button:hover { background: var(--canvas); color: var(--ink); }
.layer-switch button.is-active { background: var(--accent); color: #fff; }

.map-legend {
  position: absolute; top: 12px; left: 12px; z-index: 800; width: 214px;
  background: var(--white); border-radius: var(--r-lg); box-shadow: var(--float-shadow);
  max-height: calc(100% - 100px); display: flex; flex-direction: column; overflow: hidden;
}
.legend-toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 10px 12px; font-weight: 600; font-size: 13px;
}
.legend-toggle .i { transition: transform 0.15s; color: var(--ink-3); }
.legend-toggle[aria-expanded="false"] .i { transform: rotate(-90deg); }
.legend-list { overflow: auto; padding: 0 6px 6px; border-top: 1px solid var(--line); padding-top: 6px; }
.legend-toggle[aria-expanded="false"] + .legend-list { display: none; }
.legend-list button {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: var(--r-sm);
  font-size: 13px; text-align: left; color: var(--ink);
}
.legend-list button:hover { background: var(--canvas); }
.legend-list button.is-on { background: var(--accent-tint); font-weight: 500; }
.legend-list button.is-zero { color: var(--ink-3); }
.legend-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-list .n { font-variant-numeric: tabular-nums; color: var(--ink-3); }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--dot, var(--accent)); }

.mode-bar {
  position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 850;
  display: flex; align-items: center; gap: 20px; width: max-content; max-width: calc(100% - 32px);
  padding: 10px 10px 10px 18px;
  background: var(--white); border-radius: var(--r-lg); box-shadow: var(--float-shadow);
  border-left: 4px solid var(--accent);
}
.mode-text { display: flex; flex-direction: column; min-width: 0; }
.mode-text strong { font-size: 14px; }
.mode-text span { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.mode-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* Leaflet adjustments */
.leaflet-container { font-family: var(--font-sans); }
.leaflet-bar { border: 0 !important; box-shadow: var(--float-shadow) !important; border-radius: var(--r-md) !important; overflow: hidden; }
.leaflet-bar a, .leaflet-bar button {
  width: 34px !important; height: 34px !important; line-height: 34px !important;
  background: var(--white); color: var(--ink); border-bottom: 1px solid var(--line) !important;
  display: flex; align-items: center; justify-content: center; text-decoration: none; font-size: 18px;
}
.leaflet-bar a:hover, .leaflet-bar button:hover { background: var(--canvas); }
.leaflet-bar a:last-child, .leaflet-bar button:last-child { border-bottom: 0 !important; }
.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.85) !important; font-size: 11px; color: var(--ink-2);
}
.leaflet-control-scale-line {
  background: rgba(255, 255, 255, 0.85); border-color: var(--ink-2); color: var(--ink); font-size: 11px;
}
.leaflet-tooltip.tip {
  background: var(--white); border: 0; border-radius: var(--r-md); padding: 8px 10px; box-shadow: var(--float-shadow);
  color: var(--ink); font-family: var(--font-sans);
}
.leaflet-tooltip.tip::before { display: none; }
.tip-id { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tip-name { font-size: 13px; font-weight: 600; }
.tip-sci { font-size: 13px; color: var(--ink-2); }

.pin-wrap, .cluster-wrap { background: none; border: 0; }
.pin { transform-origin: 50% 100%; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35)); transition: transform 0.12s; }
.pin svg { display: block; }
.pin-wrap:hover .pin { transform: scale(1.1); }
.pin.is-active { filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.45)); }
.pin.is-dragging { animation: lift 0.2s ease-out both; }
@keyframes lift { from { transform: translateY(0); } to { transform: translateY(-4px); } }
.cluster {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--white); border: 2.5px solid var(--accent); color: var(--accent-ink);
  font-weight: 600; font-size: 13px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ---- Side panel ---- */
.panel {
  min-width: 0; min-height: 0; display: flex; flex-direction: column;
  background: var(--white); border-left: 1px solid var(--line);
}
.panel-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.panel-head {
  flex: none; height: 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px 0 20px; border-bottom: 1px solid var(--line);
}
#panelDetail .panel-head { padding: 0 12px 0 8px; }
.panel-head h2 { font-size: 15px; }
.count {
  min-width: 26px; padding: 1px 8px; text-align: center; border-radius: 99px;
  background: var(--muted-bg); color: var(--ink-2); font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums;
}

.tree-list { flex: 1; min-height: 0; overflow: auto; }
.tree-row {
  width: 100%; display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 12px; align-items: center;
  padding: 10px 20px; text-align: left; border-bottom: 1px solid var(--line); position: relative;
}
.tree-row:hover { background: #F8FAF9; }
.tree-row.is-selected { background: var(--accent-tint); }
.tree-row.is-selected::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.thumb { position: relative; width: 56px; height: 56px; border-radius: var(--r-md); overflow: hidden; background: var(--muted-bg); }
.thumb img { width: 100%; height: 100%; object-fit: cover; position: relative; z-index: 1; }
.thumb::after, .ph::after {
  content: ''; position: absolute; inset: 0; opacity: 0.55;
  background: center / 28px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2366727F' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 20A7 7 0 0 1 9.8 6.1C15.5 5 17 4.5 19 2c1 2 2 4.2 2 8 0 5.5-4.8 10-10 10Z'/%3E%3Cpath d='M2 21c0-3 1.9-5.6 5-7.5 2.2-1.4 4.6-2.2 7-2.5'/%3E%3C/svg%3E");
}
.row-text { min-width: 0; }
.row-common { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sci { font-family: var(--font-serif); font-style: italic; font-size: 13.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: flex; align-items: center; gap: 8px; margin-top: 2px; font-size: 12px; color: var(--ink-3); min-width: 0; }
.row-meta .zone { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tag { font-size: 12px; font-weight: 500; color: var(--ink-2); font-variant-numeric: tabular-nums; flex: none; }

/* ---- Detail ---- */
.detail-scroll { flex: 1; min-height: 0; overflow: auto; }
.photo { position: relative; aspect-ratio: 2 / 1; background: var(--muted-bg); overflow: hidden; cursor: zoom-in; }
.photo img { width: 100%; height: 100%; object-fit: cover; position: relative; z-index: 1; }
.photo.is-empty img { visibility: hidden; }
.photo-empty { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--ink-3); font-size: 13px; }
.photo.is-empty { cursor: default; }
.photo.is-empty .photo-empty { display: flex; }
.photo.is-empty .photo-zoom { display: none; }
.photo-zoom {
  position: absolute; right: 10px; bottom: 10px; z-index: 2; width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: var(--white); border-radius: var(--r-md); box-shadow: var(--float-shadow); color: var(--ink);
}
.photo-zoom:hover { background: var(--canvas); }

.identity { padding: 18px 20px 16px; }
.identity-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px 0 8px;
  border: 1px solid var(--line-strong); border-radius: 99px; font-size: 12.5px; font-weight: 500; background: var(--white);
}
.status {
  display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 99px;
  font-size: 12.5px; font-weight: 500; background: var(--accent-tint); color: var(--accent-ink);
}
.status.is-potted { background: var(--warn-tint); color: var(--warn-ink); }
.binomial { font-family: var(--font-serif); font-style: italic; font-weight: 600; font-size: 24px; line-height: 1.2; letter-spacing: -0.005em; overflow-wrap: anywhere; }
.binomial .sci-roman { font-weight: 400; }
.common { margin-top: 4px; font-size: 15px; font-weight: 500; color: var(--ink); }
.tamil { margin-top: 2px; font-size: 14px; color: var(--ink-2); }

.tabs {
  position: sticky; top: 0; z-index: 3; display: flex; gap: 20px; padding: 0 20px;
  background: var(--white); border-bottom: 1px solid var(--line);
}
.tab { position: relative; height: 42px; font-weight: 500; color: var(--ink-2); }
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--accent-ink); }
.tab.is-active::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--accent); }
.tab-panel { display: none; padding: 6px 20px 24px; }
.tab-panel.is-active { display: block; }

.facts > div { display: grid; grid-template-columns: 108px minmax(0, 1fr); gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--ink-3); font-size: 13px; }
.facts dd { overflow-wrap: anywhere; }
.sub-head { margin: 22px 0 6px; font-size: 14px; }
.sub-head.first { margin-top: 14px; }
.prose { color: var(--ink); line-height: 1.65; max-width: 62ch; }

.nearby li { border-bottom: 1px solid var(--line); }
.nearby button {
  width: 100%; display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 8px 0; text-align: left;
}
.nearby button:hover .near-name { color: var(--accent); }
.nearby .thumb { width: 40px; height: 40px; border-radius: var(--r-sm); }
.nearby .thumb::after { background-size: 20px; }
.near-name { font-weight: 500; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.near-sci { font-family: var(--font-serif); font-style: italic; font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.near-dist { font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--ink-2); }

.detail-actions { flex: none; display: flex; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--white); }
.detail-actions .btn { flex: 1; }

/* ---- Empty states ---- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 48px 24px; color: var(--ink-2); }
.empty .i-lg { color: var(--ink-3); }
.empty h3 { font-size: 15px; color: var(--ink); }
.empty p { max-width: 34ch; margin-bottom: 8px; }

/* ---- Gallery ---- */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px; }
.card {
  display: flex; flex-direction: column; background: var(--white); border: 1px solid var(--line);
  border-radius: var(--r-lg); overflow: hidden; cursor: pointer; text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.card:hover { border-color: var(--accent-line); box-shadow: 0 4px 14px rgba(31, 41, 51, 0.08); }
.card-photo { position: relative; aspect-ratio: 4 / 3; background: var(--muted-bg); }
.card-photo img { width: 100%; height: 100%; object-fit: cover; position: relative; z-index: 1; }
.card-photo .ph-flag {
  position: absolute; top: 10px; left: 10px; z-index: 2; height: 22px; padding: 0 9px; border-radius: 99px;
  display: inline-flex; align-items: center; font-size: 12px; font-weight: 500;
  background: var(--warn-tint); color: var(--warn-ink);
}
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.card-common { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sci { font-family: var(--font-serif); font-style: italic; color: var(--ink-2); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; gap: 8px; font-size: 12.5px; color: var(--ink-2); }
.card-foot .fam { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.card-foot .fam span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Table ---- */
.table-wrap { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: auto; max-height: 100%; }
.data-table { width: 100%; min-width: 1120px; border-collapse: separate; border-spacing: 0; }
.data-table th {
  position: sticky; top: 0; z-index: 2; text-align: left; font-weight: 600; font-size: 12.5px; color: var(--ink-2);
  background: #FAFBFC; border-bottom: 1px solid var(--line); padding: 0 14px; height: 42px; white-space: nowrap;
}
.data-table th button { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; color: inherit; height: 100%; }
.data-table th button:hover { color: var(--ink); }
.sort-ind { opacity: 0; }
.data-table th[aria-sort="ascending"] .sort-ind, .data-table th[aria-sort="descending"] .sort-ind { opacity: 1; color: var(--accent); }
.data-table td { padding: 8px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: #F8FAF9; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tr.is-selected { background: var(--accent-tint); }
.col-photo { width: 64px; }
.thumb-btn { display: block; border-radius: var(--r-sm); }
.thumb-btn .thumb { width: 44px; height: 44px; border-radius: var(--r-sm); }
.thumb-btn .thumb::after { background-size: 22px; }
.cell-sub { font-size: 12.5px; color: var(--ink-3); }
.cell-fam { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

/* ---- Analytics ---- */
.notice {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; margin-bottom: 16px; border: 1px solid var(--accent-line); background: var(--accent-tint);
  border-radius: var(--r-lg); color: var(--accent-ink);
}
.kpis {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg); margin-bottom: 20px;
}
.kpi { padding: 18px 22px; border-left: 1px solid var(--line); }
.kpi:first-child { border-left: 0; }
.kpi-val { font-family: var(--font-serif); font-weight: 600; font-size: 34px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-val small { font-family: var(--font-sans); font-weight: 400; font-size: 13px; color: var(--ink-2); margin-left: 8px; }
.kpi-lbl { margin-top: 4px; font-size: 13px; color: var(--ink-2); }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.card-block { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px 22px; }
.card-block h3 { font-size: 15px; margin-bottom: 14px; }
.chart-box { position: relative; min-height: 240px; }
.profiles li { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 20px; padding: 14px 0; border-top: 1px solid var(--line); }
.profiles li:first-child { border-top: 0; padding-top: 0; }
.profile-name { display: flex; align-items: flex-start; gap: 8px; font-weight: 600; }
.profile-name .dot { margin-top: 6px; }
.profile-name small { display: block; font-weight: 400; font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.profile-note { color: var(--ink); line-height: 1.6; }
.profile-species { margin-top: 2px; font-family: var(--font-serif); font-style: italic; font-size: 13.5px; color: var(--ink-2); }

/* ==========================================================================
   Dialogs
   ========================================================================== */
.dialog {
  border: 0; padding: 0; border-radius: var(--r-xl); background: var(--white); color: var(--ink);
  width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  box-shadow: 0 24px 64px rgba(31, 41, 51, 0.28), 0 0 0 1px rgba(31, 41, 51, 0.06);
  margin: auto;
}
.dialog[open] { display: flex; flex-direction: column; animation: dialog-in 0.16s ease-out; }
.dialog::backdrop { background: rgba(31, 41, 51, 0.45); }
.dialog form { display: flex; flex-direction: column; min-height: 0; max-height: calc(100vh - 48px); }
.dialog-sm { width: min(440px, calc(100vw - 32px)); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

.dialog-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 14px 24px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 17px; }
.dialog-body { padding: 8px 24px 20px; overflow: auto; }
.dialog-sm .dialog-body { padding-top: 22px; }
.dialog-sm h2 { font-size: 17px; margin-bottom: 8px; }
.dialog-foot { flex: none; display: flex; align-items: center; gap: 10px; padding: 14px 24px; border-top: 1px solid var(--line); background: #FAFBFC; }
.spacer { flex: 1; }

fieldset { border: 0; margin-top: 18px; min-width: 0; }
legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 10px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { margin-bottom: 14px; min-width: 0; }
.field label { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field input, .field textarea {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--white); outline: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field textarea { height: auto; padding: 8px 12px; resize: vertical; line-height: 1.5; }
.field input::placeholder, .field textarea::placeholder { color: #98A2AE; }
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(29, 111, 74, 0.16); }
.field.has-error input { border-color: var(--danger); }
.field.has-error input:focus { box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.14); }
.field-error { margin-top: 4px; font-size: 12.5px; color: var(--danger); }
.field-hint { margin-top: 4px; font-size: 12.5px; color: var(--ink-3); }
fieldset > .field-hint { margin: -6px 0 12px; color: var(--warn-ink); }

/* Photo viewer */
.lightbox {
  border: 0; padding: 0; background: transparent; color: #fff; width: 100vw; height: 100vh; max-width: none; max-height: none;
}
.lightbox[open] { display: flex; align-items: center; justify-content: center; }
.lightbox::backdrop { background: rgba(17, 24, 31, 0.92); }
.lightbox figure { display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: min(1100px, calc(100vw - 160px)); }
.lb-stage { display: flex; align-items: center; justify-content: center; min-height: 120px; }
.lb-stage img { max-width: 100%; max-height: calc(100vh - 130px); border-radius: var(--r-md); object-fit: contain; }
.lb-stage p { max-width: 40ch; text-align: center; color: #CBD2D9; }
.lightbox figcaption { text-align: center; font-size: 14px; color: #E4E7EB; }
.lightbox figcaption .sci { color: #fff; }
.lightbox figcaption .tag { color: #CBD2D9; margin-right: 8px; }
.lb-btn {
  position: absolute; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: rgba(255, 255, 255, 0.12); color: #fff;
}
.lb-btn:hover { background: rgba(255, 255, 255, 0.22); }
.lb-btn:focus-visible { outline-color: #fff; }
.lb-close { top: 18px; right: 18px; }
.lb-prev { left: 18px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 18px; top: 50%; transform: translateY(-50%); }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 3000; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: var(--r-md);
  background: var(--ink); color: #fff; font-size: 13.5px; box-shadow: 0 8px 24px rgba(31, 41, 51, 0.3);
  animation: toast-in 0.18s ease-out;
}
.toast .i { color: #7FD1A5; }
.toast.is-error .i { color: #FFB4AB; }
.toast.is-leaving { opacity: 0; transition: opacity 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Additions */
.data-table td.num, .data-table td:first-child { white-space: nowrap; }
.charts { align-items: start; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #912018; }
.map-wrap.is-placing .leaflet-grab,
.map-wrap.is-placing .leaflet-interactive { cursor: crosshair; }
.row-common, .row-sci, .near-name, .near-sci { display: block; }
.photo img:not([src]) { visibility: hidden; }

/* Print sheet is hidden on screen */
.print-sheet { display: none; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1180px) {
  .brand-text p { display: none; }
  .topbar { gap: 20px; }
  :root { --panel-w: 380px; }
}

@media (max-width: 960px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .brand-text { display: none; }
  .view-tab { padding: 0 10px; }
  .btn-label { display: none; }
  .topbar-actions .btn:not(.btn-icon) { padding: 0 10px; }
  .topbar-actions .btn-label + .i { display: none; }

  .filterbar { padding: 8px 12px; gap: 8px; }
  .search { flex: 1 1 100%; }
  .filters { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 2px; scrollbar-width: none; }
  .filters::-webkit-scrollbar { display: none; }
  .filters > * { flex: none; }
  .filter-summary { margin-left: 0; width: 100%; justify-content: space-between; }

  #viewMap.is-active { grid-template-columns: 1fr; grid-template-rows: minmax(260px, 46%) minmax(0, 1fr); }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .map-legend { width: 180px; }
  .layer-switch button { padding: 0 9px; }
  .mode-bar { flex-direction: column; align-items: stretch; gap: 8px; bottom: 16px; }

  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi:nth-child(3) { border-left: 0; }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--line); }
  .charts { grid-template-columns: 1fr; }
  .profiles li { grid-template-columns: 1fr; gap: 6px; }
  .page { padding: 16px 12px; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .lightbox figure { max-width: calc(100vw - 32px); }
  .lb-prev { left: 8px; } .lb-next { right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.print-sheet { display: none; }

/* ==========================================================================
   Print: field survey sheet
   ========================================================================== */
@page { size: A4 landscape; margin: 12mm; }

@media print {
  html, body { height: auto; overflow: visible; background: #fff; }
  body > *:not(#printSheet) { display: none !important; }
  .print-sheet { display: block !important; color: #000; font-size: 9.5pt; }
  .print-sheet h1 { font-size: 15pt; margin-bottom: 2pt; }
  .print-sheet p { color: #333; margin-bottom: 10pt; }
  .print-sheet table { width: 100%; border-collapse: collapse; }
  .print-sheet th, .print-sheet td { border: 1px solid #999; padding: 4pt 5pt; text-align: left; vertical-align: top; }
  .print-sheet th { background: #eee; font-weight: 600; }
  .print-sheet tr { break-inside: avoid; }
  .print-sheet .notes { width: 22%; }
  .print-sheet i { font-family: var(--font-serif); }
}
