/* ==========================================================================
   ByteHelpers Workbench Layout & Components
   Apple-DNA macOS Developer Workbench / Xcode-Inspired Precision
   Requires: ./tokens.css
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  background-color: var(--bh-canvas);
  color: var(--bh-text);
  font-family: var(--bh-font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bh-canvas);
  color: var(--bh-text);
  overflow-x: clip;
}

[hidden] {
  display: none !important;
}

/* Visually hidden for screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip link */
.skip-link {
  position: fixed;
  top: -100px;
  left: var(--bh-space-4);
  z-index: 1000;
  padding: var(--bh-space-2) var(--bh-space-4);
  border-radius: var(--bh-radius-control);
  background: var(--bh-mint);
  color: var(--bh-mint-ink);
  font-weight: 600;
  font-size: var(--bh-text-ui);
  text-decoration: none;
  transition: top var(--bh-dur-control) var(--bh-ease-standard);
}

.skip-link:focus {
  top: var(--bh-space-2);
  outline: 2px solid var(--bh-focus-ring);
  outline-offset: 2px;
}

/* Focus rings — WCAG 2.2 AA visible focus */
:focus-visible {
  outline: 2px solid var(--bh-focus-ring);
  outline-offset: 2px;
}

button,
select,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Tabular numerals helper */
.tabular {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--bh-font-mono);
}

/* ==========================================================================
   1. Workbench Topbar (48px fixed height)
   ========================================================================== */

.bh-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--bh-topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--bh-space-3);
  padding: 0 var(--bh-space-4);
  background-color: var(--bh-surface-1);
  border-bottom: 1px solid var(--bh-border);
}

.bh-topbar-left {
  display: flex;
  align-items: center;
  gap: var(--bh-space-2);
  min-width: 0;
}

.bh-topbar-right {
  display: flex;
  align-items: center;
  gap: var(--bh-space-2);
  flex-shrink: 0;
}

.bh-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--bh-radius-control);
  color: var(--bh-text-secondary);
  border: 1px solid transparent;
  transition:
    background-color var(--bh-dur-control) var(--bh-ease-standard),
    color var(--bh-dur-control) var(--bh-ease-standard),
    border-color var(--bh-dur-control) var(--bh-ease-standard);
}

.bh-icon-btn:hover {
  background-color: var(--bh-surface-hover);
  color: var(--bh-text);
}

.bh-icon-btn[aria-pressed="true"],
.bh-icon-btn[aria-expanded="true"] {
  background-color: var(--bh-surface-2);
  border-color: var(--bh-border-strong);
  color: var(--bh-text);
}

.bh-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--bh-space-2);
  text-decoration: none;
  color: var(--bh-text);
  padding: 4px 6px;
  border-radius: var(--bh-radius-control);
  flex-shrink: 0;
}

.bh-brand:hover {
  background-color: var(--bh-surface-2);
}

.bh-brand-mark {
  width: 24px;
  height: 24px;
  display: block;
  flex-shrink: 0;
}

.bh-brand-wordmark {
  font-family: var(--bh-font-mono);
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--bh-text);
}

.bh-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: var(--bh-space-1);
  padding-left: var(--bh-space-3);
  border-left: 1px solid var(--bh-border);
  font-size: var(--bh-text-ui);
  color: var(--bh-text-muted);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

.bh-breadcrumb-hub {
  color: var(--bh-text-muted);
}

.bh-breadcrumb-sep {
  color: var(--bh-border-strong);
  user-select: none;
}

.bh-breadcrumb-current {
  color: var(--bh-text-secondary);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Command trigger pill in topbar */
.bh-cmd-trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--bh-space-2);
  height: 32px;
  padding: 0 10px;
  border-radius: var(--bh-radius-control);
  background-color: var(--bh-editor);
  border: 1px solid var(--bh-border);
  color: var(--bh-text-secondary);
  font-size: var(--bh-text-ui);
  transition:
    border-color var(--bh-dur-control) var(--bh-ease-standard),
    background-color var(--bh-dur-control) var(--bh-ease-standard),
    color var(--bh-dur-control) var(--bh-ease-standard);
}

.bh-cmd-trigger:hover {
  border-color: var(--bh-border-strong);
  color: var(--bh-text);
  background-color: var(--bh-surface-2);
}

.bh-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 6px;
  min-height: 20px;
  border-radius: 5px;
  background-color: var(--bh-surface-2);
  border: 1px solid var(--bh-border-strong);
  font-family: var(--bh-font-mono);
  font-size: 11px;
  line-height: 1;
  color: var(--bh-text-secondary);
}

/* Local processing status badge */
.bh-local-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border-radius: var(--bh-radius-pill);
  background-color: var(--bh-mint-subtle);
  border: 1px solid var(--bh-mint-border);
  color: var(--bh-mint);
  font-size: var(--bh-text-ui-sm);
  font-weight: 500;
  white-space: nowrap;
}

.bh-local-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--bh-mint);
  flex-shrink: 0;
}

