/* =====================================================================
   Cloudflare OS, sliced — Graphite & Ember shell
   Tokens mirror theserverless.dev. One flat ember accent. No gradients.
   ===================================================================== */

:root {
  --ember: #c2410c;
  --ember-2: #e2622e;
  --ember-rgb: 194, 65, 12;
  --font-heading: "Bricolage Grotesque", "Space Grotesk", system-ui, sans-serif;
  --font-body: "Hanken Grotesk", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --fast: 0.16s cubic-bezier(0.4, 0, 0.2, 1);
  --normal: 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  --topbar-h: 56px;
  --rail-w: 56px;
  --chat-w: 400px;
}

:root, [data-theme="dark"] {
  --bg: #0e0e11;
  --bg-rgb: 14, 14, 17;
  --surface: #141418;
  --surface-2: #1b1b20;
  --surface-3: #232329;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --text: #c9c9c4;
  --text-strong: #e8e8e4;
  --muted: #8a8a85;
  --accent-text: #e2622e;
  --ember-soft: rgba(194, 65, 12, 0.14);
  --ok: #5aa877;
  --warn: #d19a2a;
  --danger: #d0533f;
  --shadow: rgba(0, 0, 0, 0.55);
  --mesh: rgba(255, 255, 255, 0.035);
}

[data-theme="light"] {
  --ember: #b23a0a;
  --ember-2: #c2410c;
  --ember-rgb: 178, 58, 10;
  --bg: #faf9f6;
  --bg-rgb: 250, 249, 246;
  --surface: #ffffff;
  --surface-2: #f3f1eb;
  --surface-3: #ebe8e0;
  --border: rgba(23, 23, 26, 0.1);
  --border-strong: rgba(23, 23, 26, 0.2);
  --text: #3d3a34;
  --text-strong: #17171a;
  --muted: #6b675e;
  --accent-text: #b23a0a;
  --ember-soft: rgba(178, 58, 10, 0.09);
  --ok: #2f7d4f;
  --warn: #a86f0a;
  --danger: #b43d2b;
  --shadow: rgba(23, 23, 26, 0.12);
  --mesh: rgba(23, 23, 26, 0.04);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}
