*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
:root {
  --bg: #f3f2ee; --surface: #fff; --surface2: #eeede8;
  --border: #dddbd3; --border2: #c8c6bc;
  --text: #1c1b18; --text2: #6b6960; --text3: #9b9890;
  --green: #2a7a58; --green-light: #e8f4ef; --green-mid: #6dba9a; --green-dark: #1a5940;
  --blue: #2c5f8a; --blue-light: #e8f0f7; --blue-mid: #7aaed4;
  --amber: #8a6020; --amber-light: #faf2e0; --amber-mid: #d4a84b;
  --red: #8a2c2c; --red-light: #faf0f0; --red-mid: #d47a7a;
  --radius: 6px; --radius-lg: 10px;
  --font-sans: system-ui, -apple-system, sans-serif;
}
body { font-family: var(--font-sans); background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; display: flex; flex-direction: column; font-size: 14px; margin: 0; }

header { background: var(--green-dark); color: white; padding: 0 1.5rem; display: flex; align-items: center; justify-content: space-between; height: 52px; flex-shrink: 0; }
.header-brand { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; white-space: nowrap; }
.header-brand h1 { font-size: 16px; color: white; margin: 0; }
.header-brand h1 strong { font-weight: 700; }
.header-brand h1 em { font-weight: 300; font-style: normal; }
.header-brand h1 a { color: white; text-decoration: none; }
.header-brand h1 a:hover { text-decoration: underline; }
.header-brand span { font-size: 12px; color: rgba(255,255,255,0.5); font-weight: 300; }
.header-right { font-size: 11px; color: rgba(255,255,255,0.45); font-weight: 300; }

.layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 52px); overflow: hidden; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }
.sidebar-section { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.section-label { font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text3); margin-bottom: 0.7rem; }
.section-label.collapsible { cursor: pointer; display: flex; align-items: center; justify-content: space-between; user-select: none; margin-bottom: 0; }
.section-label.collapsible:hover { color: var(--text2); }
.section-chevron { font-size: 18px; line-height: 1; transition: transform 0.2s; display: inline-block; color: var(--text2); }
.section-label.collapsible.collapsed .section-chevron { transform: rotate(-90deg); }
.section-body { margin-top: 0.7rem; }
.section-body.collapsed { display: none; }
.instruction-box { background: var(--green-light); border: 0.5px solid var(--green-mid); border-radius: var(--radius); padding: 10px 12px; font-size: 12.5px; color: var(--green-dark); line-height: 1.65; margin-bottom: 0.8rem; }

.drop-zone { border: 1.5px dashed var(--border2); border-radius: var(--radius); padding: 14px 10px; text-align: center; cursor: pointer; transition: all 0.15s; background: var(--surface2); }
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--green); background: var(--green-light); }
.drop-zone input { display: none; }
.dz-icon { font-size: 20px; margin-bottom: 5px; }
.dz-text { font-size: 12.5px; color: var(--text2); }
.dz-sub { font-size: 11px; color: var(--text3); margin-top: 3px; }

.poly-list { margin-top: 0.6rem; display: flex; flex-direction: column; gap: 5px; }
.poly-item { display: flex; flex-direction: column; gap: 4px; padding: 5px 8px; border-radius: var(--radius); background: var(--green-light); border: 0.5px solid var(--green-mid); font-size: 12px; color: var(--green-dark); }
.poly-item.species-entry { background: var(--blue-light); border-color: var(--blue-mid); }
.poly-item.species-entry .poly-item-name { color: var(--blue); cursor: default; }
.poly-item.species-entry .poly-remove { color: var(--blue-mid); }
.poly-group-label { font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text3); margin: 0.5rem 0 0.25rem; padding: 0 1px; }
.poly-item-row { display: flex; align-items: center; gap: 6px; width: 100%; }
.poly-buffer-row { display: flex; align-items: center; gap: 3px; padding-top: 3px; border-top: 0.5px solid var(--green-mid); }
.poly-buffer-label { font-size: 10px; color: var(--text3); font-weight: 600; flex-shrink: 0; margin-right: 2px; }
.poly-buf-btn { font-size: 10px; padding: 2px 6px; border-radius: 10px; border: 0.5px solid var(--green-mid); background: transparent; color: var(--green-dark); cursor: pointer; font-family: var(--font-sans); transition: all 0.12s; white-space: nowrap; line-height: 1.4; }
.poly-buf-btn:hover { background: var(--green-mid); }
.poly-buf-btn.active { background: var(--green-dark); color: white; border-color: var(--green-dark); }
.poly-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: text; }
.poly-item-name:hover { text-decoration: underline dotted; }
.poly-name-input { flex: 1; font-size: 12px; font-family: var(--font-sans); color: var(--green-dark); background: white; border: 1px solid var(--green-mid); border-radius: 4px; padding: 1px 5px; min-width: 0; outline: none; }
.poly-item-count { font-size: 11px; color: var(--green); flex-shrink: 0; }
.poly-remove { cursor: pointer; color: var(--green); font-size: 14px; flex-shrink: 0; line-height: 1; padding: 4px 8px; min-width: 30px; min-height: 30px; display: flex; align-items: center; justify-content: center; border-radius: 4px; }
.poly-remove:hover { color: var(--red); }
.poly-empty { font-size: 12px; color: var(--text3); padding: 6px 0; }

