:root {
  --bg: #f3f4f7; --panel: #fff; --text: #1b1d23; --muted: #6b7280; --line: #e3e6ec;
  --accent: #0f766e; --accent-soft: #e6f4f1; --accent-ink: #0b5c56; --err: #c62828; --err-soft: #fdecec;
  --mono: ui-monospace, Menlo, Consolas, monospace; --r: 10px; --gap: 12px; --side: 300px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121419; --panel: #1a1d24; --text: #e8eaf0; --muted: #98a1b3; --line: #2a2f3a;
    --accent: #2dd4bf; --accent-soft: #10302d; --accent-ink: #7fe7da; --err: #f87171; --err-soft: #3a1c1c; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
#app { display: flex; flex-direction: column; min-height: 100vh; }
code, .sql, .grid td, .fields { font-family: var(--mono); }
code { font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.err { color: var(--err); background: var(--err-soft); padding: 8px 10px; border-radius: 8px; white-space: pre-wrap; font-size: 13px; margin: 8px 0 0; }
h2 { margin: 0 0 10px; font-size: 18px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; }
h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.bar { display: flex; align-items: center; gap: var(--gap); padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.brand { font-weight: 700; font-size: 16px; color: var(--accent-ink); }
.btn { font: inherit; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.link { font: inherit; font-size: 13px; background: none; border: 0; color: var(--accent-ink); cursor: pointer; padding: 0; text-align: left; }
.link:disabled { opacity: .5; cursor: default; }
.row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-top: 10px; }

.layout { flex: 1; display: grid; grid-template-columns: var(--side) minmax(0, 1fr); gap: var(--gap); padding: var(--gap) 16px 32px; align-items: start; }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } .side { position: static; max-height: none; } }
.side { position: sticky; top: 58px; max-height: calc(100vh - 70px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 8px; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px 8px; }
.side-item { display: flex; flex-direction: column; width: 100%; text-align: left; padding: 7px 10px; border: 0; background: none; color: var(--text); border-radius: 7px; font: inherit; gap: 2px; }
button.side-item { cursor: pointer; }
button.side-item:hover { background: var(--bg); }
.src-name { font-weight: 600; }
.fields { font-size: 12px; color: var(--muted); word-break: break-word; }
.empty { padding: 8px; font-size: 14px; }

.stage { min-width: 0; display: flex; flex-direction: column; gap: var(--gap); }
.block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.question { width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); resize: vertical; }
.answer { font-size: 17px; margin: 4px 0 12px; padding: 12px 14px; background: var(--accent-soft); border-radius: 8px; }
.sql-box { margin-top: 12px; }
.sql { margin: 8px 0 0; font-size: 13px; white-space: pre-wrap; background: var(--bg); padding: 10px; border-radius: 8px; }

.table-wrap { overflow: auto; max-height: 60vh; border: 1px solid var(--line); border-radius: 8px; }
.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
.grid th, .grid td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.grid th { position: sticky; top: 0; background: var(--panel); font-weight: 600; }
.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid td.nil { color: var(--muted); }
