:root {
  --bg: #0c0e13;
  --bg2: #14171f;
  --bg3: #1c2230;
  --bg4: #262d3e;
  --fg: #e6e9ef;
  --fg2: #9aa3b2;
  --fg3: #6b7385;
  --accent: #7c9cff;
  --accent2: #5a7ce0;
  --border: #242938;
  --border2: #2f3548;
  --ok: #5fd479;
  --err: #ff7080;
  --tool: #d8a55c;
  --user-bubble: #2a3142;
  --asst-bg: transparent;
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 -apple-system, system-ui, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--fg2); }

/* ----- icons ----- */
.icon { width: 16px; height: 16px; flex-shrink: 0; vertical-align: middle; }
.icon-lg { width: 20px; height: 20px; flex-shrink: 0; vertical-align: middle; color: var(--accent); }
.icon-sm { width: 13px; height: 13px; flex-shrink: 0; }

button {
  font: inherit;
  color: var(--fg);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 6px 10px;
}
button:hover { background: var(--bg3); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 6px;
  border-radius: var(--radius-sm);
  color: var(--fg2);
  transition: background .1s, color .1s;
}
.icon-btn:hover { background: var(--bg3); color: var(--fg); }
.icon-btn.primary { background: var(--accent); color: #fff; padding: 8px 10px; }
.icon-btn.primary:hover { background: var(--accent2); color: #fff; }
.icon-btn.primary:disabled { background: var(--bg3); color: var(--fg3); cursor: not-allowed; }
.icon-btn.danger { background: var(--err); color: #fff; padding: 8px 10px; }
.icon-btn.danger:hover { filter: brightness(1.1); }

select {
  background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 5px 10px; font: inherit; cursor: pointer; min-width: 140px;
}
select:hover { border-color: var(--border2); }

/* ----- login ----- */
#login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(ellipse at top, #1a2030 0%, var(--bg) 60%);
}
#login-form {
  background: var(--bg2); padding: 36px; border-radius: var(--radius);
  border: 1px solid var(--border); min-width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
#login-form h1 { margin: 0 0 20px; font-size: 20px; display: flex; align-items: center; gap: 8px; }
#login-form input {
  width: 100%; padding: 10px 12px; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 12px;
  font: inherit;
}
#login-form input:focus { outline: none; border-color: var(--accent); }
#login-form button {
  width: 100%; padding: 10px; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius-sm); cursor: pointer; font-weight: 500;
}
#login-form button:hover { background: var(--accent2); }
#login-error { color: var(--err); margin: 8px 0 0; min-height: 1em; font-size: 13px; }

/* ----- app layout ----- */
#app { display: flex; flex-direction: column; height: 100vh; }
header {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 48px;
}
header .brand { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; letter-spacing: .2px; }
header .spacer { flex: 1; }
#workspace-bar { display: flex; align-items: center; gap: 4px; }
#session-indicator { font-size: 12px; margin-left: 8px; font-family: ui-monospace, monospace; }
#context-pill {
  font-size: 11px; font-family: ui-monospace, monospace;
  padding: 3px 8px; border-radius: 4px;
  background: var(--bg3); color: var(--fg2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
#context-pill.warn  { background: rgba(216,165,92,0.18); color: var(--tool); border-color: rgba(216,165,92,0.4); }
#context-pill.alert { background: rgba(255,112,128,0.18); color: var(--err);  border-color: rgba(255,112,128,0.4); }
.context-bar {
  display: inline-block; width: 38px; height: 4px;
  background: var(--bg4); border-radius: 2px; margin-right: 6px; vertical-align: middle;
  overflow: hidden; position: relative;
}
.context-bar > i {
  display: block; height: 100%; background: var(--accent);
}
#context-pill.warn  .context-bar > i { background: var(--tool); }
#context-pill.alert .context-bar > i { background: var(--err); }

/* compact-boundary divider in chat */
.compact-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 24px; padding: 8px 14px;
  color: var(--fg3); font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px;
}
.compact-divider::before, .compact-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

main {
  display: grid;
  grid-template-columns: var(--sidebar-w, 220px) 4px var(--chat-w, 1fr) 4px 1fr;
  flex: 1; overflow: hidden;
}
body.sidebar-collapsed main { grid-template-columns: var(--chat-w, 1fr) 4px 1fr; }
body.sidebar-collapsed #sidebar, body.sidebar-collapsed #splitter-l { display: none; }

