/* ============================================================
   SPATIAL SQL EXPLORER — style.css
   Dark industrial / terminal GIS aesthetic
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap');

/* ── Variables — dark (default) ─────────────────────────────── */
:root {
    --bg-base: #0b0f14;
    --bg-panel: #0f1419;
    --bg-elevated: #161d26;
    --bg-hover: #1d2733;
    --bg-active: #1a2535;

    --border: #1f2d3d;
    --border-bright: #2a3f57;

    --text-primary: #c9d4e0;
    --text-secondary: #6b8099;
    --text-dim: #3d5166;

    --accent: #f0a500;
    --accent-dim: #a87000;
    --accent-glow: rgba(240, 165, 0, 0.15);

    --success: #3ddc84;
    --error: #ff5a5a;
    --warning: #ffb347;

    --panel-left: 300px;
    --panel-right: 400px;

    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --font-ui: 'IBM Plex Sans', system-ui, sans-serif;

    --radius-sm: 4px;
    --radius: 6px;
    --radius-lg: 10px;

    --transition: 150ms ease;
}

/* ── Variables — light theme ────────────────────────────────── */
[data-theme="light"] {
    --bg-base: #f0f2f5;
    --bg-panel: #ffffff;
    --bg-elevated: #f7f8fa;
    --bg-hover: #ebedf2;
    --bg-active: #e0e4eb;

    --border: #d5dbe5;
    --border-bright: #b8c3d3;

    --text-primary: #1c2a3a;
    --text-secondary: #526580;
    --text-dim: #94a3b8;

    --accent: #c07800;
    --accent-dim: #a06200;
    --accent-glow: rgba(192, 120, 0, 0.10);

    --success: #1a8f54;
    --error: #c92a2a;
    --warning: #c07020;
}

/* ── Reset ──────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── App grid ───────────────────────────────────────────────── */
#app {
    display: grid;
    grid-template-columns: var(--panel-left) 4px 1fr 4px var(--panel-right);
    grid-template-rows: 100vh;
    height: 100vh;
    overflow: hidden;
}

/* ── Resize handles ─────────────────────────────────────────── */
.resize-handle {
    background: var(--border);
    cursor: col-resize;
    position: relative;
    z-index: 20;
    transition: background var(--transition);
    user-select: none;
}

.resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 32px;
    background: var(--border-bright);
    border-radius: 2px;
    transition: background var(--transition), height var(--transition);
}

.resize-handle:hover,
.resize-handle.dragging {
    background: var(--accent-glow);
}

.resize-handle:hover::after,
.resize-handle.dragging::after {
    background: var(--accent);
    height: 48px;
}

/* ── Scrollbars ─────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-bright);
    border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* ── Shared section label ───────────────────────────────────── */
.section-label {
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 10px;
    display: block;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.section-header .section-label {
    margin-bottom: 0;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-bright);
    background: var(--bg-elevated);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-dim);
    color: var(--accent);
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: #fffcf5;
    border-color: var(--accent);
    font-weight: 600;
    flex: 1;
    padding: 9px 16px;
    font-size: 12px;
    letter-spacing: 0.02em;
}

.btn-primary:hover {
    background: #fbb800;
    border-color: #fbb800;
    color: #fffcf5;
    box-shadow: 0 0 16px var(--accent-glow);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-sm {
    font-size: 11px;
    padding: 4px 9px;
}

.btn-export {
    font-size: 10px;
    padding: 4px 9px;
    background: var(--bg-elevated);
    border-color: var(--border);
    color: var(--text-secondary);
}

.btn-export:hover {
    color: var(--accent);
    border-color: var(--accent-dim);
}

/* icon-btn: small text button for secondary actions */
.icon-btn {
    font-family: var(--font-mono);
    font-size: 9px;
    padding: 3px 7px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.04em;
}

.icon-btn:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
    border-color: var(--border);
}

.icon-btn.danger:hover {
    color: var(--error);
    border-color: rgba(255, 90, 90, 0.3);
    background: rgba(255, 90, 90, 0.06);
}

.btn-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

/* ═══════════════════════════════════════════════════════════
   LEFT PANEL
   ═══════════════════════════════════════════════════════════ */
