/* SqlDriver admin console */
:root {
    --bg: #f3f5fb;
    --surface: #ffffff;
    --surface-2: #f7f8fc;
    --ink: #1b2135;
    --ink-2: #3a4260;
    --muted: #6b7390;
    --line: #e4e7f1;
    --line-2: #d6dae8;
    --indigo: #5b5bf0;
    --violet: #8b5cf6;
    --pink: #ec4899;
    --amber: #f59e0b;
    --teal: #0fb89a;
    --green: #16a34a;
    --blue: #3b82f6;
    --red: #e11d48;
    --grad: linear-gradient(120deg, #4f46e5 0%, #7c3aed 45%, #db2777 100%);
    --grad-soft: linear-gradient(120deg, rgba(99, 102, 241, .10), rgba(236, 72, 153, .10));
    --shadow: 0 1px 2px rgba(27, 33, 53, .05), 0 6px 20px rgba(27, 33, 53, .06);
    --radius: 14px;
    --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.45;
}
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(900px 420px at 0% 0%, rgba(124, 58, 237, .08), transparent 60%),
        radial-gradient(800px 380px at 100% 0%, rgba(236, 72, 153, .07), transparent 60%);
}
code { background: #eef0f8; padding: 1px 6px; border-radius: 6px; font-family: var(--mono); font-size: .9em; }
h1 { font-size: 22px; margin: 0 0 18px; letter-spacing: -.01em; }

/* ---------- top bar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 22px;
    height: 58px;
    padding: 0 22px;
    color: #fff;
    background: var(--grad);
    box-shadow: 0 6px 24px rgba(79, 70, 229, .25);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 750; font-size: 16px; letter-spacing: .2px; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: rgba(255, 255, 255, .18); border: 1px solid rgba(255, 255, 255, .28); }
.nav { display: flex; gap: 6px; }
.nav a { color: rgba(255, 255, 255, .82); text-decoration: none; padding: 7px 14px; border-radius: 999px; font-weight: 600; transition: background .15s, color .15s; }
.nav a:hover { color: #fff; background: rgba(255, 255, 255, .14); }
.nav a.active { color: #4338ca; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .12); }
.spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 8px; color: rgba(255, 255, 255, .92); font-weight: 600; }
.avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: rgba(255, 255, 255, .22); font-size: 12px; }
.topbar form { margin: 0; }
.btn-ghost { color: #fff; background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .3); padding: 6px 14px; border-radius: 999px; cursor: pointer; font: inherit; font-weight: 600; }
.btn-ghost:hover { background: rgba(255, 255, 255, .24); }

main { max-width: 1160px; margin: 26px auto; padding: 0 20px; }
main.wide { max-width: none; width: 100%; margin: 0; padding: 10px 8px; }

/* ---------- cards, tables, forms ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { border-bottom: 1px solid var(--line); padding: 10px 12px; text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; background: var(--surface-2); }
tbody tr:hover td { background: #fafbff; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.on { background: #dcfce7; color: var(--green); }
.pill.off { background: #ffe4e6; color: var(--red); }
label { display: block; font-weight: 650; margin: 0 0 6px; color: var(--ink-2); font-size: 13px; }
select, input[type=text], input[type=password], input[type=number], input[type=search], textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    font: inherit;
    color: var(--ink);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(139, 92, 246, .18); }
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--grad); color: #fff; border: 0; padding: 10px 18px; border-radius: 10px;
    cursor: pointer; font: inherit; font-weight: 700; box-shadow: 0 4px 14px rgba(124, 58, 237, .3);
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.muted { color: var(--muted); }
.error { background: #fff1f3; color: var(--red); border: 1px solid #fecdd6; padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; }
.ok { color: var(--green); }

/* ---------- dashboard ---------- */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--c, var(--violet)); }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 28px; font-weight: 800; margin-top: 4px; }

/* ---------- login ---------- */
.login-wrap { max-width: 400px; margin: 70px auto; }
.login-wrap .card { padding: 28px; }
.login-wrap h1 { text-align: center; }