.bh-focus-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--bh-radius-control);
  background-color: var(--bh-surface-2);
  border: 1px solid var(--bh-border);
  color: var(--bh-text-secondary);
  font-size: var(--bh-text-ui);
  font-weight: 500;
  transition:
    background-color var(--bh-dur-control) var(--bh-ease-standard),
    border-color var(--bh-dur-control) var(--bh-ease-standard),
    color var(--bh-dur-control) var(--bh-ease-standard);
}

.bh-focus-btn:hover {
  background-color: var(--bh-surface-hover);
  border-color: var(--bh-border-strong);
  color: var(--bh-text);
}

.bh-focus-btn[aria-pressed="true"] {
  background-color: var(--bh-blue-subtle);
  border-color: var(--bh-blue-border);
  color: var(--bh-blue);
}

/* ==========================================================================
   2. App Shell: Collapsible Tool Navigator + Main Workbench Column
   ========================================================================== */

.bh-shell {
  display: grid;
  grid-template-columns: var(--bh-sidebar-w) minmax(0, 1fr);
  min-height: calc(100vh - var(--bh-topbar-h));
  transition: grid-template-columns var(--bh-dur-panel) var(--bh-ease-standard);
}

.bh-shell[data-sidebar-collapsed="true"],
body[data-focus-mode="true"] .bh-shell {
  grid-template-columns: 0px minmax(0, 1fr);
}

/* Sidebar Navigator */
.bh-sidebar {
  background-color: var(--bh-surface-1);
  border-right: 1px solid var(--bh-border);
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--bh-space-3) var(--bh-space-2);
  transition:
    opacity var(--bh-dur-panel) var(--bh-ease-standard),
    transform var(--bh-dur-panel) var(--bh-ease-standard);
}

.bh-shell[data-sidebar-collapsed="true"] .bh-sidebar,
body[data-focus-mode="true"] .bh-sidebar {
  opacity: 0;
  pointer-events: none;
  border-right-color: transparent;
  padding: 0;
}

.bh-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px var(--bh-space-2) var(--bh-space-2);
  margin-bottom: var(--bh-space-1);
}

.bh-sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bh-text-muted);
}

.bh-drawer-close {
  display: none;
}

.bh-tree-group {
  margin-bottom: var(--bh-space-3);
}

.bh-tree-group-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px var(--bh-space-2);
  border-radius: var(--bh-radius-sm);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--bh-text-muted);
  transition:
    background-color var(--bh-dur-control) var(--bh-ease-standard),
    color var(--bh-dur-control) var(--bh-ease-standard);
}

.bh-tree-group-btn:hover {
  background-color: var(--bh-surface-2);
  color: var(--bh-text-secondary);
}

.bh-tree-chevron {
  transition: transform var(--bh-dur-control) var(--bh-ease-standard);
}

.bh-tree-group-btn[aria-expanded="false"] .bh-tree-chevron {
  transform: rotate(-90deg);
}

.bh-tree-list {
  list-style: none;
  margin: 2px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bh-tree-item-link {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--bh-space-2);
  padding: 6px var(--bh-space-2) 6px var(--bh-space-3);
  border-radius: var(--bh-radius-control);
  font-size: var(--bh-text-ui);
  color: var(--bh-text-secondary);
  text-decoration: none;
  text-align: left;
  transition:
    background-color var(--bh-dur-control) var(--bh-ease-standard),
    color var(--bh-dur-control) var(--bh-ease-standard);
}

.bh-tree-item-link:hover {
  background-color: var(--bh-surface-2);
  color: var(--bh-text);
}

.bh-tree-item-link[aria-current="page"],
.bh-tree-item-link.is-active {
  background-color: var(--bh-blue-subtle);
  color: var(--bh-text);
  font-weight: 500;
}

.bh-tree-item-link.is-planned {
  color: var(--bh-text-muted);
}

.bh-tree-tag {
  font-family: var(--bh-font-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background-color: var(--bh-surface-2);
  border: 1px solid var(--bh-border);
  color: var(--bh-text-muted);
  flex-shrink: 0;
}

.bh-tree-item-link.is-active .bh-tree-tag {
  background-color: var(--bh-mint-subtle);
  border-color: var(--bh-mint-border);
  color: var(--bh-mint);
}

/* Mobile drawer backdrop */
.bh-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 190;
  background-color: var(--bh-backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--bh-dur-panel) var(--bh-ease-standard);
}

.bh-drawer-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================================================
   3. Main Workbench Area (Generous outer gutters, compact active workspace)
   ========================================================================== */

.bh-main {
  min-width: 0;
  padding: var(--bh-space-4) var(--bh-gutter-desktop) var(--bh-space-8);
  display: flex;
  flex-direction: column;
  gap: var(--bh-space-4);
}

body[data-focus-mode="true"] .bh-main {
  padding-top: var(--bh-space-3);
  padding-bottom: var(--bh-space-4);
}

/* Tool Header Strip (Compact, content is hero) */
.bh-tool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--bh-space-3);
}

.bh-tool-title-group {
  display: flex;
  align-items: baseline;
  gap: var(--bh-space-3);
  flex-wrap: wrap;
  min-width: 0;
}

