/* ============================================================
   LAYOUT — App shell, nav sidebar, view container
   Responsibility: main structural layout ONLY
   (component styles remain in base.css / panels.css / files.css)
   ============================================================ */

/* ── App shell ──────────────────────────────────────────────── */
#app-shell {
  display: none;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* ── Header ─────────────────────────────────────────────────── */
#app-header {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  z-index: 200;
  position: relative;
}

.header-left {
  display: flex;
  align-items: center;
  height: 100%;
}

.nav-toggle-btn {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.nav-toggle-btn:hover { background: var(--bg-hover); color: var(--text); }
.nav-toggle-btn svg { width: 18px; height: 18px; }

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  padding: 0 14px;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.header-logo:hover { opacity: 0.8; }
.header-logo .logo-icon { color: var(--accent); font-size: 16px; }

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 12px;
}

/* ── App body ────────────────────────────────────────────────── */
#app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Navigation sidebar ──────────────────────────────────────── */
#app-nav {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width 0.2s ease;
  z-index: 90;
}
#app-nav.collapsed { width: 52px; }

.nav-section {
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  gap: 1px;
}
.nav-section.nav-bottom {
  padding-bottom: 12px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 7px;
  margin: 0 5px;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.1s, color 0.1s;
  font-family: var(--font);
  position: relative;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active {
  background: var(--accent-subtle, rgba(99,102,241,0.12));
  color: var(--accent);
  font-weight: 600;
}

.nav-item-icon {
  font-size: 14px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
  line-height: 1;
}
.nav-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  transition: opacity 0.15s;
}

/* Collapsed state */
#app-nav.collapsed .nav-item { padding: 10px 0; justify-content: center; }
#app-nav.collapsed .nav-item-label { display: none; }
#app-nav.collapsed .nav-item-icon { width: auto; }

/* Badge on nav item (memory count, debug count) */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 8px;
  flex-shrink: 0;
  margin-left: auto;
}
#app-nav.collapsed .nav-badge { display: none; }

/* ── Views container ─────────────────────────────────────────── */
#app-views {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

.app-view {
  display: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.app-view.active { display: flex; }

/* ── Chat view: sessions sidebar + chat main ─────────────────── */
#view-chat { flex-direction: row; }
/* .chat-layout and .sidebar kept as-is inside view-chat */

/* ── Generic scrollable view content ─────────────────────────── */
.view-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.view-header { flex-shrink: 0; }
.view-title  { font-size: 20px; font-weight: 700; margin: 0 0 4px 0; }
.view-subtitle { font-size: 13px; color: var(--text-muted); margin: 0; }

/* ── Files view ──────────────────────────────────────────────── */
#view-files { flex-direction: column; }
.files-view-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* ── Agents view ─────────────────────────────────────────────── */
#view-agents { flex-direction: column; overflow: hidden; }

/* ---- Grid state ---- */
.agents-grid-state {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  padding: 24px 28px;
}
.agents-view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 22px;
  flex-shrink: 0;
  gap: 12px;
}
.agents-view-header > div { flex: 1; }
.btn-sm { padding: 7px 14px; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  overflow-y: auto;
  flex: 1;
  align-content: start;
}
.agent-grid-card {
  padding: 18px 18px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-input);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  user-select: none;
}
.agent-grid-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
}
.agent-grid-card:active { transform: scale(0.98); }
.agent-grid-card-avatar {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
  flex-shrink: 0;
}
.agent-grid-card-name  { font-size: 14px; font-weight: 600; color: var(--text); }
.agent-grid-card-role  { font-size: 11px; color: var(--accent); font-weight: 500; }
.agent-grid-card-meta  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.agent-grid-card-status { position: absolute; top: 14px; right: 14px; }

