/* ==========================================================================
   SQL Sandbox — premium UI layer
   Structure: tokens · base · header · layout · sidebar · editor · results ·
              explainer (viz) · dialogs · responsive
   ========================================================================== */

:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --bg-grad: radial-gradient(1100px 520px at 12% -10%, rgba(99,102,241,.10), transparent 60%),
             radial-gradient(900px 480px at 100% 0%, rgba(14,165,233,.08), transparent 55%);
  --panel: #ffffff;
  --panel-2: #fbfbfd;
  --head: #f1f2f8;
  --line: #e4e6ef;
  --line-strong: #cfd3e1;
  --fg: #12141d;
  --fg-2: #353a4d;
  --muted: #687089;
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --accent-fg: #ffffff;
  --accent-soft: #eceafe;
  --code-bg: #fcfcfe;
  --kw: #a21caf; --str: #15803d; --num: #b45309; --cmt: #8b92a8;
  --err: #c0262d; --err-bg: #fdecee;
  --ok: #15803d; --ok-bg: #e6f6ec;
  --p0: #e5484d; --p1: #3e63dd; --p2: #2f9e63; --p3: #d99100; --p4: #8e4ec6; --p5: #12a594; --p6: #d6409f; --p7: #e2682a;
  --src0: #2f6fdd; --src1: #d9730d; --src2: #8b46d6; --src3: #0d9488; --src4: #c2185b;
  --shadow-sm: 0 1px 2px rgba(18,20,40,.05);
  --shadow: 0 1px 2px rgba(18,20,40,.04), 0 12px 32px -18px rgba(30,32,80,.28);
  --shadow-pop: 0 24px 60px -16px rgba(20,22,60,.38);
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
  --r-sm: 8px; --r: 12px; --r-lg: 16px;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark;
    --bg: #0a0b12;
    --bg-grad: radial-gradient(1100px 560px at 10% -10%, rgba(99,102,241,.16), transparent 60%),
               radial-gradient(900px 480px at 100% 0%, rgba(56,189,248,.07), transparent 55%);
    --panel: #121420; --panel-2: #0f111b; --head: #181b2a; --line: #232739; --line-strong: #323853;
    --fg: #eceef7; --fg-2: #c3c8dc; --muted: #8b92ac;
    --accent: #8b8cf8; --accent-2: #a78bfa; --accent-fg: #0b0b1d; --accent-soft: #1d1f3d; --code-bg: #0e101a;
    --kw: #e879f9; --str: #6ee7a0; --num: #fbbf6a; --cmt: #636b86;
    --err: #ff8a90; --err-bg: #2c1519; --ok: #6ee7a0; --ok-bg: #11271b;
    --p0: #ff6b6f; --p1: #7b97ff; --p2: #4cc38a; --p3: #f5b83d; --p4: #b98af0; --p5: #2fd4c0; --p6: #f06cba; --p7: #ff8a50;
    --src0: #6a9bff; --src1: #ff9a3d; --src2: #b98af0; --src3: #2fd4c0; --src4: #f06cba;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow: 0 1px 2px rgba(0,0,0,.35), 0 16px 40px -20px rgba(0,0,0,.7);
    --shadow-pop: 0 28px 70px -16px rgba(0,0,0,.8);
  }
}
:root[data-theme="dark"] { color-scheme: dark;
  --bg: #0a0b12;
  --bg-grad: radial-gradient(1100px 560px at 10% -10%, rgba(99,102,241,.16), transparent 60%),
             radial-gradient(900px 480px at 100% 0%, rgba(56,189,248,.07), transparent 55%);
  --panel: #121420; --panel-2: #0f111b; --head: #181b2a; --line: #232739; --line-strong: #323853;
  --fg: #eceef7; --fg-2: #c3c8dc; --muted: #8b92ac;
  --accent: #8b8cf8; --accent-2: #a78bfa; --accent-fg: #0b0b1d; --accent-soft: #1d1f3d; --code-bg: #0e101a;
  --kw: #e879f9; --str: #6ee7a0; --num: #fbbf6a; --cmt: #636b86;
  --err: #ff8a90; --err-bg: #2c1519; --ok: #6ee7a0; --ok-bg: #11271b;
  --p0: #ff6b6f; --p1: #7b97ff; --p2: #4cc38a; --p3: #f5b83d; --p4: #b98af0; --p5: #2fd4c0; --p6: #f06cba; --p7: #ff8a50;
  --src0: #6a9bff; --src1: #ff9a3d; --src2: #b98af0; --src3: #2fd4c0; --src4: #f06cba;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 16px 40px -20px rgba(0,0,0,.7);
  --shadow-pop: 0 28px 70px -16px rgba(0,0,0,.8);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); background-image: var(--bg-grad); background-repeat: no-repeat; background-attachment: fixed;
  color: var(--fg); font-family: var(--font-ui); font-size: 14.5px; line-height: 1.55;
  font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  padding: 0 max(20px, env(safe-area-inset-right, 0px)) 40px max(20px, env(safe-area-inset-left, 0px));
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); background: var(--bg); z-index: 30; }
button { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; border: 3px solid transparent; }
::-webkit-scrollbar-corner { background: transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

.app { max-width: 1440px; margin: 0 auto; }
.label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--fg-2); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; font-weight: 500; font-size: 13.5px; line-height: 1.2;
  box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s, color .15s, transform .08s, box-shadow .15s;
}
.btn:hover { border-color: var(--line-strong); background: var(--head); color: var(--fg); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 5px 11px; font-size: 12.5px; border-radius: 8px; }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff) 0%, var(--accent) 100%);
  color: var(--accent-fg); border-color: color-mix(in srgb, var(--accent) 75%, #000); font-weight: 600; padding: 9px 18px; font-size: 14px;
  box-shadow: 0 1px 0 rgba(255,255,255,.28) inset, 0 6px 16px -6px color-mix(in srgb, var(--accent) 70%, transparent);
}
.btn.primary:hover { filter: brightness(1.07); background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff) 0%, var(--accent) 100%); color: var(--accent-fg); }
.btn.sm.primary { padding: 5px 11px; font-size: 12.5px; }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 55%, var(--line)); background: var(--err-bg); }
.btn.dangerfill { background: var(--err); color: #fff; border-color: var(--err); font-weight: 600; }
.btn.quiet { border-color: transparent; background: transparent; box-shadow: none; color: var(--muted); padding: 4px 2px; margin-top: 6px; font-size: 12.5px; }
.btn.quiet:hover { color: var(--err); background: transparent; }
.btn.quiet.danger { color: var(--err); }
kbd {
  font-family: var(--font-code); font-size: 10.5px; padding: 2px 6px; border-radius: 5px; margin-left: 4px;
  background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.28); color: inherit; opacity: .95;
}
.btn:not(.primary) kbd { background: var(--head); border-color: var(--line); }