.bh-tool-title {
  margin: 0;
  font-size: var(--bh-text-h1);
  line-height: var(--bh-leading-h1);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--bh-text);
}

.bh-tool-subtitle {
  margin: 0;
  font-size: var(--bh-text-ui);
  color: var(--bh-text-muted);
}

/* Segmented Control (macOS Xcode-style) */
.bh-segmented {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  border-radius: 10px;
  background-color: var(--bh-editor);
  border: 1px solid var(--bh-border);
  gap: 2px;
}

.bh-seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 12px;
  border-radius: var(--bh-radius-control);
  font-size: var(--bh-text-ui);
  font-weight: 500;
  color: var(--bh-text-secondary);
  transition:
    background-color var(--bh-dur-control) var(--bh-ease-standard),
    color var(--bh-dur-control) var(--bh-ease-standard);
}

.bh-seg-btn:hover {
  color: var(--bh-text);
}

.bh-seg-btn[aria-selected="true"],
.bh-seg-btn[aria-pressed="true"] {
  background-color: var(--bh-surface-2);
  color: var(--bh-text);
  box-shadow: var(--bh-shadow-control);
}

/* ==========================================================================
   4. Workbench Surface Shell (Toolbar + Split Editor + Diagnostics + Status)
   ========================================================================== */

.bh-workbench {
  display: flex;
  flex-direction: column;
  border-radius: var(--bh-radius-panel);
  border: 1px solid var(--bh-border);
  background-color: var(--bh-surface-1);
  overflow: hidden;
}

/* Primary Toolbar */
.bh-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--bh-space-2);
  padding: var(--bh-space-2) var(--bh-space-3);
  background-color: var(--bh-surface-1);
  border-bottom: 1px solid var(--bh-border);
}

.bh-toolbar-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.bh-toolbar-divider {
  width: 1px;
  height: 20px;
  background-color: var(--bh-border);
  margin: 0 2px;
}

/* Buttons — 8-10px control radius, restrained highlights */
.bh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: var(--bh-radius-control);
  font-size: var(--bh-text-ui);
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid var(--bh-border);
  background-color: var(--bh-surface-2);
  color: var(--bh-text);
  box-shadow: var(--bh-shadow-control);
  transition:
    background-color var(--bh-dur-control) var(--bh-ease-standard),
    border-color var(--bh-dur-control) var(--bh-ease-standard),
    color var(--bh-dur-control) var(--bh-ease-standard),
    transform var(--bh-dur-control) var(--bh-ease-standard);
}

.bh-btn:hover:not(:disabled) {
  background-color: var(--bh-surface-hover);
  border-color: var(--bh-border-strong);
}

.bh-btn:active:not(:disabled) {
  transform: scale(0.98);
}

/* One Primary Action per state: Mint button */
.bh-btn-primary {
  background-color: var(--bh-mint);
  border-color: var(--bh-mint);
  color: var(--bh-mint-ink);
  font-weight: 600;
  box-shadow: none;
}

.bh-btn-primary:hover:not(:disabled) {
  background-color: var(--bh-mint-hover);
  border-color: var(--bh-mint-hover);
  color: var(--bh-mint-ink);
}

.bh-btn-primary:active:not(:disabled) {
  background-color: var(--bh-mint-active);
}

.bh-btn-ghost {
  background-color: transparent;
  border-color: transparent;
  color: var(--bh-text-secondary);
  box-shadow: none;
}

.bh-btn-ghost:hover:not(:disabled) {
  background-color: var(--bh-surface-2);
  border-color: var(--bh-border);
  color: var(--bh-text);
}

.bh-btn-toggle[aria-pressed="true"] {
  background-color: var(--bh-blue-subtle);
  border-color: var(--bh-blue-border);
  color: var(--bh-blue);
}

.bh-btn-danger {
  background-color: var(--bh-error-subtle);
  border-color: var(--bh-error-border);
  color: var(--bh-error);
  box-shadow: none;
}

.bh-btn-danger:hover:not(:disabled) {
  background-color: rgba(255, 133, 133, 0.22);
}

.bh-btn-sm {
  min-height: 28px;
  padding: 0 9px;
  font-size: var(--bh-text-ui-sm);
}

/* Select inputs in toolbar */
.bh-select-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--bh-text-ui-sm);
  color: var(--bh-text-muted);
}

.bh-select {
  min-height: 34px;
  padding: 0 26px 0 10px;
  border-radius: var(--bh-radius-control);
  border: 1px solid var(--bh-border);
  background-color: var(--bh-surface-2);
  color: var(--bh-text);
  font-size: var(--bh-text-ui);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%23B4BDCC' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
  transition: border-color var(--bh-dur-control) var(--bh-ease-standard);
}

.bh-select:hover {
  border-color: var(--bh-border-strong);
}

/* Mobile Segmented Input/Output Tabs (hidden on desktop) */
.bh-mobile-tabs {
  display: none;
  padding: var(--bh-space-2) var(--bh-space-3);
  background-color: var(--bh-surface-1);
  border-bottom: 1px solid var(--bh-border);
}

