        :root {
            --app-height: 100dvh;
        }

        html, body {
            margin: 0;
            padding: 0;
            height: 100%;
            font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
            background: #f0f2f5;
            overflow: hidden;
        }

        #app {
            display: flex;
            height: var(--app-height);
            width: 100vw;
        }

        #sidebar {
            width: 360px;
            min-width: 240px;
            max-width: 800px;
            background: #ffffff;
            border-right: 1px solid #d0d0d0;
            box-shadow: 2px 0 4px rgba(0,0,0,0.08);
            box-sizing: border-box;
            padding: 10px 10px 12px 10px;
            display: flex;
            flex-direction: column;
            gap: 8px;
            overflow: hidden;
        }

        /* --- Vertical split inside sidebar (Query/Response vs Results) --- */
        #sidebarTop {
            flex: 0 0 auto;              /* height is controlled via flex-basis set in JS */
            min-height: 160px;
            display: flex;
            flex-direction: column;
            gap: 6px;
            overflow: hidden;            /* ensure inner flex children can shrink/grow */
        }

        #hDivider {
            height: 6px;
            cursor: row-resize;
            background: #e0e0e0;
            border-radius: 3px;
            touch-action: none;   /* enable dragging on touch */
            user-select: none;
        }

        #hDivider:hover {
            background: #c0c0c0;
        }

        #sidebarBottom {
            flex: 1 1 auto;
            min-height: 120px;
            display: flex;
            flex-direction: column;
            gap: 6px;
        }

        #divider {
            width: 5px;
            cursor: col-resize;
            background: #e0e0e0;
            touch-action: none;   /* enable dragging on touch */
            user-select: none;
        }

        #divider:hover {
            background: #c0c0c0;
        }

        #map {
            flex: 1;
            height: var(--app-height);
            min-width: 0;
            position: relative;
        }

        .maplibregl-canvas {
            filter: grayscale(30%);
        }

        .top-row {
            display: flex;
            align-items: center;
            flex-wrap: nowrap;
            gap: 6px;
            margin-bottom: 4px;
            overflow-x: auto;
            scrollbar-width: none;
        }

        .top-row::-webkit-scrollbar {
            display: none;
        }

        .btn-primary {
            padding: 5px 10px;
            border-radius: 7px;
            border: 1px solid #386dd8;
            background: linear-gradient(180deg, #5c89ea, #4472d6);
            color: #ffffff;
            font-size: 12px;
            font-weight: 600;
            cursor: pointer;
            min-height: 31px;
            box-shadow: 0 1px 2px rgba(30, 64, 175, 0.16);
            display: inline-flex;
            align-items: center;
            gap: 6px;
            white-space: nowrap;
        }

        .btn-primary:hover {
            background: linear-gradient(180deg, #668ff0, #4d79db);
        }

        .btn-secondary {
            padding: 5px 9px;
            border-radius: 7px;
            border: 1px solid #cfd6e2;
            background: linear-gradient(180deg, #ffffff, #f2f5f9);
            color: #3b4758;
            font-size: 11px;
            cursor: pointer;
            min-height: 31px;
            box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            white-space: nowrap;
        }

        .btn-secondary:hover {
            background: linear-gradient(180deg, #ffffff, #e9eef5);
        }

        .mobile-only {
            display: none;
        }

        .toggle-chip {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            padding: 5px 10px;
            border-radius: 999px;
            border: 1px solid #d6dce8;
            background: linear-gradient(180deg, #fafbfd, #eef2f7);
            color: #334155;
            font-size: 11px;
            cursor: pointer;
            box-shadow: 0 1px 2px rgba(15,23,42,0.06);
            user-select: none;
            min-height: 31px;
        }

        .toggle-chip:hover {
            background: linear-gradient(180deg, #f7f9fc, #e8edf4);
        }

        .toggle-chip .toggle-icon {
            font-size: 12px;
        }

        .toggle-chip .toggle-label {
            font-weight: 500;
        }

        .btn-icon {
            flex: 0 0 auto;
            font-size: 12px;
            line-height: 1;
        }

        .btn-label {
            flex: 0 1 auto;
        }

        .icon-only-btn {
            width: 31px;
            min-width: 31px;
            padding: 0;
            justify-content: center;
        }

        .toggle-chip.is-off {
            opacity: 0.68;
            background: #f6f7fa;
            border-color: #d8dde6;
        }

        .status-dot {
            flex: 0 0 auto;
            margin-left: auto;
            width: 14px;
            height: 14px;
            border-radius: 50%;
            border: 1px solid #000;
            background-color: red;
        }

        .status-dot.is-pending {
            background-color: #f59e0b !important;
            box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.55);
            animation: pending-pulse 1.2s ease-out infinite;
        }

        @keyframes pending-pulse {
            0% {
                box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.55);
            }
            100% {
                box-shadow: 0 0 0 10px rgba(245, 158, 11, 0);
            }
        }

        .field-label {
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: #666;
            margin-top: 4px;
        }

        .field-textarea {
            width: 100%;
            min-height: 80px;
            resize: vertical;
            border-radius: 4px;
            border: 1px solid #ccc;
            padding: 6px 8px;
            font-family: monospace;
            font-size: 12px;
            box-sizing: border-box;
        }

        #editor {
            min-height: 120px;
            flex: 1 1 auto;              /* grows/shrinks with sidebarTop */
            height: auto;
            resize: none;                /* let the splitter control height */
        }

        .translate-row {
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto auto;
            gap: 8px;
            align-items: start;
        }

        .translate-row .field-textarea {
            min-height: 56px;
        }

        .mic-btn.is-recording {
            border-color: #c45555;
            background: #fff1f1;
            color: #7d2424;
        }

        .mic-btn.is-unavailable {
            border-style: dashed;
            color: #6b7280;
        }

        .experimental-panel {
            display: grid;
            gap: 8px;
            padding: 8px;
            border: 1px solid #d6dbe6;
            border-radius: 8px;
            background: #f7f9fc;
        }

        .experimental-panel.is-collapsed {
            display: none;
        }

        .experimental-toggle {
            display: inline-flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
            width: 100%;
            padding: 7px 10px;
            border: 1px solid #cfd7e6;
            border-radius: 8px;
            background: #eef3fb;
            color: #30415f;
            font-size: 12px;
            cursor: pointer;
            text-align: left;
        }

        .experimental-toggle:hover {
            background: #e6edf8;
        }

        .experimental-toggle-title {
            font-weight: 600;
        }

        .experimental-toggle-subtitle {
            font-size: 11px;
            color: #60708f;
        }

        .experimental-toggle-icon {
            flex: 0 0 auto;
            font-size: 12px;
            color: #4b5d7f;
        }

        .translate-debug {
            display: none;
            gap: 6px;
            padding: 8px;
            border: 1px solid #e2d3b5;
            border-radius: 6px;
            background: #fff8ea;
            color: #6b4f1d;
            font-size: 12px;
        }

        .translate-debug.is-visible {
            display: grid;
        }

        .translate-debug-label {
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: #8a6a2c;
        }

        .translate-debug-query {
            margin: 0;
            white-space: pre-wrap;
            word-break: break-word;
            font-family: monospace;
            font-size: 12px;
            color: #4f3a12;
        }

        .parse-debug {
            display: none;
            gap: 6px;
            padding: 8px;
            border: 1px solid #e5c6c6;
            border-radius: 6px;
            background: #fff2f2;
            color: #7a2f2f;
            font-size: 12px;
        }

        .parse-debug.is-visible {
            display: grid;
        }

        .parse-debug-line {
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: #984848;
        }

        .parse-debug-source {
            margin: 0;
            white-space: pre-wrap;
            word-break: break-word;
            font-family: monospace;
            font-size: 12px;
            color: #612525;
        }

        .temporary-filter-banner {
            display: none;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
            padding: 6px 8px;
            border: 1px solid #d7dbe6;
            border-radius: 6px;
            background: #f3f5f9;
            color: #4a5568;
            font-size: 12px;
        }

        .temporary-filter-banner.is-visible {
            display: flex;
        }

        .temporary-filter-text {
            min-width: 0;
            flex: 1 1 auto;
        }

        .temporary-filter-chip {
            display: inline-flex;
            align-items: center;
            max-width: 100%;
            padding: 4px 10px;
            border-radius: 999px;
            background: #dfe6f3;
            color: #33425c;
            font-family: monospace;
            font-size: 12px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .temporary-filter-close {
            flex: 0 0 auto;
            width: 24px;
            height: 24px;
            border: 1px solid #c4cada;
            border-radius: 999px;
            background: #ffffff;
            color: #51607a;
            cursor: pointer;
            line-height: 1;
            font-size: 14px;
        }

        .temporary-filter-close:hover {
            background: #edf1f7;
        }

        #response {
            min-height: 28px;
            height: 28px;
            max-height: 28px;
            resize: none;
            flex: 0 0 auto;
        }
        
        .field-textarea[readonly] {
            background: #fafafa;
        }

        .results-list {
            width: 100%;
            flex: 1 1 auto;
            overflow-y: auto;
            border-radius: 4px;
            border: 1px solid #ccc;
            background: #ffffff;
            font-family: monospace;
            font-size: 12px;
        }

        .results-pager {
            margin-top: 4px;
            font-size: 11px;
            color: #555;
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
        }

        .results-pager button {
            padding: 2px 8px;
            font-size: 11px;
            border-radius: 3px;
            border: 1px solid #ccc;
            background: #f5f5f5;
            cursor: pointer;
        }

        .results-pager button:disabled {
            opacity: 0.5;
            cursor: default;
        }

        .results-list-row {
            display: grid;
            grid-template-columns: 48px 120px minmax(0, 1fr);
            align-items: center;
            padding: 2px 6px;
            cursor: pointer;
            column-gap: 8px;
            font-variant-numeric: tabular-nums;
            position: relative;
        }

        .results-list-row:nth-child(odd) {
            background: #ffffff;
        }

        .results-list-row:nth-child(even) {
            background: #d9e2f3;
        }

        .results-list-row:hover {
            background: #3874d9 !important;
            color: #ffffff;
        }

        .results-list-row span.result-col-num {
            text-align: right;
            color: #555;
            border-right: 1px solid #ccd3e0;
            padding-right: 6px;
        }

        .results-list-row span.result-col-id {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            font-family: monospace;
            border-right: 1px solid #ccd3e0;
            padding: 0 6px;
        }

        .results-list-row span.result-col-id.is-object-link {
            color: #1d4ed8;
            font-weight: 600;
            cursor: pointer;
        }

        .results-list-row:hover span.result-col-id.is-object-link {
            color: #ffffff;
            text-decoration: underline;
        }

        .results-list-row span.result-meta {
            font-size: 11px;
            color: #555;
            white-space: nowrap;
        }

        .results-list-row:hover span.result-meta {
            color: #e0e7ff;
        }

        .result-link {
            color: #1a73e8;
            text-decoration: none;
            font-weight: 500;
        }

        .results-list-row:hover .result-link {
            color: #ffffff;
            text-decoration: underline;
        }

        .count-result-row {
            position: relative;
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto;
            align-items: center;
            gap: 8px;
            padding: 8px 10px;
            border-bottom: 1px solid #e4e8f0;
            background: #ffffff;
        }

        .count-result-row:nth-child(even) {
            background: #f7f9fc;
        }

        .count-result-main {
            min-width: 0;
        }

        .count-result-filter {
            display: block;
            font-family: monospace;
            color: #22314a;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .count-result-count {
            display: block;
            margin-top: 2px;
            font-size: 11px;
            color: #69758a;
        }

        .count-mode-help {
            padding: 8px 10px;
            font-size: 11px;
            color: #64748b;
            background: #f4f7fb;
            border-bottom: 1px solid #e2e8f0;
        }

        .editor-help {
            font-size: 11px;
            color: #64748b;
            margin-top: -2px;
        }

        .results-help {
            font-size: 11px;
            color: #64748b;
            margin: -2px 0 4px;
        }

        .results-header-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
        }

        .results-download-btn {
            flex: 0 0 auto;
            min-height: 28px;
            padding: 4px 9px;
            font-size: 11px;
        }

        .count-result-actions {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            flex-wrap: nowrap;
            justify-content: flex-end;
        }

        .count-result-btn {
            min-width: 0;
            padding: 5px 7px;
            border-radius: 6px;
            border: 1px solid #cbd5e1;
            background: #ffffff;
            color: #334155;
            font-size: 11px;
            cursor: pointer;
            white-space: nowrap;
        }

        .count-result-btn:hover {
            background: #eef2f7;
        }

        .count-result-btn.is-primary {
            border-color: #90aee8;
            background: #dfeaff;
            color: #22417c;
        }

        .count-result-btn.is-primary:hover {
            background: #d3e2ff;
        }

        .count-style-popover {
            position: fixed;
            display: none;
            gap: 8px;
            width: 210px;
            padding: 10px;
            border: 1px solid #d5dbe7;
            border-radius: 10px;
            background: #ffffff;
            box-shadow: 0 12px 30px rgba(15,23,42,0.14);
            z-index: 30;
        }

        .count-style-popover.is-visible {
            display: grid;
        }

        .count-style-row {
            display: grid;
            gap: 4px;
        }

        .count-style-title {
            font-size: 12px;
            font-weight: 600;
            color: #334155;
        }

        .count-style-row label {
            font-size: 11px;
            color: #475569;
        }

        .count-style-row input[type="text"] {
            width: 100%;
            min-width: 0;
            padding: 6px 8px;
            border: 1px solid #cbd5e1;
            border-radius: 6px;
            font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
            font-size: 12px;
            box-sizing: border-box;
        }

        .count-style-inline {
            display: grid;
            grid-template-columns: 40px 1fr auto;
            gap: 8px;
            align-items: center;
        }

        .count-style-inline input[type="color"] {
            width: 40px;
            height: 30px;
            padding: 0;
            border: 1px solid #cbd5e1;
            border-radius: 6px;
            background: #fff;
        }

        .count-style-inline input[type="range"] {
            width: 100%;
        }

        .count-style-value {
            width: 34px;
            text-align: right;
            font-size: 11px;
            color: #475569;
            font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
        }

        .count-style-actions {
            display: flex;
            justify-content: flex-end;
            gap: 6px;
        }

        .col-resizer {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 5px;
            cursor: col-resize;
            background: transparent;
            z-index: 20;
        }

        #suggestBox {
            position: absolute;
            z-index: 20;
            display: none;
            background: #ffffff;
            border: 1px solid #aaa;
            font-family: monospace;
            font-size: 12px;
            max-height: 200px;
            overflow-y: auto;
            box-shadow: 0 2px 6px rgba(0,0,0,0.2);
        }

        #suggestBox div {
            padding: 2px 6px;
            cursor: pointer;
        }

        #suggestBox div.highlight {
            background: #3874d9;
            color: #ffffff;
        }

        #resultsSheetHeader {
            display: none;
        }

        #resultsSheetPeek {
            display: none;
        }

        .results-sheet-handle {
            width: 42px;
            height: 5px;
            border-radius: 999px;
            background: #cfd6e4;
            margin: 0 auto 8px;
        }

        .results-sheet-handle.flush {
            margin: 0;
        }

        #resultsSheetTitleRow {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
        }

        .field-label.tight {
            margin: 0;
        }

        #resultsSheetMeta {
            font-size: 12px;
            color: #667085;
        }

        .hidden-results-pane {
            display: none;
        }

        #zoomIndicator {
            position: absolute;
            bottom: 20px;
            left: 20px;
            padding: 6px 10px;
            background: rgba(0,0,0,0.6);
            color: white;
            border-radius: 4px;
            font-size: 12px;
            z-index: 100;
        }

        #versionBadge {
            position: absolute;
            right: 20px;
            bottom: 20px;
            padding: 6px 10px;
            background: rgba(255,255,255,0.92);
            color: #334155;
            border: 1px solid rgba(148,163,184,0.6);
            border-radius: 999px;
            font-size: 11px;
            font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
            z-index: 100;
            box-shadow: 0 4px 16px rgba(15,23,42,0.12);
        }

        #featureInfoPanel {
            position: absolute;
            top: 20px;
            right: 20px;
            min-width: 200px;
            max-width: 260px;
            padding: 10px 12px;
            background: white;
            border: 1px solid #d0d7e2;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(15,23,42,0.16);
            z-index: 120;
            display: none;
        }

        .popup-meta {
            font-size: 12px;
        }

        .feature-info-title {
            font-size: 14px;
            margin-bottom: 6px;
        }

        @media (max-width: 820px) {
            html, body {
                overflow: auto;
            }

            #app {
                flex-direction: column;
                height: auto;
                min-height: var(--app-height);
            }

            #sidebar {
                width: 100% !important;
                min-width: 0;
                max-width: none;
                border-right: 0;
                border-bottom: 1px solid #d0d0d0;
                box-shadow: 0 2px 10px rgba(0,0,0,0.08);
                padding:
                    max(10px, env(safe-area-inset-top))
                    max(10px, env(safe-area-inset-right))
                    10px
                    max(10px, env(safe-area-inset-left));
                gap: 10px;
                overflow: visible;
            }

            #sidebarTop {
                min-height: 0;
                flex-basis: auto !important;
            }

            body.mobile-query-collapsed #sidebarTop {
                display: none;
            }

            #sidebarBottom {
                position: fixed;
                left: max(8px, env(safe-area-inset-left));
                right: max(8px, env(safe-area-inset-right));
                bottom: calc(8px + env(safe-area-inset-bottom));
                min-height: 0;
                max-height: min(62dvh, 460px);
                background: rgba(255,255,255,0.98);
                border: 1px solid #d0d7e2;
                border-radius: 18px;
                box-shadow: 0 18px 48px rgba(15,23,42,0.22);
                padding: 10px 10px 12px;
                z-index: 80;
                transform: translateY(calc(100% - 58px));
                transition: transform 0.22s ease;
                backdrop-filter: blur(10px);
            }

            body.results-sheet-open #sidebarBottom {
                transform: translateY(0);
            }

            #resultsSheetHeader {
                display: block;
                padding-bottom: 8px;
                border-bottom: 1px solid #e5e7eb;
                margin-bottom: 8px;
            }

            #resultsSheetPeek {
                display: flex;
                align-items: center;
                justify-content: space-between;
                gap: 10px;
                min-height: 40px;
                cursor: pointer;
            }

            body.results-sheet-open #resultsSheetPeek {
                display: none;
            }

            #resultsSheetPeekText {
                font-size: 13px;
                font-weight: 600;
                color: #334155;
            }

            #resultsSheetCloseBtn {
                padding: 6px 10px;
                border-radius: 999px;
                border: 1px solid #cbd5e1;
                background: #f8fafc;
                color: #334155;
                font-size: 12px;
            }

            #divider,
            #hDivider,
            .col-resizer {
                display: none !important;
            }

            #map {
                height: min(56dvh, 520px);
                min-height: 320px;
            }

            .top-row {
                display: grid;
                grid-template-columns: repeat(2, minmax(0, 1fr));
                gap: 8px;
                margin-bottom: 0;
            }

            .top-row > * {
                min-width: 0;
            }

            #wsStatus {
                justify-self: end;
                align-self: center;
                margin-left: 0;
            }

            .btn-primary,
            .btn-secondary,
            .toggle-chip {
                justify-content: center;
                width: 100%;
            }

            .mobile-only {
                display: inline-flex;
            }

            .field-label {
                margin-top: 0;
            }

            .field-textarea {
                font-size: 16px;
            }

            #editor {
                min-height: 132px;
                max-height: 34dvh;
            }

            #response {
                min-height: 64px;
                height: 64px;
                max-height: 96px;
            }

            .results-list {
                min-height: 160px;
                max-height: min(36dvh, 280px);
            }

            .results-pager {
                gap: 10px;
                flex-wrap: wrap;
            }

            .results-pager button {
                min-height: 34px;
                padding: 6px 10px;
            }

            .results-list-row {
                grid-template-columns: 40px minmax(84px, 96px) minmax(0, 1fr);
                padding: 6px 8px;
            }

            .results-list-row span.result-col-id,
            .results-list-row span.result-meta {
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }

            #featureInfoPanel {
                top: auto !important;
                right: 10px !important;
                left: 10px !important;
                bottom: calc(74px + env(safe-area-inset-bottom)) !important;
                min-width: 0 !important;
                max-width: none !important;
                font-size: 14px !important;
            }

            #versionBadge {
                right: 10px;
                bottom: calc(10px + env(safe-area-inset-bottom));
                font-size: 10px;
                padding: 5px 8px;
            }
        }

        @media (max-width: 820px) and (orientation: landscape), (max-width: 900px) and (max-height: 520px) {
            #sidebar {
                padding:
                    max(6px, env(safe-area-inset-top))
                    max(8px, env(safe-area-inset-right))
                    6px
                    max(8px, env(safe-area-inset-left));
                gap: 6px;
            }

            .top-row {
                display: flex;
                flex-wrap: nowrap;
                overflow-x: auto;
                gap: 6px;
                padding-bottom: 2px;
                scrollbar-width: none;
            }

            .top-row::-webkit-scrollbar {
                display: none;
            }

            .top-row > * {
                flex: 0 0 auto;
            }

            .btn-primary,
            .btn-secondary,
            .toggle-chip {
                width: auto;
                min-height: 30px;
                padding: 5px 9px;
                font-size: 11px;
                white-space: nowrap;
            }

            #wsStatus {
                flex: 0 0 auto;
                justify-self: auto;
            }

            body.mobile-query-collapsed #sidebar {
                padding-bottom: 2px;
            }

            #map {
                height: min(66dvh, 360px);
                min-height: 220px;
            }

            #editor {
                min-height: 88px;
                max-height: 24dvh;
            }

            #response {
                min-height: 44px;
                height: 44px;
                max-height: 64px;
            }

            #sidebarBottom {
                max-height: min(70dvh, 320px);
            }

            .results-list {
                min-height: 110px;
                max-height: min(34dvh, 160px);
            }
        }

        @media (max-width: 480px) {
            #sidebar {
                padding:
                    max(8px, env(safe-area-inset-top))
                    max(8px, env(safe-area-inset-right))
                    8px
                    max(8px, env(safe-area-inset-left));
            }

            .top-row {
                grid-template-columns: 1fr 1fr;
            }

            .btn-primary,
            .toggle-chip {
                font-size: 12px;
            }

            #map {
                height: min(52dvh, 460px);
                min-height: 300px;
            }

            .results-list-row {
                grid-template-columns: 32px minmax(72px, 88px) minmax(0, 1fr);
                column-gap: 6px;
            }

            .results-list-row span.result-col-num,
            .results-list-row span.result-meta {
                font-size: 10px;
            }

            .translate-row {
                grid-template-columns: 1fr;
            }
        }
