:root {
    color-scheme: dark;
    --bg: #0d1117;
    --panel: #111820;
    --panel-2: #161f29;
    --panel-3: #1b2632;
    --line: #2b3947;
    --line-soft: #22303d;
    --text: #e9f0f6;
    --muted: #92a2b2;
    --accent: #66d2c8;
    --accent-strong: #84eee3;
    --accent-ink: #072522;
    --warning: #f0bc6b;
    --danger: #ff7b86;
    --success: #69d892;
    --shadow: 0 20px 60px rgba(0, 0, 0, .38);
    --topbar-height: 54px;
    --statusbar-height: 28px;
    --query-height: 48%;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { color: inherit; }

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

.app-shell { height: 100%; display: grid; grid-template-rows: var(--topbar-height) 1fr var(--statusbar-height); }

.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 14px;
    background: linear-gradient(180deg, #18232e 0%, #111922 100%);
    border-bottom: 1px solid var(--line);
    min-width: 0;
}

.brand {
    display: inline-flex;
    align-items: baseline;
    text-decoration: none;
    letter-spacing: -.035em;
    white-space: nowrap;
    margin-right: 6px;
}
.brand-name { color: #fff; font-size: 20px; font-weight: 760; }
.brand-mark { color: var(--accent); font-size: 18px; font-weight: 800; }

.topbar-group { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-spacer, .statusbar-spacer, .modal-footer-spacer { flex: 1; }
.connection-group { flex: 0 1 510px; }
.connection-select { min-width: 190px; max-width: 390px; flex: 1; }
.actions-group { justify-content: flex-end; }
.compact-label { color: var(--muted); font-size: 12px; }
.compact-control { width: 82px; }

.control {
    width: 100%;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #0f161e;
    color: var(--text);
    padding: 6px 10px;
    outline: none;
}
.control:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(102, 210, 200, .13); }
.control::placeholder { color: #647587; }

.button, .icon-button, .result-tab {
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    transition: background .14s ease, border-color .14s ease, color .14s ease, transform .14s ease;
}
.button { min-height: 34px; padding: 6px 12px; white-space: nowrap; }
.button:hover, .icon-button:hover, .result-tab:hover { background: rgba(255,255,255,.06); }
.button:active, .icon-button:active { transform: translateY(1px); }
.button:disabled { opacity: .42; cursor: not-allowed; transform: none; }
.button-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 750; }
.button-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.button-quiet { border-color: var(--line); background: rgba(255,255,255,.025); }
.button-danger { color: var(--danger); border-color: rgba(255, 123, 134, .42); }
.button-small { min-height: 29px; padding: 4px 9px; font-size: 12px; }
.icon-button { width: 31px; height: 31px; color: var(--muted); font-size: 20px; }

.workspace {
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(180px, var(--query-height)) 6px minmax(130px, 1fr);
    background: var(--bg);
}

.query-pane { min-height: 0; display: grid; grid-template-columns: 270px minmax(0, 1fr); }
.schema-panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto auto 1fr; background: var(--panel); border-right: 1px solid var(--line); }
.panel-heading, .editor-toolbar, .results-toolbar {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-bottom: 1px solid var(--line-soft);
    background: var(--panel-2);
}
.panel-heading { justify-content: space-between; }
.eyebrow { display: block; color: var(--accent); font-size: 9px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; margin-bottom: 2px; }
.panel-heading strong { font-size: 13px; }
.schema-tools { padding: 8px; border-bottom: 1px solid var(--line-soft); }
.schema-tools .control { min-height: 31px; font-size: 12px; }
.schema-tree { min-height: 0; overflow: auto; padding: 7px 5px 18px; }

.schema-group { margin-bottom: 5px; }
.schema-table {
    width: 100%;
    min-height: 30px;
    display: grid;
    grid-template-columns: 19px minmax(0, 1fr) auto;
    align-items: center;
    gap: 5px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--text);
    text-align: left;
    padding: 4px 6px;
    cursor: pointer;
}
.schema-table:hover, .schema-column:hover { background: rgba(255,255,255,.05); }
.schema-caret { color: var(--muted); transform-origin: 45% 50%; transition: transform .12s ease; }
.schema-group.open .schema-caret { transform: rotate(90deg); }
.schema-object-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.schema-badge { color: var(--muted); font-size: 9px; text-transform: uppercase; }
.schema-columns { display: none; padding-left: 24px; }
.schema-group.open .schema-columns { display: block; }
.schema-column {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    padding: 4px 7px;
    text-align: left;
    cursor: pointer;
    font-size: 11px;
}
.schema-column-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #c6d1dc; }
.schema-column-type { white-space: nowrap; color: #71869a; }
.schema-key { color: var(--warning); }

.editor-panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: 44px 1fr; background: #10161d; }
.editor-toolbar { justify-content: space-between; }
.editor-context { min-width: 0; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.editor-context span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-toolbar-actions { display: flex; gap: 6px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #596775; box-shadow: 0 0 0 3px rgba(89,103,117,.12); }
.status-dot.connected { background: var(--success); box-shadow: 0 0 0 3px rgba(105,216,146,.12); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 3px rgba(255,123,134,.12); }
.editor-host { min-width: 0; min-height: 0; }

.pane-splitter { background: #263441; cursor: row-resize; position: relative; }
.pane-splitter::after { content: ""; position: absolute; inset: 2px 45%; border-top: 1px solid #758493; border-bottom: 1px solid #758493; opacity: .55; }
.pane-splitter:hover, body.resizing .pane-splitter { background: var(--accent); }
body.resizing { cursor: row-resize; user-select: none; }

.results-pane { min-height: 0; display: grid; grid-template-rows: 44px 1fr; background: var(--panel); }
.results-toolbar { min-width: 0; }
.result-tabs { align-self: stretch; display: flex; gap: 4px; }
.result-tab { position: relative; color: var(--muted); padding: 0 10px; font-size: 12px; }
.result-tab.active { color: var(--text); background: rgba(255,255,255,.045); }
.result-tab.active::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -7px; height: 2px; background: var(--accent); }
.results-summary { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; }
.results-actions { display: flex; gap: 6px; }
.results-view { min-height: 0; overflow: hidden; }
.results-view.active { display: block; }
.grid-wrap { height: 100%; overflow: auto; background: #0d1319; }

.result-grid { border-collapse: separate; border-spacing: 0; min-width: 100%; font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.result-grid th, .result-grid td { max-width: 460px; min-width: 80px; padding: 6px 9px; border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); text-align: left; white-space: pre; overflow: hidden; text-overflow: ellipsis; }
.result-grid th { position: sticky; top: 0; z-index: 2; background: #1a2530; color: #cfdae4; font-family: inherit; font-weight: 700; }
.result-grid td { color: #bfcbd6; background: #0f161d; }
.result-grid tr:nth-child(even) td { background: #111a22; }
.result-grid td.null-value { color: #6f8395; font-style: italic; }
.result-grid td:hover { overflow: visible; position: relative; z-index: 1; background: #1b2834; }
.row-number { min-width: 46px !important; width: 46px; color: #71869a !important; text-align: right !important; }

.messages-log { height: 100%; margin: 0; overflow: auto; padding: 14px; background: #0d1319; color: #b9c6d2; font: 12px/1.55 "Cascadia Code", "SFMono-Regular", Consolas, monospace; white-space: pre-wrap; }
.messages-log.error { color: #ffc2c7; }

.empty-state { padding: 18px 12px; color: var(--muted); text-align: center; font-size: 12px; line-height: 1.5; }
.empty-state.large { min-height: 100%; display: grid; place-items: center; }

.statusbar { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 0 10px; background: #16212b; border-top: 1px solid var(--line); color: #8fa0af; font-size: 11px; }
.status-divider { color: #536372; }

.modal-backdrop { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 24px; background: rgba(3, 7, 11, .72); backdrop-filter: blur(5px); }
.modal-backdrop[hidden] { display: none; }
.modal { width: min(680px, 100%); max-height: calc(100vh - 48px); display: grid; grid-template-rows: auto 1fr; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 18px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.modal-header h1 { margin: 0; font-size: 20px; }
.modal-body { min-height: 0; overflow: auto; padding: 16px 18px 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { display: grid; gap: 5px; color: #b8c5d0; font-size: 12px; }
.field-wide { grid-column: 1 / -1; }
.check-field { display: flex; align-items: flex-start; gap: 8px; color: var(--muted); font-size: 12px; }
.check-field input { margin-top: 2px; accent-color: var(--accent); }
.advanced { border: 1px solid var(--line-soft); border-radius: 7px; padding: 9px 10px; color: var(--muted); font-size: 12px; }
.advanced summary { cursor: pointer; color: #c3cfda; }
.nested-grid { margin-top: 12px; }
.security-note { margin: 14px 0 8px; padding: 10px 12px; border-left: 3px solid var(--warning); background: rgba(240,188,107,.07); color: #c8b995; font-size: 11px; line-height: 1.5; }
.modal-message { min-height: 26px; padding: 4px 0; color: var(--muted); font-size: 12px; }
.modal-message.success { color: var(--success); }
.modal-message.error { color: var(--danger); }
.modal-footer { position: sticky; bottom: 0; display: flex; gap: 8px; align-items: center; margin: 0 -18px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--panel-2); }

.current-statement-highlight { background: rgba(102,210,200,.045); }
.current-statement-glyph { border-left: 2px solid var(--accent); margin-left: 3px; }

@media (max-width: 850px) {
    .topbar { gap: 8px; }
    .brand-name { font-size: 17px; }
    .connection-group { flex: 1; }
    .connection-select { min-width: 120px; }
    .compact-label { display: none; }
    .query-pane { grid-template-columns: 210px minmax(0, 1fr); }
    .results-actions .button:first-child { display: none; }
}

@media (max-width: 640px) {
    :root { --topbar-height: 98px; }
    .topbar { flex-wrap: wrap; align-content: center; padding-block: 7px; }
    .brand { width: 110px; }
    .connection-group { flex: 1 1 calc(100% - 120px); }
    .actions-group { flex: 1 1 100%; justify-content: flex-end; }
    .query-pane { grid-template-columns: 150px minmax(0, 1fr); }
    .schema-column-type, .schema-badge { display: none; }
    .results-toolbar { gap: 5px; }
    .results-actions .button { padding-inline: 6px; }
    .form-grid { grid-template-columns: 1fr; }
    .field-wide { grid-column: auto; }
    .modal-backdrop { padding: 8px; }
    .modal { max-height: calc(100vh - 16px); }
}
