:root {
  --bg: #ffffff;
  --panel: #f6f8fa;
  --panel-2: #eef1f5;
  --border: #d1d9e0;
  --text: #1f2328;
  --muted: #59636e;
  --muted-2: #8b949e;
  --accent: #0969da;
  --green: #1a7f37;
  --yellow: #9a6700;
  --red: #cf222e;
  --accent-soft: rgba(9, 105, 218, 0.08);
  --accent-border: rgba(9, 105, 218, 0.28);
  --green-soft: rgba(26, 127, 55, 0.08);
  --green-border: rgba(26, 127, 55, 0.3);
  --red-soft: rgba(207, 34, 46, 0.08);
  --red-border: rgba(207, 34, 46, 0.28);
  --surface-soft: rgba(0, 0, 0, 0.03);
  --topbar-bg: rgba(255, 255, 255, 0.96);
  --left-gradient-a: rgba(255, 255, 255, 0.96);
  --left-gradient-b: rgba(246, 248, 250, 1);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'SF Mono', 'Fira Code', monospace;
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #101319;
  --border: #2a303b;
  --text: #edf2f7;
  --muted: #98a2b3;
  --muted-2: #98a2b3;
  --accent: #59a4ff;
  --green: #2fb86e;
  --yellow: #d4a132;
  --red: #e05d6f;
  --accent-soft: rgba(89, 164, 255, 0.12);
  --accent-border: rgba(89, 164, 255, 0.3);
  --green-soft: rgba(47, 184, 110, 0.12);
  --green-border: rgba(47, 184, 110, 0.45);
  --red-soft: rgba(224, 93, 111, 0.1);
  --red-border: rgba(224, 93, 111, 0.45);
  --surface-soft: rgba(255, 255, 255, 0.03);
  --topbar-bg: rgba(15, 17, 21, 0.96);
  --left-gradient-a: rgba(23, 26, 33, 0.95);
  --left-gradient-b: rgba(16, 19, 25, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
body { min-height: 100vh; overflow: hidden; }
#builder-app { min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; }

.b-shell { min-height: 100vh; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.b-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.b-brand { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.b-brand a { color: var(--muted); }
.b-brand strong { display: block; font-size: 15px; }
.b-brand span { color: var(--muted); font-size: 12px; }
.b-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; }
.b-btn, .b-select, .b-input {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.b-btn {
  padding: 8px 12px;
  cursor: pointer;
  transition: 0.18s;
}
.b-btn:hover { border-color: var(--muted-2); }
.b-btn-accent { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); }
.b-btn-green { background: var(--green-soft); border-color: var(--green-border); color: var(--green); }
.b-btn-red { background: var(--red-soft); border-color: var(--red-border); color: var(--red); }
.b-btn-small { padding: 6px 10px; font-size: 12px; }
.b-btn:disabled { cursor: default; opacity: 0.55; }
.b-select, .b-input { padding: 8px 10px; min-width: 160px; }
.b-status { font-size: 12px; color: var(--muted); white-space: nowrap; }

.b-main { display: flex; flex: 1; min-height: 0; }
.b-mobile-main-tabs { display: none; }
.b-left {
  width: 63%;
  min-width: 360px;
  max-width: 1100px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, var(--left-gradient-a), var(--left-gradient-b));
}
.b-right {
  flex: 1;
  min-width: 0;
  min-height: 0;
  background: #fff;
  position: relative;
  overflow: hidden;
}
.b-right-file-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.b-right-file-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.b-right-file-meta strong {
  font-size: 14px;
}
.b-right-file-meta span {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.b-right-file-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.b-right-preview,
.b-preview {
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
}
.b-preview { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
.b-file-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  z-index: 2;
}

.b-left-meta {
  min-height: 0;
  border-bottom: 1px solid var(--border);
}

.b-session {
  padding: 14px 18px;
  display: grid;
  gap: 8px;
}
.b-session-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.b-session-title-main {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.b-session-title strong { font-size: 16px; }
.b-session-title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.b-title-input {
  min-width: 240px;
  width: min(100%, 420px);
}
.b-session-meta { color: var(--muted); font-size: 12px; }
.b-badges { display: flex; gap: 8px; flex-wrap: wrap; }
.b-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--surface-soft);
}
.b-badge-status-runnable { color: var(--green); border-color: var(--green-border); background: var(--green-soft); }
.b-badge-status-publish-blocked,
.b-badge-status-preview-error { color: var(--red); border-color: var(--red-border); background: var(--red-soft); }
.b-badge-status-draft { color: var(--accent); border-color: var(--accent-border); background: var(--accent-soft); }

.b-validation {
  padding: 0 18px 14px;
}
.b-validation-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  font-size: 12px;
  color: var(--muted);
}
.b-validation-body {
  margin-top: 8px;
  max-height: 104px;
  overflow: auto;
  padding-right: 4px;
}
.b-validation ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; }
.b-validation strong { font-size: 12px; color: var(--text); }
.b-validation-errors strong { color: var(--red); }
.b-validation-warnings strong { color: var(--yellow); }

