:root {
  --bg:        #080809;
  --bg1:       #0e0e10;
  --bg2:       #141416;
  --bg3:       #1a1a1e;
  --bg4:       #212126;
  --border:    #232328;
  --border2:   #2e2e35;
  --text:      #e8e8f0;
  --text2:     #9090a0;
  --text3:     #55555f;
  --accent:    #6b8afd;
  --accent-dim:#2a3566;
  --green:     #4dba87;
  --red:       #e06c75;
  --yellow:    #e5c07b;
  --orange:    #d19a66;

  --header-h: 44px;
  --drawer-w: 400px;
  --sans: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', ui-monospace, monospace;
  --radius: 8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header pill buttons (admin / shared widgets / settings).
   One class rather than the same inline style copied onto each, because it was
   copied onto two different ELEMENTS: <a> inherits the body's font and
   line-height, <button> does not — browsers apply their own font shorthand to
   form controls, so the button rendered a hair smaller than its neighbours.
   font:inherit is what actually makes them identical; the rest was already the
   same. */
.hdr-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  font-size: 11.5px;
  line-height: 1.5;
  padding: 4px 10px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text3);
  text-decoration: none;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.hdr-btn:hover { color: var(--text); border-color: var(--accent); }

/* ── Layout ──────────────────────────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  /* UI scale: zoom the whole app; #bg-fx (a sibling) stays unscaled. The height
     is divided back out so the zoomed result still fills exactly one viewport. */
  zoom: var(--ui-scale, 1);
  height: calc(100vh / var(--ui-scale, 1));
  overflow: hidden;
  position: relative;   /* sits above the animated #bg-fx layer */
  z-index: 1;
  background: transparent;
}

/* ── Shell: left rail + main pane ─────────────────────────────────────────── */
#body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}
#view-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  letter-spacing: 0.02em;
}

#rail {
  width: 54px;
  flex-shrink: 0;
  position: relative;
  /* Above the widget-window band (20..200, see windows.js) so the hover flyout
     covers windows, but below the modal/panel layer (250+). */
  z-index: 220;
}
#rail-inner {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 54px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  background: var(--bg1);
  border-right: 1px solid var(--border);
  transition: width 0.16s ease, box-shadow 0.16s ease;
}
#rail:hover #rail-inner {
  width: 184px;
  box-shadow: 6px 0 28px rgba(0,0,0,0.45);
}
.rail-section { display: flex; flex-direction: column; gap: 2px; }
.rail-spacer { flex: 1; }
.rail-sep { height: 1px; background: var(--border); margin: 8px 12px; }

.rail-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  padding-left: 16px;
  background: none;
  border: none;
  color: var(--text2);
  font: inherit;
  font-size: 13px;
  text-align: left;            /* buttons center by default — keep labels left */
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.rail-item:hover { background: var(--bg2); color: var(--text); }
.rail-item.active {
  color: var(--accent);
  background: var(--bg2);
  box-shadow: inset 3px 0 0 var(--accent);   /* indicator that doesn't shift content */
}
.rail-icon { width: 22px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; line-height: 1; position: relative; }
.rail-badge { position: absolute; top: -5px; right: -7px; min-width: 14px; height: 14px; padding: 0 3px; background: var(--accent); color: #fff; font-size: 9px; font-weight: 700; line-height: 14px; text-align: center; border-radius: 999px; box-shadow: 0 0 0 2px var(--bg1); }
.rail-icon svg { width: 18px; height: 18px; }
.rail-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.12s;
}
#rail:hover .rail-label { opacity: 1; }
.rail-new { color: var(--text3); }

/* board rename/delete, only visible when the rail is expanded + row hovered */
.rail-board-act {
  background: none; border: none; color: var(--text3);
  cursor: pointer; font-size: 12px; padding: 2px 6px; opacity: 0;
  transition: opacity 0.1s, color 0.1s;
}
#rail:hover .rail-item:hover .rail-board-act { opacity: 0.7; }
.rail-board-act:hover { opacity: 1 !important; color: var(--text); }

#main {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
#app-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: var(--bg);
  z-index: 3;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

#dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 20px;
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  /* Above the widget-window band (20..200, see windows.js) so header dropdowns —
     the notification panel especially — are never covered by a widget. Matches the
     rail (220); stays below the modal/panel layer (250+). Was z-index:10, which
     trapped the notif-panel (z-index:300 but scoped to this header's context)
     underneath any focused widget. */
  z-index: 230;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Session switcher ────────────────────────────────────────────────────── */

#session-switcher {
  position: relative;
}

#session-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
#session-btn:hover { border-color: var(--accent); background: var(--bg3); }
#session-btn svg { color: var(--text3); flex-shrink: 0; }

.session-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 180px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 300;
  overflow: hidden;
}

.session-row {
  display: flex;
  align-items: center;
  padding: 2px 6px 2px 4px;
  transition: background 0.1s;
}
.session-row:hover { background: var(--bg3); }
.session-row.active { background: var(--accent-dim); }

.session-name-btn {
  flex: 1;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-size: 12.5px;
  padding: 7px 8px;
  cursor: pointer;
}
.session-row.active .session-name-btn { color: var(--accent); font-weight: 600; }

.session-del-btn {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 15px;
  padding: 4px 6px;
  cursor: pointer;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.session-del-btn:hover { color: var(--red); background: rgba(224, 108, 117, 0.12); }

.session-menu-footer {
  border-top: 1px solid var(--border);
  padding: 6px;
}
.session-menu-footer button {
  width: 100%;
  background: none;
  border: 1px dashed var(--border2);
  color: var(--text2);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.session-menu-footer button:hover { color: var(--accent); border-color: var(--accent); }

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text3);
}