.bh-mobile-tab-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  padding: 3px;
  border-radius: 10px;
  background-color: var(--bh-editor);
  border: 1px solid var(--bh-border);
  gap: 3px;
}

.bh-mobile-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  border-radius: var(--bh-radius-control);
  font-size: var(--bh-text-ui);
  font-weight: 500;
  color: var(--bh-text-secondary);
}

.bh-mobile-tab[aria-selected="true"] {
  background-color: var(--bh-surface-2);
  color: var(--bh-text);
  font-weight: 600;
}

.bh-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--bh-radius-pill);
  font-family: var(--bh-font-mono);
  font-size: 11px;
  font-weight: 600;
}

.bh-tab-badge.is-error {
  background-color: var(--bh-error-subtle);
  color: var(--bh-error);
  border: 1px solid var(--bh-error-border);
}

.bh-tab-badge.is-ok {
  background-color: var(--bh-mint-subtle);
  color: var(--bh-mint);
  border: 1px solid var(--bh-mint-border);
}

/* ==========================================================================
   5. Split Editor Workspace (510px tall on 1440x900, resizable)
   ========================================================================== */

.bh-split {
  --bh-split-left: 50%;
  display: grid;
  grid-template-columns: minmax(240px, var(--bh-split-left)) 9px minmax(240px, 1fr);
  height: 510px;
  min-height: 400px;
  background-color: var(--bh-editor);
  position: relative;
}

body[data-focus-mode="true"] .bh-split {
  height: calc(100vh - 220px);
  min-height: 460px;
}

.bh-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background-color: var(--bh-editor);
  position: relative;
}

.bh-pane.is-dragover {
  outline: 2px dashed var(--bh-mint);
  outline-offset: -4px;
}

.bh-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--bh-space-2);
  height: 38px;
  padding: 0 var(--bh-space-3);
  background-color: var(--bh-surface-1);
  border-bottom: 1px solid var(--bh-border-subtle);
  flex-shrink: 0;
}

.bh-pane-title-wrap {
  display: flex;
  align-items: center;
  gap: var(--bh-space-2);
  min-width: 0;
}

.bh-pane-title {
  font-size: var(--bh-text-ui-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--bh-text-secondary);
  text-transform: uppercase;
}

.bh-sample-pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: var(--bh-radius-pill);
  background-color: var(--bh-blue-subtle);
  border: 1px solid var(--bh-blue-border);
  color: var(--bh-blue);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.bh-pane-meta {
  font-family: var(--bh-font-mono);
  font-size: 11.5px;
  color: var(--bh-text-muted);
  white-space: nowrap;
}

.bh-pane-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Inline copy feedback badge (no reflow) */
.bh-copy-feedback {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 64px;
  justify-content: center;
}

/* Keyboard-accessible Splitter */
.bh-splitter {
  position: relative;
  background-color: var(--bh-surface-1);
  border-left: 1px solid var(--bh-border);
  border-right: 1px solid var(--bh-border);
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  transition: background-color var(--bh-dur-control) var(--bh-ease-standard);
}

.bh-splitter::after {
  content: "";
  width: 3px;
  height: 36px;
  border-radius: 99px;
  background-color: var(--bh-border-strong);
  transition: background-color var(--bh-dur-control) var(--bh-ease-standard);
}

.bh-splitter:hover,
.bh-splitter.is-dragging {
  background-color: var(--bh-surface-2);
}

.bh-splitter:hover::after,
.bh-splitter.is-dragging::after,
.bh-splitter:focus-visible::after {
  background-color: var(--bh-blue);
}

.bh-splitter:focus-visible {
  outline: 2px solid var(--bh-focus-ring);
  outline-offset: -2px;
}

/* Editor Surface (Zero blur over code editors!) */
.bh-editor-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  background-color: var(--bh-editor);
  position: relative;
  overflow: hidden;
}

.bh-gutter {
  background-color: var(--bh-editor-gutter);
  border-right: 1px solid var(--bh-border-subtle);
  padding: 12px 8px 12px 4px;
  font-family: var(--bh-font-mono);
  font-size: var(--bh-text-code);
  line-height: var(--bh-leading-code);
  color: var(--bh-text-muted);
  text-align: right;
  user-select: none;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

.bh-gutter-line {
  display: block;
  padding-right: 2px;
  border-radius: 3px;
}

.bh-gutter-line.is-error {
  background-color: var(--bh-editor-error-line);
  color: var(--bh-error);
  font-weight: 600;
}

.bh-textarea {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 12px 14px;
  border: 0;
  resize: none;
  background-color: var(--bh-editor);
  color: var(--bh-text);
  font-family: var(--bh-font-mono);
  font-size: var(--bh-text-code);
  line-height: var(--bh-leading-code);
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  outline: none;
}

.bh-textarea:focus-visible {
  outline: 2px solid var(--bh-focus-ring);
  outline-offset: -2px;
}

.bh-textarea::placeholder {
  color: var(--bh-text-muted);
}

/* Highlighted Code Output */
.bh-code-output {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 12px 14px;
  overflow: auto;
  background-color: var(--bh-editor);
  color: var(--bh-text);
  font-family: var(--bh-font-mono);
  font-size: var(--bh-text-code);
  line-height: var(--bh-leading-code);
  white-space: pre;
  tab-size: 2;
}

.bh-code-output:focus-visible {
  outline: 2px solid var(--bh-focus-ring);
  outline-offset: -2px;
}

/* Semantic Syntax Tokens */
.tok-key { color: var(--bh-syn-key); }
.tok-string { color: var(--bh-syn-string); }
.tok-number { color: var(--bh-syn-number); }
.tok-boolean { color: var(--bh-syn-boolean); }
.tok-null { color: var(--bh-syn-null); font-style: italic; }
.tok-punct { color: var(--bh-syn-punct); }

/* Empty / Worker Progress States inside Output Pane */
.bh-pane-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--bh-space-6);
  gap: var(--bh-space-3);
  background-color: var(--bh-editor);
  color: var(--bh-text-secondary);
}

