/* ===========================================================
   AGENT HUD — vanilla boilerplate
   Same HTML/JS for desktop + mobile. CSS media queries handle layout.
   =========================================================== */

:root {
  --bg:        #0a0a0c;
  --bg-2:      #0e0e11;
  --bg-3:      #15151a;
  --bg-4:      #1a1a20;
  --border:    #1f1f25;
  --border-2:  #2c2c34;
  --text:      #d7d7db;
  --text-dim:  #8a8a94;
  --text-faint:#5e5e68;

  --accent:        #6ea1ff;
  --accent-soft:   #3a5a9c;
  --accent-text:   #c8d8ff;

  --green:     #6ce098;
  --yellow:    #f6c177;
  --red:       #ff6b6b;

  --mono: 'JetBrains Mono','IBM Plex Mono','SF Mono',ui-monospace,Menlo,monospace;
  --sans: 'Inter',system-ui,-apple-system,'Segoe UI',sans-serif;

  --rail-w: 240px;
  --rail-w-collapsed: 44px;
  --tabs-w: 40vw;
  --tabs-w-collapsed: 44px;
  --top-h:  56px;
  --foot-h: 56px;
  --slide-ms: 360ms;
  --slide-curve: cubic-bezier(0.22, 0.8, 0.18, 1);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.5;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===========================================================
   TOP BAR
   =========================================================== */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  height: var(--top-h);
  background: var(--bg);
  position: sticky; top: 0; z-index: 10;
  gap: 12px;
}
.top-left { display: flex; align-items: center; gap: 18px; min-width: 0; }
.agent { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.agent-name { font-size: 15px; font-weight: 600; color: #fff; letter-spacing: -0.005em; }
.build-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-width: 0;
}
.build-toggle input { display: none; }
.toggle-track {
  width: 28px; height: 16px;
  background: var(--bg-4);
  border: 1px solid var(--border-2);
  border-radius: 9px;
  position: relative;
  flex-shrink: 0;
}
.toggle-thumb {
  position: absolute;
  width: 10px; height: 10px;
  background: var(--text-dim);
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: transform 180ms ease, background 180ms ease;
}
.build-toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(12px);
  background: var(--accent);
}
.toggle-label { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.toggle-title { font-size: 12px; color: var(--text); }
.toggle-sub { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 28ch; }

.top-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.meter {
  background: var(--bg-3);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text);
  letter-spacing: 0.03em;
  white-space: nowrap;
  flex-shrink: 0;
}
.meter-sep { color: var(--text-faint); margin: 0 4px; }
.live { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); flex-shrink: 0; }
.live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(108,224,152,0.6);
  animation: livePulse 1.6s ease-out infinite;
}
@keyframes livePulse {
  0%   { box-shadow: 0 0 0 0 rgba(108,224,152,0.5); }
  100% { box-shadow: 0 0 0 7px rgba(108,224,152,0); }
}
.top-btn {
  background: transparent;
  color: var(--text-dim);
  border: 0;
  padding: 6px 9px;
  font-family: var(--sans);
  font-size: 12.5px;
  cursor: pointer;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}
.top-btn:hover { color: var(--accent); background: var(--bg-2); }
.top-btn svg { color: currentColor; }
.top-btn.icon-only { padding: 6px; }

/* ===========================================================
   SHELL — 3 columns (desktop)
   =========================================================== */
.shell {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr var(--tabs-w);
  height: calc(100vh - var(--top-h));
  height: calc(100dvh - var(--top-h));
}