.small-btn { margin-top: 0.5rem; padding: 5px 10px; font-size: 12px; font-family: var(--font-sans); border-radius: var(--radius); cursor: pointer; border: 0.5px solid var(--border); background: var(--surface2); color: var(--text2); transition: all 0.12s; }
.small-btn:hover { background: var(--red-light); color: var(--red); border-color: var(--red-mid); }
.clear-link { display:none; background:none; border:none; padding:0; margin-top:5px; font-size:11px; font-family:var(--font-sans); color:var(--text3); cursor:pointer; }
.clear-link:hover { color:var(--red); }

.field { margin-bottom: 0.65rem; }
.field label { display: block; font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text3); margin-bottom: 4px; }
.field input, .field select { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 9px; font-size: 13px; font-family: var(--font-sans); background: var(--surface); color: var(--text); -webkit-appearance: none; appearance: none; }
.field input:focus, .field select:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 2px rgba(42,122,88,0.1); }
.half { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check-row { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text); margin-bottom: 0.45rem; }
.check-row input[type=checkbox] { width: 14px; height: 14px; accent-color: var(--green); }

/* NZ species search */
.sp-wrap { position: relative; margin-top: 0.6rem; }
.sp-input { width: 100%; padding: 6px 26px 6px 9px; font-size: 12.5px; font-family: var(--font-sans); border: 1px solid var(--border2); border-radius: var(--radius); color: var(--text); background: var(--surface); outline: none; box-sizing: border-box; }
.sp-input:focus { border-color: var(--green-mid); }
.sp-input.sp-active { border-color: var(--green); background: var(--green-light); font-weight: 500; }
.sp-input:disabled { opacity: 0.45; cursor: not-allowed; }
@keyframes sp-shake { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-5px)} 40%,80%{transform:translateX(5px)} }
.sp-input.sp-warn { border-color: var(--amber-mid) !important; background: var(--amber-light) !important; animation: sp-shake 0.35s ease; }
.sp-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; font-size: 15px; color: var(--text3); line-height: 1; padding: 2px; display: none; }
.sp-clear:hover { color: var(--red); }
#spDrop { position: fixed; z-index: 9500; background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius); box-shadow: 0 6px 18px rgba(0,0,0,0.14); max-height: 220px; overflow-y: auto; display: none; }
.sp-item { padding: 7px 11px; cursor: pointer; border-bottom: 0.5px solid var(--border); }
.sp-item:last-child { border-bottom: none; }
.sp-item:hover, .sp-item.sp-focus { background: var(--green-light); }
.sp-sci { font-size: 12.5px; font-style: italic; color: var(--text); }
.sp-common { font-size: 11px; color: var(--text2); margin-top: 1px; }
.sp-common.sp-genus-tag { color: var(--blue); font-style: normal; }
.sp-loading { font-size: 11px; color: var(--text3); padding: 8px 11px; font-style: italic; }
.nvs-badge { font-size:9px;font-weight:700;letter-spacing:0.06em;background:#e0f2fe;color:#0369a1;padding:1px 5px;border-radius:3px; }


@keyframes hintFade { from { opacity:0; transform:translateX(-6px); } to { opacity:1; transform:translateX(0); } }
.run-btn { width: 100%; padding: 9px; font-size: 14px; font-family: var(--font-sans); font-weight: 500; background: var(--green-dark); color: white; border: none; border-radius: var(--radius); cursor: pointer; transition: background 0.15s, opacity 0.15s; }
.run-btn:hover:not(:disabled) { opacity: 0.88; }
.run-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.run-btn.cancelling { background: #b91c1c; }

.status-bar { font-size: 12px; padding: 8px 10px; border-radius: var(--radius); margin-top: 0.7rem; line-height: 1.55; display: none; }
.status-bar.info    { background: var(--blue-light);  color: var(--blue);       border: 0.5px solid var(--blue-mid); }
.status-bar.success { background: var(--green-light); color: var(--green-dark); border: 0.5px solid var(--green-mid); }
.status-bar.error   { background: var(--red-light);   color: var(--red);        border: 0.5px solid var(--red-mid); }
.status-bar.warning { background: var(--amber-light); color: var(--amber);      border: 0.5px solid var(--amber-mid); }

.progress-wrap { margin-top: 0.6rem; display: none; }
.progress-track { height: 28px; background: transparent; position: relative; }
.progress-track::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--surface2); transform: translateY(-50%); border-radius: 1px; }
.progress-footprint { position: absolute; top: 2px; color: var(--green); opacity: 0; transform: translateX(-50%) scale(0.4); transition: opacity 0.25s, transform 0.25s; pointer-events: none; }
.progress-footprint.right-foot { top: 17px; transform: translateX(-50%) scale(0.4) scaleY(-1); }
.progress-footprint.visible { opacity: 1; transform: translateX(-50%) scale(1); }
.progress-footprint.right-foot.visible { opacity: 1; transform: translateX(-50%) scale(1) scaleY(-1); }
.progress-label { font-size: 11px; color: var(--text3); margin-top: 2px; }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 0.7rem; }
.metric { background: var(--surface2); border-radius: var(--radius); padding: 9px 8px; text-align: center; }
.metric-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text3); }
.metric-value { font-size: 19px; font-weight: 500; margin-top: 2px; color: var(--green-dark); }