.bh-pane-state-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--bh-text);
}

.bh-pane-state-desc {
  margin: 0;
  max-width: 38ch;
  font-size: var(--bh-text-ui);
  color: var(--bh-text-muted);
}

.bh-progress-track {
  width: 240px;
  max-width: 100%;
  height: 6px;
  border-radius: var(--bh-radius-pill);
  background-color: var(--bh-surface-2);
  overflow: hidden;
}

.bh-progress-bar {
  height: 100%;
  width: 35%;
  border-radius: var(--bh-radius-pill);
  background-color: var(--bh-mint);
  transition: width 160ms var(--bh-ease-standard);
}

/* ==========================================================================
   6. Diagnostics Panel & Structural Diff Panel
   ========================================================================== */

.bh-diagnostics {
  border-top: 1px solid var(--bh-border);
  background-color: var(--bh-surface-1);
  padding: var(--bh-space-3) var(--bh-space-4);
  display: flex;
  flex-direction: column;
  gap: var(--bh-space-2);
}

.bh-diag-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--bh-space-3);
  flex-wrap: wrap;
}

.bh-diag-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.bh-diag-header {
  display: flex;
  align-items: center;
  gap: var(--bh-space-2);
  flex-wrap: wrap;
}

.bh-severity {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 5px;
  font-family: var(--bh-font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.bh-severity.is-error {
  background-color: var(--bh-error-subtle);
  border: 1px solid var(--bh-error-border);
  color: var(--bh-error);
}

.bh-severity.is-warning {
  background-color: var(--bh-warning-subtle);
  border: 1px solid var(--bh-warning-border);
  color: var(--bh-warning);
}

.bh-diag-loc {
  font-family: var(--bh-font-mono);
  font-size: var(--bh-text-ui-sm);
  color: var(--bh-text-secondary);
}

.bh-diag-msg {
  font-size: var(--bh-text-ui);
  font-weight: 500;
  color: var(--bh-text);
}

.bh-diag-hint {
  margin: 0;
  font-size: var(--bh-text-ui-sm);
  color: var(--bh-text-secondary);
}

.bh-diag-snippet {
  margin: 4px 0 0;
  padding: 8px 12px;
  border-radius: var(--bh-radius-control);
  background-color: var(--bh-editor);
  border: 1px solid var(--bh-border);
  font-family: var(--bh-font-mono);
  font-size: 12.5px;
  line-height: 1.45;
  overflow-x: auto;
  color: var(--bh-text);
}

.bh-diag-caret {
  color: var(--bh-error);
  font-weight: 700;
}

/* Structural Diff Results Panel */
.bh-diff-panel {
  border-top: 1px solid var(--bh-border);
  background-color: var(--bh-surface-1);
}

.bh-diff-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--bh-space-2);
  padding: var(--bh-space-2) var(--bh-space-4);
  border-bottom: 1px solid var(--bh-border-subtle);
  font-size: var(--bh-text-ui);
}

.bh-diff-badges {
  display: flex;
  align-items: center;
  gap: var(--bh-space-2);
  flex-wrap: wrap;
}

.bh-diff-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--bh-radius-pill);
  font-family: var(--bh-font-mono);
  font-size: 12px;
  font-weight: 500;
}

.bh-diff-pill.is-add {
  background-color: var(--bh-diff-add-bg);
  color: var(--bh-diff-add-text);
}

.bh-diff-pill.is-del {
  background-color: var(--bh-diff-del-bg);
  color: var(--bh-diff-del-text);
}

.bh-diff-pill.is-mod {
  background-color: var(--bh-diff-mod-bg);
  color: var(--bh-diff-mod-text);
}