h1, h2, h3, h4 { font-family: var(--font-heading); color: var(--text-strong); letter-spacing: -0.02em; line-height: 1.12; }
a { color: var(--text-strong); text-decoration: none; }
a:hover { color: var(--accent-text); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
code, kbd, .mono { font-family: var(--font-mono); }
code {
  font-size: 0.86em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.08em 0.36em;
  color: var(--text-strong);
}
.icon { width: 18px; height: 18px; flex-shrink: 0; display: block; }
.icon-sm { width: 14px; height: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; }
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------ boot */
.boot { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; }
.boot__mark { color: var(--accent-text); animation: boot-pulse 1.4s ease-in-out infinite; }
.boot__text { font: 500 12px/1 var(--font-mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
@keyframes boot-pulse { 50% { transform: scale(0.94); opacity: 0.7; } }

/* ------------------------------------------------------------ shared controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45em;
  height: 34px; padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  color: var(--text-strong);
  font-weight: 600; font-size: 13px; white-space: nowrap;
  transition: border-color var(--fast), background-color var(--fast), color var(--fast), transform var(--fast);
}
.btn:hover { border-color: rgba(var(--ember-rgb), 0.6); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--ember); border-color: var(--ember); color: #fff; }
.btn-primary:hover { background: var(--ember-2); border-color: var(--ember-2); color: #fff; }
.btn-ghost { border-color: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--text-strong); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-sm { height: 28px; padding: 0 9px; font-size: 12px; }
.icon-btn {
  width: 34px; height: 34px; display: inline-grid; place-items: center;
  border-radius: var(--radius-sm); color: var(--text);
  border: 1px solid transparent;
  transition: background-color var(--fast), color var(--fast), border-color var(--fast);
  position: relative;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-strong); }
.icon-btn[aria-pressed="true"] { color: var(--accent-text); background: var(--ember-soft); }
.badge {
  position: absolute; top: 2px; right: 1px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 99px; background: var(--ember); color: #fff;
  font: 600 10px/16px var(--font-mono); text-align: center;
}
.chip {
  display: inline-flex; align-items: center; gap: 0.35em;
  font: 500 11px/1 var(--font-mono);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.38em 0.7em;
  white-space: nowrap;
}
.chip--ember { color: var(--accent-text); border-color: rgba(var(--ember-rgb), 0.35); background: var(--ember-soft); }
.chip--ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.chip--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.chip--warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.eyebrow {
  display: inline-flex; align-items: center; gap: 0.55rem;
  font: 500 11px/1 var(--font-mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent-text);
}
.eyebrow--rule::before { content: ""; width: 1.6rem; height: 1px; background: var(--ember); }
.muted { color: var(--muted); }
.kbd { font: 500 11px/1 var(--font-mono); padding: 3px 5px; border: 1px solid var(--border-strong); border-radius: 4px; color: var(--muted); }
.switch {
  position: relative; width: 34px; height: 20px; border-radius: 99px; flex-shrink: 0;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  transition: background-color var(--fast), border-color var(--fast);
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); transition: transform var(--fast), background-color var(--fast);
}
.switch[aria-checked="true"] { background: var(--ember); border-color: var(--ember); }
.switch[aria-checked="true"]::after { transform: translateX(14px); background: #fff; }

/* ------------------------------------------------------------ layout */
.os {
  position: relative;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  height: 100dvh;
  isolation: isolate;
}
.os::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: linear-gradient(var(--mesh) 1px, transparent 1px), linear-gradient(90deg, var(--mesh) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(120% 80% at 70% 0%, #000, transparent 70%);
  -webkit-mask-image: radial-gradient(120% 80% at 70% 0%, #000, transparent 70%);
}

/* ------------------------------------------------------------ top bar */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 12px 0 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(var(--bg-rgb), 0.86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  min-width: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.brand .logo-mark { color: var(--accent-text); transition: transform var(--fast); transform-origin: 62% 60%; }
.brand:hover .logo-mark { transform: rotate(-8deg) scale(1.05); }
.brand__word { font: 800 15px/1 var(--font-heading); letter-spacing: -0.03em; color: var(--text-strong); }
.brand__tld { color: var(--accent-text); }
.crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.crumbs__sep { color: var(--border-strong); font-size: 18px; font-weight: 300; }
.crumbs__app { display: inline-flex; align-items: baseline; gap: 7px; font: 700 15px/1 var(--font-heading); color: var(--text-strong); white-space: nowrap; }
.crumbs__app a { color: var(--muted); font-weight: 600; }
.crumbs__app a:hover { color: var(--accent-text); }
.ws-title {
  min-width: 60px; max-width: 280px; width: 100%;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 5px 8px; color: var(--text); font-size: 14px; font-weight: 500;
  text-overflow: ellipsis;
}
.ws-title:hover { border-color: var(--border); }
.ws-title:focus { outline: none; border-color: rgba(var(--ember-rgb), 0.55); background: var(--surface); color: var(--text-strong); }
.top-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.conn { display: inline-flex; align-items: center; gap: 7px; font: 500 11px/1 var(--font-mono); color: var(--muted); padding: 0 8px; letter-spacing: 0.04em; text-transform: uppercase; }
.conn__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.conn[data-state="live"] .conn__dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.conn[data-state="connecting"] .conn__dot { background: var(--warn); animation: blink 1s steps(2) infinite; }
.conn[data-state="offline"] .conn__dot { background: var(--danger); }
@keyframes blink { 50% { opacity: 0.3; } }
.presence { display: flex; align-items: center; padding: 0 6px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font: 700 10px/1 var(--font-mono); color: #fff;
  border: 2px solid var(--bg);
  margin-left: -7px;
  cursor: default;
}
.avatar:first-child { margin-left: 0; }
.avatar--me { outline: 1px solid var(--text-strong); outline-offset: 1px; }
.cost { cursor: default; }
.top-divider { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }

/* ------------------------------------------------------------ main */
.main {
  display: grid;
  grid-template-columns: var(--rail-w) var(--chat-w) 1px minmax(0, 1fr);
  min-height: 0;
  position: relative;
}
.os[data-chat="closed"] .main { grid-template-columns: var(--rail-w) 0 0 minmax(0, 1fr); }
.os[data-chat="closed"] .chat { visibility: hidden; }

.rail {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 0;
  border-right: 1px solid var(--border);
  background: rgba(var(--bg-rgb), 0.6);
}
.rail__spacer { flex: 1; }
.rail .icon-btn { width: 38px; height: 38px; }
.rail__sep { width: 22px; height: 1px; background: var(--border); margin: 6px 0; }

[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  background: var(--text-strong); color: var(--bg);
  font: 600 12px/1 var(--font-body); padding: 7px 9px; border-radius: 6px; white-space: nowrap;
  pointer-events: none; z-index: 50;
}
.topbar [data-tip]:hover::after { left: 50%; top: calc(100% + 8px); transform: translateX(-50%); }

.splitter { background: var(--border); position: relative; cursor: col-resize; z-index: 5; }
.splitter::after { content: ""; position: absolute; inset: 0 -4px; }
.splitter:hover, .splitter.dragging { background: var(--ember); }

/* ------------------------------------------------------------ chat */
.chat { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-height: 0; min-width: 0; background: rgba(var(--bg-rgb), 0.5); overflow: hidden; }
.pane-head {
  display: flex; align-items: center; gap: 10px;
  height: 48px; padding: 0 16px;
  border-bottom: 1px solid var(--border);
}
.pane-head h2 { font-size: 16px; }
.pane-head__spacer { flex: 1; }
.agent-status {
  position: relative; height: 2px; overflow: hidden; background: transparent;
}
.chat[data-busy="true"] .agent-status { background: var(--border); }
.chat[data-busy="true"] .agent-status::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 30%; background: var(--ember);
  animation: scan 1.1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
@keyframes scan { from { left: -30%; } to { left: 100%; } }

.messages { overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.msg { display: flex; flex-direction: column; gap: 5px; max-width: 100%; }
.is-new { animation: rise 0.22s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
.msg__meta { display: flex; align-items: center; gap: 7px; font: 500 11px/1 var(--font-mono); color: var(--muted); letter-spacing: 0.02em; }
.msg__dot { width: 8px; height: 8px; border-radius: 50%; }
.msg__body { color: var(--text); font-size: 14.5px; overflow-wrap: anywhere; }
.msg__body p + p, .msg__body p + ul, .msg__body ul + p { margin-top: 0.5em; }
.msg__body ul { padding-left: 1.1em; list-style: none; }
.msg__body li { position: relative; margin: 0.2em 0; }
.msg__body li::before { content: ""; position: absolute; left: -0.95em; top: 0.62em; width: 5px; height: 5px; background: var(--ember); }
.msg__body strong { color: var(--text-strong); font-weight: 650; }
.msg--user { align-items: flex-end; }
.msg--user .msg__body {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 9px 12px; border-radius: 12px 12px 3px 12px; color: var(--text-strong); max-width: 92%;
}
.msg--assistant .msg__meta .logo-mark { color: var(--accent-text); }
.msg--system { align-items: center; }
.msg--system .msg__body { font: 400 11.5px/1.45 var(--font-mono); color: var(--muted); text-align: center; max-width: 92%; }
.tool {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 4px 10px;
  border: 1px solid var(--border); border-left: 2px solid var(--ember);
  border-radius: var(--radius-sm); padding: 8px 10px; background: var(--surface);
  font-size: 12.5px;
}
.tool[data-ok="false"] { border-left-color: var(--danger); }
.tool__icon { color: var(--accent-text); }
.tool[data-ok="false"] .tool__icon { color: var(--danger); }
.tool__name { font: 600 12px/1.2 var(--font-mono); color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool__args, .tool__result { grid-column: 2 / 4; font: 400 11px/1.45 var(--font-mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool__result { color: var(--text); opacity: 0.8; }
.tool__open { font: 600 11px/1 var(--font-mono); color: var(--accent-text); }
.tool__open:hover { text-decoration: underline; }

.composer { border-top: 1px solid var(--border); padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 10px; background: rgba(var(--bg-rgb), 0.7); }
.suggestions { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.suggestions::-webkit-scrollbar { display: none; }
.suggestion {
  flex-shrink: 0; font-size: 12.5px; color: var(--text);
  border: 1px solid var(--border); border-radius: 99px; padding: 5px 11px;
  transition: border-color var(--fast), color var(--fast);
}
.suggestion:hover { border-color: rgba(var(--ember-rgb), 0.55); color: var(--text-strong); }
.composer__box {
  display: flex; align-items: flex-end; gap: 8px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface);
  padding: 6px 6px 6px 12px;
  transition: border-color var(--fast);
}
.composer__box:focus-within { border-color: rgba(var(--ember-rgb), 0.65); }
.composer textarea {
  flex: 1; resize: none; border: none; outline: none; background: transparent;
  max-height: 160px; min-height: 24px; padding: 5px 0; font-size: 14.5px; color: var(--text-strong);
}
.composer textarea::placeholder { color: var(--muted); }
.composer__send { width: 34px; height: 34px; border-radius: 8px; background: var(--ember); color: #fff; display: grid; place-items: center; flex-shrink: 0; }
.composer__send:hover { background: var(--ember-2); }
.composer__send:disabled { opacity: 0.45; cursor: not-allowed; }
.composer__foot { display: flex; justify-content: space-between; gap: 8px; font: 400 11px/1.3 var(--font-mono); color: var(--muted); }

/* ------------------------------------------------------------ gadget pane */
.gadgets { display: grid; grid-template-rows: auto auto minmax(0, 1fr); min-height: 0; min-width: 0; position: relative; }
.tabs {
  display: flex; align-items: stretch; gap: 2px; height: 48px; padding: 0 10px;
  border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  padding: 0 8px 0 12px; color: var(--muted); font-weight: 600; font-size: 13.5px; white-space: nowrap;
  border-radius: 8px 8px 0 0;
  transition: color var(--fast), background-color var(--fast);
}
.tab:hover { color: var(--text-strong); background: var(--surface); }
.tab[aria-selected="true"] { color: var(--text-strong); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--ember); }
.tab[aria-selected="true"] .tab__icon { color: var(--accent-text); }
.tab__ver { font: 500 10px/1 var(--font-mono); color: var(--muted); }
.tab__close { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 5px; color: var(--muted); opacity: 0; }
.tab:hover .tab__close, .tab[aria-selected="true"] .tab__close { opacity: 1; }
.tab__close:hover { background: var(--surface-3); color: var(--text-strong); }
.tab-add { align-self: center; margin-left: 4px; }
.tab.flash { animation: tabflash 0.9s ease-out; }
@keyframes tabflash { 0% { background: var(--ember-soft); } 100% { background: transparent; } }

.subbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 14px; border-bottom: 1px solid var(--border); min-height: 46px;
}
.seg { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.seg button { height: 26px; padding: 0 11px; border-radius: 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.seg button:hover { color: var(--text-strong); }
.seg button[aria-selected="true"] { background: var(--surface-3); color: var(--text-strong); }
.subbar__meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-left: auto; min-width: 0; }
.subbar__meta .chip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

.pane-body { position: relative; min-height: 0; overflow: hidden; grid-row: 3; }
.tabs { grid-row: 1; }
.subbar { grid-row: 2; }
.view { position: absolute; inset: 0; overflow: auto; }
.view[hidden] { display: none; }
.frame-host { position: absolute; inset: 0; }
.frame-host iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--bg); }
.frame-host iframe[hidden] { display: none; }
.frame-overlay {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px;
  background: rgba(var(--bg-rgb), 0.82); backdrop-filter: blur(2px); z-index: 2;
  font: 500 12px/1 var(--font-mono); color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase;
  animation: fade 0.2s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--ember); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.approval-banner {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 12px;
  max-width: min(560px, calc(100% - 28px));
  background: var(--surface); border: 1px solid rgba(var(--ember-rgb), 0.5); border-left: 3px solid var(--ember);
  border-radius: var(--radius); padding: 10px 10px 10px 14px;
  box-shadow: 0 12px 32px var(--shadow);
  animation: rise 0.25s ease-out;
}
.approval-banner__text { font-size: 13px; color: var(--text-strong); min-width: 0; }
.approval-banner__text span { display: block; font: 400 11px/1.4 var(--font-mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------ empty state */
.empty { max-width: 1040px; margin: 0 auto; padding: 44px 28px 60px; }
.empty h1 { font-size: clamp(28px, 4vw, 42px); letter-spacing: -0.035em; margin: 14px 0 10px; }
.empty h1 .accent { color: var(--accent-text); }
.empty__lede { max-width: 60ch; color: var(--muted); font-size: 16px; }
.bp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-top: 28px; }
.bp {
  position: relative; text-align: left; display: flex; flex-direction: column; gap: 10px;
  padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface);
  transition: transform var(--normal), border-color var(--normal), box-shadow var(--normal);
  overflow: hidden;
}
.bp::after { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: var(--ember); transform: scaleX(0); transform-origin: left; transition: transform var(--normal); }
.bp:hover { transform: translateY(-3px); border-color: rgba(var(--ember-rgb), 0.4); box-shadow: 0 10px 22px var(--shadow); }
.bp:hover::after { transform: scaleX(1); }
.bp__icon { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; background: var(--ember-soft); color: var(--accent-text); }
.bp__title { font: 700 17px/1.2 var(--font-heading); color: var(--text-strong); letter-spacing: -0.02em; }
.bp__desc { font-size: 13px; color: var(--muted); flex: 1; }
.bp__foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.bp__cta { font: 600 12px/1 var(--font-body); color: var(--text-strong); display: inline-flex; align-items: center; gap: 5px; }
.bp:hover .bp__cta { color: var(--accent-text); }
.bp--agent { border-style: dashed; background: transparent; }

.arch { margin-top: 40px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); padding: 20px; }
.arch__head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.arch__head h3 { font-size: 18px; }
.flow { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0; align-items: stretch; }
.node {
  position: relative; border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 10px 11px;
  background: var(--bg); min-width: 0; transition: border-color 0.4s, background-color 0.4s;
}
.node + .node { margin-left: 22px; }
.node + .node::before {
  content: ""; position: absolute; left: -23px; top: 50%; width: 22px; height: 1px; background: var(--border-strong);
}
.node + .node::after {
  content: ""; position: absolute; left: -7px; top: calc(50% - 3px); border: 3px solid transparent; border-left-color: var(--border-strong); border-left-width: 5px;
}
.node__label { font: 500 10px/1.2 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent-text); }
.node__title { font: 700 13.5px/1.25 var(--font-heading); color: var(--text-strong); margin-top: 5px; }
.node__sub { font: 400 11px/1.35 var(--font-mono); color: var(--muted); margin-top: 4px; overflow-wrap: anywhere; }
.node.hot { border-color: var(--ember); background: var(--ember-soft); transition: none; }
.node.hot + .node::before, .node.hot + .node::after { background: var(--ember); border-left-color: var(--ember); }
.flow-notes { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 22px; margin-top: 18px; }
.flow-note { font-size: 13px; color: var(--muted); }
.flow-note strong { color: var(--text-strong); font-weight: 600; }

/* ------------------------------------------------------------ code view */
.code { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100%; }
.code__bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.code__note { font: 400 11.5px/1.3 var(--font-mono); color: var(--muted); flex: 1; min-width: 180px; }
.editor { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); min-height: 0; background: var(--surface); }
.editor__gutter {
  padding: 14px 10px 14px 14px; text-align: right; user-select: none; overflow: hidden;
  font: 400 12.5px/1.6 var(--font-mono); color: var(--muted); opacity: 0.6; border-right: 1px solid var(--border);
  white-space: pre;
}
.editor textarea {
  border: 0; outline: 0; resize: none; background: transparent; padding: 14px 16px;
  font: 400 12.5px/1.6 var(--font-mono); color: var(--text-strong); white-space: pre; overflow: auto; tab-size: 2;
}
.dirty-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ember); display: inline-block; }

/* ------------------------------------------------------------ panels (connections / storage / drawers) */
.panel { max-width: 920px; margin: 0 auto; padding: 22px 22px 48px; display: flex; flex-direction: column; gap: 16px; }
.panel__intro { color: var(--muted); font-size: 14px; max-width: 70ch; }
.card { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); padding: 16px; }
.card__head { display: flex; align-items: center; gap: 12px; }
.card__head h3 { font-size: 16px; }
.card__icon { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--accent-text); flex-shrink: 0; }
.card__desc { font-size: 13px; color: var(--muted); margin-top: 10px; }
.card__rows { margin-top: 12px; display: flex; flex-direction: column; border-top: 1px solid var(--border); }
.row-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.row-toggle:last-child { border-bottom: 0; }
.row-toggle small { display: block; font: 400 11px/1.4 var(--font-mono); color: var(--muted); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); margin-top: 10px; }
table { border-collapse: collapse; width: 100%; font: 400 12px/1.45 var(--font-mono); }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
th { color: var(--muted); font-weight: 500; background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td { color: var(--text-strong); }
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; min-width: 120px; background: var(--surface); }
.stat__v { font: 700 20px/1.1 var(--font-heading); color: var(--text-strong); letter-spacing: -0.02em; }
.stat__l { font: 500 10.5px/1.3 var(--font-mono); color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 3px; }
.live-pill { display: inline-flex; align-items: center; gap: 6px; font: 500 11px/1 var(--font-mono); color: var(--muted); }
.live-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.live-pill.pulse::before { animation: livepulse 0.6s ease-out; }
@keyframes livepulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); } 100% { box-shadow: 0 0 0 8px transparent; } }

.drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(440px, 100%); z-index: 15;
  background: var(--bg); border-left: 1px solid var(--border);
  display: grid; grid-template-rows: auto minmax(0, 1fr);
  box-shadow: -18px 0 40px var(--shadow);
  transform: translateX(104%); transition: transform var(--normal);
  visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
.drawer__body { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.section-label { font: 500 11px/1 var(--font-mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.action {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: var(--surface);
  display: flex; flex-direction: column; gap: 8px;
}
.action--pending { border-color: rgba(var(--ember-rgb), 0.5); border-left: 3px solid var(--ember); }
.action__top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.action__title { font-weight: 650; color: var(--text-strong); font-size: 14px; }
.action__detail { font: 400 11.5px/1.45 var(--font-mono); color: var(--muted); overflow-wrap: anywhere; }
.action__buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.history { display: flex; flex-direction: column; }
.history__row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 2px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.history__row .mono { font-size: 11px; color: var(--muted); }
.history__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }

.trace { display: flex; flex-direction: column; font: 400 12px/1.35 var(--font-mono); }
.trace__row { display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 7px 2px; border-bottom: 1px solid var(--border); }
.trace__time { color: var(--muted); font-size: 11px; }
.trace__call { color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trace__call .via { color: var(--muted); }
.trace__ms { color: var(--muted); font-size: 11px; text-align: right; }
.trace__row[data-ok="false"] .trace__call { color: var(--danger); }
.trace__row[data-via="gatekeeper"] .trace__call::before { content: "⇢ "; color: var(--accent-text); }
.mini-flow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mini-flow .node + .node { margin-left: 0; }
.mini-flow .node + .node::before, .mini-flow .node + .node::after { display: none; }

/* ------------------------------------------------------------ modal + toast */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 60; display: grid; place-items: center; padding: 20px; animation: fade 0.18s ease-out; }
.modal {
  width: min(760px, 100%); max-height: calc(100dvh - 40px); overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: 0 30px 60px var(--shadow); padding: 24px;
  animation: rise 0.22s ease-out;
}
.modal__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.modal h2 { font-size: 24px; letter-spacing: -0.03em; }
.modal .bp-grid { margin-top: 18px; }
.compare { width: 100%; margin-top: 14px; }
.compare td, .compare th { white-space: normal; font-family: var(--font-body); font-size: 13px; vertical-align: top; max-width: none; }
.compare td:first-child { color: var(--muted); font-family: var(--font-mono); font-size: 11.5px; }

.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 80; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; background: var(--text-strong); color: var(--bg); padding: 9px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 600; box-shadow: 0 10px 24px var(--shadow); animation: rise 0.2s ease-out; max-width: min(520px, 90vw);
}
.toast--error { background: var(--danger); color: #fff; }

/* ------------------------------------------------------------ mobile */
.mobile-nav { display: none; }
@media (max-width: 1100px) {
  :root { --chat-w: 340px; }
  .brand__word, .conn__label { display: none; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  .os { grid-template-rows: var(--topbar-h) minmax(0, 1fr) 56px; }
  .main { grid-template-columns: minmax(0, 1fr) !important; }
  .rail, .splitter { display: none; }
  .chat, .gadgets { grid-column: 1; grid-row: 1; }
  .os[data-mobile="agent"] .gadgets, .os[data-mobile="gadgets"] .chat { display: none; }
  .os[data-chat="closed"] .chat { visibility: visible; }
  .mobile-nav {
    display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--border); background: rgba(var(--bg-rgb), 0.95);
  }
  .mobile-nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font: 600 10.5px/1 var(--font-body); color: var(--muted); position: relative; }
  .mobile-nav button[aria-selected="true"] { color: var(--accent-text); }
  .mobile-nav .badge { top: 6px; right: calc(50% - 20px); }
  .crumbs__sep, .crumbs__app, .presence, .cost, .top-divider { display: none; }
  .ws-title { max-width: none; }
  .flow { grid-template-columns: 1fr; gap: 18px; }
  .node + .node { margin-left: 0; }
  .node + .node::before { left: 50%; top: -19px; width: 1px; height: 18px; }
  .node + .node::after { display: none; }
  .subbar__meta { display: none; }
  .drawer { width: 100%; }
  .empty { padding: 28px 16px 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
