/* ============================================================
   Agents Cubed — engine-room UI
   Design source of truth: docs/design/DESIGN.md (Pass 1 tokens).
   Legacy var names kept; values re-pointed at the family palette.
   Grammar: teal = live · amber = needs you · red = stopped only.
   ============================================================ */

:root {
  --bg: #0c0f13;            /* bay-950 */
  --bg-soft: #11151b;       /* bay-900 */
  --panel: #171c24;         /* bay-800 */
  --pane: #11151b;          /* terminal screens glow slightly above the page */
  --glass: rgba(255, 255, 255, 0.03);
  --glass-2: rgba(255, 255, 255, 0.055);
  --line: #232a35;          /* bay-700 — solid, machined */
  --line-soft: rgba(255, 255, 255, 0.06);

  --text: #e9edf1;
  --muted: #a9b2bc;
  --dim: #5f6b76;

  /* ONE accent — the old sky/gradient pair collapses into flat teal */
  --teal: #14b8a6;
  --sky: #14b8a6;
  --grad: #14b8a6;
  --grad-soft: rgba(20, 184, 166, 0.14);

  --green: #14b8a6;  /* running = live = teal (family grammar) */
  --amber: #f59e0b;
  --need: #f59e0b;   /* agent is requesting input — amber, never pink/red */
  --red: #ef4444;    /* stopped / danger ONLY */

  --font-ui: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", var(--font-mono);
  --font-display: "Space Grotesk", var(--font-ui);

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
::selection { background: rgba(20, 184, 166, 0.3); }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

/* ambient glow behind everything */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: radial-gradient(1100px 600px at 18% -8%, rgba(20, 184, 166, 0.07), transparent 60%);
}

#app { position: relative; z-index: 1; display: flex; height: 100vh; }

/* custom scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.10); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); background-clip: padding-box; }

button { font-family: inherit; }
.ghost-btn {
  background: var(--glass); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); cursor: pointer; padding: 3px 9px; font-size: 14px;
  transition: all .15s ease;
}
.ghost-btn:hover { border-color: var(--teal); color: var(--teal); box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.08); }

/* ============================================================ SIDEBAR */

#sidebar {
  width: 274px; flex: 0 0 274px;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 14px; gap: 14px; overflow-y: auto;
  transition: width .22s ease, flex-basis .22s ease, padding .22s ease;
}

#brand { display: flex; align-items: center; gap: 11px; padding: 2px 2px 10px; border-bottom: 1px solid var(--line-soft); }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: 0 0 30px;
  display: grid; place-items: center; color: var(--text);
  background: var(--bg-soft); border: 1px solid var(--line);
}
.brand-mark svg { display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-family: var(--font-display); font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-family: var(--font-mono); font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; }

.section-head { display: flex; align-items: center; justify-content: space-between; }
.section-head .ghost-btn { padding: 1px 7px; font-size: 12px; }
#sidebar h2 { font-size: 10px; margin: 0 0 7px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.4px; font-weight: 600; }

#sidebar form { display: flex; flex-direction: column; gap: 7px; }
#sidebar form label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 11px; }
#sidebar input, #sidebar select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); padding: 6px 8px; font-family: var(--font-mono); font-size: 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
#sidebar input:focus, #sidebar select:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.12); }
#sidebar form button {
  background: var(--grad); color: #0c0f13; font-weight: 700; border: none;
  border-radius: 8px; padding: 7px 10px; cursor: pointer; transition: filter .15s ease, transform .05s ease;
}
#sidebar form button:hover { filter: brightness(1.08); }
#sidebar form button:active { transform: translateY(1px); }
#sidebar .row { display: flex; gap: 6px; }
#btn-agent { flex: 1; }
#agent-target { font-size: 11px; text-transform: none; letter-spacing: 0; color: var(--teal); }

details > summary { cursor: pointer; color: var(--teal); font-size: 12px; user-select: none; list-style: none; padding: 4px 0; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; color: var(--muted); }
details[open] > summary::before { content: "▾ "; }