#splitter-l, #splitter-r {
  background: var(--border);
  cursor: col-resize;
  transition: background .15s;
  position: relative;
}
#splitter-l:hover, #splitter-l.dragging,
#splitter-r:hover, #splitter-r.dragging { background: var(--accent); }
#splitter-l::after, #splitter-r::after {
  content: ''; position: absolute; inset: 0 -4px;
}
/* While a splitter is being dragged: make iframes transparent to pointer
   events so the drag doesn't lose tracking once the cursor crosses into the
   preview pane, force the resize cursor everywhere, and suppress text
   selection that would otherwise highlight as the cursor sweeps. */
body.dragging-splitter { cursor: col-resize; user-select: none; }
body.dragging-splitter iframe { pointer-events: none; }

/* ---------- sidebar ---------- */
#sidebar {
  background: var(--bg2);
  display: flex; flex-direction: column;
  overflow: hidden;
  min-width: 160px;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 6px;
}
.sidebar-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--fg3); font-weight: 600;
}
.sidebar-header .icon-btn { padding: 4px; }
#workspace-list {
  flex: 1; overflow-y: auto;
  padding: 4px 6px 12px;
  display: flex; flex-direction: column; gap: 1px;
}
#workspace-list::-webkit-scrollbar { width: 8px; }
#workspace-list::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 4px; }

.ws-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--fg);
  transition: background .1s;
  position: relative;
  min-width: 0;
}
.ws-item:hover { background: var(--bg3); }
.ws-item.active { background: var(--accent); color: #fff; }
.ws-item.active .ws-meta { color: rgba(255,255,255,0.75); }
.ws-item.active .dot { background: rgba(255,255,255,0.7); }
.ws-item.active.has-preview .dot { background: #b8f5c4; box-shadow: 0 0 6px #b8f5c4; }
.ws-item .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--bg4);
  flex-shrink: 0;
}
.ws-item.has-preview .dot { background: var(--ok); box-shadow: 0 0 4px rgba(95, 212, 121, 0.6); }
.ws-item .name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px;
}
.ws-item .ws-meta {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--fg3);
  flex-shrink: 0;
}
.ws-item .shared-tag {
  display: inline-block; padding: 1px 5px; border-radius: 3px;
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.5px;
  background: rgba(124,156,255,0.18); color: var(--accent);
  margin-left: 4px;
}
.ws-item.active .shared-tag { background: rgba(255,255,255,0.20); color: #fff; }
.user-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 4px; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.user-row:last-child { border-bottom: none; }
.user-row .name { flex: 1; }
.user-row .role {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 2px 6px; border-radius: 3px;
  background: var(--bg3); color: var(--fg2);
}
.user-row .role.admin { background: rgba(216,165,92,0.18); color: var(--tool); }
.share-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  background: var(--bg3); border-radius: 6px; margin-bottom: 4px;
  font-size: 13px;
}
.share-row .name { flex: 1; }
.ws-item.active .ws-meta { color: rgba(255,255,255,0.7); }
.ws-item:hover .ws-meta { display: none; }
.ws-item.active .ws-meta { display: inline; }
.ws-item.active:hover .ws-meta { display: none; }
.ws-item .ws-actions {
  display: none; align-items: center; gap: 1px;
}
.ws-item:hover .ws-actions { display: inline-flex; }
.ws-item.active .ws-actions { display: inline-flex; }
.ws-actions .icon-btn { padding: 3px; color: inherit; opacity: 0.75; }
.ws-actions .icon-btn:hover { opacity: 1; background: rgba(255,255,255,0.1); }
.ws-item .name-input {
  flex: 1; background: var(--bg); color: var(--fg);
  border: 1px solid var(--accent); border-radius: 3px;
  padding: 2px 6px; font: inherit; font-size: 13px;
  outline: none; min-width: 0;
}

#new-workspace-form {
  padding: 4px 12px 10px;
  border-bottom: 1px solid var(--border);
}
#new-workspace-form input {
  width: 100%; padding: 6px 8px; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 13px; outline: none;
}
#new-workspace-form input:focus { border-color: var(--accent); }
.form-row { display: flex; gap: 6px; margin-top: 6px; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.btn-sm:hover { background: var(--bg3); }
.form-error { color: var(--err); font-size: 12px; min-height: 1em; margin-top: 4px; }

#active-workspace-label {
  font-size: 12px;
  font-family: ui-monospace, monospace;
  padding: 2px 8px;
  background: var(--bg3);
  border-radius: 4px;
}
#active-workspace-label:empty { display: none; }