/* ---- Detail state: single scrollable column of sections ---- */
.agents-detail-state {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
/* Single scrollable column that holds all agent-detail sections */
.agents-detail-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
/* Each section: stacks naturally, collapsed body is hidden */
.adet-section {
  border-bottom: 1px solid var(--border);
}
.adet-body {
  /* visible by default; JS sets display:none when collapsed */
}
.adet-inner {
  padding: 16px 18px;
}
/* Memory body: cap height so it doesn't eat the whole page */
.adet-memory-body {
  max-height: 480px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.agents-detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-card);
}
.agents-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.12s, color 0.12s;
}
.agents-back-btn:hover { background: var(--bg-hover); color: var(--text); }
.agents-detail-title-input {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  padding: 2px 6px;
  margin: 0 2px;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.adet-delete-btn { color: var(--text-muted); }
.adet-delete-btn:hover { color: #e05252; background: rgba(224,82,82,0.1); }
.adet-duplicate-btn { color: var(--text-muted); }
.adet-duplicate-btn:hover { color: var(--accent); background: rgba(var(--accent-rgb,99,102,241),0.1); }
/* Default agent badge (grid card + detail label) */
.agent-grid-default-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 4px;
  padding: 1px 5px;
  margin-top: 4px;
}
.agent-default-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: middle;
}
/* Readonly inline input (default agent name) */
.adet-inline-input.adet-readonly {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  cursor: default;
  pointer-events: none;
}
/* Description textarea in info section */
.adet-inline-textarea {
  background: var(--bg-input, var(--surface));
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  line-height: 1.5;
  padding: 4px 8px;
  width: 100%;
  min-height: 64px;
  max-height: 160px;
  resize: vertical;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s;
}
.adet-inline-textarea:focus { border-color: var(--accent); }
.adet-inline-textarea::placeholder { color: var(--text-muted); font-style: italic; }
/* Generate description button */
.adet-gen-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  opacity: 0.7;
}
.adet-gen-btn:hover { opacity: 1; }
/* Save / Cancel bar at bottom of info section */
.adet-save-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
  padding-top: 10px;
  margin-top: 6px;
  border-top: 1px solid var(--border);
}
.adet-save-status {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
}
/* Info rows inside adet-inner */
.agent-info-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
}
.agent-info-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}
.agent-info-value {
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
}
.agent-info-value.mono { font-family: var(--mono, monospace); font-size: 11px; }
.agent-info-divider { height: 1px; background: var(--border); margin: 8px 0; }
.agent-info-hint {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: 2px;
}
/* Editable role inline input inside an info row */
.adet-inline-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  padding: 2px 6px;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.adet-inline-input:hover { border-color: var(--border); }
.adet-inline-input:focus { border-color: var(--accent); background: var(--bg-input, var(--surface)); }
.adet-inline-input::placeholder { color: var(--text-muted); font-style: italic; }
/* Custom prompt toggle */
.adet-prompt-toggle-row { margin-bottom: 4px; }
.adet-toggle-label {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  user-select: none;
}
.adet-toggle-label input[type=checkbox] {
  cursor: pointer;
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
/* Custom prompt textarea */
.adet-prompt-textarea {
  width: 100%;
  min-height: 110px;
  max-height: 280px;
  resize: vertical;
  background: var(--bg-input, var(--surface));
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  line-height: 1.5;
  padding: 9px 12px;
  box-sizing: border-box;
  margin-top: 6px;
  display: block;
}
.adet-prompt-textarea:focus { border-color: var(--accent); outline: none; }
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-input);
  border-radius: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  max-height: 160px;
  overflow-y: auto;
  margin-top: 4px;
}
/* Memory body */
.memory-panel-body { flex: 1; overflow-y: auto; }

/* ---- Capabilities / tools section ---- */
.agent-caps-header-actions { display: flex; gap: 4px; }
.btn-xs {
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 6px;
  line-height: 1.3;
}
.agent-caps-list {
  display: flex;
  flex-direction: column;
}
/* Capability group headers (collapsible) */
.agent-cap-group { flex-shrink: 0; }
.agent-cap-group-hdr {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  margin: 4px -18px 0;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border-top: 1px solid var(--border);
  user-select: none;
  transition: background 0.1s, color 0.1s;
  flex-shrink: 0;
}
.agent-cap-group-hdr:hover { background: var(--bg-hover); color: var(--text); }
.agent-cap-group-label { flex: 1; }
.agent-cap-group-body { padding: 2px 0 4px; }
.agent-cap-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}
.agent-cap-item:hover { background: var(--bg-hover); }
.agent-cap-item input[type="checkbox"] { accent-color: var(--accent); width: 13px; height: 13px; flex-shrink: 0; cursor: pointer; margin-top: 2px; }
.agent-cap-label { font-size: 12px; color: var(--text); flex: 1; line-height: 1.45; }
.agent-cap-desc { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.agent-caps-save-row {
  min-height: 18px;
  margin-top: 6px;
  display: flex;
  align-items: center;
}
.agent-caps-saved-label {
  font-size: 11px;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.4s;
}
.agent-caps-saved-label.visible { opacity: 1; }

/* ---- Create agent modal ---- */
.agent-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(2px);
}
.agent-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px 28px 22px;
  width: 380px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.3);
}
.agent-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.agent-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}
.agent-create-error {
  font-size: 12px;
  color: var(--error, #f87171);
  min-height: 16px;
}

/* ── Settings view ───────────────────────────────────────────── */
#view-settings { flex-direction: column; overflow: hidden; }
.settings-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}
.settings-sidebar {
  width: 180px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  overflow-y: auto;
}
.settings-sidebar-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
  padding: 0 16px 10px;
}
.stab-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.stab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.12s, color 0.12s;
}
.stab:hover { background: var(--bg-hover); color: var(--text); }
.stab.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.settings-content {
  flex: 1;
  overflow-y: auto;
  position: relative;
}
.stab-pane {
  display: none;
  padding: 28px 32px;
  max-width: 720px;
}
.stab-pane.active { display: block; }
.stab-pane-actions {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 12px 0;
  margin-top: 20px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
/* Theme swatches */
.theme-swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.theme-card {
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid var(--border);
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
  background: var(--bg-card);
}
.theme-card:hover { transform: translateY(-2px); border-color: var(--text-muted); }
.theme-card.active-theme { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.theme-card-preview {
  height: 68px;
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 5px;
}
.theme-card-bar { height: 10px; border-radius: 5px; }
.theme-card-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 10px 8px;
}
/* Display preview */
.display-preview-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin: 14px 0;
  pointer-events: none;
  font-size: 12px;
}
.display-preview-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.display-preview-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.display-preview-avatar {
  width: 26px; height: 26px;
  background: var(--bg-hover);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
  color: var(--accent);
}
.display-preview-body { flex: 1; min-width: 0; }