.bh-diff-list {
  list-style: none;
  margin: 0;
  padding: var(--bh-space-2) var(--bh-space-4) var(--bh-space-3);
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bh-diff-row {
  display: grid;
  grid-template-columns: 28px minmax(140px, 240px) minmax(0, 1fr);
  gap: var(--bh-space-2);
  align-items: baseline;
  padding: 6px 10px;
  border-radius: var(--bh-radius-control);
  font-family: var(--bh-font-mono);
  font-size: 12.5px;
}

.bh-diff-row.is-added {
  background-color: var(--bh-diff-add-bg);
  color: var(--bh-diff-add-text);
}

.bh-diff-row.is-removed {
  background-color: var(--bh-diff-del-bg);
  color: var(--bh-diff-del-text);
}

.bh-diff-row.is-changed {
  background-color: var(--bh-diff-mod-bg);
  color: var(--bh-diff-mod-text);
}

.bh-diff-sym {
  font-weight: 700;
  text-align: center;
}

.bh-diff-path {
  color: var(--bh-text);
  word-break: break-word;
}

.bh-diff-val {
  word-break: break-word;
}

/* ==========================================================================
   7. Status Bar
   ========================================================================== */

.bh-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--bh-space-3);
  min-height: 36px;
  padding: 6px var(--bh-space-3);
  background-color: var(--bh-surface-1);
  border-top: 1px solid var(--bh-border);
  font-size: var(--bh-text-ui-sm);
  color: var(--bh-text-secondary);
}

.bh-status-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--bh-space-3);
}

.bh-status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.bh-status-indicator.is-valid { color: var(--bh-mint); }
.bh-status-indicator.is-invalid { color: var(--bh-error); }
.bh-status-indicator.is-idle { color: var(--bh-text-secondary); }
.bh-status-indicator.is-working { color: var(--bh-blue); }

.bh-status-metric {
  font-family: var(--bh-font-mono);
  color: var(--bh-text-muted);
}

.bh-status-metric strong {
  color: var(--bh-text-secondary);
  font-weight: 500;
}

/* ==========================================================================
   8. Reserved Advertising Region (Immutable Dimensions, Zero Ad CLS)
   ========================================================================== */

.bh-ad-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: var(--bh-space-2) 0;
}

body[data-focus-mode="true"] .bh-ad-section {
  display: none;
}

.bh-ad-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--bh-text-muted);
}

.bh-ad-slot {
  width: 728px;
  height: 90px;
  min-height: 90px;
  max-width: 100%;
  border-radius: var(--bh-radius-control);
  border: 1px dashed var(--bh-border-strong);
  background-color: var(--bh-surface-1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--bh-space-3);
  padding: 0 var(--bh-space-4);
  color: var(--bh-text-muted);
  font-size: var(--bh-text-ui-sm);
  contain: layout size;
}

.bh-ad-slot-size {
  font-family: var(--bh-font-mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: var(--bh-surface-2);
  color: var(--bh-text-secondary);
}

.bh-ad-size-mobile,
.bh-ad-size-narrow {
  display: none;
}

/* ==========================================================================
   9. Below-Workspace: CommandLinkList & Readable Technical Documentation
   ========================================================================== */

body[data-focus-mode="true"] .bh-below-fold,
body[data-focus-mode="true"] .bh-footer {
  display: none;
}

.bh-below-fold {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.85fr);
  gap: var(--bh-space-6);
  padding-top: var(--bh-space-2);
  align-items: start;
}

.bh-section-card {
  background-color: var(--bh-surface-1);
  border: 1px solid var(--bh-border);
  border-radius: var(--bh-radius-panel);
  padding: var(--bh-space-5);
}

.bh-section-title {
  margin: 0 0 var(--bh-space-3);
  font-size: var(--bh-text-h2);
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--bh-text);
}

.bh-prose {
  max-width: 68ch;
  font-size: var(--bh-text-body);
  color: var(--bh-text-secondary);
}

.bh-prose p {
  margin: 0 0 var(--bh-space-3);
}

.bh-prose p:last-child {
  margin-bottom: 0;
}

.bh-prose code {
  font-family: var(--bh-font-mono);
  font-size: 0.875em;
  padding: 1px 5px;
  border-radius: 4px;
  background-color: var(--bh-editor);
  border: 1px solid var(--bh-border);
  color: var(--bh-text);
}

.bh-spec-list {
  margin: var(--bh-space-3) 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--bh-space-2);
}

.bh-spec-list li {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: var(--bh-space-2);
  padding-top: var(--bh-space-2);
  border-top: 1px solid var(--bh-border-subtle);
  font-size: var(--bh-text-ui);
}

.bh-spec-list strong {
  color: var(--bh-text);
  font-weight: 500;
}

/* Command-like Related Tool List (No marketing cards!) */
.bh-cmd-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--bh-border);
  border-radius: var(--bh-radius-control);
  overflow: hidden;
  background-color: var(--bh-editor);
}

.bh-cmd-row + .bh-cmd-row {
  border-top: 1px solid var(--bh-border-subtle);
}

.bh-cmd-link {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--bh-space-2);
  padding: 10px 12px;
  color: var(--bh-text);
  text-decoration: none;
  font-size: var(--bh-text-ui);
  text-align: left;
  transition: background-color var(--bh-dur-control) var(--bh-ease-standard);
}

.bh-cmd-link:hover {
  background-color: var(--bh-surface-2);
}