/* ---------- header ---------- */
header.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 14px 0;
  margin-bottom: 4px;
}
header.bar::before {
  content: ""; position: absolute; inset: 0 calc(50% - 50vw); z-index: -1;
  background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; min-width: 0; }
.logo {
  flex: none; width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(145deg, var(--accent-2), var(--accent) 55%, #0ea5e9);
  box-shadow: 0 1px 0 rgba(255,255,255,.35) inset, 0 8px 18px -6px color-mix(in srgb, var(--accent) 65%, transparent);
}
.logo svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.brand-t { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-n { font-size: 16.5px; font-weight: 650; letter-spacing: -.015em; }
.brand-n b { font-weight: 650; background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand small { font-size: 12px; color: var(--muted); margin-top: 3px; }
.dbchip {
  display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-code); font-size: 12px; font-weight: 500;
  padding: 5px 12px 5px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.dbchip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 22%, transparent); }
.dbchip.none { background: transparent; border-color: var(--line); color: var(--muted); }
.dbchip.none::before { box-shadow: none; opacity: .5; }
.save { display: inline-flex; align-items: center; font-size: 12px; font-weight: 500; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: var(--panel); white-space: nowrap; }
.save::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; margin-right: 8px; }
.save.saved { color: var(--ok); } .save.saving { color: var(--num); } .save.saving::before { animation: pulse 1s ease-in-out infinite; }
.save.err { color: var(--err); border-color: var(--err); }
@keyframes pulse { 50% { opacity: .3; } }
.iconbtn { width: 34px; height: 34px; padding: 0; border-radius: 10px; }
.iconbtn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn .moon { display: none; }
:root[data-theme="dark"] .iconbtn .sun { display: none; } :root[data-theme="dark"] .iconbtn .moon { display: block; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .iconbtn .sun { display: none; } :root:not([data-theme="light"]) .iconbtn .moon { display: block; } }

/* ---------- layout & cards ---------- */
main { display: grid; grid-template-columns: 288px minmax(0, 1fr); gap: 22px; padding-top: 22px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.editor, .res, aside, details.help {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow);
}

/* ---------- sidebar ---------- */
aside { padding: 16px; min-width: 0; position: sticky; top: calc(env(safe-area-inset-top, 0px) + 84px); max-height: calc(100vh - 108px); overflow: auto; }
aside > details > summary { display: none; cursor: pointer; font-weight: 600; list-style: none; padding: 2px 0; }
aside > details > summary::-webkit-details-marker { display: none; }
.lblrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.lblrow .label { margin: 0; }
.db { margin-bottom: 8px; }
.dbrow { display: flex; align-items: center; gap: 2px; }
.dbrow > button.dbname {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: left; border: 0; background: transparent;
  padding: 7px 8px; border-radius: 9px; cursor: pointer; font-family: var(--font-code); font-size: 13px; font-weight: 500; color: var(--fg-2); transition: background .15s;
}
.dbrow > button.dbname:hover { background: var(--head); }
.db.current .dbrow > button.dbname { color: var(--accent); background: var(--accent-soft); }
.db.current .dbrow > button.dbname::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.db:not(.current) .dbrow > button.dbname::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--muted); }
.tables { margin: 4px 0 0 15px; padding-left: 10px; border-left: 1px solid var(--line); }
.tables details summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 7px; font-family: var(--font-code); font-size: 12.5px; color: var(--fg-2); }
.tables details summary::-webkit-details-marker { display: none; }
.tables details summary::before { content: ""; flex: none; width: 5px; height: 5px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); margin: 0 3px 0 1px; transition: transform .15s; }
.tables details[open] > summary::before { transform: rotate(45deg); }
.tables details summary:hover { background: var(--head); }
.tname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; font-family: var(--font-ui); }
.browse { border: 1px solid var(--line); background: var(--panel-2); color: var(--accent); cursor: pointer; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; }
.browse:hover { border-color: var(--accent); background: var(--accent-soft); }
.cols { list-style: none; margin: 2px 0 6px 14px; padding: 0; font-family: var(--font-code); font-size: 12px; color: var(--muted); }
.cols li { display: flex; align-items: center; gap: 2px; justify-content: space-between; padding: 2px 4px; border-radius: 5px; }
.cols li:hover { background: var(--head); }
.cols li > span:first-child { flex: 1; min-width: 0; color: var(--fg-2); }
.cols .ty { opacity: .8; margin-right: 4px; font-size: 11px; }
.cols.fks { margin-top: 0; } .cols.fks:empty { display: none; }
.pk { color: var(--num); font-weight: 700; margin-left: 6px; font-size: 9.5px; padding: 1px 5px; border-radius: 4px; background: color-mix(in srgb, var(--num) 14%, transparent); }
.fkrow .pk { color: var(--accent); background: var(--accent-soft); }
.addc { margin: 0 0 6px 14px; font-size: 12px; }
.empty-note { color: var(--muted); font-size: 12.5px; padding: 3px 6px; }
.ib { flex: none; border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 5px; border-radius: 7px; display: inline-grid; place-items: center; transition: background .15s, color .15s; }
.ib:hover { color: var(--accent); background: var(--head); }
.ib.del:hover { color: var(--err); background: var(--err-bg); }
.ib svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.cols li .ib { padding: 3px; }
@media (pointer: coarse) { .ib { padding: 9px; } .ib svg { width: 16px; height: 16px; } }

