/* =====================================================================================
   QueryX — dark developer theme
   Tokens first, then layout, then components. Tailwind supplies small utilities only.
   ===================================================================================== */
:root {
  --bg-app: #0e1016;
  --bg-panel: #14171e;
  --bg-sunken: #0b0d12;
  --bg-elevated: #1a1e27;
  --bg-hover: #212633;
  --bg-active: #283043;
  --border: #242a36;
  --border-strong: #323a4a;
  --text: #e4e8f0;
  --text-muted: #9ba4b5;
  --text-dim: #6b7486;
  --accent: #4f8cff;
  --accent-hover: #6a9dff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --success: #3fb950;
  --success-soft: rgba(63, 185, 80, 0.14);
  --warning: #e3a33b;
  --warning-soft: rgba(227, 163, 59, 0.14);
  --danger: #f85149;
  --danger-soft: rgba(248, 81, 73, 0.14);
  --gold: #e3b341;

  /* Lego clause colours */
  --c-select: #4f8cff;
  --c-from: #2dd4bf;
  --c-join: #a78bfa;
  --c-where: #f0b429;
  --c-group: #f472b6;
  --c-having: #fb923c;
  --c-order: #34d399;
  --c-top: #38bdf8;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;

  --sidebar-w: 280px;
  --bottom-h: 36vh;
  --split: 50%;
  --topbar-h: 48px;
  --statusbar-h: 24px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg-app);
  color: var(--text);
  font: 13px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
kbd {
  font: 500 10px/1 var(--mono); padding: 2px 5px; border-radius: 4px;
  border: 1px solid var(--border-strong); background: var(--bg-elevated); color: var(--text-muted);
}
a { color: var(--accent); }
::selection { background: rgba(79, 140, 255, 0.35); }
.hidden { display: none !important; }
.flex-1 { flex: 1 1 auto; }
.mono { font-family: var(--mono); }
.text-muted-c { color: var(--text-muted); }
.text-dim-c { color: var(--text-dim); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2b3242; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #3a4357; background-clip: padding-box; border: 2px solid transparent; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }

.icon { width: 16px; height: 16px; flex: none; display: inline-block; vertical-align: middle; }
.icon.sm { width: 14px; height: 14px; }
.icon.xs { width: 12px; height: 12px; }
.icon.lg { width: 18px; height: 18px; }

/* ================================== App layout ================================== */
.app { display: flex; flex-direction: column; height: 100vh; }
.main { flex: 1; display: flex; min-height: 0; }

.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 10px;
  padding: 0 12px; background: var(--bg-panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; user-select: none; }
/* Wordmark ("QueryX by Quantynx", transparent PNG from packaging/make_brand_assets.py); icon only when narrow */
.brand-wordmark { height: 40px; width: auto; display: block; }
.brand-icon { height: 28px; width: 28px; display: none; }
.welcome-logo { width: 84px; height: 84px; margin-bottom: 8px; filter: drop-shadow(0 6px 18px rgba(56, 132, 255, 0.35)); }
.brand { cursor: pointer; border-radius: 8px; padding: 2px 4px; margin-left: -4px; }
.brand:hover { background: var(--bg-hover); }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* About dialog */
.about { display: flex; flex-direction: column; gap: 14px; font-size: 13px; line-height: 1.6; }
.about-hero { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 0 14px; border-bottom: 1px solid var(--border); }
.about-wordmark { height: 84px; width: auto; }
.about-tagline { font-size: 15px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.about-version { font-size: 11.5px; color: var(--text-dim); }
.about h3 { margin: 0 0 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-dim); }
.about p { margin: 0 0 8px; color: var(--text-muted); }
.about p b { color: var(--text); font-weight: 600; }
.about-contact-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-sunken); }
.about-contact-row a { color: var(--accent); font-weight: 500; text-decoration: none; }
.about-contact-row a:hover { text-decoration: underline; }
.topbar-sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }

.activitybar {
  width: 46px; flex: none; background: var(--bg-panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: 8px 0; gap: 4px;
}
.activitybar button {
  width: 36px; height: 36px; border-radius: var(--radius); color: var(--text-dim); display: grid; place-items: center;
  position: relative;
}
.activitybar button .icon { width: 19px; height: 19px; }
.activitybar button:hover { color: var(--text); background: var(--bg-hover); }
.activitybar button.active { color: var(--text); }
.activitybar button.active::before {
  content: ''; position: absolute; left: -5px; top: 8px; bottom: 8px; width: 2px; border-radius: 2px; background: var(--accent);
}
.activitybar .spacer { flex: 1; }

.sidebar {
  width: var(--sidebar-w); min-width: 200px; max-width: 520px; flex: none; display: flex; flex-direction: column;
  background: var(--bg-panel); border-right: 1px solid var(--border); min-height: 0;
}
body.explorer-collapsed .sidebar, body.explorer-collapsed .resizer[data-resize="sidebar"] { display: none; }
.sidebar-search { padding: 10px 10px 6px; }
.sidebar-scroll { flex: 1; overflow: auto; display: flex; flex-direction: column; min-height: 0; }

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.editor-area { flex: 1; min-height: 120px; display: flex; flex-direction: column; }
.workspace-toolbar {
  height: 42px; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 10px 0 14px; border-bottom: 1px solid var(--border); background: var(--bg-app);
}
.doc-title { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.doc-title > span:first-child { color: var(--text-dim); display: flex; }
.dirty-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); flex: none; }

.workspace-panes { flex: 1; display: flex; min-height: 0; }
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.builder-pane { flex: 0 0 var(--split); background: var(--bg-app); }
.editor-pane { flex: 1; background: var(--bg-sunken); }
.workspace-panes[data-mode="visual"] .editor-pane,
.workspace-panes[data-mode="visual"] .resizer,
.workspace-panes[data-mode="sql"] .builder-pane,
.workspace-panes[data-mode="sql"] .resizer { display: none; }
.workspace-panes[data-mode="visual"] .builder-pane { flex: 1; }

body.focus-mode .sidebar, body.focus-mode .activitybar, body.focus-mode .resizer[data-resize="sidebar"],
body.focus-mode .bottom-panel, body.focus-mode .resizer[data-resize="bottom"] { display: none; }
body.panel-max .editor-area, body.panel-max .resizer[data-resize="bottom"] { display: none; }
body.panel-max .bottom-panel { flex: 1; height: auto; }

.resizer { flex: none; background: transparent; position: relative; z-index: 5; }
.resizer-v { width: 5px; margin: 0 -2px; cursor: col-resize; }
.resizer-h { height: 5px; margin: -2px 0; cursor: row-resize; }
.resizer:hover, .resizer.dragging { background: var(--accent); opacity: 0.6; }
body.resizing { user-select: none; }
body.resizing iframe { pointer-events: none; }

.bottom-panel {
  height: var(--bottom-h); min-height: 90px; flex: none; display: flex; flex-direction: column;
  background: var(--bg-panel); border-top: 1px solid var(--border);
}
.panel-tabs {
  height: 36px; flex: none; display: flex; align-items: stretch; gap: 2px; padding: 0 8px;
  border-bottom: 1px solid var(--border);
}
.panel-tabs > button[data-tab] {
  padding: 0 12px; color: var(--text-dim); font-weight: 500; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.04em; border-bottom: 2px solid transparent; display: flex; align-items: center; gap: 6px;
}
.panel-tabs > button[data-tab]:hover { color: var(--text); }
.panel-tabs > button[data-tab].active { color: var(--text); border-bottom-color: var(--accent); }
.tab-count:not(:empty) {
  font: 600 10px/1 var(--font); padding: 2px 6px; border-radius: 10px; background: var(--bg-active); color: var(--text-muted);
  text-transform: none; letter-spacing: 0;
}
.tab-count.danger:not(:empty) { background: var(--danger-soft); color: var(--danger); }
.panel-body { flex: 1; min-height: 0; position: relative; }
.panel-view { position: absolute; inset: 0; display: none; flex-direction: column; min-height: 0; }
.panel-view.active { display: flex; }
.exec-summary { display: flex; align-items: center; gap: 14px; color: var(--text-muted); font-size: 12px; margin-right: 8px; }
.exec-summary .ok { color: var(--success); }
.exec-summary .bad { color: var(--danger); }
.exec-summary span { display: inline-flex; align-items: center; gap: 5px; }

.statusbar {
  height: var(--statusbar-h); flex: none; display: flex; align-items: center; gap: 16px; padding: 0 12px;
  background: #11141b; border-top: 1px solid var(--border); color: var(--text-dim); font-size: 11.5px;
}
.statusbar span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.statusbar .icon { width: 12px; height: 12px; }
.statusbar .ok { color: var(--success); }
.statusbar .warn { color: var(--warning); }
.statusbar .bad { color: var(--danger); }

