:root {
    --bg: #0f1419;
    --panel: #171d24;
    --panel-border: #2a3441;
    --text: #e7edf4;
    --muted: #8b98a5;
    --accent: #f59e0b;
    --accent-soft: rgba(245, 158, 11, 0.15);
    --selected: #2563eb;
    --selected-soft: rgba(37, 99, 235, 0.18);
    --blm: #d97706;
    --reviewed: #22c55e;
    --danger: #ef4444;
    --surface-raised: rgba(255, 255, 255, 0.02);
    --tap-highlight: rgba(255, 255, 255, 0.05);
    --swatch-border: rgba(255, 255, 255, 0.35);
    --switch-track-off: #334155;
    --border: #334155;
    /* Deliberately NOT overridden in the light theme below — this pill
       floats over map tiles, not app chrome, so it stays a consistently
       legible dark scrim regardless of theme or tile brightness. */
    --overlay-bg: rgba(15, 20, 25, 0.9);
    --safe-top: env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
    --safe-left: env(safe-area-inset-left, 0);
    --safe-right: env(safe-area-inset-right, 0);
}

:root[data-theme="light"] {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --panel-border: #dde3ea;
    --text: #14181f;
    --muted: #64748b;
    /* --accent stays the same amber in both themes — it's the brand
       color, and a dozen+ other rules in this file hardcode
       rgba(245, 158, 11, X) tints derived from it (hover/active states,
       badge backgrounds) rather than referencing a token; changing the
       hue here would only desync those from the button/text accent. */
    --selected-soft: rgba(37, 99, 235, 0.12);
    --reviewed: #15803d;
    --danger: #dc2626;
    --surface-raised: rgba(0, 0, 0, 0.03);
    --tap-highlight: rgba(0, 0, 0, 0.05);
    --swatch-border: rgba(0, 0, 0, 0.3);
    --switch-track-off: #cbd5e1;
    --border: #cbd5e1;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-touch-callout: none;
}

.hidden {
    display: none !important;
}

.auth-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: max(1rem, var(--safe-top)) max(1rem, var(--safe-right)) max(1rem, var(--safe-bottom)) max(1rem, var(--safe-left));
}

.auth-card {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
}

.auth-card h1 {
    margin: 0 0 0.5rem;
}

.auth-card p {
    color: var(--muted);
    margin: 0 0 1.5rem;
}

#google-sign-in {
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 10px;
    background: #fff;
    color: #111;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    font-size: 16px;
}

.auth-error {
    margin: 1rem 0 0;
    color: var(--danger);
    font-size: 0.85rem;
    min-height: 1.2rem;
}

.auth-setup {
    margin: 1rem 0 0;
    color: var(--muted);
    font-size: 0.85rem;
    line-height: 1.5;
    text-align: left;
}

.auth-setup a {
    color: var(--accent);
}

.hosted-banner {
    grid-column: 1 / -1;
    background: rgba(245, 158, 11, 0.12);
    border-bottom: 1px solid rgba(245, 158, 11, 0.35);
    color: var(--text);
    padding: max(0.65rem, calc(0.65rem + var(--safe-top))) max(1rem, var(--safe-right)) 0.65rem max(1rem, var(--safe-left));
    font-size: 0.85rem;
    line-height: 1.45;
}

.hosted-banner code {
    font-size: 0.8rem;
}

/* Edge/deploy status chrome is passive info, not an alert — keep it compact
   and on one line (device name and deploy version share this element). */
#edge-status {
    padding: max(0.2rem, calc(0.2rem + var(--safe-top))) max(1rem, var(--safe-right)) 0.2rem max(1rem, var(--safe-left));
    font-size: 0.68rem;
    line-height: 1.3;
    opacity: 0.75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layout {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    height: 100vh;
    height: 100dvh;
}