.badge {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.badge-running { background: var(--green); box-shadow: 0 0 6px var(--green); }
.badge-stopped { background: var(--red); }
.badge-unknown { background: var(--text3); }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Notification bell ───────────────────────────────────────────────────── */

#notif-btn {
  position: relative;
  background: none;
  border: 1px solid var(--border2);
  color: var(--text3);
  padding: 5px 7px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color 0.15s, border-color 0.15s;
}
#notif-btn:hover, #notif-btn.has-notif { color: var(--text); border-color: var(--accent); }

#notif-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  padding: 0 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
}

/* ── Notification panel ──────────────────────────────────────────────────── */

.notif-panel {
  position: absolute;
  top: calc(var(--header-h) + 4px);
  right: 60px;
  width: 320px;
  max-height: 420px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 300;
  flex-direction: column;
  overflow: hidden;
}

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  flex-shrink: 0;
}
.notif-panel-header button {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s;
}
.notif-panel-header button:hover { color: var(--accent); }

#notif-list {
  overflow-y: auto;
  flex: 1;
}

.notif-empty {
  padding: 24px;
  text-align: center;
  color: var(--text3);
  font-size: 12px;
}

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg3); }
.notif-item.read { opacity: 0.55; }

.notif-icon {
  font-size: 13px;
  flex-shrink: 0;
  margin-top: 1px;
  font-style: normal;
}
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-size: 12.5px; color: var(--text); font-weight: 500; }
.notif-msg   { font-size: 11px; color: var(--text2); margin-top: 2px; }
.notif-time  { font-size: 10px; color: var(--text3); flex-shrink: 0; }
.notif-delete {
  background: none; border: none; color: var(--text3); cursor: pointer;
  font-size: 11px; padding: 0 2px; flex-shrink: 0; opacity: 0;
  transition: color 0.15s, opacity 0.15s;
}
.notif-item:hover .notif-delete { opacity: 1; }
.notif-delete:hover { color: var(--red); }

/* ── Toast notifications ─────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 80px;
  right: 24px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.notif-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.45);
  padding: 10px 12px;
  min-width: 260px;
  max-width: 320px;
  pointer-events: all;
  cursor: pointer;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.25s, transform 0.25s;
}
.notif-toast.visible { opacity: 1; transform: translateX(0); }

.notif-toast-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.notif-toast-body { flex: 1; min-width: 0; }
.notif-toast-title { font-size: 12.5px; font-weight: 600; color: var(--text); }
.notif-toast-msg   { font-size: 11px; color: var(--text2); margin-top: 2px; }
.notif-toast-close {
  background: none; border: none; color: var(--text3);
  font-size: 16px; cursor: pointer; padding: 0 2px; line-height: 1;
  flex-shrink: 0; transition: color 0.15s;
}
.notif-toast-close:hover { color: var(--text); }

#model-select {
  background: var(--bg2);
  border: 1px solid var(--border2);
  color: var(--text2);
  font-size: 11.5px;
  font-family: var(--sans);
  padding: 4px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  max-width: 180px;
  outline: none;
  transition: border-color 0.15s;
}
#model-select:hover, #model-select:focus { border-color: var(--accent); }
#model-select option { background: var(--bg2); }

/* ── Dashboard ───────────────────────────────────────────────────────────── */

#dashboard {
  flex: 1;
  position: relative;       /* positioning context for free-floating windows */
  overflow: auto;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */

#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: calc(100vh - var(--header-h) - 40px);
  text-align: center;
  pointer-events: none;
}

.empty-icon {
  font-size: 40px;
  opacity: 0.15;
  line-height: 1;
}

.empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text2);
  opacity: 0.5;
}

.empty-hint {
  font-size: 13px;
  color: var(--text3);
}

.empty-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 6px;
  pointer-events: auto;
}

.empty-examples span {
  background: var(--bg2);
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  user-select: none;
}
.empty-examples span:hover {
  background: var(--bg3);
  color: var(--text);
  border-color: var(--accent);
}

/* ── Widget window (free-floating) ───────────────────────────────────────── */

.widget-window {
  position: absolute;
  min-width: 200px;
  min-height: 120px;
  display: flex;
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.45), 0 0 0 1px var(--border);
}

/* ── Widget card ─────────────────────────────────────────────────────────── */

.widget-card {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  transition: border-color 0.15s;
}
.widget-card:hover { border-color: var(--border2); }

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  height: 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 6px;
  cursor: grab;
  user-select: none;
}
.widget-header:active { cursor: grabbing; }

.widget-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.widget-min, .widget-lock {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 1px 5px;
  border-radius: 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s, background 0.1s;
}
.widget-card:hover .widget-min,
.widget-card:hover .widget-lock { opacity: 1; }
.widget-min:hover, .widget-lock:hover { color: var(--text); background: var(--bg3); }
.widget-lock { font-size: 13px; }
.widget-min { font-size: 16px; font-weight: 600; }

.widget-body {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.widget-body iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* ── Window resize handle ─────────────────────────────────────────────────── */

/* Workspace terminal (Ctrl+`) — hidden bottom panel */
#term-panel { position: fixed; left: 0; right: 0; bottom: 0; height: 42vh; background: var(--bg); border-top: 1px solid var(--border2); z-index: 300; display: flex; flex-direction: column; transform: translateY(100%); transition: transform .18s ease; box-shadow: 0 -10px 36px rgba(0,0,0,.45); }
#term-panel.open { transform: translateY(0); }
#term-head { display: flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 11px; color: var(--text2); border-bottom: 1px solid var(--border); background: var(--bg2); }
#term-hint { font-size: 10px; color: var(--text3); }
#term-close { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 13px; padding: 0 4px; }
#term-close:hover { color: var(--text); }
#term-body { flex: 1; min-height: 0; padding: 4px 4px 4px 10px; overflow: hidden; }
#term-body .xterm { height: 100%; }

/* Alignment guides shown while snapping a window */
.snap-guide { position: absolute; z-index: 205; pointer-events: none; display: none; background: var(--accent); box-shadow: 0 0 4px var(--accent); }
.snap-guide.v { top: 0; bottom: 0; width: 1px; }
.snap-guide.h { left: 0; right: 0; height: 1px; }

.window-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 2;
}
.widget-window:hover .window-resize { opacity: 1; }
.window-resize::after {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 9px;
  height: 9px;
  border-bottom: 2.5px solid var(--border2);
  border-right: 2.5px solid var(--border2);
  transition: border-color 0.15s;
}
.window-resize:hover::after { border-color: var(--accent); }