#panel-left {
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    overflow: hidden;
    z-index: 10;
}

/* ── App header ─────────────────────────────────────────────── */
#app-header {
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#app-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 3px;
}

#app-title {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    /* link reset — title is now an <a> tag */
    text-decoration: none;
    cursor: pointer;
}

#app-title:hover {
    opacity: 0.75;
}

#app-subtitle {
    font-size: 10px;
    color: var(--text-dim);
}

/* Theme toggle button */
#theme-toggle {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid var(--border-bright);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
    line-height: 1;
    padding: 0;
}

#theme-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--accent-dim);
    color: var(--accent);
    transform: rotate(20deg);
}

/* Light mode: CodeMirror chrome is handled by EditorView.theme() in JS */

/* Light mode: map legend card */
[data-theme="light"] #map-legend {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(0, 0, 0, 0.12);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Light mode: basemap switcher */
[data-theme="light"] #basemap-switcher {
    background: rgba(255, 255, 255, 0.92);
    border-color: var(--border-bright);
}

/* Light mode: share toast */
[data-theme="light"] .share-toast {
    background: #ffffff;
    border-color: var(--accent-dim);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

/* Light mode: map status bar */
[data-theme="light"] #map-statusbar {
    background: rgba(255, 255, 255, 0.9);
}

/* Light mode: map attribution */
[data-theme="light"] .maplibregl-ctrl-attrib {
    background: rgba(255, 255, 255, 0.85) !important;
}

/* Light mode: ghost overlays on graduated legend */
[data-theme="light"] .ml-ghost {
    background: rgba(255, 255, 255, 0.65);
}

/* Light mode: selection window border */
[data-theme="light"] .ml-sel-window {
    border-color: rgba(0, 0, 0, 0.6);
}

[data-theme="light"] .ml-sel-window:hover {
    border-color: rgba(0, 0, 0, 0.85);
}

/* Light mode: categorical row hover */
[data-theme="light"] .ml-cat-row:hover {
    background: rgba(0, 0, 0, 0.04);
}

/* Light mode: swatch borders */
[data-theme="light"] .ml-swatch,
[data-theme="light"] .legend-break-swatch,
[data-theme="light"] .legend-cat-swatch {
    border-color: rgba(0, 0, 0, 0.1);
}

/* Light mode: ramp swatch active border */
[data-theme="light"] .ramp-swatch.active {
    border-color: #1a2535;
}

/* Light mode: range selection overlay */
[data-theme="light"] .legend-range-selection {
    background: rgba(0, 0, 0, 0.12);
    border-color: rgba(0, 0, 0, 0.5);
}

/* Light mode: number cells in result table */
[data-theme="light"] #results-table tbody td.cell-number {
    color: #1565c0;
}

/* Light mode: active pills text (on accent bg) */
[data-theme="light"] .mode-pill.active,
[data-theme="light"] .basemap-pill.active {
    color: #1a1000;
}

/* Light mode: drag handle shadow */
[data-theme="light"] .ml-handle {
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
}

/* Light mode: range handle shadow */
[data-theme="light"] .legend-range-handle {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* ── Generic left section wrapper ───────────────────────────── */
.left-section {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

/* ── Table Registry ─────────────────────────────────────────── */
#section-registry {
    padding-bottom: 8px;
}

#table-registry {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 130px;
    overflow-y: auto;
}

.registry-empty {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-dim);
    padding: 4px 0;
}

.registry-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    transition: border-color var(--transition);
}

.registry-row:hover {
    border-color: var(--border-bright);
}

.registry-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.registry-name {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.registry-meta {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-dim);
}

.registry-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.reg-btn {
    font-size: 10px;
    width: 22px;
    height: 22px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-hover);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.reg-btn:hover {
    border-color: var(--border-bright);
}

.reg-btn.reg-query:hover {
    color: var(--success);
    border-color: var(--success);
}

.reg-btn.reg-delete:hover {
    color: var(--error);
    border-color: var(--error);
}

/* ── Data Source / Drop Zone ────────────────────────────────── */
#file-input {
    display: none;
}

#drop-zone {
    border: 1px dashed var(--border-bright);
    border-radius: var(--radius);
    padding: 10px 12px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