.bh-cmd-link-main {
  display: flex;
  align-items: center;
  gap: var(--bh-space-2);
  min-width: 0;
}

.bh-cmd-prefix {
  font-family: var(--bh-font-mono);
  color: var(--bh-mint);
  font-weight: 600;
}

.bh-cmd-path {
  font-family: var(--bh-font-mono);
  font-size: 11.5px;
  color: var(--bh-text-muted);
}

.bh-shortcut-grid {
  margin-top: var(--bh-space-4);
  display: grid;
  gap: 6px;
}

.bh-shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--bh-text-ui-sm);
  color: var(--bh-text-secondary);
  padding: 4px 0;
  border-bottom: 1px solid var(--bh-border-subtle);
}

/* Footer */
.bh-footer {
  margin-top: var(--bh-space-2);
  padding-top: var(--bh-space-4);
  border-top: 1px solid var(--bh-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--bh-space-3);
  font-size: var(--bh-text-ui-sm);
  color: var(--bh-text-muted);
}

/* ==========================================================================
   10. Floating Overlays (Command Palette & Share Modal — Translucent Chrome)
   ========================================================================== */

.bh-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  background-color: var(--bh-backdrop);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh var(--bh-space-4) var(--bh-space-4);
}

.bh-modal {
  width: 100%;
  max-width: 560px;
  border-radius: var(--bh-radius-overlay);
  background-color: var(--bh-popover-fallback);
  border: 1px solid var(--bh-border-strong);
  box-shadow: var(--bh-shadow-popover);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@supports (backdrop-filter: blur(18px)) {
  .bh-modal {
    background-color: var(--bh-popover-bg);
    backdrop-filter: blur(18px) saturate(150%);
    -webkit-backdrop-filter: blur(18px) saturate(150%);
  }
}

@media (prefers-reduced-transparency: reduce) {
  .bh-modal {
    background-color: var(--bh-popover-fallback);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

.bh-palette-input-wrap {
  display: flex;
  align-items: center;
  gap: var(--bh-space-2);
  padding: var(--bh-space-3) var(--bh-space-4);
  border-bottom: 1px solid var(--bh-border);
}

.bh-palette-input {
  flex: 1;
  background: transparent;
  border: 0;
  font-size: 0.9375rem;
  color: var(--bh-text);
  outline: none;
}

.bh-palette-input::placeholder {
  color: var(--bh-text-muted);
}

.bh-palette-list {
  list-style: none;
  margin: 0;
  padding: var(--bh-space-2);
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bh-palette-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--bh-space-3);
  padding: 9px 12px;
  border-radius: var(--bh-radius-control);
  font-size: var(--bh-text-ui);
  color: var(--bh-text-secondary);
  text-align: left;
  cursor: pointer;
}

.bh-palette-item[aria-selected="true"],
.bh-palette-item:hover {
  background-color: var(--bh-blue-subtle);
  color: var(--bh-text);
}

.bh-palette-item-meta {
  display: flex;
  align-items: center;
  gap: var(--bh-space-2);
  font-family: var(--bh-font-mono);
  font-size: 11px;
  color: var(--bh-text-muted);
}

.bh-palette-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px var(--bh-space-4);
  border-top: 1px solid var(--bh-border);
  font-size: 11.5px;
  color: var(--bh-text-muted);
}

/* Share Modal internals */
.bh-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--bh-space-4);
  border-bottom: 1px solid var(--bh-border);
}

.bh-modal-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--bh-text);
}

.bh-modal-body {
  padding: var(--bh-space-4);
  display: flex;
  flex-direction: column;
  gap: var(--bh-space-3);
  font-size: var(--bh-text-ui);
  color: var(--bh-text-secondary);
}

.bh-checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: var(--bh-space-2);
  padding: var(--bh-space-3);
  border-radius: var(--bh-radius-control);
  background-color: var(--bh-editor);
  border: 1px solid var(--bh-border);
  cursor: pointer;
}

.bh-checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 1px;
  accent-color: var(--bh-mint);
  flex-shrink: 0;
}

.bh-secret-warning {
  padding: var(--bh-space-3);
  border-radius: var(--bh-radius-control);
  background-color: var(--bh-warning-subtle);
  border: 1px solid var(--bh-warning-border);
  color: var(--bh-warning);
  font-size: var(--bh-text-ui-sm);
}

.bh-secret-warning ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.bh-share-url-row {
  display: flex;
  gap: var(--bh-space-2);
}

.bh-share-url-input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border-radius: var(--bh-radius-control);
  background-color: var(--bh-editor);
  border: 1px solid var(--bh-border);
  font-family: var(--bh-font-mono);
  font-size: 12px;
  color: var(--bh-text);
}

/* ==========================================================================
   11. Responsive Breakpoints (1024px, 768px Mobile 390x844, Narrow 320px)
   ========================================================================== */

@media (max-width: 1080px) {
  .bh-below-fold {
    grid-template-columns: 1fr;
  }

  .bh-breadcrumbs {
    display: none;
  }
}