/* ── Widget dock (taskbar) ────────────────────────────────────────────────── */

#widget-dock {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 88px 6px 10px;   /* right space kept clear for the chat FAB */
  background: var(--bg1);
  border-top: 1px solid var(--border);
  max-height: 96px;
  overflow-y: auto;
}
.dock-chip {
  display: flex;
  align-items: center;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 999px;
  overflow: hidden;
  opacity: 0.6;
  transition: opacity 0.15s, border-color 0.15s;
}
.dock-chip.open { opacity: 1; border-color: var(--accent-dim); }
.dock-chip:hover { opacity: 1; }
.dock-tidy { margin-left: auto; background: var(--bg2); border: 1px solid var(--border2); color: var(--text2); border-radius: 999px; padding: 4px 12px; font-size: 11.5px; cursor: pointer; white-space: nowrap; transition: color .15s, border-color .15s; }
.dock-tidy:hover { color: var(--accent); border-color: var(--accent); }
.dock-chip-label {
  background: none;
  border: none;
  color: var(--text2);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  padding: 4px 4px 4px 12px;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dock-chip.open .dock-chip-label { color: var(--text); }
.dock-chip-del {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 11px;
  padding: 4px 9px 4px 5px;
  opacity: 0.5;
  transition: color 0.1s, opacity 0.1s;
}
.dock-chip-del:hover { color: var(--red); opacity: 1; }

/* ── Theme picker ─────────────────────────────────────────────────────────── */

#theme-select {
  background: var(--bg2);
  border: 1px solid var(--border2);
  color: var(--text3);
  font-size: 11.5px;
  padding: 4px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
#theme-select:hover { color: var(--text); border-color: var(--accent); }

#approval-select {
  background: var(--bg2);
  border: 1px solid var(--border2);
  color: var(--text3);
  font-size: 11.5px;
  padding: 4px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
#approval-select:hover { color: var(--text); border-color: var(--accent); }
#approval-select.manual { color: var(--yellow, #d9a441); border-color: var(--yellow, #d9a441); }

/* Approve/Reject bar shown under a tool call awaiting the user's verdict */
.tool-approve-bar {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.tool-approve-bar .ta-waiting { color: var(--text3); font-style: italic; margin-right: auto; }
.tool-approve-bar button {
  font: inherit; font-size: 12px; cursor: pointer;
  padding: 3px 12px; border-radius: var(--radius);
  background: var(--bg2); color: var(--text); border: 1px solid var(--border2);
  transition: color .15s, border-color .15s;
}
.tool-approve-bar .ta-approve:hover { color: var(--green, #4caf50); border-color: var(--green, #4caf50); }
.tool-approve-bar .ta-reject:hover { color: var(--red, #e05252); border-color: var(--red, #e05252); }

/* ── Zoom control ────────────────────────────────────────────────────────── */


/* ── File editor ─────────────────────────────────────────────────────────── */

#editor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 250;
}
#editor-overlay.visible { opacity: 1; pointer-events: auto; }

#editor-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -48%) scale(0.97);
  width: min(92vw, 960px);
  height: min(88vh, 780px);
  background: var(--bg1);
  border: 1px solid var(--border2);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 260;
  overflow: hidden;
}
#editor-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

#editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

#editor-filename {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text2);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#editor-status {
  font-size: 11px;
  color: var(--green);
  min-width: 70px;
  text-align: right;
  transition: opacity 0.3s;
}

#editor-save-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 12px;
  font-family: var(--sans);
  padding: 5px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}
#editor-save-btn:hover { background: #7c9bff; }

#editor-codemirror {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
#editor-codemirror .CodeMirror {
  flex: 1;
  height: 100%;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  background: #282a36;
}

/* ── Config button ───────────────────────────────────────────────────────── */

#config-btn {
  background: var(--bg2);
  border: 1px solid var(--border2);
  color: var(--text3);
  border-radius: var(--radius);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}
#config-btn:hover { color: var(--text); border-color: var(--accent); background: var(--bg3); }
#config-btn.active { color: var(--accent); border-color: var(--accent); }

/* ── Config overlay ──────────────────────────────────────────────────────── */

#config-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s;
  z-index: 190;
}
#config-overlay.visible { opacity: 1; pointer-events: auto; }

/* ── Config panel ────────────────────────────────────────────────────────── */

#config-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -48%) scale(0.97);
  width: min(92vw, 780px);
  max-height: 82vh;
  background: var(--bg1);
  border: 1px solid var(--border2);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  z-index: 200;
  overflow: hidden;
}
#config-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

#config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.config-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.config-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text3);
}
#config-stats {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 8px;
  border-radius: 10px;
}

#config-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Config sections ─────────────────────────────────────────────────────── */

.config-section {}

.config-cat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.config-cat-icon { font-size: 15px; line-height: 1; }
.config-cat-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text2);
}

.config-tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.config-tool-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: border-color 0.15s, opacity 0.15s;
}
.config-tool-card:hover { border-color: var(--border2); }
.config-tool-card.disabled { opacity: 0.42; }