section { display: flex; flex-direction: column; overflow: hidden; min-width: 280px; }

/* ----- chat ----- */
#chat-pane { background: var(--bg); }
#messages {
  flex: 1; overflow-y: auto;
  padding: 20px 0;
  display: flex; flex-direction: column;
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 10px; }
#messages::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 5px; }
#messages::-webkit-scrollbar-thumb:hover { background: var(--bg4); }

.msg-row {
  display: flex; gap: 12px; padding: 8px 20px;
  max-width: 100%; align-items: flex-start;
}
.msg-row .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg3); display: grid; place-items: center;
  flex-shrink: 0; margin-top: 2px;
  color: var(--fg2);
}
.msg-row.user .avatar { background: var(--accent); color: #fff; }
.msg-row.assistant .avatar { background: linear-gradient(135deg, #d97c3c 0%, #ce6c33 100%); color: #fff; }

.msg-row .body { min-width: 0; flex: 1; }
.msg-row .role {
  font-size: 12px; font-weight: 600; color: var(--fg2);
  margin-bottom: 2px;
}
.msg-row.user .role { color: var(--accent); }
.msg-row.assistant .role { color: #e89968; }

.msg-row .content {
  color: var(--fg);
  word-wrap: break-word;
}
.msg-row .content > *:first-child { margin-top: 0; }
.msg-row .content > *:last-child { margin-bottom: 0; }
.msg-row .content p { margin: 0.4em 0; }
.msg-row .content h1, .msg-row .content h2, .msg-row .content h3 { margin: 0.8em 0 0.3em; }
.msg-row .content h1 { font-size: 1.3em; }
.msg-row .content h2 { font-size: 1.15em; }
.msg-row .content h3 { font-size: 1.05em; }
.msg-row .content ul, .msg-row .content ol { padding-left: 1.5em; margin: 0.4em 0; }
.msg-row .content li { margin: 0.15em 0; }
.msg-row .content a { color: var(--accent); text-decoration: none; }
.msg-row .content a:hover { text-decoration: underline; }
.msg-row .content code {
  background: var(--bg3); padding: 1px 5px; border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em;
}
.msg-row .content pre {
  background: var(--bg3); border: 1px solid var(--border);
  padding: 10px 12px; margin: 0.6em 0;
  border-radius: var(--radius-sm); overflow-x: auto;
}
.msg-row .content pre code {
  background: transparent; padding: 0; font-size: 0.85em; line-height: 1.5;
}
.msg-row .content blockquote {
  border-left: 3px solid var(--border2);
  margin: 0.6em 0; padding: 0 0 0 14px; color: var(--fg2);
}
.msg-row .content table {
  border-collapse: collapse; margin: 0.5em 0;
}
.msg-row .content th, .msg-row .content td {
  border: 1px solid var(--border); padding: 4px 8px;
}

/* user messages: rounded bubble, right-leaning */
.msg-row.user { justify-content: flex-end; }
.msg-row.user .body { max-width: 80%; flex: 0 1 auto; }
.msg-row.user .role { display: none; }
.msg-row.user .content {
  background: var(--user-bubble); padding: 10px 14px;
  border-radius: 14px 14px 4px 14px; white-space: pre-wrap;
}

/* tool calls — compact chip */
.tool-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 12px 4px 8px;
  font-family: ui-monospace, monospace; font-size: 12px;
  color: var(--tool); cursor: pointer; margin: 4px 0;
  transition: background .1s;
  max-width: 100%;
}
.tool-chip:hover { background: var(--bg3); }
.tool-chip .chevron { transition: transform .15s; color: var(--fg3); }
.tool-chip.open .chevron { transform: rotate(90deg); }
.tool-chip .tool-name { color: var(--tool); font-weight: 600; }
.tool-chip .tool-summary { color: var(--fg); opacity: 0.85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 380px; }

.tool-detail {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px;
  font-family: ui-monospace, monospace; font-size: 12px;
  margin: 4px 0 8px;
  white-space: pre-wrap;
  max-height: 320px; overflow: auto;
  color: var(--fg2);
}
.tool-detail .label { color: var(--fg3); font-weight: 600; margin-bottom: 2px; }

/* ask_user form */
.msg-row.ask .avatar { background: linear-gradient(135deg, #d97c3c 0%, #ce6c33 100%); color: #fff; }
.ask-question { margin: 0 0 14px; padding: 10px 12px; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; }
.ask-question:last-child { margin-bottom: 8px; }
.ask-question .ask-header {
  display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px;
  padding: 2px 6px; background: var(--bg4); color: var(--fg2); border-radius: 3px;
  margin-bottom: 6px;
}
.ask-question .ask-q-text { font-weight: 500; margin-bottom: 8px; }
.ask-options { display: flex; flex-direction: column; gap: 4px; }
.ask-option {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 6px 10px; border-radius: 6px; cursor: pointer;
  border: 1px solid transparent;
}
.ask-option:hover { background: var(--bg3); }
.ask-option input { margin-top: 3px; flex-shrink: 0; accent-color: var(--accent); }
.ask-option .ask-label { font-weight: 500; }
.ask-option .ask-desc { font-size: 12px; color: var(--fg2); margin-top: 2px; }
.ask-option.checked { background: rgba(124,156,255,0.10); border-color: rgba(124,156,255,0.5); }
.ask-submit-row { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.ask-submit-row .btn-primary { padding: 6px 14px; font-size: 13px; }
.ask-submit-row .ask-note { font-size: 12px; color: var(--fg3); }
.msg-row.ask.submitted .ask-option { cursor: default; }
.msg-row.ask.submitted .ask-option:not(.checked) { opacity: 0.45; }
.msg-row.ask.submitted .ask-option.checked { background: rgba(95,212,121,0.12); border-color: rgba(95,212,121,0.5); }
.msg-row.ask.submitted .ask-option input { pointer-events: none; }
.msg-row.ask.submitted .ask-submit-row { display: none; }

/* result & system */
.msg-row.system .content { color: var(--fg3); font-size: 12px; font-style: italic; padding: 0; }
.msg-row.system .avatar { display: none; }
.msg-row.system .role { display: none; }
.msg-row.error .content { color: var(--err); }

.result-line {
  text-align: center; color: var(--fg3); font-size: 11px;
  padding: 8px 20px 4px; border-top: 1px solid var(--border);
  margin: 12px 20px 0;
}

/* streaming pulse */
.streaming::after {
  content: '▍'; color: var(--accent); animation: blink 1s infinite;
  margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ----- composer ----- */
#chat-form {
  padding: 12px 20px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
  transition: border-color .15s;
}
.composer:focus-within { border-color: var(--accent); }
.composer.drag-over { border-color: var(--accent); background: rgba(124,156,255,0.06); }
#attachment-strip {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px 8px 0;
}
.attach-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 6px 4px 10px;
  font-size: 12px;
}
.attach-chip .thumb {
  width: 28px; height: 28px; border-radius: 4px;
  background: var(--bg2); display: grid; place-items: center;
  color: var(--fg2); flex-shrink: 0; overflow: hidden;
}
.attach-chip .thumb img { width: 100%; height: 100%; object-fit: cover; }
.attach-chip .thumb.zoomable { cursor: zoom-in; }
.msg-row.user .content img { cursor: zoom-in; transition: filter .1s; }
.msg-row.user .content img:hover { filter: brightness(1.05); }

/* lightbox */
#image-lightbox {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.88);
  display: grid; place-items: center;
  cursor: zoom-out; padding: 24px;
}
#image-lightbox.hidden { display: none; }
#lightbox-img {
  max-width: 96vw; max-height: 92vh; object-fit: contain;
  border-radius: 6px; box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
#lightbox-close {
  position: absolute; top: 16px; right: 18px;
  background: rgba(255,255,255,0.08); color: #fff;
  border: 1px solid rgba(255,255,255,0.18); border-radius: 50%;
  width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer;
}
#lightbox-close:hover { background: rgba(255,255,255,0.18); }
.attach-chip .name { color: var(--fg); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .size { color: var(--fg3); }
.attach-chip .icon-btn { padding: 2px; color: var(--fg3); }
.attach-chip .icon-btn:hover { color: var(--err); }
#prompt-input {
  flex: 1; background: transparent; color: var(--fg); border: none;
  resize: none; font: inherit; line-height: 1.5;
  padding: 6px 0; min-height: 22px; max-height: 240px;
  outline: none;
}
#prompt-input::placeholder { color: var(--fg3); }
.composer-meta {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 4px 0; font-size: 11px; min-height: 16px;
}
#model-select, #backend-select {
  background: var(--bg2); color: var(--fg2); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 6px; font: inherit; font-size: 11px;
  cursor: pointer; min-width: 0;
}
#model-select:hover, #backend-select:hover { color: var(--fg); border-color: var(--border2); }
.composer-toggle {
  background: var(--bg2); color: var(--fg2); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 8px; font: inherit; font-size: 11px;
  cursor: pointer;
}
.composer-toggle:hover { color: var(--fg); }
.composer-toggle.active {
  background: rgba(216,165,92,0.18);
  color: var(--tool);
  border-color: rgba(216,165,92,0.6);
}
body.plan-mode .composer { border-color: var(--tool); }
#status::before {
  content: ''; display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--fg3); margin-right: 6px;
  vertical-align: middle;
}
#status.ready::before { background: var(--ok); }
#status.running::before { background: var(--accent); animation: pulse 1.2s infinite; }
#status.error::before { background: var(--err); }
@keyframes pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