.b-columns {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
}
.b-columns-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 10px minmax(320px, var(--builder-sidecar-width, 50%));
  grid-template-areas: "chat resize sidecar";
  min-height: 0;
  overflow: hidden;
}
.b-chat, .b-sidecar { min-height: 0; }
.b-chat {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.b-sidecar-resizer {
  grid-area: resize;
  position: relative;
  min-width: 10px;
  cursor: col-resize;
  touch-action: none;
}
.b-sidecar-resizer::before {
  content: '';
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: var(--border);
  transition: background 0.18s, box-shadow 0.18s;
}
.b-sidecar-resizer:hover::before,
.b-sidecar-resizer:focus-visible::before {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.b-sidecar-resizer:focus-visible {
  outline: none;
}
.b-sidecar {
  grid-area: sidecar;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
body.is-builder-sidecar-resizing,
body.is-builder-sidecar-resizing * {
  cursor: col-resize !important;
  user-select: none;
}
.b-side-tabs {
  display: flex;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  flex-wrap: nowrap;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}
.b-side-tab {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: 0.18s;
  white-space: nowrap;
}
.b-side-tab:hover {
  border-color: var(--muted-2);
  color: var(--text);
}
.b-side-tab.is-active {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-soft);
}
.b-file-scope-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.b-file-scope-tab {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: 0.18s;
}
.b-file-scope-tab span {
  color: inherit;
  font-variant-numeric: tabular-nums;
}
.b-file-scope-tab:hover {
  border-color: var(--muted-2);
  color: var(--text);
}
.b-file-scope-tab.is-active {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-soft);
}
.b-mobile-main-tab.is-active {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-soft);
}
.b-sidecar-pane {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.b-panel-head {
  min-width: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.b-chat-meta {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
  display: grid;
  gap: 10px;
}
.b-chat-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.b-chat-status-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.b-chat-session-line {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.b-chat-session-usage {
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}
.b-chat-progress {
  position: relative;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
}
.b-chat-progress-bar {
  position: absolute;
  inset: 0 auto 0 -35%;
  width: 35%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: b-progress-slide 1.2s linear infinite;
}
.b-recent-actions {
  display: grid;
  gap: 8px;
}
.b-recent-action {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}
.b-recent-action-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.b-recent-action-copy strong {
  font-size: 12px;
  line-height: 1.4;
}
.b-recent-action-copy span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}
.b-live-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  margin-top: 3px;
  background: var(--muted-2);
}
.b-live-dot-running { background: var(--accent); box-shadow: 0 0 0 rgba(9, 105, 218, 0.35); animation: b-dot-pulse 1.3s ease-out infinite; }
.b-live-dot-done { background: var(--green); }
.b-live-dot-error { background: var(--red); }
.b-live-dot-info { background: var(--muted-2); }
.b-messages {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}
.b-message {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 10px 12px;
  max-width: min(92%, 720px);
  width: fit-content;
  line-height: 1.5;
  font-size: 14px;
  white-space: normal;
  word-break: break-word;
}
.b-message-user {
  align-self: flex-end;
  margin-left: 24px;
  background: var(--accent-soft);
  border-color: var(--accent-border);
}
.b-message-assistant {
  align-self: flex-start;
  margin-right: 12px;
}
.b-message-system {
  align-self: stretch;
  max-width: 100%;
  background: rgba(154, 103, 0, 0.06);
  border-color: rgba(154, 103, 0, 0.2);
}
.b-message-processing {
  min-width: 180px;
  background: var(--panel);
}
.b-processing-head {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-bottom: 8px;
}
.b-processing-label {
  font-weight: 600;
  color: var(--text);
}
.b-processing-time {
  color: var(--muted);
  white-space: nowrap;
}
.b-message-plain {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font: inherit;
  color: inherit;
}
.b-message-md {
  display: grid;
  gap: 2px;
}
.b-processing-line {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}
.b-processing-usage {
  color: var(--muted-2);
  font-size: 12px;
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}
.b-processing-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.b-processing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
  opacity: 0.22;
  animation: b-processing-bounce 1.1s ease-in-out infinite;
}
.b-processing-dots span:nth-child(2) { animation-delay: 0.14s; }
.b-processing-dots span:nth-child(3) { animation-delay: 0.28s; }
.b-message-empty {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  padding: 12px;
}
.b-list {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable both-edges;
  padding: 10px 12px;
  padding-bottom: 14px;
  scroll-padding-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.b-activity, .b-file {
  flex: 0 0 auto;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: 10px;
  padding: 8px 10px;
}
.b-activity-top, .b-file-top {
  display: flex;
  justify-content: space-between;
  min-width: 0;
  gap: 10px;
  align-items: baseline;
}
.b-activity-top strong, .b-file-top strong {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.b-activity-state, .b-file-kind {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
}
.b-activity-detail, .b-file-path { margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.45; word-break: break-word; }
.b-activity-state-running { color: var(--accent); }
.b-activity-state-done { color: var(--green); }
.b-activity-state-error { color: var(--red); }
.b-change-group {
  flex: 0 0 auto;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 10px;
}
.b-change-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}
.b-change-head strong {
  min-width: 0;
  font-size: 12px;
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.b-change-head span {
  flex: none;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}
.b-change-files {
  display: grid;
  gap: 8px;
}
.b-change-file {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.b-change-file:hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}
.b-change-file-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.b-change-file-copy strong {
  min-width: 0;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}
.b-change-file-copy span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}
.b-change-file-action {
  flex: none;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}
.b-reference-hub {
  flex: 0 0 auto;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 12px;
}
.b-reference-hub-copy {
  display: grid;
  gap: 4px;
}
.b-reference-hub-copy strong {
  font-size: 13px;
}
.b-reference-hub-copy span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
.b-reference-hub-meta {
  display: grid;
  gap: 2px;
}
.b-reference-hub-meta span {
  color: var(--muted);
  font-size: 11px;
}
.b-reference-hub-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.b-reference-list {
  display: grid;
  gap: 8px;
}
.b-reference-entry {
  width: 100%;
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
}
.b-reference-entry:hover {
  border-color: var(--accent-border);
  background: var(--surface-soft);
}
.b-reference-entry-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.b-reference-entry-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.b-reference-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--panel);
}
.b-reference-chip-status-processed {
  color: var(--green);
  border-color: var(--green-border);
  background: var(--green-soft);
}
.b-reference-chip-status-needs_review {
  color: var(--yellow);
  border-color: rgba(154, 103, 0, 0.28);
  background: rgba(154, 103, 0, 0.08);
}
.b-reference-chip-status-failed {
  color: var(--red);
  border-color: var(--red-border);
  background: var(--red-soft);
}
.b-reference-chip-status-raw_only {
  color: var(--muted);
}
.b-reference-entry-summary {
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
}
.b-reference-entry-warning {
  color: var(--yellow);
  font-size: 12px;
  line-height: 1.5;
}
.b-reference-entry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.b-reference-derived {
  display: grid;
  gap: 8px;
}
.b-reference-derived-file {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.b-reference-derived-file:hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}
.b-reference-derived-file span:first-child {
  min-width: 0;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}