.config-tool-info { flex: 1; min-width: 0; }
.config-tool-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}
.config-tool-desc {
  font-size: 11.5px;
  color: var(--text3);
  line-height: 1.5;
  margin-bottom: 5px;
}
.config-tool-id {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text3);
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 3px;
  display: inline-block;
}

/* ── Toggle switch ───────────────────────────────────────────────────────── */

.toggle-switch {
  position: relative;
  flex-shrink: 0;
  width: 34px;
  height: 20px;
  cursor: pointer;
  margin-top: 1px;
}
.toggle-switch input { display: none; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: 10px;
  transition: background 0.2s, border-color 0.2s;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: var(--text3);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.toggle-switch input:checked + .toggle-track {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(14px);
  background: var(--accent);
}

/* ── Chat overlay ────────────────────────────────────────────────────────── */

/* ── Chat: docked side panel ─────────────────────────────────────────────── */

/* Docked side panel: a flex sibling of #main inside #body (no overlay) so you
   can read a mail / work a dashboard AND chat side by side. */
#chat-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--drawer-w);
  min-width: 300px;
  max-width: 95vw;
  z-index: 250;
  background: var(--bg1);
  border-left: 1px solid var(--border);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.28);
  flex-direction: column;
  overflow: hidden;
  display: none;
}
#chat-drawer.open { display: flex; }
#chat-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: ew-resize;
  z-index: 10;
  transition: background 0.15s;
}
#chat-resize-handle:hover,
#chat-resize-handle.dragging { background: var(--accent-dim); }

/* Chat panel docked on the left instead of the right (overlay) */
[data-chat-side="left"] #chat-drawer { right: auto; left: 0; border-left: none; border-right: 1px solid var(--border); box-shadow: 10px 0 40px rgba(0, 0, 0, 0.28); }
[data-chat-side="left"] #chat-resize-handle { left: auto; right: 0; }
[data-chat-side="left"] #chat-fab { right: auto; left: 24px; }

#chat-agent {
  text-transform: none;
  letter-spacing: 0.01em;
  font-size: 12.5px;
  color: var(--text2);
}

/* Context bar — shows what the agent currently "sees" */
#chat-context-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 11px;
  color: var(--text2);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#chat-context-bar::before {
  content: '👁';
  font-size: 11px;
  flex-shrink: 0;
  opacity: .7;
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text3);
}
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
#chat-header button {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  font-size: 11.5px;
  font-family: var(--sans);
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.1s, background 0.1s;
}
#chat-header button:hover { color: var(--text); background: var(--bg4); }
.drawer-close {
  background: none !important;
  border: none !important;
  color: var(--text3) !important;
  font-size: 16px !important;
  padding: 4px 6px !important;
  cursor: pointer;
  border-radius: 5px !important;
  line-height: 1;
  transition: color 0.1s, background 0.1s !important;
}
.drawer-close:hover { color: var(--text) !important; background: var(--bg3) !important; }

/* Messages */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
}

.chat-msg { display: flex; flex-direction: column; gap: 5px; }
.chat-progress {
  font-size: 11.5px;
  color: var(--text3);
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 1px 2px;
  font-family: var(--mono);
}
.chat-progress::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: progressPulse 1.2s ease-in-out infinite;
}
@keyframes progressPulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

.chat-history-sep {
  text-align: center;
  font-size: 10px;
  color: var(--text3);
  padding: 6px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin: 4px 0;
  letter-spacing: 0.05em;
}

.chat-msg-role {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.chat-msg.user .chat-msg-role      { color: var(--accent); }
.chat-msg.assistant .chat-msg-role { color: var(--text3); }

.chat-msg-time {
  font-weight: 400;
  color: var(--text3);
  font-size: 9px;
  margin-left: 5px;
  letter-spacing: 0;
}

.chat-msg-content {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text);
  word-break: break-word;
}
.chat-msg.user .chat-msg-content {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 10px 13px;
}

/* Markdown */
.chat-msg-content p { margin-bottom: 7px; }
.chat-msg-content p:last-child { margin-bottom: 0; }
.chat-msg-content code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--orange);
}
.chat-msg-content pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 13px;
  overflow-x: auto;
  margin: 6px 0;
}
.chat-msg-content pre code {
  background: none; border: none; padding: 0;
  color: var(--text); font-size: 12px;
}
.chat-msg-content ul { padding-left: 18px; margin: 4px 0; }
.chat-msg-content ol { padding-left: 24px; margin: 4px 0; }
.chat-msg-content li { margin: 2px 0; }
.chat-msg-content h2, .chat-msg-content h3, .chat-msg-content h4 {
  margin: 8px 0 3px; color: var(--text); font-weight: 600;
}
.chat-msg-content strong { font-weight: 600; }
.chat-msg-content em { font-style: italic; color: var(--text2); }
.chat-msg-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 12.5px;
}
.chat-msg-content th,
.chat-msg-content td {
  border: 1px solid var(--border2);
  padding: 5px 10px;
  text-align: left;
}
.chat-msg-content th {
  background: var(--bg3);
  color: var(--text2);
  font-weight: 600;
}
.chat-msg-content tr:nth-child(even) td { background: var(--bg2); }

