@font-face {
  font-family: "JetBrains Mono";
  font-weight: 400;
  font-display: swap;
  src: url("/vendor/fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-weight: 700;
  font-display: swap;
  src: url("/vendor/fonts/jetbrains-mono-latin-700-normal.woff2") format("woff2");
}

:root {
  --bg: #0d0d0d;
  --panel: #111111;
  --panel-2: #161616;
  --border: #292929;
  --text: #d4d4d4;
  --muted: #737373;
  --dim: #4a4a4a;
  --green: #7ee787;
  --yellow: #d29922;
  --red: #f85149;
  --blue: #58a6ff;
  --font: "JetBrains Mono", "IBM Plex Mono", "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs: 13px;
  --sidebar: 210px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: var(--fs)/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--text); text-decoration: none; }
a:hover { color: #fff; text-decoration: underline; text-decoration-color: var(--dim); }
h1, h2, h3 { font-size: var(--fs); font-weight: 700; margin: 0; }
h1 { font-size: 15px; }
pre, code, input, select, textarea, button { font: inherit; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.green { color: var(--green); }
.yellow { color: var(--yellow); }
.red { color: var(--red); }
.blue { color: var(--blue); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- shell */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  grid-template-rows: 30px 1fr;
  height: 100vh;
}
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand { font-weight: 700; letter-spacing: 0.15em; }
.topbar .host { color: var(--muted); }
.topbar .spacer { flex: 1; }
.topbar kbd, kbd {
  border: 1px solid var(--border);
  padding: 0 4px;
  color: var(--muted);
  font-size: 11px;
}
.sidebar {
  border-right: 1px solid var(--border);
  padding: 10px 0;
  overflow-y: auto;
  background: var(--panel);
}
.sidebar .section { color: var(--muted); padding: 10px 12px 2px; font-size: 11px; letter-spacing: 0.1em; }
.sidebar a {
  display: flex;
  gap: 6px;
  padding: 1px 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar a:hover { background: var(--panel-2); text-decoration: none; }
.sidebar a.active { color: #fff; background: #1b1b1b; }
.sidebar a .caret { width: 1ch; color: var(--green); }
.sidebar a .dot { margin-left: auto; font-size: 10px; }
.main { overflow: auto; position: relative; display: flex; flex-direction: column; min-width: 0; }
.content { padding: 14px 18px 40px; }
.content.full { padding: 0; flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ---------------------------------------------------------------- project header & tabs */
.phead { padding: 12px 18px 0; border-bottom: 1px solid var(--border); background: var(--bg); }
.phead .title { display: flex; gap: 16px; align-items: baseline; flex-wrap: wrap; }
.phead .meta { color: var(--muted); }
.tabs { display: flex; gap: 2px; margin-top: 10px; flex-wrap: wrap; }
.tabs a {
  padding: 3px 8px;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: none;
  margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-color: var(--border); background: var(--bg); border-bottom: 1px solid var(--bg); }
.subtabs { display: flex; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.subtabs a { color: var(--muted); }
.subtabs a.active { color: var(--text); }
.subtabs a.active::before { content: "> "; color: var(--green); }

/* ---------------------------------------------------------------- status */
.st { font-weight: 700; white-space: nowrap; }
.st-running { color: var(--green); }
.st-stopped { color: var(--muted); }
.st-crashed { color: var(--red); }
.st-starting, .st-stopping { color: var(--yellow); }

/* ---------------------------------------------------------------- buttons & forms */
.btn {
  display: inline-block;
  background: none;
  border: none;
  color: var(--text);
  padding: 1px 2px;
  cursor: pointer;
  white-space: nowrap;
}
.btn::before { content: "[ "; color: var(--dim); }
.btn::after { content: " ]"; color: var(--dim); }
.btn:hover { color: #fff; text-decoration: none; }
.btn:hover::before, .btn:hover::after { color: var(--muted); }
.btn:focus-visible { outline: 1px solid var(--blue); }
.btn.primary { color: var(--blue); }
.btn.danger { color: var(--red); }
.btn.ok { color: var(--green); }
.btn[disabled], .btn.htmx-request { opacity: 0.45; cursor: progress; }
.link { background: none; border: none; color: var(--muted); padding: 0; cursor: pointer; }
.link:hover { color: var(--text); text-decoration: underline; }
.link.danger:hover { color: var(--red); }

input[type="text"], input[type="password"], input[type="number"], input:not([type]), select, textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 3px 6px;
  border-radius: 0;
  outline: none;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); }
textarea { width: 100%; resize: vertical; }
input[type="checkbox"] { accent-color: var(--blue); }
.form { display: grid; grid-template-columns: max-content minmax(0, 520px); gap: 6px 14px; align-items: center; }
.form label { color: var(--muted); }
.form .full { grid-column: 1 / -1; }
.form .hint { grid-column: 2; color: var(--dim); font-size: 12px; margin-top: -4px; }
.form input[type="text"], .form input:not([type]), .form select, .form input[type="number"], .form input[type="password"] { width: 100%; }
fieldset { border: 1px solid var(--border); padding: 10px 12px 12px; margin: 0 0 14px; max-width: 760px; }
legend { color: var(--muted); padding: 0 6px; }

/* ---------------------------------------------------------------- tables & lists */
.tbl { border-collapse: collapse; width: 100%; }
.tbl th {
  text-align: left;
  font-weight: 400;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding: 2px 12px 2px 0;
  white-space: nowrap;
}
.tbl td { padding: 2px 12px 2px 0; vertical-align: top; border-bottom: 1px solid #181818; }
.tbl tr:hover td { background: #121212; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl.data td { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl.data td.null { color: var(--dim); font-style: italic; }
.tbl .actions { text-align: right; white-space: nowrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 1px 24px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.scroll-x { overflow-x: auto; }

/* ---------------------------------------------------------------- boxes */
.box { border: 1px solid var(--border); background: var(--panel); padding: 8px 10px; }
.box-title { color: var(--muted); margin-bottom: 6px; display: flex; gap: 10px; align-items: center; }
.split { display: grid; grid-template-columns: 220px 1fr; gap: 18px; }
.flash { position: sticky; top: 0; z-index: 20; }
.flash:empty { display: none; }
.alert { border: 1px solid var(--border); border-left: 3px solid var(--red); background: #160d0d; padding: 8px 12px; margin: 10px 18px; position: relative; }
.alert.ok { border-left-color: var(--green); background: #0d140e; }
.alert.warn { border-left-color: var(--yellow); background: #15120b; }
.alert .msg { font-weight: 700; }
.alert pre { margin-top: 6px; color: var(--text); max-height: 300px; overflow: auto; }
.alert .close { position: absolute; right: 8px; top: 6px; }
.empty { color: var(--muted); padding: 12px 0; }

/* ---------------------------------------------------------------- logs */
.logview {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px;
  background: var(--bg);
  min-height: 160px;
  font-size: 12.5px;
  line-height: 1.45;
}
.logview .ln { display: flex; gap: 10px; white-space: pre-wrap; word-break: break-word; }
.logview .ts { color: var(--dim); flex: none; }
.logview .ln.e .tx { color: #ffb4ae; }
.logview .ln.s .tx { color: var(--blue); }
.logview.compact { max-height: 320px; border: 1px solid var(--border); }
.toolbar { display: flex; gap: 10px; align-items: center; padding: 4px 12px; border-bottom: 1px solid var(--border); background: var(--panel); flex-wrap: wrap; }
.toolbar .sep { color: var(--dim); }

/* ---------------------------------------------------------------- files / editor */
.ide { display: grid; grid-template-columns: 240px 1fr; flex: 1; min-height: 0; }
.tree { border-right: 1px solid var(--border); overflow: auto; background: var(--panel); padding: 4px 0; font-size: 12.5px; }
.tree .node { display: flex; align-items: center; gap: 4px; padding: 0 8px; cursor: pointer; white-space: nowrap; user-select: none; }
.tree .node:hover { background: #1a1a1a; }
.tree .node.sel { background: #1f2630; }
.tree .node .ic { width: 1.5ch; color: var(--muted); flex: none; }
.tree .node.dir .nm { color: #c9d1d9; }
.tree .node.link .nm { color: var(--blue); }
.editor-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.editor-tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--border); background: var(--panel); min-height: 26px; }
.editor-tabs .tab { padding: 3px 10px; border-right: 1px solid var(--border); color: var(--muted); cursor: pointer; white-space: nowrap; display: flex; gap: 8px; align-items: center; }
.editor-tabs .tab.active { color: var(--text); background: var(--bg); }
.editor-tabs .tab .x { color: var(--dim); }
.editor-tabs .tab .x:hover { color: var(--red); }
.editor-tabs .tab.dirty .nm::after { content: " ●"; color: var(--yellow); }
#editor { flex: 1; min-height: 0; }
.editor-status { border-top: 1px solid var(--border); padding: 1px 10px; color: var(--muted); display: flex; gap: 16px; background: var(--panel); font-size: 12px; }
.placeholder { padding: 30px; color: var(--muted); }

/* ---------------------------------------------------------------- terminal */
.term-wrap { flex: 1; min-height: 0; background: #0a0a0a; padding: 4px 0 0 8px; }
#terminal { height: 100%; }
.xterm .xterm-viewport { background-color: #0a0a0a !important; }

/* ---------------------------------------------------------------- palette */
.palette-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 100; display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; }
.palette { width: min(620px, 92vw); background: var(--panel); border: 1px solid var(--border); box-shadow: 0 10px 40px #000; }
.palette input { width: 100%; border: none; border-bottom: 1px solid var(--border); padding: 8px 12px; background: var(--panel); }
.palette ul { list-style: none; margin: 0; padding: 4px 0; max-height: 50vh; overflow: auto; }
.palette li { padding: 2px 12px; cursor: pointer; display: flex; gap: 12px; }
.palette li .k { color: var(--muted); margin-left: auto; }
.palette li.sel { background: #1f2630; }
.palette .hint { padding: 4px 12px; color: var(--dim); border-top: 1px solid var(--border); font-size: 11px; }

/* ---------------------------------------------------------------- login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login form { width: 320px; border: 1px solid var(--border); background: var(--panel); padding: 18px; }
.login input { width: 100%; margin: 6px 0 12px; }

/* ---------------------------------------------------------------- sql */
.sql-editor { width: 100%; min-height: 110px; font-size: 13px; }
.result-meta { color: var(--muted); margin: 8px 0 4px; display: flex; gap: 16px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  :root { --sidebar: 160px; }
  .split { grid-template-columns: 1fr; }
  .ide { grid-template-columns: 180px 1fr; }
}
@media (max-width: 640px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 30px auto 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 30vh; }
  .ide { grid-template-columns: 1fr; grid-template-rows: 30vh 1fr; }
  .form { grid-template-columns: 1fr; }
  .form .hint { grid-column: 1; }
}