/* RAIL — collapsible */
.rail {
  border-right: 1px solid var(--border);
  background: var(--bg);
  padding: 18px 14px 18px 44px;          /* leave room for collapse button */
  overflow-y: auto;
  position: relative;
  transition: width var(--slide-ms) var(--slide-curve), padding var(--slide-ms) var(--slide-curve);
}
.rail-collapse {
  position: absolute;
  top: 8px; left: 8px;
  width: 28px; height: 28px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
.rail-collapse:hover { color: var(--accent); border-color: var(--accent-soft); }
.rail[data-collapsed="false"] .rail-collapse svg {
  transform: rotate(0deg);                 /* chevron-left when expanded → click to collapse */
}
.rail[data-collapsed="true"] .rail-collapse svg {
  transform: rotate(180deg);               /* chevron-right when collapsed → click to expand */
}
.rail[data-collapsed="true"] .rail-content { display: none; }
.rail-content { display: block; }
.rail-section { margin-bottom: 26px; }
.rail-head {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.history, .projects { list-style: none; padding: 0; margin: 0; }
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.history-item:hover { background: var(--bg-2); color: var(--text); }
.history-item.is-current { background: rgba(110,161,255,0.06); color: var(--accent); }
.hi-time { font-family: var(--mono); font-size: 10px; color: var(--text-faint); width: 38px; flex-shrink: 0; }
.hi-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hi-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }
.hi-dot.is-done { background: var(--green); }
.hi-dot.is-running { background: var(--yellow); }
.hi-dot.is-failed { background: var(--red); }

.proj-item {
  padding: 7px 10px;
  font-size: 12.5px;
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
}
.proj-item:hover { background: var(--bg-2); color: var(--text); }
.proj-item-meta { font-family: var(--mono); font-size: 10px; color: var(--text-faint); margin-top: 1px; }

/* ===========================================================
   STAGE — hero orb + voice/chat controls
   =========================================================== */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  background: radial-gradient(ellipse at center, var(--bg-2) 0%, var(--bg) 70%);
  border-right: 1px solid var(--border);
  padding: 24px;
  min-height: 0;
}
.orb-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.orb-wrap { position: relative; transition: transform 200ms ease; }
#orb-canvas {
  width: min(54vh, 480px);
  height: min(54vh, 480px);
  display: block;
}
.orb-wrap:hover { transform: scale(1.012); }
.orb-label {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  min-height: 16px;
}
.orb-label[data-state="listening"] { color: var(--green); }
.orb-label[data-state="thinking"]  { color: var(--yellow); }
.orb-label[data-state="talking"]   { color: var(--accent); }
.orb-label[data-state="confirming"]{ color: var(--yellow); }

.stage-ctrl {
  display: flex;
  gap: 10px;
}
.ctrl {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 22px;
  font-family: var(--sans);
  font-size: 12.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease;
}
.ctrl:hover { color: var(--accent); border-color: var(--accent-soft); }
.ctrl-voice[data-state="on"] {
  background: rgba(108,224,152,0.10);
  border-color: rgba(108,224,152,0.45);
  color: var(--green);
}

/* ===========================================================
   TABS (right column) — collapsible
   =========================================================== */
.shell {
  transition: grid-template-columns var(--slide-ms) var(--slide-curve);
}
/* RAIL collapsed */
.shell[data-rail-collapsed="true"] {
  grid-template-columns: var(--rail-w-collapsed) 1fr var(--tabs-w);
}
/* TABS collapsed */
.shell[data-tabs-collapsed="true"] {
  grid-template-columns: var(--rail-w) 1fr var(--tabs-w-collapsed);
}
/* BOTH collapsed — maximum stage / orb */
.shell[data-rail-collapsed="true"][data-tabs-collapsed="true"] {
  grid-template-columns: var(--rail-w-collapsed) 1fr var(--tabs-w-collapsed);
}
.tabs-wrap {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  transition: width var(--slide-ms) var(--slide-curve);
}
.tabs-collapse {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
  width: 28px; height: 28px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 200ms ease;
}
.tabs-collapse:hover { color: var(--accent); border-color: var(--accent-soft); }
.tabs-wrap[data-collapsed="false"] .tabs-collapse svg {
  transform: rotate(0deg);                 /* chevron-right when expanded → click to collapse */
}
.tabs-wrap[data-collapsed="true"] .tabs-collapse svg {
  transform: rotate(180deg);               /* chevron-left when collapsed → click to expand */
}
.tabs-wrap[data-collapsed="true"] .tabs,
.tabs-wrap[data-collapsed="true"] .tab-viewport,
.tabs-wrap[data-collapsed="true"] .tab-indicator { display: none; }