/* Tool blocks */
.chat-msg.tool .tool-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-family: var(--mono);
  font-size: 11px;
}
.tool-block-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 11px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.tool-block-name { color: var(--yellow); font-weight: 600; white-space: nowrap; }
.tool-block-input-inline {
  color: var(--text3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  cursor: pointer;
}
/* Click-to-unfold: the one-line summary above, in full. */
.tool-block-input-inline.expanded {
  white-space: pre-wrap;
  overflow: visible;
  text-overflow: clip;
  word-break: break-all;
}
/* Pending manual approval: the output slot shows the FULL command/arguments
   being approved — neutral color, taller cap than normal output. */
.tool-block-output.approval {
  color: var(--text1);
  max-height: 320px;
}
.tool-block-output {
  padding: 5px 11px;
  color: var(--green);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 160px;
  overflow-y: auto;
}
.tool-block-output.running { color: var(--text3); font-style: italic; }
.tool-block-output.error   { color: var(--red); }

.tool-block-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 0 4px;
}
.tool-block-images img {
  max-width: 320px;
  max-height: 220px;
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: contain;
  background: var(--bg);
  cursor: zoom-in;
}

/* ── Thinking blocks ─────────────────────────────────────────────────────── */

.thinking-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 2px 0 8px;
  overflow: hidden;
}
.thinking-block summary {
  padding: 5px 11px;
  font-size: 11px;
  color: var(--text3);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 5px;
  list-style: none;
  transition: color 0.15s;
}
.thinking-block summary::-webkit-details-marker { display: none; }
.thinking-block summary::before {
  content: '▶';
  font-size: 8px;
  transition: transform 0.15s;
  flex-shrink: 0;
}
.thinking-block[open] summary::before { transform: rotate(90deg); }
.thinking-block summary:hover { color: var(--text2); }
.thinking-icon { font-size: 12px; }
.thinking-content {
  padding: 8px 12px;
  font-size: 11.5px;
  color: var(--text3);
  border-top: 1px solid var(--border);
  line-height: 1.6;
  font-style: italic;
}

/* Thinking indicator (streaming) */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text3);
  font-size: 12px;
  font-style: italic;
  padding: 4px 0 8px;
}
.thinking-dots::before {
  content: '●●●';
  letter-spacing: 4px;
  font-size: 7px;
  color: var(--accent);
  animation: thinking-pulse 1.4s ease-in-out infinite;
}
@keyframes thinking-pulse {
  0%, 100% { opacity: 0.3; }
  50%       { opacity: 1; }
}

/* ── Tool spinner ─────────────────────────────────────────────────────────── */

.tool-spinner {
  display: inline-block;
  width: 9px;
  height: 9px;
  border: 1.5px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chat-msg.tool { animation: tool-appear 0.18s ease-out; }
@keyframes tool-appear {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Streaming cursor */
@keyframes blink { 50% { opacity: 0; } }
.cursor::after {
  content: '▌';
  color: var(--accent);
  animation: blink 0.9s step-end infinite;
  margin-left: 1px;
}

/* Input area */
#chat-suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
.suggest-chip { font-size: 11.5px; padding: 4px 10px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--border2); color: var(--text2); cursor: pointer; white-space: nowrap; transition: color .12s, border-color .12s; }
.suggest-chip:hover { color: var(--accent); border-color: var(--accent); }

#chat-input-area {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

.emoji-picker {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 14px;
  width: 264px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  z-index: 300;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.emoji-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 6px 0;
  border-bottom: 1px solid var(--border);
}
.emoji-tab {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 5px 7px;
  border-radius: 6px;
  line-height: 1;
  transition: background 0.12s;
  opacity: 0.55;
}
.emoji-tab:hover,
.emoji-tab.active { background: var(--bg4); opacity: 1; }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 1px;
  padding: 6px;
  max-height: 176px;
  overflow-y: auto;
}
.emoji-item {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 19px;
  padding: 4px 2px;
  border-radius: 5px;
  line-height: 1;
  text-align: center;
  transition: background 0.1s;
}
.emoji-item:hover { background: var(--bg4); }

/* Image previews strip */
#image-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.img-preview-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border2);
}
.img-preview-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.img-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.65);
  border: none;
  color: #fff;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* File attachment chip in the preview bar */
.file-preview-chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 4px 24px 4px 8px;
  font-size: 12px;
  color: var(--text2);
  max-width: 160px;
  height: 64px;
  box-sizing: border-box;
}
.file-preview-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* File chips inside a sent chat message */
.chat-msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}
.chat-msg-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 12px;
  color: var(--text2);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Row with attach button + textarea + send */
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

/* Attach button */
#attach-btn {
  flex-shrink: 0;
  cursor: pointer;
  color: var(--text3);
  padding: 8px 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}
#attach-btn:hover { color: var(--accent); }

#emoji-btn {
  flex-shrink: 0;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text3);
  padding: 5px 6px;
  font-size: 17px;
  line-height: 1;
  display: flex;
  align-items: center;
  border-radius: 6px;
  transition: background 0.15s, opacity 0.15s;
  opacity: 0.7;
}
#emoji-btn:hover { background: var(--bg4); opacity: 1; }

/* Images in chat messages */
.chat-msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}
.chat-msg-images img {
  max-width: 220px;
  max-height: 160px;
  border-radius: 6px;
  border: 1px solid var(--border2);
  object-fit: cover;
  cursor: zoom-in;
}

#chat-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.5;
  padding: 9px 12px;
  resize: none;
  overflow-y: auto;
  max-height: 180px;
  min-height: 38px;
  outline: none;
  transition: border-color 0.15s;
}
#chat-input:focus { border-color: var(--accent); }
#chat-input::placeholder { color: var(--text3); }

#send-btn {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
#send-btn:hover { background: #7c9bff; }
#send-btn:active { transform: scale(0.93); }
#send-btn.loading { background: var(--bg4); cursor: not-allowed; }

/* ── Floating action button ──────────────────────────────────────────────── */

#chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 20px rgba(107, 138, 253, 0.4);
  transition: background 0.15s, transform 0.2s, box-shadow 0.15s, opacity 0.2s, visibility 0.2s;
  z-index: 210;
}
#chat-fab:hover {
  background: #7c9bff;
  transform: scale(1.06);
  box-shadow: 0 6px 24px rgba(107, 138, 253, 0.55);
}
#chat-fab:active { transform: scale(0.96); }