.scripts { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.scripts .label { display: block; margin-bottom: 8px; }
.scripts ul { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.scripts li { display: flex; align-items: center; gap: 4px; }
.scripts li.empty-note { padding: 4px 6px; }
.scripts .sname { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 13.5px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scripts .sname:hover { background: var(--head); color: var(--accent); }
.scripts .sdel { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 17px; line-height: 1; padding: 2px 8px; border-radius: 6px; }
.scripts .sdel:hover { color: var(--err); background: var(--err-bg); }
.scripts form { display: flex; gap: 6px; }
.scripts .row { display: flex; flex-wrap: wrap; gap: 6px; }
.scripts input, dialog input[type=text], dialog select {
  font: inherit; font-size: 13.5px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--code-bg); color: var(--fg);
  flex: 1; min-width: 0; transition: border-color .15s, box-shadow .15s;
}
.scripts input:focus, dialog input[type=text]:focus, dialog select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.scripts input::placeholder { color: var(--muted); opacity: .8; }
dialog input[type=text], dialog select { width: 100%; flex: none; }
.bk-msg { margin: 8px 0 0; font-size: 12px; color: var(--muted); min-height: 1em; }

/* ---------- editor ---------- */
.editor { overflow: hidden; }
.examples { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 13px; font-size: 12.5px; font-weight: 500; color: var(--fg-2);
  cursor: pointer; box-shadow: var(--shadow-sm); transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.codebox { position: relative; background: var(--code-bg); height: 280px; min-height: 160px; max-height: 70vh; resize: vertical; overflow: hidden; }
.codebox pre, .codebox textarea {
  position: absolute; inset: 0; margin: 0; padding: 14px 16px 14px 68px; border: 0; width: 100%; height: 100%;
  font-family: var(--font-code); font-size: 13.5px; line-height: 1.7; tab-size: 2; white-space: pre; overflow: auto; letter-spacing: 0; font-variant-ligatures: none;
}
.codebox pre { pointer-events: none; color: var(--fg); overflow: hidden; }
.codebox textarea { background: transparent; color: transparent; caret-color: var(--accent); resize: none; outline: none; }
.codebox textarea::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); color: transparent; }
.codebox pre.gutter { inset: 0 auto 0 0; width: 52px; height: auto; padding: 14px 12px 14px 0; text-align: right; color: var(--cmt); background: var(--panel-2); border-right: 1px solid var(--line); overflow: hidden; user-select: none; opacity: .9; }
.k { color: var(--kw); font-weight: 500; } .s { color: var(--str); } .n { color: var(--num); } .c { color: var(--cmt); font-style: italic; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--panel-2); }
.actions .hint { color: var(--muted); font-size: 12.5px; margin-left: auto; }

/* ---------- results ---------- */
.results-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 14px; }
.results-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-left: auto; }
.tgl { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.tgl input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; cursor: pointer; }
.results { display: flex; flex-direction: column; gap: 14px; }
.results:empty::before {
  content: "No results yet — write a query above and press Run, or pick one of the examples.";
  display: block; padding: 44px 24px; text-align: center; color: var(--muted); font-size: 14px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--r-lg); background: color-mix(in srgb, var(--panel) 55%, transparent);
}
.res { min-width: 0; overflow: hidden; }
.res.err { border-color: color-mix(in srgb, var(--err) 55%, var(--line)); }
.res-head { display: flex; align-items: center; gap: 12px; padding: 11px 16px; background: var(--panel-2); border-bottom: 1px solid var(--line); min-width: 0; }
.res.err .res-head { background: var(--err-bg); }
.res-head .dot { display: none; }
.kind { flex: none; font-size: 10.5px; font-weight: 700; letter-spacing: .08em; padding: 3px 9px; border-radius: 999px; }
.kind.read { background: var(--accent-soft); color: var(--accent); }
.kind.write { background: color-mix(in srgb, var(--num) 15%, transparent); color: var(--num); }
.kind.ddl { background: color-mix(in srgb, var(--kw) 14%, transparent); color: var(--kw); }
.kind.bad { background: color-mix(in srgb, var(--err) 18%, transparent); color: var(--err); }
.sqltext { flex: 1; min-width: 0; font-family: var(--font-code); font-size: 12.5px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { flex: none; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.msg { padding: 16px; font-size: 14.5px; }
.res.err .msg { color: var(--err); font-weight: 500; }
.more { padding: 10px 16px; color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--line); background: var(--panel-2); }
.tabs { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.tab { border: 0; background: transparent; padding: 12px 14px; cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s; }
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab:disabled { opacity: .45; cursor: not-allowed; }
.tab .spark { display: inline-block; margin-left: 4px; }

.tablewrap { overflow: auto; max-height: 440px; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-family: var(--font-code); font-size: 12.5px; }
th, td { padding: 9px 16px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { position: sticky; top: 0; background: var(--head); font-family: var(--font-ui); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 1px solid var(--line-strong); z-index: 1; }
table:not(.vt) tbody tr:last-child td { border-bottom: 0; }
table:not(.vt) tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--head) 40%, transparent); }
th.rn, td.rn { color: var(--muted); text-align: right; width: 1%; font-weight: 400; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 7%, var(--panel)) !important; }
.null { color: var(--muted); font-style: italic; opacity: .75; }