.b-reference-derived-file span:last-child {
  flex: none;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}
.b-reference-entry-head .b-reference-entry-copy {
  flex: 1 1 auto;
}
.b-reference-entry-head .b-reference-entry-copy span {
  word-break: break-all;
}
.b-reference-entry-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.b-reference-entry-copy strong {
  min-width: 0;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}
.b-reference-entry-copy span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}

.b-file-tree { flex: 0 0 auto; display: flex; flex-direction: column; gap: 4px; }
.b-tree-file-entry { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; }
.b-tree-folder {
  flex: 0 0 auto;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
  overflow: hidden;
}
.b-tree-folder + .b-tree-folder,
.b-tree-folder + .b-tree-row,
.b-tree-row + .b-tree-folder,
.b-tree-row + .b-tree-row { margin-top: 6px; }
.b-tree-folder > summary {
  list-style: none;
}
.b-tree-folder > summary::-webkit-details-marker {
  display: none;
}
.b-tree-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: 12px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
}
.b-tree-row-folder {
  cursor: pointer;
  font-weight: 600;
}
.b-tree-row-folder:hover,
.b-tree-row-file:hover {
  background: rgba(127, 127, 127, 0.06);
}
.b-tree-row-folder.is-open {
  background: rgba(127, 127, 127, 0.06);
}
.b-tree-row-file {
  flex: 0 0 auto;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
  cursor: pointer;
  justify-content: flex-start;
  text-align: left;
}
.b-tree-row-file.is-open {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}
.b-tree-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.b-tree-row-file .b-tree-name {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  word-break: break-word;
}
.b-tree-meta {
  flex: none;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}
