/* =====================================================================
   SlothDB Playground — VS Code-inspired layout.
   Palette borrows from VS Code dark+ / pgAdmin 4.
   ===================================================================== */

:root {
  /* Chrome (UI surfaces) */
  --bg-app:        #1e1e1e;  /* main background */
  --bg-editor:     #1e1e1e;  /* editor area */
  --bg-panel:      #1e1e1e;  /* bottom panel */
  --bg-side:       #252526;  /* sidebar */
  --bg-activity:   #333333;  /* activity bar */
  --bg-title:      #3c3c3c;  /* title bar */
  --bg-status:     #007acc;  /* status bar (classic VS Code blue) — but we override to green */
  --bg-statusbar:  #7ed07a;
  --bg-tab-act:    #1e1e1e;
  --bg-tab-ina:    #2d2d2d;
  --bg-hover:      #2a2d2e;
  --bg-selected:   #094771;
  --bg-grid-head:  #252526;
  --bg-grid-row:   #1e1e1e;
  --bg-grid-alt:   #232629;

  /* Foreground */
  --fg:            #cccccc;
  --fg-bright:     #ffffff;
  --fg-dim:        #8c8c8c;
  --fg-fade:       #6a6a6a;

  /* Accent (Sloth green) */
  --accent:        #7ed07a;
  --accent-dim:    #3e7a3c;
  --accent-soft:   rgba(126, 208, 122, 0.12);
  --accent-focus:  rgba(126, 208, 122, 0.35);

  /* Semantic */
  --error:         #f48771;
  --warn:          #cca700;
  --info:          #75beff;

  /* Borders */
  --border:        #2b2b2b;
  --border-soft:   #1f1f1f;
  --border-active: #7ed07a;

  /* Fonts */
  --mono:          "JetBrains Mono","Cascadia Code","SF Mono","Fira Code",Consolas,"Liberation Mono",monospace;
  --sans:          -apple-system,BlinkMacSystemFont,"Segoe WPC","Segoe UI",system-ui,sans-serif;

  /* Sizes */
  --h-title:       32px;
  --h-status:      22px;
  --h-tabs:        34px;
  --h-panel-head:  28px;
  --w-activity:    48px;
  --w-sidebar:     260px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  background: var(--bg-app);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button {
  font-family: inherit;
  color: inherit;
  background: transparent;
  border: none;
  cursor: pointer;
}
button:disabled { cursor: not-allowed; opacity: 0.45; }
kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 5px;
  background: rgba(0,0,0,0.22);
  border-radius: 3px;
  font-weight: 500;
  margin-left: 4px;
  vertical-align: 1px;
}

/* ───── Outer layout ───── */

.ide {
  display: grid;
  grid-template-rows: var(--h-title) 1fr var(--h-status);
  height: 100vh;
}

.main {
  display: grid;
  grid-template-columns: var(--w-activity) var(--w-sidebar) 1fr;
  overflow: hidden;
}
.main.sidebar-collapsed {
  grid-template-columns: var(--w-activity) 0 1fr;
}
.main.sidebar-collapsed .sidebar { display: none; }

/* ───── Title bar ───── */

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-title);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  font-size: 12px;
  color: var(--fg);
  user-select: none;
}
.tb-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tb-right { display: flex; align-items: center; gap: 6px; }
.tb-logo { font-size: 14px; }
.tb-brand { font-weight: 600; letter-spacing: -0.01em; color: var(--fg-bright); }
.tb-sep { color: var(--fg-fade); }
.tb-title { color: var(--fg-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 22px;
  color: var(--fg-dim);
  border-radius: 4px;
}
.tb-link:hover { background: rgba(255,255,255,0.08); color: var(--fg-bright); }

/* ───── Activity bar ───── */

.activity {
  background: var(--bg-activity);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0;
}
.act {
  width: var(--w-activity);
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-dim);
  position: relative;
}
.act:hover { color: var(--fg-bright); }
.act.active { color: var(--fg-bright); }
.act.active::before {
  content: "";
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--accent);
  border-radius: 1px;
}
.act-spacer { flex: 1; }

/* ───── Sidebar ───── */

.sidebar {
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.view { flex: 1; overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }
.view[hidden] { display: none !important; }

.view-head {
  padding: 8px 16px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-dim);
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.view-note {
  padding: 0 16px 6px;
  font-size: 12px;
  color: var(--fg-dim);
  margin: 0;
}

/* Tree (collapsible groups) */
.tree-group { border-bottom: 1px solid var(--border-soft); }
.tree-head {
  padding: 4px 16px 4px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-dim);
  cursor: pointer;
  user-select: none;
}
.tree-head:hover { color: var(--fg); }
.tree-head .caret {
  color: var(--fg-dim);
  transform: rotate(90deg);
  transition: transform 120ms;
  flex-shrink: 0;
}
.tree-group.collapsed .caret { transform: rotate(0deg); }
.tree-group.collapsed .tree { display: none; }
.tree-head span { flex: 1; }
.tree-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  color: var(--fg-dim);
  border-radius: 3px;
  position: relative;
  cursor: pointer;
}
.tree-action:hover { color: var(--fg); background: var(--bg-hover); }
.tree-action input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
}