#drop-zone:hover,
#drop-zone.drag-over {
    border-color: var(--accent-dim);
    background: var(--accent-glow);
}

.drop-icon {
    font-size: 16px;
    opacity: 0.4;
}

.drop-main {
    font-size: 11px;
    color: var(--text-secondary);
}

.drop-formats {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-dim);
    letter-spacing: 0.04em;
}

/* ── SQL Editor ─────────────────────────────────────────────── */
#editor-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-bottom: 1px solid var(--border);
    min-height: 0;
}

#editor-label {
    padding: 8px 16px 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#editor-hint {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-dim);
}

#editor-wrapper {
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* CodeMirror — minimal chrome (EditorView.theme() in JS handles most styling) */
.cm-editor {
    height: 100%;
    font-size: 13px !important;
}

.cm-editor .cm-scroller {
    font-family: var(--font-mono) !important;
    overflow: auto;
}

.cm-editor.cm-focused {
    outline: none !important;
}

/* ── SQL Syntax Highlighting — Token Colors ────────────────────
   classHighlighter (from @lezer/highlight) maps Lezer syntax
   tokens to stable .tok-* CSS class names.
   Dark mode is the default; light mode overrides below.
   ────────────────────────────────────────────────────────────── */

/* ── Dark Theme (default) ── */
.tok-keyword {
    color: #f0a500 !important;
    font-weight: 600;
}

.tok-operator {
    color: #e06c75 !important;
}

.tok-string,
.tok-string2 {
    color: #98c379 !important;
}

.tok-number {
    color: #61afef !important;
}

.tok-comment {
    color: #5c6a7a !important;
    font-style: italic;
}

.tok-variableName {
    color: #c9d4e0 !important;
}

.tok-definition {
    color: #e5c07b !important;
}

.tok-typeName {
    color: #c678dd !important;
}

.tok-punctuation {
    color: #7a8899 !important;
}

.tok-bracket {
    color: #7a8899 !important;
}

.tok-bool,
.tok-atom {
    color: #d19a66 !important;
    font-weight: 600;
}

.tok-null {
    color: #d19a66 !important;
    font-style: italic;
}

.tok-meta {
    color: #e5c07b !important;
}

/* ── Light Theme ── */
[data-theme="light"] .tok-keyword {
    color: #9b5500 !important;
    font-weight: 600;
}

[data-theme="light"] .tok-operator {
    color: #c92a2a !important;
}

[data-theme="light"] .tok-string,
[data-theme="light"] .tok-string2 {
    color: #2e7d32 !important;
}

[data-theme="light"] .tok-number {
    color: #1565c0 !important;
}

[data-theme="light"] .tok-comment {
    color: #8a97a8 !important;
    font-style: italic;
}

[data-theme="light"] .tok-variableName {
    color: #1c2a3a !important;
}

[data-theme="light"] .tok-definition {
    color: #805500 !important;
}

[data-theme="light"] .tok-typeName {
    color: #7b1fa2 !important;
}

[data-theme="light"] .tok-punctuation,
[data-theme="light"] .tok-bracket {
    color: #526580 !important;
}

[data-theme="light"] .tok-bool,
[data-theme="light"] .tok-atom {
    color: #b35900 !important;
    font-weight: 600;
}

[data-theme="light"] .tok-null {
    color: #b35900 !important;
    font-style: italic;
}

[data-theme="light"] .tok-meta {
    color: #805500 !important;
}

/* ── Run Controls ───────────────────────────────────────────── */
#run-controls {
    padding: 10px 16px;
    display: flex;
    gap: 8px;
    align-items: center;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.cap-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-dim);
    white-space: nowrap;
}

#safety-cap-input {
    background: var(--bg-elevated);
    border: 1px solid var(--border-bright);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    width: 72px;
    text-align: right;
}

#safety-cap-input:focus {
    outline: none;
    border-color: var(--accent-dim);
}

/* ── Query History ──────────────────────────────────────────── */
#query-history {
    flex-shrink: 0;
    max-height: 150px;
    overflow-y: auto;
    padding: 10px 16px;
}

.history-item {
    padding: 6px 8px;
    border-left: 2px solid transparent;
    margin-bottom: 4px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    cursor: pointer;
    transition: all var(--transition);
}