.b-tree-children {
  padding: 0 0 8px;
}
.b-reference-folder-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 8px;
  padding-bottom: 6px;
}
.b-tree-empty {
  color: var(--muted);
  font-size: 12px;
  padding-top: 4px;
  padding-bottom: 4px;
}
.b-tree-empty-reference {
  display: grid;
  gap: 4px;
}
.b-tree-empty-reference strong {
  color: var(--text);
  font-size: 12px;
}
.b-tree-empty-reference span {
  line-height: 1.5;
}
.b-file-preview {
  margin: 0 0 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  max-height: 320px;
  overflow: auto;
}
.b-right-file-preview {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: var(--bg);
}
.b-right-file-preview.b-json-preview,
.b-right-file-preview.b-md-preview {
  max-height: none;
}
.b-reference-editor {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px;
  background: var(--bg);
}
.b-reference-editor-textarea {
  width: 100%;
  height: 100%;
  min-height: 280px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  padding: 14px 16px;
  line-height: 1.6;
  font-family: var(--mono);
}
.b-reference-editor-textarea:focus {
  outline: 2px solid var(--accent-border);
  outline-offset: 0;
}
.b-file-preview pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  font-family: var(--mono);
}
.b-file-preview-image {
  display: block;
  max-width: 100%;
  border-radius: 8px;
}
.b-json-preview { max-height: 320px; }
.b-json-md { font-size: 12px; line-height: 1.6; }
.b-jv-row { padding: 1px 0; }
.b-jv-key { font-weight: 600; color: var(--text); text-transform: capitalize; }
.b-jv-str { color: var(--muted); }
.b-jv-num { color: var(--accent); font-family: var(--mono); }
.b-jv-bool { color: var(--yellow); font-family: var(--mono); }
.b-jv-null { color: var(--muted-2); font-style: italic; }
.b-jv-section { margin: 6px 0; }
.b-jv-nested { padding-left: 16px; border-left: 2px solid var(--border); margin: 2px 0; }
.b-jv-item { padding: 4px 0; border-bottom: 1px solid var(--border); }
.b-jv-item:last-child { border-bottom: none; }
.b-md-preview { line-height: 1.6; font-size: 13px; }
.b-md-h { font-size: 14px; font-weight: 700; color: var(--text); margin: 10px 0 4px; }
h2.b-md-h { font-size: 16px; margin-top: 14px; }
h3.b-md-h { font-size: 14px; }
h4.b-md-h { font-size: 13px; color: var(--muted); }
.b-md-p { margin: 2px 0; color: var(--text); }
.b-md-li { padding-left: 16px; position: relative; margin: 1px 0; color: var(--text); }
.b-md-li::before { content: '\2022'; position: absolute; left: 4px; color: var(--muted); }
.b-md-ol { margin: 1px 0; color: var(--text); }
.b-md-gap { height: 8px; }
.b-md-hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.b-md-code { font-family: var(--mono); font-size: 12px; background: var(--surface-soft); padding: 1px 4px; border-radius: 3px; }
.b-md-link { color: var(--accent); text-decoration: none; }
.b-md-link:hover { text-decoration: underline; }
.b-md-pre {
  margin: 8px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
}
.b-md-pre code {
  white-space: pre;
  color: var(--text);
}
.b-md-pre-lang {
  margin-bottom: 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
}
.b-md-table-wrap {
  margin: 8px 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}