.tabs {
  display: flex;
  gap: 0;
  padding: 0 14px 0 44px;                  /* leave room for collapse button */
  border-bottom: 1px solid var(--border);
  height: 44px;
  align-items: stretch;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  padding: 0 14px;
  font-family: var(--sans);
  font-size: 13px;
  cursor: pointer;
  position: relative;
  white-space: nowrap;
  transition: color 180ms ease;
  display: flex;
  align-items: center;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); }
.tab-indicator {
  position: absolute;
  top: 43px;
  height: 2px;
  background: var(--accent);
  transition: transform var(--slide-ms) var(--slide-curve), width var(--slide-ms) var(--slide-curve);
  pointer-events: none;
  width: 0;
}

.tab-viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.tab-track {
  display: flex;
  height: 100%;
  transition: transform var(--slide-ms) var(--slide-curve);
  will-change: transform;
}
.tab-panel {
  flex: 0 0 100%;
  height: 100%;
  overflow-y: auto;
  padding: 26px 28px;
}

/* PROJECT panel */
.proj-title {
  font-size: 24px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.02em;
  margin: 4px 0 4px;
}
.proj-id {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  margin-bottom: 24px;
}
.proj-section { margin-bottom: 22px; }
.proj-key {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
  letter-spacing: 0.14em;
  margin-bottom: 7px;
  text-transform: uppercase;
}
.proj-val {
  font-size: 13.5px;
  color: var(--text);
  font-family: var(--mono);
  letter-spacing: 0.02em;
}
.state-job { color: var(--accent); }
.state-status { color: var(--text-dim); }
.dot-sep { color: var(--text-faint); margin: 0 6px; }

.art-pills { display: flex; gap: 7px; flex-wrap: wrap; }
.art-pill {
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 4px 11px;
  border-radius: 13px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.art-pill.is-empty { color: var(--text-faint); background: transparent; }
.art-pill.has {
  color: var(--accent-text);
  border-color: var(--accent-soft);
  background: rgba(110,161,255,0.06);
}

.pipeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.pipe-step {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 12.5px;
  width: fit-content;
  min-width: 180px;
}
.pipe-step.done    { background: rgba(108,224,152,0.07); border-color: rgba(108,224,152,0.35); color: var(--green); }
.pipe-step.running { background: rgba(246,193,119,0.07); border-color: rgba(246,193,119,0.35); color: var(--yellow); }
.pipe-step.failed  { background: rgba(255,107,107,0.07); border-color: rgba(255,107,107,0.35); color: var(--red); }
.pipe-mark { width: 10px; height: 10px; border-radius: 50%; border: 1.4px solid currentColor; flex-shrink: 0; position: relative; }
.pipe-step.done .pipe-mark { background: var(--green); border-color: var(--green); }
.pipe-step.done .pipe-mark::after {
  content: ''; position: absolute; left: 2px; top: 3.5px;
  width: 5px; height: 2px; border-left: 1.5px solid var(--bg); border-bottom: 1.5px solid var(--bg);
  transform: rotate(-45deg);
}
.pipe-step.running .pipe-mark {
  border-color: var(--yellow);
  border-top-color: transparent;
  animation: spin 1.1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.pipe-meta { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); margin-left: 6px; }

.rubric-mini {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 6px 14px;
  align-items: center;
  max-width: 380px;
}
.r-axis { font-family: var(--mono); font-size: 10.5px; color: var(--text-dim); letter-spacing: 0.04em; }
.r-bar { height: 4px; background: var(--bg-3); border-radius: 2px; overflow: hidden; }
.r-bar i { display: block; height: 100%; background: var(--accent); transition: width 360ms ease; }

.empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px;
  height: 100%;
  color: var(--text-dim);
  text-align: center;
}
.empty svg { color: var(--text-faint); }
.empty-title { font-size: 14px; color: var(--text); }
.empty-sub { font-size: 12px; color: var(--text-dim); max-width: 280px; line-height: 1.5; }

pre.logs {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--green);
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.55;
  height: 100%;
  overflow-y: auto;
}

/* ===========================================================
   SIDE SHEET — chat slides in from the LEFT
   =========================================================== */