/* ── Admin view ──────────────────────────────────────────────── */
#view-admin { flex-direction: column; overflow: hidden; }
.admin-view-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
/* Override panel-level sizing/border in inline context */
#view-admin .admin-panel {
  width: 100%;
  max-height: none;
  border-radius: 0;
  border: none;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: none;
}
#view-admin .admin-panel-header {
  border-radius: 0;
}

/* ── Debug view ──────────────────────────────────────────────── */
#view-debug { flex-direction: column; overflow: hidden; }
.debug-view-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
/* Override debug console in inline context */
#view-debug .debug-console {
  display: flex !important;
  flex-direction: column;
  flex: 1 1 auto;
  border-radius: 0;
  border: none;
  position: static;
  height: auto;
  max-height: none;
  bottom: auto; left: auto; right: auto;
  z-index: auto;
  width: 100%;
}
#view-debug .debug-console.collapsed { flex: 1 1 auto; transform: none; }

/* ── Heartbeats / Webhooks views ─────────────────────────────── */
#view-heartbeats,
#view-webhooks { flex-direction: column; overflow: hidden; }
#view-heartbeats .view-content,
#view-webhooks .view-content { max-width: 780px; }

/* ── Mobile — nav drawer ─────────────────────────────────────── */
@media (max-width: 768px) {
  #app-nav {
    position: fixed;
    left: 0;
    top: 48px;
    bottom: 0;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform 0.25s ease, width 0.2s ease;
    width: 200px !important;
  }
  #app-nav.mobile-open { transform: translateX(0); }
  #app-nav.collapsed { width: 200px !important; }
  #app-nav.collapsed .nav-item-label { display: block; }
  #app-nav.collapsed .nav-item { padding: 8px 12px; justify-content: flex-start; }

  /* Settings on mobile: convert vertical rail into a horizontal scrollable tab bar */
  .settings-layout { flex-direction: column; }
  .settings-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 6px 0;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    flex-shrink: 0;
  }
  .settings-sidebar::-webkit-scrollbar { height: 0; }
  .settings-sidebar-title { display: none; }
  .stab-nav { flex-direction: row; gap: 4px; padding: 0 8px; flex: 0 0 auto; width: max-content; }
  .stab {
    flex: 0 0 auto;
    width: auto;
    padding: 7px 12px;
    font-size: 12px;
    white-space: nowrap;
    border: 1px solid transparent;
  }
  .stab.active { border-color: var(--accent-dim); }
  .settings-content { padding: 0; }
  .stab-pane { padding: 16px 14px; max-width: 100%; }
  .settings-row {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    margin-bottom: 14px;
  }
  .settings-row label { min-width: 0; font-weight: 600; }
  .settings-row select,
  .settings-row input[type="text"],
  .settings-row input[type="number"],
  .settings-row textarea { width: 100%; }
}

/* ── Header user email (small, subtle) ───────────────────────── */
.user-email-header {
  font-size: 11px;
  color: var(--text-muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Model Picker ─────────────────────────────────────────────── */
.model-picker-wrap {
  position: relative;
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 2px;
}
.model-picker-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 11px;
  font-family: var(--font);
  padding: 5px 9px;
  cursor: pointer;
  white-space: nowrap;
  max-width: 150px;
  transition: border-color 0.15s, background 0.15s;
  line-height: 1.4;
}
.model-picker-btn:hover { border-color: var(--accent); background: var(--bg-hover); }
#model-picker-label {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
  display: inline-block;
}
.mpb-chevron { font-size: 9px; opacity: 0.5; flex-shrink: 0; }