.history-item:hover {
    background: var(--bg-hover);
    border-left-color: var(--accent-dim);
}

.history-item.success {
    border-left-color: var(--success);
}

.history-item.error {
    border-left-color: var(--error);
}

.history-status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 2px;
}

.history-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.history-dot.success {
    background: var(--success);
}

.history-dot.error {
    background: var(--error);
}

.history-timestamp {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-dim);
    margin-left: auto;
}

.history-preview {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Init Overlay ───────────────────────────────────────────── */
#init-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-base);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    gap: 16px;
    transition: opacity 0.4s ease;
}

#init-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.init-title {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.init-log {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
    max-width: 320px;
    line-height: 1.8;
}

.init-spinner {
    width: 28px;
    height: 28px;
    border: 2px solid var(--border-bright);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}


/* ═══════════════════════════════════════════════════════════
   CENTER PANEL — MAP
   ═══════════════════════════════════════════════════════════ */
#panel-map {
    position: relative;
    overflow: hidden;
    background: var(--bg-base);
}

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

.maplibregl-ctrl-attrib {
    background: rgba(11, 15, 20, 0.8) !important;
    color: var(--text-dim) !important;
    font-size: 9px !important;
}

.maplibregl-ctrl-attrib a {
    color: var(--text-dim) !important;
}

#map-statusbar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 5px 14px;
    background: rgba(11, 15, 20, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-dim);
    border-top: 1px solid var(--border);
    pointer-events: none;
}

#map-coords {
    color: var(--text-secondary);
}

#map-engine {
    color: var(--text-dim);
}


/* ═══════════════════════════════════════════════════════════
   RIGHT PANEL — OUTPUT
   ═══════════════════════════════════════════════════════════ */
#panel-right {
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    overflow: hidden;
    z-index: 10;
}

/* ── Output header ──────────────────────────────────────────── */
#output-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#output-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

#output-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 3px;
}

#output-meta {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-secondary);
}

#output-meta.has-geo::after {
    content: ' · geometry';
    color: var(--accent);
}

#export-btns {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}

/* ── Error banner ───────────────────────────────────────────── */
#error-banner {
    display: none;
    padding: 9px 16px;
    background: rgba(255, 90, 90, 0.08);
    border-bottom: 1px solid rgba(255, 90, 90, 0.2);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--error);
    word-break: break-word;
}

#error-banner.visible {
    display: block;
}

/* ── Loading indicator ──────────────────────────────────────── */
#query-loading {
    display: none;
    padding: 10px 16px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent);
    align-items: center;
    gap: 8px;
}

#query-loading.visible {
    display: flex;
}

.mini-spinner {
    width: 12px;
    height: 12px;
    border: 1.5px solid var(--border-bright);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

/* ── Style Panel ────────────────────────────────────────────── */
#style-panel {
    padding: 10px 16px 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg-base);
    max-height: 52vh;
    overflow-y: auto;
}

.style-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.style-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 9px;
    flex-wrap: wrap;
}

.style-label {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    width: 48px;
    flex-shrink: 0;
}

.style-select {
    flex: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border-bright);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 4px 7px;
    border-radius: var(--radius-sm);
    outline: none;
    cursor: pointer;
}

.style-select:focus {
    border-color: var(--accent-dim);
}

.style-select option {
    background: var(--bg-elevated);
}

/* Mode pills */
.mode-pills {
    display: flex;
    gap: 2px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-bright);
    border-radius: var(--radius-sm);
    padding: 2px;
    flex: 1;
}