.sheet {
  position: fixed;
  top: var(--top-h); left: 0; bottom: 0;
  width: 380px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform var(--slide-ms) var(--slide-curve);
  display: flex;
  flex-direction: column;
  z-index: 50;
  box-shadow: 20px 0 40px rgba(0,0,0,0.45);
}
.sheet[data-open="true"] { transform: translateX(0); }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border);
}
.sheet-title { font-size: 12px; font-family: var(--mono); color: var(--text-faint); letter-spacing: 0.16em; text-transform: uppercase; }
.sheet-close {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  padding: 4px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.sheet-close:hover { color: var(--accent); }

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 4px;
}
.transcript { display: flex; flex-direction: column; gap: 12px; padding-bottom: 8px; }
.msg { line-height: 1.55; font-size: 13.5px; max-width: 92%; }
.msg-system { align-self: flex-start; color: var(--text-dim); font-style: italic; max-width: 100%; }
.msg-user {
  align-self: flex-end;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 14px;
  color: #ececec;
}
.msg-agent { align-self: flex-start; color: var(--text); }
.msg-agent .msg-body { white-space: pre-wrap; }
.pills {
  align-self: flex-start;
  display: flex; flex-wrap: wrap; gap: 5px;
  margin: 2px 0;
}
.pill {
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border-2);
  background: var(--bg-3);
  color: var(--text-dim);
}
.pill-skill    { border-color: rgba(108,224,152,0.4); color: var(--green); }
.pill-tool     { border-color: rgba(110,161,255,0.4); color: var(--accent); }
.pill-artifact { border-color: rgba(246,193,119,0.4); color: var(--yellow); }

.composer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}
.cmp-btn, .cmp-send {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  width: 34px; height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.cmp-btn:hover { background: var(--bg-3); color: var(--accent); }
.cmp-send {
  background: var(--bg-3);
  border: 1px solid var(--border);
}
.cmp-send:hover { background: var(--accent); color: var(--bg); border-color: var(--accent); }
#cmp-input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  padding: 8px 6px;
}
#cmp-input::placeholder { color: var(--text-faint); }

/* ===========================================================
   MOBILE FOOTER — edge-to-edge flat bar with raised Talk button.
   Mobile-only — desktop hides this entirely (see @media min-width).
   Order: Chat · New · Project · TALK · Preview · Logs
   =========================================================== */