.b-md-table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  font-size: 12px;
}
.b-md-table th,
.b-md-table td {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.b-md-table thead th {
  border-top: 0;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 700;
}

.b-composer {
  flex: none;
  border-top: 1px solid var(--border);
  padding: 12px 14px 14px;
  display: grid;
  gap: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.65), var(--left-gradient-a));
}
.b-textarea {
  width: 100%;
  min-height: 88px;
  max-height: 180px;
  resize: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  line-height: 1.5;
  overflow: auto;
}
.b-composer-actions { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.b-composer-hint { color: var(--muted); font-size: 12px; }

.b-empty {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: calc(100vh - 61px);
  padding: 28px;
}
.b-empty-card {
  width: min(860px, 100%);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--left-gradient-a), var(--left-gradient-b));
  border-radius: 20px;
  padding: 28px;
  display: grid;
  gap: 20px;
}
.b-empty-card h1 { margin: 0; font-size: 28px; }
.b-empty-card p { margin: 0; color: var(--muted); line-height: 1.6; }
.b-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.b-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: var(--surface-soft);
  display: grid;
  gap: 8px;
}
.b-card strong { font-size: 15px; }
.b-card span, .b-card p { color: var(--muted); font-size: 13px; margin: 0; line-height: 1.5; }
.b-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.b-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  min-width: 240px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(23, 26, 33, 0.98);
  color: var(--text);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.28);
}
.b-toast-error { border-color: rgba(224, 93, 111, 0.45); }
.b-toast-success { border-color: rgba(47, 184, 110, 0.45); }

@keyframes b-dot-pulse {
  0% { box-shadow: 0 0 0 0 rgba(9, 105, 218, 0.38); }
  70% { box-shadow: 0 0 0 7px rgba(9, 105, 218, 0); }
  100% { box-shadow: 0 0 0 0 rgba(9, 105, 218, 0); }
}

@keyframes b-progress-slide {
  0% { transform: translateX(0); }
  100% { transform: translateX(390%); }
}

@keyframes b-processing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.22; }
  40% { transform: translateY(-3px); opacity: 0.92; }
}

@media (max-width: 1200px) {
  .b-left { width: 60%; min-width: 320px; }
  .b-columns-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1.15fr) minmax(220px, 0.85fr);
    grid-template-areas:
      "chat"
      "sidecar";
  }
  .b-sidecar-resizer {
    display: none;
  }
  .b-sidecar {
    border-top: 1px solid var(--border);
    grid-template-rows: auto minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  .b-topbar { align-items: stretch; flex-direction: column; }
  .b-brand { min-width: 0; }
  .b-controls {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 2px;
  }
  .b-status {
    white-space: normal;
  }
  .b-main {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
  }
  .b-mobile-main-tabs {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-soft);
  }
  .b-mobile-main-tab {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: 0.18s;
  }
  .b-left,
  .b-right {
    grid-row: 2;
    grid-column: 1;
    width: 100%;
    max-width: none;
    min-width: 0;
    border-right: 0;
  }
  .b-left {
    border-bottom: 0;
  }
  .b-right {
    min-height: 0;
  }
  .b-right-file-head {
    align-items: flex-start;
    flex-direction: column;
  }
  .b-right-file-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .b-session-title {
    align-items: flex-start;
    flex-direction: column;
  }
  .b-session-title-main {
    width: 100%;
    flex-wrap: wrap;
  }
  .b-session-title-actions {
    width: 100%;
  }
  .b-title-input {
    width: 100%;
    min-width: 0;
  }
  .b-left.is-mobile-hidden,
  .b-right.is-mobile-hidden {
    display: none;
  }
  .b-composer-actions {
    flex-direction: column;
    align-items: stretch;
  }
}