/* connect-GitHub box */
#gh-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; background: var(--glass); }
#gh-box.connected > summary { color: var(--green); }
.gh-hint { color: var(--muted); font-size: 10px; line-height: 1.5; margin: 6px 0 0; }

/* ---- download a session (sidebar box above Workspaces) ---- */
#dl-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; background: var(--glass); }
.dl-hint { color: var(--muted); font-size: 10px; line-height: 1.5; margin: 6px 0 4px; }
.dl-hint code { font-size: 10px; color: var(--text); }
#dl-list { list-style: none; margin: 4px 0 0; padding: 0; max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.dl-empty { color: var(--muted); font-size: 10px; padding: 4px 0; }
.dl-item .dl-get { display: block; text-decoration: none; padding: 5px 6px; border-radius: 7px; border: 1px solid transparent; }
.dl-item .dl-get:hover { background: var(--glass-2); border-color: var(--line); }
.dl-ws { display: flex; align-items: center; gap: 5px; }
.dl-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; background: var(--muted); }
.dl-wsname { color: var(--text); font-size: 10.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-title { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-id { display: block; font-family: var(--font-mono); font-size: 9.5px; color: var(--muted); opacity: .8; margin-top: 1px; user-select: all; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-meta { display: block; color: var(--muted); font-size: 10px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-meta b { color: var(--teal); font-weight: 700; }
.dl-agent { color: var(--muted); }

/* ---- workspace list (compact + expanded) ---- */

#ws-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.ws-item {
  padding: 7px 8px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid transparent; transition: background .15s ease, border-color .15s ease;
}
.ws-item:hover { background: var(--glass); }
.ws-item.selected { border-color: var(--line); background: var(--glass-2); box-shadow: inset 2px 0 0 var(--teal); }
/* header row: chevron, color, icon, NAME, status (actions are a separate row below) */
.ws-row { display: flex; align-items: center; gap: 7px; }
.b-expand { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 10px; padding: 0 1px; flex: 0 0 auto; line-height: 1; }
.b-expand:hover { color: var(--teal); }
.ws-color { width: 3px; height: 16px; border-radius: 3px; flex: 0 0 3px; box-shadow: 0 0 8px currentColor; }
.ws-icon { font-size: 12px; flex: 0 0 auto; }
.ws-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; font-weight: 500; }
.ws-status { font-size: 10px; color: var(--muted); flex: 0 0 auto; }
.ws-status.s-creating { color: var(--teal); }
.ws-status.s-error { color: var(--red); }
.ws-status.s-stopped { color: var(--dim); }

/* action icons: their OWN row, indented under the name */
.ws-actions { display: flex; gap: 2px; flex-wrap: wrap; margin-top: 5px; padding-left: 18px; }
.ws-actions button {
  background: none; border: none; cursor: pointer; font-size: 12px; color: var(--muted);
  padding: 2px 5px; border-radius: 6px; transition: all .12s ease;
}
.ws-actions button::after { content: ""; }
.ws-actions button:hover { color: var(--text); background: var(--glass-2); }
.ws-actions .b-remove:hover { color: var(--red); }
.ws-actions .b-checkpoint.on { color: var(--green); }
.ws-meta { color: var(--muted); font-size: 10px; padding: 4px 0 0 18px; line-height: 1.7; }
.svc-chip { background: var(--glass-2); border: 1px solid var(--line); color: var(--text); border-radius: 4px; padding: 0 5px; margin-right: 4px; }
.git-badge { border-radius: 4px; padding: 0 5px; font-weight: 600; }
.ws-err { color: var(--red); font-size: 10px; margin-top: 3px; white-space: normal; word-break: break-word; line-height: 1.4; }
.git-badge.dirty { background: rgba(245, 158, 11, 0.14); color: var(--amber); }
.git-badge.clean { color: var(--green); }
.cp-badge { margin-left: 6px; color: var(--green); }
.cp-badge.failed { color: var(--red); }

/* per-workspace expanded card: labeled buttons in a tidy 2-col grid */
.ws-item.expanded { background: var(--glass); border-color: var(--line); border-radius: var(--radius-lg); padding: 11px; }
.ws-item.expanded.selected { box-shadow: inset 0 0 0 1px var(--teal), 0 6px 20px rgba(0,0,0,.3); }
.ws-item.expanded .ws-color { height: 20px; }
.ws-item.expanded .ws-name { font-size: 14px; font-weight: 700; }
.ws-item.expanded .ws-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 11px; padding-left: 0; }
.ws-item.expanded .ws-actions button { display: flex; align-items: center; gap: 8px; justify-content: flex-start; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
.ws-item.expanded .ws-actions button:hover { border-color: var(--teal); background: var(--glass-2); }
.ws-item.expanded .ws-actions button::after { content: attr(data-label); font-size: 11px; color: var(--text); }
.ws-item.expanded .ws-meta { padding-left: 0; margin-top: 9px; }

/* ---- resume picker ---- */
#resume-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; background: var(--glass); }
#resume-box input { width: 100%; margin: 7px 0 4px; }
#resume-list { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.resume-item { display: flex; flex-direction: column; gap: 1px; padding: 6px 7px; border-radius: 7px; cursor: pointer; }
.resume-item:hover { background: var(--glass-2); }
.resume-item .r-title { color: var(--text); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resume-item .r-meta { color: var(--muted); font-size: 10px; }
.resume-status { color: var(--green); font-size: 10px; margin: 3px 2px 5px; opacity: 0.9; cursor: default; }
.import-session { width: 100%; margin-top: 7px; padding: 7px; font-size: 11px; color: var(--text); cursor: pointer;
  background: var(--glass); border: 1px dashed var(--line); border-radius: 8px; }
.import-session:hover { background: var(--glass-2); border-color: var(--teal); }
.ws-item.drop-target { outline: 2px dashed var(--teal); outline-offset: -2px; background: var(--grad-soft); }

/* New-agent quick-setup presets */
#new-agent-form .presets { display: flex; align-items: flex-start; gap: 7px; flex-wrap: wrap; margin-top: 8px; }
#preset-chips { display: flex; flex-wrap: wrap; gap: 7px; flex: 1; }
.presets-label { color: var(--muted); font-size: 10px; padding-top: 5px; }
.preset { font-size: 11px; padding: 4px 9px; color: var(--text); cursor: pointer;
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px; }
.preset:hover { background: var(--glass-2); border-color: var(--teal); }
.preset.custom { padding-right: 5px; }
.preset.custom .px { margin-left: 6px; padding: 0 4px; border-radius: 50%; color: var(--muted); font-weight: 700; }
.preset.custom .px:hover { color: var(--red); background: var(--glass-2); }
.preset.add-preset { border-style: dashed; color: var(--muted); }
.preset.add-preset:hover { color: var(--text); }
#ws-docker-row { font-size: 10.5px; color: var(--muted); }
#ws-docker-row select { accent-color: var(--teal); }
/* while dragging a file, hint that docker containers are drop zones for a session .jsonl */
body.file-dragging .ws-item.droppable { outline: 1px dashed var(--sky); outline-offset: -2px; }
body.file-dragging .ws-item.droppable::after { content: '⬆ drop a session here'; display: block;
  padding: 2px 8px 4px; font-size: 9.5px; color: var(--sky); }

/* ---- session placement popover (SESSION_PLACEMENT P1) ---- */
.place-backdrop { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(2px); }
.place-card { width: min(430px, 92vw); max-height: 86vh; overflow-y: auto; padding: 15px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.55); }
.place-head { color: var(--text); font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place-sub { color: var(--muted); font-size: 10px; margin-top: 3px; }
.place-label { color: var(--muted); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.06em; margin: 13px 0 5px; }
.place-rows { display: flex; flex-direction: column; gap: 2px; }
.place-row { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.place-row:hover { background: var(--glass-2); }
.place-row input { margin: 0; accent-color: var(--teal); }
.place-row .pt-ic { width: 14px; text-align: center; color: var(--muted); }
.place-row .pt-name { color: var(--text); font-size: 12px; }
.place-row .pt-dir { color: var(--muted); font-size: 10px; margin-left: auto; font-family: var(--font-mono); }
.place-empty { color: var(--muted); font-size: 11px; padding: 8px; }
.place-extra { display: flex; gap: 8px; margin-top: 8px; }
.place-extra button { flex: 1; padding: 6px; font-size: 11px; color: var(--text); cursor: pointer;
  background: var(--glass); border: 1px solid var(--line); border-radius: 8px; }
.place-extra button:hover:not(:disabled) { background: var(--glass-2); }
.place-extra button:disabled { opacity: 0.45; cursor: not-allowed; }
.place-what { color: var(--muted); font-size: 10.5px; line-height: 1.45; margin: 11px 0;
  padding: 8px 10px; background: var(--glass); border: 1px solid var(--line-soft); border-radius: 8px; }
.place-actions { display: flex; justify-content: flex-end; gap: 8px; }
.place-actions button { padding: 6px 15px; font-size: 12px; color: var(--text); cursor: pointer;
  background: var(--glass); border: 1px solid var(--line); border-radius: 8px; }
.place-actions button:hover:not(:disabled) { background: var(--glass-2); }
.place-actions .primary { color: #0c0f13; font-weight: 600; background: var(--grad); border-color: transparent; }
.place-actions button:disabled { opacity: 0.55; cursor: default; }

#status-line { color: var(--muted); font-size: 10.5px; margin-top: auto; padding-top: 8px; border-top: 1px solid var(--line-soft); }

#app.sidebar-collapsed #sidebar { width: 0; flex-basis: 0; padding: 0; border: 0; overflow: hidden; }

/* ============================================================ FILE EXPLORER */

#explorer {
  width: 250px; flex: 0 0 250px; background: var(--bg-soft);
  border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0;
}
#explorer[hidden] { display: none; }
#explorer-header { display: flex; align-items: center; gap: 7px; padding: 9px; border-bottom: 1px solid var(--line); font-size: 11px; color: var(--muted); }
#explorer-header .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; box-shadow: 0 0 8px currentColor; }
#explorer-root { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#explorer-header button { background: none; border: none; color: var(--muted); cursor: pointer; }
#explorer-header button:hover { color: var(--teal); }
#explorer-add { display: flex; flex-direction: column; gap: 6px; padding: 9px; background: var(--glass);
  border-bottom: 1px solid var(--line); }
#explorer-add .add-row { display: flex; align-items: center; gap: 6px; }
#explorer-add label.add-row { font-size: 10px; color: var(--muted); }
#explorer-add select, #explorer-add input[type=text] { flex: 1; min-width: 0; font-size: 11px;
  background: var(--bg-soft); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
#explorer-add button { font-size: 11px; padding: 5px 9px; white-space: nowrap; cursor: pointer;
  background: var(--glass); color: var(--text); border: 1px solid var(--line); border-radius: 6px; }
#explorer-add button:hover { background: var(--glass-2); border-color: var(--teal); }
#explorer-add #add-upload { flex: 1; }
#tree { overflow: auto; flex: 1; padding: 5px 0; font-size: 12px; }
.tree-item { display: flex; align-items: center; gap: 5px; padding: 3px 9px; cursor: pointer; white-space: nowrap; color: var(--text); }
.tree-item:hover { background: var(--glass); }
.tree-item.t-dir { color: var(--muted); }
.tree-item.t-dir.open { color: var(--text); }
.tree-item .t-size { margin-left: auto; color: var(--dim); font-size: 10px; }
.tree-children { display: none; }
.tree-children.open { display: block; }

/* ============================================================ MAIN COLUMN */

#main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* ---- agent bar ---- */
#agent-bar {
  display: flex; align-items: center; gap: 9px; padding: 7px 10px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line); flex: 0 0 auto; min-height: 44px;
}
#project-filter {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); padding: 5px 8px; font-size: 12px; max-width: 220px; cursor: pointer;
}
#project-filter:focus { outline: none; border-color: var(--teal); }
#view-toggle { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
#view-toggle button { background: var(--bg); border: none; color: var(--muted); cursor: pointer; padding: 5px 11px; font-size: 13px; transition: all .15s ease; }
#view-toggle button:hover { color: var(--text); }
#view-toggle button.active { background: var(--grad); color: #0c0f13; }
#tab-strip { display: flex; gap: 5px; overflow-x: auto; flex: 1; padding-bottom: 1px; }
#tab-strip::-webkit-scrollbar { height: 0; }