/* Mobile only: a pane is open (default) — give the sidebar the whole
   screen and shrink the map row to nothing, so "open a pane" and "just
   the map" are both literally true, not a 45vh sheet sharing space with
   the map. Scoped to mobile because on desktop the sidebar is a column,
   not a row, and always spans the full height regardless of collapse
   state (see .sidebar's grid-row: 1 / -1 under the 768px breakpoint) —
   an unscoped override here would fight that breakpoint's own
   grid-template-rows (used for the hosted-banner row) via :not()'s
   higher specificity. */
@media (max-width: 767.98px) {
    .layout:not(.sidebar-collapsed) {
        grid-template-rows: 0 1fr;
    }
}

.sidebar {
    grid-row: 2;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-top: 1px solid var(--panel-border);
    overflow: hidden;
    max-height: 100vh;
    max-height: 100dvh;
}

.sidebar-header {
    flex-shrink: 0;
    padding: 1rem max(1rem, var(--safe-right)) 0.75rem max(1rem, var(--safe-left));
}

.header-row {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.sidebar-header h1 {
    margin: 0;
    font-size: 1.15rem;
}

.sidebar-header p {
    margin: 0.25rem 0 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.user-label {
    margin: 0.5rem 0 0;
    color: var(--muted);
    font-size: 0.75rem;
}

/* Collapsed = map-only: hide everything except the pane-tabs strip, so the
   tabs stay reachable as the only way back into a pane. */
.layout.sidebar-collapsed .sidebar-header,
.layout.sidebar-collapsed .pane {
    display: none;
}

.pane-tabs {
    flex-shrink: 0;
    display: flex;
    gap: 0.4rem;
    padding: 0.5rem max(0.75rem, var(--safe-right)) max(0.5rem, var(--safe-bottom)) max(0.75rem, var(--safe-left));
    border-top: 1px solid var(--panel-border);
}

.pane-tab {
    flex: 1;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    min-height: 44px;
    padding: 0.5rem 0.4rem;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.pane-tab[aria-selected="true"] {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: rgba(245, 158, 11, 0.35);
}

.pane-tab-count {
    display: inline-grid;
    place-items: center;
    min-width: 1.2rem;
    height: 1.2rem;
    padding: 0 0.3rem;
    border-radius: 999px;
    background: var(--accent);
    color: #111;
    font-size: 0.65rem;
    font-weight: 800;
}

.pane {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0 max(1rem, var(--safe-right)) max(1rem, calc(1rem + var(--safe-bottom))) max(1rem, var(--safe-left));
}

.pane-header {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: flex-start;
    padding-top: 1rem;
    flex-shrink: 0;
}

.pane-header h2 {
    margin: 0;
    font-size: 1.05rem;
}

.pane-subtitle {
    margin: 0.2rem 0 0;
    color: var(--muted);
    font-size: 0.75rem;
}

.pane-close-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    line-height: 1;
    cursor: pointer;
    padding: 0.35rem;
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    font-size: 1.5rem;
}

.pane-close-btn:active {
    color: var(--text);
}

.pane-body {
    flex: 1;
    min-height: 0;
}

.ghost-btn {
    border: 1px solid var(--panel-border);
    background: transparent;
    color: var(--text);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    cursor: pointer;
    min-height: 36px;
    min-width: 36px;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    font-size: 16px;
}

.ghost-btn:active {
    background: var(--tap-highlight);
}

.stats {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.stat {
    flex: 1;
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.35rem;
    background: var(--bg);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 0.5rem 0.4rem;
}

.stat-value {
    font-size: 1rem;
    font-weight: 700;
}

.stat-label {
    color: var(--muted);
    font-size: 0.68rem;
}

.filters {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    flex-shrink: 0;
}

.filters-primary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 0.65rem;
}

.filters-full {
    grid-column: 1 / -1;
}

.filters label {
    display: grid;
    gap: 0.3rem;
    font-size: 0.8rem;
    color: var(--muted);
}

/* Shared collapsible-section look — used by "Advanced filters" in the
   Sightings pane and by each section of the Settings pane. */
.disclosure {
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 0.55rem 0.65rem;
}

.disclosure summary {
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    -webkit-tap-highlight-color: transparent;
}

.disclosure[open] summary {
    color: var(--text);
    margin-bottom: 0.5rem;
}

.disclosure .checkbox-row {
    margin-top: 0.5rem;
}

.disclosure .checkbox-row:first-of-type {
    margin-top: 0;
}

.disclosure + .disclosure {
    margin-top: 0.65rem;
}

.filters select,
.filters input[type="search"] {
    width: 100%;
    padding: 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    min-height: 44px;
    -webkit-appearance: none;
    appearance: none;
}

.filters select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238b98a5' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    background-size: 12px 8px;
    padding-right: 2rem;
}

.checkbox-row {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    color: var(--text) !important;
}

.checkbox-row.is-checked {
    background: var(--accent-soft);
    font-weight: 600;
    border-radius: 8px;
    padding: 0.35rem 0.5rem;
    margin: 0 -0.5rem;
}

.checkbox-check {
    display: none;
    color: var(--accent);
    font-weight: 700;
}

.checkbox-row.is-checked .checkbox-check {
    display: inline;
}

.layer-hint {
    margin: -0.2rem 0 0.5rem;
    font-size: 0.75rem;
    color: var(--muted);
    line-height: 1.3;
}

.mi-land-filters {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.35rem;
}

.land-layer-fieldset {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.55rem 0.65rem 0.45rem;
    margin: 0;
}

.land-layer-fieldset legend {
    font-size: 0.8rem;
    color: var(--muted);
    padding: 0 0.25rem;
}

.land-layer-fieldset .checkbox-row {
    margin-bottom: 0.25rem;
}

#refresh-btn {
    padding: 0.75rem;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #111;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    font-size: 0.9rem;
    -webkit-tap-highlight-color: transparent;
}