.sum { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.sum-hint { margin: 0; color: var(--muted); font-size: 14px; }
.sum-err { border: 1px solid color-mix(in srgb, var(--err) 50%, var(--line)); background: var(--err-bg); border-radius: 10px; padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
.sum-err b { color: var(--err); } .sum-err code { font-family: var(--font-code); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.sum-all summary { cursor: pointer; font-size: 13.5px; color: var(--accent); font-weight: 500; }
.sum-all ul { list-style: none; margin: 10px 0 0; padding: 0; max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.sum-all li { display: grid; grid-template-columns: 20px minmax(0, 1.4fr) minmax(0, 1fr); gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--line); font-size: 12.5px; align-items: baseline; }
.sum-all li:last-child { border-bottom: 0; }
.sum-all li .st { color: var(--ok); } .sum-all li.bad .st, .sum-all li.bad .mm { color: var(--err); }
.sum-all li code { font-family: var(--font-code); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sum-all li .mm { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

details.help { padding: 4px 20px; }
details.help summary { cursor: pointer; font-weight: 600; padding: 14px 0; list-style: none; display: flex; align-items: center; gap: 10px; }
details.help summary::-webkit-details-marker { display: none; }
details.help summary::before { content: ""; width: 6px; height: 6px; border-right: 1.8px solid var(--muted); border-bottom: 1.8px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; }
details.help[open] summary::before { transform: rotate(45deg); }
details.help ul { margin: 0 0 16px; padding-left: 20px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; }
details.help code { font-family: var(--font-code); font-size: 12px; color: var(--fg-2); background: var(--head); padding: 1px 6px; border-radius: 5px; }
.foot { color: var(--muted); font-size: 12.5px; margin: 0; padding: 2px 4px; text-align: center; }

/* ---------- visual explainer ---------- */
.viz { padding: 20px 22px 24px; min-width: 0; }
.vz-sql { margin-bottom: 18px; }
.vz-sql pre { margin: 8px 0 0; padding: 14px 16px; background: var(--code-bg); border: 1px solid var(--line); border-radius: 12px; font-family: var(--font-code); font-size: 13px; line-height: 1.8; white-space: pre-wrap; overflow-wrap: anywhere; }
.vz-sql .seg { border-radius: 4px; transition: opacity .25s, background-color .25s, box-shadow .25s; }
.vz-sql.focus .seg[data-k]:not([data-k=""]) { opacity: .5; }
.vz-sql.focus .seg.on { opacity: 1; background: color-mix(in srgb, var(--accent) 20%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.vz-nav { display: flex; flex-direction: column; align-items: stretch; gap: 12px; margin: 0 0 22px; }
.vz-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.vz-chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 13px 4px 5px; font-family: var(--font-ui); font-size: 13px; font-weight: 500; color: var(--fg-2); cursor: pointer; transition: all .15s; }
.vz-chip.all { padding-left: 13px; }
.vz-chip .n { display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 999px; background: var(--head); font-size: 11px; font-weight: 600; color: var(--muted); }
.vz-chip:hover { border-color: var(--accent); color: var(--accent); }
.vz-chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); box-shadow: 0 6px 14px -6px color-mix(in srgb, var(--accent) 70%, transparent); }
.vz-chip[aria-pressed="true"] .n { background: rgba(255,255,255,.25); color: inherit; }
.vz-ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.vz-pos { margin-left: auto; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.vz-nav select.spd { font: inherit; font-size: 12.5px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--fg); padding: 5px 8px; }
.vz-steps { display: flex; flex-direction: column; gap: 28px; min-width: 0; }
.step { min-width: 0; }
.step + .step { padding-top: 24px; border-top: 1px dashed var(--line); }
.step-h { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.step-n { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(145deg, var(--accent-2), var(--accent)); color: var(--accent-fg); font-size: 12px; font-weight: 700; box-shadow: 0 4px 10px -3px color-mix(in srgb, var(--accent) 60%, transparent); }
.step-l { font-family: var(--font-code); font-weight: 600; font-size: 14.5px; }
.step-t { color: var(--muted); font-size: 13px; }
.step-h .replay { margin-left: auto; }
.narr { margin: 6px 0 16px; max-width: 76ch; line-height: 1.7; font-size: 14.5px; color: var(--fg-2); }
.narr code, .vz-title code { font-family: var(--font-code); font-size: 12.5px; background: var(--head); border: 1px solid var(--line); padding: 1px 7px; border-radius: 6px; color: var(--fg); }
.narr s { opacity: .6; }
.vz-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-bottom: 10px; }
.lgl { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 600; margin-right: 2px; }
.lg { font-family: var(--font-code); font-size: 12px; padding: 2px 10px; border-radius: 999px; border: 1.5px solid var(--sc); color: var(--sc); background: color-mix(in srgb, var(--sc) 10%, transparent); }
.s0 { --sc: var(--src0); } .s1 { --sc: var(--src1); } .s2 { --sc: var(--src2); } .s3 { --sc: var(--src3); } .s4 { --sc: var(--src4); }
.vz-stats { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.pill { font-size: 12.5px; font-weight: 500; padding: 3px 11px; border-radius: 999px; background: var(--head); color: var(--muted); border: 1px solid var(--line); }
.pill.ok { color: var(--ok); background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.pill.bad { color: var(--err); background: var(--err-bg); border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.pill.warn { color: var(--num); background: color-mix(in srgb, var(--num) 12%, transparent); border-color: color-mix(in srgb, var(--num) 40%, transparent); }
.vz-title { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; font-weight: 600; margin: 0 0 8px; color: var(--fg-2); }
.vz-title .ct { color: var(--muted); font-weight: 400; }
.vz-down { text-align: center; color: var(--muted); font-size: 12px; margin: 12px 0 10px; letter-spacing: .02em; }
.vz-scroll { overflow-x: auto; padding-bottom: 4px; }
.vz-wrap { position: relative; display: grid; grid-template-columns: minmax(0, 1.5fr) var(--gap, 96px) minmax(250px, 1fr); min-width: 700px; align-items: start; }
.vz-col { min-width: 0; }
svg.arrows { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; z-index: 2; }
svg.arrows path { fill: none; stroke-width: 2; opacity: .85; pointer-events: stroke; transition: opacity .12s, stroke-width .12s; }
.vz-wrap.hovering svg.arrows path:not(.hot) { opacity: .1; }
svg.arrows path.hot { stroke-width: 3.5; opacity: 1; }
.vt-box { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); box-shadow: var(--shadow-sm); }
.vt-scroll { overflow-x: auto; }
table.vt { border-collapse: collapse; font-family: var(--font-code); font-size: 12.5px; width: 100%; }
table.vt th, table.vt td { padding: 6px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.vt tr:last-child td { border-bottom: 0; }
table.vt th { background: var(--head); font-family: var(--font-code); font-weight: 600; font-size: 12.5px; text-transform: none; letter-spacing: 0; color: var(--fg); vertical-align: bottom; position: static; border-bottom: 2px solid var(--line-strong); }
table.vt th.s0, table.vt th.s1, table.vt th.s2, table.vt th.s3, table.vt th.s4 { border-bottom-color: var(--sc); }
table.vt th .hn { display: block; }
table.vt th .hs { display: block; font-weight: 400; font-size: 10.5px; color: var(--sc, var(--muted)); max-width: 22ch; overflow: hidden; text-overflow: ellipsis; }
table.vt th .ht { display: inline-block; margin-top: 3px; font-weight: 600; font-size: 10px; padding: 0 7px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
table.vt td.s0, table.vt td.s1, table.vt td.s2, table.vt td.s3, table.vt td.s4 { background: color-mix(in srgb, var(--sc) 8%, transparent); }
table.vt td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.vt td.nul { color: var(--muted); font-style: italic; }
table.vt td.key { text-decoration: underline; text-decoration-color: var(--rc, var(--accent)); text-decoration-thickness: 2px; text-underline-offset: 3px; font-weight: 600; }
table.vt th.rn, table.vt td.rn { color: var(--muted); text-align: right; width: 1%; font-weight: 400; }
table.vt td.rn .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--rc); margin-right: 6px; }
table.vt th.mk, table.vt td.mk { font-size: 11px; font-weight: 600; letter-spacing: .02em; color: var(--muted); }
table.vt tbody tr { transition: opacity .12s; }
table.vt tbody tr.empty td { color: var(--muted); font-style: italic; padding: 14px; }
table.vt tbody tr:hover td { background: inherit !important; }
table.vt tr.keep td.mk { color: var(--ok); }
table.vt tr.drop { opacity: .5; }
table.vt tr.drop td:not(.mk):not(.rn) { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--err) 70%, transparent); background: var(--err-bg); }
table.vt tr.drop td.mk { color: var(--err); }
table.vt tr.nomatch { background: repeating-linear-gradient(135deg, transparent 0 6px, color-mix(in srgb, var(--num) 10%, transparent) 6px 12px); }
table.vt tr.nomatch td.mk { color: var(--num); }
table.vt tr.nullrow td.nul { color: var(--num); }
table.vt tr.rightonly td.rn .dot { display: none; }
table.vt tr.new td { background: color-mix(in srgb, var(--ok) 16%, transparent); }
table.vt tr.new td.mk { color: var(--ok); }
table.vt tr.deleted td { background: var(--err-bg); text-decoration: line-through; opacity: .85; }
table.vt tr.deleted td.mk { color: var(--err); text-decoration: none; }
table.vt tr.changed td.mk { color: var(--num); }
table.vt td.chg { background: color-mix(in srgb, var(--num) 18%, transparent); }
table.vt td.chg s { color: var(--muted); } table.vt td.chg .arr { margin: 0 5px; color: var(--num); } table.vt td.chg b { color: var(--fg); }
.vt-more { padding: 6px 12px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }
.vz-wrap.hovering tr[data-g]:not(.hot) { opacity: .3; }
tr.hot td { background: color-mix(in srgb, var(--rc, var(--accent)) 24%, transparent) !important; }
tr.hot { outline: 2px solid var(--rc, var(--accent)); outline-offset: -2px; }
.vz-combined { min-width: 0; } .vz-combined .vt-scroll { overflow-x: auto; }
.buckets { display: flex; flex-direction: column; gap: 10px; min-width: 260px; }
.bucket { border: 1.5px solid var(--rc); border-radius: 12px; padding: 10px 12px; background: color-mix(in srgb, var(--rc) 7%, var(--panel)); font-size: 13px; transition: opacity .12s; }
.bucket.dropped { opacity: .65; border-style: dashed; }
.vz-wrap.hovering .bucket:not(.hot) { opacity: .3; }
.bucket.hot { box-shadow: 0 0 0 2px var(--rc); }
.bk-h { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; margin-bottom: 4px; }
.bk-t { color: var(--rc); } .bk-n { color: var(--muted); font-weight: 400; font-size: 12px; }
.bk-key { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-bottom: 4px; font-family: var(--font-code); font-size: 12px; }
.bk-key i { font-style: normal; color: var(--muted); }
.bk-agg { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 8px; align-items: baseline; font-family: var(--font-code); font-size: 12px; padding: 3px 0; border-top: 1px dashed var(--line); }
.bk-agg code { font-weight: 600; } .bk-agg .calc { color: var(--muted); overflow-wrap: anywhere; } .bk-agg .eq b { color: var(--rc); font-size: 13px; }
.bk-out, .bk-rm { margin-top: 6px; font-size: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.bk-rm { color: var(--err); } .bk-rm code { font-family: var(--font-code); }
.chipv { font-family: var(--font-code); background: var(--panel); border: 1px solid var(--rc); border-radius: 5px; padding: 0 6px; }
.ddl-list { display: flex; flex-direction: column; gap: 8px; }
.ddl-row { display: grid; grid-template-columns: minmax(150px, 220px) 1fr; gap: 6px 14px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; align-items: baseline; background: var(--panel-2); }
.ddl-name { font-family: var(--font-code); font-size: 13px; } .ddl-name span { color: var(--muted); font-size: 12px; margin-left: 6px; }
.ddl-chips { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; font-size: 12px; color: var(--muted); }
.chipk { font-family: var(--font-code); font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); }
.chiptip { margin-right: 6px; }

/* animation states (used by the explainer player) */
.step.playing .pend { opacity: 0; transform: translateY(8px); }
.step.playing .pend.in { opacity: 1; transform: none; transition: opacity .35s ease, transform .35s ease; }
.step.playing table.vt tr.judge:not(.in) { opacity: 1; }
.step.playing table.vt tr.judge:not(.in) td:not(.mk):not(.rn) { text-decoration: none; background-color: transparent; }
.step.playing table.vt tr.judge:not(.in) td.mk { color: transparent; }
.step.playing table.vt tr.judge .mk, .step.playing table.vt tr.judge td { transition: opacity .3s, background-color .3s, color .3s; }
table.vt tr.scan td { background-image: linear-gradient(color-mix(in srgb, var(--accent) 24%, transparent), color-mix(in srgb, var(--accent) 24%, transparent)); }
table.vt tr.scan { outline: 2px solid var(--accent); outline-offset: -2px; }
@keyframes flashtd { 0% { background-color: color-mix(in srgb, var(--accent) 45%, transparent); } 100% { background-color: transparent; } }
tr.flash td { animation: flashtd .8s ease-out; }
@keyframes bpop { 0% { box-shadow: 0 0 0 4px var(--rc); transform: scale(1.015); } 100% { box-shadow: 0 0 0 0 transparent; transform: none; } }
.bucket.flash { animation: bpop .5s ease-out; }
@media (prefers-reduced-motion: no-preference) { .res { animation: rise .22s ease-out; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- dialogs ---------- */
dialog { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); color: var(--fg); padding: 0; width: min(660px, 94vw); max-height: 90vh; box-shadow: var(--shadow-pop); }
dialog::backdrop { background: rgba(8, 10, 22, .55); backdrop-filter: blur(4px); }
dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
dialog form { display: flex; flex-direction: column; max-height: 90vh; }
.dlg-h { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 650; font-size: 16px; letter-spacing: -.01em; }
.dlg-b { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; overflow: auto; }
.dlg-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--panel-2); }
.dlg-p { margin: 0; line-height: 1.65; color: var(--fg-2); }
.dlg-err { color: var(--err); background: var(--err-bg); border: 1px solid color-mix(in srgb, var(--err) 50%, var(--line)); border-radius: 10px; padding: 9px 13px; font-size: 13.5px; }
.fld > label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.clist { display: flex; flex-direction: column; gap: 10px; }
.ccard { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--panel-2); }
.ccard .r1 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, .8fr); gap: 8px; }
.ccard .flags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; }
.ccard .flags label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; color: var(--fg-2); }
.ccard .flags input { accent-color: var(--accent); }
.ccard .flags .ib { margin-left: auto; }

