/* ==========================================================================
   SQL Query Builder Pro Lite
   Colours are design tokens only; components never hard-code colours.
   Theme: [data-theme="light|dark"] forces a palette; without it the system
   preference (prefers-color-scheme) decides.
   ========================================================================== */

:root {
    color-scheme: light;
    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-2: #f0f3f7;
    --surface-3: #e4e9f0;
    --border: #d3dae3;
    --border-strong: #7b8696;
    --text: #17202b;
    --text-2: #3f4b5a;
    --text-muted: #56626f;
    --accent: #1d5fd6;
    --accent-hover: #174cad;
    --accent-soft: #e2ecfd;
    --on-accent: #ffffff;
    --danger: #b42318;
    --danger-soft: #fdecea;
    --warning: #7a4f00;
    --warning-soft: #fff4d6;
    --success: #16723a;
    --success-soft: #e3f5e9;
    --info-soft: #e8f0fb;
    --suggest: #6a2fc0;
    --suggest-soft: #f4eefd;
    --focus: #1d5fd6;
    --code-bg: #f7f9fc;
    --tok-keyword: #7a2fd0;
    --tok-string: #0f7a4c;
    --tok-number: #a84e00;
    --tok-operator: #b42318;
    --tok-func: #1d5fd6;
    --tok-identifier: #7a4f00;
    --tok-comment: #5f6b7b;
    --line-number: #7a8697;
    --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
    --shadow-lg: 0 12px 32px rgb(16 24 40 / 18%);
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Fira Code", Menlo, Consolas, monospace;
    --transition: 0.15s ease;
    /* Safe areas (notches, status bar, gesture bar). env() is the browser value;
       --safe-area-inset-* is injected by Capacitor on Android, where some WebView
       versions report 0 for env(). Both are 0 on ordinary desktop browsers. */
    --safe-top: max(env(safe-area-inset-top, 0px), var(--safe-area-inset-top, 0px));
    --safe-right: max(env(safe-area-inset-right, 0px), var(--safe-area-inset-right, 0px));
    --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--safe-area-inset-bottom, 0px));
    --safe-left: max(env(safe-area-inset-left, 0px), var(--safe-area-inset-left, 0px));
}

/* Dark palette: applied for the system preference unless light is forced… */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0e1117;
        --surface: #161b24;
        --surface-2: #1d2430;
        --surface-3: #283141;
        --border: #313b4c;
        --border-strong: #66728a;
        --text: #eef1f6;
        --text-2: #c8d0dc;
        --text-muted: #a3aebd;
        --accent: #6ea3ff;
        --accent-hover: #93bbff;
        --accent-soft: #1b2c4a;
        --on-accent: #0b1220;
        --danger: #ff8a80;
        --danger-soft: #3a1c1c;
        --warning: #f5c35b;
        --warning-soft: #362a10;
        --success: #6fd49a;
        --success-soft: #16301f;
        --info-soft: #1b2638;
        --suggest: #c7a2ff;
        --suggest-soft: #261e3a;
        --focus: #93bbff;
        --code-bg: #11151d;
        --tok-keyword: #c7a2ff;
        --tok-string: #7fd8a6;
        --tok-number: #ffb570;
        --tok-operator: #ff8a80;
        --tok-func: #8cb8ff;
        --tok-identifier: #f5c35b;
        --tok-comment: #8f9bac;
        --line-number: #6b7688;
        --shadow: 0 1px 2px rgb(0 0 0 / 40%);
        --shadow-lg: 0 12px 32px rgb(0 0 0 / 55%);
    }
}

/* …and whenever dark is chosen explicitly. Keep both blocks in sync. */
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0e1117;
    --surface: #161b24;
    --surface-2: #1d2430;
    --surface-3: #283141;
    --border: #313b4c;
    --border-strong: #66728a;
    --text: #eef1f6;
    --text-2: #c8d0dc;
    --text-muted: #a3aebd;
    --accent: #6ea3ff;
    --accent-hover: #93bbff;
    --accent-soft: #1b2c4a;
    --on-accent: #0b1220;
    --danger: #ff8a80;
    --danger-soft: #3a1c1c;
    --warning: #f5c35b;
    --warning-soft: #362a10;
    --success: #6fd49a;
    --success-soft: #16301f;
    --info-soft: #1b2638;
    --suggest: #c7a2ff;
    --suggest-soft: #261e3a;
    --focus: #93bbff;
    --code-bg: #11151d;
    --tok-keyword: #c7a2ff;
    --tok-string: #7fd8a6;
    --tok-number: #ffb570;
    --tok-operator: #ff8a80;
    --tok-func: #8cb8ff;
    --tok-identifier: #f5c35b;
    --tok-comment: #8f9bac;
    --line-number: #6b7688;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-lg: 0 12px 32px rgb(0 0 0 / 55%);
}

/* ---------------------------------------------------------------- base */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

h1, h2, h3, h4, p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

[hidden] { display: none !important; }

.skip-link {
    position: absolute;
    left: 1rem;
    top: -3rem;
    z-index: 100;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--on-accent);
    text-decoration: none;
}
.skip-link:focus { top: calc(1rem + var(--safe-top)); }

kbd {
    display: inline-block;
    min-width: 1.6em;
    padding: 0.05rem 0.4rem;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--surface-2);
    font-family: var(--font-mono);
    font-size: 0.8em;
    text-align: center;
}

/* -------------------------------------------------------------- layout */

.app {
    max-width: 1480px;
    margin: 0 auto;
    padding: calc(1rem + var(--safe-top)) calc(1rem + var(--safe-right)) calc(2rem + var(--safe-bottom)) calc(1rem + var(--safe-left));
}

.app-header {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 1rem;
}

.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-icon { width: 28px; height: 28px; color: var(--accent); flex-shrink: 0; }
.brand h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-weight: 500; color: var(--text-muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; }

.workspace {
    display: grid;
    gap: 1rem;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
}

.side { display: grid; gap: 1rem; min-width: 0; }

/* Two columns from tablet width, so the SQL sits beside the builder */
@media (min-width: 760px) {
    .workspace { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
    .side {
        position: sticky;
        top: calc(1rem + var(--safe-top));
        max-height: calc(100vh - 2rem - var(--safe-top) - var(--safe-bottom));
        overflow: auto;
        overscroll-behavior: contain;
        padding-right: 2px;
    }
}

.panel {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1rem;
}

.panel-header {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.panel-header h2 { font-size: 1.05rem; font-weight: 650; }

.app-footer {
    margin-top: 1.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
}

/* ------------------------------------------------------------- buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 2.25rem;
    padding: 0.4rem 0.85rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    font-size: 0.9rem;
    font-weight: 550;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color var(--transition), border-color var(--transition), color var(--transition);
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }

.btn-ghost { color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger); color: var(--surface); }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-soft); }

.btn-link { color: var(--accent); padding-inline: 0.25rem; min-height: auto; text-decoration: underline; }

.btn-sm { min-height: 2rem; padding: 0.25rem 0.6rem; font-size: 0.85rem; }

.btn-icon { width: 2.25rem; padding: 0; font-size: 1rem; }

.btn-copy { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.btn-copy:hover { border-color: var(--accent); }
.btn-copy.copied { background: var(--success-soft); color: var(--success); border-color: var(--success); }

/* --------------------------------------------------------------- menus */

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: "▾"; font-size: 0.75em; }

.menu-panel {
    position: absolute;
    right: 0;
    z-index: 20;
    display: grid;
    min-width: 14rem;
    margin-top: 0.25rem;
    padding: 0.35rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.menu-item {
    padding: 0.55rem 0.75rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    text-align: left;
    cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); }

/* ----------------------------------------------------------- type tabs */

.type-tabs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--surface-2);
    border-radius: var(--radius);
}

