:root {
  --bg: #f6f7fb; --panel: #fff; --panel2: #f0f2f8; --line: #dde1ec; --text: #1c2233; --muted: #6a7390;
  --accent: #4f7cff; --accent-text: #fff; --err: #c2304a; --ok: #1d7a54; --code-bg: #fbfcff;
  --kw: #7b3fd6; --str: #1d7a54; --num: #c26a0d; --com: #8b93ab; --fn: #1f6fd0; --param: #d1397f;
  --chart-bg: #fff; --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151e; --panel: #1a1e2b; --panel2: #222737; --line: #2e3448; --text: #e4e8f4; --muted: #8e97b3;
    --accent: #6b92ff; --accent-text: #0c1020; --err: #ff7088; --ok: #4fd1a0; --code-bg: #161a26;
    --kw: #b99bff; --str: #7fdcae; --num: #ffb064; --com: #707a99; --fn: #7db4ff; --param: #ff8cc0; --chart-bg: #1a1e2b;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; display: flex; flex-direction: column; }
button, select, input, textarea { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 11px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
kbd { font: 11px var(--mono); opacity: 0.75; margin-left: 4px; }
input, select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.muted { color: var(--muted); } .pad { padding: 12px; } .err { color: var(--err); }

.topbar { display: flex; align-items: center; gap: 18px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: -0.3px; }
.brand .logo { background: var(--accent); color: var(--accent-text); border-radius: 5px; padding: 0 5px; margin-right: 2px; }
.brand small { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 10px; letter-spacing: 0; }
.modes { display: flex; gap: 4px; background: var(--panel2); border-radius: 8px; padding: 3px; }
.mode { border: 0; background: transparent; }
.mode.active { background: var(--panel); box-shadow: 0 1px 3px #0002; font-weight: 600; }
.actions { margin-left: auto; display: flex; gap: 6px; }
.progress { position: relative; height: 18px; background: var(--panel2); } .progress div { height: 100%; background: var(--accent); opacity: 0.5; transition: width 0.1s; } .progress span { position: absolute; inset: 0; padding: 0 12px; font-size: 12px; line-height: 18px; }

.layout { flex: 1; display: grid; grid-template-columns: 280px 1fr; min-height: 0; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-tabs { display: flex; border-bottom: 1px solid var(--line); }
.side-tab { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 8px 4px; color: var(--muted); }
.side-tab.active { color: var(--text); box-shadow: inset 0 -2px var(--accent); font-weight: 600; }
.side-pane { overflow: auto; flex: 1; padding: 6px; }
.side-actions { padding: 2px 4px 6px; }
.tbl summary { cursor: pointer; display: flex; gap: 6px; align-items: center; padding: 4px 6px; border-radius: 6px; list-style-position: inside; }
.tbl summary:hover { background: var(--panel2); }
.tbl .tname { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.tbl em, .hist em { font-style: normal; color: var(--muted); font-size: 12px; }
.tbtns { display: none; gap: 2px; } .tbl summary:hover .tbtns, .hist:hover .tbtns { display: inline-flex; }
.tbtns button { padding: 0 6px; font-size: 11px; }
.tbl ul { list-style: none; margin: 0 0 6px 18px; padding: 0; }
.tbl li { display: flex; justify-content: space-between; flex-wrap: wrap; padding: 2px 6px; border-radius: 4px; cursor: pointer; font-family: var(--mono); font-size: 12.5px; }
.tbl li:hover { background: var(--panel2); }
.stats { width: 100%; font-family: system-ui; background: var(--panel2); border-radius: 6px; padding: 6px 8px; margin: 3px 0; cursor: default; }
.stats dl { display: grid; grid-template-columns: auto 1fr; gap: 1px 10px; margin: 0; font-size: 12px; } .stats dt { color: var(--muted); } .stats dd { margin: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; }
.stats .top { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; } .stats .top span { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0 7px; font-size: 11px; } .stats b { color: var(--accent); }
.hist { padding: 6px 8px; border-radius: 6px; cursor: pointer; border-bottom: 1px solid var(--line); position: relative; }
.hist:hover { background: var(--panel2); } .hist code { display: block; font: 12px var(--mono); white-space: pre-wrap; word-break: break-word; max-height: 4.4em; overflow: hidden; } .hist.bad em { color: var(--err); }
.hist .tbtns { position: absolute; right: 6px; top: 6px; }

.view { overflow: auto; padding: 12px 16px; min-width: 0; min-height: 0; }
.view[hidden] { display: none; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar .hint { color: var(--muted); font-size: 12px; margin-left: 6px; }
.title-input { min-width: 200px; font-weight: 600; }

.editor { position: relative; height: 210px; background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font: 13.5px/20px var(--mono); }
.ed-hl, .ed-ta { position: absolute; inset: 0; margin: 0; padding: 10px 12px; font: inherit; letter-spacing: 0; tab-size: 2; white-space: pre; overflow: auto; border: 0; }
.ed-hl { pointer-events: none; color: var(--text); scrollbar-width: none; }
.ed-hl::-webkit-scrollbar { display: none; }
.ed-ta { background: transparent; color: transparent; caret-color: var(--text); resize: none; outline: none !important; }
.ed-ta::selection { background: #4f7cff55; color: transparent; }
.tok-keyword { color: var(--kw); font-weight: 600; } .tok-string { color: var(--str); } .tok-number { color: var(--num); }
.tok-comment { color: var(--com); font-style: italic; } .tok-function { color: var(--fn); } .tok-param { color: var(--param); } .tok-quoted { color: var(--fn); }
.ed-pop { position: absolute; z-index: 20; list-style: none; margin: 0; padding: 3px; min-width: 200px; max-height: 220px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 24px #0003; font: 13px var(--mono); }
.ed-pop li { display: flex; align-items: center; gap: 8px; padding: 2px 8px; border-radius: 5px; cursor: pointer; } .ed-pop li.on { background: var(--accent); color: var(--accent-text); }
.ed-pop em { margin-left: auto; font: 11px system-ui; opacity: 0.7; padding-left: 14px; }
.ed-pop .k { width: 16px; height: 16px; border-radius: 4px; background: var(--panel2); color: var(--text); font: 10px/16px system-ui; text-align: center; text-transform: uppercase; }
.params { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 8px; padding: 6px 10px; background: var(--panel2); border-radius: 8px; }
.params[hidden] { display: none; } .params input { width: 130px; font-family: var(--mono); }

.results { margin-top: 12px; }
.rv-msg { font-size: 13px; margin-bottom: 6px; } .rv-msg.ok { color: var(--ok); } .rv-msg.err { color: var(--err); background: color-mix(in srgb, var(--err) 10%, transparent); padding: 8px 10px; border-radius: 6px; font-family: var(--mono); white-space: pre-wrap; }
.rv-bar { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.rv-bar button { padding: 2px 8px; font-size: 12.5px; }
.rv-tabs { display: flex; background: var(--panel2); border-radius: 7px; padding: 2px; } .rv-tabs button { border: 0; background: transparent; } .rv-tabs button.on { background: var(--panel); font-weight: 600; box-shadow: 0 1px 2px #0002; }
.rv-filter { width: 170px; } .rv-info { color: var(--muted); font-size: 12px; } .rv-spacer { flex: 1; }
.rv-pane[hidden] { display: none; }
.grid { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-size: 13px; }
.grid-head { display: grid; overflow: hidden; background: var(--panel2); border-bottom: 1px solid var(--line); width: 100%; }
.hcell { padding: 3px 8px; min-width: 0; } .hcell.idx { padding: 0; }
.hcell .sort { border: 0; background: none; padding: 0; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; text-align: left; }
.hcell input { width: 100%; padding: 1px 5px; font-size: 11.5px; margin-top: 2px; }
.grid-body { position: relative; flex: 1; overflow: auto; }
.grid-spacer { position: relative; min-width: 100%; }
.grid-row { position: absolute; left: 0; display: grid; height: 26px; width: var(--gw); }
.grid-row.alt { background: color-mix(in srgb, var(--panel2) 55%, transparent); }
.cell { padding: 3px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12.5px; }
.cell.idx { color: var(--muted); text-align: right; font-size: 11px; } .cell.num { text-align: right; } .cell.null { color: var(--muted); font-style: italic; }
.chart-controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-bottom: 8px; } .chart-controls label { display: inline-flex; gap: 6px; align-items: center; } .chk { margin-right: 4px; }
.chart-wrap { background: var(--chart-bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-width: 900px; }
.chart { width: 100%; height: auto; display: block; } .chart-text { fill: var(--muted); font: 11px system-ui; } .chart-grid { stroke: var(--line); } .chart-axis { stroke: var(--muted); }
.plan ul { list-style: none; margin: 0; padding-left: 20px; border-left: 1px dashed var(--line); } .plan > ul { border: 0; padding: 0; }
.plan li { margin: 5px 0; } .plan-node { font-family: var(--mono); background: var(--panel2); padding: 2px 8px; border-radius: 5px; display: inline-block; } .plan-node.scan { border-left: 3px solid var(--num); } .plan-node.search { border-left: 3px solid var(--ok); }

.cells { display: flex; flex-direction: column; gap: 12px; max-width: 1100px; }
.cell-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.cell-bar { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; } .cell-spacer { flex: 1; } .cell-bar button { padding: 1px 8px; font-size: 12.5px; }
.badge { font: 700 10.5px var(--mono); background: var(--panel2); color: var(--muted); border-radius: 4px; padding: 2px 6px; }
.cell-card.sql .badge { color: var(--kw); }
.md-view { padding: 4px 6px; } .md-view h1, .md-view h2 { margin: 0.2em 0; } .md-view code { background: var(--panel2); padding: 0 4px; border-radius: 4px; font-family: var(--mono); } .md-view pre { background: var(--panel2); padding: 8px; border-radius: 6px; overflow: auto; }
.md-edit { width: 100%; font-family: var(--mono); background: var(--code-bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.md-edit[hidden], .md-view[hidden] { display: none; }

.statusbar { display: flex; justify-content: space-between; padding: 3px 14px; font-size: 12px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); }
.dropzone { position: fixed; inset: 10px; z-index: 50; border: 3px dashed var(--accent); border-radius: 16px; background: color-mix(in srgb, var(--bg) 85%, transparent); display: grid; place-items: center; font-size: 28px; font-weight: 700; color: var(--accent); pointer-events: none; }
.dropzone[hidden], .toast[hidden], .progress[hidden] { display: none; }
.toast { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; z-index: 60; box-shadow: 0 6px 20px #0004; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 200px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand small { display: none; }
}
