/* DbManager - IDE-style console for SQL Server */
:root {
  --bg: #f4f5f7;
  --bg-2: #eceef2;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --line: #dde1e7;
  --line-2: #e9ecf0;
  --text: #1c2230;
  --text-2: #4a5263;
  --muted: #7a8394;
  --accent: #2f6fed;
  --accent-2: #2358c9;
  --accent-soft: #e6eefd;
  --sel: #dbe7fd;
  --danger: #d23b48;
  --danger-soft: #fdecee;
  --ok: #1f9d5c;
  --warn: #b7791f;
  --warn-soft: #fdf4e3;
  --grid-odd: #fafbfc;
  --grid-head: #f3f5f8;
  --null: #a0a7b4;
  --shadow: 0 8px 28px rgba(20, 28, 45, .14), 0 1px 3px rgba(20, 28, 45, .08);
  --radius: 7px;
  --font: 'Segoe UI Variable Text', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'Cascadia Code', 'JetBrains Mono', Consolas, 'SFMono-Regular', Menlo, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #111317;
  --bg-2: #0d0f12;
  --panel: #181b21;
  --panel-2: #1d2128;
  --line: #2a2f38;
  --line-2: #22262e;
  --text: #dfe3ea;
  --text-2: #b3bac6;
  --muted: #7f8898;
  --accent: #4d8dff;
  --accent-2: #6ba1ff;
  --accent-soft: #1b2a45;
  --sel: #20355a;
  --danger: #ff6b76;
  --danger-soft: #3a1c21;
  --ok: #3fcf86;
  --warn: #e8b34f;
  --warn-soft: #3a2f18;
  --grid-odd: #1b1e24;
  --grid-head: #1f232a;
  --null: #5f6878;
  --shadow: 0 10px 34px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317; --bg-2: #0d0f12; --panel: #181b21; --panel-2: #1d2128; --line: #2a2f38; --line-2: #22262e;
    --text: #dfe3ea; --text-2: #b3bac6; --muted: #7f8898; --accent: #4d8dff; --accent-2: #6ba1ff; --accent-soft: #1b2a45;
    --sel: #20355a; --danger: #ff6b76; --danger-soft: #3a1c21; --ok: #3fcf86; --warn: #e8b34f; --warn-soft: #3a2f18;
    --grid-odd: #1b1e24; --grid-head: #1f232a; --null: #5f6878;
    --shadow: 0 10px 34px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.45 var(--font); -webkit-font-smoothing: antialiased; overflow: hidden; }