.mode-pill {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 4px 6px;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.mode-pill:hover {
    color: var(--text-primary);
}

.mode-pill.active {
    background: var(--accent);
    color: #fffcf5;
    font-weight: 600;
}

/* Classification method pills */
.classify-pills {
    display: flex;
    gap: 2px;
    flex: 1;
}

.classify-pill {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 9px;
    padding: 4px 4px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-align: center;
}

.classify-pill:hover {
    border-color: var(--border-bright);
    color: var(--text-primary);
}

.classify-pill.active {
    border-color: var(--accent-dim);
    color: var(--accent);
    background: var(--accent-glow);
}

/* Class count buttons */
.class-count-btns {
    display: flex;
    gap: 3px;
}

.class-count-btn {
    width: 26px;
    height: 24px;
    font-family: var(--font-mono);
    font-size: 11px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.class-count-btn:hover {
    border-color: var(--border-bright);
    color: var(--text-primary);
}

.class-count-btn.active {
    border-color: var(--accent-dim);
    color: var(--accent);
    background: var(--accent-glow);
}

/* Ramp swatches */
#ramp-swatches {
    display: flex;
    gap: 4px;
    flex: 1;
}

.ramp-swatch {
    flex: 1;
    height: 16px;
    border-radius: 3px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color var(--transition), transform var(--transition);
}

.ramp-swatch:hover {
    transform: scaleY(1.25);
}

.ramp-swatch.active {
    border-color: white;
}

/* Single color picker */
.single-color-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-picker {
    width: 40px;
    height: 26px;
    border: 1px solid var(--border-bright);
    border-radius: 3px;
    background: transparent;
    cursor: pointer;
    padding: 1px;
}

.hex-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-secondary);
}

/* Opacity slider */
.opacity-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.opacity-slider {
    flex: 1;
    height: 4px;
    appearance: none;
    background: var(--border-bright);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.opacity-slider::-webkit-slider-thumb {
    appearance: none;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-panel);
}

.opacity-slider::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-panel);
}

.opacity-val {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-secondary);
    width: 32px;
    text-align: right;
    flex-shrink: 0;
}

/* ── Legend ─────────────────────────────────────────────────── */
#style-legend {
    padding: 6px 0 12px;
}

.legend-title {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-note-inline {
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-dim);
    opacity: 0.7;
}

.legend-reset {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--accent-dim);
    cursor: pointer;
    text-transform: none;
    letter-spacing: 0;
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 5px;
    transition: all var(--transition);
}

.legend-reset:hover {
    color: var(--accent);
    border-color: var(--accent-dim);
}

/* Graduated — gradient bar + breaks */
.legend-gradient-bar {
    height: 12px;
    border-radius: 3px;
    margin-bottom: 4px;
}

.legend-gradient-labels {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.legend-breaks {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.legend-break-row {
    display: flex;
    align-items: center;
    gap: 7px;
}

.legend-break-swatch {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.legend-break-label {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-secondary);
}

/* Categorical */
.legend-cat-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 180px;
    overflow-y: auto;
}

.legend-cat-row {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 3px 5px;
    border-radius: 3px;
    cursor: pointer;
    transition: background var(--transition);
    user-select: none;
}

.legend-cat-row:hover {
    background: var(--bg-hover);
}

.legend-cat-row.legend-hidden {
    opacity: 0.4;
}

.legend-cat-row.legend-hidden .legend-cat-label {
    text-decoration: line-through;
}

.legend-cat-swatch {
    width: 13px;
    height: 13px;
    border-radius: 2px;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: background 0.15s ease;
}

.legend-cat-label {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-secondary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.legend-cat-count {
    font-family: var(--font-mono);
    font-size: 8px;
    color: var(--text-dim);
    margin-left: auto;
    flex-shrink: 0;
}

.legend-note {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-dim);
    margin-top: 5px;
    padding-top: 5px;
    border-top: 1px solid var(--border);
}

/* ── Graduated range slider ─────────────────────────────────── */
.legend-range-wrap {
    position: relative;
    height: 20px;
    margin-bottom: 6px;
    cursor: default;
}

.legend-range-bar {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    right: 0;
    height: 10px;
    border-radius: 5px;
    pointer-events: none;
}

.legend-range-selection {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 10px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.25);
    pointer-events: none;
    border: 1.5px solid rgba(255, 255, 255, 0.7);
}

.legend-range-handle {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: white;
    border: 2px solid var(--accent);
    cursor: ew-resize;
    z-index: 2;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.legend-range-handle:hover {
    transform: translate(-50%, -50%) scale(1.2);
    box-shadow: 0 0 8px var(--accent-glow);
}

.legend-range-readout {
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding: 0 2px;
}

.range-val-min,
.range-val-max {
    background: var(--bg-elevated);
    border: 1px solid var(--border-bright);
    border-radius: 3px;
    padding: 2px 5px;
    color: var(--accent);
    font-weight: 600;
}

.range-val-sep {
    color: var(--text-dim);
}

/* ── Floating map legend card ───────────────────────────────── */
#map-legend {
    position: absolute;
    bottom: 36px;
    /* above status bar */
    left: 12px;
    z-index: 10;
    background: rgba(11, 15, 20, 0.92);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 1px 4px rgba(0, 0, 0, 0.4);
    min-width: 200px;
    max-width: 280px;
    padding: 12px 14px 10px;
    pointer-events: all;
    user-select: none;
}