.tool-row { display: flex; gap: 6px; margin-top: 0.6rem; }
.tool-btn { flex: 1; padding: 6px; font-size: 12px; font-family: var(--font-sans); border-radius: var(--radius); cursor: pointer; border: 0.5px solid var(--border); background: var(--surface2); color: var(--text2); transition: all 0.12s; text-align: center; }
.tool-btn.active { background: var(--green-dark); color: white; border-color: var(--green-dark); }
.tool-btn:hover:not(.active) { background: var(--border); }

.export-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 0.6rem; }
.draw-dist-label { background: transparent !important; border: none !important; box-shadow: none !important; overflow: visible !important; pointer-events: none; }
.draw-dist-label span { display: inline-block; background: rgba(0,0,0,0.68); color: #fff; font-size: 13px; font-weight: 600; padding: 3px 9px; border-radius: 10px; white-space: nowrap; font-family: var(--font-sans); box-shadow: 0 1px 5px rgba(0,0,0,0.45); transform: translate(-50%,-50%); pointer-events: none; }
.draw-dist-moving span { background: rgba(200,97,26,0.92); }
.dl-btn { width: 100%; padding: 8px; font-size: 13px; font-family: var(--font-sans); font-weight: 500; background: var(--green-light); color: var(--green-dark); border: 1px solid var(--green-mid); border-radius: var(--radius); cursor: pointer; transition: background 0.12s; }
.dl-btn:hover { background: #c8e8db; }
.dl-btn.full { grid-column: 1 / -1; font-size: 14px; padding: 9px; }

.filter-section { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: none; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 0.5rem; }
.chip { padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; cursor: pointer; border: 1.5px solid transparent; transition: all 0.15s; user-select: none; }
.chip.off { opacity: 0.35; text-decoration: line-through; }

.legend { position: absolute; bottom: 28px; left: 10px; z-index: 800; background: white; border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; font-size: 12px; display: none; min-width: 140px; }
.legend-title { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text3); margin-bottom: 6px; }
.legend-item { display: flex; align-items: center; gap: 7px; margin-bottom: 3px; color: var(--text2); font-size: 11px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.checklist-panel { position: absolute; top: 0; right: 0; width: 290px; height: calc(100% - 22px); background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; z-index: 900; transform: translateX(100%); transition: transform 0.25s ease; box-shadow: -4px 0 16px rgba(0,0,0,0.08); overflow: visible; }
.checklist-panel.open { transform: translateX(0); }
.cl-header { display: flex; align-items: center; justify-content: space-between; padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); flex-shrink: 0; background: var(--surface2); }
.cl-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text3); }
#clToggleHandle { position: absolute; left: -26px; top: 50%; transform: translateY(-50%); width: 26px; height: 64px; background: var(--surface); border: 1px solid var(--border); border-right: none; border-radius: 6px 0 0 6px; cursor: pointer; box-shadow: -3px 0 8px rgba(0,0,0,0.10); display: none; align-items: center; justify-content: center; padding: 0; font-size: 16px; color: var(--text2); z-index: 901; transition: background 0.12s, color 0.12s; }
#clToggleHandle:hover { background: var(--green-light); color: var(--green-dark); }
.cl-selected-info { padding: 6px 10px; font-size: 11px; background: var(--green-light); color: var(--green-dark); border-bottom: 1px solid var(--green-mid); display: none; }
.cl-clear-sel { cursor: pointer; text-decoration: underline; margin-left: 6px; }
.cl-search { padding: 8px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.cl-search input { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 9px; font-size: 12px; font-family: var(--font-sans); background: var(--surface2); color: var(--text); }
.cl-search input:focus { outline: none; border-color: var(--green); }
.cl-scroll { flex: 1; overflow-y: auto; }
.cl-footer { padding: 7px 10px; font-size: 10px; color: var(--text3); border-top: 0.5px solid var(--border); background: var(--surface2); flex-shrink: 0; line-height: 1.5; }
.cl-group-header { padding: 5px 10px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; background: var(--surface2); color: var(--text2); position: sticky; top: 0; z-index: 1; border-bottom: 0.5px solid var(--border); transition: background 0.1s; user-select: none; }
.cl-group-header:hover { background: var(--border); }
.cl-row { display: flex; flex-direction: column; padding: 7px 10px; font-size: 12px; border-bottom: 0.5px solid var(--border); cursor: pointer; transition: background 0.1s; }
.cl-row:hover { background: var(--green-light); }
.cl-row.selected { background: var(--green-light); border-left: 3px solid var(--green); padding-left: 7px; }
.cl-row.hidden { display: none; }
.cl-row-top { display: flex; justify-content: space-between; align-items: baseline; }
.cl-name { font-style: italic; color: var(--text); flex: 1; }
.cl-count { color: var(--text3); font-size: 11px; flex-shrink: 0; margin-left: 8px; }
.cl-common { font-size: 11px; color: var(--text2); margin-top: 1px; }
.nztcs-badge { display:inline-block; font-size:9px; font-weight:700; letter-spacing:0.03em; padding:1px 4px; border-radius:3px; vertical-align:middle; margin-left:5px; flex-shrink:0; white-space:nowrap; }
.nb-nc { background:#fee2e2; color:#991b1b; border:0.5px solid #fca5a5; }
.nb-ne { background:#ffedd5; color:#9a3412; border:0.5px solid #fdba74; }
.nb-nv { background:#fef9c3; color:#854d0e; border:0.5px solid #fde047; }
.nb-ar { background:#dbeafe; color:#1e40af; border:0.5px solid #93c5fd; }
.nb-ex { background:#f1f5f9; color:#475569; border:0.5px solid #cbd5e1; }
.nb-rc { background:#dcfce7; color:#166534; border:0.5px solid #86efac; }
.nb-oi { background:#f3f4f6; color:#6b7280; border:0.5px solid #d1d5db; }
.cl-nztcs-btn { font-size:10px; font-weight:600; font-family:var(--font-sans); background:none; border:0.5px solid var(--border); border-radius:4px; padding:3px 7px; cursor:pointer; color:var(--text3); transition:all 0.12s; white-space:nowrap; }
.cl-nztcs-btn:hover { border-color:var(--green); color:var(--green); }
.cl-nztcs-btn.unlocked { color:var(--green-dark); border-color:var(--green-mid); background:var(--green-light); }
.cl-nztcs-filters { display:flex; flex-wrap:wrap; gap:4px; padding:6px 10px; border-bottom:0.5px solid var(--border); background:var(--surface2); }
.nztcs-fc { font-size:10px; font-weight:700; font-family:var(--font-sans); padding:2px 7px; border-radius:3px; cursor:pointer; transition:all 0.1s; border:1px solid var(--border2); background:var(--surface); color:var(--text3); white-space:nowrap; }
.nztcs-fc:hover { color:var(--text); }
.nztcs-fc.active               { background:var(--green-dark); color:white; border-color:var(--green-dark); }
.nztcs-fc[data-f="nc"].active  { background:#991b1b; color:white; border-color:#991b1b; }
.nztcs-fc[data-f="ne"].active  { background:#9a3412; color:white; border-color:#9a3412; }
.nztcs-fc[data-f="nv"].active  { background:#854d0e; color:white; border-color:#854d0e; }
.nztcs-fc[data-f="ar"].active  { background:#1e40af; color:white; border-color:#1e40af; }
.nztcs-fc[data-f="rc"].active  { background:#166534; color:white; border-color:#166534; }
.nztcs-fc[data-f="ex"].active  { background:#475569; color:white; border-color:#475569; }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 9999; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: white; border-radius: var(--radius-lg); padding: 1.5rem; max-width: 380px; width: 90%; }
.modal h2 { font-size: 16px; font-weight: 600; margin-bottom: 0.6rem; }
.modal p { font-size: 13px; color: var(--text2); line-height: 1.65; margin-bottom: 1rem; }
.modal-btns { display: flex; gap: 8px; }
.modal-btn { flex: 1; padding: 8px; font-size: 13px; font-family: var(--font-sans); border-radius: var(--radius); cursor: pointer; font-weight: 500; border: 1px solid var(--border); background: var(--surface2); color: var(--text); transition: background 0.12s; }
.modal-btn:hover { background: var(--border); }
.modal-btn.primary { background: var(--green-dark); color: white; border-color: var(--green-dark); }
.modal-btn.primary:hover { opacity: 0.88; }

.sidebar-footer { padding: 1rem 1.25rem; margin-top: auto; border-top: 1px solid var(--border); }
.note { font-size: 11px; color: var(--text3); line-height: 1.65; }
.note a { color: var(--green); text-decoration: none; }
.note a:hover { text-decoration: underline; }

/* Citation banner */

/* Quality flags */
.quality-box { background: var(--amber-light); border: 0.5px solid var(--amber-mid); border-radius: var(--radius); padding: 6px 10px; margin-top: 0.6rem; font-size: 12px; color: var(--amber); line-height: 1.4; display: none; }
.quality-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; }
.quality-val { font-weight: 600; }
.quality-flag-warn { color: var(--red); }

/* Species richness per polygon */
.richness-box { margin-top: 0.7rem; display: none; }
.richness-box strong { display: block; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text3); margin-bottom: 5px; }
.richness-row { display: flex; justify-content: space-between; font-size: 12px; padding: 4px 8px; border-radius: 4px; background: var(--surface2); margin-bottom: 3px; }
.richness-name { color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.richness-val { color: var(--green-dark); font-weight: 600; flex-shrink: 0; margin-left: 8px; }

/* About modal */
.about-btn { background: none; border: none; cursor: pointer; font-size: 13px; color: rgba(255,255,255,0.6); padding: 4px 8px; border-radius: 4px; font-family: var(--font-sans); }
.about-btn:hover { background: rgba(255,255,255,0.1); color: white; }
.about-modal { max-width: 520px; }
.about-modal h2 { color: var(--green-dark); font-size: 17px; }
.about-modal h3 { font-size: 13px; font-weight: 600; color: var(--text); margin: 1rem 0 0.35rem; }
.about-modal p { font-size: 13px; color: var(--text2); line-height: 1.7; margin-bottom: 0; }
.about-modal ul { font-size: 13px; color: var(--text2); line-height: 1.7; padding-left: 1.2rem; margin-bottom: 0.5rem; }
.about-modal .licence-badge { display: inline-block; background: var(--green-light); border: 0.5px solid var(--green-mid); color: var(--green-dark); border-radius: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; margin-right: 4px; }

/* Prevent any element from blowing out the viewport width */
html, body { max-width: 100vw; overflow-x: hidden; }

/* Mobile responsiveness */
@media (max-width: 700px) {
  body { overflow-y: auto; }
  header { position: sticky; top: 0; z-index: 1100; }
  .layout { grid-template-columns: 1fr; height: auto; overflow: visible; max-width: 100vw; }
  /* Map first on mobile so sidebar controls are below and reachable by scrolling down */
  #map-wrap { order: 1; height: 58vh; min-height: 280px; position: relative; width: 100%; max-width: 100vw; }
  .sidebar { order: 2; border-right: none; border-top: 1px solid var(--border); overflow-y: visible; max-width: 100vw; }
  .sidebar-section { padding: 0.45rem 1rem; }
  .section-body { margin-top: 0.45rem; }
  #map { position: absolute; inset: 0; }
  .checklist-panel { width: 100%; height: 370px; top: auto; bottom: 0; transform: translateY(100%); overflow: visible; }
  .checklist-panel.open { transform: translateY(0); }
  #clToggleHandle { left: 50%; top: -26px; transform: translateX(-50%); width: 64px; height: 26px; border-radius: 6px 6px 0 0; border-bottom: none; border-right: 1px solid var(--border); writing-mode: horizontal-tb; font-size: 14px; }
  .header-right { display: none; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  /* Hide Leaflet's built-in draw action buttons — we provide touch-safe replacements */
  .leaflet-draw-actions { display: none !important; }
  /* Tree of life not available on small screens */
  #taxoBrowseBtn { display: none !important; }
}
@media (max-width: 400px) {
  .sidebar-section { padding: 0.75rem 0.9rem; }
  .field-row { flex-direction: column; gap: 6px; }
  .export-row { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
}
/* Draw action bar (shown over map while drawing) */
#drawActionBar {
  display: none;
  position: absolute;
  bottom: 16px; left: 50%; transform: translateX(-50%);
  z-index: 1200;
  gap: 8px;
  white-space: nowrap;
}
#drawActionBar button {
  background: var(--green-dark); color: white;
  border: none; border-radius: 20px;
  padding: 11px 22px; font-size: 14px; font-weight: 500;
  font-family: var(--font-sans); cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  touch-action: none;
}
#cancelDrawBtn { background: #b91c1c; }

.taxon-dropdown { position: relative; }
.taxon-dropdown-trigger { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 9px; font-size: 13px; cursor: pointer; background: var(--surface); user-select: none; }
.taxon-dropdown-trigger:hover { border-color: var(--green); }
.taxon-arrow { font-size: 10px; color: var(--text3); }
.taxon-dropdown-menu { position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); z-index: 1000; max-height: 280px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,0.1); margin-top: 2px; }
.taxon-group-label { font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text3); padding: 4px 10px 2px; background: var(--surface2); border-top: 0.5px solid var(--border); }
.taxon-item { display: flex; align-items: center; gap: 7px; padding: 3px 10px; font-size: 11.5px; cursor: pointer; color: var(--text3); transition: color 0.1s; user-select: none; }
.taxon-item:hover { color: var(--text); }
.taxon-item.selected { color: var(--text); font-weight: 500; }
.taxon-item input[type=checkbox] { display: none; }
.taxon-all { border-bottom: 0.5px solid var(--border); font-weight: 500; padding: 5px 10px; }

#map-wrap { position: relative; width: 100%; overflow: hidden; }
#map { position: absolute; top: 0; left: 0; right: 0; bottom: 0; }
@media (min-width: 701px) {
  #map-wrap { height: calc(100vh - 52px); }
}


/* Changelog panel — slides up from bottom of sidebar */
.changelog-overlay { display:none; position:fixed; inset:0; z-index:9998; }
.changelog-overlay.open { display:block; }
.changelog-panel {
  position: fixed;
  bottom: 0; left: 0;
  width: 320px;
  max-height: 70vh;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-radius: 0 10px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  z-index: 9999;
  transform: translateY(100%);
  transition: transform 0.25s ease;
}
.changelog-panel.open { transform: translateY(0); }
.changelog-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  flex-shrink: 0; background: var(--surface2);
  border-radius: 0 10px 0 0;
}
.changelog-title { font-size:12px; font-weight:600; text-transform:uppercase; letter-spacing:0.08em; color:var(--text3); }
.changelog-close { cursor:pointer; font-size:16px; color:var(--text3); background:none; border:none; padding:2px 5px; border-radius:4px; }
.changelog-close:hover { color:var(--red); background:var(--red-light); }
.changelog-scroll { flex:1; overflow-y:auto; padding:1rem; }
.changelog-version { margin-bottom:1.2rem; }
.changelog-version-tag {
  display: inline-block; font-size:11px; font-weight:700;
  background: var(--green-dark); color: white;
  border-radius: 4px; padding: 2px 8px; margin-bottom:4px;
  letter-spacing: 0.04em;
}
.changelog-date { font-size:11px; color:var(--text3); margin-left:6px; }
.changelog-version ul { margin:6px 0 0 0; padding-left:1.1rem; }
.changelog-version li { font-size:12px; color:var(--text2); line-height:1.7; }
.changelog-empty { font-size:12px; color:var(--text3); font-style:italic; padding:0.5rem 0; }
@media (max-width:700px) { .changelog-panel { width:100%; border-radius:10px 10px 0 0; } }

/* Mobile warning banner */
.mobile-banner {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--green-dark);
  z-index: 99999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}
.mobile-banner-icon { font-size: 48px; margin-bottom: 1rem; }
.mobile-banner h2 { color: white; font-size: 20px; margin-bottom: 0.75rem; }
.mobile-banner p { color: rgba(255,255,255,0.75); font-size: 14px; line-height: 1.7; margin-bottom: 1.5rem; max-width: 300px; }
.mobile-banner-btn {
  background: white; color: var(--green-dark); border: none;
  border-radius: var(--radius); padding: 10px 24px;
  font-size: 14px; font-weight: 600; font-family: var(--font-sans);
  cursor: pointer; margin-bottom: 0.75rem; width: 100%; max-width: 280px;
}
.mobile-banner-btn:hover { opacity: 0.9; }
.mobile-banner-skip {
  color: rgba(255,255,255,0.45); font-size: 12px; cursor: pointer;
  background: none; border: none; font-family: var(--font-sans);
  text-decoration: underline;
}

/* KML multi-polygon browse mode */
.browse-panel { margin-top: 0.6rem; display: none; }
.browse-header { font-size: 12px; color: var(--text2); margin-bottom: 0.5rem; line-height: 1.5; }
.browse-search { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 9px; font-size: 12px; font-family: var(--font-sans); background: var(--surface2); color: var(--text); margin-bottom: 0.4rem; box-sizing: border-box; }
.browse-search:focus { outline: none; border-color: var(--green); }
.browse-list { max-height: 160px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 0.5rem; }
.browse-item { display: flex; align-items: center; gap: 7px; padding: 5px 8px; font-size: 12px; cursor: pointer; border-bottom: 0.5px solid var(--border); transition: background 0.1s; user-select: none; }
.browse-item:last-child { border-bottom: none; }
.browse-item:hover { background: var(--green-light); }
.browse-item.selected { background: var(--green-light); color: var(--green-dark); font-weight: 500; }
.browse-item input[type=checkbox] { accent-color: var(--green); flex-shrink: 0; cursor: pointer; }
.browse-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.browse-actions { display: flex; gap: 6px; }
.browse-add-btn { flex: 1; padding: 7px; font-size: 12.5px; font-family: var(--font-sans); font-weight: 500; background: var(--green-dark); color: white; border: none; border-radius: var(--radius); cursor: pointer; transition: opacity 0.12s; }
.browse-add-btn:hover:not(:disabled) { opacity: 0.88; }
.browse-add-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.browse-cancel-btn { padding: 7px 12px; font-size: 12px; font-family: var(--font-sans); border-radius: var(--radius); cursor: pointer; border: 0.5px solid var(--border); background: var(--surface2); color: var(--text2); transition: all 0.12s; }
.browse-cancel-btn:hover { background: var(--red-light); color: var(--red); border-color: var(--red-mid); }
.browse-sel-all { font-size: 11px; color: var(--green); cursor: pointer; background: none; border: none; font-family: var(--font-sans); padding: 2px 4px; border-radius: 3px; white-space: nowrap; }
.browse-sel-all:hover { text-decoration: underline; }

/* ── Taxonomy Browser Sunburst ───────────────────────────────────────────── */
.taxo-overlay { position:fixed;inset:0;z-index:10000;background:rgba(12,18,14,0.72);display:flex;align-items:center;justify-content:center; }
.taxo-box { background:#fff;border-radius:16px;width:min(1160px,96vw);max-width:96vw;max-height:92vh;display:flex;flex-direction:column;overflow:hidden;box-shadow:0 24px 80px rgba(0,0,0,0.38); }
.taxo-hdr { display:flex;align-items:center;gap:10px;padding:13px 18px 11px;border-bottom:1px solid var(--border);flex-shrink:0;position:relative; }
.taxo-title { font-size:14px;font-weight:700;color:var(--text1);flex-shrink:0; }
.taxo-crumb { flex:1;font-size:11px;color:var(--text3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0;padding:0 6px; }
.taxo-loading-msg { position:absolute;left:50%;transform:translateX(-50%);font-size:10px;color:var(--text3);font-style:italic;max-width:320px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;opacity:0.8;pointer-events:none;transition:opacity 0.4s ease; }
.taxo-x { background:none;border:none;cursor:pointer;font-size:20px;line-height:1;color:var(--text3);padding:0 2px;flex-shrink:0; }
.taxo-x:hover { color:var(--text1); }
.taxo-body { flex:1;display:flex;flex-direction:column;overflow:hidden;padding:10px 14px 6px; }
.miller-wrap { display:flex;flex:1;overflow:hidden;border:1px solid var(--border);border-radius:8px; }
.miller-col { flex:1;overflow-y:auto;border-right:1px solid var(--border);min-width:130px; }
.miller-col:last-child { border-right:none;flex:2;min-width:160px; }
.miller-col-hdr { font-size:9px;font-weight:700;text-transform:uppercase;letter-spacing:0.09em;color:var(--text3);padding:5px 10px 4px;background:var(--surface2);border-bottom:1px solid var(--border);position:sticky;top:0; }
.miller-item { display:flex;align-items:center;gap:5px;padding:7px 9px;cursor:pointer;font-size:12px;border-bottom:0.5px solid #f2eeea;user-select:none;transition:background 0.08s; }
.miller-item:hover { background:#f5f2ef; }
.miller-item.miller-sel { background:var(--green);color:#fff; }
.miller-item.miller-sel:hover { background:var(--green); }
.miller-text { flex:1;min-width:0;overflow:hidden; }
.miller-name { display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; }
.miller-common { display:block;font-size:10px;color:var(--text3);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-top:1px; }
.miller-item.miller-sel .miller-common { color:rgba(255,255,255,0.7); }
.miller-rank { font-size:9px;text-transform:uppercase;letter-spacing:0.06em;color:var(--text3);background:var(--surface2);padding:1px 5px;border-radius:3px;flex-shrink:0;white-space:nowrap; }
.miller-item.miller-sel .miller-rank { background:rgba(255,255,255,0.22);color:rgba(255,255,255,0.85); }
.miller-arr { color:#ccc;flex-shrink:0;font-size:13px;margin-left:1px; }
.miller-item.miller-sel .miller-arr { color:rgba(255,255,255,0.6); }
.miller-msg { padding:18px 12px;text-align:center;font-size:12px;color:var(--text3);font-style:italic; }
.miller-count { font-size:10px;color:var(--text3);margin-left:3px;flex-shrink:0; }
.miller-drill-hint { font-size:10px;color:var(--text3);padding:4px 14px 0;min-height:18px; }
.miller-search-row { padding:8px 14px 0;flex-shrink:0; }
.miller-search-wrap { position:relative; }
.miller-search-in { width:100%;box-sizing:border-box;border:1px solid var(--border);border-radius:8px;padding:7px 28px 7px 30px;font-size:12.5px;font-family:var(--font-sans);background:var(--surface);color:var(--text1);outline:none; }
.miller-search-in:focus { border-color:var(--green);box-shadow:0 0 0 2px rgba(42,94,58,0.1); }
.miller-search-icon { position:absolute;left:10px;top:50%;transform:translateY(-50%);font-size:11px;color:var(--text3);pointer-events:none; }
.miller-search-x { position:absolute;right:8px;top:50%;transform:translateY(-50%);background:none;border:none;cursor:pointer;font-size:16px;color:var(--text3);line-height:1;padding:0 2px; }
.miller-search-x:hover { color:var(--text1); }
.miller-drop { position:absolute;top:calc(100% + 4px);left:0;right:0;background:#fff;border:1px solid var(--border);border-radius:8px;box-shadow:0 4px 16px rgba(0,0,0,0.13);z-index:200;max-height:260px;overflow-y:auto; }
.miller-sug { display:flex;align-items:center;gap:8px;padding:8px 12px;cursor:pointer;border-bottom:0.5px solid #f0ece8;transition:background 0.08s; }
.miller-sug:last-child { border-bottom:none; }
.miller-sug:hover { background:var(--surface2); }
.miller-sug-info { flex:1;min-width:0; }
.miller-sug-main { font-size:12.5px;color:var(--text1);overflow:hidden;text-overflow:ellipsis;white-space:nowrap; }
.miller-sug-main.vern { font-weight:500; }
.miller-sug-main.sci { font-style:italic; }
.miller-sug-sub { font-size:11px;color:var(--text3);font-style:italic;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-top:1px; }
.miller-sug-rank { font-size:9px;text-transform:uppercase;letter-spacing:0.06em;color:var(--text3);background:var(--surface2);padding:1px 5px;border-radius:3px;flex-shrink:0;white-space:nowrap; }
.miller-sug-msg { padding:14px 12px;text-align:center;font-size:12px;color:var(--text3); }
.taxo-ftr { display:flex;align-items:center;padding:11px 16px;border-top:1px solid var(--border);flex-shrink:0; }
.taxo-add { flex:1;background:var(--green);color:#fff;border:none;border-radius:8px;padding:9px 14px;font-size:12.5px;font-weight:600;cursor:pointer;text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;transition:background 0.15s; }
.taxo-add:hover:not(:disabled) { background:var(--green-dark,#1b5e3a); }
.taxo-add:disabled { background:#cbc7c2;cursor:default; }
.taxo-browse-link { display:inline-flex;align-items:center;gap:4px;background:none;border:none;cursor:pointer;font-size:11px;color:var(--text3);padding:2px 0;font-family:var(--font-sans);margin-top:3px; }
.taxo-browse-link:hover { color:var(--green); }