/* ---- agent tabs (taller, editable, truncated, status-colored) ---- */
.agent-tab {
  display: flex; align-items: center; gap: 7px;
  background: var(--glass); border: 1px solid var(--line);
  border-radius: 9px; color: var(--text); cursor: pointer;
  padding: 6px 12px; font-size: 12px; white-space: nowrap; position: relative;
  transition: all .15s ease; min-height: 30px;
}
.agent-tab::after { /* workspace-color underline */
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px;
  background: var(--wcolor, transparent); border-radius: 2px; opacity: .8;
}
.agent-tab:hover { background: var(--glass-2); border-color: var(--line); transform: translateY(-1px); }
.agent-tab.active { background: var(--glass-2); border-color: var(--teal); box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.10); }
.agent-tab .tab-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: 0 0 8px; box-shadow: 0 0 8px var(--green); }
.agent-tab .tab-name { max-width: 168px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-tab .tab-edit { background: var(--bg); border: 1px solid var(--teal); border-radius: 5px; color: var(--text); font-size: 12px; padding: 1px 5px; width: 150px; font-family: inherit; }
.agent-tab .tab-edit:focus { outline: none; }
.agent-tab.s-idle .tab-dot { background: var(--muted); box-shadow: none; }
.agent-tab.s-needs-input { border-color: var(--need); background: rgba(245, 158, 11, 0.10); color: var(--amber); }
.agent-tab.s-needs-input .tab-dot { background: var(--need); box-shadow: 0 0 10px var(--need); animation: pulse 1.2s ease-in-out infinite; }
.agent-tab.s-exited { border-color: var(--red); color: var(--red); }
.agent-tab.s-exited .tab-dot { background: var(--red); box-shadow: 0 0 8px var(--red); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* ---- embedded VS Code ---- */
#editor { flex: 1 1 62%; display: flex; flex-direction: column; min-height: 0; border-bottom: 1px solid var(--line); }
#editor[hidden] { display: none; }
#editor-header { display: flex; align-items: center; gap: 10px; padding: 6px 11px; background: var(--bg-soft); border-bottom: 1px solid var(--line); font-size: 11px; }
#editor-header .spacer { flex: 1; }
#editor-title { font-weight: 600; }
#editor-header button { background: var(--glass); border: 1px solid var(--line); border-radius: 6px; color: var(--muted); cursor: pointer; font-size: 11px; padding: 3px 8px; }
#editor-header button:hover { color: var(--text); border-color: var(--teal); }
#editor-frame { flex: 1; width: 100%; border: 0; background: #1e1e1e; min-height: 0; }

/* ---- read-only viewer ---- */
#viewer { flex: 0 0 45%; display: flex; flex-direction: column; border-bottom: 2px solid var(--teal); background: var(--pane); min-height: 0; }
#viewer[hidden] { display: none; }
#viewer-header { display: flex; align-items: center; gap: 10px; padding: 6px 11px; background: var(--bg-soft); border-bottom: 1px solid var(--line); font-size: 11px; }
#viewer-title { font-weight: 600; color: var(--teal); }
#viewer-meta { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#viewer-header button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; }
#viewer-header button:hover { color: var(--red); }
#viewer-body { flex: 1; margin: 0; padding: 12px 16px; overflow: auto; font-family: var(--font-mono); font-size: 12px; line-height: 1.55; color: var(--text); tab-size: 4; }

/* ---- terminal grid ---- */
#grid { flex: 1; display: grid; grid-auto-rows: 1fr; gap: 8px; padding: 8px; min-width: 0; min-height: 0; }
#grid.single { grid-template-rows: 1fr; }
#grid:empty::before {
  content: "No agents yet — create or pick a workspace on the left, then + Agent. Each pane is a real terminal running your CLI.";
  color: var(--muted); align-self: center; justify-self: center; max-width: 440px; text-align: center; line-height: 1.7;
}

.pane {
  display: flex; flex-direction: column; background: var(--pane);
  border: 1px solid var(--line); border-top: 2px solid var(--line);
  border-radius: var(--radius); overflow: hidden; min-width: 0; min-height: 0;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.pane.focused { box-shadow: 0 0 0 1px var(--teal), 0 10px 30px rgba(0,0,0,.4); }
.pane.needs-input { border-color: var(--need); box-shadow: 0 0 0 1px var(--need), 0 0 24px rgba(245,158,11,.16); }

.pane-header { display: flex; align-items: center; gap: 9px; padding: 6px 9px; background: var(--bg-soft); border-bottom: 1px solid var(--line); font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.pane-header .ws-tag { color: #0c0f13; font-weight: 700; font-size: 10px; border-radius: 5px; padding: 1px 7px; }
.pane-header .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.pane-header .dot.running { background: var(--green); box-shadow: 0 0 8px var(--green); }
.pane-header .dot.idle { background: var(--muted); box-shadow: none; }
.pane-header .dot.needs-input { background: var(--need); box-shadow: 0 0 10px var(--need); animation: pulse 1.2s ease-in-out infinite; }
.pane-header .dot.exited { background: var(--red); box-shadow: 0 0 8px var(--red); animation: none; }
.pane-header .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); cursor: text; }
.pane-header button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0 4px; border-radius: 5px; transition: color .12s ease; }
.pane-header button:hover { color: var(--teal); }
.pane-header .btn-close:hover { color: var(--red); }
.pane-term { flex: 1; min-height: 0; padding: 5px; }
.pane-term .xterm { height: 100%; }

/* bottom composer: quick keys + a roomy chat card (mirrors the mobile prompt, taller) */
.pane-keys { display: flex; gap: 6px; padding: 9px 11px 0; flex: 0 0 auto; background: var(--bg-soft); border-top: 1px solid var(--line); }
.pane-keys .key-btn { min-width: 32px; height: 28px; background: var(--glass); color: var(--text); border: 1px solid var(--line); border-radius: 7px; cursor: pointer; font-size: 12px; font-weight: 600; }
.pane-keys .key-btn:hover { border-color: var(--teal); color: var(--teal); box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.08); }
.pane-keys .key-btn:active { background: var(--teal); color: #0c0f13; }

.pane-prompt { display: flex; gap: 8px; align-items: stretch; padding: 8px 11px 11px; background: var(--bg-soft); flex: 0 0 auto; }
.pane-prompt .prompt-input {
  flex: 1; resize: none; min-height: 60px; max-height: 180px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-family: inherit; font-size: 13px; line-height: 1.5;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}
.pane-prompt .prompt-input::placeholder { color: var(--muted); }
.pane-prompt .prompt-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.10); }
.pane-prompt .prompt-send {
  flex: 0 0 auto; align-self: stretch; min-width: 48px;
  background: var(--teal); color: #0c0f13; border: none; border-radius: 10px;
  cursor: pointer; font-size: 16px; font-weight: 700;
}
.pane-prompt .prompt-send:hover { filter: brightness(1.12); }