#map-legend-inner {
    position: relative;
}

.map-legend-dismiss {
    position: absolute;
    top: -6px;
    right: -4px;
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: color var(--transition);
}

.map-legend-dismiss:hover {
    color: var(--text-primary);
}

/* Map legend shared elements */
.ml-header {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    padding-right: 16px;
    /* room for × */
}

.ml-title {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.04em;
}

.ml-subtitle {
    font-family: var(--font-mono);
    font-size: 8px;
    color: var(--text-dim);
    flex: 1;
}

.ml-reset {
    font-family: var(--font-mono);
    font-size: 8px;
    color: var(--accent-dim);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 2px 6px;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    margin-left: auto;
}

.ml-reset:hover {
    color: var(--accent);
    border-color: var(--accent-dim);
}

/* Categorical rows */
.ml-cat-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    max-height: 220px;
    overflow-y: auto;
    margin-bottom: 2px;
}

.ml-cat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 5px;
    border-radius: 3px;
    cursor: pointer;
    transition: background var(--transition), opacity var(--transition);
}

.ml-cat-row:hover {
    background: rgba(255, 255, 255, 0.06);
}

.ml-cat-row.ml-hidden {
    opacity: 0.35;
}

.ml-cat-row.ml-hidden .ml-label {
    text-decoration: line-through;
}

.ml-swatch {
    width: 13px;
    height: 13px;
    border-radius: 2px;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: background 0.15s;
}

.ml-label {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-secondary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ml-count {
    font-family: var(--font-mono);
    font-size: 8px;
    color: var(--text-dim);
    flex-shrink: 0;
}

.ml-note {
    font-family: var(--font-mono);
    font-size: 8px;
    color: var(--text-dim);
    margin-top: 6px;
    padding-top: 5px;
    border-top: 1px solid var(--border);
}

/* Graduated bar + ghost overlays */
.ml-bar-wrap {
    position: relative;
    height: 24px;
    margin-bottom: 6px;
}

.ml-grad-bar {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    right: 0;
    height: 12px;
    border-radius: 6px;
}

/* Ghost overlays — darken unselected portions */
.ml-ghost {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 12px;
    background: rgba(11, 15, 20, 0.62);
    pointer-events: none;
    z-index: 1;
}

.ml-ghost-left {
    left: 0;
    border-radius: 6px 0 0 6px;
}

.ml-ghost-right {
    right: 0;
    border-radius: 0 6px 6px 0;
}

/* Draggable selection window */
.ml-sel-window {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 4px;
    cursor: ew-resize;
    z-index: 2;
    box-sizing: border-box;
}

.ml-sel-window:hover {
    border-color: white;
}

/* Drag handles */
.ml-handle {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: white;
    border: 2.5px solid var(--accent);
    cursor: ew-resize;
    z-index: 3;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.6);
    transition: transform 0.1s, box-shadow 0.1s;
}

.ml-handle:hover {
    transform: translate(-50%, -50%) scale(1.25);
    box-shadow: 0 0 10px var(--accent-glow);
}

/* Readout */
.ml-readout {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 10px;
    font-family: var(--font-mono);
    font-size: 9px;
}

.ml-val {
    background: var(--bg-elevated);
    border: 1px solid var(--border-bright);
    border-radius: 3px;
    padding: 2px 6px;
    color: var(--accent);
    font-weight: 600;
}

.ml-val-sep {
    color: var(--text-dim);
}

/* Break rows under graduated */
.ml-breaks {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#basemap-switcher {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 10;
    display: flex;
    gap: 2px;
    background: rgba(11, 15, 20, 0.88);
    backdrop-filter: blur(6px);
    border: 1px solid var(--border-bright);
    border-radius: var(--radius);
    padding: 3px;
}