#fab-icon-close { display: none; }
#chat-fab.active { opacity: 0; visibility: hidden; transform: scale(0.8); }

/* ── Scrollbars ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── Secret dialog ───────────────────────────────────────────────────────── */
#secret-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 600;
}
#secret-overlay.visible { opacity: 1; pointer-events: auto; }

#secret-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -52%) scale(0.96);
  width: min(90vw, 420px);
  background: var(--bg1);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 601;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
#secret-dialog.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}
.secret-dialog-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
}
.secret-dialog-desc {
  font-size: 13px;
  color: var(--text2);
  line-height: 1.5;
}
#secret-dialog-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s;
  font-family: monospace;
  letter-spacing: 0.1em;
}
#secret-dialog-input:focus { border-color: var(--accent); }
.secret-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.secret-btn-cancel {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.secret-btn-cancel:hover { border-color: var(--text3); color: var(--text); }
.secret-btn-submit {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.secret-btn-submit:hover { opacity: 0.85; }

/* ── Config panel — secrets section ─────────────────────────────────────── */
.config-secrets-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.config-secret-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
}
.config-secret-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.config-secret-name {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}
.config-secret-env {
  font-size: 11px;
  color: var(--text3);
  font-family: monospace;
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 3px;
}
.config-secret-del {
  background: transparent;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.config-secret-del:hover { color: var(--red); background: rgba(224,108,117,0.1); }

/* ─── Config panel tabs ─────────────────────────────────────────────────────── */
.config-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}
.config-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text3);
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 12px 8px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  letter-spacing: 0.02em;
}
.config-tab:hover { color: var(--text); }
.config-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.config-tab-content { padding: 0; }

/* ─── MCP server cards ───────────────────────────────────────────────────────── */
.mcp-server-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 14px 0;
  transition: border-color 0.15s;
}
.mcp-server-card:hover { border-color: var(--border2); }
.mcp-server-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.mcp-server-info { flex: 1; min-width: 0; }
.mcp-server-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: block;
}
.mcp-server-url {
  font-size: 11px;
  color: var(--text3);
  font-family: monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  margin-top: 2px;
}
.mcp-server-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.mcp-tool-count {
  font-size: 11px;
  color: var(--text3);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 8px;
}
.mcp-server-del {
  background: transparent;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.mcp-server-del:hover { color: var(--red); background: rgba(224,108,117,0.1); }
.mcp-server-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 10px;
}
.mcp-tool-pill {
  font-size: 10.5px;
  font-family: monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 8px;
  color: var(--text3);
}
.mcp-server-tool-grid {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  transition: opacity 0.2s;
}
.mcp-server-tool-grid .config-tool-card {
  background: var(--bg);
}
.mcp-empty {
  margin: 20px 16px 0;
  font-size: 13px;
  color: var(--text3);
}
.config-mcp-server-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 0 4px;
}

/* ─── MCP add-server form ────────────────────────────────────────────────────── */
.mcp-add-form {
  margin: 16px 14px 14px;
  padding: 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.mcp-add-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}
.mcp-add-fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.mcp-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 12.5px;
  padding: 6px 10px;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s;
}
.mcp-input:focus { border-color: var(--accent); }
.mcp-add-submit {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 6px 16px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.mcp-add-submit:hover { opacity: 0.85; }
.mcp-add-submit:disabled { opacity: 0.45; cursor: default; }
.mcp-add-status {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text3);
  min-height: 16px;
}
.mcp-add-status.ok    { color: var(--green); }
.mcp-add-status.error { color: var(--red); }

/* ── Login overlay ────────────────────────────────────────────────────────── */
#login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
#login-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(90vw, 340px);
  background: var(--bg1);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 32px 28px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
}
#login-input {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  box-sizing: border-box;
  width: 100%;
  transition: border-color .15s;
  font-family: monospace;
  letter-spacing: .1em;
}
#login-input:focus { border-color: var(--accent); }
#login-error {
  display: none;
  font-size: 12px;
  color: var(--red);
}
#login-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
#login-btn:hover   { opacity: .85; }
#login-btn:disabled { opacity: .5; cursor: default; }

/* ══ Animated background (per theme) ════════════════════════════════════════
 * #bg-fx is a fixed, non-interactive layer behind #app. The empty dashboard
 * area is transparent, so the animation shows through behind the windows. All
 * effects are tinted with the active theme's tokens, so they re-colour for free
 * on theme switch; tech themes override the default "aurora" with their own. */

#bg-fx {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background: var(--bg);
  opacity: var(--bgfx-opacity, 1);   /* animated-background intensity (0 = off) */
}

/* Tron canvas (bgfx.js) — drawn transparently over the #bg-fx base gradient */
#bgfx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
}

/* Default — slow drifting accent glows (used by all non-tech themes) */
#bg-fx::before {
  content: '';
  position: absolute;
  inset: -25%;
  background:
    radial-gradient(38% 38% at 20% 28%, var(--accent), transparent 70%),
    radial-gradient(34% 34% at 82% 72%, var(--accent), transparent 70%),
    radial-gradient(30% 30% at 62% 18%, var(--green), transparent 70%);
  opacity: .14;
  filter: blur(60px);
  will-change: transform;
  animation: bgAurora 26s ease-in-out infinite alternate;
}
@keyframes bgAurora {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(3%, -2%) scale(1.12); }
  100% { transform: translate(-3%, 2%) scale(1.05); }
}