/* ================================== Controls ================================== */
.btn {
  height: 30px; padding: 0 12px; border-radius: var(--radius-sm); display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border-strong); background: var(--bg-elevated); color: var(--text); font-weight: 500;
  white-space: nowrap; transition: background 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); border-color: #3d4659; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--bg-hover); border-color: transparent; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-run { background: var(--success); border: 1px solid var(--success); color: #06140a; font-weight: 600; padding: 0 14px; }
.btn-run:hover:not(:disabled) { filter: brightness(1.08); background: var(--success); }
.btn-run.running { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); background: var(--danger); }
.btn-sm { height: 26px; padding: 0 9px; font-size: 12px; gap: 5px; }
.btn-xs { height: 22px; padding: 0 7px; font-size: 11.5px; gap: 4px; border-radius: 5px; }
.btn-dashed { border-style: dashed; background: transparent; color: var(--text-muted); }
.btn-dashed:hover:not(:disabled) { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }

.icon-btn {
  width: 26px; height: 26px; border-radius: var(--radius-sm); display: inline-grid; place-items: center;
  color: var(--text-dim); flex: none;
}
.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--bg-hover); }
.icon-btn.lg { width: 32px; height: 32px; }
.icon-btn.active { color: var(--accent); background: var(--accent-soft); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.icon-btn.fav.on { color: var(--gold); }
.icon-btn.fav.on svg { fill: var(--gold); }

.input, .select, .textarea {
  height: 32px; width: 100%; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--bg-sunken); color: var(--text); outline: none; transition: border-color 0.12s, box-shadow 0.12s;
}
.textarea { height: auto; padding: 8px 10px; resize: vertical; min-height: 70px; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder, .textarea::placeholder { color: var(--text-dim); }
.input-sm { height: 26px; font-size: 12px; padding: 0 8px; }
.select { appearance: none; padding-right: 26px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ba4b5' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 7px center; background-size: 13px; }
.select option, .select optgroup { background: var(--bg-elevated); color: var(--text); }
input[type="date"], input[type="datetime-local"], input[type="time"] { color-scheme: dark; }

.select-btn {
  height: 30px; display: inline-flex; align-items: center; gap: 8px; padding: 0 10px; min-width: 180px; max-width: 260px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--bg-sunken);
}
.select-btn:hover { border-color: #3d4659; }
.select-btn-label { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-btn .chev { width: 10px; height: 10px; border-right: 1.5px solid var(--text-muted); border-bottom: 1.5px solid var(--text-muted); transform: rotate(45deg) translate(-2px, -2px); }
.select-wrap { position: relative; width: 190px; }
.select-wrap .select { height: 30px; padding-left: 30px; }
.select-wrap .select-icon { position: absolute; left: 9px; top: 7px; color: var(--text-dim); pointer-events: none; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); flex: none; }
.status-dot.on { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 11px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
}
.status-pill.connected { background: var(--success-soft); color: var(--success); }
.status-pill.disconnected { background: var(--bg-elevated); color: var(--text-dim); }
.status-pill.busy { background: var(--accent-soft); color: var(--accent); }

.segmented { display: inline-flex; padding: 2px; border-radius: var(--radius); background: var(--bg-panel); border: 1px solid var(--border); }
.segmented button { height: 26px; padding: 0 12px; border-radius: 6px; color: var(--text-muted); font-weight: 500; font-size: 12.5px; }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--bg-active); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.4); }
.segmented button.muted-tab { color: var(--text-dim); }
.segmented.sm button { height: 22px; padding: 0 8px; font-size: 11.5px; }