.basemap-pill {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 500;
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.03em;
}

.basemap-pill:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.basemap-pill.active {
    background: var(--accent);
    color: #fffcf5;
    font-weight: 700;
}

/* ── Map statusbar export PNG button ────────────────────────── */
#export-png-btn {
    font-family: var(--font-mono);
    font-size: 9px;
    padding: 3px 8px;
    border: 1px solid var(--border-bright);
    border-radius: 3px;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    pointer-events: all;
    margin-left: auto;
}

#export-png-btn:hover {
    color: var(--accent);
    border-color: var(--accent-dim);
}

/* ── Share toast notification ───────────────────────────────── */
.share-toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: var(--bg-elevated);
    border: 1px solid var(--accent-dim);
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 10px 20px;
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    max-width: 520px;
    text-align: center;
    line-height: 1.5;
}

.share-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#table-wrapper {
    flex: 1;
    overflow: auto;
}

#results-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 11px;
}

#results-table thead {
    position: sticky;
    top: 0;
    z-index: 5;
}

#results-table thead th {
    background: var(--bg-elevated);
    padding: 7px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 10px;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-bright);
    white-space: nowrap;
    text-transform: uppercase;
}

#results-table tbody tr {
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
}

#results-table tbody tr:hover {
    background: var(--bg-hover);
}

#results-table tbody td {
    padding: 6px 10px;
    color: var(--text-primary);
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#results-table tbody td.cell-number {
    color: #7ec8e3;
    text-align: right;
}

/* ── Checkbox column ────────────────────────────────────────── */
#results-table .col-check {
    width: 30px;
    min-width: 30px;
    text-align: center;
    padding: 5px 4px;
}

#results-table input[type="checkbox"] {
    width: 13px;
    height: 13px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ── Sortable column headers ────────────────────────────────── */
#results-table thead th.col-sortable {
    cursor: pointer;
    user-select: none;
}

#results-table thead th.col-sortable:hover {
    color: var(--accent);
    background: var(--bg-hover);
}

.sort-indicator {
    color: var(--accent);
    font-size: 9px;
}

/* ── Filter row ─────────────────────────────────────────────── */
#results-table thead tr.filter-row th {
    background: var(--bg-panel);
    padding: 4px 6px;
    border-bottom: 1px solid var(--border-bright);
}

.filter-input {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 3px 6px;
    outline: none;
    transition: border-color var(--transition);
}

.filter-input:focus {
    border-color: var(--accent-dim);
}

.filter-input::placeholder {
    color: var(--text-dim);
}

/* ── Selected rows ──────────────────────────────────────────── */
#results-table tbody tr.row-selected {
    background: rgba(240, 165, 0, 0.1) !important;
}

#results-table tbody tr.row-selected td {
    color: var(--accent) !important;
}

/* Light mode: selected row has warmer tone */
[data-theme="light"] #results-table tbody tr.row-selected {
    background: rgba(192, 120, 0, 0.08) !important;
}

/* ── Empty state ────────────────────────────────────────────── */
#empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 10px;
    color: var(--text-dim);
    padding: 40px;
    text-align: center;
}

#empty-state .empty-icon {
    font-size: 30px;
    opacity: 0.25;
}

#empty-state p {
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.7;
}

#empty-state strong {
    color: var(--text-secondary);
}


/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════ */

/* Light mode: MapLibre navigation controls */
[data-theme="light"] .maplibregl-ctrl-group {
    background: #ffffff !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12) !important;
}

[data-theme="light"] .maplibregl-ctrl-group button {
    background-color: #ffffff !important;
}

[data-theme="light"] .maplibregl-ctrl-group button+button {
    border-top-color: var(--border) !important;
}

/* Light mode: geocoder */
[data-theme="light"] .maplibregl-ctrl-geocoder {
    background: #ffffff !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12) !important;
}

[data-theme="light"] .maplibregl-ctrl-geocoder input {
    color: var(--text-primary) !important;
}

@media (max-width: 960px) {
    :root {
        --panel-left: 260px;
        --panel-right: 340px;
    }
}

@media (max-width: 700px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-rows: 100vh;
    }

    #panel-left,
    #panel-right,
    .resize-handle {
        display: none;
    }
}