/* ---------- autocomplete popup (injected by complete.js; refine it) ---------- */
.ac { border-radius: 12px !important; box-shadow: var(--shadow-pop) !important; border-color: var(--line-strong) !important; font-family: var(--font-code); font-size: 12.5px; padding: 4px; }

/* ---------- responsive ---------- */
@media (max-width: 960px) { main { grid-template-columns: 252px minmax(0, 1fr); gap: 16px; } }
@media (max-width: 820px) {
  main { grid-template-columns: minmax(0, 1fr); gap: 16px; padding-top: 16px; }
  aside { position: static; max-height: none; padding: 12px 16px; }
  aside > details > summary { display: flex; align-items: center; gap: 10px; }
  aside > details > summary::before { content: ""; width: 6px; height: 6px; border-right: 1.8px solid var(--muted); border-bottom: 1.8px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; }
  aside > details[open] > summary::before { transform: rotate(45deg); }
  aside > details[open] > summary { margin-bottom: 12px; }
}
@media (max-width: 640px) {
  body { padding-inline: max(14px, env(safe-area-inset-left, 0px)) max(14px, env(safe-area-inset-right, 0px)); font-size: 15px; }
  .brand small { display: none; }
  .viz { padding: 16px 14px 20px; }
  .vz-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; }
  .vz-chip { flex: none; }
  .vz-pos { order: -1; width: 100%; margin-left: 0; }
  .codebox { height: 220px; }
  .actions .hint { display: none; }
  .actions .btn { flex: 1; }
  .res-head { flex-wrap: wrap; }
  .sqltext { flex-basis: 100%; order: 3; white-space: normal; max-height: 3.2em; }
  .sum-all li { grid-template-columns: 20px minmax(0, 1fr); } .sum-all li .mm { display: none; }
  .ddl-row { grid-template-columns: 1fr; }
  .ccard .r1 { grid-template-columns: 1fr 1fr; } .ccard .r1 > :first-child { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- sidebar table rows: actions reveal on hover so names stay readable ---------- */
.tables details summary { position: relative; }
.tables details summary .ib { position: absolute; top: 50%; transform: translateY(-50%); opacity: 0; pointer-events: none; background: var(--head); }
.tables details summary .ib:nth-last-child(1) { right: 4px; }
.tables details summary .ib:nth-last-child(2) { right: 30px; }
.tables details summary:hover .ib, .tables details summary:focus-within .ib { opacity: 1; pointer-events: auto; }
.tables details summary:hover .count, .tables details summary:focus-within .count { visibility: hidden; }
@media (pointer: coarse) {
  .tables details summary .ib { position: static; transform: none; opacity: 1; pointer-events: auto; background: transparent; }
  .tables details summary:hover .count { visibility: visible; }
}

/* ---------- sessions, export and import dialogs ---------- */
.sessbtn { font-family: var(--font-code); font-size: 12px; letter-spacing: -.01em; }
dialog.wide { width: min(780px, 94vw); }
.dlg-note { margin-right: auto; align-self: center; font-size: 12.5px; color: var(--muted); }
.dlg-p.small { font-size: 13px; margin-top: 8px; }
.dlg-p.warn { color: var(--err); }
.og { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px 12px; margin: 0; min-width: 0; background: var(--panel-2); }
.og > legend { padding: 0 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.og-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: 14px; align-items: start; }
.og-stack { display: flex; flex-direction: column; gap: 12px; }
.opt { display: flex; align-items: flex-start; gap: 10px; padding: 5px 0; cursor: pointer; }
.opt input { margin: 3px 0 0; accent-color: var(--accent); flex: none; }
.opt-t { display: flex; flex-direction: column; min-width: 0; }
.opt-l { font-size: 13.5px; color: var(--fg); }
.opt-h { font-size: 12px; color: var(--muted); line-height: 1.4; }
.opt.off { opacity: .45; cursor: not-allowed; }
.opt.off input { cursor: not-allowed; }
.opt-inline { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 13.5px; }
.opt-inline select { width: auto; }
.opt-stack { display: flex; flex-direction: column; gap: 8px; padding-top: 6px; }
.pick { max-height: 190px; overflow: auto; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 4px; }
.pk-db, .pk-t { display: flex; align-items: center; gap: 9px; padding: 4px 8px; border-radius: 7px; cursor: pointer; font-size: 13.5px; }
.pk-db { font-weight: 600; } .pk-t { padding-left: 30px; font-weight: 400; color: var(--fg-2); }
.pk-db:hover, .pk-t:hover { background: var(--head); }
.pk-db input, .pk-t input { accent-color: var(--accent); margin: 0; }
.pk-n { font-family: var(--font-code); font-size: 12.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pk-c { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 400; white-space: nowrap; }
.pk-tools { display: flex; gap: 4px; margin: 2px 0 8px; }
.pk-tools .btn.quiet { margin: 0; padding: 3px 8px; }
.exp-pre { margin: 0; max-height: 220px; overflow: auto; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--code-bg); font-family: var(--font-code); font-size: 12px; line-height: 1.55; white-space: pre; tab-size: 2; color: var(--fg-2); }
.exp-stat { margin-top: 6px; font-size: 12px; color: var(--muted); }
.drop { border: 1.5px dashed var(--line-strong); border-radius: 14px; padding: 22px 16px; text-align: center; cursor: pointer; background: var(--panel-2); transition: border-color .15s, background .15s; }
.drop:hover, .drop.over, .drop:focus-visible { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.drop.has { padding: 14px 16px; border-style: solid; }
.drop-t { font-weight: 600; font-size: 14px; word-break: break-all; }
.drop-s { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.found .vz-stats { margin: 0; }
.bar-track { height: 8px; border-radius: 99px; background: var(--head); overflow: hidden; border: 1px solid var(--line); }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .12s linear; }
.sess { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); }
.sess.cur { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft); flex-direction: column; align-items: flex-start; gap: 2px; }
.sess-list { display: flex; flex-direction: column; gap: 8px; }
.sess-t { flex: 1; min-width: 0; font-size: 13.5px; }
.sess-t code { font-family: var(--font-code); font-size: 12.5px; background: var(--head); padding: 1px 7px; border-radius: 6px; }
.sess-s { font-size: 12.5px; color: var(--muted); }
.sess-a { display: flex; gap: 4px; flex: none; }
.sess-a .btn.quiet { margin: 0; padding: 5px 9px; }
@media (max-width: 640px) {
  .og-grid { grid-template-columns: minmax(0, 1fr); }
  .sess { flex-wrap: wrap; }
  dialog .dlg-f { flex-wrap: wrap; }
  .dlg-note { flex-basis: 100%; }
}