#refresh-btn:active {
    filter: brightness(0.95);
}

.list-section {
    display: flex;
    flex-direction: column;
    /* A real minimum, not 0 — otherwise flexbox happily squeezes this to
       near-nothing when stats+filters are tall (e.g. Advanced filters
       open), since .pane's own overflow:auto only kicks in once content
       actually exceeds its box. Without this, "1500 results" can render
       with room for barely one visible card. */
    min-height: 55vh;
    flex: 1;
}

.hidden-count-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    color: var(--text);
}

.hidden-count-banner button {
    flex: 0 0 auto;
    background: none;
    border: 1px solid currentColor;
    color: var(--accent);
    border-radius: 6px;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.list-header h2 {
    margin: 0;
    font-size: 0.95rem;
}

#list-count {
    color: var(--muted);
    font-size: 0.8rem;
}

.sightings-list {
    overflow: auto;
    display: grid;
    gap: 0.5rem;
    padding-right: 0.25rem;
    -webkit-overflow-scrolling: touch;
}

.sighting-card {
    background: var(--bg);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 0.75rem;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
    display: flex;
    flex-direction: column;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.sighting-card:active {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.sighting-card.reviewed {
    border-left: 3px solid var(--reviewed);
}

.sighting-card.active {
    border-color: var(--selected);
    border-left-color: var(--selected);
    background: var(--selected-soft);
}

.sighting-title {
    margin: 0 0 0.2rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.review-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--muted);
}

.review-badge::before {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--muted);
}

.review-badge.is-reviewed {
    color: var(--reviewed);
}

.review-badge.is-reviewed::before {
    background: var(--reviewed);
}

.sighting-meta {
    margin: 0;
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 1.3;
}

.sighting-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.35rem;
}

.land-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--land-badge-color, var(--accent));
    color: var(--land-badge-color, var(--accent));
    background: rgba(245, 158, 11, 0.12);
}

.land-badge.is-near {
    opacity: 0.75;
}

.list-chip {
    display: inline-flex;
    align-items: center;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--selected);
    color: var(--selected);
    background: var(--selected-soft);
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sighting-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.sighting-actions button {
    border: 1px solid var(--panel-border);
    background: transparent;
    color: var(--text);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    font-size: 0.7rem;
    cursor: pointer;
    min-height: 36px;
    flex: 1;
    -webkit-tap-highlight-color: transparent;
    font-size: 16px;
}