.mobile-foot {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
.mobile-foot .foot-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 90px 1fr 1fr 1fr;
  height: var(--foot-h);
  align-items: center;
}
.foot-btn {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  padding: 6px 0;
  font-family: var(--sans);
  font-size: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  letter-spacing: 0.04em;
  transition: color 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.foot-btn svg { color: currentColor; width: 20px; height: 20px; }
.foot-btn:active { color: var(--accent); }
.foot-btn.is-active { color: var(--accent); }
.foot-btn.is-active::before {
  content: '';
  position: absolute;
  top: 0; height: 2px; background: var(--accent);
  width: 28px;
  border-radius: 0 0 2px 2px;
  transform: translateX(-50%);
  left: 50%;
}
.foot-btn { position: relative; }
.foot-btn .foot-lbl { white-space: nowrap; opacity: 0.85; }

/* Big raised Talk button in centre — sits ABOVE the bar */
.foot-talk {
  justify-self: center;
  width: 68px; height: 68px;
  border-radius: 50%;
  border: 0;
  background: var(--bg-3);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-top: -28px;                    /* raise above the bar */
  box-shadow: 0 6px 18px rgba(0,0,0,0.5), 0 0 0 5px var(--bg);
  transition: background 200ms ease, color 200ms ease, transform 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.foot-talk:active { transform: scale(0.96); }
.foot-talk[data-state="on"] {
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 6px 24px rgba(110,161,255,0.45), 0 0 0 5px var(--bg);
}
.foot-talk svg { width: 26px; height: 26px; }

/* ===========================================================
   STAGE OVERLAY — content swap on mobile (no drawers)
   When a mobile-menu icon is tapped, the matching tab content
   is mirrored into .stage-overlay; orb hides; tap-same-icon returns.
   =========================================================== */
.stage-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 5;
}
.stage[data-view="orb"] .stage-overlay { display: none; }
.stage:not([data-view="orb"]) .stage-overlay { display: flex; }
.stage:not([data-view="orb"]) .orb-wrap,
.stage:not([data-view="orb"]) .stage-ctrl { display: none; }

.so-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.so-title { font-family: var(--mono); font-size: 11px; color: var(--accent); letter-spacing: 0.16em; text-transform: uppercase; }
.so-body { flex: 1; overflow-y: auto; padding: 16px 20px 24px; }
.so-body .empty { padding-top: 12vh; }

/* ===========================================================
   WIDGET DRAWER — slides in from the right (opposite chat)
   Used by window.HudWidgets.show()
   =========================================================== */
.widget-drawer {
  position: fixed;
  top: var(--top-h); right: 0; bottom: 0;
  width: 420px;
  max-width: 92vw;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform var(--slide-ms) var(--slide-curve);
  display: flex;
  flex-direction: column;
  z-index: 55;
  box-shadow: -20px 0 40px rgba(0,0,0,0.45);
}
.widget-drawer[data-open="true"] { transform: translateX(0); }
.wd-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border);
}
.wd-title-row { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wd-eyebrow { font-family: var(--mono); font-size: 10px; color: var(--text-faint); letter-spacing: 0.16em; text-transform: uppercase; }
.wd-title { font-size: 14px; color: var(--text); font-weight: 500; }
.wd-close {
  background: transparent; border: 0; color: var(--text-dim); cursor: pointer;
  padding: 4px; display: flex; align-items: center; justify-content: center;
}
.wd-close:hover { color: var(--accent); }
.wd-body { flex: 1; overflow-y: auto; padding: 14px 18px; }

/* Widget styles */
.widget-inline { background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 6px 0; }

.w-rich { font-size: 13.5px; color: var(--text); line-height: 1.55; }
.w-rich h3 { font-size: 15px; color: #fff; margin: 10px 0 6px; }
.w-rich h4 { font-size: 13.5px; color: var(--accent); margin: 8px 0 4px; }
.w-rich p { margin: 4px 0 8px; }
.w-rich code { font-family: var(--mono); font-size: 12px; background: var(--bg); padding: 1px 6px; border-radius: 3px; }
.w-rich ul { padding-left: 18px; margin: 6px 0; }
.w-rich li { margin: 2px 0; }

.w-link { display: flex; gap: 12px; text-decoration: none; color: inherit; padding: 10px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; transition: border-color 150ms ease; }
.w-link:hover { border-color: var(--accent-soft); }
.w-link-img { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.w-link-body { min-width: 0; }
.w-link-host { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); letter-spacing: 0.06em; text-transform: uppercase; }
.w-link-title { font-size: 13.5px; color: var(--text); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-link-desc { font-size: 12px; color: var(--text-dim); margin-top: 4px; line-height: 1.45; }

.w-code { background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.w-code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; border-bottom: 1px solid var(--border); background: var(--bg); }
.w-code-lang { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); letter-spacing: 0.06em; text-transform: uppercase; }
.w-code-copy { background: transparent; border: 1px solid var(--border-2); color: var(--text-dim); font-family: var(--mono); font-size: 10.5px; padding: 3px 8px; border-radius: 3px; cursor: pointer; }
.w-code-copy:hover { color: var(--accent); border-color: var(--accent-soft); }
.w-code-body { margin: 0; padding: 12px 14px; }
.w-code code { font-family: var(--mono); font-size: 12px; color: var(--text); }

.w-cal { display: flex; flex-direction: column; gap: 8px; }
.w-cal-empty { color: var(--text-dim); font-style: italic; padding: 16px 0; text-align: center; }
.w-cal-row { display: flex; gap: 12px; padding: 8px 10px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 6px; }
.w-cal-time { display: flex; flex-direction: column; min-width: 60px; }
.w-cal-hr { font-family: var(--mono); font-size: 12px; color: var(--text); }
.w-cal-end { color: var(--text-faint); }
.w-cal-meta { min-width: 0; }
.w-cal-title { font-size: 13px; color: var(--text); }
.w-cal-loc { font-family: var(--mono); font-size: 10.5px; color: var(--text-dim); margin-top: 2px; }

.w-deal { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; }
.w-deal-head { display: flex; justify-content: space-between; align-items: baseline; }
.w-deal-name { font-size: 14px; color: var(--text); font-weight: 500; }
.w-deal-amount { font-family: var(--mono); font-size: 13px; color: var(--accent); }
.w-deal-bar { height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.w-deal-fill { height: 100%; background: var(--accent); transition: width 360ms ease; }
.w-deal-stages { display: flex; gap: 6px; font-family: var(--mono); font-size: 10px; flex-wrap: wrap; color: var(--text-faint); letter-spacing: 0.04em; text-transform: uppercase; }
.w-deal-stage { padding: 2px 7px; border: 1px solid var(--border); border-radius: 9px; }
.w-deal-stage.is-done { color: var(--accent); border-color: var(--accent-soft); background: rgba(110,161,255,0.08); }
.w-deal-meta { display: flex; gap: 16px; font-size: 11.5px; color: var(--text-dim); font-family: var(--mono); }
.w-deal-row { display: flex; gap: 6px; }
.w-dk { color: var(--text-faint); }

.w-notion { background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.w-notion-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.w-notion-title { font-size: 14px; color: var(--text); font-weight: 500; }
.w-notion-link { font-family: var(--mono); font-size: 11px; color: var(--accent); text-decoration: none; }
.w-notion-block { font-size: 12.5px; color: var(--text); padding: 4px 0; border-bottom: 1px dashed var(--border); }
.w-notion-block:last-child { border: 0; }

.w-chart { background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.w-chart-meta { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.w-chart-label { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); letter-spacing: 0.08em; text-transform: uppercase; }
.w-chart-val { font-family: var(--mono); font-size: 13px; color: var(--accent); }
.w-chart svg polyline { stroke: var(--accent); }

.w-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.w-table th, .w-table td { padding: 6px 9px; border-bottom: 1px solid var(--border); text-align: left; }
.w-table th { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); letter-spacing: 0.08em; text-transform: uppercase; }
.w-table td { color: var(--text); }

/* Decision Flow — CONTROL widget (Alfred V4 pattern, per
   docs/blueprints/widget-hud-capability.md). Vertical timeline + NEXT ACTION.
   Not in the data-widget enum; renders as a card in the inline transcript
   OR inside the widget drawer when shown via HudWidgets.show. */
.w-flow {
  background: rgba(14,14,17,0.92);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  padding: 14px 16px 12px;
  margin: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
  font-family: var(--sans);
}
.w-flow-head {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}
.w-flow-glyph {
  width: 28px; height: 28px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}
.w-flow-glyph svg { width: 14px; height: 14px; }
.w-flow-title { font-size: 14px; color: var(--text); font-weight: 500; }
.w-flow-status {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--accent);
  letter-spacing: 0.18em;
  background: rgba(110,161,255,0.08);
  border: 1px solid var(--accent-soft);
  border-radius: 8px;
  padding: 2px 8px;
}
.w-flow-steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.w-flow-step {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 12px;
  padding: 6px 0;
  position: relative;
}
.w-flow-step:not(.is-last)::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 22px;
  bottom: 0;
  width: 1px;
  background: var(--border-2);
}
.w-flow-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--text-faint);
  background: transparent;
  margin-top: 4px;
  flex-shrink: 0;
  z-index: 1;
}
.w-flow-step.is-done .w-flow-dot     { background: var(--green); border-color: var(--green); }
.w-flow-step.is-active .w-flow-dot   { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px rgba(110,161,255,0.16); }
.w-flow-step.is-failed .w-flow-dot   { background: var(--red); border-color: var(--red); }
.w-flow-step.is-pending              { opacity: 0.4; }
.w-flow-body { min-width: 0; }
.w-flow-step-title { font-size: 13px; color: var(--text); line-height: 1.35; }
.w-flow-step-sub   { font-family: var(--mono); font-size: 11px; color: var(--text-faint); margin-top: 2px; letter-spacing: 0.02em; }

