:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --accent: #14b8a6;
  --glow-primary: rgba(59,130,246,0.18);
  --glow-accent:  rgba(20,184,166,0.12);
  --sql-linenum-w: 44px;
  --sql-line-h: 22.275px;
}
:root.theme-light {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #0d9488;
  --glow-primary: rgba(37,99,235,0.12);
  --glow-accent:  rgba(13,148,136,0.08);
}

.kwcase-opt {
  flex: 1; text-align: center; padding: 5px 0;
  border-radius: 6px; border: 1px solid var(--border);
  background: transparent; color: var(--text-muted);
  cursor: pointer; font-size: 12px; font-weight: 500;
  transition: background 0.12s, color 0.12s, border-color 0.12s; user-select: none;
}
.kwcase-opt:hover { background: var(--border); color: var(--text); }
.kwcase-opt.sel { background: var(--glow-primary); color: var(--primary); border-color: var(--primary); }

.divider {
  width: 6px;
  flex-shrink: 0;
  background: var(--border);
  cursor: col-resize;
  position: relative;
  z-index: 10;
  transition: background 0.15s;
}
.divider:hover { background: var(--primary); opacity: 0.5; }
.divider.dragging { background: var(--primary); opacity: 0.7; cursor: col-resize; }

.dot-blue  { background: var(--primary); box-shadow: 0 0 5px var(--glow-primary); }
.dot-green { background: var(--success); box-shadow: 0 0 5px rgba(52,200,138,.5); }

.input-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--surface);
  min-height: 0;
}

/* ===== 行号 ===== */
.line-numbers {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 3;
  width: var(--sql-linenum-w);
  padding: 16px 8px 16px 0;
  box-sizing: border-box;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
  text-align: right;
  pointer-events: none;
  user-select: none;
}
.line-number {
  position: absolute;
  left: 0;
  right: 8px;
  height: var(--sql-line-h);
}

/* 输入框的隐藏镶镜层：用于测量每行在自动换行下的实际渲染高度，从而让行号与文本对齐。
   与 textarea 使用完全相同的 overflow-y/scrollbar-gutter 设置，避免滚动条是否出现导致
   两者可用宽度不一致、从而使换行位置产生偏差。 */
.line-mirror {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow-y: scroll;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  padding: 16px 16px 16px calc(var(--sql-linenum-w) + 12px);
  box-sizing: border-box;
  color: transparent;
  pointer-events: none;
  font-family: var(--font-mono); font-size: 13.5px; line-height: 1.65; tab-size: 2;
  white-space: pre-wrap;
  word-break: break-word;
}
.line-mirror::-webkit-scrollbar { width: 7px; height: 7px; background: transparent; }
.line-mirror::-webkit-scrollbar-corner { background: transparent; }
.line-mirror::-webkit-scrollbar-thumb { background: transparent; }
.line-mirror-row { min-height: var(--sql-line-h); }

textarea {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  background: transparent;
  color: #a8b8cc;
  caret-color: #a8b8cc;
  border: none; outline: none; resize: none;
  padding: 16px 16px 16px calc(var(--sql-linenum-w) + 12px);
  font-family: var(--font-mono); font-size: 13.5px; line-height: 1.65; tab-size: 2;
  white-space: pre-wrap;
  word-break: break-word;
  z-index: 1;
  box-sizing: border-box;
  overflow-y: scroll;
  scrollbar-gutter: stable;
}
textarea::placeholder { color: var(--text-muted); opacity: 0.7; }

textarea::-webkit-scrollbar { width: 7px; height: 7px; }
textarea::-webkit-scrollbar-track { background: transparent; }
textarea::-webkit-scrollbar-corner { background: transparent; }
textarea::-webkit-scrollbar-thumb {
  background: rgba(120, 135, 165, 0.25);
  border-radius: 4px;
  transition: background 0.15s;
}
textarea::-webkit-scrollbar-thumb:hover  { background: rgba(120, 135, 165, 0.45); }
textarea::-webkit-scrollbar-thumb:active { background: rgba(120, 135, 165, 0.65); }
textarea { scrollbar-width: thin; scrollbar-color: rgba(120,135,165,.25) transparent; }

:root.theme-light textarea {
  color: #2e3d52;
  caret-color: #2e3d52;
}
:root.theme-light textarea::-webkit-scrollbar-thumb { background: rgba(100,116,139,.2); }
:root.theme-light textarea::-webkit-scrollbar-thumb:hover  { background: rgba(100,116,139,.38); }
:root.theme-light textarea { scrollbar-color: rgba(100,116,139,.2) transparent; }