.type-tab { position: relative; }
.type-tab input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.type-tab span {
    display: block;
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 650;
    letter-spacing: 0.02em;
    color: var(--text-2);
}
.type-tab input:checked + span { background: var(--accent); color: var(--on-accent); }
.type-tab input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------- builder */

.builder { display: grid; gap: 0.75rem; }
.builder:focus { outline: none; }

.section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.section-summary {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.65rem 0.85rem;
    cursor: pointer;
    font-weight: 600;
    list-style: none;
    border-radius: var(--radius);
}
.section-summary::-webkit-details-marker { display: none; }
.section-summary::before {
    content: "▸";
    color: var(--text-muted);
    transition: transform var(--transition);
}
.section[open] > .section-summary::before { transform: rotate(90deg); }
.section-summary:hover { background: var(--surface-2); }

.section-body { display: grid; gap: 0.6rem; padding: 0 0.85rem 0.85rem; }
.section-description { color: var(--text-muted); font-size: 0.85rem; }

.badge {
    min-width: 1.4rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.75rem;
    text-align: center;
}

.sub-heading { font-size: 0.85rem; font-weight: 650; color: var(--text-2); }

.item-list { display: grid; gap: 0.5rem; margin: 0; padding: 0; list-style: none; }
/* Long option labels (e.g. in a UNION card's select) must not widen the page */
.item-list > li, .card > *, .select-editor > .section, .select-editor > .section-frame { min-width: 0; }
.card-header > .select { flex: 0 1 auto; min-width: 0; }

.row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    min-width: 0;
}

.row .grow { flex: 1 1 7rem; min-width: 0; }
.row .alias { flex: 0 1 7.5rem; min-width: 5rem; }
.row .alias-wide { flex: 1 1 9rem; }

.row-tools { display: flex; flex-wrap: nowrap; gap: 0.1rem; margin-left: auto; }
.row-tools .btn-icon { width: 2rem; }

/* Column rows: shrink the selects before the tools wrap onto their own line */
.column-row .select-narrow { min-width: 0; max-width: 9.5rem; }
.column-row .alias { flex-basis: 6.5rem; }

.card {
    display: grid;
    gap: 0.6rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
}

.card-header { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; justify-content: space-between; }
.card-header .field { flex: 1 1 12rem; }

.keyword {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 650;
    color: var(--tok-keyword);
}

.field { display: grid; gap: 0.3rem; min-width: 0; }
.field-row { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); }
.field-label { font-size: 0.85rem; font-weight: 600; color: var(--text-2); }
.required { color: var(--danger); }
.field-hint { font-size: 0.8rem; color: var(--text-muted); }
.field-error { font-size: 0.8rem; color: var(--danger); min-height: 1em; }