.w-flow-next {
  margin-top: 4px;
  padding: 10px 12px;
  background: rgba(160,140,255,0.06);
  border: 1px solid rgba(160,140,255,0.22);
  border-radius: 8px;
}
.w-flow-next-label {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--text-faint);
  letter-spacing: 0.18em;
  margin-bottom: 4px;
}
.w-flow-next-text {
  font-size: 13px;
  color: #c8b9ff;
  line-height: 1.4;
  margin-bottom: 8px;
}
.w-flow-progress {
  height: 2px;
  background: rgba(255,255,255,0.06);
  border-radius: 1px;
  overflow: hidden;
}
.w-flow-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #a08cff 0%, #c8b9ff 100%);
  transition: width 360ms ease;
}

/* Preview-panel loading meta — Canvas pattern. CONTROL widget rendered into
   the preview tab body (NOT the transcript). Self-centring; takes the full
   panel height when active. */
.w-preview-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 50vh;
  width: 100%;
  padding: 40px 24px;
  text-align: center;
}
.w-preview-action {
  font-family: var(--mono);
  font-size: 17px;
  color: var(--text);
  letter-spacing: 0.005em;
  line-height: 1.4;
  max-width: 480px;
}
.w-preview-elapsed {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}
.w-preview-sub {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  max-width: 420px;
  line-height: 1.5;
  min-height: 1em;             /* keep layout stable when sub_step is empty */
}