.sighting-actions button:active {
    background: var(--tap-highlight);
}

.sighting-actions button.primary {
    border-color: var(--reviewed);
    color: var(--reviewed);
}

.quick-add-btn {
    flex: 0 0 auto;
    width: 36px;
    font-weight: 700;
}

.quick-add-btn.is-added {
    border-color: var(--reviewed);
    color: var(--reviewed);
}

.map-panel {
    grid-row: 1;
    position: relative;
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100%;
}

.map-status {
    position: absolute;
    top: calc(1rem + var(--safe-top));
    right: calc(1rem + var(--safe-right));
    z-index: 500;
    background: var(--overlay-bg);
    border: 1px solid var(--panel-border);
    border-radius: 999px;
    padding: 0.5rem 0.85rem;
    font-size: 0.75rem;
    color: var(--muted);
}

/* Collapsed (map-only): narrow the sidebar column to just the pane-tabs
   strip on desktop instead of 0, so tabs stay reachable to reopen a pane
   (mirrors mobile, where .layout.sidebar-collapsed above already shrinks
   the sidebar to its own natural content height — the tabs bar only). */
@media (min-width: 768px) {
    .layout.sidebar-collapsed {
        grid-template-columns: 6rem 1fr;
    }

    .layout.sidebar-collapsed .pane-tabs {
        flex-direction: column;
    }
}

.new-list-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.85rem;
}

.new-list-form input {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: var(--surface-raised);
    color: var(--text);
    font-size: 0.85rem;
}

.new-list-form button {
    border: 1px solid var(--reviewed);
    color: var(--reviewed);
    background: transparent;
    border-radius: 8px;
    padding: 0.5rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

#lists-picker-search {
    display: block;
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: var(--surface-raised);
    color: var(--text);
    font-size: 0.85rem;
    margin: 0 0 0.5rem;
}

.lists-body {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.list-row {
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 0.65rem 0.75rem;
    background: var(--surface-raised);
}

.list-row-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.list-row-name {
    font-weight: 700;
}

.list-row-count {
    color: var(--muted);
    font-size: 0.75rem;
}

.list-row-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.list-row-actions button {
    border: 1px solid var(--panel-border);
    background: transparent;
    color: var(--text);
    border-radius: 6px;
    padding: 0.35rem 0.55rem;
    font-size: 0.72rem;
    cursor: pointer;
    min-height: 32px;
    -webkit-tap-highlight-color: transparent;
}

.list-row-actions button.primary {
    border-color: var(--reviewed);
    color: var(--reviewed);
}

.list-row-items {
    margin-top: 0.55rem;
    padding-top: 0.55rem;
    border-top: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.list-item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    cursor: pointer;
    border-radius: 6px;
    -webkit-tap-highlight-color: transparent;
}

.list-item-row:hover,
.list-item-row:focus-visible {
    background: var(--surface-raised);
    outline: none;
}

.list-item-row button {
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.72rem;
    padding: 0.2rem 0.4rem;
    -webkit-tap-highlight-color: transparent;
}

.map-legend {
    font-size: 0.75rem;
}

.map-legend-section + .map-legend-section {
    margin-top: 0.65rem;
    padding-top: 0.65rem;
    border-top: 1px solid var(--panel-border);
}

.map-legend h2 {
    margin: 0 0 0.4rem;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.map-legend-row {
    display: grid;
    grid-template-columns: 0.85rem 1fr;
    align-items: center;
    gap: 0.45rem;
    line-height: 1.35;
}

.map-legend-row + .map-legend-row {
    margin-top: 0.3rem;
}

.map-legend-swatch {
    width: 0.85rem;
    height: 0.85rem;
    border: 1px solid var(--swatch-border);
    border-radius: 2px;
}

.map-legend-swatch.is-point {
    border-radius: 50%;
}

.layers-group + .layers-group {
    margin-top: 1.1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--panel-border);
}

.layers-group h3 {
    margin: 0 0 0.35rem;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.layers-group-hint {
    margin: 0 0 0.65rem;
    font-size: 0.73rem;
    color: var(--muted);
    line-height: 1.3;
}

.layers-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.layer-row {
    display: grid;
    grid-template-columns: 1rem 1fr auto;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.6rem;
    border-radius: 10px;
    background: var(--surface-raised);
    border: 1px solid transparent;
    min-height: 40px;
}

.layer-row.is-on {
    border-color: rgba(245, 158, 11, 0.25);
    background: rgba(245, 158, 11, 0.06);
}

.layer-swatch {
    width: 1rem;
    height: 1rem;
    border-radius: 4px;
    border: 1px solid var(--swatch-border);
    flex-shrink: 0;
}

.layer-label {
    font-size: 0.85rem;
    line-height: 1.25;
}

.layer-switch {
    position: relative;
    width: 2.5rem;
    height: 1.45rem;
    flex-shrink: 0;
}

.layer-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.layer-switch-slider {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: var(--switch-track-off);
    transition: background 0.15s ease;
    cursor: pointer;
}

.layer-switch-slider::before {
    content: "";
    position: absolute;
    width: 1.05rem;
    height: 1.05rem;
    left: 0.2rem;
    top: 0.2rem;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.15s ease;
}

.layer-switch input:checked + .layer-switch-slider {
    background: var(--accent);
}

.layer-switch input:checked + .layer-switch-slider::before {
    transform: translateX(1.05rem);
}

.layer-switch input:focus-visible + .layer-switch-slider {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.maplibregl-popup-content {
    background: var(--panel);
    color: var(--text);
}

.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--panel); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--panel); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--panel); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--panel); }
.maplibregl-popup-close-button { color: var(--text); }