.input, .select {
    min-height: 2.25rem;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.input { width: 100%; font-family: var(--font-mono); font-size: 0.85rem; }
.row .input { width: auto; }
.input::placeholder { color: var(--text-muted); opacity: 0.85; }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.input:focus-visible, .select:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.select { max-width: 100%; }
.select-narrow { flex: 0 1 auto; }
.select-op { flex: 0 0 auto; font-family: var(--font-mono); font-size: 0.85rem; }

/* Invalid fields stay red even while focused */
.input.is-invalid, .select.is-invalid, .input.is-invalid:focus, .select.is-invalid:focus {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px var(--danger-soft);
}
.has-error { box-shadow: inset 3px 0 0 var(--danger); }

.check { display: inline-flex; gap: 0.45rem; align-items: center; cursor: pointer; }
.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
.check-block { align-items: flex-start; }
.check-block input { flex: none; margin-top: 0.2rem; }

.add-bar { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.add-bar .btn { color: var(--accent); }

.empty-hint { color: var(--text-muted); font-size: 0.85rem; }

.fieldset {
    display: grid;
    gap: 0.6rem;
    margin: 0;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.fieldset legend { padding: 0 0.3rem; font-weight: 650; }
.format-preview {
    margin: 0;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--code-bg);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.5;
    /* Wraps instead of scrolling, so the dialog never needs a sideways scroll */
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    tab-size: 4;
}

.dml-editor { display: grid; gap: 0.9rem; }
.dml-head { display: flex; gap: 0.5rem; align-items: center; justify-content: space-between; }
.dml-title { display: flex; flex-wrap: wrap; gap: 0 0.5rem; align-items: baseline; min-width: 0; }
.dml-tagline { color: var(--text-muted); font-size: 0.85rem; }

.callout {
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}
.callout-warning { background: var(--warning-soft); color: var(--warning); border-left: 4px solid var(--warning); }

/* conditions */

.cond-group { display: grid; gap: 0.5rem; }
.cond-group:not(.root) {
    padding: 0.6rem 0.6rem 0.6rem 0.75rem;
    border: 1px dashed var(--border-strong);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.cond-group-header { font-size: 0.85rem; color: var(--text-2); }
.cond-list { gap: 0.4rem; }
.cond-item { display: grid; gap: 0.25rem; }
.logic-label {
    justify-self: start;
    padding: 0 0.45rem;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
}
.condition { display: grid; gap: 0.5rem; }

.subquery {
    display: grid;
    gap: 0.5rem;
    padding: 0.6rem;
    border-left: 3px solid var(--tok-keyword);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.subquery-label { font-size: 0.8rem; font-weight: 650; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.select-editor { display: grid; gap: 0.6rem; min-width: 0; }
.select-editor.nested .section { background: var(--surface); }
.join-on { display: grid; gap: 0.35rem; }
.window-over {
    display: grid;
    gap: 0.4rem;
    padding: 0.6rem;
    border-left: 3px solid var(--tok-func);
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.source { min-width: 0; }

.builder-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.builder-actions .btn-primary { flex: 1 1 12rem; min-height: 2.6rem; font-size: 1rem; }

/* Two-column layout: Generate stays in view at the bottom of a long builder */
@media (min-width: 760px) {
    .builder-actions {
        position: sticky;
        bottom: 0;
        z-index: 5;
        margin-inline: -1rem;
        margin-bottom: -1rem;
        padding: 0.75rem 1rem calc(0.75rem + var(--safe-bottom));
        background: var(--surface);
        border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    }
}

/* ------------------------------------------------------- dialect picker */

.panel-title { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.dialect-picker { display: inline-flex; gap: 0.4rem; align-items: center; }
.dialect-picker-label { color: var(--text-muted); font-size: 0.8rem; font-weight: 600; }
.dialect-select {
    min-height: 2rem;
    padding: 0.2rem 0.5rem;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 600;
}
.dialect-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.dialect-select:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
@media (max-width: 719px) {
    .dialect-select { min-height: 2.5rem; }
}

.dialect-note { color: var(--text-muted); font-size: 0.85rem; }
.field-optional { color: var(--text-muted); font-weight: 400; }
.library-filter { display: inline-flex; gap: 0.4rem; align-items: center; margin-left: auto; color: var(--text-muted); font-size: 0.8rem; font-weight: 600; }
.select-sm { min-height: 2rem; padding: 0.2rem 0.4rem; font-size: 0.85rem; }
.library-snippet.example-sql {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.library-chip { padding: 0.05rem 0.45rem; border: 1px solid var(--border); border-radius: 999px; font-size: 0.75rem; }

/* -------------------------------------------------------------- output */

.output-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; }

.segmented {
    display: inline-flex;
    padding: 0.15rem;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.segment {
    min-height: 2rem;
    padding: 0.3rem 0.6rem;
    border: 0;
    border-radius: 5px;
    background: none;
    color: var(--text-2);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}
.segment[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.sql-output {
    margin: 0;
    max-height: 60vh;
    overflow: auto;
    padding: 0.9rem 1rem 0.9rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--code-bg);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.65;
    white-space: pre;
    tab-size: 4;
    counter-reset: line;
}
.sql-output code { font-family: inherit; }
.sql-output .line { counter-increment: line; }
.sql-output .line::before {
    content: counter(line);
    display: inline-block;
    width: 3.2em;
    padding-right: 1em;
    margin-right: 0.25em;
    color: var(--line-number);
    text-align: right;
    user-select: none;
    -webkit-user-select: none;
}

/* Wrap long lines (display only). Continuation lines start after the number. */
.sql-output.wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.sql-output.wrap .line { display: block; padding-left: 3.45em; text-indent: -3.45em; }

.tok-keyword { color: var(--tok-keyword); font-weight: 650; }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--tok-number); }
.tok-operator { color: var(--tok-operator); }
.tok-func { color: var(--tok-func); }
.tok-identifier { color: var(--tok-identifier); }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-param { color: var(--tok-number); font-weight: 650; }

.output-state:empty { display: none; }
.output-state { margin-bottom: 0.5rem; }
.output-note {
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    background: var(--info-soft);
    color: var(--text-2);
    font-size: 0.9rem;
}

.empty-state {
    display: grid;
    gap: 0.4rem;
    padding: 1.25rem;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    color: var(--text-muted);
    text-align: center;
    list-style: none;
}
.empty-title { color: var(--text); font-weight: 650; }
.empty-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; margin-top: 0.25rem; }

/* The saved template being edited, and Save */
.query-name-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.query-name { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; align-items: baseline; min-width: 0; font-size: 0.85rem; }
.query-name-text { font-weight: 650; overflow-wrap: anywhere; }
.query-name-text.muted { color: var(--text-muted); font-weight: 500; }
.query-name-state { color: var(--success); font-size: 0.8rem; }
.query-name-state.changed { color: var(--warning); }

/* Query structure: the clauses in processing order, each a jump into the builder */
.structure { margin-top: 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); }
.structure-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    min-height: 2.5rem;
    padding: 0.45rem 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    list-style: none;
}
.structure-summary::-webkit-details-marker { display: none; }
.structure-summary::before { content: "▸"; color: var(--text-muted); transition: transform var(--transition); }
.structure[open] > .structure-summary::before { transform: rotate(90deg); }
.structure-summary:hover { background: var(--surface-2); }
.structure-title { font-size: 0.85rem; font-weight: 650; }
.complexity { color: var(--text-muted); font-size: 0.8rem; }
.structure-insights {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0.5rem 0;
    padding: 0 0.75rem;
    list-style: none;
}
.insight {
    padding: 0.1rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 0.78rem;
}
.insight-band { font-weight: 650; color: var(--text); }
.structure-intro, .structure-notes { padding: 0 0.75rem; color: var(--text-muted); font-size: 0.8rem; }
.structure-notes:empty { display: none; }
.structure-steps { display: grid; gap: 0.15rem; margin: 0.4rem 0; padding: 0 0.4rem; list-style: none; }
.structure-step { padding: 0.15rem 0; }
.structure-jump {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.5rem;
    align-items: baseline;
    width: 100%;
    min-height: 2.25rem;
    padding: 0.35rem 0.4rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.structure-jump:hover { background: var(--surface-2); }
.structure-jump:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.structure-index {
    display: inline-grid;
    place-items: center;
    min-width: 1.35rem;
    height: 1.35rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
}
.structure-clause { font-family: var(--font-mono); font-size: 0.85rem; font-weight: 700; color: var(--tok-keyword); }
.structure-detail { color: var(--text-2); font-size: 0.85rem; overflow-wrap: anywhere; }
.structure-explain { margin: 0 0 0.2rem 2.25rem; color: var(--text-muted); font-size: 0.8rem; }
.structure-more { margin: 0.15rem 0 0.2rem 2.25rem; padding-left: 0.5rem; border-left: 2px solid var(--border); color: var(--text-2); font-size: 0.8rem; }
/* Tables and joins diagram (inside Query structure) */
.diagram { margin: 0.4rem 0.75rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.diagram-summary { display: flex; gap: 0.35rem; align-items: center; min-height: 2.5rem; padding: 0.35rem 0.6rem; font-size: 0.85rem; font-weight: 650; cursor: pointer; list-style: none; }
.diagram-summary::-webkit-details-marker { display: none; }
.diagram-summary::before { content: "▸"; color: var(--text-muted); transition: transform var(--transition); }
.diagram[open] > .diagram-summary::before { transform: rotate(90deg); }
.diagram-summary:hover { background: var(--surface-2); }
.diagram-intro { margin: 0 0 0.4rem; padding: 0 0.6rem; color: var(--text-muted); font-size: 0.8rem; }
.diagram-scroll { overflow-x: auto; padding: 0 0.6rem; }
.diagram-scroll:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.diagram-svg { display: block; margin: 0 auto; max-width: none; font-family: var(--font-mono); }
.diagram-node rect { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1; }
.diagram-known rect { stroke: var(--accent); }
.diagram-cte rect, .diagram-subquery rect { stroke-dasharray: 5 3; }
.diagram-title { fill: var(--text); font-size: 12px; font-weight: 700; }
.diagram-subtitle { fill: var(--text-muted); font-size: 11px; }
.diagram-column { fill: var(--text-2); font-size: 11px; }
.diagram-rule { stroke: var(--border); }
.flow-main rect { stroke: var(--accent); stroke-width: 2; }
.flow-cte rect { stroke-dasharray: 5 3; }
.diagram-edge path { fill: none; stroke: var(--text-muted); stroke-width: 1.5; }
.diagram-edge-fk path { stroke: var(--accent); }
.diagram-edge-many path { stroke: var(--warning); }
.diagram-edge-unlinked path { stroke-dasharray: 4 4; }
.diagram-arrow { fill: var(--text-muted); }
.diagram-label-bg { fill: var(--surface-2); stroke: var(--border); }
.diagram-label { fill: var(--text-2); font-size: 10.5px; }
.diagram-links { display: grid; gap: 0.15rem; margin: 0.4rem 0 0.5rem; padding: 0 0.4rem; list-style: none; }
.diagram-jump {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.35rem 0.4rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-2);
    font: inherit;
    font-size: 0.8rem;
    text-align: left;
    overflow-wrap: anywhere;
    cursor: pointer;
}
.diagram-jump:hover { background: var(--surface-2); }
.diagram-jump:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.structure-sentence { margin: 0.6rem 0 0; padding: 0 0.75rem; color: var(--text); font-size: 0.85rem; overflow-wrap: anywhere; }
.structure-levels { display: flex; flex-wrap: wrap; gap: 0.35rem 0.6rem; align-items: center; padding: 0 0.75rem; margin-bottom: 0.5rem; }
.structure-levels-label { color: var(--text-muted); font-size: 0.8rem; font-weight: 600; }

.issues { margin-top: 0.75rem; }
.issues-heading { font-size: 0.9rem; font-weight: 650; }
.issues-summary { font-weight: 500; color: var(--text-muted); }
.issues-list { display: grid; gap: 0.35rem; margin: 0.5rem 0 0; padding: 0; list-style: none; }
.issue {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.6rem;
    align-items: baseline;
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius-sm);
    border-left: 4px solid;
    font-size: 0.875rem;
}
.issue-message { flex: 1 1 14rem; }
.issue-level { font-size: 0.72rem; font-weight: 750; text-transform: uppercase; letter-spacing: 0.05em; }
.issue-error { background: var(--danger-soft); border-color: var(--danger); }
.issue-error .issue-level { color: var(--danger); }
.issue-warning { background: var(--warning-soft); border-color: var(--warning); }
.issue-warning .issue-level { color: var(--warning); }
.issue-suggestion { background: var(--suggest-soft); border-color: var(--suggest); }
.issue-suggestion .issue-level { color: var(--suggest); }
.issue-info { background: var(--info-soft); border-color: var(--accent); }
.issue-info .issue-level { color: var(--accent); }
.issue-safety { font-weight: 600; }

.security-note {
    margin-top: 0.9rem;
    padding: 0.6rem 0.75rem;
    border-left: 4px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 0.8rem;
}

/* ------------------------------------------------------------- library */

.tabs { display: flex; gap: 0.25rem; margin-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
.tabs [role="tab"] {
    padding: 0.5rem 0.75rem;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--text-2);
    font-weight: 600;
    cursor: pointer;
}
.tabs [role="tab"][aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
/* A narrow library panel (phones, tablets in two columns): the tabs share
   the row, and wrap onto a second row when they don't fit, so every tab
   stays in view. Browsers without container queries scroll the row. */
.library-panel { container: library / inline-size; }
.tabs { overflow-x: auto; scrollbar-width: none; }
@container library (max-width: 440px) {
    .tabs { gap: 0; flex-wrap: wrap; overflow-x: visible; }
    .tabs [role="tab"] { flex: 1 1 auto; min-width: 0; padding-inline: 0.2rem; font-size: 0.8rem; }
}
/* Too narrow for five tabs in a row: two even rows */
@container library (max-width: 340px) {
    .tabs { display: grid; grid-template-columns: repeat(3, 1fr); }
}
@container library (max-width: 300px) {
    .tabs [role="tab"] { font-size: 0.78rem; }
}

.tab-panel { display: grid; gap: 0.6rem; }
.library-toolbar { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.library-toolbar .input { flex: 1 1 10rem; width: auto; font-family: var(--font-sans); }
.library-toolbar-filters #template-search { flex-basis: 100%; }
.library-toolbar-filters .library-filter { flex: 1 1 11rem; min-width: 0; margin-left: 0; }
.tab-panel > * { min-width: 0; }
.library-toolbar-filters .library-filter select { flex: 1; min-width: 0; }
.library-pin { border-color: var(--accent); color: var(--accent); }
.library-current { border-color: var(--success); color: var(--success); }

.library-list { display: grid; gap: 0.5rem; margin: 0; padding: 0; list-style: none; max-height: 28rem; overflow: auto; }
.library-item {
    display: grid;
    gap: 0.35rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
}
.library-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; color: var(--text-muted); font-size: 0.8rem; }
.library-name { color: var(--text); font-size: 0.9rem; }
.library-detail { color: var(--text-muted); font-size: 0.8rem; }
.library-snippet {
    margin: 0;
    overflow: hidden;
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    white-space: pre-wrap;
    word-break: break-word;
}
.library-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; }

/* Schema panel */
.schema-details > summary { cursor: pointer; color: var(--text-2); font-size: 0.8rem; width: fit-content; }
.schema-columns { display: grid; gap: 0.2rem; margin: 0.4rem 0 0; padding: 0; list-style: none; }
.schema-column { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; align-items: baseline; font-size: 0.8rem; }
.schema-column-name { font-family: var(--font-mono); color: var(--text); overflow-wrap: anywhere; }
.schema-column-type { font-family: var(--font-mono); color: var(--text-muted); overflow-wrap: anywhere; }
.schema-column-note { color: var(--text-muted); }
.schema-key { border-color: var(--accent); color: var(--accent); }
.schema-import-result { display: grid; gap: 0.35rem; font-size: 0.85rem; }
.schema-import-result p { margin: 0; }
.schema-import-problems { margin: 0; padding-left: 1.2rem; color: var(--danger); font-size: 0.8rem; }
.sql-import-result { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.35rem; font-size: 0.85rem; }
.sql-import-result p { margin: 0; }
.sql-import-ok { font-weight: 600; color: var(--success); }
.sql-import-differences { margin: 0; padding-left: 1.2rem; font-size: 0.8rem; overflow-wrap: anywhere; }
.sql-import-sql summary { cursor: pointer; color: var(--text-muted); font-size: 0.8rem; }
.sql-import-sql pre { margin: 0.35rem 0 0; max-height: 14rem; overflow: auto; padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-family: var(--font-mono); font-size: 0.78rem; white-space: pre; }
.compare-result { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.5rem; font-size: 0.85rem; }
.compare-result p { margin: 0; }
.compare-same { font-weight: 600; color: var(--success); }
.compare-differences, .compare-checks { margin: 0; padding-left: 1.2rem; font-size: 0.8rem; overflow-wrap: anywhere; }
.compare-level { font-weight: 650; }
.compare-error .compare-level { color: var(--danger); }
.compare-warning .compare-level { color: var(--warning); }
.compare-panes { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); gap: 0.75rem; }
.compare-pane { min-width: 0; }
.compare-pane-title { margin: 0 0 0.3rem; font-size: 0.8rem; font-weight: 650; color: var(--text-2); }
.compare-pane pre { margin: 0; max-height: 18rem; overflow: auto; padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-family: var(--font-mono); font-size: 0.78rem; white-space: pre; }
.sql-import-note { margin: 0; font-size: 0.8rem; color: var(--text-muted); }
.textarea { min-height: 8rem; resize: vertical; line-height: 1.45; white-space: pre; overflow-wrap: normal; overflow-x: auto; }

.type-badge {
    padding: 0.05rem 0.45rem;
    border-radius: 4px;
    background: var(--accent-soft);
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
}
.type-badge.type-update, .type-badge.type-delete { background: var(--warning-soft); color: var(--warning); }
.type-badge.type-insert { background: var(--success-soft); color: var(--success); }

/* ------------------------------------------------------------- dialogs */

.dialog {
    width: min(34rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem - var(--safe-top) - var(--safe-bottom));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
}
.dialog-sm { width: min(26rem, calc(100vw - 2rem)); }
.dialog-wide { width: min(60rem, calc(100vw - 2rem)); }
.dialog::backdrop { background: rgb(8 12 20 / 55%); }
.dialog-body { display: grid; gap: 0.9rem; padding: 1.25rem; }
.dialog-title { font-size: 1.1rem; }
.dialog-message { color: var(--text-2); }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: flex-end; }

/* Command palette: sits near the top like other palettes, list scrolls */
.palette { margin-top: max(8vh, calc(1rem + var(--safe-top))); }
.palette-body { gap: 0.6rem; padding: 0.9rem; }
.palette-list { display: grid; gap: 1px; max-height: min(22rem, 55vh); margin: 0; padding: 0; overflow: auto; list-style: none; }
.palette-option {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    min-height: 2.5rem;
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius);
    cursor: pointer;
}
.palette-option:hover { background: var(--surface-2); }
.palette-option[aria-selected="true"] { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.palette-label { flex: 1; min-width: 0; font-weight: 600; }
.palette-group { color: var(--text-muted); font-size: 0.8rem; }
.palette-keys { display: flex; gap: 0.2rem; }

/* JOIN assistant: suggested ON conditions */
.join-hint { display: flex; flex-wrap: wrap; gap: 0.35rem 0.5rem; align-items: center; margin: 0 0 0.5rem; padding: 0.5rem 0.6rem; border: 1px dashed var(--border); border-radius: var(--radius); }
.join-hint[hidden] { display: none; }
.join-hint-text { flex: 1 1 100%; margin: 0; color: var(--text-2); font-size: 0.85rem; }
.join-hint-use { max-width: 100%; white-space: normal; text-align: left; }
.join-hint-use code { font-family: var(--font-mono); font-size: 0.8rem; overflow-wrap: anywhere; }

/* Suggestions under builder fields */
.suggest-list {
    position: fixed;
    z-index: 50;
    display: grid;
    gap: 1px;
    width: max-content;
    max-width: min(28rem, calc(100vw - 16px));
    max-height: 20rem;
    margin: 0;
    padding: 0.25rem;
    overflow: auto;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overscroll-behavior: contain;
}
.suggest-list[hidden] { display: none; }
.suggest-option {
    display: flex;
    gap: 0.75rem;
    align-items: baseline;
    justify-content: space-between;
    min-height: 2.25rem;
    padding: 0.35rem 0.55rem;
    border-radius: var(--radius);
    cursor: pointer;
}
.suggest-option:hover { background: var(--surface-2); }
.suggest-option[aria-selected="true"] { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.suggest-label { min-width: 0; font-family: var(--font-mono); font-size: 0.85rem; overflow-wrap: anywhere; }
.suggest-detail { flex-shrink: 0; max-width: 45%; color: var(--text-muted); font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-option[data-kind="function"] .suggest-detail, .suggest-option[data-kind="alias"] .suggest-detail { font-style: italic; }
.palette-empty { padding: 0.6rem; color: var(--text-muted); }
.palette-hint { margin: 0; }
@media (max-width: 480px) {
    .palette-keys, .palette-hint { display: none; }
}

.shortcut-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.shortcut-table th, .shortcut-table td { padding: 0.4rem 0.25rem; border-bottom: 1px solid var(--border); text-align: left; }
.shortcut-table th { color: var(--text-muted); font-size: 0.8rem; font-weight: 600; }

/* --------------------------------------------------------------- toast */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(1.25rem + var(--safe-bottom));
    z-index: 60;
    max-width: min(32rem, calc(100vw - 2rem));
    padding: 0.65rem 1rem;
    border-radius: var(--radius);
    background: var(--text);
    color: var(--bg);
    box-shadow: var(--shadow-lg);
    font-size: 0.9rem;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 0.5rem);
    transition: opacity var(--transition), transform var(--transition);
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: var(--danger); color: var(--surface); }
.toast[data-kind="success"] { background: var(--success); color: var(--surface); }
.toast[data-kind="warning"] { background: var(--warning); color: var(--surface); }

/* ---------------------------------------------------------- mobile bar */

.mobile-bar { display: none; }

.status-badge {
    min-width: 1.35rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: var(--warning);
    color: var(--surface);
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.35rem;
    text-align: center;
}
.status-badge[data-level="error"] { background: var(--danger); }

.output-panel:focus { outline: none; }

/* Below the two-column layout the SQL sits under the builder, so phones
   and narrow windows get a fixed bar with the main actions. */
@media (max-width: 759px) {
    .app { padding-bottom: calc(6rem + var(--safe-bottom)); }
    .toast { bottom: calc(5.5rem + var(--safe-bottom)); }
    .output-panel { scroll-margin-top: calc(0.75rem + var(--safe-top)); }

    .mobile-bar {
        position: fixed;
        inset: auto 0 0 0;
        z-index: 40;
        display: grid;
        grid-template-columns: 2fr 1fr 1fr;
        gap: 0.5rem;
        padding: 0.6rem calc(0.75rem + var(--safe-right)) calc(0.6rem + var(--safe-bottom)) calc(0.75rem + var(--safe-left));
        background: var(--surface);
        border-top: 1px solid var(--border);
        box-shadow: var(--shadow-lg);
    }
    .mobile-bar .btn { min-height: 2.75rem; }
}

@media (max-width: 719px) {
    body { font-size: 16px; } /* 16px inputs prevent iOS zoom on focus */
    .app { padding: calc(0.75rem + var(--safe-top)) calc(0.75rem + var(--safe-right)) calc(6rem + var(--safe-bottom)) calc(0.75rem + var(--safe-left)); }
    .brand h1 { font-size: 1.1rem; }
    .panel { padding: 0.75rem; border-radius: var(--radius); }
    .type-tabs { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; }
    .type-tab span { padding-inline: 0.25rem; text-align: center; }
    .input, .select { min-height: 2.6rem; font-size: 16px; }
    .row .alias { flex: 1 1 8rem; }
    .row-tools { margin-left: 0; }
    .btn-icon { width: 2.6rem; min-height: 2.6rem; }
    .check input { width: 1.35rem; height: 1.35rem; }
    .builder-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .builder-actions .btn-primary { grid-column: 1 / -1; }
    .output-actions { width: 100%; }
    .sql-output { font-size: 0.8rem; max-height: none; }
    .segment { min-height: 2.5rem; padding-inline: 0.75rem; }
    /* Theme lives in Settings, and shortcuts need a keyboard: one toolbar row */
    #theme-btn, #shortcuts-btn { display: none; }
    .row-tools .btn-icon { width: 2.6rem; }
    .column-row .select-narrow { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

@media print {
    .toolbar, .builder-panel, .library-panel, .mobile-bar, .output-actions, .toast { display: none !important; }
    .sql-output { max-height: none; border: 0; }
}

/* ------------------------------------------------------------- SQL Lab */

.view-switch { margin-right: 0.25rem; }
.view-switch .segment { font-size: 0.85rem; }

.lab-header { align-items: flex-start; }
.lab-title { display: grid; gap: 0.2rem; min-width: 0; }
.lab-title h2:focus { outline: none; }
.lab-engine { color: var(--text-muted); font-size: 0.85rem; }
.lab-subheading { font-size: 0.85rem; font-weight: 650; color: var(--text-2); }
.lab-notice {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    align-items: center;
    margin-bottom: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}
.lab-notice p { flex: 1 1 18rem; }
.lab-notice-warning { background: var(--warning-soft); color: var(--warning); border-left: 4px solid var(--warning); }
.lab-notice-error { background: var(--danger-soft); color: var(--text); border-left: 4px solid var(--danger); }
.lab-notice[hidden] { display: none; }

.lab-body { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 760px) {
    .lab-body { grid-template-columns: minmax(14rem, 20rem) minmax(0, 1fr); }
}

.lab-explorer {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-width: 0;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
}
.lab-explorer-head { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; justify-content: space-between; }

/* The tree, like SSMS's Object Explorer, scrolls on its own */
.lab-tree {
    min-height: 0;
    max-height: min(32rem, 60vh);
    margin: 0 -0.35rem;
    padding: 0.25rem 0.35rem;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong, var(--text-muted)) transparent;
    scrollbar-gutter: stable;
    border-top: 1px solid var(--border);
}
.lab-tree::-webkit-scrollbar { width: 10px; height: 10px; }
.lab-tree::-webkit-scrollbar-thumb { background: var(--border-strong, var(--text-muted)); border: 2px solid var(--surface-2); border-radius: 999px; }
.lab-tree::-webkit-scrollbar-track { background: transparent; }
@media (min-width: 760px) {
    /* Beside the editor: as tall as the window allows, and it stays in view */
    .lab-explorer { position: sticky; top: 0.75rem; max-height: calc(100dvh - 1.5rem); }
    .lab-tree { flex: 1 1 auto; max-height: none; }
}
.lab-db-list, .lab-children { display: grid; margin: 0; padding: 0; list-style: none; }
/* Names stay on one line, as in SSMS; a long one scrolls the tree sideways */
.lab-db-list, .lab-tree > .lab-objects { width: max-content; min-width: 100%; }
.lab-children { position: relative; margin-left: 0.7rem; padding-left: 0.55rem; }
/* Guide lines, as in a tree view */
.lab-children::before { content: ""; position: absolute; top: 0; bottom: 0.9rem; left: 0; border-left: 1px dotted var(--text-muted); opacity: 0.6; }
.lab-children > .lab-node > .lab-row::before { content: ""; position: absolute; left: -0.55rem; top: 50%; width: 0.45rem; border-top: 1px dotted var(--text-muted); opacity: 0.6; }
.lab-objects:empty { display: none; }
.lab-row { position: relative; display: flex; align-items: center; gap: 0.1rem; min-height: 1.85rem; min-width: 0; }
.lab-twisty {
    flex: 0 0 auto;
    display: inline-grid;
    place-items: center;
    width: 1.35rem;
    height: 1.35rem;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
    cursor: pointer;
}
.lab-twisty::before { content: ""; width: 0.4rem; height: 0.4rem; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform 0.12s ease; }
.lab-twisty[aria-expanded="true"]::before { transform: rotate(45deg) translate(-0.1rem, -0.1rem); }
.lab-twisty.is-leaf::before { content: none; }
.lab-twisty:not(.is-leaf):hover { background: var(--surface); color: var(--text); }
.lab-twisty:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; }
.lab-twisty:disabled { cursor: progress; }
.lab-db-btn, .lab-object-btn {
    display: flex;
    flex: 1 1 auto;
    gap: 0.4rem;
    align-items: center;
    min-width: 0;
    min-height: 1.85rem;
    padding: 0.15rem 0.4rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.lab-db-btn:hover, .lab-object-btn:hover { background: var(--surface); }
.lab-db-btn:focus-visible, .lab-object-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; }
.lab-db-btn[aria-current="true"], .lab-object-btn[aria-current="true"] { background: var(--accent-soft, var(--surface)); border-color: var(--accent); }
.lab-db-btn:disabled, .lab-object-btn:disabled { cursor: progress; }
.lab-db-name { font-weight: 650; white-space: nowrap; }
.lab-db-meta { margin-left: auto; padding-left: 0.4rem; color: var(--text-muted); font-size: 0.75rem; white-space: nowrap; }
.lab-object-name { font-family: var(--font-mono); font-size: 0.85rem; white-space: nowrap; }
.lab-folder-label, .lab-leaf-label { display: flex; gap: 0 0.4rem; white-space: nowrap; align-items: center; min-width: 0; padding: 0.15rem 0.4rem; font-size: 0.875rem; }
.lab-folder-label { color: var(--text-2); font-weight: 600; cursor: pointer; user-select: none; }
.lab-leaf-label { font-size: 0.82rem; }
.lab-column-name { font-family: var(--font-mono); }
.lab-column-detail { color: var(--text-muted); font-size: 0.78rem; }
.lab-icon { flex: 0 0 auto; width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.25; stroke-linecap: round; stroke-linejoin: round; }
.lab-icon-database { color: #6b8fb8; }
.lab-icon-folder { color: #c9962e; fill: color-mix(in srgb, #e6b54a 35%, transparent); }
.lab-icon-table, .lab-icon-view { color: #4a8fd4; }
.lab-icon-column { color: var(--text-muted); }
.lab-icon-key { color: #c9a227; }
.lab-icon-link { color: #8a7fd0; }
.lab-empty-hint { color: var(--text-muted); font-size: 0.85rem; }

.lab-main { display: grid; gap: 0.75rem; min-width: 0; }
.lab-main-head { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; justify-content: space-between; }
.lab-db-title { font-size: 1rem; font-weight: 650; overflow-wrap: anywhere; }
.lab-db-title:focus, .lab-main .empty-title:focus { outline: none; }
.lab-main-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; }

.lab-structure { display: grid; gap: 0.6rem; }
.lab-structure-head { display: flex; flex-wrap: wrap; gap: 0.4rem 0.6rem; align-items: baseline; }
.lab-structure-title { font-family: var(--font-mono); font-size: 0.95rem; overflow-wrap: anywhere; }
.lab-structure-rows { color: var(--text-muted); font-size: 0.85rem; }
.lab-table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.lab-table-scroll:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.lab-columns { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.lab-columns th, .lab-columns td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; white-space: nowrap; }
.lab-columns thead th { background: var(--surface-2); color: var(--text-2); font-size: 0.8rem; font-weight: 650; }
.lab-columns tbody th { font-family: var(--font-mono); font-weight: 600; }
.lab-columns tbody tr:last-child > * { border-bottom: 0; }
.lab-columns .muted { color: var(--text-muted); }
.lab-create-sql > summary { min-height: 2.25rem; padding: 0.35rem 0; font-size: 0.85rem; font-weight: 650; cursor: pointer; }
.lab-create-sql .sql-output { max-height: 20rem; }

.lab-note { margin-top: 1rem; color: var(--text-muted); font-size: 0.8rem; }

/* Create tables in SQL Lab */
.lab-check-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-bottom: 0.25rem; }
.lab-check-list { display: grid; gap: 0.3rem; max-height: 14rem; overflow: auto; margin: 0; padding: 0; list-style: none; }
.lab-check-name { font-family: var(--font-mono); font-size: 0.85rem; overflow-wrap: anywhere; }
.lab-check-state { color: var(--text-muted); font-size: 0.8rem; }
.check input:disabled + .lab-check-name { color: var(--text-muted); }
.lab-tables-notes { display: grid; gap: 0.25rem; margin: 0; padding: 0.6rem 0.75rem 0.6rem 1.75rem; border-radius: var(--radius-sm); background: var(--info-soft); color: var(--text-2); font-size: 0.85rem; }
.lab-tables-notes[hidden] { display: none; }
.lab-sql-preview { max-height: 16rem; }
#lab-tables-new-field[hidden] { display: none; }

/* Import into SQL Lab */
.lab-explorer-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.lab-explorer-actions [hidden] { display: none; }
.lab-import-source { display: flex; flex-wrap: wrap; gap: 0.4rem 0.6rem; align-items: center; }
.lab-import-file-name { color: var(--text-muted); font-size: 0.85rem; overflow-wrap: anywhere; min-width: 0; }
#lab-import-dialog .field[hidden], #lab-import-dialog .fieldset[hidden] { display: none; }
#lab-import-dialog .field-row { align-items: start; }
#lab-import-dialog .field-row .select, #lab-import-dialog .field-row .input { width: 100%; min-width: 0; }
.lab-import-header { align-self: end; min-height: 2.5rem; }
.lab-import-preview { display: grid; gap: 0.5rem; min-width: 0; }
.lab-import-preview:empty { display: none; }
.lab-import-status { font-size: 0.875rem; color: var(--text-2); }
.lab-import-problem { color: var(--danger); }
.lab-import-preview .lab-import-status.lab-import-problem { padding: 0.5rem 0.75rem; border-left: 4px solid var(--danger); border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--text); }
.lab-import-warning { color: var(--warning); }
.lab-import-preview .lab-import-status.lab-import-warning { padding: 0.5rem 0.75rem; border-left: 4px solid var(--warning); border-radius: var(--radius-sm); background: var(--warning-soft); }
.lab-import-scroll { max-height: 16rem; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.lab-import-scroll:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.lab-import-statements { display: grid; margin: 0; padding: 0; list-style: none; font-size: 0.85rem; }
.lab-import-statements > li { display: flex; flex-wrap: wrap; gap: 0.1rem 0.6rem; align-items: baseline; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); }
.lab-import-statements > li:last-child { border-bottom: 0; }
.lab-import-statement { font-family: var(--font-mono); font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.lab-import-meta { color: var(--text-muted); font-size: 0.8rem; }
.lab-import-statements > li.is-skipped .lab-import-statement { color: var(--text-muted); font-weight: 400; text-decoration: line-through; }
.lab-import-statements > li.has-issues { box-shadow: inset 3px 0 0 var(--warning); }
.lab-import-issues { flex-basis: 100%; display: grid; gap: 0.15rem; margin: 0.15rem 0 0; padding-left: 1.1rem; color: var(--warning); font-size: 0.8rem; }
.lab-import-sample { max-height: 18rem; overflow: auto; }
.lab-data td { font-family: var(--font-mono); font-size: 0.8rem; max-width: 18rem; overflow: hidden; text-overflow: ellipsis; }
.lab-data .lab-null { color: var(--text-muted); font-style: italic; }
.lab-data thead th { position: sticky; top: 0; font-family: var(--font-mono); }
.select-sm { min-height: 2rem; padding-top: 0.2rem; padding-bottom: 0.2rem; font-size: 0.85rem; }
.lab-columns td .select-sm { min-width: 7.5rem; }

/* The phone action bar is for the builder */
body.view-lab .mobile-bar { display: none; }
@media (max-width: 759px) {
    body.view-lab .app { padding-bottom: calc(2rem + var(--safe-bottom)); }
    body.view-lab .toast { bottom: calc(1.5rem + var(--safe-bottom)); }
}
@media (max-width: 719px) {
    .view-switch { width: 100%; margin-right: 0; }
    .view-switch .segment { flex: 1 1 0; }
    /* Bigger touch targets on phones */
    .lab-row, .lab-db-btn, .lab-object-btn { min-height: 2.5rem; }
    .lab-twisty { width: 2rem; height: 2rem; }
}

.noscript { padding: 1rem; text-align: center; }

/* ------------------------------------------------------------ practice */

.practice {
    display: grid;
    gap: 0.6rem;
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius, 8px);
    background: var(--accent-soft);
}
.practice[hidden] { display: none; }
.practice > * { margin: 0; min-width: 0; }
.practice-head { display: flex; gap: 0.5rem; align-items: flex-start; justify-content: space-between; }
.practice-kicker { margin: 0; color: var(--text-2); font-size: 0.8rem; font-weight: 600; }
.practice-title { margin: 0.1rem 0 0; font-size: 1.05rem; }
.practice-title:focus { outline: none; }
.practice-title:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.practice-goal { font-weight: 600; }
.practice-tables { display: grid; gap: 0.3rem; justify-items: start; font-size: 0.85rem; }
.practice-tables p, .practice-answer p { margin: 0; }
.practice-tables ul { margin: 0; padding-left: 1.1rem; overflow-wrap: anywhere; }
.practice-tables-label { color: var(--text-2); font-weight: 600; }
.practice-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.practice-hints { margin: 0; padding-left: 1.3rem; display: grid; gap: 0.25rem; font-size: 0.9rem; }
.practice-result { display: grid; gap: 0.4rem; padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.practice-result.practice-passed { border-color: var(--success); }
.practice-result > * { margin: 0; }
.practice-summary { font-weight: 700; }
.practice-passed .practice-summary { color: var(--success); }
.practice-checks { display: grid; gap: 0.3rem; margin: 0; padding: 0; list-style: none; font-size: 0.9rem; }
.practice-checks li { display: grid; grid-template-columns: 1.2rem 1fr; column-gap: 0.3rem; }
.practice-mark { font-weight: 700; }
.practice-checks .is-ok .practice-mark { color: var(--success); }
.practice-checks .is-missing .practice-mark { color: var(--danger); }
.practice-check-hint { grid-column: 2; color: var(--text-2); font-size: 0.85rem; }
.practice-explain { font-size: 0.9rem; }
.practice-result .btn { justify-self: start; }
.practice-answer { display: grid; gap: 0.4rem; }
.practice-answer-sql { margin: 0; max-height: 16rem; overflow: auto; white-space: pre; }
.practice-note { color: var(--text-2); font-size: 0.8rem; }
.practice-done { border-color: var(--success); color: var(--success); }

/* ------------------------------------------------------------ versions */

.versions-list { display: grid; gap: 0.4rem; margin: 0; padding: 0; list-style: none; max-height: 18rem; overflow: auto; }
.version-item { display: grid; gap: 0.35rem; padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.version-item.is-selected { border-color: var(--accent); }
.version-current { background: var(--surface-2); }
.version-change { color: var(--text-2); }
.versions-compare { display: grid; gap: 0.4rem; min-width: 0; }
.versions-compare:empty { display: none; }
.version-compare-title { margin: 0; font-weight: 600; }
.version-diff {
    margin: 0;
    max-height: 22rem;
    overflow: auto;
    padding: 0.5rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    white-space: pre;
}
.diff-line { display: block; padding: 0 0.6rem; }
.diff-added { background: color-mix(in srgb, var(--success) 16%, transparent); }
.diff-removed { background: color-mix(in srgb, var(--danger) 14%, transparent); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.diff-mark { color: var(--text-2); user-select: none; }

/* ------------------------------------------------------------ projects */

.project-bar { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; align-items: center; margin-bottom: 0.5rem; min-width: 0; }
.project-label { color: var(--text-2); font-size: 0.8rem; font-weight: 600; }
.project-current { min-width: 0; overflow-wrap: anywhere; }
.project-bar .btn { margin-left: auto; }
.projects-list { display: grid; gap: 0.4rem; margin: 0 0 0.75rem; padding: 0; list-style: none; max-height: 20rem; overflow: auto; }
.project-item { display: grid; gap: 0.35rem; padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.project-item.is-current { border-color: var(--success); }
.project-item .library-name { overflow-wrap: anywhere; }
.project-counts { color: var(--text-2); font-size: 0.85rem; }
.projects-new-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.projects-new-row .input { flex: 1 1 12rem; min-width: 0; width: auto; }

/* Section help: the info button beside a section header, and its popover */
.section-frame { position: relative; }
.section-frame > .section > .section-summary { padding-right: 2.75rem; }
.help-btn {
    display: inline-grid;
    flex: none;
    place-items: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    color: var(--text-muted);
    font: italic 700 0.85rem/1 Georgia, "Times New Roman", serif;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: 50%;
    cursor: help;
    position: relative;
}
.section-frame > .help-btn { position: absolute; top: 0.45rem; right: 0.55rem; }
.help-btn:hover, .help-btn[aria-expanded="true"] { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
.help-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* A finger-sized target without a bigger circle */
.help-btn::after { content: ""; position: absolute; inset: -0.5rem; }
@media (pointer: coarse) {
    .help-btn::after { inset: -0.6rem; }
}

.help-popover {
    position: fixed;
    z-index: 55;
    top: 0;
    left: 0;
    width: max-content;
    max-width: min(22rem, calc(100vw - 16px));
    padding: 0.7rem 0.85rem;
    overflow: auto;
    color: var(--text);
    font-size: 0.85rem;
    line-height: 1.45;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overscroll-behavior: contain;
}
.help-popover[hidden] { display: none; }
.help-title { margin-bottom: 0.4rem; color: var(--text-2); }
.help-title strong { color: var(--text); font-family: var(--font-mono); }
.help-list { display: grid; gap: 0.1rem; margin: 0; }
.help-list dt { margin-top: 0.35rem; color: var(--text-muted); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.help-list dt:first-child { margin-top: 0; }
.help-list dd { margin: 0; }
.help-code {
    display: block;
    padding: 0.3rem 0.45rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    overflow-wrap: anywhere;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.help-note { margin-top: 0.5rem; padding-top: 0.45rem; color: var(--text-2); border-top: 1px solid var(--border); }

/* SQL Lab console: editor, Run, results, messages, history */
.lab-head-slot { display: grid; gap: 0.5rem; min-width: 0; }
.lab-console { display: grid; gap: 0.5rem; min-width: 0; }
.lab-console[hidden], .lab-tabs[hidden], .lab-panel[hidden] { display: none; }
.lab-console-head { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.lab-console-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; justify-content: flex-end; }
.lab-editor {
    position: relative;
    min-width: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--code-bg);
}
.lab-editor:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }
.lab-editor-highlight, .lab-editor-input {
    margin: 0;
    padding: 0.6rem 0.75rem;
    border: 0;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.5;
    tab-size: 4;
    white-space: pre;
    overflow-wrap: normal;
    letter-spacing: normal;
}
.lab-editor-highlight {
    position: absolute;
    inset: 0;
    overflow: hidden;
    color: var(--text);
    pointer-events: none;
}
.lab-editor-highlight code { font-family: inherit; }
.lab-editor-input {
    position: relative;
    display: block;
    width: 100%;
    min-height: 9rem;
    max-height: 60vh;
    resize: vertical;
    overflow: auto;
    background: transparent;
    color: transparent;
    caret-color: var(--text);
}
.lab-editor-input:focus { outline: none; }
.lab-editor-input::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); color: transparent; }
@media (forced-colors: active) {
    .lab-editor-highlight { display: none; }
    .lab-editor-input { color: CanvasText; }
}
.lab-sql-from, .lab-sql-notices {
    display: grid;
    gap: 0.35rem;
    justify-items: start;
    padding: 0.5rem 0.75rem;
    border-left: 4px solid var(--warning);
    border-radius: var(--radius-sm);
    background: var(--warning-soft);
    color: var(--text);
    font-size: 0.85rem;
}
.lab-sql-from { border-left-color: var(--accent); background: var(--info-soft); }
.lab-sql-from[hidden], .lab-sql-notices[hidden] { display: none; }
.lab-sql-notices ul { display: grid; gap: 0.2rem; margin: 0; padding-left: 1.1rem; }
.lab-sql-notice-title { font-weight: 650; }
.lab-link-btn { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
.lab-link-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.lab-run-bar { display: flex; flex-wrap: wrap; gap: 0.4rem 0.6rem; align-items: center; }
.lab-run-bar [hidden] { display: none; }
.lab-run-hint { flex: 1 1 14rem; margin: 0; }
.lab-transaction { border-color: var(--warning); background: var(--warning-soft); color: var(--warning); font-weight: 600; }

.lab-tabs { display: flex; gap: 0.25rem; overflow-x: auto; border-bottom: 1px solid var(--border); }
.lab-tab {
    min-height: 2.5rem;
    padding: 0.4rem 0.8rem;
    border: 0;
    border-bottom: 3px solid transparent;
    background: none;
    color: var(--text-2);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}
.lab-tab:hover { color: var(--text); }
.lab-tab[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--text); }
.lab-tab:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.lab-panel { display: grid; gap: 0.75rem; min-width: 0; }
.lab-panel:focus { outline: none; }

.lab-result { display: grid; gap: 0.4rem; justify-items: start; min-width: 0; }
.lab-result > .lab-table-scroll { justify-self: stretch; }
.lab-result-head { display: flex; flex-wrap: wrap; gap: 0.2rem 0.75rem; align-items: baseline; }
.lab-result-title { font-size: 0.85rem; font-weight: 650; }
.lab-result-status { font-size: 0.85rem; color: var(--text-2); }
.lab-result-time { font-size: 0.8rem; color: var(--text-muted); }
.lab-result-scroll { max-height: 26rem; overflow: auto; }
.lab-data td.is-number { text-align: right; }
.lab-data .lab-blob { color: var(--text-muted); }
.lab-result-error { padding: 0.5rem 0.75rem; border-left: 4px solid var(--danger); border-radius: var(--radius-sm); background: var(--danger-soft); font-size: 0.85rem; }

.lab-message-summary { font-weight: 600; }
.lab-messages { display: grid; margin: 0; padding: 0; list-style: none; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.85rem; }
.lab-message { display: flex; flex-wrap: wrap; gap: 0.1rem 0.75rem; align-items: baseline; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); min-width: 0; }
.lab-message:last-child { border-bottom: 0; }
.lab-message-where { color: var(--text-muted); font-size: 0.8rem; white-space: nowrap; }
.lab-message-text { flex: 1 1 12rem; min-width: 0; }
.lab-message-time { color: var(--text-muted); font-size: 0.8rem; }
.lab-message-sql { flex-basis: 100%; color: var(--text-2); font-family: var(--font-mono); font-size: 0.8rem; overflow-wrap: anywhere; }
.lab-message-more { color: var(--text-muted); font-style: italic; }
.lab-message-error { box-shadow: inset 4px 0 0 var(--danger); background: var(--danger-soft); }
.lab-message-note { color: var(--text-2); font-size: 0.85rem; }

.lab-history-head { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; justify-content: space-between; }
.lab-history { display: grid; gap: 0.5rem; margin: 0; padding: 0; list-style: none; }
.lab-history-item { display: grid; gap: 0.3rem; padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 0; }
.lab-history-item.is-error { box-shadow: inset 3px 0 0 var(--danger); }
.lab-history-sql { font-family: var(--font-mono); font-size: 0.8rem; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 7.5rem; overflow: hidden; }
.lab-history-meta { display: flex; flex-wrap: wrap; gap: 0.1rem 0.75rem; color: var(--text-muted); font-size: 0.8rem; }
.lab-history-error { color: var(--danger); }
.lab-history-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.lab-import-change { flex: 1 1 20rem; min-width: 0; }
#lab-import-adapt-field[hidden] { display: none; }