#app { height: 100%; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
kbd { font: 11px var(--mono); padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--panel); color: var(--text-2); }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.spacer { flex: 1; }
.only-sm { display: none !important; }
.warn-text { color: var(--warn); }
.danger-text { color: var(--danger) !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.icon { display: inline-flex; width: 16px; height: 16px; flex: none; }
.icon svg { width: 100%; height: 100%; }
.icon.big { width: 34px; height: 34px; color: var(--accent); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: var(--panel-2); border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { border-color: transparent; background: transparent; color: var(--danger); }
.btn.danger-ghost:hover:not(:disabled) { background: var(--danger-soft); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover:not(:disabled) { background: var(--bg-2); border-color: transparent; color: var(--text); }
.btn.icon-only { padding: 0; width: 30px; justify-content: center; }
.btn.sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn.sm.icon-only { width: 26px; padding: 0; }
.btn.block { width: 100%; justify-content: center; height: 36px; }

.input, .select {
  height: 30px; padding: 0 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
  color: var(--text); font: inherit; min-width: 0;
}
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.sm, .select.sm { height: 26px; font-size: 12px; padding: 0 7px; }
.input.mono { font-family: var(--mono); font-size: 12px; }
.input:disabled { opacity: .5; }
.select { padding-right: 4px; cursor: pointer; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.check input { accent-color: var(--accent); margin: 0; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; background: var(--bg-2); color: var(--text-2); font-size: 11px; font-weight: 500; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; flex: none; }
.spinner.sm { width: 11px; height: 11px; border-width: 1.5px; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { flex: 1; display: grid; place-items: center; }

/* ---------- login ---------- */
.login-screen {
  flex: 1; display: grid; place-items: center; padding: 24px 16px; overflow: auto;
  background: radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent 70%), var(--bg);
}
.login-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 26px 26px 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 13px; }
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.login-brand h1 { font-size: 20px; letter-spacing: -.01em; }
.login-brand p { margin: 1px 0 0; }
.logo { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: #fff; }
.logo .icon { width: 22px; height: 22px; }
.logo.sm { width: 24px; height: 24px; border-radius: 6px; }
.logo.sm .icon { width: 15px; height: 15px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field .input, .field .select { height: 34px; }
.login-advanced { border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 12px; }
.login-advanced summary { cursor: pointer; color: var(--text-2); font-weight: 500; }
.login-advanced[open] { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }
.login-advanced[open] summary { margin-bottom: 2px; }
.login-error { background: var(--danger-soft); color: var(--danger); padding: 9px 11px; border-radius: 7px; font-size: 12.5px; white-space: pre-wrap; }
.login-foot { text-align: center; margin: 2px 0 0; }

/* ---------- shell ---------- */
.topbar { height: 44px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 10px 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 14px; margin-right: 10px; }
.conn { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 4px 10px; border-radius: 6px; background: var(--bg-2); font-size: 12px; overflow: hidden; }
.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.conn-server { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn-login, .conn-db { color: var(--muted); white-space: nowrap; }
.conn-db::before { content: '/ '; }
.layout { flex: 1; display: flex; min-height: 0; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--panel); }

.splitter { flex: none; background: transparent; position: relative; z-index: 5; }
.splitter-x { width: 5px; margin: 0 -2px; cursor: col-resize; }
.splitter-y { height: 5px; margin: -2px 0; cursor: row-resize; }
.splitter:hover, .splitter:active { background: var(--accent); opacity: .6; }
body.resizing-x { cursor: col-resize; user-select: none; }
body.resizing-y { cursor: row-resize; user-select: none; }

/* ---------- explorer ---------- */
.explorer { width: 290px; flex: none; display: flex; flex-direction: column; background: var(--panel-2); border-right: 1px solid var(--line); min-width: 0; }
.explorer-head { display: flex; align-items: center; padding: 8px 6px 4px 12px; }
.explorer-title { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); flex: 1; }
.explorer-search-wrap { position: relative; margin: 0 8px 6px; }
.explorer-search-wrap .icon { position: absolute; left: 8px; top: 7px; color: var(--muted); width: 14px; height: 14px; }
.explorer-search { width: 100%; padding-left: 28px; height: 28px; }
.tree-scroll { flex: 1; overflow: auto; padding-bottom: 20px; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree-row { display: flex; align-items: center; gap: 5px; height: 25px; padding-right: 8px; cursor: pointer; white-space: nowrap; user-select: none; border-radius: 0; }
.tree-row:hover { background: var(--bg-2); }
.tree-row.selected { background: var(--sel); }
.tree-row.dim { opacity: .55; }
.twisty { width: 14px; height: 14px; display: inline-flex; color: var(--muted); transition: transform .12s; flex: none; }
.twisty .icon { width: 13px; height: 13px; }
.twisty.open { transform: rotate(90deg); }
.twisty.none { visibility: hidden; }
.ti { width: 15px; height: 15px; color: var(--text-2); }
.ti-db, .ti-server { color: var(--accent); }
.ti-table { color: #3b82c4; }
.ti-view { color: #8b5cc4; }
.ti-proc { color: #c47a2c; }
.ti-func { color: #2c9c8a; }
.ti-folder { color: #c9a13a; }
.ti-key, .key-ic { color: #d4a017; }
.key-ic { width: 13px; height: 13px; vertical-align: -2px; margin-right: 3px; }
.tree-label { overflow: hidden; text-overflow: ellipsis; }
.tree-count { font-size: 11px; color: var(--muted); }
.tree-count::before { content: '('; } .tree-count::after { content: ')'; }
.tree-hint { font-size: 11px; color: var(--muted); margin-left: auto; padding-left: 8px; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); }

/* ---------- tabs ---------- */
.tabstrip { display: flex; height: 36px; flex: none; background: var(--panel-2); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; }
.tab {
  display: flex; align-items: center; gap: 7px; padding: 0 6px 0 12px; max-width: 240px; min-width: 110px; cursor: pointer;
  border-right: 1px solid var(--line-2); color: var(--text-2); position: relative; user-select: none; flex: none;
}
.tab:hover { background: var(--bg-2); }
.tab.active { background: var(--panel); color: var(--text); }
.tab.active::after { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--accent); }
.tab .icon { width: 14px; height: 14px; }
.tab-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-close { border: 0; background: transparent; color: var(--muted); width: 20px; height: 20px; border-radius: 4px; display: grid; place-items: center; cursor: pointer; padding: 0; opacity: 0; }
.tab:hover .tab-close, .tab.active .tab-close { opacity: 1; }
.tab-close:hover { background: var(--line); color: var(--text); }
.tab-close .icon { width: 12px; height: 12px; }
.pages { flex: 1; min-height: 0; position: relative; display: flex; }
.tab-page { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.welcome { margin: auto; text-align: center; padding: 30px 16px; max-width: 560px; }
.welcome h2 { font-size: 20px; margin-bottom: 6px; }
.welcome-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 18px 0; }
.shortcuts { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; }

/* ---------- toolbar / status ---------- */
.toolbar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; flex: none; background: var(--panel); }
.tb-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.tb-label { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.tb-label .select { max-width: 220px; }
.statusbar { display: flex; align-items: center; gap: 10px; height: 26px; padding: 0 10px; border-top: 1px solid var(--line); background: var(--panel-2); font-size: 12px; flex: none; color: var(--text-2); overflow: hidden; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.status-dot.ok { background: var(--ok); }
.status-dot.error { background: var(--danger); }
.status-dot.warn { background: var(--warn); }
.status-dot.running { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.status-meta { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.status-meta.strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- query tab ---------- */
.editor-pane { height: 42%; min-height: 80px; flex: none; position: relative; border-bottom: 1px solid var(--line); }
.editor-host { position: absolute; inset: 0; }
.fallback-editor { width: 100%; height: 100%; border: 0; resize: none; padding: 10px 12px; font: 13px/20px var(--mono); background: var(--panel); color: var(--text); outline: none; tab-size: 4; }
.results-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.result-head { display: flex; align-items: center; border-bottom: 1px solid var(--line); background: var(--panel-2); flex: none; min-height: 32px; }
.result-tabs { display: flex; overflow-x: auto; flex: 1; min-width: 0; }
.rtab { border: 0; background: transparent; color: var(--text-2); padding: 0 12px; height: 32px; font: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; border-bottom: 2px solid transparent; white-space: nowrap; }
.rtab:hover { color: var(--text); }
.rtab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.rtab.error { color: var(--danger); }
.rtab-count { font-size: 11px; font-weight: 500; padding: 0 6px; border-radius: 8px; background: var(--bg-2); color: var(--muted); }
.result-actions { display: flex; align-items: center; gap: 2px; padding: 0 6px; flex: none; }
.result-body { flex: 1; min-height: 0; display: flex; position: relative; }
.empty { margin: auto; text-align: center; padding: 20px; }
.empty-title { font-weight: 600; margin-bottom: 4px; }
.messages { flex: 1; overflow: auto; padding: 8px 0; font: 12px/1.55 var(--mono); }
.msg pre { margin: 0; padding: 3px 14px; white-space: pre-wrap; word-break: break-word; font: inherit; }
.msg.error { color: var(--danger); }
.msg.rows, .msg.meta { color: var(--muted); }
.msg.clickable { cursor: pointer; }
.msg.clickable:hover { background: var(--danger-soft); }

/* ---------- grid ---------- */
.grid { flex: 1; min-width: 0; min-height: 0; display: flex; outline: none; position: relative; }
.grid-scroll { flex: 1; overflow: auto; position: relative; }
.grid-canvas { position: relative; min-width: 100%; }
.grid-header { position: sticky; top: 0; z-index: 3; display: flex; height: 30px; background: var(--grid-head); border-bottom: 1px solid var(--line); width: fit-content; min-width: 100%; }
.gh { position: relative; display: flex; align-items: center; gap: 5px; padding: 0 8px; border-right: 1px solid var(--line-2); font-weight: 600; font-size: 12px; white-space: nowrap; overflow: hidden; flex: none; user-select: none; }
.gh.sortable { cursor: pointer; }
.gh.sortable:hover { background: var(--bg-2); }
.gh.is-key .gh-name::before { content: '🔑'; font-size: 10px; margin-right: 3px; filter: saturate(.7); }
.gh-name { overflow: hidden; text-overflow: ellipsis; }
.gh-type { font-weight: 400; color: var(--muted); font-size: 11px; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; }
.gh-sort { color: var(--accent); font-size: 9px; }
.gh-resize { position: absolute; right: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 2; }
.gh-num, .gc-num { position: sticky; left: 0; z-index: 2; background: var(--grid-head); color: var(--muted); justify-content: flex-end; text-align: right; font-weight: 500; }
.grid-header .gh-num { z-index: 4; }
.grid-body { position: absolute; left: 0; top: 0; right: 0; }
.gr { position: absolute; left: 0; height: 26px; display: flex; width: fit-content; min-width: 100%; }
.gr.odd { background: var(--grid-odd); }
.gr:hover { background: var(--bg-2); }
.gr.sel, .gr.sel .gc-num { background: var(--sel); }
.gc { flex: none; height: 26px; line-height: 25px; padding: 0 8px; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); white-space: pre; overflow: hidden; text-overflow: ellipsis; font: 12px/25px var(--mono); cursor: default; }
.gc.num { text-align: right; }
.gc-num { font: 11px/25px var(--font); padding-right: 8px; cursor: pointer; }
.gc.active { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--accent-soft); }
.gc.saving { background: var(--warn-soft); }
.gc.error { background: var(--danger-soft); outline: 2px solid var(--danger); outline-offset: -2px; }
.gc .null { color: var(--null); font-style: italic; }
.grid-editor { position: absolute; z-index: 6; border: 2px solid var(--accent); border-radius: 0; padding: 0 6px; font: 12px var(--mono); background: var(--panel); color: var(--text); outline: none; box-shadow: var(--shadow); }
.grid-editor::placeholder { color: var(--null); font-style: italic; }

/* ---------- object tab ---------- */
.object-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 10px 14px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; flex: none; }
.object-title { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; min-width: 0; }
.object-title h2 { font-size: 15px; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb { color: var(--muted); }
.crumb-sep { color: var(--line); }
.subnav { display: flex; gap: 2px; }
.subnav-btn { border: 0; background: transparent; color: var(--text-2); font: inherit; font-weight: 500; padding: 7px 12px 8px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; border-bottom: 2px solid transparent; }
.subnav-btn .icon { width: 14px; height: 14px; }
.subnav-btn:hover { color: var(--text); }
.subnav-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.subcontent { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.grid-host { flex: 1; min-height: 0; display: flex; position: relative; }
.grid-host.loading::after { content: ''; position: absolute; inset: 0; background: color-mix(in srgb, var(--panel) 55%, transparent); }
.grid-host.fixed-h { flex: none; height: 300px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.where-wrap { flex: 1; min-width: 180px; max-width: 520px; display: flex; }
.where-wrap .input { flex: 1; }
.pager { display: flex; align-items: center; gap: 4px; }
.filter-bar { display: flex; gap: 6px; flex-wrap: wrap; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.filter-chip { display: flex; gap: 4px; align-items: center; padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.filter-chip .input { width: 150px; }
.structure { overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; flex: 1; }
.card { border: 1px solid var(--line); border-radius: 9px; background: var(--panel); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.card.grow { flex: 1; min-height: 320px; }
.card h3 { font-size: 13px; display: flex; align-items: center; gap: 7px; }
.card h3 .icon { width: 15px; height: 15px; color: var(--text-2); }
.card .count { font-size: 11px; font-weight: 500; color: var(--muted); background: var(--bg-2); padding: 0 7px; border-radius: 8px; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-head .input { width: 220px; }
.table-wrap { overflow-x: auto; }
.data-table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.data-table th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 11.5px; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel-2); }
.data-table td { padding: 5px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--panel-2); }
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 12px; min-width: 110px; }
.stat-k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat-v { font-size: 14px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; word-break: break-word; }
.description { margin: 0; color: var(--text-2); }
.code-wrap { flex: 1; overflow: auto; background: var(--panel); }
.code-view { margin: 0; padding: 12px 16px; font: 13px/20px var(--mono); white-space: pre; tab-size: 4; }
.loading-block, .error-block { display: flex; align-items: center; gap: 10px; padding: 24px; color: var(--muted); }
.error-block { color: var(--danger); white-space: pre-wrap; }

/* ---------- overview ---------- */
.overview { overflow: auto; padding: 16px; gap: 14px; background: var(--bg); }
.overview-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.overview-head h2 { font-size: 18px; }
.version summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.version pre { font: 11.5px/1.5 var(--mono); white-space: pre-wrap; color: var(--text-2); margin: 6px 0 0; }

/* ---------- modal / menu / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 22, .45); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .12s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(460px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow); }
.modal.wide { width: min(760px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 18px; }
.modal-head h2 { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 4px 18px 12px; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--line-2); }
.confirm-text { margin: 4px 0; color: var(--text-2); line-height: 1.55; }
.value-view { width: 100%; height: min(60vh, 520px); font: 12.5px/1.5 var(--mono); padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); color: var(--text); resize: vertical; }
.form-grid { display: flex; flex-direction: column; gap: 8px; }
.form-row { display: grid; grid-template-columns: minmax(140px, 1fr) 2fr; gap: 10px; align-items: center; }
.form-label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.form-field { display: flex; gap: 6px; }
.form-field .input { flex: 1; }
.ctx-menu { position: fixed; z-index: 200; min-width: 200px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.ctx-item { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: transparent; color: var(--text); font: inherit; text-align: left; padding: 6px 10px; border-radius: 5px; cursor: pointer; white-space: nowrap; }
.ctx-item .icon { width: 14px; height: 14px; color: var(--text-2); }
.ctx-item:hover:not(:disabled), .ctx-item:focus-visible { background: var(--accent-soft); outline: none; }
.ctx-item:disabled { opacity: .45; cursor: default; }
.ctx-item.danger, .ctx-item.danger .icon { color: var(--danger); }
.ctx-label { flex: 1; }
.ctx-hint { color: var(--muted); font-size: 11px; }
.ctx-sep { height: 1px; background: var(--line-2); margin: 4px 6px; }
.ctx-has-sub { position: relative; }
.ctx-sub { display: none; position: absolute; left: calc(100% - 4px); top: -5px; }
.ctx-has-sub:hover > .ctx-sub, .ctx-has-sub:focus-within > .ctx-sub { display: block; }
.ctx-sub-arrow { margin-left: auto; width: 12px !important; height: 12px !important; }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; max-width: min(460px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--panel); padding: 9px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; animation: toast-in .18s ease-out; transition: opacity .25s, transform .25s; }
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- narrow screens ---------- */
@media (max-width: 760px) {
  .explorer { position: absolute; z-index: 20; left: 0; top: 44px; bottom: 0; width: min(300px, 85vw) !important; transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow); }
  body.explorer-open .explorer { transform: none; }
  .layout > .splitter { display: none; }
  .only-sm { display: inline-flex !important; }
  .conn-login, .conn-db, .hide-sm, .brand-text { display: none; }
  .topbar .btn.primary span { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .object-head { padding: 8px 10px 0; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- phase 1-3 additions ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; }
.badge .icon { width: 12px; height: 12px; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.btn.on { background: var(--accent-soft); color: var(--accent); }
.tran-chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 10px; border-radius: 16px; background: var(--warn-soft); color: var(--warn); font-weight: 600; font-size: 12px; margin-left: 6px; }
.tran-dot, .tab-tran { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; animation: pulse 1.6s ease-in-out infinite; }
.tab.in-tran { box-shadow: inset 0 -2px 0 var(--warn); }
.msg.warn { color: var(--warn); }
.warn-list { margin: 8px 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; color: var(--text-2); }
.warn-list strong { color: var(--danger); font-weight: 600; }
.result-filter { width: 170px; margin-right: 4px; }
.result-actions .muted { margin-right: 6px; white-space: nowrap; }

/* pick lists (history, snippets) */
.pick { display: flex; flex-direction: column; gap: 10px; }
.pick-list { display: flex; flex-direction: column; gap: 8px; max-height: min(60vh, 560px); overflow: auto; }
.pick-item { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--panel-2); }
.pick-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; flex-wrap: wrap; }
.pick-meta .icon { width: 14px; height: 14px; color: var(--text-2); }
.pick-sql { margin: 6px 0 0; font: 12px/1.45 var(--mono); white-space: pre-wrap; word-break: break-word; max-height: 140px; overflow: hidden; color: var(--text-2); }
.pad { padding: 12px; }

/* login with saved connections */
.login-wrap { display: flex; gap: 16px; align-items: stretch; width: min(820px, 100%); flex-wrap: wrap; justify-content: center; }
.login-wrap .login-card { flex: 1 1 380px; }
.login-saved { flex: 1 1 280px; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.login-saved h2 { font-size: 14px; }
.saved-list { display: flex; flex-direction: column; gap: 6px; overflow: auto; max-height: 460px; }
.saved-conn { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 10px; border: 1px solid var(--line-2); border-radius: 8px; cursor: pointer; }
.saved-conn:hover, .saved-conn.active { border-color: var(--accent); background: var(--accent-soft); }
.saved-conn .icon { color: var(--accent); }
.saved-text { flex: 1; min-width: 0; }
.saved-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-conn { display: flex; flex-direction: column; gap: 8px; }
.login-user { margin-left: auto; text-align: right; display: flex; flex-direction: column; }
.login-brand { flex-wrap: wrap; }

/* execution plan */
.plan-view { flex: 1; display: flex; min-height: 0; min-width: 0; }
.plan-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.result-inline-actions { display: flex; gap: 4px; padding: 4px 8px; border-bottom: 1px solid var(--line-2); }
.plan-canvas { flex: 1; overflow: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 18px; }
.plan-stmt { display: flex; flex-direction: column; gap: 8px; }
.plan-stmt-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.plan-stmt-text { margin: 0; font: 12px/1.45 var(--mono); color: var(--text-2); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 6px 10px; max-height: 90px; overflow: auto; white-space: pre-wrap; }
.plan-missing { border: 1px solid var(--warn); background: var(--warn-soft); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.plan-missing pre { margin: 0; font: 12px/1.45 var(--mono); white-space: pre-wrap; }
.plan-missing .btn { align-self: flex-start; }
.plan-tree { overflow: visible; padding: 4px 0 8px; }
.pn { display: flex; align-items: flex-start; }
.pn-kids { display: flex; flex-direction: column; gap: 10px; padding-left: 26px; position: relative; }
.pn-kid { position: relative; }
.pn-kid::before { content: ''; position: absolute; left: -26px; top: 28px; width: 26px; border-top: 1.5px solid var(--muted); }
.pn-kids::before { content: ''; position: absolute; left: 0; top: 28px; bottom: 0; border-left: 1.5px solid var(--muted); }
.pn-kid:last-child::after { content: ''; position: absolute; left: -26px; top: 29px; bottom: -12px; border-left: 3px solid var(--panel); margin-left: -1px; }
.pn > .pn-box + .pn-kids { margin-left: 0; }
.pn-box { width: 176px; flex: none; text-align: left; font: inherit; color: var(--text); border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 9px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; position: relative; }
.pn-box::after { content: ''; position: absolute; right: -27px; top: 28px; width: 26px; border-top: 1.5px solid var(--muted); }
.pn:not(:has(.pn-kids)) > .pn-box::after { display: none; }
.pn-box:hover { border-color: var(--accent); }
.pn-box.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pn-box.warm { border-left: 4px solid var(--warn); }
.pn-box.hot { border-left: 4px solid var(--danger); }
.pn-op { display: flex; align-items: center; gap: 5px; font-weight: 600; font-size: 12px; }
.pn-op .icon { width: 13px; height: 13px; color: var(--accent); }
.pn-sub, .pn-obj { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pn-obj { font-family: var(--mono); color: var(--text-2); }
.pn-cost { font-size: 11.5px; font-weight: 600; }
.pn-rows, .pn-time { font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.pn-rows.skew { color: var(--danger); font-weight: 600; }
.pn-warn { color: var(--warn); margin-left: auto; }
.pn-par { color: var(--accent); }
.plan-details { width: 300px; flex: none; border-left: 1px solid var(--line); padding: 12px; overflow: auto; background: var(--panel-2); display: flex; flex-direction: column; gap: 8px; }
.plan-details h3 { font-size: 13px; }
.kv { border-collapse: collapse; font-size: 12px; width: 100%; }
.kv th { text-align: left; font-weight: 500; color: var(--muted); padding: 3px 8px 3px 0; vertical-align: top; white-space: nowrap; }
.kv td { padding: 3px 0; font-variant-numeric: tabular-nums; word-break: break-word; }
.kv-block pre { margin: 3px 0 0; font: 11.5px/1.45 var(--mono); white-space: pre-wrap; word-break: break-word; }
@media (max-width: 900px) { .plan-details { display: none; } }