/* ── Tech — faint drifting grid + accent scan ─────────────────────────────── */
[data-theme="tech"] #bg-fx::before {
  inset: 0;
  background:
    linear-gradient(var(--border2) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, var(--border2) 1px, transparent 1px) 0 0 / 48px 48px;
  opacity: .35;
  filter: none;
  animation: bgDrift 34s linear infinite;
}
[data-theme="tech"] #bg-fx::after {
  content: '';
  position: absolute;
  inset: -25%;
  background: radial-gradient(45% 45% at 30% 25%, var(--accent), transparent 70%);
  opacity: .12;
  filter: blur(70px);
  animation: bgAurora 22s ease-in-out infinite alternate;
}
@keyframes bgDrift {
  from { background-position: 0 0, 0 0; }
  to   { background-position: 48px 48px, 48px 48px; }
}

/* ── Cyberpunk — Tron grid with travelling glow points (canvas: bgfx.js) ───── */
[data-theme="cyberpunk"] #bg-fx {
  background: radial-gradient(circle at 50% 40%, var(--accent-dim), var(--bg) 70%);
}
/* The CSS aurora layer is replaced by the canvas for this theme. */
[data-theme="cyberpunk"] #bg-fx::before { display: none; }
@keyframes bgGrid {
  from { background-position: 0 0, 0 0; }
  to   { background-position: 0 50px, 50px 0; }
}

/* ── Synthwave — retro sun + horizon grid ─────────────────────────────────── */
[data-theme="synthwave"] #bg-fx {
  background: linear-gradient(180deg, var(--bg) 0%, var(--accent-dim) 72%, var(--bg2) 100%);
}
[data-theme="synthwave"] #bg-fx::before {
  content: '';
  position: absolute;
  left: -50%; right: -50%; bottom: -8%;
  height: 120%;
  background:
    linear-gradient(var(--accent) 2px, transparent 2px) 0 0 / 50px 50px,
    linear-gradient(90deg, var(--green) 2px, transparent 2px) 0 0 / 50px 50px;
  opacity: .18;
  transform: perspective(440px) rotateX(64deg);
  transform-origin: bottom center;
  animation: bgGrid 6s linear infinite;
}
[data-theme="synthwave"] #bg-fx::after {
  content: '';
  position: absolute;
  left: 50%; top: 14%;
  width: 280px; height: 280px;
  margin-left: -140px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--yellow), var(--accent));
  -webkit-mask: repeating-linear-gradient(180deg, #000 0 9px, transparent 9px 14px);
          mask: repeating-linear-gradient(180deg, #000 0 9px, transparent 9px 14px);
  filter: blur(1px);
  opacity: .55;
  animation: bgSun 7s ease-in-out infinite alternate;
}
@keyframes bgSun {
  from { opacity: .4; filter: blur(1px); }
  to   { opacity: .65; filter: blur(3px); }
}

/* ── Matrix — falling code rain (canvas: bgfx.js) + CRT scanlines on top ───── */
[data-theme="matrix"] #bg-fx {
  background: radial-gradient(ellipse at center, var(--bg1), #000 82%);
}
[data-theme="matrix"] #bg-fx::before { display: none; }  /* rain drawn on canvas */
[data-theme="matrix"] #bg-fx::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(57,255,20,.07) 0 1px, transparent 1px 3px);
  box-shadow: inset 0 0 220px 50px rgba(0,0,0,.85);
  animation: bgScan 7s linear infinite, bgFlicker 4s ease-in-out infinite;
}
@keyframes bgScan {
  from { background-position: 0 0; }
  to   { background-position: 0 120px; }
}
/* Gentle CRT brightness drift — subtle, not a strobe */
@keyframes bgFlicker {
  0%, 100% { opacity: .85; }
  47%      { opacity: .7; }
  50%      { opacity: 1; }
  53%      { opacity: .72; }
}

/* ── Midnight — drifting, twinkling starfield + faint nebula ───────────────── */
[data-theme="midnight"] #bg-fx::before {
  inset: 0;
  background:
    radial-gradient(1.4px 1.4px at 12% 22%, var(--text), transparent 60%),
    radial-gradient(1px 1px at 28% 68%, var(--text2), transparent 60%),
    radial-gradient(1.6px 1.6px at 45% 38%, var(--accent), transparent 60%),
    radial-gradient(1px 1px at 62% 80%, var(--text2), transparent 60%),
    radial-gradient(1.3px 1.3px at 73% 28%, var(--text), transparent 60%),
    radial-gradient(1px 1px at 84% 60%, var(--text2), transparent 60%),
    radial-gradient(1.5px 1.5px at 92% 14%, var(--accent), transparent 60%),
    radial-gradient(1px 1px at 18% 90%, var(--text2), transparent 60%),
    radial-gradient(1.2px 1.2px at 53% 12%, var(--text), transparent 60%),
    radial-gradient(1px 1px at 38% 52%, var(--text2), transparent 60%);
  background-repeat: no-repeat;
  opacity: .55;
  filter: none;
  animation: bgTwinkle 5s ease-in-out infinite alternate, bgFloat 50s ease-in-out infinite alternate;
}
[data-theme="midnight"] #bg-fx::after {
  content: '';
  position: absolute;
  inset: -25%;
  background: radial-gradient(40% 40% at 70% 30%, var(--accent), transparent 70%);
  opacity: .10;
  filter: blur(70px);
  animation: bgAurora 28s ease-in-out infinite alternate;
}

/* ── Nord — slow aurora borealis bands ────────────────────────────────────── */
[data-theme="nord"] #bg-fx::before {
  inset: -30%;
  background: linear-gradient(115deg, transparent 18%, var(--accent) 38%, var(--green) 52%, var(--accent) 66%, transparent 84%);
  opacity: .12;
  filter: blur(55px);
  animation: bgBands 16s ease-in-out infinite alternate;
}