/* Bubble */
.model-picker-bubble {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  min-width: 220px;
  max-width: 310px;
  max-height: 380px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 36px rgba(0,0,0,0.45);
  z-index: 400;
  padding: 6px;
}
/* Speech bubble arrow pointing down-left */
.model-picker-bubble::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 18px;
  width: 11px;
  height: 11px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transform: rotate(45deg);
}
.mpb-group-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 6px 8px 2px;
  user-select: none;
}
.mpb-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12px;
  font-family: var(--font);
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mpb-item:hover { background: var(--bg-hover); }
.mpb-item.active { background: var(--accent); color: #fff; }

/* ── Collapsible Sessions List ──────────────────────────────────────────── */
.sidebar-section-title.sessions-title {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  transition: color 0.15s;
}
.sidebar-section-title.sessions-title:hover { color: var(--text); }
.sessions-chevron {
  font-size: 9px;
  opacity: 0.55;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.sessions-chevron.collapsed { transform: rotate(-90deg); }

/* ── Agent Trace Block ──────────────────────────────────────────────────── */
.agent-trace {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--tool-bg);
  font-size: 12px;
  margin-bottom: 6px;
}
.agent-trace-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
  transition: background 0.15s, color 0.15s;
  font-size: 11px;
  font-family: var(--mono);
}
.agent-trace-header:hover { background: var(--bg-hover); color: var(--text); }
.trace-done-icon { color: var(--accent); font-size: 12px; flex-shrink: 0; }
.trace-spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--text-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
.trace-summary { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trace-chevron {
  font-size: 9px;
  opacity: 0.5;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.agent-trace.open .trace-chevron { transform: rotate(180deg); }
/* Body hidden when closed, shown when .open */
.agent-trace-body {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
}
.agent-trace.open .agent-trace-body { display: flex; }

/* ── Nested sub-agent trace ─────────────────────────────────────────────── */
/* Same visual language as .agent-trace but indented and accent-coloured */
.sub-agent-trace {
  border: 1px solid var(--accent-dim, color-mix(in srgb, var(--accent) 30%, transparent));
  border-radius: 7px;
  overflow: hidden;
  background: color-mix(in srgb, var(--accent) 4%, var(--tool-bg));
  font-size: 12px;
  margin: 4px 0 4px 14px;
}
.sub-agent-trace-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
  transition: background 0.15s, color 0.15s;
  font-size: 11px;
  font-family: var(--mono);
  border-bottom: 1px solid transparent;
}
.sub-agent-trace-header:hover { background: var(--bg-hover); color: var(--text); }
.sub-agent-icon { font-size: 12px; opacity: 0.7; flex-shrink: 0; color: var(--accent); }
.sub-agent-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); opacity: 0.85; }
.sub-agent-trace-body {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  border-top: 1px solid var(--accent-dim, color-mix(in srgb, var(--accent) 20%, transparent));
}
.sub-agent-trace.open .sub-agent-trace-body { display: flex; }
.sub-agent-trace.open .trace-chevron { transform: rotate(180deg); }
.sub-agent-limit-badge {
  font-size: 11px;
  color: var(--warning, #f59e0b);
  padding: 4px 6px;
  opacity: 0.85;
}
.sub-agent-error {
  font-size: 11px;
  color: var(--error, #ef4444);
  padding: 4px 6px;
}


.trace-iter-sep {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 2px;
}
.trace-iter-sep-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.7;
  white-space: nowrap;
}
.trace-iter-sep-line {
  flex: 1;
  height: 1px;
  background: var(--border);
  opacity: 0.5;
}
/* Intermediate content blocks (not the final response) */
.trace-intermediate-body {
  font-size: 13px;
  opacity: 0.8;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* ── Right panel (live trace) ──────────────────────────────────── */
.right-panel {
  width: 0;
  overflow: hidden;
  border-left: none;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: var(--bg-card);
  transition: width 0.22s ease, border-color 0.22s ease;
}
body.right-panel-trace .right-panel {
  width: 320px;
  border-left: 1px solid var(--border);
  overflow: visible; /* let children overflow */
}
.rp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.rp-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.rp-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.rp-close-btn:hover { background: var(--bg-hover); color: var(--text); }
.rp-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  width: 320px; /* keep content width stable even during transition */
}
.rp-body::-webkit-scrollbar { width: 4px; }
.rp-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.rp-idle {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 32px 16px;
}
/* Header toggle button: highlight when panel is open */
.rp-toggle-header-btn { opacity: 0.55; }
body.right-panel-trace .rp-toggle-header-btn { opacity: 1; color: var(--accent); }