/* =====================================================================
   Query workbench
   ===================================================================== */
.workbench { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 10px; align-items: start; }
.wb-side { display: flex; flex-direction: column; gap: 10px; position: sticky; top: 68px; max-height: calc(100vh - 78px); }
.wb-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.panel h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.panel-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.panel-head .count { margin-left: auto; font-size: 11px; font-weight: 700; color: var(--violet); background: #f1edff; padding: 2px 8px; border-radius: 999px; }
.panel.conn { background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--grad) border-box; border: 1.5px solid transparent; }
.field { margin-bottom: 10px; }
.field-row { display: flex; gap: 6px; }
.icon-btn {
    display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 9px;
    border: 1px solid var(--line-2); border-radius: 10px; background: #fff; color: var(--ink-2);
    cursor: pointer; font: inherit; font-weight: 600; white-space: nowrap;
}
.icon-btn:hover { border-color: var(--violet); color: var(--violet); background: #faf8ff; }
.icon-btn.sm { min-width: 28px; height: 28px; border-radius: 8px; font-size: 12px; }
.conn-status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #cbd0df; flex: none; }
.dot.on { background: var(--teal); box-shadow: 0 0 0 4px rgba(15, 184, 154, .18); }
.dot.off { background: var(--red); box-shadow: 0 0 0 4px rgba(225, 29, 72, .14); }
.dot.busy { background: var(--amber); box-shadow: 0 0 0 4px rgba(245, 158, 11, .2); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.explorer { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.explorer input[type=search] { padding: 7px 10px; margin-bottom: 8px; }
.tree { overflow: auto; min-height: 120px; flex: 1; margin: 0 -6px; font-size: 13px; }
.tree-group > summary { list-style: none; cursor: pointer; padding: 5px 6px; font-weight: 700; color: var(--ink-2); border-radius: 8px; display: flex; align-items: center; gap: 6px; }
.tree-group > summary::-webkit-details-marker { display: none; }
.tree-group > summary::before { content: "▸"; color: var(--muted); font-size: 10px; transition: transform .15s; }
.tree-group[open] > summary::before { transform: rotate(90deg); }
.tree-group > summary .n { margin-left: auto; font-size: 11px; color: var(--muted); font-weight: 600; }
.tree-obj > summary { list-style: none; cursor: pointer; padding: 4px 6px 4px 18px; border-radius: 8px; display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.tree-obj > summary::-webkit-details-marker { display: none; }
.tree-obj > summary:hover, .tree-leaf:hover { background: #f4f1ff; }
.tree-obj .schema { color: var(--muted); }
.tree-obj .name { overflow: hidden; text-overflow: ellipsis; }
.tree-obj .act { margin-left: auto; opacity: 0; border: 0; background: #ede9fe; color: var(--violet); border-radius: 6px; font-size: 11px; font-weight: 700; padding: 1px 7px; cursor: pointer; }
.tree-obj > summary:hover .act { opacity: 1; }
.ico { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; font-size: 10px; font-weight: 800; color: #fff; flex: none; }
.ico.U { background: var(--blue); }
.ico.V { background: var(--teal); }
.ico.P { background: var(--amber); }
.ico.F { background: var(--pink); }
.tree-leaf { padding: 3px 6px 3px 44px; border-radius: 8px; cursor: pointer; display: flex; gap: 8px; white-space: nowrap; }
.tree-leaf .t { color: var(--muted); font-family: var(--mono); font-size: 11.5px; margin-left: auto; }
.tree-empty { color: var(--muted); padding: 10px 8px; font-size: 12.5px; }

.history { max-height: 230px; display: flex; flex-direction: column; }
.history ul { list-style: none; margin: 0 -6px; padding: 0; overflow: auto; }
.history li { padding: 6px 8px; border-radius: 8px; cursor: pointer; display: grid; grid-template-columns: 8px 1fr; gap: 8px; align-items: start; }
.history li:hover { background: #f4f1ff; }
.history li .sql { font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.history li .meta { font-size: 11px; color: var(--muted); }
.history li .dot { margin-top: 5px; width: 8px; height: 8px; }
.history li.tree-empty { display: block; cursor: default; }
.history li.tree-empty:hover { background: none; }

/* toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow); }
.toolbar .sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }
.toolbar .opt { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.toolbar .opt input, .toolbar .opt select { width: auto; padding: 6px 8px; font-size: 13px; }
.toolbar .opt input { width: 92px; }
.btn-run { padding: 9px 18px; }
.btn-cancel { background: linear-gradient(120deg, #f43f5e, #f97316); box-shadow: 0 4px 14px rgba(244, 63, 94, .3); }
kbd { font-family: var(--mono); font-size: 10.5px; background: rgba(255, 255, 255, .22); border: 1px solid rgba(255, 255, 255, .35); border-radius: 5px; padding: 0 5px; }
.context-chip { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--grad-soft); color: #4c1d95; font-weight: 650; font-size: 12.5px; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* editor */
.editor-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.editor-card .CodeMirror { height: 260px; font-family: var(--mono); font-size: 13.5px; line-height: 1.55; }
.editor-resize { height: 8px; cursor: ns-resize; background: var(--surface-2); border-top: 1px solid var(--line); display: grid; place-items: center; }
.editor-resize::after { content: ""; width: 36px; height: 3px; border-radius: 3px; background: var(--line-2); }
.editor-foot { display: flex; gap: 14px; align-items: center; padding: 6px 12px; font-size: 12px; color: var(--muted); background: var(--surface-2); border-top: 1px solid var(--line); }
.editor-foot .hint { margin-left: auto; }

/* syntax colours (CodeMirror 5 "sqld" theme) */
.cm-s-sqld.CodeMirror { background: #fff; color: #1f2544; }
.cm-s-sqld .CodeMirror-gutters { background: #fafbff; border-right: 1px solid var(--line); }
.cm-s-sqld .CodeMirror-linenumber { color: #a3a9c2; }
.cm-s-sqld .CodeMirror-activeline-background { background: #f6f3ff; }
.cm-s-sqld .CodeMirror-activeline-gutter { background: #efeaff; }
.cm-s-sqld .CodeMirror-selected { background: #e0e7ff !important; }
.cm-s-sqld .CodeMirror-cursor { border-left: 2px solid var(--violet); }
.cm-s-sqld .cm-keyword { color: #7c3aed; font-weight: 700; }
.cm-s-sqld .cm-builtin { color: #0891b2; font-weight: 600; }
.cm-s-sqld .cm-string, .cm-s-sqld .cm-string-2 { color: #059669; }
.cm-s-sqld .cm-number { color: #ea580c; }
.cm-s-sqld .cm-comment { color: #94a3b8; font-style: italic; }
.cm-s-sqld .cm-operator { color: #db2777; }
.cm-s-sqld .cm-atom { color: #d97706; font-weight: 700; }
.cm-s-sqld .cm-variable-2 { color: #2563eb; }
.cm-s-sqld .cm-variable-3, .cm-s-sqld .cm-type { color: #0891b2; }
.cm-s-sqld .cm-bracket { color: #64748b; }
.cm-s-sqld .cm-punctuation { color: #64748b; }
.cm-s-sqld .CodeMirror-matchingbracket { color: #16a34a !important; background: #dcfce7; font-weight: 700; }
.cm-s-sqld .cm-error-line { background: #fff1f3; }
.cm-s-sqld .CodeMirror-placeholder { color: #a3a9c2; }
.CodeMirror-hints { border-radius: 10px; border: 1px solid var(--line-2); box-shadow: 0 10px 30px rgba(27, 33, 53, .15); font-family: var(--mono); font-size: 12.5px; padding: 4px; }
.CodeMirror-hint { border-radius: 6px; padding: 3px 8px; }
li.CodeMirror-hint-active { background: var(--violet); }

/* results */
.results { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.results-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { border: 0; background: transparent; padding: 8px 14px; border-radius: 10px 10px 0 0; cursor: pointer; font: inherit; font-weight: 650; color: var(--muted); border-bottom: 3px solid transparent; }
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tab.active { color: #5b21b6; border-bottom-color: var(--violet); background: #faf8ff; }
.tab .n { font-size: 11px; font-weight: 700; margin-left: 6px; padding: 1px 7px; border-radius: 999px; background: #ede9fe; color: #6d28d9; }
.tab.msgs .n { background: #e0f2fe; color: #0369a1; }
.tab.err { color: var(--red); }
.tab.err .n { background: #ffe4e6; color: var(--red); }
.result-stats { margin-left: auto; display: flex; gap: 8px; padding-bottom: 8px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.badge.ok { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.badge.bad { background: #ffe4e6; color: var(--red); border-color: #fecdd6; }
.badge.warn { background: #fef3c7; color: #b45309; border-color: #fde68a; }
.badge.info { background: #e0f2fe; color: #0369a1; border-color: #bae6fd; }

.grid-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.grid-toolbar input[type=search] { width: 260px; padding: 7px 10px; }
.grid-toolbar .grow { flex: 1; }
.grid-toolbar .filter-help { font-size: 12px; color: var(--muted); }
.grid-host { height: 62vh; min-height: 320px; }
.messages { margin: 0; padding: 14px 16px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; max-height: 62vh; overflow: auto; color: var(--ink-2); }
.messages .m-err { color: var(--red); font-weight: 600; }
.messages .m-ok { color: var(--green); font-weight: 600; }
.empty-state { display: grid; place-items: center; text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state .art { width: 64px; height: 64px; border-radius: 18px; background: var(--grad-soft); display: grid; place-items: center; margin: 0 auto 12px; color: var(--violet); }
.empty-state b { color: var(--ink-2); display: block; margin-bottom: 4px; font-size: 15px; }
.running-bar { height: 3px; background: linear-gradient(90deg, transparent, var(--violet), var(--pink), transparent); background-size: 200% 100%; animation: slide 1.1s linear infinite; }
@keyframes slide { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* AG Grid tweaks (theme colours are set in query.js) */
.grid-host .ag-header-cell-label { align-items: center; }
.grid-host .hdr-stack { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.grid-host .hdr-stack .ag-header-cell-text { overflow: hidden; text-overflow: ellipsis; }
.grid-host .col-type { font-family: var(--mono); font-size: 10.5px; font-weight: 500; color: #8b90ad; }
.grid-host .ag-cell.rownum { color: #a3a9c2; background: #fafbff; font-family: var(--mono); font-size: 11.5px; text-align: right; }
.grid-host .ag-cell.cell-num { text-align: right; }
.grid-host .ag-floating-filter-input input { border-radius: 7px; }
.grid-host .ag-cell { user-select: text; }
.v-null { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .04em; color: #a3a9c2; background: #f2f3f8; border-radius: 5px; padding: 0 6px; font-style: italic; }
.v-num { color: #c2410c; font-family: var(--mono); font-size: 12.5px; }
.v-date { color: #0e7490; font-family: var(--mono); font-size: 12.5px; }
.v-bin { color: #7c3aed; font-family: var(--mono); font-size: 12px; }
.v-true { color: #15803d; background: #dcfce7; border-radius: 5px; padding: 0 7px; font-weight: 700; font-size: 11.5px; }
.v-false { color: #be123c; background: #ffe4e6; border-radius: 5px; padding: 0 7px; font-weight: 700; font-size: 11.5px; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; background: #1f2544; color: #fff; padding: 10px 16px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); font-weight: 600; opacity: 0; transform: translateY(8px); transition: all .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }

@media (max-width: 980px) {
    .workbench { grid-template-columns: minmax(0, 1fr); }
    .wb-side { position: static; max-height: none; }
    .explorer .tree { max-height: 300px; }
    .context-chip { max-width: 100%; margin-left: 0; }
}
@media (max-width: 640px) {
    .topbar { gap: 10px; padding: 0 12px; }
    .user-chip { display: none; }
    .grid-toolbar input[type=search] { width: 100%; }
}
