:root {
    color-scheme: light dark;
    --bg: #ffffff;
    --fg: #1a1a1a;
    --muted: #555555;
    --border: #cccccc;
    --accent: #2b5aa0;
    --bg-panel: #f4f4f4;
    --bg-tab: #e8e8e8;
    --bg-surface: #ffffff;
    --error: #c62828;
    --warning: #e68a00;
    --info: #1565c0;
    --shadow: rgba(0, 0, 0, 0.25);
    --backdrop: rgba(0, 0, 0, 0.35);
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1e1e1e;
        --fg: #e0e0e0;
        --muted: #aaaaaa;
        --border: #444444;
        --accent: #6ea8fe;
        --bg-panel: #2a2a2a;
        --bg-tab: #333333;
        --bg-surface: #252525;
        --error: #ff6b6b;
        --warning: #ffb84d;
        --info: #6ea8fe;
        --shadow: rgba(0, 0, 0, 0.6);
        --backdrop: rgba(0, 0, 0, 0.55);
    }
}
* { box-sizing: border-box; }
html, body {
    margin: 0;
    height: 100%;
    font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--fg);
}
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}
.menu-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 8px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    align-items: center;
}
.menu-bar select, .menu-bar button {
    font-size: 13px;
}
.btn-icon {
    width: 16px;
    height: 16px;
    vertical-align: middle;
    margin-right: 3px;
}
.status {
    margin-left: auto;
    color: var(--muted);
    font-size: 12px;
}
.status + .status {
    margin-left: 12px;
}
.tab-bar {
    display: flex;
    gap: 2px;
    background: var(--bg-panel);
    padding: 4px 4px 0 4px;
    overflow-x: auto;
}
.tab {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    background: var(--bg-tab);
    color: var(--fg);
    cursor: pointer;
    white-space: nowrap;
}
.tab.selected {
    background: var(--bg-surface);
    font-weight: bold;
}
.tab .dirty::after {
    content: " *";
}
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-top: 1px solid var(--border);
}
.query-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px;
    border-bottom: 1px solid var(--border);
    align-items: center;
}
.query-bar input[type=text] {
    font-family: monospace;
}
#query-input {
    flex: 1 1 160px;
}
#timeout-input {
    width: 6em;
}
.split {
    flex: 1;
    display: flex;
    min-height: 0;
}
#editor {
    position: relative;
    flex: 1;
    font-family: "SFMono-Regular", Consolas, Menlo, monospace;
    font-size: 14px;
}
.split-handle {
    flex: 0 0 6px;
    cursor: col-resize;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    /* Without this, a touch-drag on the handle also scrolls/pans the page before pointermove ever fires. */
    touch-action: none;
}
.split-handle:hover, .split-handle.dragging {
    background: var(--accent);
}
.side {
    width: 40%;
    min-width: 320px;
    display: flex;
    flex-direction: column;
}
.side-tab-bar {
    display: flex;
    gap: 2px;
    background: var(--bg-panel);
    padding: 4px 4px 0 4px;
    flex-wrap: wrap;
}
.tab-icon {
    width: 14px;
    height: 14px;
    vertical-align: middle;
    margin-right: 3px;
}
.side-tab {
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    background: var(--bg-tab);
    color: var(--fg);
    cursor: pointer;
    font-size: 12px;
}
.side-tab.selected {
    background: var(--bg-surface);
    font-weight: bold;
}
.side-tab .unread::after {
    content: " \25CF";
    color: var(--accent);
}
.side-content {
    flex: 1;
    overflow: auto;
    padding: 6px;
    font-family: monospace;
    font-size: 12px;
    white-space: pre-wrap;
    color: var(--fg);
}
.side-content table {
    border-collapse: collapse;
    width: 100%;
}
.side-content th, .side-content td {
    border: 1px solid var(--border);
    padding: 2px 6px;
    text-align: left;
}
ul.solutions {
    list-style: none;
    margin: 0;
    padding: 0;
}
ul.solutions li {
    margin-bottom: 4px;
}
ul.solutions .query {
    font-weight: bold;
    cursor: pointer;
}
.diagnostic.ERROR { color: var(--error); }
.diagnostic.WARNING { color: var(--warning); }
.diagnostic.INFO { color: var(--info); }
.overlay-backdrop {
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.dialog {
    background: var(--bg-surface);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 12px;
    min-width: 320px;
    max-width: 80vw;
    max-height: 80vh;
    overflow: auto;
    box-shadow: 0 4px 16px var(--shadow);
}
.dialog .row {
    margin-bottom: 8px;
}
.dialog ul {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 240px;
    overflow: auto;
}
.dialog li {
    padding: 4px;
    cursor: pointer;
}
.dialog li:hover {
    background: var(--bg-panel);
}

/* Below this width, a 320px-min side panel next to the editor leaves neither one usable, so the side panel
   drops below the editor instead of beside it; dragging #split-handle to resize a *width* stops making sense
   in that layout, so it's hidden and the side panel gets a fixed, independently-scrollable height instead. */
@media (max-width: 820px) {
    .split {
        flex-direction: column;
    }
    #editor {
        min-height: 160px;
    }
    .split-handle {
        display: none;
    }
    .side {
        /* !important: overrides the inline px width the (desktop-only) drag handle may have left behind
           before the viewport shrank below this breakpoint. */
        width: 100% !important;
        min-width: 0;
        height: 40vh;
        border-top: 1px solid var(--border);
    }
    .dialog {
        min-width: 0;
        width: 92vw;
    }
}