@media (max-width: 860px) {
  /* Sidebar becomes slide-over drawer */
  .bh-shell,
  .bh-shell[data-sidebar-collapsed="true"] {
    grid-template-columns: minmax(0, 1fr);
  }

  .bh-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(290px, 86vw);
    z-index: 200;
    transform: translateX(-104%);
    opacity: 1 !important;
    pointer-events: none !important;
    padding: var(--bh-space-3) var(--bh-space-3) var(--bh-space-6) !important;
    border-right: 1px solid var(--bh-border-strong) !important;
    box-shadow: var(--bh-shadow-popover);
  }

  .bh-sidebar.is-drawer-open {
    transform: translateX(0);
    pointer-events: auto !important;
  }

  .bh-drawer-close {
    display: inline-flex;
  }

  .bh-local-badge-text {
    display: none;
  }

  .bh-focus-label {
    display: none;
  }
}

/* Mobile Layout (<= 767px, optimized for 390x844) */
@media (max-width: 767px) {
  .bh-topbar {
    padding: 0 var(--bh-space-2);
    gap: var(--bh-space-2);
  }

  /* 44x44 CSS px primary touch targets on mobile */
  .bh-icon-btn,
  .bh-btn,
  .bh-select,
  .bh-seg-btn,
  .bh-cmd-trigger,
  .bh-focus-btn {
    min-height: 44px;
  }

  .bh-icon-btn {
    width: 44px;
    height: 44px;
  }

  .bh-cmd-trigger-label,
  .bh-cmd-trigger .bh-kbd {
    display: none;
  }

  .bh-cmd-trigger {
    width: 44px;
    padding: 0;
    justify-content: center;
  }

  .bh-focus-btn {
    width: 44px;
    padding: 0;
    justify-content: center;
  }

  .bh-local-badge {
    height: 30px;
    padding: 0 8px;
  }

  .bh-main {
    padding: var(--bh-space-3) var(--bh-gutter-mobile) var(--bh-space-6);
    gap: var(--bh-space-3);
  }

  .bh-tool-header {
    gap: var(--bh-space-2);
  }

  .bh-tool-title {
    font-size: 1.125rem;
  }

  .bh-tool-subtitle {
    display: none;
  }

  .bh-toolbar {
    padding: var(--bh-space-2);
    gap: var(--bh-space-2);
  }

  .bh-toolbar-group {
    width: 100%;
    gap: 6px;
  }

  .bh-toolbar-group-primary {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr;
  }

  .bh-toolbar-group-secondary {
    display: flex;
    flex-wrap: wrap;
  }

  .bh-toolbar-divider {
    display: none;
  }

  /* Segmented Input / Output Tabs on Mobile */
  .bh-mobile-tabs {
    display: block;
  }

  .bh-split {
    display: block;
    height: 300px;
    min-height: 270px;
  }

  .bh-splitter {
    display: none;
  }

  .bh-pane {
    height: 100%;
  }

  .bh-split[data-mobile-tab="input"] .bh-pane-right {
    display: none;
  }

  .bh-split[data-mobile-tab="output"] .bh-pane-left {
    display: none;
  }

  /* >= 16px on mobile editor prevents iOS Safari zoom on focus */
  .bh-textarea,
  .bh-code-output,
  .bh-gutter {
    font-size: 16px;
    line-height: 1.5;
  }

  .bh-editor-wrap {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .bh-pane-header {
    min-height: 44px;
    padding: 4px var(--bh-space-2);
  }

  .bh-btn-sm {
    min-height: 36px;
    padding: 0 10px;
  }

  /* Reserved mobile ad slot: exact 320x100 on 390x844 */
  .bh-ad-slot {
    width: 320px;
    height: 100px;
    min-height: 100px;
    flex-direction: column;
    gap: 4px;
    text-align: center;
  }

  .bh-ad-size-desktop {
    display: none;
  }

  .bh-ad-size-mobile {
    display: inline-block;
  }

  .bh-diff-row {
    grid-template-columns: 24px minmax(0, 1fr);
  }

  .bh-diff-val {
    grid-column: 2;
  }

  .bh-spec-list li {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .bh-section-card {
    padding: var(--bh-space-4);
  }
}

/* Narrow-Mobile Reflow (320px viewport width — WCAG 1.4.10 Reflow, 0px horizontal overflow) */
@media (max-width: 352px) {
  .bh-main {
    padding: var(--bh-space-2) 10px var(--bh-space-5);
  }

  .bh-brand-wordmark {
    font-size: 0.875rem;
  }

  .bh-toolbar-group-primary {
    grid-template-columns: 1fr 1fr;
  }

  .bh-toolbar-group-primary .bh-btn-primary {
    grid-column: 1 / -1;
  }

  /* Provider-compatible narrower slot (300x50) fits cleanly in 320px viewport with 10px gutters */
  .bh-ad-slot {
    width: 300px;
    height: 50px;
    min-height: 50px;
    flex-direction: row;
    padding: 0 10px;
  }

  .bh-ad-size-mobile {
    display: none;
  }

  .bh-ad-size-narrow {
    display: inline-block;
  }
}

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