.popup-title {
    margin: 0 0 0.35rem;
    font-weight: 700;
}

.popup-meta {
    margin: 0;
    font-size: 0.85rem;
    color: var(--muted);
    line-height: 1.45;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: flex-start;
    flex-shrink: 0;
    padding-top: 1rem;
}

.settings-header h2 {
    margin: 0;
    font-size: 1rem;
}

/* Pre-existing gap found during the theme/reorg visual pass: bare labels
   inside the Settings pane had no block-level styling, so consecutive
   <label> elements (State/region, Add a species) rendered inline on the
   same line instead of stacking. Matches .filters label's treatment. */
.settings-panel label:not(.settings-species-row) {
    display: grid;
    gap: 0.3rem;
    font-size: 0.8rem;
    color: var(--muted);
    margin: 0.5rem 0;
}

/* type="text" deliberately excluded — #invites-link-input is the only
   one in this panel and .invites-link-row input already styles it. */
.settings-panel select,
.settings-panel input[type="search"] {
    width: 100%;
    padding: 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    min-height: 44px;
}

.settings-subtitle,
.settings-summary,
.settings-untracked,
.settings-status {
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
    line-height: 1.4;
}

.settings-status.error {
    color: var(--danger);
}

.settings-status.success {
    color: var(--reviewed);
}

.settings-untracked {
    padding: 0.65rem 0.75rem;
    border-radius: 10px;
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.25);
    font-size: 0.78rem;
}

#settings-species-search {
    width: 100%;
    padding: 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    min-height: 44px;
}

.settings-species-search-results {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: 12rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.settings-species-search-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    background: var(--surface-raised);
    font-size: 0.85rem;
    cursor: pointer;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.settings-species-search-row:active {
    border-color: rgba(245, 158, 11, 0.45);
    background: var(--accent-soft);
}

.settings-species-search-row .add-label {
    flex: 0 0 auto;
    color: var(--accent);
    font-weight: 700;
    font-size: 0.72rem;
}

.settings-species-search-empty {
    margin: 0;
    padding: 0.5rem 0.1rem;
    font-size: 0.78rem;
    color: var(--muted);
}

.settings-species-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
    flex: 1;
    padding-right: 0.25rem;
}

.settings-species-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    background: var(--surface-raised);
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.settings-species-row:active {
    border-color: rgba(245, 158, 11, 0.45);
    background: var(--accent-soft);
}