/* ── Solarized — slowly rotating warm sun rays + glow ──────────────────────── */
[data-theme="solarized-dark"] #bg-fx::before {
  inset: -60%;
  background: conic-gradient(from 0deg at 50% 50%,
    transparent 0 6deg, var(--yellow) 6deg 7deg, transparent 7deg 18deg,
    var(--orange) 18deg 19deg, transparent 19deg 36deg);
  opacity: .05;
  filter: blur(1px);
  animation: bgRays 90s linear infinite;
}
[data-theme="solarized-dark"] #bg-fx::after {
  content: '';
  position: absolute;
  inset: -25%;
  background: radial-gradient(38% 38% at 50% 45%, var(--yellow), transparent 70%);
  opacity: .07;
  filter: blur(70px);
  animation: bgAurora 24s ease-in-out infinite alternate;
}

/* ── Rosé Pine — floating soft bokeh ──────────────────────────────────────── */
[data-theme="rose-pine"] #bg-fx::before {
  inset: -15%;
  background:
    radial-gradient(60px 60px at 20% 80%, var(--accent), transparent 70%),
    radial-gradient(45px 45px at 65% 90%, var(--orange), transparent 70%),
    radial-gradient(80px 80px at 80% 72%, var(--green), transparent 70%),
    radial-gradient(50px 50px at 40% 95%, var(--yellow), transparent 70%);
  background-repeat: no-repeat;
  opacity: .13;
  filter: blur(22px);
  animation: bgRise 26s ease-in-out infinite alternate;
}

/* ── Prism Light — kept sober (a whisper of the default aurora) ────────────── */
[data-theme="prism-light"] #bg-fx::before { opacity: .05; }

/* ── The professional set (theme.js) ───────────────────────────────────────── */
/* Paper stays almost still — it is the reading theme. */
[data-theme="paper"] #bg-fx::before { opacity: .04; }

/* Graphite — pinstripe, the suit fabric, drifting imperceptibly. The 67.9px
   travel is one 48px stripe period projected on the x axis (48·√2). */
[data-theme="graphite"] #bg-fx::before {
  inset: -80px;
  background: repeating-linear-gradient(45deg, var(--text3) 0 1px, transparent 1px 48px);
  opacity: .05;
  filter: none;
  animation: bgPinstripe 120s linear infinite;
}
@keyframes bgPinstripe { to { transform: translateX(67.9px); } }

/* Themes with a canvas animation (bgfx.js) drop their CSS pattern layer so the
   two don't double up; the gradient base and ambient ::after glow stay. */
[data-theme="midnight"] #bg-fx::before,
[data-theme="nord"] #bg-fx::before,
[data-theme="solarized-dark"] #bg-fx::before,
[data-theme="rose-pine"] #bg-fx::before,
[data-theme="tech"] #bg-fx::before,
[data-theme="slate"] #bg-fx::before,
[data-theme="boardroom"] #bg-fx::before,
[data-theme="synthwave"] #bg-fx::before,
[data-theme="synthwave"] #bg-fx::after { display: none; }

@keyframes bgTwinkle { from { opacity: .35; } to { opacity: .6; } }
@keyframes bgFloat   { from { transform: translateY(2%); } to { transform: translateY(-6%); } }
@keyframes bgBands {
  0%   { transform: translate(-12%, -6%) rotate(-5deg) scaleY(1); }
  100% { transform: translate(12%, 6%) rotate(5deg) scaleY(1.2); }
}
@keyframes bgRays { to { transform: rotate(360deg); } }
@keyframes bgRise { from { transform: translateY(8%); } to { transform: translateY(-12%); } }

/* Respect users who ask for less motion — keep the colour, drop the animation */
@media (prefers-reduced-motion: reduce) {
  #bg-fx, #bg-fx::before, #bg-fx::after { animation: none !important; }
}

/* ── Density (compact / comfortable / spacious) ───────────────────────────── */
html.density-compact  #chat-messages { padding: 10px 12px; gap: 10px; }
html.density-compact  .chat-msg-content { font-size: 12.5px; line-height: 1.45; }
html.density-compact  .rail-item { height: 34px; }
html.density-compact  .widget-header { height: 18px; }
html.density-spacious #chat-messages { padding: 22px 20px; gap: 24px; }
html.density-spacious .chat-msg-content { font-size: 14.5px; line-height: 1.7; }
html.density-spacious .rail-item { height: 46px; }

/* ── Themed confirmation dialog (prismConfirm) ─────────────────────────────── */
.pc-overlay {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .5); backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.pc-overlay.visible { opacity: 1; pointer-events: auto; }
.pc-card {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: calc(var(--radius) + 2px); padding: 20px;
  width: min(420px, calc(100vw - 40px)); box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
  transform: translateY(6px) scale(.98); transition: transform .18s ease;
}
.pc-overlay.visible .pc-card { transform: none; }
.pc-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.pc-msg { font-size: 13px; color: var(--text2); line-height: 1.5; margin-bottom: 18px; }
.pc-actions { display: flex; gap: 8px; justify-content: flex-end; }
.pc-btn {
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--border2);
  font-size: 13px; cursor: pointer; background: var(--bg3); color: var(--text);
  transition: background .12s, border-color .12s, color .12s, filter .12s;
}
.pc-btn:hover { background: var(--bg4); }
.pc-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pc-btn-cancel { background: transparent; color: var(--text2); }
.pc-btn-cancel:hover { background: var(--bg3); color: var(--text); }
.pc-btn-confirm { background: var(--accent); border-color: var(--accent); color: #fff; }
.pc-btn-confirm:hover { background: var(--accent); filter: brightness(1.08); }
.pc-btn-danger { background: #e5484d; border-color: #e5484d; color: #fff; }
.pc-btn-danger:hover { background: #e5484d; filter: brightness(1.08); }