/* ----- preview ----- */
#preview-pane { background: var(--bg2); position: relative; }

/* ---------- run bar ---------- */
#run-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#run-bar .run-bar-spacer { flex: 1; }
#run-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 14px; background: var(--ok); color: #0a1a0d;
  border: none; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 13px;
}
#run-btn:hover { filter: brightness(1.05); }
#run-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#run-btn.is-running { background: var(--err); color: #fff; }
#run-btn.is-running #run-btn-icon { transform: scale(0.85); }
#restart-btn, #console-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 13px;
}
#restart-btn:hover, #console-toggle:hover { background: var(--bg4); }
#console-toggle.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#run-status { font-size: 12px; display: inline-flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
#run-status .dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--fg3); flex-shrink: 0;
}
#run-status.running .dot { background: var(--ok); box-shadow: 0 0 6px rgba(95,212,121,.6); }
#run-status.stopped .dot { background: var(--err); }
#run-status.none .dot { background: var(--fg3); }
#run-status .name { font-weight: 500; color: var(--fg); }
#run-status .port { font-family: ui-monospace, monospace; color: var(--accent); }
#run-status .cmd { color: var(--fg3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#run-open, #run-reload {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 4px; border-radius: 4px; color: var(--fg2);
  background: transparent; border: 1px solid transparent;
  text-decoration: none; cursor: pointer;
}
#run-open:hover, #run-reload:hover { color: var(--fg); background: var(--bg3); }

