:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-sunken: #f5f5f7;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --border: #e3e3e6;
  --border-strong: #d2d2d7;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --green: #34c759;
  --amber: #ff9f0a;
  --red: #ff3b30;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06), 0 1px 4px rgba(0, 0, 0, 0.04);
  --radius: 18px;
  --radius-sm: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 28px; }
.brand h1 { font-size: 19px; font-weight: 600; margin: 0; letter-spacing: -0.02em; }
.subtitle { margin: 2px 0 0; font-size: 12.5px; color: var(--text-tertiary); }
.conn-indicator { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--text-secondary); font-weight: 500; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-tertiary); }
.dot.muted { background: var(--text-tertiary); }
.dot.connecting { background: var(--amber); animation: pulse 1.2s infinite; }
.dot.ready { background: var(--green); box-shadow: 0 0 0 4px rgba(52, 199, 89, 0.16); }
.dot.error { background: var(--red); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---- layout ---- */
.layout {
  flex: 1; display: grid; grid-template-columns: 340px minmax(0, 1fr) 400px;
  gap: 20px; padding: 22px; min-height: 0;
  transition: grid-template-columns 0.36s cubic-bezier(0.4, 0, 0.2, 1);
}
.layout.collapse-left { grid-template-columns: 0px minmax(0, 1fr) 400px; }
.layout.collapse-right { grid-template-columns: 340px minmax(0, 1fr) 0px; }
.layout.collapse-left.collapse-right { grid-template-columns: 0px minmax(0, 1fr) 0px; }
.side-panel { transition: opacity 0.24s ease, transform 0.3s ease, padding 0.36s; }
.layout.collapse-left .left-panel { opacity: 0; transform: translateX(-12px); padding-left: 0; padding-right: 0; pointer-events: none; }
.layout.collapse-right .right-panel { opacity: 0; transform: translateX(12px); padding-left: 0; padding-right: 0; pointer-events: none; }

/* topbar toggles */
.topbar-right { display: flex; align-items: center; gap: 14px; }
.icon-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 30px; padding: 0; border-radius: 9px;
  background: transparent; color: var(--text-tertiary); border: none; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-toggle:hover { background: rgba(0, 0, 0, 0.05); color: var(--text-secondary); }
.icon-toggle.active { color: var(--accent); background: rgba(0, 113, 227, 0.1); }
.brand .icon-toggle { margin-right: 4px; }
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.panel h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-tertiary); font-weight: 600; margin: 0 0 14px;
}
.connect-panel { overflow-y: auto; }
.left-panel { overflow-y: auto; overflow-x: hidden; }

