:root {
    color-scheme: light;
    --bg: #f8f8f8;
    --bg-surface: #fff;
    --text: #1a1a1a;
    --text-secondary: #666;
    --text-muted: #555;
    --text-empty: #888;
    --border: #e0e0e0;
    --border-light: #f0f0f0;
    --border-mid: #e8e8e8;
    --hover: #f5f5f5;
    --accent: #1a73e8;
    --accent-hover: #1557b0;
    --success: #2e7d32;
    --disabled: #aaa;
    --input-border: #ccc;
    --input-bg: #fff;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #1a1a1a;
    --bg-surface: #252525;
    --text: #e0e0e0;
    --text-secondary: #999;
    --text-muted: #aaa;
    --text-empty: #777;
    --border: #333;
    --border-light: #2a2a2a;
    --border-mid: #333;
    --hover: #2e2e2e;
    --accent: #5b9cf6;
    --accent-hover: #4a8be0;
    --success: #66bb6a;
    --disabled: #555;
    --input-border: #444;
    --input-bg: #2a2a2a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; color: var(--text); background: var(--bg); }

/* Logo in sidebar */
.sidebar-logo { text-align: center; padding-bottom: 1rem; align-items: center; border-bottom: 1px solid var(--border); overflow: hidden; margin: -1.5rem -1.5rem 0 -1.5rem; padding-top: 1.5rem; flex-shrink: 0; }
.sidebar-logo p { color: var(--text-secondary); margin-top: 0.25rem; font-size: 0.85rem; }
.logo { height: 5rem; vertical-align: middle; }
.logo-dark { display: none; }
html[data-theme="dark"] .logo-light { display: none; }
html[data-theme="dark"] .logo-dark { display: inline; }

.theme-switch {
    position: relative;
    width: 44px; height: 24px;
    background: #1a1a1a; border: 1px solid var(--border); border-radius: 12px;
    cursor: pointer; user-select: none;
}
html[data-theme="dark"] .theme-switch { background: #f8f8f8; }
.theme-switch-knob {
    position: absolute; top: 3px; left: 3px;
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--accent); transition: left 0.2s ease;
}
html[data-theme="dark"] .theme-switch-knob { left: 23px; }

.sidebar-footer {
    padding-top: 1rem; border-top: 1px solid var(--border);
    font-size: 0.7rem; line-height: 1.4; color: var(--text-secondary);
}
.sidebar-footer a { color: var(--accent); text-decoration: none; }
.sidebar-footer a:hover { text-decoration: underline; }
.sidebar-footer .citation {
    margin-top: 0.4rem; font-style: italic; color: var(--text-muted); font-size: 0.65rem;
}

.layout { display: flex; height: 100vh; }

.sidebar {
    width: 340px; min-width: 340px; background: var(--bg-surface);
    border-right: 1px solid var(--border); padding: 1.5rem;
    display: flex; flex-direction: column; gap: 1.25rem;
    overflow-y: auto;
}

.form-group label {
    display: block; font-size: 0.8rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-muted); margin-bottom: 0.4rem;
}
.form-group input, .form-group select {
    width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--input-border);
    border-radius: 6px; font-size: 0.9rem; background: var(--input-bg); color: var(--text);
}
.form-group select {
    appearance: none;
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
}
.form-group select:not(:disabled) { cursor: pointer; }
.form-group select:not(:disabled):hover { border-color: var(--accent); }
.form-group input[type="file"] { padding: 0.4rem; }
.list-type-toggle {
    display: flex; border: 1px solid var(--input-border); border-radius: 6px;
    overflow: hidden; margin-bottom: 0.4rem;
}
.list-type-btn {
    flex: 1; padding: 0.4rem; font-size: 0.85rem; font-weight: 500;
    border: none; background: var(--input-bg); color: var(--text-secondary);
    cursor: pointer; transition: background 0.15s, color 0.15s;
}
.list-type-btn:not(:last-child) { border-right: 1px solid var(--input-border); }
.list-type-btn:hover { background: var(--hover); }
.list-type-btn.active { background: var(--accent); color: #fff; }
.search-mode-btn {
    flex: 1; padding: 0.4rem; font-size: 0.85rem; font-weight: 500;
    border: none; background: var(--input-bg); color: var(--text-secondary);
    cursor: pointer; transition: background 0.15s, color 0.15s;
}
.search-mode-btn:not(:last-child) { border-right: 1px solid var(--input-border); }
.search-mode-btn:hover { background: var(--hover); }
.search-mode-btn.active { background: var(--accent); color: #fff; }
.target-mode-btn {
    flex: 1; padding: 0.4rem; font-size: 0.85rem; font-weight: 500;
    border: none; background: var(--input-bg); color: var(--text-secondary);
    cursor: pointer; transition: background 0.15s, color 0.15s;
}
.target-mode-btn:not(:last-child) { border-right: 1px solid var(--input-border); }
.target-mode-btn:hover { background: var(--hover); }
.target-mode-btn.active { background: var(--accent); color: #fff; }
.lifelist-source-btn {
    flex: 1; padding: 0.4rem; font-size: 0.85rem; font-weight: 500;
    border: none; background: var(--input-bg); color: var(--text-secondary);
    cursor: pointer; transition: background 0.15s, color 0.15s;
}
.lifelist-source-btn:not(:last-child) { border-right: 1px solid var(--input-border); }
.lifelist-source-btn:hover { background: var(--hover); }
.lifelist-source-btn.active { background: var(--accent); color: #fff; }
.date-row { display: flex; gap: 0.75rem; }
.date-row > div { flex: 1; min-width: 0; }
.date-selects { display: flex; gap: 0.35rem; }
.date-selects select:first-child { flex: 1.4; }
.date-selects select:last-child { flex: 1; }

.multi-select {
    position: relative;
}
.multi-select-display {
    width: 100%; padding: 0.5rem 0.75rem; padding-right: 2rem; border: 1px solid var(--input-border);
    border-radius: 6px; font-size: 0.9rem; background: var(--input-bg); color: var(--text);
    cursor: pointer; user-select: none;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
}
.multi-select-display:hover { border-color: var(--accent); }
.multi-select-dropdown {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: var(--bg-surface); border: 1px solid var(--input-border);
    border-radius: 6px; margin-top: 2px; overflow-y: auto;
    z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.multi-select-dropdown.open { display: block; }
.multi-select-item {
    padding: 0.4rem 0.75rem; cursor: pointer; border-radius: 6px; font-size: 0.9rem;
    display: flex; align-items: center; justify-content: space-between;
}
.multi-select-item:hover { background: var(--hover); }
.multi-select-item .check {
    color: var(--accent); font-size: 0.9rem; visibility: hidden;
}
.multi-select-item.selected { background: var(--hover); }
.multi-select-item.selected .check {
    visibility: visible;
}
.multi-select-actions {
    display: flex; gap: 0; border-bottom: 1px solid var(--border-light);
    position: sticky; top: 0; background: var(--bg-surface); z-index: 1;
}
.multi-select-sub-actions { top: auto; }
.multi-select-actions button {
    flex: 1; padding: 0.35rem; font-size: 0.75rem; cursor: pointer;
    background: none; border: none; color: var(--accent); font-weight: 500;
}
.multi-select-actions button:hover { background: var(--hover); }
.multi-select-actions button.active { color: #fff; background: var(--accent); }
.form-hint { font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.25rem; }

#learn-more-close {
    display: block; margin: 0 auto;
}

.help-btn {
    width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--text-secondary);
    background: none; color: var(--text-secondary); font-size: .9rem; font-weight: 600;
    font-family: system-ui, -apple-system, sans-serif;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; padding: 0; line-height: 1; margin-top: 6px;
}
.help-btn:hover { border-color: var(--accent); color: var(--accent); }
.help-dialog-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    z-index: 2000; align-items: center; justify-content: center;
}
.help-dialog-overlay.open { display: flex; }
.help-dialog {
    background: var(--bg-surface); border: 1px solid var(--border); border-radius: 10px;
    padding: 1.5rem; max-width: 360px; width: 90%; max-height: 85vh; overflow-y: auto;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2); text-align: center;
}
.help-dialog p { font-size: 0.9rem; color: var(--text); line-height: 1.5; margin-bottom: 1rem; }
.help-dialog .katex-display { overflow-x: auto; overflow-y: hidden; }
.help-dialog a { color: var(--accent); text-decoration: none; }
.help-dialog a:hover { text-decoration: underline; }
.help-dialog-close {
    padding: 0.4rem 1.5rem; background: var(--accent); color: #fff;
    border: none; border-radius: 6px; font-size: 0.85rem; font-weight: 500; cursor: pointer;
}
.help-dialog-close:hover { background: var(--accent-hover); }

.form-hint.loaded { color: var(--success); }
.form-hint.error { color: #d32f2f; }
html[data-theme="dark"] .form-hint.error { color: #ef5350; }

button.primary {
    width: 100%; padding: 0.7rem; background: var(--accent); color: #fff;
    border: none; border-radius: 6px; font-size: 0.95rem; font-weight: 500;
    cursor: pointer;
}
button.primary:hover { background: var(--accent-hover); }
button.primary:disabled { background: var(--disabled); cursor: not-allowed; }

.main { flex: 1; padding: 0 2rem 1.5rem; overflow-y: auto; scroll-padding-top: calc(350px + 1.5rem); }

.metrics { display: flex; gap: 1rem; margin-bottom: 1.5rem; }
.metric-card {
    background: var(--bg-surface); border: 1px solid var(--border); border-radius: 8px;
    padding: 1rem 1.25rem; flex: 1;
}
.metric-card .value { font-size: 1.75rem; font-weight: 700; }
.metric-card .label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.2rem; }

/* Results layout */
.results-layout { display: flex; flex-direction: column; }
.results-map { order: -1; position: sticky; top: 0; z-index: 2; background: var(--bg); padding-top: 1.5rem; }
#map { height: 350px; border-radius: 8px; border: 1px solid var(--border); }
.results-list { padding-top: 1.5rem; padding-bottom: 40vh; }
.map-marker { background: none; border: none; }
.map-marker-inner {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--accent); color: #fff; border: 2px solid #fff;
    font-size: 0.8rem; font-weight: 700; font-family: system-ui, sans-serif;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    opacity: 0.9;
    transition: transform 0.15s ease;
}
.map-marker-inner.itinerary-marker {
    background: var(--success);
}
.map-marker-inner.highlight {
    transform: scale(1.2);
}
.map-fit-btn {
    width: 34px; height: 34px; border: none; border-radius: 6px;
    background: var(--bg-surface); color: var(--text);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.map-fit-btn:hover { background: var(--hover); }
.leaflet-bar a {
    background-color: var(--bg-surface) !important;
    color: var(--text) !important;
    border-bottom-color: var(--border) !important;
}
.leaflet-bar a:hover { background-color: var(--hover) !important; }
.leaflet-bar { border-color: var(--border) !important; }

.hotspot-card {
    background: var(--bg-surface); border: 1px solid var(--border); border-radius: 8px;
    margin-bottom: 1rem; overflow: hidden; transition: border-color 0.15s ease;
    scroll-margin-top: 0.75rem;
}
.hotspot-card.highlight {
    border-color: var(--accent);
}
.hotspot-header {
    padding: 1rem 1.25rem; cursor: pointer; display: flex;
    justify-content: space-between; align-items: center;
}
.hotspot-header:hover { background: var(--hover); }
.drag-active .hotspot-header:hover { background: none; }
.hotspot-header .rank {
    font-size: 1.1rem; font-weight: 600; color: var(--accent);
    margin-right: 0.75rem;
}
.hotspot-header .name { font-weight: 500; flex: 1; }
.hotspot-header .gain-group { text-align: right; display: flex; flex-direction: column; align-items: flex-end; }
.hotspot-header .gain { font-size: 0.9rem; color: var(--success); font-weight: 500; }
.hotspot-header .gain-marginal { font-size: 0.75rem; color: var(--accent); font-weight: 400; }
.hotspot-body { display: none; padding: 0 1.25rem 1rem; border-top: 1px solid var(--border-mid); }
.hotspot-body.open { display: block; }
.hotspot-meta { font-size: 0.85rem; color: var(--text-secondary); padding-top: 0.75rem; margin-bottom: 0.75rem; }
.hotspot-meta a { color: var(--accent); text-decoration: none; }
.hotspot-meta a:hover { text-decoration: underline; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th { text-align: left; font-weight: 600; color: var(--text-muted); padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
td { padding: 0.4rem 0; border-bottom: 1px solid var(--border-light); }
.prob-bar {
    display: inline-block; height: 6px; background: var(--accent); border-radius: 3px;
    margin-right: 0.5rem; vertical-align: middle;
}

.location-search { position: relative; }
.location-input-row {
    display: flex; gap: 0;
}
.location-input-row input {
    flex: 1; min-width: 0;
    border-top-right-radius: 0 !important; border-bottom-right-radius: 0 !important;
    border-right: none !important;
}
.location-btn {
    display: flex; align-items: center; justify-content: center;
    width: 36px; flex-shrink: 0;
    border: 1px solid var(--input-border); border-left: none;
    border-radius: 0 6px 6px 0;
    background: var(--input-bg); color: var(--text-secondary);
    cursor: pointer; transition: color 0.15s, background 0.15s;
}
.location-btn:hover { color: var(--accent); background: var(--hover); }
.driving-time-input {
    display: flex; align-items: center;
    border: 1px solid var(--input-border); border-radius: 6px;
    background: var(--input-bg); overflow: hidden;
}
.driving-time-input input {
    flex: 1; min-width: 0; border: none !important; border-radius: 0 !important;
    background: transparent !important;
}
.driving-time-suffix {
    padding: 0 0.75rem; font-size: 0.85rem; color: var(--text-secondary);
    white-space: nowrap; user-select: none;
}
.location-dropdown {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: var(--bg-surface); border: 1px solid var(--input-border);
    border-radius: 6px; margin-top: 2px; max-height: 14rem; overflow-y: auto;
    z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.location-dropdown.open { display: block; }
.location-dropdown-item {
    padding: 0.45rem 0.75rem; cursor: pointer; font-size: 0.85rem;
}
.location-dropdown-item:hover, .location-dropdown-item.active {
    background: var(--hover);
}
.location-selected {
    margin-top: 0.35rem; font-size: 0.85rem; color: var(--success); font-weight: 500;
}

.species-search { position: relative; }
.species-dropdown {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: var(--bg-surface); border: 1px solid var(--input-border);
    border-radius: 6px; margin-top: 2px; max-height: 14rem; overflow-y: auto;
    z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.species-dropdown.open { display: block; }
.species-dropdown-item {
    padding: 0.45rem 0.75rem; cursor: pointer; font-size: 0.85rem;
}
.species-dropdown-item:hover, .species-dropdown-item.active {
    background: var(--hover);
}
.species-dropdown-item .sci-name {
    color: var(--text-secondary); font-style: italic; font-size: 0.8rem;
    margin-left: 0.35rem;
}
/* Species chips */
.species-chips {
    display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.4rem;
}
.species-chip {
    display: inline-flex; align-items: center; gap: 0.3rem;
    background: var(--hover); border: 1px solid var(--input-border);
    border-radius: 999px; padding: 0.2rem 0.55rem; font-size: 0.8rem;
    color: var(--text); line-height: 1.4;
}
.species-chip-remove {
    background: none; border: none; color: var(--text-secondary);
    cursor: pointer; font-size: 1rem; line-height: 1; padding: 0;
    margin-left: 0.1rem; display: flex; align-items: center;
}
.species-chip-remove:hover { color: var(--text); }
/* Region search */
.region-search { position: relative; }
.region-search-dropdown {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: var(--bg-surface); border: 1px solid var(--input-border);
    border-radius: 6px; margin-top: 2px; max-height: 14rem; overflow-y: auto;
    z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.region-search-dropdown.open { display: block; }
.region-search-item {
    padding: 0.45rem 0.75rem; cursor: pointer; font-size: 0.85rem;
    display: flex; align-items: center; justify-content: space-between;
}
.region-search-item:hover, .region-search-item.active { background: var(--hover); }
.region-search-item .region-context {
    color: var(--text-secondary); font-size: 0.75rem; margin-left: 0.5rem;
}
.region-search-item .region-level {
    font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em;
    padding: 0.1rem 0.35rem; border-radius: 3px; font-weight: 600;
    background: var(--border); color: var(--text-secondary); flex-shrink: 0; margin-left: 0.5rem;
}

/* Hotspot search in Plan tab */
.hotspot-search { position: relative; margin-bottom: 1rem; }
.hotspot-search input {
    width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--input-border);
    border-radius: 6px; font-size: 0.9rem; background: var(--input-bg); color: var(--text);
    box-sizing: border-box;
}
.hotspot-search-dropdown {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: var(--bg-surface); border: 1px solid var(--input-border);
    border-radius: 6px; margin-top: 2px; max-height: 14rem; overflow-y: auto;
    z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.hotspot-search-dropdown.open { display: block; }
.hotspot-search-dropdown-item {
    padding: 0.45rem 0.75rem; cursor: pointer; font-size: 0.85rem;
}
.hotspot-search-dropdown-item:hover, .hotspot-search-dropdown-item.active {
    background: var(--hover);
}
.hotspot-search-dropdown-item .hotspot-search-county {
    color: var(--text-secondary); font-size: 0.8rem; margin-left: 0.35rem;
}

/* Results mode toggle (Explore / Plan) */
.results-mode-toggle {
    display: flex; border: 1px solid var(--input-border); border-radius: 6px;
    overflow: hidden; margin-bottom: 1rem;
}
.results-mode-btn {
    flex: 1; padding: 0.4rem; font-size: 0.85rem; font-weight: 500;
    border: none; background: var(--input-bg); color: var(--text-secondary);
    cursor: pointer; transition: background 0.15s, color 0.15s;
}
.results-mode-btn:not(:last-child) { border-right: 1px solid var(--input-border); }
.results-mode-btn:hover { background: var(--hover); }
.results-mode-btn.active { background: var(--accent); color: #fff; }

/* Add to itinerary button */
.add-itinerary-btn, .added-itinerary-btn {
    width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--input-border);
    font-size: 1.1rem; line-height: 1; display: flex; align-items: center; justify-content: center; padding-bottom: 3px;
    margin-left: 0.75rem; flex-shrink: 0; transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.add-itinerary-btn {
    background: var(--input-bg); color: var(--text-secondary); cursor: pointer;
}
.add-itinerary-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--hover); }
.added-itinerary-btn {
    background: var(--hover); color: var(--success); border-color: var(--success);
    cursor: default; font-size: 0.85rem;
}

/* Drag handle */
.drag-handle {
    font-size: 1.1rem; color: var(--text-secondary); cursor: grab; margin-right: 0.5rem;
    user-select: none; flex-shrink: 0;
}
.drag-handle:active { cursor: grabbing; }

/* Remove from itinerary button */
.remove-itinerary-btn {
    width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--input-border);
    position: relative; font-size: 0;
    margin-left: 0.75rem; flex-shrink: 0;
    background: var(--input-bg); color: var(--text-secondary); cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.remove-itinerary-btn::before, .remove-itinerary-btn::after {
    content: ''; position: absolute; top: 50%; left: 50%;
    width: 12px; height: 1.5px; background: currentColor;
}
.remove-itinerary-btn::before { transform: translate(-50%, -50%) rotate(45deg); }
.remove-itinerary-btn::after { transform: translate(-50%, -50%) rotate(-45deg); }
.remove-itinerary-btn:hover { border-color: #d32f2f; color: #d32f2f; background: var(--hover); }
html[data-theme="dark"] .remove-itinerary-btn:hover { border-color: #ef5350; color: #ef5350; }

/* Drag states */
.hotspot-card.dragging { pointer-events: none; }
.drag-placeholder { margin-bottom: 1rem; }

.empty-state {
    text-align: center; color: var(--text-empty); padding: 4rem 2rem;
    font-size: 1rem;
}

.section-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-title-row .section-title { margin-bottom: 0; }
.expand-collapse-btns { display: flex; gap: 0.5rem; }
.expand-collapse-btn {
    padding: 0.3rem 0.7rem; font-size: 0.8rem; font-weight: 500;
    border: 1px solid var(--input-border); border-radius: 6px;
    background: var(--input-bg); color: var(--text);
    cursor: pointer; transition: background 0.15s;
}
.expand-collapse-btn:hover { background: var(--hover); border-color: var(--accent); }

/* Walkthrough */
.walkthrough-overlay {
    display: none; position: fixed; inset: 0; z-index: 2500;
}
.walkthrough-overlay.open { display: block; }
.walkthrough-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    transition: clip-path 0.3s ease;
}
.walkthrough-close {
    position: absolute; top: 0.4rem; right: 0.5rem;
    background: none; border: none; font-size: 1.25rem; line-height: 1;
    color: var(--text-secondary); cursor: pointer; padding: 0.1rem 0.3rem;
}
.walkthrough-close:hover { color: var(--text); }
.walkthrough-bubble {
    position: fixed; z-index: 2501;
    background: var(--bg-surface); border: 1px solid var(--border); border-radius: 10px;
    padding: 1.25rem; max-width: 320px; width: 90%;
    box-shadow: 0 8px 30px rgba(0,0,0,0.25);
    transition: top 0.3s ease, left 0.3s ease;
}
.walkthrough-bubble::after {
    content: ''; position: absolute;
    width: 10px; height: 10px; background: var(--bg-surface);
    border: 1px solid var(--border); transform: rotate(45deg);
}
.walkthrough-bubble[data-arrow="top"]::after {
    top: -6px; left: 50%; margin-left: -5px;
    border-right: none; border-bottom: none;
}
.walkthrough-bubble[data-arrow="bottom"]::after {
    bottom: -6px; left: 50%; margin-left: -5px;
    border-left: none; border-top: none;
}
.walkthrough-bubble[data-arrow="left"]::after {
    left: -6px; top: 50%; margin-top: -5px;
    border-right: none; border-top: none;
}
.walkthrough-bubble[data-arrow="right"]::after {
    right: -6px; top: 50%; margin-top: -5px;
    border-left: none; border-bottom: none;
}
.walkthrough-title {
    font-size: 0.95rem; font-weight: 600; color: var(--text); margin-bottom: 0.4rem;
}
.walkthrough-desc {
    font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5; margin-bottom: 1rem;
}
.walkthrough-footer {
    display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
}
.walkthrough-dots {
    font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap;
}
.walkthrough-btns {
    display: flex; gap: 0.4rem;
}
.walkthrough-btn {
    padding: 0.35rem 1rem; border: none; border-radius: 6px;
    font-size: 0.8rem; font-weight: 500; cursor: pointer;
}
.walkthrough-btn.primary { background: var(--accent); color: #fff; }
.walkthrough-btn.primary:hover { background: var(--accent-hover); }
.walkthrough-btn.secondary { background: none; color: var(--text-secondary); border: 1px solid var(--border); }
.walkthrough-btn.secondary:hover { border-color: var(--accent); color: var(--accent); }
.walkthrough-btn.skip { background: none; color: var(--text-secondary); border: none; font-size: 0.75rem; }
.walkthrough-btn.skip:hover { color: var(--text); }
.walkthrough-target-highlight {
    position: relative; z-index: 2501;
    box-shadow: 0 0 0 4px var(--accent), 0 0 0 6px rgba(26,115,232,0.2);
    border-radius: 6px;
}
.tour-help-btn {
    display: flex; align-items: center; gap: 0.35rem;
    background: none; border: 1px solid var(--text-secondary); border-radius: 12px;
    color: var(--text-secondary); font-size: 0.75rem; font-weight: 500;
    cursor: pointer; padding: 0.2rem 0.6rem 0.2rem 0.35rem;
    font-family: system-ui, -apple-system, sans-serif;
}
.tour-help-btn:hover { border-color: var(--accent); color: var(--accent); }
.tour-help-btn .tour-help-icon {
    width: 16px; height: 16px; border-radius: 50%; border: 1px solid currentColor;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 600; line-height: 1; flex-shrink: 0;
}

/* Sidebar toggle — hidden by default, shown on mobile */
.sidebar-toggle { display: none; }
.mobile-footer { display: none; }

/* Mobile: stacked layout */
@media (max-width: 768px) {
    .layout { flex-direction: column; height: auto; min-height: 100vh; }
    .sidebar {
        width: 100%; min-width: 0;
        border-right: none; border-bottom: 1px solid var(--border);
        padding: 1rem;
        gap: 1rem;
        overflow: visible; transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
    }
    .sidebar.collapsed {
        max-height: 0; padding-top: 0; padding-bottom: 0;
        border-bottom: none; opacity: 0; overflow: hidden;
    }
    .sidebar-toggle {
        display: flex; align-items: center; gap: 0.4rem;
        width: 100%; padding: 0.6rem 1rem;
        padding-top: max(0.6rem, env(safe-area-inset-top));
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        background: var(--bg-surface); border: none; border-bottom: 1px solid var(--border);
        color: var(--text); font-size: 0.85rem; font-weight: 500;
        cursor: pointer; font-family: inherit;
    }
    .sidebar-toggle:hover { background: var(--hover); }
    .sidebar-toggle-logo { height: 1.5rem; vertical-align: middle; }
    .sidebar-toggle-logo.logo-dark { display: none; }
    html[data-theme="dark"] .sidebar-toggle-logo.logo-light { display: none; }
    html[data-theme="dark"] .sidebar-toggle-logo.logo-dark { display: inline; }
    .sidebar-toggle-icon {
        display: inline-block; width: 18px; height: 14px; position: relative;
    }
    .sidebar-toggle-icon::before {
        content: ''; position: absolute; left: 0; top: 0;
        width: 18px; height: 2px; background: currentColor; border-radius: 1px;
        box-shadow: 0 6px 0 currentColor, 0 12px 0 currentColor;
        transition: transform 0.2s;
    }
    .sidebar-footer { display: none; }
    .mobile-footer {
        display: block; padding: 1rem;
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        font-size: 0.7rem; line-height: 1.4; color: var(--text-secondary);
        border-top: 1px solid var(--border); background: var(--bg-surface);
    }
    .mobile-footer a { color: var(--accent); text-decoration: none; }
    .mobile-footer a:hover { text-decoration: underline; }
    .mobile-footer .citation {
        margin-top: 0.4rem; font-style: italic; color: var(--text-muted); font-size: 0.65rem;
    }
    .sidebar-logo { display: none; }
    /* Prevent iOS Safari auto-zoom on input focus */
    input, select, .multi-select-display { font-size: 16px; }
    .main { padding: 0 1rem 1.5rem; scroll-padding-top: calc(250px + 1rem); }
    .results-map { padding-top: 1rem; }
    #map { height: 250px; }
    .metrics { flex-direction: column; gap: 0.5rem; }
    .metric-card { padding: 0.75rem 1rem; }
    .metric-card .value { font-size: 1.35rem; }
    .empty-state { padding: 2rem 1rem; }
    .hotspot-header { padding: 0.75rem 1rem; }
    .hotspot-body { padding: 0 1rem 0.75rem; }
    .walkthrough-bubble { max-width: 280px; padding: 1rem; }
    .help-dialog { padding: 1.25rem; }
}

/* Tablet */
@media (max-width: 1024px) and (min-width: 769px) {
    .sidebar { width: 280px; min-width: 280px; padding: 1.25rem; }
    .sidebar-logo { margin: -1.25rem -1.25rem 0 -1.25rem; padding-top: 1.25rem; }
    .logo { height: 3rem; }
    .sidebar-logo p { font-size: 0.75rem; }
    .main { padding: 0 1.5rem 1.5rem; }
    #map { height: 300px; }
}

/* Wide screen: map on right, hotspot list on left */
@media (min-width: 1400px) {
    .layout { height: 100vh; }
    .main { overflow-y: auto; scroll-padding-top: 0; }
    .results-layout {
        flex-direction: row; gap: 1.5rem;
    }
    .results-list { flex: 1; min-width: 0; }
    .results-map {
        order: 0; width: 45%; min-width: 400px; flex-shrink: 0;
        position: sticky; top: 0; align-self: flex-start;
    }
    .results-map #map { height: calc(100vh - 3rem); margin-bottom: 0; }
}