/* ---------- run config form ---------- */
#run-config-form {
  padding: 18px 20px; background: var(--bg2); border-bottom: 1px solid var(--border);
}
#run-config-form h3 { margin: 0 0 12px; font-size: 14px; }
#run-config-form label { display: block; font-size: 12px; color: var(--fg2); margin: 10px 0 4px; }
#run-config-form input {
  width: 100%; padding: 8px 10px; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit;
  font-family: ui-monospace, monospace; font-size: 13px;
}
#run-config-form input:focus { outline: none; border-color: var(--accent); }
#run-config-form code {
  background: var(--bg3); padding: 1px 4px; border-radius: 3px;
  font-size: 11px; font-family: ui-monospace, monospace;
}

/* ---------- console pane ---------- */
#console-pane {
  position: absolute; inset: 0; top: auto; bottom: 0; right: 0; left: 0;
  background: #050608;
  display: flex; flex-direction: column;
}
/* Make it fill the preview area */
#preview-pane #console-pane {
  position: static; flex: 1; min-height: 0;
}
#console-content {
  flex: 1; margin: 0; padding: 12px 14px;
  background: #050608; color: #d6dce3;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; word-break: break-all;
  overflow: auto;
}

/* ---------- services panel ---------- */
#services-panel {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 8px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.svc-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 8px 4px 10px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px; color: var(--fg);
}
.svc-chip.kind-process { border-color: #4a3a4a; }
.svc-chip.kind-static { opacity: 0.85; }
.svc-chip .kind-tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 1px 6px; border-radius: 3px;
  background: var(--bg4); color: var(--fg2);
}
.svc-chip.kind-service .kind-tag { background: rgba(124,156,255,0.18); color: var(--accent); }
.svc-chip.kind-process .kind-tag { background: rgba(216,165,92,0.18); color: var(--tool); }
.svc-chip.kind-static .kind-tag { background: rgba(95,212,121,0.18); color: var(--ok); }
.svc-chip .svc-port {
  font-family: ui-monospace, monospace; font-size: 11px; color: var(--fg2);
}
.svc-chip .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--bg4); flex-shrink: 0;
}
.svc-chip.alive .dot { background: var(--ok); box-shadow: 0 0 4px rgba(95, 212, 121, 0.6); }
.svc-chip.dead .dot { background: var(--err); }
.svc-chip .svc-name { font-weight: 600; }
.svc-chip .svc-cmd {
  font-family: ui-monospace, monospace; color: var(--fg2);
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.svc-chip .icon-btn { padding: 2px; color: var(--fg2); }
.svc-chip .icon-btn:hover { color: var(--fg); background: var(--bg4); }

/* logs modal */
.modal {
  position: absolute; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.55);
  display: grid; place-items: center;
  padding: 24px;
}
.modal-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%; height: 100%;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600;
}
.modal-header > div { display: flex; gap: 4px; }
#logs-content {
  flex: 1; overflow: auto; margin: 0; padding: 12px 14px;
  background: var(--bg); color: var(--fg);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; word-break: break-all;
}