/* Inline action buttons (Canvas-style approval / quick-actions) */
.w-action-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 6px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.w-action-prompt {
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
}
.w-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.w-action-btn {
  background: var(--bg);
  border: 1px solid var(--border-2);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12.5px;
  padding: 6px 14px;
  border-radius: 16px;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease, opacity 150ms ease;
}
.w-action-btn:hover { color: var(--accent); border-color: var(--accent-soft); }
.w-action-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.w-action-btn.is-primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.w-action-btn.is-primary:hover { color: var(--bg); border-color: var(--accent); }
.w-action-btn.is-danger  { color: var(--red); border-color: rgba(255,107,107,0.45); }
.w-action-btn.is-claimed { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent-soft); opacity: 1; }

/* Thinking / decision-log message — styled reasoning bubble between user msg and tool pills */
.msg-thinking {
  align-self: flex-start;
  background: rgba(110,161,255,0.04);
  border: 1px dashed var(--border-2);
  border-radius: 10px;
  padding: 8px 12px;
  max-width: 95%;
  font-size: 12.5px;
  color: var(--text-dim);
}
.think-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.think-glyph { color: var(--accent); font-size: 11px; }
.think-title { color: var(--text-faint); }
.msg-thinking .msg-body { display: flex; flex-direction: column; gap: 4px; }
.think-row { display: flex; gap: 8px; align-items: baseline; }
.think-label {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--accent);
  letter-spacing: 0.04em;
  min-width: 88px;
  flex-shrink: 0;
}
.think-detail { color: var(--text); font-size: 12.5px; line-height: 1.5; }

.w-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.w-list-row { display: flex; gap: 10px; align-items: flex-start; padding: 6px 10px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 6px; }
.w-list-mark { width: 10px; height: 10px; border: 1.4px solid var(--text-dim); border-radius: 50%; margin-top: 4px; flex-shrink: 0; }
.w-list-row.is-done .w-list-mark { background: var(--green); border-color: var(--green); }
.w-list-row.is-done .w-list-text { color: var(--text-dim); text-decoration: line-through; }
.w-list-text { font-size: 13px; color: var(--text); }
.w-list-sub { font-family: var(--mono); font-size: 11px; color: var(--text-faint); margin-top: 2px; }

/* ===========================================================
   MOBILE (≤760px) — PWA-style cleanup
   =========================================================== */