/* ---- forms ---- */
.form { display: flex; flex-direction: column; gap: 13px; margin-bottom: 24px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--text-secondary); font-weight: 500; }
.form input, .form select, textarea, .duo-panel input {
  background: var(--surface-sunken);
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; font-family: inherit;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.form input::placeholder, textarea::placeholder { color: var(--text-tertiary); }
.form input:focus, .form select:focus, textarea:focus, .duo-panel input:focus {
  outline: none; background: var(--surface);
  border-color: var(--accent); box-shadow: 0 0 0 3.5px rgba(0, 113, 227, 0.16);
}
.form .check { flex-direction: row; align-items: center; gap: 9px; color: var(--text); font-size: 12.5px; cursor: pointer; }
.form .check input, .pipeline-toggle input { accent-color: var(--accent); width: 15px; height: 15px; }
.hidden { display: none !important; }

/* ---- buttons ---- */
.btn-row { display: flex; gap: 10px; margin-top: 6px; }
button {
  border: none; background: var(--surface-sunken); color: var(--text);
  border-radius: 980px; padding: 10px 18px; font-size: 14px; font-weight: 500;
  cursor: pointer; font-family: inherit; transition: background 0.15s, opacity 0.15s, transform 0.05s;
}
button:hover:not(:disabled) { background: #ebebed; }
button:active:not(:disabled) { transform: scale(0.98); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.ghost { background: transparent; color: var(--accent); }
button.ghost:hover:not(:disabled) { background: rgba(0, 113, 227, 0.08); }
button.small { padding: 6px 12px; font-size: 12px; }
.danger-btn {
  width: 100%; margin-top: 10px; background: transparent; color: var(--red);
  border: 1px solid rgba(255, 59, 48, 0.35); border-radius: 980px;
}
.danger-btn:hover:not(:disabled) { background: rgba(255, 59, 48, 0.08); }

/* ---- Duo step ---- */
.duo-panel {
  background: #fff7ec; border: 1px solid #ffe2b8;
  border-radius: var(--radius-sm); padding: 18px; margin-bottom: 24px;
}
.duo-panel h2 { color: #b25e00; margin-top: 0; }
.duo-prompt {
  white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px; background: #fff; border: 1px solid #ffe2b8; padding: 10px; border-radius: 10px;
  margin: 0 0 12px; max-height: 180px; overflow: auto; color: #7a4a00; line-height: 1.5;
}
.duo-panel label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 10px; }
.duo-panel input { background: #fff; border: 1px solid #ffe2b8; letter-spacing: 2px; font-size: 15px; }
.duo-hint { font-size: 11.5px; color: var(--text-tertiary); margin: 10px 0 0; }

/* ---- pipeline ---- */
.pipeline { list-style: none; padding: 0; margin: 0 0 24px; display: flex; flex-direction: column; gap: 13px; }
.pipeline li { display: flex; align-items: center; gap: 12px; font-size: 13.5px; color: var(--text-tertiary); transition: color 0.2s; }
.step-dot { width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--border-strong); flex: none; transition: all 0.2s; }
.pipeline li.active { color: var(--text); font-weight: 500; }
.pipeline li.active .step-dot { border-color: var(--amber); background: var(--amber); box-shadow: 0 0 0 4px rgba(255, 159, 10, 0.16); }
.pipeline li.done { color: var(--text); }
.pipeline li.done .step-dot { border-color: var(--green); background: var(--green); }
.pipeline li.failed .step-dot { border-color: var(--red); background: var(--red); }

/* ---- GPU card ---- */
.gpu-card { background: var(--surface-sunken); border-radius: var(--radius-sm); padding: 16px; }
.gpu-card.empty { color: var(--text-tertiary); }
.gpu-name { font-size: 13.5px; font-weight: 600; }
.gpu-meta { font-size: 11.5px; color: var(--text-tertiary); margin: 4px 0 12px; }
.meter { height: 7px; background: #e3e3e6; border-radius: 4px; overflow: hidden; margin-top: 8px; }
.meter-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 4px; transition: width 0.5s ease; }
.meter-fill.mem { background: var(--green); }
.meter-label { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-secondary); margin-top: 5px; }

/* ---- chat ---- */
.chat-panel { min-width: 0; }
.chat-panel h2 small { color: var(--accent); text-transform: none; letter-spacing: 0; margin-left: 8px; font-weight: 500; font-size: 12px; }
.chat-stream { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-right: 8px; }
.empty-hint { color: var(--text-tertiary); font-size: 14px; margin: auto; text-align: center; max-width: 320px; line-height: 1.5; }
.msg { max-width: 88%; padding: 12px 16px; border-radius: 20px; font-size: 14.5px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--surface-sunken); color: var(--text); border-bottom-left-radius: 6px; }
.msg.assistant strong { font-weight: 600; }
.msg.assistant h2, .msg.assistant h3 { color: var(--text); font-size: 15px; font-weight: 600; margin: 14px 0 6px; letter-spacing: -0.01em; }
.msg.assistant code { background: rgba(0, 0, 0, 0.06); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.artifacts-block { align-self: flex-start; max-width: 88%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.artifacts-block .artifacts-title { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; margin-bottom: 8px; }
.artifacts-block a { display: flex; align-items: baseline; gap: 6px; color: var(--accent); text-decoration: none; font-size: 13.5px; padding: 4px 0; font-weight: 500; }
.artifacts-block a:hover { text-decoration: underline; }
.artifacts-block a span { color: var(--text-tertiary); font-size: 11.5px; font-weight: 400; }
.artifact-bundle {
  display: inline-flex !important; align-items: center; margin: 2px 0 8px; padding: 8px 14px;
  background: var(--accent); color: #fff !important; border-radius: 980px; font-size: 13px; font-weight: 600;
}
.artifact-bundle:hover { background: var(--accent-hover); text-decoration: none !important; }

.chat-controls { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.pipeline-toggle { display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--text-tertiary); line-height: 1.4; }
.dataset-input {
  flex: 1; min-width: 160px; background: var(--surface-sunken); border: 1px solid transparent; color: var(--text);
  border-radius: 980px; padding: 7px 14px; font-size: 12px; font-family: inherit;
}
.dataset-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3.5px rgba(0, 113, 227, 0.16); }
.workflow-select {
  background: var(--surface-sunken); border: 1px solid transparent; color: var(--text);
  border-radius: 980px; padding: 7px 14px; font-size: 12.5px; font-family: inherit; cursor: pointer; font-weight: 500;
}
.workflow-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3.5px rgba(0, 113, 227, 0.16); }
/* The plan/clarify render AS a chat message (plan.md style) that stands out from a
   normal assistant bubble with a blue tint + accent border, and carries inline actions. */
.plan-card { border: 1px solid rgba(0, 113, 227, 0.3); background: rgba(0, 113, 227, 0.06); max-width: 92%; }
.plan-card .plan-actions-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 13px; }
.plan-actions-hint { font-size: 12px; color: var(--text-secondary); }
.plan-actions-status { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.plan-card .clarify-q { margin-top: 10px; }
/* Clarify: option chips + a custom answer via the composer. */
.plan-clarify { display: flex; flex-direction: column; gap: 12px; }
.clarify-q { display: flex; flex-direction: column; gap: 7px; }
.clarify-question { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.clarify-options { display: flex; flex-wrap: wrap; gap: 8px; }
.clarify-chip {
  font: inherit; font-size: 12.5px; cursor: pointer;
  padding: 6px 13px; border-radius: 999px;
  background: #fff; border: 1px solid rgba(0, 113, 227, 0.35); color: var(--accent);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.clarify-chip:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.preset-panel {
  margin-top: 10px; padding: 12px 14px; border-radius: 12px;
  background: var(--surface-sunken); border: 1px solid var(--border);
}
.preset-hint { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 8px; }
/* Axis A — the "Advanced" disclosure that hides the skill override (the PI chooses by default). */
.advanced-panel { margin-top: 10px; }
.advanced-panel > summary {
  cursor: pointer; font-size: 12.5px; color: var(--text-secondary);
  list-style: none; user-select: none; padding: 2px 0; width: fit-content;
}
.advanced-panel > summary::-webkit-details-marker { display: none; }
.advanced-panel > summary::before { content: "▸ "; color: var(--text-tertiary); }
.advanced-panel[open] > summary::before { content: "▾ "; }
.advanced-panel > summary:hover { color: var(--text-primary); }
.preset-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.preset-prompt {
  width: 100%; box-sizing: border-box; resize: vertical; min-height: 110px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 9px 11px; font-size: 13px; line-height: 1.55; font-family: inherit;
}
.preset-prompt:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3.5px rgba(0, 113, 227, 0.16); }
.chat-input { display: flex; gap: 10px; margin-top: 10px; }
.chat-input textarea { flex: 1; resize: none; border-radius: 14px; }
.chat-input button { align-self: stretch; }
/* The Send/Stop action is a fixed-width pill — never let the shared full-width
   `.danger-btn` rule stretch Stop across the row and crush the input box. */
.chat-input #chatSend, .chat-input #chatStop { flex: none; width: auto; min-width: 92px; margin-top: 0; }

/* downloads (right panel) */
.downloads { display: flex; flex-direction: column; gap: 5px; max-height: 38%; overflow-y: auto; margin-bottom: 20px; }
.downloads-empty { color: var(--text-tertiary); font-size: 12.5px; line-height: 1.5; }
.dl-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 11px; border-radius: 10px;
  background: var(--surface-sunken); color: var(--text); text-decoration: none; font-size: 13px;
}
.dl-item:hover { background: #ebebed; }
.dl-name { color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- log ---- */
.right-panel { overflow: hidden; }
.log-panel { min-width: 0; }
.log-head { display: flex; justify-content: space-between; align-items: center; }
.log-stream { flex: 1; overflow-y: auto; font-size: 12px; display: flex; flex-direction: column; gap: 6px; }
.log-entry {
  padding: 9px 12px; border-radius: 10px; background: var(--surface-sunken);
  border-left: 3px solid var(--border-strong);
}
.log-entry .meta { color: var(--text-tertiary); font-size: 10.5px; margin-bottom: 3px; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.log-entry > div:last-child { color: var(--text); line-height: 1.45; }
.log-entry.info { border-left-color: var(--accent); }
.log-entry.step { border-left-color: var(--text-tertiary); }
.log-entry.stream { border-left-color: var(--border-strong); opacity: 0.8; }
.log-entry.success { border-left-color: var(--green); }
.log-entry.warning { border-left-color: var(--amber); background: #fff7ec; }
.log-entry.error { border-left-color: var(--red); background: #fff0ef; }
.log-entry .detail-toggle { color: var(--accent); cursor: pointer; font-size: 11.5px; margin-top: 5px; display: inline-block; font-weight: 500; }
.log-entry pre {
  white-space: pre-wrap; word-break: break-word; background: #fff; border: 1px solid var(--border);
  padding: 10px; border-radius: 8px; margin: 7px 0 0; max-height: 260px; overflow: auto;
  color: #b3261e; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px;
}

/* ---- storage modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.28); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md); width: min(560px, 92vw); max-height: 82vh; overflow-y: auto; padding: 22px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.storage-base { font-size: 12px; color: var(--text-tertiary); font-family: ui-monospace, "SF Mono", Menlo, monospace; margin-bottom: 8px; word-break: break-all; }
.storage-used { font-size: 13.5px; color: var(--text-secondary); margin-bottom: 10px; }
.storage-used strong { color: var(--text); }
.storage-quota { background: var(--surface-sunken); border-radius: 10px; padding: 10px; font-size: 11.5px; color: var(--text-secondary); white-space: pre-wrap; word-break: break-word; margin: 0 0 14px; max-height: 120px; overflow: auto; }
.storage-items { display: flex; flex-direction: column; gap: 6px; }
.storage-loading, .storage-empty { color: var(--text-tertiary); font-size: 13px; padding: 8px 0; }
.storage-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface-sunken); }
.storage-item .si-name { flex: 1; font-size: 13px; word-break: break-all; }
.storage-item .si-size { font-size: 12px; color: var(--text-tertiary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.storage-item .si-del { padding: 5px 12px; border-radius: 980px; font-size: 12px; background: transparent; color: var(--red); border: 1px solid rgba(255, 59, 48, 0.35); }
.storage-item .si-del:hover { background: rgba(255, 59, 48, 0.1); }
.ghost.small.danger { color: var(--red); border-color: rgba(255, 59, 48, 0.35); }
.ghost.small.danger:hover { background: rgba(255, 59, 48, 0.1); }
.storage-note { font-size: 11.5px; color: var(--text-tertiary); margin: 14px 0 0; line-height: 1.5; }
.storage-note code { background: var(--surface-sunken); padding: 1px 5px; border-radius: 4px; }

/* ---- toast ---- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(30, 30, 32, 0.92); backdrop-filter: blur(20px); color: #fff;
  padding: 12px 20px; border-radius: 14px; font-size: 13.5px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: var(--shadow-md);
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #c7c7cc; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b0b0b5; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* full-width buttons + inline hints */
button.full { width: 100%; margin-top: 6px; }
.hint-inline { color: var(--text-tertiary); font-weight: 400; font-size: 11px; margin-left: 6px; }

/* compact connected card */
.conn-card { background: var(--surface-sunken); border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 14px; }
.conn-card-top { display: flex; align-items: center; gap: 10px; }
.conn-card-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(52, 199, 89, 0.16); flex: none; }
.conn-card-id { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.conn-card-id strong { font-size: 14px; font-weight: 600; }
.conn-card-id span { font-size: 12px; color: var(--text-tertiary); }
.conn-gpu { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-secondary); margin-top: 11px; }
.gpu-pill { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.gpu-pill.ok { background: var(--green); }
.gpu-pill.bad { background: var(--red); }

/* model selector (connected card) */
.model-row { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--text-secondary); font-weight: 500; margin-bottom: 12px; }
.model-row-controls { display: flex; gap: 8px; align-items: stretch; }
.model-row select {
  flex: 1; background: var(--surface-sunken); border: 1px solid transparent; color: var(--text);
  border-radius: 10px; padding: 9px 11px; font-size: 13.5px; font-family: inherit; cursor: pointer;
}
.model-row select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3.5px rgba(0, 113, 227, 0.16); }
.model-row .icon-btn { flex: none; }

/* sessions sidebar (ChatGPT-style) */
.sessions { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 18px; }
.sessions-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sessions-head h2 { margin: 0; }
.icon-btn {
  width: 28px; height: 28px; padding: 0; border-radius: 8px; font-size: 18px; line-height: 1;
  background: var(--surface-sunken); color: var(--text-secondary); display: inline-flex;
  align-items: center; justify-content: center;
}
.icon-btn:hover { background: #ebebed; color: var(--accent); }
.session-list { display: flex; flex-direction: column; gap: 3px; }
.session-empty { color: var(--text-tertiary); font-size: 12.5px; padding: 6px 2px; }
.session-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 11px; border-radius: 10px;
  cursor: pointer; transition: background 0.12s;
}
.session-item:hover { background: var(--surface-sunken); }
.session-item.active { background: rgba(0, 113, 227, 0.1); }
.session-item.active .session-title { color: var(--accent); font-weight: 500; }
.session-title { flex: 1; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-del {
  width: 22px; height: 22px; padding: 0; border-radius: 6px; font-size: 12px; flex: none;
  background: transparent; color: var(--text-tertiary); opacity: 0; transition: opacity 0.12s, background 0.12s;
}
.session-item:hover .session-del { opacity: 1; }
.session-del:hover { background: rgba(255, 59, 48, 0.12); color: var(--red); }

/* chat header */
.chat-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.chat-head h2 {
  margin: 0; font-size: 16px; font-weight: 600; text-transform: none; letter-spacing: -0.01em; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-head small { color: var(--accent); font-size: 12px; font-weight: 500; flex: none; }

@media (max-width: 1100px) {
  .layout, .layout.collapse-left, .layout.collapse-right { grid-template-columns: 1fr; grid-auto-rows: minmax(280px, auto); overflow-y: auto; }
}

/* streamed model thinking (Qwen3) — a subtle collapsible box above the answer */
.msg.assistant .think {
  background: #f5f5f7; border: 1px solid #e5e5ea; border-radius: 10px;
  padding: 6px 10px; margin-bottom: 8px; font-size: 13px; color: #6e6e73;
}
.msg.assistant .think summary { cursor: pointer; user-select: none; list-style: none; outline: none; }
.msg.assistant .think summary::-webkit-details-marker { display: none; }
.msg.assistant .think .think-body {
  white-space: pre-wrap; margin-top: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  line-height: 1.45; max-height: 240px; overflow-y: auto;
}

/* --- live key-progress feed (lab runs) --- */
.msg.assistant .lab-progress {
  display: flex; flex-direction: column; gap: 3px;
  margin-bottom: 8px; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--border, #e5e5ea);
  border-radius: 10px; font-size: 13px; line-height: 1.4;
}
.msg.assistant .lab-progress.done { opacity: 0.7; }
.msg.assistant .lab-progress .progress-line {
  color: var(--text); animation: progress-in 0.2s ease;
}
.msg.assistant .lab-progress .progress-line:last-child:not(.sub) { font-weight: 500; }
.msg.assistant .lab-progress.done .progress-line:last-child { font-weight: 400; }
.msg.assistant .lab-progress .progress-line.sub {
  color: var(--text-secondary); font-size: 12px; padding-left: 14px;
}
.msg.assistant .lab-progress .progress-line.success { color: var(--green); }
.msg.assistant .lab-progress .progress-line.warning { color: var(--amber); }
@keyframes progress-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

/* --- artifacts file grid + preview modal --- */
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 10px; }
.file-grid-title { grid-column: 1 / -1; color: var(--text-tertiary); font-size: 12px; margin: 6px 0 2px; }
.file-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; background: var(--surface); border: 1px solid var(--border, #e5e5e8); border-radius: 8px; cursor: pointer; overflow: hidden; }
.file-cell:hover { background: #ebebed; }
.file-cell img { width: 100%; height: 56px; object-fit: cover; border-radius: 4px; background: #f4f4f6; }
.file-cell .file-icon { font-size: 30px; height: 56px; display: flex; align-items: center; }
.file-cell-name { font-size: 10.5px; line-height: 1.2; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }

/* --- file area: thumbnails on top, folder-grouped directory list below --- */
.file-area { margin-top: 10px; }
.artifacts-hint { color: var(--text-tertiary); font-size: 12px; margin-top: 6px; line-height: 1.4; }
.file-folder { margin-top: 8px; border: 1px solid var(--border, #e5e5ea); border-radius: 8px; overflow: hidden; }
.file-folder > summary { cursor: pointer; user-select: none; list-style: none; padding: 7px 10px; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); background: var(--surface-sunken); }
.file-folder > summary::-webkit-details-marker { display: none; }
.file-folder-count { color: var(--text-tertiary); font-weight: 400; font-size: 11.5px; margin-left: 4px; }
.file-row { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 10px; background: var(--surface); border: 0; border-top: 1px solid var(--border, #eee); cursor: pointer; text-align: left; font-size: 12.5px; }
.file-row:hover { background: #ebebed; }
.file-row-icon { flex: 0 0 auto; }
.file-row-name { flex: 1 1 auto; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row-size { flex: 0 0 auto; color: var(--text-tertiary); font-size: 11px; }
.preview-card { width: min(900px, 94vw); max-height: 88vh; }
.preview-actions { display: flex; align-items: center; gap: 10px; }
.preview-body { max-height: 74vh; overflow: auto; display: flex; justify-content: center; }
.preview-img { max-width: 100%; height: auto; }
.preview-frame { width: 100%; height: 70vh; border: 0; }
.preview-text { width: 100%; white-space: pre-wrap; word-break: break-word; font-size: 12px; line-height: 1.5; text-align: left; background: #f7f7f8; padding: 12px; border-radius: 6px; }

/* ===== Phase 1: login + operon-style shell + 5 views ===== */

/* login overlay */
.login-overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #eaf2ff 0%, var(--bg) 60%);
}
.login-card {
  width: 380px; max-width: 92vw; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 32px 30px;
}
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.login-sub { margin: 6px 0 22px; color: var(--text-tertiary); font-size: 13px; }
.login-error { color: var(--red); font-size: 13px; margin: 4px 0 0; }
.login-foot { margin: 18px 0 0; font-size: 12px; color: var(--text-tertiary); line-height: 1.5; }

/* --- reattach hint: shown on the connect screen after a gateway restart --- */
.reattach-hint { position: relative; margin: 0 0 16px; padding: 11px 30px 11px 12px; background: rgba(52, 199, 89, 0.10); border: 1px solid rgba(52, 199, 89, 0.35); border-radius: 10px; font-size: 12.5px; line-height: 1.5; color: var(--text); }
.reattach-hint code { background: rgba(0, 0, 0, 0.06); padding: 1px 5px; border-radius: 5px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11.5px; }
.reattach-dismiss { position: absolute; top: 6px; right: 8px; background: transparent; border: 0; color: var(--text-tertiary); font-size: 17px; line-height: 1; cursor: pointer; padding: 2px 4px; }
.reattach-dismiss:hover { color: var(--text-secondary); }

/* app shell: topbar + (nav rail | views) */
.app-shell { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.shell-body { flex: 1; display: flex; min-height: 0; }
.user-chip {
  font-size: 12.5px; font-weight: 600; color: var(--text-secondary);
  background: var(--surface-sunken); border: 1px solid var(--border); border-radius: 980px; padding: 5px 12px;
}

/* operon-style activity bar */
.nav-rail {
  flex: 0 0 92px; display: flex; flex-direction: column; gap: 4px; padding: 14px 8px;
  background: var(--surface); border-right: 1px solid var(--border);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 11px 4px;
  border: none; background: none; border-radius: var(--radius-sm); cursor: pointer; color: var(--text-tertiary);
  font: inherit; transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface-sunken); color: var(--text-secondary); }
.nav-item.active { background: rgba(0, 113, 227, 0.10); color: var(--accent); }
.nav-ico { font-size: 20px; line-height: 1; }
.nav-label { font-size: 11px; font-weight: 600; }

/* views */
.views { flex: 1; display: flex; min-height: 0; }
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; flex-direction: column; min-height: 0; }
.view#view-research.active .layout { flex: 1; }

/* page-style views (datasets/runs/admin/account) */
.page { flex: 1; overflow-y: auto; padding: 26px 32px; max-width: 1100px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 600; }
.page-sub { color: var(--text-tertiary); font-size: 13px; margin: 6px 0 18px; }
.page h3 { font-size: 15px; font-weight: 600; margin: 26px 0 10px; }
.muted { color: var(--text-tertiary); }
.ok { color: var(--green); font-weight: 600; }
.bad { color: var(--red); font-weight: 600; }

/* card lists (datasets, runs) */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px;
}
.card-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.card-main strong { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-main .muted { font-size: 12px; }

/* run artifacts panel */
.run-artifacts { margin-top: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; }
.run-art-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

/* admin table + create-user form */
.create-user { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.create-user input, .create-user select {
  background: var(--surface-sunken); border: 1px solid var(--border); border-radius: 980px;
  padding: 7px 13px; font: inherit; font-size: 13px; color: var(--text);
}
.create-user input:focus, .create-user select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3.5px rgba(0, 113, 227, 0.16); }
.user-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.user-table th, .user-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.user-table th { color: var(--text-tertiary); font-weight: 600; font-size: 12px; }
.row-actions { display: flex; gap: 6px; }

/* account view */
.account-info { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px 18px; }
.account-info p { margin: 4px 0; font-size: 14px; }
.form.narrow { max-width: 360px; }

/* ===== System page (agents / tools / capabilities / roadmap) ===== */
.cap-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.cap { font-size: 12px; font-weight: 600; border-radius: 980px; padding: 4px 11px; border: 1px solid var(--border); }
.cap.on { color: #1a7f37; background: rgba(52,199,89,0.12); border-color: rgba(52,199,89,0.35); }
.cap.off { color: var(--text-tertiary); background: var(--surface-sunken); }
.sys-cat { margin-bottom: 14px; }
.sys-cat h4 { margin: 12px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-tertiary); }
.sys-desc { font-size: 12.5px; color: var(--text-secondary); line-height: 1.45; }
.tag-priv { font-size: 10.5px; font-weight: 600; color: #b25e00; background: rgba(255,159,10,0.14); border-radius: 980px; padding: 1px 7px; vertical-align: middle; }
.roadmap { display: flex; flex-direction: column; gap: 7px; }
.road-row { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.road-badge { font-size: 11px; font-weight: 700; border-radius: 980px; padding: 3px 10px; min-width: 72px; text-align: center; }
.road-badge.done { color: #1a7f37; background: rgba(52,199,89,0.14); }
.road-badge.in_progress { color: #8a5a00; background: rgba(255,159,10,0.16); }
.road-badge.planned { color: var(--text-tertiary); background: var(--surface-sunken); }

/* workflow presets */
.card.flow { align-items: flex-start; }
.flow-kind { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--accent); background: rgba(0,113,227,0.10); border-radius: 980px; padding: 1px 8px; vertical-align: middle; }
.flow-stages { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.flow-stage { font-size: 11.5px; font-weight: 600; color: var(--text-secondary);
  background: var(--surface-sunken); border: 1px solid var(--border); border-radius: 8px; padding: 3px 9px; }
.flow-arrow { color: var(--text-tertiary); font-size: 12px; }

/* --- System: live workflow graph (read-only) --- */
.sys-graph-h { margin: 18px 0 8px; font-size: 14px; font-weight: 600; }
.sys-graph-h .muted { font-weight: 400; font-size: 12px; }
.sys-graph-wrap { display: flex; gap: 12px; margin-bottom: 22px; }
.sys-graph {
  flex: 1 1 auto; min-width: 0; height: 440px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
}
.sys-graph-info {
  flex: 0 0 280px; width: 280px; height: 440px; overflow: auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); box-shadow: var(--shadow-sm);
  padding: 14px; font-size: 13px; line-height: 1.5;
}
.sys-graph-info > div { margin-bottom: 6px; }
.gi-title { font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.gi-type { font-size: 10.5px; color: var(--text-tertiary); border: 1px solid var(--border-strong); border-radius: 980px; padding: 1px 8px; margin-left: 4px; font-weight: 500; }
.gi-k { display: inline-block; min-width: 62px; color: var(--text-tertiary); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.02em; }
.gi-desc { margin-top: 10px; color: var(--text-secondary); }
@media (max-width: 720px) { .sys-graph-wrap { flex-direction: column; } .sys-graph-info { flex-basis: auto; width: auto; height: auto; max-height: 240px; } }

/* ===== micro-interactions: subtle Apple-style hover lift / press ===== */
:root { --ease-spring: cubic-bezier(0.2, 0.8, 0.2, 1); }

/* shared smooth transition for the interactive surfaces */
button, .clarify-chip, .artifact-bundle, .workflow-select, .nav-item,
.card, .conn-card, .gpu-card, .dl-item, .session-item, .artifacts-block {
  transition: background 0.18s var(--ease-spring), color 0.18s var(--ease-spring),
              transform 0.18s var(--ease-spring), box-shadow 0.18s var(--ease-spring),
              border-color 0.18s var(--ease-spring), opacity 0.18s var(--ease-spring);
}

/* buttons grow a hair on hover and press in on click */
button:not(:disabled):hover { transform: translateY(-1px) scale(1.03); }
button:not(:disabled):active { transform: scale(0.97); }
button.primary:not(:disabled):hover { box-shadow: 0 6px 18px rgba(0, 113, 227, 0.28); }
/* full-width buttons lift but do NOT scale (scaling would overflow their container) */
button.full:not(:disabled):hover, .danger-btn:not(:disabled):hover,
.chat-input button:not(:disabled):hover { transform: translateY(-1px) scale(1); }
.clarify-chip:hover { transform: translateY(-1px) scale(1.04); }
/* the selected nav item stays put — only idle items react */
.nav-item.active, .nav-item.active:hover { transform: none; }

/* cards / list rows / tooltips lift and deepen their shadow on hover */
.card:hover, .conn-card:hover, .gpu-card:hover, .artifacts-block:hover {
  transform: translateY(-2px); box-shadow: var(--shadow-md);
}
.dl-item:hover, .session-item:hover { transform: translateY(-1px); }

/* file thumbnails: card lifts, image zooms gently inside it */
.file-cell { transition: transform 0.2s var(--ease-spring), background 0.18s var(--ease-spring), box-shadow 0.2s var(--ease-spring); }
.file-cell:hover { transform: translateY(-2px) scale(1.02); box-shadow: var(--shadow-sm); }
.file-cell img { transition: transform 0.25s var(--ease-spring); }
.file-cell:hover img { transform: scale(1.05); }

/* the active pipeline step gently breathes so the eye lands on it */
.pipeline li.active .step-dot { animation: stepBreathe 1.8s ease-in-out infinite; }
@keyframes stepBreathe {
  0%, 100% { box-shadow: 0 0 0 4px rgba(255, 159, 10, 0.16); }
  50%      { box-shadow: 0 0 0 7px rgba(255, 159, 10, 0.07); }
}

/* ===== entrance motion: views, messages, panels glide in instead of snapping =====
   View switches and newly-rendered content used to appear instantly (felt abrupt). A
   short fade-up on each gives the UI a continuous, considered feel. Fill-mode is left
   at default on the big containers so no lingering transform traps position:fixed
   descendants (toast / modal) after the animation ends. */
@keyframes viewIn   { from { opacity: 0; transform: translateY(8px); }            to { opacity: 1; transform: translateY(0); } }
@keyframes msgIn    { from { opacity: 0; transform: translateY(7px) scale(0.99); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes panelIn  { from { opacity: 0; transform: translateY(-6px); }           to { opacity: 1; transform: translateY(0); } }

.view.active { animation: viewIn 0.34s var(--ease-spring); }
.msg         { animation: msgIn 0.3s var(--ease-spring); }
.preset-panel:not(.hidden), .duo-panel:not(.hidden) {
  animation: panelIn 0.28s var(--ease-spring);
}

/* hover lift made a touch more legible (the previous 1.03 read as "nothing happened") */
button:not(:disabled):hover { transform: translateY(-1px) scale(1.045); }
.card:hover, .conn-card:hover, .gpu-card:hover, .artifacts-block:hover {
  transform: translateY(-3px); box-shadow: var(--shadow-md);
}
/* idle nav items nudge toward their label on hover so the sidebar feels responsive */
.nav-item:not(.active):hover { transform: translateX(2px); }

/* accessibility: honour reduced-motion — drop the transforms and loops */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  button:hover, .card:hover, .conn-card:hover, .gpu-card:hover, .artifacts-block:hover,
  .dl-item:hover, .session-item:hover, .file-cell:hover, .file-cell:hover img,
  .clarify-chip:hover, .nav-item:not(.active):hover { transform: none !important; }
}