/* docs modal */
#memory-modal { position: fixed; inset: 0; z-index: 80; }
.docs-modal { width: 1100px; max-width: 95vw; height: 80vh; max-height: 80vh; }
.docs-body {
  flex: 1; display: grid; grid-template-columns: 260px 1fr; overflow: hidden;
}
.docs-files {
  background: var(--bg2); border-right: 1px solid var(--border);
  padding: 10px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
}
.docs-files .btn-sm { margin-bottom: 4px; }
#docs-file-list { display: flex; flex-direction: column; gap: 1px; }
.docs-file {
  padding: 7px 10px; cursor: pointer; border-radius: 4px;
  font-size: 13px; color: var(--fg); display: flex; flex-direction: column; gap: 2px;
}
.docs-file:hover { background: var(--bg3); }
.docs-file.active { background: var(--accent); color: #fff; }
.docs-file.active .meta { color: rgba(255,255,255,0.75); }
.docs-file .name { font-family: ui-monospace, monospace; font-size: 12.5px; }
.docs-file .meta { font-size: 10px; color: var(--fg3); }
.docs-pane { position: relative; background: var(--bg); overflow: hidden; }
.docs-pane #memory-content,
.docs-pane #memory-rendered {
  position: absolute; inset: 0;
  margin: 0; padding: 18px 22px;
  background: var(--bg); color: var(--fg);
  overflow: auto;
}
#memory-content {
  font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  border: none; outline: none; resize: none;
}
.md-rendered {
  font: 14px/1.65 -apple-system, system-ui, "Segoe UI", Roboto, Inter, sans-serif;
}
.md-rendered > *:first-child { margin-top: 0; }
.md-rendered > *:last-child { margin-bottom: 0; }
.md-rendered h1 { font-size: 1.7em; margin: 0.6em 0 0.4em; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.md-rendered h2 { font-size: 1.35em; margin: 1.1em 0 0.4em; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.md-rendered h3 { font-size: 1.15em; margin: 1em 0 0.3em; }
.md-rendered h4 { font-size: 1.0em; margin: 0.9em 0 0.3em; }
.md-rendered p { margin: 0.5em 0; }
.md-rendered ul, .md-rendered ol { margin: 0.4em 0; padding-left: 1.6em; }
.md-rendered li { margin: 0.2em 0; }
.md-rendered a { color: var(--accent); text-decoration: none; }
.md-rendered a:hover { text-decoration: underline; }
.md-rendered code {
  background: var(--bg3); padding: 1px 5px; border-radius: 3px;
  font: 0.88em ui-monospace, monospace;
}
.md-rendered pre {
  background: var(--bg3); border: 1px solid var(--border);
  padding: 12px 14px; margin: 0.7em 0;
  border-radius: var(--radius-sm); overflow-x: auto;
}
.md-rendered pre code { background: transparent; padding: 0; font-size: 0.86em; line-height: 1.55; }
.md-rendered blockquote {
  border-left: 3px solid var(--border2);
  margin: 0.7em 0; padding: 0 0 0 14px; color: var(--fg2);
}
.md-rendered hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }
.md-rendered table {
  border-collapse: collapse; margin: 0.7em 0;
}
.md-rendered th, .md-rendered td {
  border: 1px solid var(--border); padding: 6px 10px;
}
.md-rendered th { background: var(--bg2); }
.md-rendered img { max-width: 100%; }
.md-rendered.empty::before {
  content: 'Empty doc. Click Edit to add content.';
  color: var(--fg3); font-style: italic;
}
#preview-tabs {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 8px; background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0; overflow-x: auto; min-height: 38px;
}
#url-bar {
  display: flex; align-items: stretch; gap: 0;
  padding: 6px 8px; background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#url-bar .url-prefix {
  padding: 5px 10px; background: var(--bg3); border: 1px solid var(--border);
  border-right: none; border-top-left-radius: 6px; border-bottom-left-radius: 6px;
  color: var(--fg2); font-family: ui-monospace, monospace; font-size: 12px;
  white-space: nowrap; display: flex; align-items: center;
}
#url-bar #url-path {
  flex: 1; min-width: 0;
  padding: 5px 10px; background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); border-radius: 0;
  font-family: ui-monospace, monospace; font-size: 12px; outline: none;
}
#url-bar #url-path:focus { border-color: var(--accent); }
#url-bar #url-go {
  padding: 5px 12px; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-left: none;
  border-top-right-radius: 6px; border-bottom-right-radius: 6px;
  cursor: pointer;
}
#url-bar #url-go:hover { background: var(--bg4); }
.port-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 10px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap;
  font-size: 12px; color: var(--fg2);
  transition: background .1s;
}
.port-tab.kind-static { opacity: 0.75; font-style: italic; }
.port-tab.kind-service { font-weight: 500; }
.port-tab .tab-label { font-family: inherit; }
.port-tab:hover { background: var(--bg4); color: var(--fg); }
.port-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.port-tab.active .ext { color: rgba(255,255,255,0.85); }
.port-tab .ext {
  display: inline-flex; padding: 2px; border-radius: 3px;
  color: var(--fg3);
}
.port-tab .ext:hover { background: rgba(255,255,255,0.15); color: var(--fg); }
.tab-spacer { flex: 1; }
.tab-action { background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 8px; color: var(--fg2); cursor: pointer; }
.tab-action:hover { color: var(--fg); }