/* transport dropped, agent still alive server-side — amber, not the red of a real exit */
.pane.reconnecting { position: relative; border-color: var(--need); }
.pane.reconnecting::after {
  content: '⟳ reconnecting…'; position: absolute; top: 30px; right: 8px; z-index: 6;
  font-size: 10px; color: var(--need); background: rgba(7, 8, 12, 0.82);
  padding: 2px 7px; border-radius: 6px; pointer-events: none;
}

/* ============================================================ ONBOARDING */

#onboarding { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 800px at 20% -10%, rgba(20,184,166,.10), transparent 55%), rgba(4, 6, 10, 0.88);
  backdrop-filter: blur(10px); animation: obFade .3s ease; }
#onboarding[hidden] { display: none; }
@keyframes obFade { from { opacity: 0; } to { opacity: 1; } }

.ob-stage {
  position: relative; width: min(920px, 96vw); max-height: 92vh; overflow-y: auto;
  background: linear-gradient(180deg, rgba(17,20,28,.96), rgba(11,13,19,.96));
  border: 1px solid var(--line); border-radius: 20px; padding: 40px 40px 22px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.05);
}
.ob-stage::before { content: ""; position: absolute; inset: 0; border-radius: 20px; padding: 1px; pointer-events: none;
  background: linear-gradient(135deg, rgba(20,184,166,.5), rgba(20,184,166,.2), transparent 60%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; }
.ob-skip { position: absolute; top: 16px; right: 18px; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; }
.ob-skip:hover { color: var(--text); }

.ob-screen { animation: obSlide .35s ease; }
@keyframes obSlide { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.ob-hero { text-align: center; margin-bottom: 26px; }
.ob-mark { width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 16px; display: grid; place-items: center; color: var(--text); background: var(--bg-soft); border: 1px solid var(--line); }
.ob-hero h1 { font-family: var(--font-display); font-size: 30px; margin: 0 0 10px; font-weight: 700; letter-spacing: -0.02em; }
.grad { color: var(--teal); } /* the gradient-text era is over — one flat teal */
.ob-lead { color: var(--muted); font-size: 14px; max-width: 560px; margin: 0 auto; line-height: 1.6; }

.ob-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.ob-card { background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; transition: transform .15s ease, border-color .15s ease; }
.ob-card:hover { transform: translateY(-3px); border-color: rgba(20,184,166,.4); }
.ob-ico { font-size: 26px; margin-bottom: 8px; }
.ob-card h3 { margin: 0 0 6px; font-size: 14px; }
.ob-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.ob-steps { display: flex; flex-direction: column; gap: 14px; }
.ob-step { display: flex; gap: 16px; align-items: flex-start; background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px 18px; }
.ob-num { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-weight: 800; color: #0c0f13; background: var(--grad); box-shadow: 0 6px 18px rgba(20,184,166,.35); }
.ob-step h3 { margin: 2px 0 5px; font-size: 14px; }
.ob-step p { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.ob-fine { text-align: center; color: var(--dim); font-size: 11.5px; margin: 18px 0 0; }
.ob-fine a { color: var(--teal); text-decoration: none; }

#onboarding code { background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font-size: 11.5px; color: var(--teal); }

.ob-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.ob-dots { display: flex; gap: 8px; }
.ob-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); cursor: pointer; transition: all .2s ease; }
.ob-dot.active { background: var(--grad); width: 22px; border-radius: 4px; }
.ob-nav { display: flex; gap: 10px; }
.ob-btn { border-radius: 9px; padding: 9px 18px; font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s ease; }
.ob-btn.primary { background: var(--grad); color: #0c0f13; border: none; }
.ob-btn.primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.ob-btn.ghost { background: none; border: 1px solid var(--line); color: var(--text); }
.ob-btn.ghost:hover { border-color: var(--teal); color: var(--teal); }

@media (max-width: 760px) {
  .ob-cards { grid-template-columns: 1fr; }
  .ob-stage { padding: 28px 22px 18px; }
}

/* L-A: suspended ("sleeping") agents — a record with no terminal/socket until you click to wake it */
#suspended-strip { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line-soft); background: rgba(255,255,255,.02); }
#suspended-strip[hidden] { display: none; }
.susp-label { font-size: 11.5px; color: var(--dim); margin-right: 4px; }
.susp-card { display: inline-flex; align-items: center; gap: 7px; background: var(--glass); border: 1px solid var(--line); border-left: 3px solid var(--wcolor, var(--line)); border-radius: 8px; padding: 5px 11px; cursor: pointer; color: var(--text); font-size: 12.5px; opacity: .72; transition: opacity .15s ease, transform .15s ease, border-color .15s ease; }
.susp-card:hover { opacity: 1; transform: translateY(-1px); border-color: var(--teal); }
.susp-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); box-shadow: 0 0 0 2px rgba(255,255,255,.04); }
.susp-name { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot.suspended { background: var(--dim); }
.agent-tab.s-suspended { opacity: .6; }

/* L-C: notify toggle, lit when on */
#btn-notify.on { color: var(--teal); }

/* L-D: sidebar agent tree under an expanded workspace (click to focus; red dot = needs you) */
.ws-agents { list-style: none; margin: 1px 0 7px; padding: 0 0 0 26px; display: flex; flex-direction: column; gap: 1px; }
.ws-agent { display: flex; align-items: center; gap: 7px; padding: 3px 8px; border-radius: 6px; cursor: pointer; font-size: 12px; color: var(--muted); transition: background .12s ease, color .12s ease; }
.ws-agent:hover { background: rgba(255,255,255,.05); color: var(--text); }
.ws-agent.active { background: rgba(20,184,166,.12); color: var(--text); }
.ws-agent .wa-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* drag-and-drop upload dialog */
#upload-dialog { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(4,6,10,.6); backdrop-filter: blur(3px); }
#upload-dialog[hidden] { display: none; }
.ud-card { position: relative; width: min(460px, 92vw); background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 22px 22px 18px; box-shadow: 0 24px 70px rgba(0,0,0,.5); }
.ud-card h2 { margin: 0 0 6px; font-size: 18px; }
.ud-close { position: absolute; top: 12px; right: 14px; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; }
.ud-close:hover { color: var(--text); }
.ud-lead { color: var(--muted); font-size: 12.5px; line-height: 1.6; margin: 0 0 14px; }
.ud-drop { border: 1.5px dashed var(--line); border-radius: var(--radius-lg); padding: 26px 16px; text-align: center; color: var(--muted); transition: border-color .15s ease, background .15s ease; }
.ud-drop.over { border-color: var(--teal); background: rgba(20,184,166,.07); color: var(--text); }
.ud-ico { font-size: 26px; margin-bottom: 6px; }
.ud-or { font-size: 12px; margin-top: 8px; }
.ud-or button { background: none; border: none; color: var(--teal); cursor: pointer; text-decoration: underline; font-size: 12px; padding: 0; }
.ud-dest { display: block; margin: 14px 0 0; font-size: 12px; color: var(--muted); }
.ud-dest input { width: 100%; margin-top: 5px; }
.ud-status { min-height: 18px; margin: 12px 0 0; font-size: 12.5px; color: var(--teal); }

/* archive: a greyed-out archived (stopped) workspace + the orphaned-volumes panel */
.ws-item.archived { opacity: .5; }
.ws-item.archived .ws-name::after { content: ' · archived'; color: var(--dim); font-size: 10px; }
#archived-count { color: var(--dim); font-weight: 400; }
.ab-hint { font-size: 11px; color: var(--muted); margin: 5px 2px 8px; line-height: 1.55; }
#archived-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.ab-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 8px; border-radius: 7px; }
.ab-item:hover { background: rgba(255,255,255,.04); }
.ab-info { display: flex; flex-direction: column; min-width: 0; }
.ab-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ab-size { font-size: 10px; color: var(--dim); }
.ab-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.ab-actions button { background: var(--glass); border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer; }
.ab-actions button:hover { color: var(--text); border-color: var(--teal); }
.ab-empty { list-style: none; font-size: 11px; color: var(--dim); padding: 4px 8px; }

/* P0.7/P0.8 top banners (update available / connect-claude nudge) */
.top-banner { display: flex; align-items: center; gap: 10px; padding: 8px 14px; font-size: 13px;
  background: var(--panel); color: var(--text); border-bottom: 1px solid var(--line); }
.top-banner.update { background: rgba(20, 184, 166, 0.08); }
.top-banner.claude { background: rgba(245, 158, 11, 0.08); }
.top-banner a { color: var(--teal); }
.top-banner code { background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 4px; }
.top-banner .banner-go { margin-left: auto; }
.top-banner button { background: var(--glass-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 10px; cursor: pointer; font-size: 12px; }
.top-banner button:hover { border-color: var(--teal); }
.top-banner .banner-x { padding: 3px 8px; }