@media (max-width: 760px) {
  :root { --top-h: 50px; --foot-h: 60px; }

  /* TOP BAR: collapse to essentials */
  .top { padding: 7px 12px; gap: 8px; }
  .top-left { gap: 10px; }
  .agent-name { font-size: 14px; }
  .build-toggle { gap: 6px; }
  .toggle-label { display: none; }       /* hide title + sub on mobile */
  .live-label { display: none; }         /* dot only */
  .top-btn .top-btn-label { display: none; }      /* icon-only buttons */
  .top-btn { padding: 6px; }
  .meter {
    font-size: 11px;
    padding: 4px 8px;
    /* compact: time/cost stacked is what was wrapping. Force single line. */
    display: flex; gap: 4px;
  }
  .meter-sep { display: none; }
  #meter-cost { font-size: 10.5px; color: var(--accent); }

  /* SHELL: single-column stack — orb hero + tabs below */
  .shell {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    padding-bottom: var(--foot-h);
  }
  .rail { display: none; }                       /* hidden on mobile; lives in drawer */
  .stage {
    flex: 0 0 auto;
    min-height: 40dvh;
    padding: 16px 16px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    gap: 12px;
  }
  #orb-canvas { width: min(36dvh, 70vw); height: min(36dvh, 70vw); }

  /* DECLUTTER MOBILE — footer is the source of truth for panels/drawers */
  /* Hide header buttons that are redundant on mobile (new-chat lives in
     footer; open-chat is the footer's Chat icon; prompts is desktop-only) */
  #btn-prompts,
  #btn-new-chat,
  #btn-open-chat-top { display: none; }

  /* Hide under-orb stage controls — footer TALK + footer Chat cover both */
  .stage-ctrl { display: none; }

  /* Hide collapse chevrons — the footer nav opens/closes the right panel */
  .rail-collapse,
  .tabs-collapse { display: none; }
  /* Reclaim the space the chevrons reserved */
  .rail { padding-left: 14px; }
  .tabs { padding-left: 14px; }

  /* TABS WRAP — fully hidden on mobile. The footer buttons swap the same
     content into the stage-overlay; the inline tab-strip + stacked panels
     would just duplicate that path. */
  .tabs-wrap { display: none; }
  /* Stage gets the whole canvas; remove the lower border that used to sit
     above the now-removed tabs-wrap */
  .stage { flex: 1; border-bottom: 0; }

  /* Tighter foot-btn padding now that 7 cells share the row */
  .foot-btn { font-size: 9.5px; padding: 6px 0 4px; }
  .foot-btn svg { width: 18px; height: 18px; }

  /* PANEL CONTENT INSIDE STAGE OVERLAY — make every panel fit a small
     viewport. The same .tab-panel elements get moved here on view-swap. */
  .so-body .tab-panel { padding: 0; }
  .so-body .proj-title { font-size: 19px; margin-top: 0; }
  .so-body .proj-id { margin-bottom: 18px; }
  .so-body .proj-section { margin-bottom: 18px; }
  .so-body .pipe-step { min-width: 0; width: 100%; }
  .so-body .rubric-mini {
    grid-template-columns: 92px 1fr;
    gap: 6px 10px;
    max-width: none;
  }
  .so-body .empty { padding: 12vh 12px; }
  .so-body pre.logs { font-size: 10.5px; }

  /* Chat sheet DISABLED on mobile — chat is now an in-stage view via footer icon */
  .sheet { display: none !important; }
  /* Widget drawer becomes a bottom sheet, still respects footer */
  .widget-drawer {
    top: auto;
    bottom: calc(var(--foot-h) + env(safe-area-inset-bottom));
    width: 100vw;
    height: 70dvh;
    border-left: 0;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    transform: translateY(100%);
  }
  .widget-drawer[data-open="true"] { transform: translateY(0); }

  /* MOBILE FOOTER — show */
  .mobile-foot { display: block; }

  /* Stage gets relative-positioned so the overlay can absolute-fill */
  .stage { position: relative; }
  /* When stage is not on orb-view, the overlay fills it completely (orb hides) */
  .stage:not([data-view="orb"]) { background: var(--bg); }

  /* Mobile composer placement — when chat view is active, composer sticks to bottom of stage */
  .so-composer-slot {
    margin: 14px -16px -16px;
    border-top: 1px solid var(--border);
    background: var(--bg-2);
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  }
  .so-composer-slot .composer {
    padding: 6px 4px;
    background: transparent;
    border-top: 0;
  }

  /* Body padding-bottom so footer doesn't cover stage content */
  .shell { padding-bottom: calc(var(--foot-h) + env(safe-area-inset-bottom)); }
}

/* ===========================================================
   DESKTOP — hide mobile foot
   =========================================================== */
@media (min-width: 761px) {
  .mobile-foot { display: none; }
}