#preview-frame-wrap { flex: 1; position: relative; }
#preview-frame { width: 100%; height: 100%; border: none; background: #fff; }
#preview-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px; text-align: center; line-height: 1.7; font-size: 13px;
}
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius-sm); padding: 8px 14px; cursor: pointer;
  font: inherit; font-weight: 500;
}
.btn-primary:hover { background: var(--accent2); }

/* idle-state landing card (when there's a run config but project isn't running) */
.empty-card {
  max-width: 460px; width: 90%;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px 28px 24px; text-align: center;
  box-shadow: 0 14px 40px rgba(0,0,0,0.35);
}
.empty-card .icon-wrap {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(95,212,121,0.15); color: var(--ok);
  margin-bottom: 14px;
}
.empty-card .icon-wrap svg { width: 28px; height: 28px; }
.empty-card h2 { margin: 0 0 6px; font-size: 18px; color: var(--fg); }
.empty-card .ws-name { color: var(--accent); }
.empty-card .cmd {
  display: inline-block; margin: 10px 0 18px; padding: 5px 10px;
  font-family: ui-monospace, monospace; font-size: 12px; color: var(--fg2);
  background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
}
.empty-card .big-run {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 22px; font-size: 14px; font-weight: 600;
  background: var(--ok); color: #0a1a0d; border: none; border-radius: 8px;
  cursor: pointer;
}
.empty-card .big-run:hover { filter: brightness(1.05); }
.empty-card .alt {
  margin-top: 18px; font-size: 12px; color: var(--fg3);
}
.empty-card .alt a, .empty-card .alt button {
  background: none; border: none; color: var(--fg2);
  text-decoration: underline; cursor: pointer; padding: 0; font: inherit;
}
.empty-card .alt a:hover, .empty-card .alt button:hover { color: var(--fg); }