.search-box {
  display: flex; align-items: center; gap: 7px; height: 32px; padding: 0 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-sunken);
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box input { flex: 1; min-width: 0; background: none; border: 0; outline: none; }
.search-box input::-webkit-search-cancel-button { filter: invert(0.6); }
.search-icon { color: var(--text-dim); display: flex; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.field .help { font-size: 11.5px; color: var(--text-dim); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; color: var(--text-muted); }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }
.switch { position: relative; width: 30px; height: 17px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 10px; background: var(--border-strong); transition: 0.15s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; width: 13px; height: 13px; left: 2px; top: 2px; border-radius: 50%; background: #cfd5e1; transition: 0.15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(13px); background: #fff; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 18px; padding: 0 6px; border-radius: 4px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.02em; background: var(--bg-active); color: var(--text-muted); white-space: nowrap;
}
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.tag { display: inline-flex; align-items: center; height: 18px; padding: 0 7px; border-radius: 9px; font-size: 11px; background: #232a3a; color: #aab6d3; }

.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 24px; text-align: center; color: var(--text-dim); }
.empty-state .icon { width: 30px; height: 30px; color: #3a4357; margin-bottom: 4px; }
.empty-state h3 { margin: 0; font-size: 14px; color: var(--text-muted); font-weight: 600; }
.empty-state p { margin: 0; max-width: 360px; }

.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.7s linear infinite; flex: none; }
.spinner.lg { width: 26px; height: 26px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { height: 12px; border-radius: 4px; background: linear-gradient(90deg, #1b202b 25%, #242b39 50%, #1b202b 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ================================== Sidebar sections ================================== */
.side-section { border-bottom: 1px solid var(--border); }
.side-section.grow { flex: 1; border-bottom: 0; display: flex; flex-direction: column; min-height: 0; }
.section-header {
  height: 32px; display: flex; align-items: center; gap: 6px; padding: 0 8px 0 10px; cursor: pointer; user-select: none;
  font-size: 11px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted);
}
.section-header:hover { color: var(--text); }
.section-header .chev-icon { transition: transform 0.15s; color: var(--text-dim); }
.section-header.collapsed .chev-icon { transform: rotate(-90deg); }
.section-header .actions { margin-left: auto; display: flex; gap: 2px; opacity: 0.8; }
.section-body { padding: 0 6px 8px; }
.section-header.collapsed + .section-body { display: none; }

.conn-item {
  display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: var(--radius-sm); cursor: pointer;
}
.conn-item:hover { background: var(--bg-hover); }
.conn-item.active { background: var(--bg-active); }
.conn-item .conn-icon { color: var(--text-dim); display: flex; position: relative; }
.conn-item.active .conn-icon { color: var(--success); }
.conn-item .meta { min-width: 0; flex: 1; }
.conn-item .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn-item .sub { font-size: 11.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn-item .row-actions { display: none; gap: 1px; }
.conn-dot { position: absolute; right: -2px; bottom: -2px; width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 0 2px var(--bg-panel); }
.conn-dot.static { position: static; display: inline-block; box-shadow: none; }
.conn-item.connected .conn-icon { color: var(--text-muted); }
.qtab-conn { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.qtab-conn.off { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-dim); }
.conn-item:hover .row-actions { display: flex; }

/* Tree */
.tree { padding: 2px 4px 12px; font-size: 12.5px; flex: 1; overflow: auto; min-height: 0; }
.tree-row {
  display: flex; align-items: center; gap: 5px; height: 25px; padding-right: 6px; border-radius: 5px; cursor: pointer;
  white-space: nowrap; user-select: none; position: relative;
}
.tree-row:hover { background: var(--bg-hover); }
.tree-row.selected { background: var(--bg-active); }
.tree-row:focus { outline: 1px solid var(--accent); outline-offset: -1px; }
.tree-row .twisty { width: 16px; display: grid; place-items: center; color: var(--text-dim); flex: none; }
.tree-row .twisty .icon { width: 12px; height: 12px; transition: transform 0.12s; }
.tree-row.open > .twisty .icon { transform: rotate(90deg); }
.tree-row .node-icon { display: flex; flex: none; }
.tree-row .label { overflow: hidden; text-overflow: ellipsis; }
.tree-row .label .schema-prefix { color: var(--text-dim); }
.tree-row .count { color: var(--text-dim); font-size: 11px; margin-left: 2px; }
.tree-row .dtype { color: var(--text-dim); font: 11px var(--mono); margin-left: auto; padding-left: 8px; }
.tree-row .nullmark { font: 10px var(--mono); color: var(--text-dim); }
.tree-row .row-actions { display: none; margin-left: auto; gap: 1px; }
.tree-row:hover .row-actions { display: flex; }
.tree-row:hover .dtype { display: none; }
.tree-row .row-actions .icon-btn { width: 21px; height: 21px; }
.tree-row .row-actions .icon { width: 13px; height: 13px; }
.ni-db { color: #7aa2ff; } .ni-schema { color: #8b93a7; } .ni-folder { color: #c9a45c; }
.ni-table { color: #4fb6ff; } .ni-view { color: #b58cff; } .ni-proc { color: #f0a35c; } .ni-func { color: #5fd3a6; }
.ni-col { color: #7d879b; } .ni-pk { color: var(--gold); } .ni-fk { color: #5fa8ff; }
.tree-row.dragging { opacity: 0.5; }
.tree-message { padding: 10px 12px; color: var(--text-dim); font-size: 12px; }

/* Search results */
.search-results { padding: 2px 6px 12px; overflow: auto; flex: 1; }
.result-group-title {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 6px 4px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; color: var(--text-dim); text-transform: uppercase;
}
.result-item {
  display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 5px; cursor: pointer; min-height: 28px;
}
.result-item:hover, .result-item.focused { background: var(--bg-hover); }
.result-item.focused { box-shadow: inset 2px 0 0 var(--accent); }
.result-item .main-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-item .sub-text { color: var(--text-dim); font-size: 11.5px; }
.result-item mark { background: rgba(240, 180, 41, 0.22); color: #ffd36a; border-radius: 2px; padding: 0 1px; }
.result-item .row-actions { display: none; gap: 3px; }
.result-item:hover .row-actions, .result-item.focused .row-actions { display: flex; }
.result-cols { margin: 2px 0 6px 22px; border-left: 1px solid var(--border); padding-left: 6px; }

/* ================================== Visual builder ================================== */
.builder-scroll { flex: 1; overflow: auto; padding: 14px 16px 40px; }
.builder-banner {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; margin-bottom: 12px; border-radius: var(--radius);
  background: var(--warning-soft); color: #f3c878; border: 1px solid rgba(227, 163, 59, 0.3); font-size: 12.5px;
}
.builder-banner .icon { color: var(--warning); }
.builder-banner.info { background: var(--accent-soft); border-color: rgba(79,140,255,.3); color: #a9c4ff; }
.builder-banner.info .icon { color: var(--accent); }
.builder-warnings { margin: -4px 0 12px; display: flex; flex-direction: column; gap: 4px; }
.builder-warnings div { display: flex; gap: 6px; align-items: flex-start; font-size: 12px; color: #e6b863; }

.clause {
  --clause: var(--accent);
  position: relative; margin: 0 0 10px; border-radius: var(--radius-lg); background: var(--bg-panel);
  border: 1px solid var(--border); transition: border-color 0.15s, box-shadow 0.15s;
}
.clause::before {
  content: ''; position: absolute; left: -1px; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: var(--clause);
}
.clause:hover { border-color: var(--border-strong); }
.clause.drop-target { border-color: var(--clause); box-shadow: 0 0 0 3px color-mix(in srgb, var(--clause) 22%, transparent); }
.clause.empty-clause { background: color-mix(in srgb, var(--bg-panel) 60%, var(--bg-app)); }
.clause[data-clause="select"] { --clause: var(--c-select); }
.clause[data-clause="from"] { --clause: var(--c-from); }
.clause[data-clause="join"] { --clause: var(--c-join); }
.clause[data-clause="where"] { --clause: var(--c-where); }
.clause[data-clause="group"] { --clause: var(--c-group); }
.clause[data-clause="having"] { --clause: var(--c-having); }
.clause[data-clause="order"] { --clause: var(--c-order); }
.clause[data-clause="top"] { --clause: var(--c-top); }

.clause-header { display: flex; align-items: center; gap: 10px; padding: 9px 12px 9px 14px; cursor: pointer; user-select: none; }
.clause-tag {
  font: 700 11px/1 var(--mono); letter-spacing: 0.04em; padding: 5px 8px; border-radius: 6px;
  color: var(--clause); background: color-mix(in srgb, var(--clause) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--clause) 30%, transparent);
}
.clause-title { color: var(--text-muted); font-size: 12px; }
.clause-summary { color: var(--text-dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; font-family: var(--mono); }
.clause-header .chev-icon { color: var(--text-dim); transition: transform 0.15s; }
.clause.collapsed .clause-header .chev-icon { transform: rotate(-90deg); }
.clause.collapsed .clause-body { display: none; }
.clause-header .header-controls { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.clause-body { padding: 2px 14px 12px; }
.clause-hint { color: var(--text-dim); font-size: 12px; padding: 4px 0 8px; }

/* Lego pieces */
.pieces { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.piece {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 6px 0 4px; border-radius: 8px;
  background: color-mix(in srgb, var(--clause) 10%, var(--bg-elevated));
  border: 1px solid color-mix(in srgb, var(--clause) 30%, var(--border));
  box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--clause) 22%, transparent);
  position: relative; max-width: 100%;
}
.piece:hover { border-color: color-mix(in srgb, var(--clause) 55%, var(--border)); }
.piece.dragging { opacity: 0.4; }
.piece.drag-over { outline: 2px dashed var(--clause); outline-offset: 2px; }
.piece .grip { color: var(--text-dim); cursor: grab; display: flex; }
.piece .grip .icon { width: 13px; height: 13px; }
.piece .piece-name { font: 500 12.5px var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.piece .piece-name .q { color: var(--text-dim); }
.piece .piece-type { color: var(--text-dim); display: flex; }
.piece .piece-type .icon { width: 13px; height: 13px; }
.piece select.mini, .piece input.mini, .row select.mini, .row input.mini {
  height: 22px; font-size: 11.5px; border-radius: 5px; border: 1px solid var(--border-strong); background: var(--bg-sunken);
  padding: 0 6px; outline: none;
}
.piece select.mini { padding-right: 18px; background-position: right 3px center; background-size: 11px; }
.piece input.mini.alias { width: 96px; font-family: var(--mono); }
.piece .as { color: var(--text-dim); font: 600 10.5px var(--mono); }
.piece .remove { width: 20px; height: 20px; }
.piece .remove .icon { width: 12px; height: 12px; }
.piece.table-piece { height: 36px; padding: 0 8px; }
.piece.table-piece .piece-name { font-size: 13px; }
.piece.agg-on .piece-name::before { content: attr(data-agg); color: var(--clause); margin-right: 1px; }

.dropzone {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 10px; border-radius: var(--radius);
  border: 1.5px dashed var(--border-strong); color: var(--text-dim); cursor: pointer; text-align: center; transition: 0.15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--clause); color: var(--text); background: color-mix(in srgb, var(--clause) 8%, transparent); }

.rows { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row .connector {
  width: 50px; height: 26px; border-radius: 6px; font: 700 11px var(--mono); color: var(--clause);
  background: color-mix(in srgb, var(--clause) 12%, transparent); border: 1px solid color-mix(in srgb, var(--clause) 28%, transparent);
}
.row .connector.first { visibility: hidden; }
.row .connector:hover { filter: brightness(1.2); }
.row .col-btn { max-width: 260px; }
.row select.op { width: auto; min-width: 110px; }
.row .value-input { width: 180px; }
.row .value-input.wide { width: 260px; }
.row .and-text { color: var(--text-dim); font: 600 11px var(--mono); }
.row .row-end { margin-left: auto; display: flex; gap: 2px; }
.filter-group {
  border: 1px dashed color-mix(in srgb, var(--clause) 40%, var(--border)); border-radius: var(--radius); padding: 8px; flex: 1; min-width: 0;
  background: color-mix(in srgb, var(--clause) 4%, transparent);
}
.filter-group > .group-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 11px; color: var(--text-dim); }
.clause-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

.col-btn {
  height: 28px; display: inline-flex; align-items: center; gap: 6px; padding: 0 8px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--bg-sunken); font: 12px var(--mono); max-width: 100%;
}
.col-btn:hover { border-color: #3d4659; }
.col-btn.placeholder { color: var(--text-dim); font-family: var(--font); }
.col-btn .col-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-btn .icon { width: 13px; height: 13px; color: var(--text-dim); }

.join-block {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elevated); padding: 10px; margin-bottom: 8px;
}
.join-block.suggested { border-color: color-mix(in srgb, var(--c-join) 45%, var(--border)); background: color-mix(in srgb, var(--c-join) 6%, var(--bg-elevated)); }
.join-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.join-head select.join-type { width: 150px; height: 28px; font: 600 11.5px var(--mono); }
.join-conds { margin: 8px 0 0 14px; padding-left: 10px; border-left: 2px solid color-mix(in srgb, var(--c-join) 35%, transparent); }
.join-conds .on { font: 700 11px var(--mono); color: var(--c-join); width: 30px; }
.suggest-bar {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: var(--radius-sm); margin-bottom: 8px;
  background: color-mix(in srgb, var(--c-join) 10%, transparent); border: 1px solid color-mix(in srgb, var(--c-join) 30%, transparent);
  font-size: 12px; flex-wrap: wrap;
}
.suggest-bar .icon { color: var(--c-join); }
.suggest-bar code { font: 12px var(--mono); color: var(--text); }
.dir-toggle button { font: 600 11px var(--mono); }

.limit-row { display: flex; align-items: center; gap: 10px; }
.limit-row input { width: 120px; }

/* Column / table picker popover */
.popover {
  position: fixed; z-index: 1000; background: var(--bg-elevated); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 180px; max-height: min(460px, calc(100vh - 20px)); display: flex; flex-direction: column; overflow: hidden;
  animation: pop 0.12s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-3px); } }
.picker-search { padding: 8px; border-bottom: 1px solid var(--border); display: flex; gap: 6px; align-items: center; }
.picker { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.picker-list { overflow: auto; padding: 4px; flex: 1; min-height: 0; }
.popover.popover-tall { max-height: min(620px, calc(100vh - 20px)); }
.suggest-list { max-height: 190px; overflow-y: auto; padding-right: 2px; margin-bottom: 8px; }
.suggest-list .suggest-bar { margin-bottom: 6px; }
.suggest-list .suggest-bar:last-child { margin-bottom: 0; }
.suggest-count { font-size: 11px; padding: 2px 4px 6px; }
.picker-group { padding: 8px 8px 4px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; color: var(--text-dim); text-transform: uppercase; display: flex; align-items: center; gap: 6px; }
.picker-group button { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--accent); font-size: 11px; }
.picker-item { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 5px; cursor: pointer; min-height: 28px; }
.picker-item:hover, .picker-item.focused { background: var(--bg-hover); }
.picker-item.selected { background: var(--accent-soft); }
.picker-item .pi-name { flex: 1; font: 12.5px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-item .pi-type { color: var(--text-dim); font: 11px var(--mono); }
.picker-item input[type="checkbox"] { accent-color: var(--accent); }
.picker-footer { padding: 6px 8px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; color: var(--text-dim); font-size: 11.5px; }

.menu { padding: 4px; display: flex; flex-direction: column; min-width: 200px; overflow-y: auto; min-height: 0; }
.menu > * { flex-shrink: 0; }
.menu-item { display: flex; align-items: center; gap: 9px; padding: 6px 10px; border-radius: 5px; text-align: left; color: var(--text); font-size: 12.5px; }
.menu-item:hover:not(:disabled) { background: var(--bg-hover); }
.menu-item .icon { color: var(--text-muted); width: 14px; height: 14px; }
.menu-item kbd { margin-left: auto; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger .icon { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.menu-heading { padding: 6px 10px 3px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }

/* ================================== SQL editor ================================== */
.editor-toolbar {
  height: 38px; flex: none; display: flex; align-items: center; gap: 4px; padding: 0 8px; border-bottom: 1px solid var(--border); background: var(--bg-panel);
}
.editor-toolbar .label { font: 700 11px var(--mono); color: var(--text-dim); letter-spacing: 0.06em; margin-right: 6px; padding-left: 4px; }
.editor-host { flex: 1; min-height: 0; position: relative; }
.editor-fallback {
  position: absolute; inset: 0; width: 100%; height: 100%; resize: none; border: 0; outline: none; padding: 12px 14px;
  background: var(--bg-sunken); color: #d7dce6; font: 13.5px/1.6 var(--mono); tab-size: 4;
}
.sync-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-dim); margin-right: 4px; white-space: nowrap; }
.sync-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
.sync-badge.manual .dot { background: var(--warning); }
.sync-badge button { color: var(--accent); font-size: 11.5px; }
.sync-badge button:hover { text-decoration: underline; }

/* ================================== Results grid ================================== */
.grid-toolbar { height: 38px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 10px; border-bottom: 1px solid var(--border); }
.grid-toolbar .search-box { height: 26px; width: 240px; }
.link-btn { color: var(--accent); font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.link-btn:hover { text-decoration: underline; }
/* Column header filter button + dropdown */
/* Date-only / date & time toggle on WHERE conditions over date-time columns */
.day-toggle { color: var(--text-dim); }
.day-toggle.on { color: var(--accent); background: var(--accent-soft); }
.hcell .hfilter { margin-left: auto; width: 20px; height: 20px; border-radius: 4px; display: grid; place-items: center; flex: none;
  color: var(--text-dim); opacity: 0; transition: opacity 0.12s; }
.hcell:hover .hfilter, .hcell .hfilter:focus-visible { opacity: 1; }
.hcell .hfilter:hover { background: var(--bg-hover); color: var(--text); }
.hcell .hfilter.active { opacity: 1; color: var(--accent); background: var(--accent-soft); }
.hcell.filtered .hname { color: var(--accent-hover); }
.hcell .sort + .hfilter { margin-left: 2px; }
.colfilter { display: flex; flex-direction: column; min-height: 0; max-height: inherit; }
.colfilter-head { display: flex; align-items: center; gap: 6px; padding: 9px 10px 0; font-size: 12px; color: var(--text-muted); }
.colfilter-head b { color: var(--text); font-weight: 600; }
.colfilter-all { display: flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 12px; color: var(--text-muted); border-bottom: 1px solid var(--border); cursor: pointer; }
.colfilter-list { overflow: auto; padding: 4px; flex: 1; min-height: 60px; max-height: 300px; }
.colfilter-item { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 5px; cursor: pointer; font: 12.5px var(--mono); }
.colfilter-item:hover { background: var(--bg-hover); }
.colfilter-item .cf-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.colfilter-item .cf-special { color: var(--text-dim); font-style: italic; }
.colfilter-item .cf-count { color: var(--text-dim); font-size: 11px; }
.colfilter input[type="checkbox"] { accent-color: var(--accent); }
.colfilter-note { padding: 0 12px; font-size: 11px; color: var(--text-dim); }
.colfilter-note:empty { display: none; }
.colfilter-actions { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--border); }
/* Result-set tabs (scripts with several queries) */
.rs-tabs { display: flex; align-items: center; gap: 2px; min-width: 0; max-width: 55%; overflow-x: auto; scrollbar-width: thin; flex: none; }
.rs-tabs[hidden] { display: none; }
.rs-tab { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 6px; white-space: nowrap;
  font-size: 12px; color: var(--text-muted); border: 1px solid transparent; flex: none; }
.rs-tab:hover { background: var(--bg-hover); color: var(--text); }
.rs-tab.active { background: var(--accent-soft); color: var(--text); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.rs-tab .rs-count { font: 11px var(--mono); color: var(--text-dim); }
.rs-tab.active .rs-count { color: var(--accent-hover); }
.rs-tab.error { color: var(--danger); }
.rs-tab.error.active { background: color-mix(in srgb, var(--danger) 14%, transparent); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.grid-toolbar .info { color: var(--text-dim); font-size: 12px; white-space: nowrap; }
.grid-toolbar .info b { color: var(--text-muted); font-weight: 600; }
.grid-viewport { flex: 1; overflow: auto; position: relative; background: var(--bg-sunken); outline: none; }
.grid-inner { position: relative; min-width: 100%; }
.grid-header { position: sticky; top: 0; z-index: 3; display: grid; background: #161a22; border-bottom: 1px solid var(--border-strong); }
.grid-row { display: grid; position: absolute; left: 0; right: 0; height: 26px; }
.grid-row:nth-child(even) .gcell { background: #0f1218; }
.grid-row:hover .gcell { background: #171c26; }
.gcell {
  height: 26px; line-height: 26px; padding: 0 8px; border-right: 1px solid #1c212c; border-bottom: 1px solid #161b24;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 12.5px var(--mono); color: #d3d9e4; background: var(--bg-sunken);
  cursor: cell; user-select: none;
}
.gcell.num { text-align: right; color: #b5d7ff; }
.gcell.rownum { color: var(--text-dim); text-align: right; font-size: 11px; background: #12151c !important; position: sticky; left: 0; z-index: 1; cursor: pointer; }
.gcell.null { color: #5d6678; font-style: italic; }
.gcell.bool { color: #e7a95b; }
.gcell.sel { background: rgba(79, 140, 255, 0.22) !important; color: #fff; }
.gcell.anchor { box-shadow: inset 0 0 0 1.5px var(--accent); }
.hcell {
  position: relative; height: 30px; display: flex; align-items: center; gap: 5px; padding: 0 8px; border-right: 1px solid var(--border);
  font: 600 12px var(--font); color: var(--text); user-select: none; cursor: pointer; overflow: hidden; background: #161a22;
}
.hcell:hover { background: #1c212b; }
.hcell .hname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hcell .htype { color: var(--text-dim); display: flex; }
.hcell .htype .icon { width: 12px; height: 12px; }
.hcell .sort { color: var(--accent); display: flex; margin-left: auto; }
.hcell .sort .icon { width: 12px; height: 12px; }
.hcell.rownum-h { position: sticky; left: 0; z-index: 4; cursor: default; }
.col-resize { position: absolute; right: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 2; }
.col-resize:hover, .col-resize.active { background: var(--accent); opacity: 0.6; }
.grid-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; color: var(--text-muted); background: rgba(11, 13, 18, 0.94); z-index: 10; }
.grid-footer { height: 28px; flex: none; display: flex; align-items: center; gap: 14px; padding: 0 10px; border-top: 1px solid var(--border); color: var(--text-dim); font-size: 11.5px; }
.grid-footer .warn { color: var(--warning); display: inline-flex; align-items: center; gap: 5px; }

/* ================================== Messages / history / saved ================================== */
.list-toolbar { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.list-toolbar .search-box { height: 28px; width: 260px; }
.list-toolbar .select { height: 28px; width: auto; min-width: 120px; font-size: 12px; }
.list-scroll { flex: 1; overflow: auto; padding: 4px 10px 16px; }
.list-group-title { position: sticky; top: 0; z-index: 1; background: var(--bg-panel); padding: 10px 2px 6px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; color: var(--text-dim); text-transform: uppercase; }

.hist-item { display: grid; grid-template-columns: 18px 1fr auto; gap: 10px; align-items: start; padding: 8px 10px; border-radius: var(--radius); border: 1px solid transparent; }
.hist-item:hover { background: var(--bg-elevated); border-color: var(--border); }
.hist-item .status-icon { margin-top: 2px; }
.hist-item .status-icon.success { color: var(--success); }
.hist-item .status-icon.error { color: var(--danger); }
.hist-item .status-icon.blocked { color: var(--warning); }
.hist-item .status-icon.cancelled { color: var(--text-dim); }
.hist-item .sql-preview { font: 12px/1.5 var(--mono); color: #cfd6e3; white-space: pre-wrap; word-break: break-word; max-height: 38px; overflow: hidden; cursor: pointer; }
.hist-item .meta { display: flex; gap: 12px; flex-wrap: wrap; color: var(--text-dim); font-size: 11.5px; margin-top: 4px; }
.hist-item .meta span { display: inline-flex; align-items: center; gap: 4px; }
.hist-item .meta .icon { width: 12px; height: 12px; }
.hist-item .err { color: #f29a95; font-size: 11.5px; margin-top: 3px; }
.hist-item .actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.1s; }
.hist-item:hover .actions, .hist-item .actions .fav.on { opacity: 1; }
.hist-item:hover .actions .fav { opacity: 1; }

.saved-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; padding: 10px; }
.saved-card { border: 1px solid var(--border); background: var(--bg-elevated); border-radius: var(--radius-lg); padding: 12px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.saved-card:hover { border-color: var(--border-strong); }
.saved-card .title { display: flex; align-items: center; gap: 6px; }
.saved-card .title h4 { margin: 0; font-size: 13.5px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.saved-card .title h4:hover { color: var(--accent); }
.saved-card .desc { color: var(--text-muted); font-size: 12px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.saved-card pre { margin: 0; font: 11.5px/1.5 var(--mono); color: #aeb7c7; background: var(--bg-sunken); border-radius: 6px; padding: 8px; max-height: 70px; overflow: hidden; white-space: pre-wrap; word-break: break-word; }
.saved-card .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; color: var(--text-dim); font-size: 11.5px; }
.saved-card .actions { display: flex; gap: 4px; margin-top: 2px; }

.msg-item { display: grid; grid-template-columns: 70px 18px 1fr; gap: 8px; padding: 7px 4px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.msg-item .time { color: var(--text-dim); font: 11.5px var(--mono); padding-top: 1px; }
.msg-item .icon { margin-top: 1px; }
.msg-item.success .icon { color: var(--success); }
.msg-item.error .icon { color: var(--danger); }
.msg-item.warning .icon { color: var(--warning); }
.msg-item.info .icon { color: var(--accent); }
.msg-item .sql { font: 11.5px var(--mono); color: var(--text-dim); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.error-block { border: 1px solid rgba(248, 81, 73, 0.35); background: var(--danger-soft); border-radius: var(--radius); padding: 10px 12px; }
.error-block .error-head { display: flex; gap: 9px; align-items: flex-start; }
.error-block .error-head .icon { color: var(--danger); margin-top: 1px; }
.error-block .error-message { color: #ffb4ae; font-weight: 500; }
.error-block .error-hint { color: var(--text-muted); font-size: 12px; margin-top: 3px; }
.error-details { margin-top: 8px; }
.error-details summary { cursor: pointer; color: var(--text-dim); font-size: 12px; user-select: none; }
.error-details summary:hover { color: var(--text); }
.error-details pre { margin: 6px 0 0; padding: 8px 10px; background: var(--bg-sunken); border-radius: 6px; font: 11.5px/1.5 var(--mono); color: #c9d1de; white-space: pre-wrap; word-break: break-word; max-height: 180px; overflow: auto; }
.success-block { border: 1px solid rgba(63, 185, 80, 0.35); background: var(--success-soft); border-radius: var(--radius); padding: 10px 12px; display: flex; gap: 9px; color: #9be3a8; }
.success-block .icon { color: var(--success); margin-top: 1px; }

/* ================================== Modal, toast, tooltip ================================== */
.modal-backdrop { position: fixed; inset: 0; z-index: 900; background: rgba(5, 7, 10, 0.62); display: flex; align-items: flex-start; justify-content: center; padding-top: 8vh; animation: fade 0.12s ease-out; backdrop-filter: blur(2px); }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--bg-panel); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow); max-height: 84vh; display: flex; flex-direction: column; animation: pop 0.14s ease-out; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; }
.modal-header h2 { margin: 0; font-size: 15px; font-weight: 650; }
.modal-body { padding: 4px 16px 16px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--bg-app); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.modal-footer .left { margin-right: auto; display: flex; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span-2 { grid-column: span 2; }
.form-section-title { font-size: 11px; font-weight: 700; letter-spacing: 0.07em; color: var(--text-dim); text-transform: uppercase; margin-top: 4px; }
.auth-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.auth-card { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--bg-sunken); cursor: pointer; text-align: left; }
.auth-card:hover { border-color: #3d4659; }
.auth-card.active { border-color: var(--accent); background: var(--accent-soft); }
.auth-card .icon { color: var(--accent); margin-top: 2px; }
.auth-card b { display: block; font-weight: 600; font-size: 12.5px; }
.auth-card small { color: var(--text-dim); font-size: 11.5px; }

.palette { width: min(640px, calc(100vw - 32px)); }
.palette .modal-header { display: none; }
.palette .modal-body { padding: 0; gap: 0; }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.palette-input input { flex: 1; background: none; border: 0; outline: none; font-size: 15px; }
.palette-results { max-height: 56vh; overflow: auto; padding: 4px 8px 10px; }
.palette-footer { display: flex; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--border); color: var(--text-dim); font-size: 11.5px; }

.toast-root { position: fixed; right: 16px; bottom: 36px; z-index: 1100; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { display: flex; align-items: flex-start; gap: 10px; min-width: 260px; max-width: 420px; padding: 10px 10px 10px 12px; border-radius: var(--radius); background: var(--bg-elevated); border: 1px solid var(--border-strong); box-shadow: var(--shadow); animation: slidein 0.18s ease-out; }
.toast.leaving { opacity: 0; transform: translateX(10px); transition: 0.18s; }
@keyframes slidein { from { opacity: 0; transform: translateY(8px); } }
.toast > .icon { margin-top: 1px; }
.toast-success > .icon { color: var(--success); }
.toast-error > .icon { color: var(--danger); }
.toast-warning > .icon { color: var(--warning); }
.toast-info > .icon { color: var(--accent); }
.toast-body { flex: 1; min-width: 0; }
.toast-details { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.toast-close { width: 20px; height: 20px; }

.tooltip { position: fixed; z-index: 1200; pointer-events: none; padding: 5px 8px; border-radius: 6px; background: #252b38; border: 1px solid #343c4d; color: var(--text); font-size: 11.5px; max-width: 300px; opacity: 0; transform: translateY(2px); transition: opacity 0.1s, transform 0.1s; box-shadow: 0 4px 14px rgba(0,0,0,.4); }
.tooltip.show { opacity: 1; transform: none; }
.tooltip kbd { margin: 0 1px; }

/* ================================== AI drawer ================================== */
.ai-drawer { width: 0; flex: none; overflow: hidden; background: var(--bg-panel); border-left: 1px solid var(--border); transition: width 0.18s ease; display: flex; flex-direction: column; }
body.ai-open .ai-drawer { width: 360px; }
.ai-inner { width: 360px; display: flex; flex-direction: column; height: 100%; }
.ai-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 10px 14px; border-bottom: 1px solid var(--border); }
.ai-head h3 { margin: 0; font-size: 14px; font-weight: 650; flex: 1; }
.ai-head .spark { color: #b69cff; display: flex; }
.ai-body { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.ai-intro { color: var(--text-muted); font-size: 12.5px; }
.ai-prompts { display: flex; flex-direction: column; gap: 6px; }
.ai-prompts button { text-align: left; padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text-muted); font-size: 12.5px; }
.ai-prompts button:hover { border-color: #6b5bd6; color: var(--text); }
.ai-msg { padding: 10px 12px; border-radius: var(--radius); font-size: 12.5px; }
.ai-msg.user { background: var(--accent-soft); align-self: flex-end; max-width: 90%; }
.ai-msg.bot { background: var(--bg-elevated); border: 1px solid var(--border); }
.ai-msg.bot ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-muted); }
.ai-compose { padding: 10px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.ai-compose .quick { display: flex; gap: 6px; flex-wrap: wrap; }

/* ================================== Responsive ================================== */
@media (max-width: 1100px) {
  .brand-wordmark, #conn-status { display: none; }
  .brand-icon { display: block; }
  .select-btn { min-width: 140px; }
  .select-wrap { width: 150px; }
  .btn-label { display: none; }
}
@media (max-width: 820px) {
  :root { --sidebar-w: 240px; }
  .workspace-panes[data-mode="split"] { flex-direction: column; }
  .workspace-panes[data-mode="split"] .builder-pane { flex: 1 1 50%; }
  .workspace-panes[data-mode="split"] .resizer { display: none; }
  .select-wrap { display: none; }
  .form-grid, .auth-cards { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  body:not(.explorer-open-mobile) .sidebar, body:not(.explorer-open-mobile) .resizer[data-resize="sidebar"] { display: none; }
  body.ai-open .ai-drawer { position: fixed; right: 0; top: var(--topbar-h); bottom: 0; z-index: 50; }
}

/* Late additions */
body.panel-hidden .bottom-panel, body.panel-hidden .resizer[data-resize="bottom"] { display: none; }
button.piece-name { cursor: pointer; text-align: left; }
button.piece-name:hover { text-decoration: underline; text-decoration-color: var(--text-dim); }
.popover-menu { min-width: 200px; }
.piece .select.mini { width: auto; min-width: 58px; flex: none; }
.piece .piece-name { flex: 0 1 auto; min-width: 40px; }
.row .select.mini { flex: none; }

@media (max-width: 820px) {
  .app, .main, .workspace { min-width: 0; max-width: 100vw; }
  .topbar { gap: 6px; padding: 0 8px; }
  .topbar-sep, #btn-ai, #btn-run-query kbd, .sync-badge, #btn-fullscreen { display: none; }
  .select-btn { min-width: 0; max-width: 150px; }
  .workspace-toolbar { padding: 0 8px; gap: 6px; }

  .segmented button { padding: 0 8px; }
  .segmented button.muted-tab { display: none; }
  .editor-toolbar .btn-label { display: none; }
  .panel-tabs { overflow-x: auto; }
  .exec-summary { display: none; }
  .sidebar { position: fixed; left: 46px; top: var(--topbar-h); bottom: var(--statusbar-h); z-index: 40; box-shadow: var(--shadow); }
}
.piece .select.mini { width: 76px; min-width: 0; }
.piece input.mini.alias { width: auto; flex: 0 1 96px; min-width: 44px; }
.clause-header { flex-wrap: wrap; row-gap: 6px; }
.statusbar, .topbar { overflow: hidden; }
/* SQL -> builder sync banner stays visible while the blocks scroll */
.builder-banner.sync-banner { position: sticky; top: -14px; z-index: 6; box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35); backdrop-filter: blur(6px); }
.builder-banner.sync-banner:not(.info) { background: #2a2214; }
.builder-banner.sync-banner.info { background: #16213a; }

/* ================================== Execution plan ================================== */
.plan-toolbar { height: 38px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 10px; border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; }
.plan-stat { color: var(--text-dim); font-size: 12px; }
.plan-stat b { color: var(--text); font-weight: 600; margin-left: 3px; }
.plan-zoom { font: 11.5px var(--mono); color: var(--text-muted); min-width: 38px; text-align: center; }
.plan-body { flex: 1; min-height: 0; display: flex; }
.plan-side { width: 300px; flex: none; overflow: auto; padding: 10px 12px 16px; background: var(--bg-panel); }
.plan-insights { border-right: 1px solid var(--border); }
.plan-details { border-left: 1px solid var(--border); width: 290px; }
.plan-section-title { display: flex; align-items: center; gap: 6px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-dim); margin: 4px 0 8px; }
.plan-section-title:not(:first-child) { margin-top: 16px; }
.plan-label { font-size: 11px; font-weight: 600; color: var(--text-dim); margin: 12px 0 5px; }
.plan-kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 12px; }
.plan-kv span { color: var(--text-dim); white-space: nowrap; }
.plan-kv b { font-weight: 500; color: var(--text); text-align: right; word-break: break-word; }
.plan-pred, .plan-sql { margin: 0; padding: 7px 9px; border-radius: 6px; background: var(--bg-sunken); font: 11.5px/1.5 var(--mono); color: #cfd6e3; white-space: pre-wrap; word-break: break-word; }
.plan-sql { max-height: 160px; overflow: auto; }
.plan-cols { display: flex; flex-wrap: wrap; gap: 4px; }
.plan-table { width: 100%; border-collapse: collapse; font-size: 11.5px; margin-bottom: 8px; }
.plan-table th { text-align: right; color: var(--text-dim); font-weight: 600; padding: 3px 4px; border-bottom: 1px solid var(--border); }
.plan-table td { text-align: right; padding: 3px 4px; font-family: var(--mono); border-bottom: 1px solid #1c212c; }
.plan-table th:first-child, .plan-table td:first-child { text-align: left; font-family: var(--font); }

.insight { border: 1px solid var(--border); border-left: 3px solid var(--text-dim); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; background: var(--bg-elevated); }
.insight.high { border-left-color: var(--danger); }
.insight.medium { border-left-color: var(--warning); }
.insight.info { border-left-color: var(--accent); }
.insight.ok { border-left-color: var(--success); }
.insight-head { display: flex; gap: 7px; align-items: flex-start; font-size: 12.5px; }
.insight.high .insight-head .icon { color: var(--danger); }
.insight.medium .insight-head .icon { color: var(--warning); }
.insight.info .insight-head .icon { color: var(--accent); }
.insight.ok .insight-head .icon { color: var(--success); }
.insight-head b { font-weight: 600; }
.insight-detail { color: var(--text-muted); font-size: 12px; margin-top: 4px; line-height: 1.45; }
.insight-fix { margin: 6px 0 0; padding: 6px 8px; border-radius: 6px; background: var(--bg-sunken); font: 11px/1.5 var(--mono); color: #a5d6a7; white-space: pre-wrap; word-break: break-word; }
.insight-actions { display: flex; gap: 6px; margin-top: 6px; }
.insight-actions:empty { display: none; }

.plan-canvas-wrap { flex: 1; min-width: 0; overflow: auto; background:
  radial-gradient(circle, #1a1f29 1px, transparent 1px) 0 0 / 18px 18px, var(--bg-sunken); cursor: grab; }
.plan-canvas-wrap.panning { cursor: grabbing; user-select: none; }
.plan-sizer { position: relative; }
.plan-canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.plan-edges { position: absolute; left: 0; top: 0; overflow: visible; }
.plan-edges path { fill: none; stroke: #45506a; stroke-linejoin: round; }
.plan-edges path:hover { stroke: var(--accent); }
.plan-edges marker path { fill: #45506a; stroke: none; }
.plan-node { position: absolute; border-radius: 10px; background: var(--bg-elevated); border: 1px solid var(--border-strong); padding: 8px 10px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; box-shadow: 0 2px 8px rgba(0,0,0,.35); transition: border-color .12s, box-shadow .12s; }
.plan-node:hover { border-color: #4a5570; }
.plan-node.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), 0 2px 8px rgba(0,0,0,.35); }
.plan-node.mild { border-top: 3px solid #d4b64a; }
.plan-node.warm { border-top: 3px solid #f08c3a; }
.plan-node.hot { border-top: 3px solid var(--danger); background: color-mix(in srgb, var(--danger) 7%, var(--bg-elevated)); }
.pn-head { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12.5px; }
.pn-head > span:first-of-type { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pn-head .icon { color: var(--accent); }
.pn-warn { margin-left: auto; color: var(--warning); display: flex; }
.pn-par { color: var(--text-dim); display: flex; }
.pn-obj { font: 11px var(--mono); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pn-meta { display: flex; justify-content: space-between; align-items: center; font-size: 11.5px; color: var(--text-dim); margin-top: auto; }
.pn-meta b { color: var(--text); font-weight: 600; }
.pn-meta b.pn-off { color: var(--warning); }
.pn-cost { font: 700 12px var(--mono); color: var(--text); }
.plan-node.hot .pn-cost { color: #ff8b84; }
.plan-node.warm .pn-cost { color: #f7a766; }
.pn-time { font-size: 11px; color: var(--text-dim); }
.editor-toolbar .btn.toggle-on { color: var(--success); background: var(--success-soft); }
@media (max-width: 1100px) { .plan-side { width: 240px; } .plan-details { width: 230px; } }
@media (max-width: 820px) { .plan-body { flex-direction: column; } .plan-side { width: auto; max-height: 30%; border: 0; } }
/* Editor toolbar: collapse labels to icons when the SQL pane is narrow (tooltips keep them discoverable) */
.editor-pane { container-type: inline-size; }
.editor-toolbar { overflow: hidden; }
.editor-toolbar .label { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
@container (max-width: 900px) { .editor-toolbar .btn-label { display: none; } .editor-toolbar .btn-sm { padding: 0 7px; } }

/* ================================== Query tabs ================================== */
.workspace-toolbar { padding-left: 6px; }
.qtabs-wrap { flex: 1; min-width: 0; display: flex; align-items: flex-end; align-self: stretch; gap: 2px; }
.qtabs { display: flex; align-items: flex-end; gap: 2px; min-width: 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; align-self: stretch; }
.qtabs::-webkit-scrollbar { display: none; }
.qtab {
  flex: none; display: flex; align-items: center; gap: 6px; height: 32px; max-width: 220px; padding: 0 6px 0 10px;
  border: 1px solid transparent; border-bottom: 0; border-radius: 8px 8px 0 0; color: var(--text-dim); cursor: pointer;
  user-select: none; position: relative; font-size: 12.5px;
}
.qtab:hover { background: var(--bg-hover); color: var(--text-muted); }
.qtab.active { background: var(--bg-panel); border-color: var(--border); color: var(--text); }
.qtab.active::before { content: ''; position: absolute; left: 8px; right: 8px; top: -1px; height: 2px; border-radius: 2px; background: var(--accent); }
.qtab.active::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--bg-panel); }
.qtab-icon { display: flex; color: var(--text-dim); }
.qtab.active .qtab-icon { color: var(--accent); }
.qtab-spin { width: 11px; height: 11px; border-width: 1.5px; }
.qtab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.qtab.qtab-error .qtab-name { text-decoration: underline wavy color-mix(in srgb, var(--danger) 70%, transparent); text-underline-offset: 3px; }
.qtab-close { width: 18px; height: 18px; border-radius: 4px; display: grid; place-items: center; color: var(--text-dim); visibility: hidden; flex: none; position: relative; }
.qtab:hover .qtab-close, .qtab.active .qtab-close { visibility: visible; }
.qtab-close:hover { background: var(--bg-active); color: var(--text); }
/* Unsaved: a dot that turns into the close button on hover (VS Code style) */
.qtab.dirty .qtab-close { visibility: visible; }
.qtab.dirty .qtab-close .icon { display: none; }
.qtab.dirty .qtab-close::after { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.qtab.dirty.active .qtab-close::after { background: var(--warning); }
.qtab.dirty .qtab-close:hover .icon { display: block; }
.qtab.dirty .qtab-close:hover::after { display: none; }
.qtab.dragging { opacity: 0.4; }
.qtab.drop-before { box-shadow: inset 2px 0 0 var(--accent); }
.qtab-rename { width: 140px; height: 22px; padding: 0 6px; border-radius: 5px; border: 1px solid var(--accent); background: var(--bg-sunken); outline: none; font-size: 12.5px; }
.qtab-new { align-self: center; margin-left: 2px; }
.workspace-toolbar { align-items: stretch; }
.workspace-toolbar > .segmented, .workspace-toolbar > .flex { align-self: center; }

/* ================================== Value suggestions ================================== */
.popover-vs { max-height: min(380px, calc(100vh - 20px)); }
.vs { display: flex; flex-direction: column; min-height: 0; max-height: inherit; }
.vs-list { overflow: auto; padding: 4px; flex: 1; min-height: 0; }
.vs-item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 5px; cursor: pointer; min-height: 28px; }
.vs-item:not(:has(input)) { grid-template-columns: 1fr auto; }
.vs-item:hover, .vs-item.focused { background: var(--bg-hover); }
.vs-item.focused { box-shadow: inset 2px 0 0 var(--accent); }
.vs-item input[type="checkbox"] { accent-color: var(--accent); margin: 0; }
.vs-value { font: 12.5px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vs-value mark { background: rgba(240, 180, 41, 0.22); color: #ffd36a; border-radius: 2px; }
.vs-item.is-null .vs-value { color: var(--text-dim); }
.vs-count { position: relative; min-width: 64px; text-align: right; font: 11px var(--mono); color: var(--text-dim); padding: 1px 4px; }
.vs-bar { position: absolute; right: 0; top: 0; bottom: 0; background: var(--accent-soft); border-radius: 3px; z-index: -1; }
.vs-count { z-index: 0; }
.vs-empty { padding: 12px; color: var(--text-dim); font-size: 12px; display: flex; gap: 8px; align-items: center; }
.vs-footer { display: flex; justify-content: space-between; gap: 8px; padding: 6px 8px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted); }
.vs-wrap { display: inline-flex; align-items: center; gap: 2px; }
.vs-btn { width: 24px; height: 26px; }

/* Full table.column names everywhere in the builder — no "…" truncation */
.piece .piece-name { overflow: visible; text-overflow: clip; flex: none; min-width: auto; }
/* `*` / `Table.*` select item */
.piece-star .star-hint { margin-left: 7px; font: 600 10px Inter, system-ui, sans-serif; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.piece { max-width: none; }
.row .col-btn, .col-btn { max-width: none; }
.col-btn .col-name { overflow: visible; text-overflow: clip; }
/* Pickers grow to fit the longest schema.table / table.column on one line (ellipsis only beyond the viewport). */
.popover.popover-picker { width: max-content; min-width: 360px; max-width: calc(100vw - 24px); }
.popover-picker .picker-list { scrollbar-gutter: stable; }
.popover-picker .picker-item .pi-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.popover-picker .picker-item .pi-type { flex: none; padding-left: 12px; }

/* AI assistant: your own provider (Ask QueryX drawer, AI settings, the builder's AI bar) */
.ai-head .badge { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-setup { display: flex; gap: 10px; padding: 12px; border-radius: var(--radius); border: 1px solid color-mix(in srgb, #8b74ff 45%, var(--border));
  background: color-mix(in srgb, #8b74ff 9%, var(--bg-elevated)); font-size: 12.5px; }
.ai-setup > svg { color: #b69cff; flex: none; margin-top: 2px; }
.ai-setup p { margin: 4px 0 10px; color: var(--text-muted); }
.ai-msg.bot { display: flex; flex-direction: column; gap: 8px; }
.ai-text { white-space: pre-wrap; }
.ai-sql { margin: 0; padding: 8px 10px; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); font-size: 11.5px;
  white-space: pre-wrap; word-break: break-word; max-height: 280px; overflow: auto; color: var(--text); }
.ai-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ai-tag { font-size: 11px; color: var(--success); display: flex; align-items: center; gap: 4px; }
.ai-tag.dim { color: var(--text-dim); }
.ai-error { color: var(--danger); display: flex; gap: 6px; align-items: flex-start; }
.ai-warn { color: var(--warning); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.ai-by { font-size: 10.5px; color: var(--text-dim); text-align: right; }
.ai-thinking { flex-direction: row !important; align-items: center; color: var(--text-muted); }
.ai-ctx { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 230px; }
.builder-ai { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 10px; margin-bottom: 10px; border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, #8b74ff 40%, var(--border)); background: color-mix(in srgb, #8b74ff 7%, var(--bg-elevated)); }
.builder-ai > svg { color: #b69cff; flex: none; }
.builder-ai .input { flex: 1; min-width: 0; border-color: transparent; background: transparent; }
.builder-ai .input:focus { border-color: var(--border); background: var(--bg); }
.ai-settings .ais-intro { margin: 0 0 12px; color: var(--text-muted); font-size: 12.5px; }
.ais-providers { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.ais-provider { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; font-size: 12.5px; }
.ais-provider:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.ais-provider span { display: flex; flex-direction: column; gap: 2px; }
.ais-has { color: var(--success); display: inline-flex; gap: 3px; align-items: center; font-size: 11px; }
.ais-form { display: flex; flex-direction: column; gap: 10px; }
.ais-note { font-size: 12px; color: var(--text-muted); }
.ais-model { display: flex; gap: 6px; }
.ais-model .input { flex: 1; }
.ais-privacy { display: flex; gap: 8px; margin-top: 14px; padding: 8px 10px; border-radius: var(--radius); background: var(--bg-elevated);
  font-size: 11.5px; color: var(--text-muted); }
.ais-privacy > svg { flex: none; color: var(--success); margin-top: 1px; }
.ais-result { display: flex; gap: 6px; align-items: flex-start; margin-top: 10px; font-size: 12.5px; }
.ais-result.ok { color: var(--success); }
.ais-result.bad { color: var(--danger); }
@media (max-width: 560px) { .ais-providers { grid-template-columns: 1fr; } }
.ai-switch { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-muted); }

/* AI settings: Ollama (local models) */
.ol-status { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: var(--radius); background: var(--bg-elevated); font-size: 12.5px; }
.ol-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warning); flex: none; margin-top: 4px; }
.ol-dot.ok { background: var(--success); }
.ol-models { display: flex; flex-direction: column; gap: 6px; }
.ol-head { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); margin-top: 4px; }
.ol-model { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.ol-model.on { border-color: var(--accent); background: var(--accent-soft); }
.ol-model input { margin-top: 3px; }
.ol-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ol-title { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12.5px; }
.ol-tag { font-size: 10.5px; padding: 1px 6px; border-radius: 10px; background: var(--bg-elevated); color: var(--text-muted); border: 1px solid var(--border); }
.ol-tag.best { color: var(--success); border-color: color-mix(in srgb, var(--success) 50%, transparent); }
.ol-meta { font-size: 11.5px; color: var(--text-dim); }
.ol-why { font-size: 11.5px; color: var(--text-muted); }
.ol-err { font-size: 11.5px; color: var(--danger); }
.ol-act { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.ol-have { font-size: 11.5px; color: var(--success); display: inline-flex; gap: 3px; align-items: center; }
.ol-progress { height: 5px; border-radius: 3px; background: var(--bg-elevated); overflow: hidden; margin-top: 4px; }
.ol-progress > div { height: 100%; background: var(--accent); transition: width .3s; }
.ai-settings .modal-body { max-height: min(78vh, 760px); overflow: auto; }

/* Builder filters: calculated values (fx) */
.fx-toggle { color: var(--text-dim); }
.fx-toggle.on { color: #b69cff; background: color-mix(in srgb, #8b74ff 16%, transparent); }
.fx-wrap { display: inline-flex; align-items: center; position: relative; flex: 1 1 220px; min-width: 180px; max-width: 420px; }
.fx-badge { position: absolute; left: 7px; font: italic 600 11px/1 Georgia, serif; color: #b69cff; pointer-events: none; }
.fx-wrap .fx-input { width: 100%; padding-left: 26px; font-size: 12px; border-color: color-mix(in srgb, #8b74ff 45%, var(--border)); }

/* Table / view name completion in free-text boxes (AI chat) */
.name-complete { position: fixed; z-index: 1300; max-width: 420px; padding: 4px; border-radius: 8px; background: var(--bg-elevated);
  border: 1px solid var(--border-strong, var(--border)); box-shadow: 0 8px 24px rgba(0, 0, 0, .45); font-size: 12.5px; }
.nc-item { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 5px; cursor: pointer; white-space: nowrap; }
.nc-item.active, .nc-item:hover { background: var(--accent-soft); }
.nc-item > svg { color: var(--text-dim); flex: none; }
.nc-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nc-schema { color: var(--text-dim); }
.nc-rows { color: var(--text-dim); font-size: 11px; }
.nc-hint { padding: 4px 8px 2px; color: var(--text-dim); font-size: 10.5px; border-top: 1px solid var(--border); margin-top: 3px; }
.nc-hint kbd { font-size: 10px; }

/* ================================== Hosted mode: sign-in, account, users ================================== */
.login-screen { position: fixed; inset: 0; z-index: 3000; display: grid; place-items: center; background: var(--bg); padding: 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px; border-radius: 12px;
  background: var(--bg-panel); border: 1px solid var(--border); box-shadow: 0 20px 60px rgba(0, 0, 0, .45); }
.login-brand { display: flex; align-items: center; gap: 10px; }
.login-brand img { height: 32px; max-width: 160px; object-fit: contain; }
.login-brand h1 { margin: 0; font-size: 20px; font-weight: 650; }
.login-sub { margin: 0 0 4px; color: var(--text-muted); font-size: 13px; }
.login-note { padding: 8px 10px; border-radius: 6px; background: var(--warning-soft); color: var(--warning); font-size: 12.5px; }
.login-error { color: var(--danger); font-size: 12.5px; }
.login-btn { justify-content: center; height: 36px; margin-top: 4px; }
.login-foot { margin: 4px 0 0; color: var(--text-dim); font-size: 11.5px; }
.account-btn { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft);
  color: var(--accent); font-weight: 650; font-size: 13px; border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.account-btn:hover { background: color-mix(in srgb, var(--accent) 26%, transparent); }
.brand-custom-logo { height: 26px; max-width: 150px; object-fit: contain; }
.brand-custom-name { font-weight: 650; font-size: 15px; margin-left: 8px; white-space: nowrap; }
.brand-preview { min-width: 60px; height: 34px; display: grid; place-items: center; padding: 0 8px; border: 1px dashed var(--border); border-radius: 6px;
  color: var(--text-dim); font-size: 11.5px; }
.brand-preview img { max-height: 28px; max-width: 140px; }
.user-add { display: grid; grid-template-columns: 1.4fr 1fr 130px 1.2fr auto; gap: 6px; align-items: center; }
.role-help { display: flex; flex-direction: column; gap: 2px; margin: 10px 0; font-size: 11.5px; color: var(--text-muted); }
.user-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.user-table th { text-align: left; font-weight: 600; color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  padding: 6px 8px; border-bottom: 1px solid var(--border); }
.user-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.user-table td small { display: block; color: var(--text-dim); }
.user-table tr.inactive td { opacity: .5; }
.user-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.audit-scroll { max-height: 60vh; overflow: auto; }
.audit-detail { max-width: 420px; white-space: pre-wrap; word-break: break-word; font-size: 11.5px; }
.nowrap { white-space: nowrap; }
/* What a creator can't do is not offered (the server refuses it anyway): connections and AI set-up are the administrator's */
body.role-creator [data-act='new-connection'], body.role-creator .section-header [data-act='new'], body.role-creator [data-ai-settings],
body.role-creator #ai-drawer [data-settings], body.role-creator #ai-drawer [data-open-settings], body.role-creator [data-conn-edit],
body.role-creator [data-conn-delete] { display: none !important; }
/* Viewers: the dashboards they can open */
.viewer-home { min-height: 100vh; background: var(--bg); color: var(--text); }
.viewer-head { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--bg-panel); }
.viewer-head img { height: 26px; max-width: 150px; object-fit: contain; }
.viewer-head h1 { margin: 0; font-size: 16px; font-weight: 650; }
.viewer-user { color: var(--text-muted); font-size: 12.5px; }
.viewer-main { max-width: 760px; margin: 0 auto; padding: 28px 20px; }
.viewer-main h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); margin: 0 0 12px; }
.viewer-list { display: flex; flex-direction: column; gap: 8px; }
.viewer-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-panel); color: var(--text); text-decoration: none; }
.viewer-card:hover { border-color: var(--accent); }
.viewer-card > div { flex: 1; display: flex; flex-direction: column; }
.viewer-card small { color: var(--text-dim); }
.viewer-card > svg:first-child { color: var(--accent); }
/* The read-only dashboard page inside another application: no header chrome beyond the dashboard's own name */
body.share-embedded .share-logo, body.share-embedded [data-act='tv'] { display: none; }
body.share-embedded .dash-head { padding-top: 6px; padding-bottom: 6px; }
.share-back svg { transform: rotate(180deg); }
/* The whole workbench inside another application (/?embed=1): the customer's page already has its own header */
body.embedded .brand, body.embedded .topbar > .topbar-sep:first-of-type { display: none; }
@media (max-width: 900px) { .user-add { grid-template-columns: 1fr 1fr; } }

/* Sign in with Microsoft */
.login-ms { justify-content: center; gap: 10px; height: 38px; background: #fff; color: #1f1f1f; border: 1px solid #8c8c8c; font-weight: 600; text-decoration: none; }
.login-ms:hover { background: #f3f3f3; color: #1f1f1f; }
.login-or { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 11.5px; }
.login-or::before, .login-or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.role-help svg { vertical-align: -3px; }
