:root {
  --bg: #0b0d10;
  --panel: #111418;
  --panel-2: #171b21;
  --line: #262b33;
  --line-2: #343a44;
  --text: #e4e4e7;
  --text-2: #a1a1aa;
  --text-3: #71717a;
  --accent: #38bdf8;
  --ok: #34d399;
  --warn: #f59e0b;
  --bad: #f87171;
  --sidebar-w: 300px;
  --term-h: 280px;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 4px 1fr;
  /* minmax(0, …) so a long sidebar list scrolls instead of stretching the row. */
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
}
#app.no-sidebar { grid-template-columns: 0 0 1fr; }
#app.no-sidebar #sidebar { visibility: hidden; }

/* ---- sidebar ---------------------------------------------------------- */
#sidebar { display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); min-width: 0; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px; }
.brand { font-weight: 600; letter-spacing: .2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.search-wrap { padding: 4px 10px 8px; }
#search, #address, select {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; outline: none;
}
#search:focus, #address:focus, select:focus { border-color: var(--accent); }
.side-tabs { display: flex; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--line); }
.side-tabs button { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; padding: 7px 4px; color: var(--text-2); cursor: pointer; }
.side-tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.panel { flex: 1; overflow: auto; padding: 6px 0 12px; }
.panel-tools { padding: 4px 10px 8px; }
.panel-note { color: var(--text-3); padding: 10px 14px; line-height: 1.5; }
.panel-note.bad { color: var(--bad); }
.group-title { color: var(--text-3); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; padding: 10px 14px 4px; }

.row {
  display: flex; align-items: center; gap: 6px; height: 26px; padding-right: 6px; cursor: pointer; white-space: nowrap;
  border-left: 2px solid transparent;
}
.row:hover { background: var(--panel-2); }
.row.call .icon { color: var(--ok); }
.row.call.failed .icon, .row.call.failed .sub { color: var(--bad); }
.row.call .name { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.row:focus-visible { outline: none; border-left-color: var(--accent); background: var(--panel-2); }
.row .caret { width: 12px; color: var(--text-3); flex: none; text-align: center; font-size: 10px; }
.row .icon { width: 16px; flex: none; text-align: center; }
.row .name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.row .sub { color: var(--text-3); overflow: hidden; text-overflow: ellipsis; font-size: 11px; max-width: 45%; }
.row .acts { display: none; gap: 2px; flex: none; }
.row:hover .acts, .row:focus-within .acts { display: flex; }
.row .acts button { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; height: 20px; cursor: pointer; color: var(--text-2); font-size: 11px; }
.row .acts button:hover { color: var(--text); border-color: var(--line-2); }
.cron-tools { display: flex; gap: 6px; }
.cron-tools button { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 5px; padding: 3px 10px; cursor: pointer; }
.row.task.failed .icon, .row.task.failed .sub { color: var(--bad); }
#panel-chat:not([hidden]) { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
#chat-log { flex: 1; overflow: auto; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.chat-msg { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.chat-msg.user { align-self: flex-end; max-width: 90%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; }
.chat-msg.note { color: var(--text-3); }
.chat-msg.error { color: var(--bad); }
.chat-msg.tool { font-family: "Cascadia Mono", Consolas, monospace; font-size: 11px; color: var(--text-2); max-height: 4.5em; overflow: hidden; }
.chat-msg.tool.ok { color: var(--ok); }
.chat-msg.tool.failed { color: var(--bad); }
#chat-form { border-top: 1px solid var(--line); padding: 8px; display: flex; flex-direction: column; gap: 6px; }
#chat-input { resize: vertical; min-height: 44px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; outline: none; }
#chat-input:focus { border-color: var(--accent); }
.chat-actions { display: flex; align-items: center; gap: 6px; }
#chat-model { flex: 1; color: var(--text-3); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-actions button { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 5px; padding: 3px 12px; cursor: pointer; }
.chat-actions button:disabled { opacity: .5; cursor: default; }
#chat-send { border-color: var(--accent); }
.chat-actions .chat-attach { padding: 3px 7px; color: var(--text-2); }
.chat-actions .chat-attach[aria-pressed="true"] { border-color: var(--accent); color: var(--text); background: var(--bg); }

/* ---- splitters -------------------------------------------------------- */
.splitter { background: var(--line); }
.splitter.vertical { cursor: col-resize; }
.splitter.horizontal { cursor: row-resize; height: 4px; }
.splitter:hover, .splitter:focus-visible { background: var(--accent); outline: none; }

/* ---- main column ------------------------------------------------------ */
#main { display: grid; grid-template-rows: 36px 40px 1fr 4px var(--term-h); min-width: 0; min-height: 0; }
#main.no-terminal { grid-template-rows: 36px 40px 1fr 0 0; }
#main.no-terminal #terminal-panel, #main.no-terminal #term-split { visibility: hidden; }

#tabstrip { display: flex; align-items: end; gap: 4px; padding: 0 6px; background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; }
#tab-list { display: flex; gap: 2px; overflow-x: auto; min-width: 0; scrollbar-width: none; }
.tab {
  display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 8px 0 10px; max-width: 220px; min-width: 110px;
  background: var(--panel-2); border: 1px solid var(--line); border-bottom: 0; border-radius: 7px 7px 0 0; color: var(--text-2); cursor: pointer;
}
.tab.active { background: var(--bg); color: var(--text); border-color: var(--line-2); }
.tab img { width: 14px; height: 14px; flex: none; }
.tab .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tab .close { background: none; border: 0; color: var(--text-3); cursor: pointer; padding: 0 2px; border-radius: 3px; }
.tab .close:hover { color: var(--text); background: var(--line); }
.tab.pinned { min-width: 0; max-width: 140px; border-top: 2px solid var(--accent); }
.tab.pinned .close { display: none; }
.tab.loading .title::before { content: "◌ "; color: var(--accent); }

#navbar { display: flex; align-items: center; gap: 4px; padding: 5px 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
#address-form { flex: 1; }
#find-form { display: flex; align-items: center; gap: 2px; padding-left: 6px; border-left: 1px solid var(--line); }
#find-form[hidden] { display: none; }
#find-input { width: 180px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; outline: none; }
#find-input:focus { border-color: var(--accent); }
#find-count { color: var(--text-3); font-size: 11px; min-width: 44px; text-align: center; }
#actions-host { display: flex; align-items: center; min-height: 26px; }
.icon-btn { background: none; border: 0; border-radius: 5px; width: 28px; height: 28px; cursor: pointer; color: var(--text-2); flex: none; }
.icon-btn:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }

#content { position: relative; min-height: 0; background: var(--bg); }
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--text-2); }
.empty h1 { font-size: 22px; font-weight: 600; color: var(--text); margin: 0; }
#quick-links { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 640px; margin-top: 14px; }
#quick-links button { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
#quick-links button:hover { border-color: var(--line-2); background: var(--panel-2); }

/* ---- terminal --------------------------------------------------------- */
#terminal-panel { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.term-head { display: flex; align-items: center; gap: 4px; padding: 3px 6px; background: var(--panel); border-bottom: 1px solid var(--line); }
#term-tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.term-tab { display: flex; align-items: center; gap: 6px; background: none; border: 1px solid transparent; border-radius: 5px; padding: 2px 6px 2px 9px; color: var(--text-2); cursor: pointer; max-width: 260px; }
.term-tab.active { border-color: var(--line-2); color: var(--text); background: var(--panel-2); }
.term-tab .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-tab.exited .title { color: var(--text-3); text-decoration: line-through; }
.term-tab .close { background: none; border: 0; color: var(--text-3); cursor: pointer; }
#term-host { position: relative; flex: 1; min-height: 0; }
.term-pane { position: absolute; inset: 4px 0 0 8px; }
#confirm-bar { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--panel-2); border-bottom: 1px solid var(--warn); }
#confirm-bar[hidden] { display: none; }
#confirm-label { color: var(--text-2); white-space: nowrap; }
#confirm-cmd { flex: 1; min-width: 0; overflow-wrap: anywhere; font-family: "Cascadia Mono", Consolas, monospace; color: var(--text); }
#confirm-bar button { background: var(--panel); border: 1px solid var(--line-2); border-radius: 5px; padding: 3px 12px; cursor: pointer; }
#confirm-run { border-color: var(--warn) !important; color: var(--warn); }
#confirm-bar button:focus-visible { outline: 2px solid var(--accent); }