/* ---------- toasts ---------- */
.toasts { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; padding: 11px 8px 11px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line-strong); box-shadow: var(--shadow-pop); font-size: 13.5px; line-height: 1.45; color: var(--fg); animation: toast-in .22s ease-out; transition: opacity .35s ease, transform .35s ease; }
.toast.out { opacity: 0; transform: translateY(8px); }
.toast-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: var(--ok); }
.toast.warn .toast-dot { background: var(--num); } .toast.err .toast-dot { background: var(--err); }
.toast.err { border-color: color-mix(in srgb, var(--err) 55%, var(--line)); }
.toast-t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-x { flex: none; border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 8px; border-radius: 6px; cursor: pointer; }
.toast-x:hover { background: var(--head); color: var(--fg); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- results history: its own scroll area ---------- */
.results { position: relative; max-height: min(68vh, 720px); overflow-y: auto; overscroll-behavior: contain; padding: 2px 8px 2px 2px; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; scroll-behavior: smooth; }
.results:empty { max-height: none; overflow: visible; }
.res-x { flex: none; border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 8px; margin: -2px -6px -2px 0; border-radius: 6px; cursor: pointer; }
.res-x:hover { background: var(--head); color: var(--err); }
@media (max-width: 640px) { .toasts { left: 16px; right: 16px; width: auto; } .results { max-height: 62vh; } }
.results > .res { flex: none; }
.chip:disabled { opacity: .45; cursor: not-allowed; transform: none; pointer-events: auto; } .chip:disabled:hover { border-color: var(--line); color: inherit; background: transparent; transform: none; }

/* ---------- history log: fixed to the bottom of the page, closed by default ---------- */
:root { --dock-h: 0px; --dock-ease: cubic-bezier(.2, .8, .2, 1); }
body { padding-bottom: calc(var(--dock-h) + 24px); }
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--panel); border-top: 1px solid var(--line-strong);
  box-shadow: 0 -10px 30px -12px rgba(15, 18, 40, .22);
  padding: 0 max(20px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(20px, env(safe-area-inset-left, 0px));
}
.dock-in { max-width: 1440px; margin: 0 auto; }
.dock-head { display: flex; align-items: center; gap: 12px; padding: 6px 0; min-height: 44px; }
.dock-bar { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 6px 4px 6px 0; cursor: pointer; border-radius: 8px; color: var(--muted); text-align: left; }
.dock-bar:hover { color: var(--fg); }
.dock-bar svg { flex: none; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform .32s var(--dock-ease); }
.dock.collapsed .dock-bar svg { transform: rotate(180deg); }
.hcount { flex: none; min-width: 22px; text-align: center; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-variant-numeric: tabular-nums; }
.hcount.bump { animation: hbump .5s var(--dock-ease); }
.logdot { flex: none; position: relative; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); transition: background .2s; }
.logdot.live { background: var(--accent); }
.logdot.live::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; animation: hping 1.1s ease-out 2; }
.ticker { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: var(--font-mono, ui-monospace, monospace); font-size: 12.5px; color: var(--fg-2); transition: opacity .25s; }
.ticker.in { animation: tick-in .5s var(--dock-ease); }
.dock:not(.collapsed) .ticker { opacity: 0; }
.dock-clear { opacity: 1; transition: opacity .25s, visibility 0s; }
.dock.collapsed .dock-clear { opacity: 0; visibility: hidden; transition: opacity .2s, visibility 0s .2s; }
.dock-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .34s var(--dock-ease); }
.dock.collapsed .dock-body { grid-template-rows: 0fr; }
.dock-clip { overflow: hidden; min-height: 0; transition: visibility 0s; }
.dock.collapsed .dock-clip { visibility: hidden; transition: visibility 0s .34s; }
.hist { list-style: none; margin: 0; padding: 2px 6px 12px 0; height: clamp(140px, 30vh, 340px); overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 6px; }
.hist:empty::before { content: attr(data-empty); margin: auto; color: var(--muted); font-size: 13.5px; }
.hitem { flex: none; display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; padding: 7px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); cursor: pointer; text-align: left; font: inherit; color: inherit; transition: border-color .15s, background .15s; }
.hitem:hover { border-color: var(--line-strong); background: var(--head); }
.hitem.err { border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }
.hitem.fresh { animation: log-in .6s var(--dock-ease); }
.htime { font-family: var(--font-mono, ui-monospace, monospace); font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hsql { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: var(--font-mono, ui-monospace, monospace); font-size: 12.5px; }
.hmeta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.hitem.err .hmeta { color: var(--err); }
@keyframes tick-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes log-in { 0% { opacity: 0; transform: translateY(-10px); background: var(--accent-soft); } 100% { opacity: 1; transform: none; } }
@keyframes hbump { 0% { transform: scale(1); } 35% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes hping { 0% { opacity: .7; transform: scale(.6); } 100% { opacity: 0; transform: scale(1.8); } }
.toasts { bottom: calc(var(--dock-h) + 16px); }
@media (max-width: 640px) {
  .dock { padding-inline: max(14px, env(safe-area-inset-left, 0px)) max(14px, env(safe-area-inset-right, 0px)); }
  .hist { height: 34vh; }
  .htime { display: none; }
  .hitem { grid-template-columns: auto minmax(0, 1fr) auto; }
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .dock { box-shadow: 0 -10px 30px -12px rgba(0, 0, 0, .6); } }
:root[data-theme="dark"] .dock { box-shadow: 0 -10px 30px -12px rgba(0, 0, 0, .6); }

/* ---------- query tabs ---------- */
.tabbar { display: flex; align-items: flex-end; gap: 4px; padding: 8px 10px 0; background: var(--head); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabbar::-webkit-scrollbar { display: none; }
.qtab { flex: none; display: flex; align-items: center; max-width: 220px; margin-bottom: -1px; border: 1px solid transparent; border-bottom: 0; border-radius: 10px 10px 0 0; color: var(--muted); transition: background .15s, color .15s, border-color .15s; }
.qtab:hover { background: color-mix(in srgb, var(--panel) 55%, transparent); color: var(--fg); }
.qtab.active { background: var(--panel); color: var(--fg); border-color: var(--line); box-shadow: inset 0 2px 0 var(--accent); }
.qtab.enter { animation: qt-in .28s var(--dock-ease, ease-out); }
.qt-name { min-width: 0; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; background: transparent; padding: 9px 4px 9px 14px; cursor: pointer; font-size: 13px; font-weight: 500; }
.qt-x { flex: none; border: 0; background: transparent; color: inherit; opacity: .55; padding: 2px 7px; margin-right: 6px; border-radius: 6px; font-size: 16px; line-height: 1; cursor: pointer; }
.qt-x:hover { opacity: 1; background: var(--head); color: var(--err); }
.qtab input { width: 130px; margin: 5px 6px 5px 8px; padding: 4px 8px; font: inherit; font-size: 13px; color: var(--fg); background: var(--panel); border: 1px solid var(--accent); border-radius: 6px; outline: none; }
.qt-add { flex: none; align-self: center; width: 28px; height: 28px; margin: 0 0 6px 2px; border: 1px dashed var(--line-strong); border-radius: 8px; background: transparent; color: var(--muted); font-size: 17px; line-height: 1; cursor: pointer; transition: color .15s, border-color .15s, background .15s; }
.qt-add:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.qt-add:disabled { opacity: .4; cursor: not-allowed; }
.hname { flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; font-weight: 600; color: var(--fg-2); }
.hname::before { content: "·"; margin-right: 8px; color: var(--muted); }
.results.swap { animation: res-swap .25s ease-out; }
@keyframes qt-in { from { opacity: 0; transform: translateY(6px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes res-swap { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- extras: history filter, run again, CSV, duplicate tab ---------- */
.hbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 2px 0 10px; }
.hchips { display: flex; gap: 6px; }
.hchip { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 999px; padding: 4px 12px; font-size: 12.5px; font-weight: 500; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.hchip:hover { color: var(--fg); border-color: var(--line-strong); }
.hchip.on { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
#histSearch { flex: 1 1 180px; min-width: 0; max-width: 320px; margin-left: auto; padding: 5px 12px; font: inherit; font-size: 13px; color: var(--fg); background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; outline: none; }
#histSearch:focus { border-color: var(--accent); box-shadow: var(--ring); }
.hist { height: clamp(120px, 26vh, 300px); }
.hitem { grid-template-columns: auto auto minmax(0, 1fr) auto auto; }
.hitem:focus-visible { box-shadow: var(--ring); }
.hrun { border: 1px solid var(--line); background: var(--panel); color: var(--accent); border-radius: 8px; padding: 2px 9px; font-size: 11px; line-height: 1.6; cursor: pointer; transition: background .15s, border-color .15s; }
.hrun:hover { background: var(--accent-soft); border-color: var(--accent); }
.csvbtn { flex: none; border: 1px solid var(--line); background: var(--panel); color: var(--fg-2); border-radius: 7px; padding: 2px 9px; font-size: 11.5px; font-weight: 600; letter-spacing: .03em; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.csvbtn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.qt-dup { flex: none; align-self: center; width: 28px; height: 28px; margin: 0 0 6px 0; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted); font-size: 14px; line-height: 1; cursor: pointer; }
.qt-dup:hover:not(:disabled) { color: var(--accent); background: var(--accent-soft); }
.qt-dup:disabled { opacity: .4; cursor: not-allowed; }
@media (max-width: 640px) { .hitem { grid-template-columns: auto minmax(0, 1fr) auto auto; } .hist { height: 30vh; } #histSearch { max-width: none; } }

/* ER diagram dialog */
dialog.er { width: min(1120px, 96vw); }
.er-b { gap: 10px; }
.er-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.er-info { font-size: 13px; color: var(--muted); }
.er-sp { flex: 1; }
.er-zoom { min-width: 44px; text-align: center; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.er-view { overflow: auto; max-height: min(62vh, 640px); border: 1px solid var(--line); border-radius: var(--r); background: var(--panel-2); box-shadow: inset 0 1px 3px rgba(18,20,40,.06); }
.er-view svg .er-node, .er-view svg .er-edge { transition: opacity .18s; cursor: default; }
.er-info { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.er-view svg { display: block; }
.er-legend { margin: 0; }

.er-view.hand { cursor: grab; user-select: none; -webkit-user-select: none; }
.er-view.hand.panning { cursor: grabbing; }
.er-view.hand .er-node, .er-view.hand .er-edge { cursor: inherit; }
.er-hand { padding: 5px 9px; }
.er-hand svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }
.er-hand.on { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