.tree, .snip-list, .history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 13px;
  font-family: var(--sans);
}
.tree li, .snip-list li, .history-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 16px 3px 26px;
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
  line-height: 22px;
}
.tree li:hover, .snip-list li:hover, .history-list li:hover { background: var(--bg-hover); }
.tree li.active, .snip-list li.active { background: var(--bg-selected); color: var(--fg-bright); }

.tree li .file-icon {
  flex-shrink: 0;
  width: 16px; height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--info);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  border-radius: 2px;
}
.tree li .file-icon.csv     { color: #6fb8ff; }
.tree li .file-icon.parquet { color: #d9a34b; }
.tree li .file-icon.json    { color: #e3b341; }
.tree li .file-icon.arrow   { color: #ad6eef; }
.tree li .file-icon.xlsx    { color: #3bb371; }
.tree li .file-icon.sqlite, .tree li .file-icon.db { color: #e48e4b; }
.tree li .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.tree li .file-size { color: var(--fg-fade); font-size: 11px; flex-shrink: 0; font-family: var(--mono); }

.tree li .si {
  color: var(--fg-fade);
  font-size: 10px;
  margin-right: -2px;
  flex-shrink: 0;
}

.snip-list li { padding-left: 16px; }
.history-list li {
  padding-left: 16px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--fg);
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  line-height: 1.4;
  padding: 6px 16px;
}
.history-list li .hist-sql {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg);
}
.history-list li .hist-meta {
  font-size: 10.5px;
  color: var(--fg-fade);
  font-family: var(--mono);
}

.icon-btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px; height: 18px;
  color: var(--fg-dim);
  border-radius: 3px;
}
.icon-btn-sm:hover { background: var(--bg-hover); color: var(--fg); }

.info {
  padding: 0 16px 16px;
  font-size: 12px;
  color: var(--fg-dim);
  line-height: 1.6;
}
.info p { margin: 0 0 10px; }
.info strong { color: var(--fg); }
.info .kbd-row { display: flex; align-items: center; gap: 6px; margin: 4px 0; }

/* ───── Workspace ───── */

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-app);
}

.tabstrip {
  display: flex;
  align-items: stretch;
  height: var(--h-tabs);
  background: var(--bg-tab-ina);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.etab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 100%;
  background: var(--bg-tab-ina);
  color: var(--fg-dim);
  font-size: 12px;
  border-right: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  position: relative;
}
.etab:hover { color: var(--fg); }
.etab.active {
  background: var(--bg-tab-act);
  color: var(--fg-bright);
}
.etab.active::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 1px;
  background: var(--accent);
}
.etab .tab-icon { color: var(--info); flex-shrink: 0; }

.tabstrip-spacer { flex: 1; border-bottom: 1px solid var(--border); background: var(--bg-tab-ina); }
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--bg-tab-ina);
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
}

.btn-primary, .btn-ghost {
  height: 24px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 80ms, color 80ms;
}
.btn-ghost {
  color: var(--fg-dim);
  background: transparent;
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--fg);
  background: var(--bg-hover);
  border-color: #3e4350;
}
.btn-primary {
  color: #102710;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-primary:disabled { color: #555; background: #3a3d3a; border-color: #3a3d3a; }

/* ───── Split (editor + panel) ───── */

.split {
  flex: 1;
  display: grid;
  grid-template-rows: minmax(0, 1.2fr) 4px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.pane {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-editor);
}
.editor-pane { position: relative; }
#editor { height: 100%; overflow: auto; background: var(--bg-editor); }

.gutter {
  background: var(--border-soft);
  cursor: row-resize;
  position: relative;
  transition: background 120ms;
}
.gutter:hover, .gutter.active { background: var(--accent-dim); }

/* ───── Panel ───── */

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--h-panel-head);
  background: var(--bg-side);
  border-bottom: 1px solid var(--border);
  padding: 0 12px 0 0;
  flex-shrink: 0;
}
.panel-tabs { display: flex; height: 100%; }
.ptab {
  padding: 0 14px;
  height: 100%;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-dim);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.ptab:hover { color: var(--fg); }
.ptab.active {
  color: var(--fg-bright);
  border-bottom-color: var(--accent);
}
.panel-meta {
  flex: 1;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-dim);
  display: flex;
  gap: 12px;
  padding: 0 12px;
  overflow: hidden;
}
.panel-meta .ok { color: var(--accent); }
.panel-meta .err { color: var(--error); }
.panel-actions { display: flex; gap: 6px; }

.panel-body {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-panel);
}
.tab-panel {
  position: absolute;
  inset: 0;
  display: none;
  overflow: auto;
}
.tab-panel.active { display: block; }

#result-table { overflow: auto; height: 100%; }
.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--fg-fade);
  font-size: 12px;
  font-family: var(--mono);
}
#result-table:not(:empty) + .empty { display: none; }

/* ───── Result grid ───── */