.settings-species-row.active {
    border-color: rgba(245, 158, 11, 0.45);
    background: var(--accent-soft);
}

.settings-species-row span {
    flex: 1;
    font-size: 0.9rem;
}

.settings-species-row code {
    font-size: 0.72rem;
    color: var(--muted);
}

.settings-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.settings-actions button {
    flex: 1;
    min-width: 7rem;
    min-height: 44px;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: transparent;
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
    -webkit-tap-highlight-color: transparent;
}

.settings-actions button.primary {
    background: var(--accent);
    color: #111;
    border-color: var(--accent);
}

.settings-actions button:active {
    filter: brightness(0.9);
}

.theme-toggle {
    display: flex;
    gap: 0.4rem;
}

.theme-toggle-btn {
    flex: 1;
    min-height: 44px;
    padding: 0.5rem;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.theme-toggle-btn[aria-pressed="true"] {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: rgba(245, 158, 11, 0.35);
}

.invites-section {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding-top: 1rem;
    margin-top: 0.25rem;
    border-top: 1px solid var(--panel-border);
    flex-shrink: 0;
}

.invites-section h3 {
    margin: 0.4rem 0 0;
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#invites-generate-btn {
    min-height: 44px;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #111;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
}

#invites-generate-btn:active {
    filter: brightness(0.9);
}

.invites-link-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.invites-link-row input {
    flex: 1;
    min-width: 0;
    padding: 0.6rem 0.7rem;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.8rem;
}

.invites-link-row button {
    min-height: 40px;
    padding: 0 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 0.8rem;
}

.invites-expiry {
    flex: 0 0 100%;
    font-size: 0.72rem;
    color: var(--muted);
}

.invites-list {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    max-height: 8rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.invites-row {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: var(--surface-raised);
    font-size: 0.8rem;
}

.invites-meta {
    color: var(--muted);
    font-size: 0.72rem;
    white-space: nowrap;
}

.invites-empty {
    margin: 0;
    font-size: 0.78rem;
    color: var(--muted);
}

/* Tablet/iPad mini (768px and above) */
@media (min-width: 768px) {
    .layout {
        grid-template-columns: 380px 1fr;
        grid-template-rows: auto 1fr;
    }

    .map-panel {
        grid-column: 2;
        grid-row: 1 / -1;
    }

    .sidebar {
        grid-column: 1;
        grid-row: 1 / -1;
        border-right: 1px solid var(--panel-border);
        border-top: none;
        border-bottom: none;
        max-height: none;
    }

    .sidebar-header {
        padding: 1rem 1rem 0.75rem;
    }

    .pane-tabs {
        padding: 0 1rem 0.75rem;
        border-top: none;
    }

    .pane {
        padding: 0 1rem 1rem;
        gap: 1rem;
    }

    .filters {
        gap: 0.75rem;
    }

    .filters select,
    .filters input[type="search"] {
        font-size: 14px;
        min-height: auto;
    }

    .stat {
        padding: 0.75rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    .sidebar-header h1 {
        font-size: 1.35rem;
    }

    .map-status {
        top: 1rem;
        right: 1rem;
    }

    .popup-meta {
        font-size: 0.85rem;
    }
}

/* Large tablets and desktop (960px and above) */
@media (min-width: 960px) {
    .hosted-banner {
        padding: max(0.65rem, calc(0.65rem + var(--safe-top))) max(1rem, var(--safe-right)) 0.65rem max(1rem, var(--safe-left));
    }
}

/* Landscape mode optimizations */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar-header {
        padding-top: 0.75rem;
        padding-bottom: 0.5rem;
    }

    .pane {
        gap: 0.5rem;
        padding-bottom: 0.75rem;
    }

    .stats {
        gap: 0.35rem;
    }

    .stat {
        padding: 0.5rem;
    }

    .filters {
        gap: 0.5rem;
    }
}

/* Safari-specific fixes */
@supports (-webkit-touch-callout: none) {
    input,
    select,
    textarea,
    button {
        font-size: 16px !important;
    }
}