#input:focus {
  box-shadow: inset 0 0 0 1.5px rgba(59,130,246,.4), inset 0 0 20px rgba(59,130,246,.04);
}
:root.theme-light #input:focus {
  box-shadow: inset 0 0 0 1.5px rgba(37,99,235,.35);
}

.output-wrap { flex: 1; overflow: auto; background: var(--surface); position: relative; }

.output-wrap::-webkit-scrollbar { width: 7px; height: 7px; }
.output-wrap::-webkit-scrollbar-track { background: transparent; }
.output-wrap::-webkit-scrollbar-corner { background: transparent; }
.output-wrap::-webkit-scrollbar-thumb {
  background: rgba(120, 135, 165, 0.25);
  border-radius: 4px;
  transition: background 0.15s;
}
.output-wrap::-webkit-scrollbar-thumb:hover  { background: rgba(120, 135, 165, 0.45); }
.output-wrap::-webkit-scrollbar-thumb:active { background: rgba(120, 135, 165, 0.65); }
.output-wrap { scrollbar-width: thin; scrollbar-color: rgba(120,135,165,.25) transparent; }

:root.theme-light .output-wrap::-webkit-scrollbar-thumb { background: rgba(100,116,139,.2); }
:root.theme-light .output-wrap::-webkit-scrollbar-thumb:hover  { background: rgba(100,116,139,.38); }
:root.theme-light .output-wrap { scrollbar-color: rgba(100,116,139,.2) transparent; }

.output-wrap:focus-within {
  box-shadow: inset 0 0 0 1.5px rgba(59,130,246,.4), inset 0 0 20px rgba(59,130,246,.04);
}
:root.theme-light .output-wrap:focus-within {
  box-shadow: inset 0 0 0 1.5px rgba(37,99,235,.35);
}

#output {
  padding: 8px 0;
  box-sizing: border-box;
  font-family: var(--font-mono); font-size: 13.5px;
  line-height: 1.65;
  min-height: 100%;
  color: #a8b8cc;
  caret-color: #a8b8cc;
  outline: none;
  position: relative;
}
:root.theme-light #output { color: #2e3d52; caret-color: #2e3d52; }
#output:focus { box-shadow: none; }

/* 每一行用 flex 布局把「行号」与「内容」放在同一容器内，
   由浏览器原生保证顶部对齐、且内容因自动换行变高时行号会同步跟着变高，
   彻底避免用 JS 计算 offsetTop/offsetHeight 所带来的同步误差与错位问题。 */
.sql-line {
  display: flex;
  align-items: flex-start;
  min-height: var(--sql-line-h);
  padding: 0 16px 0 0;
}
.sql-line-num {
  flex: 0 0 var(--sql-linenum-w);
  width: var(--sql-linenum-w);
  margin-right: 12px;
  padding-right: 8px;
  border-right: 1px solid var(--border);
  text-align: right;
  color: var(--text-muted);
  user-select: none;
  -webkit-user-select: none;
}
.sql-line-code {
  flex: 1;
  min-width: 0;
  white-space: pre;
  word-break: break-all;
}
#output.wrap .sql-line-code { white-space: pre-wrap; word-break: break-word; }

.badge { display: inline-block; padding: 1px 7px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-ok   { background: rgba(52,200,138,.15); color: var(--success); }
.badge-err  { background: rgba(239,68,68,.15);  color: var(--danger); }
.badge-info { background: rgba(59,130,246,.15); color: var(--primary); }

/* SQL 语法高亮 */
.sql-kw    { color: #60a5fa; font-weight: 600; }
.sql-str   { color: #86efac; }
.sql-num   { color: #f87171; }
.sql-cmt   { color: #7a7060; font-style: italic; }
.sql-var   { color: #c4b5fd; }
.sql-op    { color: #7a7060; }
.sql-ident { color: #a8b8cc; }

:root.theme-light .sql-kw    { color: #1d4ed8; }
:root.theme-light .sql-str   { color: #15803d; }
:root.theme-light .sql-num   { color: #b91c1c; }
:root.theme-light .sql-cmt   { color: #78634a; }
:root.theme-light .sql-var   { color: #7c3aed; }
:root.theme-light .sql-op    { color: #78634a; }
:root.theme-light .sql-ident { color: #2e3d52; }