table.grid {
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--mono);
  font-size: 12px;
  width: max-content;
  min-width: 100%;
  line-height: 1.4;
}
table.grid thead th {
  position: sticky;
  top: 0;
  background: var(--bg-grid-head);
  text-align: left;
  padding: 6px 14px 6px 12px;
  font-weight: 600;
  color: var(--fg);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  z-index: 1;
  font-size: 11px;
}
table.grid thead th:hover { background: var(--bg-hover); color: var(--accent); }
table.grid thead th .sort-arrow { margin-left: 6px; color: var(--accent); font-size: 9px; }
table.grid td {
  padding: 3px 12px;
  border-bottom: 1px solid var(--border-soft);
  border-right: 1px solid var(--border-soft);
  white-space: nowrap;
  color: var(--fg);
  background: var(--bg-grid-row);
}
table.grid td:last-child, table.grid th:last-child { border-right: none; }
table.grid tbody tr:nth-child(even) td { background: var(--bg-grid-alt); }
table.grid tbody tr:hover td { background: var(--accent-soft) !important; }
table.grid td.null { color: var(--fg-fade); font-style: italic; }
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }

.row-idx {
  color: var(--fg-fade);
  font-size: 10.5px;
  padding-right: 8px !important;
  padding-left: 10px !important;
  text-align: right;
  border-right: 1px solid var(--border) !important;
  user-select: none;
  background: var(--bg-grid-head) !important;
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 38px;
  font-variant-numeric: tabular-nums;
}
thead .row-idx { z-index: 3; }

#messages {
  padding: 10px 16px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--fg);
  line-height: 1.7;
}
#messages .log-line { padding: 1px 0; }
#messages .log-line .ts { color: var(--fg-fade); margin-right: 6px; }
#messages .log-line.err { color: var(--error); }
#messages .log-line.ok { color: var(--accent); }
#messages .log-line.warn { color: var(--warn); }

/* ───── CodeMirror overrides ───── */

.cm-editor {
  height: 100%;
  font-family: var(--mono);
  font-size: 13px;
  background: var(--bg-editor);
}
.cm-editor.cm-focused { outline: none !important; }
.cm-scroller { font-family: var(--mono); padding: 8px 0; line-height: 1.55; }
.cm-gutters {
  background: var(--bg-editor) !important;
  border-right: 1px solid var(--border-soft);
  color: var(--fg-fade);
  padding-right: 4px;
}
.cm-activeLineGutter { background: transparent !important; color: var(--fg) !important; }
.cm-lineNumbers .cm-gutterElement { padding: 0 12px 0 14px; min-width: 30px; }
.cm-activeLine { background: rgba(255, 255, 255, 0.028) !important; }
.cm-line { padding: 0 16px; }
.cm-selectionBackground { background: rgba(38, 79, 120, 0.55) !important; }
.cm-cursor, .cm-dropCursor { border-left-color: var(--accent) !important; border-left-width: 2px !important; }
.cm-matchingBracket {
  background: var(--accent-soft) !important;
  outline: 1px solid var(--accent-dim);
  border-radius: 2px;
}

/* Hide CM panels overlay glow */
.cm-panels { background: var(--bg-panel) !important; border-color: var(--border) !important; }
.cm-search { padding: 6px 10px !important; }
.cm-search .cm-textfield {
  background: var(--bg-side) !important;
  border: 1px solid var(--border) !important;
  color: var(--fg) !important;
  font-family: var(--mono);
  padding: 3px 6px;
  font-size: 12px;
}
.cm-search .cm-button {
  background: var(--bg-side) !important;
  border: 1px solid var(--border) !important;
  color: var(--fg) !important;
  font-size: 11px;
  padding: 3px 8px;
}

/* ───── Status bar ───── */

.statusbar {
  background: var(--bg-statusbar);
  color: #102710;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  user-select: none;
}
.statusbar.boot { background: #444444; color: #cccccc; }
.statusbar.boot .sb-dot { background: var(--warn); }
.statusbar.err { background: #d8554a; color: #fff; }
.sb-left, .sb-right { display: flex; align-items: center; gap: 2px; }
.sb-item {
  padding: 0 8px;
  height: var(--h-status);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.sb-item + .sb-item { border-left: 1px solid rgba(16, 39, 16, 0.15); }
.statusbar.boot .sb-item + .sb-item { border-left-color: rgba(255,255,255,0.06); }
.sb-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #102710;
  flex-shrink: 0;
}
.sb-conn { font-weight: 600; }

/* ───── Scrollbars (webkit) ───── */

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(130, 130, 130, 0.35);
  border-radius: 6px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(130, 130, 130, 0.6);
  background-clip: padding-box;
}
::-webkit-scrollbar-corner { background: transparent; }

/* ───── Responsive ───── */

@media (max-width: 820px) {
  .main { grid-template-columns: var(--w-activity) 200px 1fr; }
  :root { --w-sidebar: 200px; }
}
@media (max-width: 640px) {
  .main { grid-template-columns: var(--w-activity) 0 1fr; }
  .sidebar { display: none; }
  .tb-title { display: none; }
}
