/* ==========================================================================
   Clarvy / 从简 Personal Agent OS — Base Layout & Structural Design System
   Strictly bound to CONTRACT.md CSS variables and DOM selectors.
   ========================================================================== */

:root {
  /* Resilient fallback defaults (overridden by themes/*.css via [data-theme][data-mode]) */
  --bg-canvas: #070B12;
  --bg-sidebar: #0B111C;
  --bg-main: #0D1420;
  --bg-workbench: #0B111C;
  --bg-surface: #121B2B;
  --bg-surface-hover: #172336;
  --bg-elevated: #18253A;
  --bg-recessed: #080D16;
  --bg-composer: #101827;

  --border-subtle: rgba(148, 163, 184, 0.14);
  --border-default: rgba(148, 163, 184, 0.22);
  --border-strong: rgba(56, 189, 248, 0.45);
  --rim-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.06);

  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --font-sans: "Inter", "PingFang SC", "Noto Sans SC", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", ui-monospace, monospace;

  --accent: #38BDF8;
  --accent-hover: #7DD3FC;
  --accent-fg: #04131E;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --accent-border: rgba(56, 189, 248, 0.34);
  --accent-glow: 0 0 24px rgba(56, 189, 248, 0.18);

  --accent-2: #818CF8;
  --status-live: #22C55E;
  --status-warn: #F59E0B;
  --status-danger: #EF4444;

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 9999px;

  --shadow-card: 0 2px 10px rgba(0, 0, 0, 0.25);
  --shadow-elevated: 0 16px 40px rgba(0, 0, 0, 0.45);
  --shadow-composer: 0 8px 28px rgba(0, 0, 0, 0.32);

  --panel-blur: 0px;
  --panel-gap: 0px;
  --panel-radius: 0px;

  --studio-bar-h: 48px;
}

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

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

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

code, pre, .mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Custom sleek scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==========================================================================
   Ambient Layer
   ========================================================================== */
.ambient-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.25s ease;
}

/* ==========================================================================
   Top Studio Control Bar (48px fixed)
   ========================================================================== */
.studio-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--studio-bar-h);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.studio-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.studio-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.studio-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.studio-title {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.studio-divider {
  width: 1px;
  height: 18px;
  background: var(--border-subtle);
  flex-shrink: 0;
}

.theme-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0;
}
.theme-tabs::-webkit-scrollbar {
  display: none;
}

.theme-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  border: 1px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.theme-tab:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

.theme-tab.active {
  color: var(--text-primary);
  background: var(--accent-soft);
  border-color: var(--accent-border);
  box-shadow: var(--rim-highlight);
}

.theme-swatch-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--swatch, var(--accent));
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.studio-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.view-toggle {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  border-radius: var(--radius-sm);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  gap: 2px;
}

.view-btn {
  height: 26px;
  padding: 0 9px;
  border-radius: calc(var(--radius-sm) - 2px);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: background 0.16s ease, color 0.16s ease;
}

.view-btn:hover {
  color: var(--text-primary);
}

.view-btn.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--rim-highlight);
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-primary);
  transition: background 0.16s ease, border-color 0.16s ease;
}

.mode-toggle:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
}

.mode-toggle svg {
  width: 14px;
  height: 14px;
}

[data-mode="dark"] .mode-toggle .icon-sun { display: none; }
[data-mode="light"] .mode-toggle .icon-moon { display: none; }

.wb-collapse-btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  transition: all 0.16s ease;
}

.wb-collapse-btn svg {
  width: 15px;
  height: 15px;
}

.wb-collapse-btn:hover,
.wb-collapse-btn.active {
  color: var(--text-primary);
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

/* ==========================================================================
   App Stage & 3-Pane OS Shell
   ========================================================================== */
.app-stage {
  position: relative;
  z-index: 1;
  padding-top: var(--studio-bar-h);
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

.os-shell {
  display: flex;
  height: calc(100vh - var(--studio-bar-h));
  width: 100%;
  gap: var(--panel-gap, 0px);
  padding: var(--panel-gap, 0px);
  overflow: hidden;
}

.os-shell[hidden],
.gallery-view[hidden],
.token-drawer[hidden] {
  display: none !important;
}

.sidebar,
.main-pane,
.workbench {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-radius: var(--panel-radius, 0px);
  backdrop-filter: blur(var(--panel-blur, 0px));
  -webkit-backdrop-filter: blur(var(--panel-blur, 0px));
  transition: background-color 0.2s ease, border-color 0.2s ease, border-radius 0.2s ease;
}

/* ==========================================================================
   Left Sidebar (256px)
   ========================================================================== */
.sidebar {
  width: 256px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  overflow: hidden;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px 10px;
  flex-shrink: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  color: var(--accent);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-mark svg {
  width: 28px;
  height: 28px;
}

.brand-copy {
  min-width: 0;
  flex: 1;
}

.brand-title {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.brand-daemon {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  color: var(--status-live);
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.25);
}

.cmd-trigger {
  margin: 2px 12px 10px;
  height: 34px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: var(--radius-sm);
  background: var(--bg-recessed);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: 12px;
  flex-shrink: 0;
  transition: border-color 0.16s ease, color 0.16s ease, background 0.16s ease;
}

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

.cmd-trigger-left {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.cmd-trigger svg {
  width: 13px;
  height: 13px;
  opacity: 0.75;
}

.kbd-chip {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

/* Section Labels */
.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 14px 6px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.section-count {
  font-size: 10px;
  color: var(--text-muted);
}

.icon-mini-btn {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-xs);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
}
.icon-mini-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

/* Pinned Live & Pending Cards */
.pinned-section {
  padding: 0 0 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-subtle);
}

.live-task-card {
  margin: 0 12px;
  padding: 9px 10px;
  text-align: left;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--rim-highlight), var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: transform 0.15s ease, border-color 0.16s ease, background 0.16s ease;
}

.live-task-card:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.live-task-card.pending {
  border-left: 2.5px solid var(--status-warn);
}

.live-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.live-card-tag,
.live-card-pct {
  font-size: 10.5px;
  color: var(--text-muted);
}

.live-card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.live-card-meta {
  font-size: 10.5px;
  color: var(--text-secondary);
}

.live-progress-track {
  height: 3px;
  border-radius: 999px;
  background: var(--bg-recessed);
  overflow: hidden;
}

.live-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--status-live));
}

/* Session List */
.session-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 10px;
  overflow: hidden;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.session-item {
  position: relative;
  width: 100%;
  text-align: left;
  padding: 8px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.session-item:hover {
  background: var(--bg-surface-hover);
}

.session-item.active {
  background: var(--bg-surface);
  border-color: var(--border-default);
  box-shadow: var(--rim-highlight);
}

.session-item-head {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.session-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.55;
  flex-shrink: 0;
}

.session-dot.live {
  background: var(--status-live);
  opacity: 1;
  box-shadow: 0 0 6px var(--status-live);
}

.session-name {
  font-size: 12.2px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-meta {
  font-size: 10.5px;
  color: var(--text-muted);
  padding-left: 13px;
}

/* Bottom Sidebar Nav */
.sidebar-nav {
  flex-shrink: 0;
  padding: 8px;
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  transition: background 0.14s ease, color 0.14s ease;
}

.nav-item svg {
  width: 15px;
  height: 15px;
}

.nav-item:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ==========================================================================
   Center Command Stream (.main-pane)
   ========================================================================== */
.main-pane {
  flex: 1;
  min-width: 0;
  background: var(--bg-main);
  overflow: hidden;
}

.main-topbar {
  min-height: 50px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  flex-wrap: nowrap;
}

.topbar-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.topbar-title {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-branch {
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

/* Model Picker Pill */
.model-picker-wrap {
  position: relative;
}

.pill-model {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-primary);
  transition: border-color 0.16s ease, background 0.16s ease;
}

.pill-model:hover {
  border-color: var(--accent-border);
  background: var(--bg-surface-hover);
}

.model-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.pill-model .chevron {
  width: 11px;
  height: 11px;
  color: var(--text-muted);
}

.model-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 280px;
  padding: 6px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-elevated);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.model-menu[hidden] {
  display: none;
}

.model-menu-header {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 8px 6px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 2px;
}

.model-option {
  text-align: left;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.model-option:hover {
  background: var(--bg-surface-hover);
}

.model-option.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.model-opt-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.model-opt-sub {
  font-size: 11px;
  color: var(--text-secondary);
}

/* Swarm Pill */
.pill-swarm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.16s ease;
}

.pill-swarm.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--text-primary);
}

.swarm-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.pill-swarm.active .swarm-indicator,
.tool-chip.active .swarm-indicator {
  background: var(--status-live);
  box-shadow: 0 0 8px var(--status-live);
}

/* Telemetry Pill */
.pill-telemetry {
  height: 28px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-pill);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Chat Stream */
.chat-stream {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px 24px;
}

.chat-inner {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.session-banner {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  font-size: 12.5px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* Messages */
.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11.5px;
}

.msg-author {
  font-weight: 600;
  color: var(--text-primary);
}

.msg-time {
  font-size: 10.5px;
  color: var(--text-muted);
}

.agent-badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.msg-user {
  align-self: flex-end;
  max-width: 88%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.msg-user-body {
  padding: 11px 14px;
  border-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-xs);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  box-shadow: var(--rim-highlight), var(--shadow-card);
  color: var(--text-primary);
  font-size: 13.5px;
  line-height: 1.58;
}

.msg-user-body code,
.msg-agent-prose code,
.worker-desc code,
.approval-hint code {
  font-size: 0.9em;
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  color: var(--accent);
}

/* Collapsible Timeline Card */
.timeline-card {
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--rim-highlight), var(--shadow-card);
  overflow: hidden;
}

.timeline-header {
  width: 100%;
  padding: 10px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  transition: background 0.14s ease;
}

.timeline-header:hover {
  background: var(--bg-surface-hover);
}

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

.timeline-chevron {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
  transition: transform 0.18s ease;
}

.timeline-card.collapsed .timeline-chevron {
  transform: rotate(-90deg);
}

.timeline-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.timeline-duration {
  font-size: 11px;
  color: var(--text-muted);
}

.timeline-body {
  border-top: 1px solid var(--border-subtle);
  padding: 6px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.timeline-card.collapsed .timeline-body {
  display: none;
}

.timeline-step {
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.timeline-step:hover {
  background: var(--bg-surface-hover);
}

.step-trigger {
  width: 100%;
  padding: 7px 8px;
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
}

.step-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 700;
  flex-shrink: 0;
}

.timeline-step.done .step-marker {
  background: rgba(34, 197, 94, 0.16);
  color: var(--status-live);
  border: 1px solid rgba(34, 197, 94, 0.35);
}

.timeline-step.running .step-marker {
  background: rgba(245, 158, 11, 0.16);
  color: var(--status-warn);
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.step-spin {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-warn);
  animation: clarvyPulse 1.5s infinite;
}

.step-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
}

.step-name {
  font-size: 12.2px;
  font-weight: 600;
  color: var(--text-primary);
}

.step-summary {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.step-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.step-detail {
  margin: 0 8px 8px 35px;
  padding: 7px 10px;
  border-radius: var(--radius-xs);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
  line-height: 1.55;
  color: var(--text-secondary);
  overflow-x: auto;
}

/* Inline Swarm Coordination Summary Card */
.swarm-inline-card {
  position: relative;
  padding: 11px 13px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  box-shadow: var(--rim-highlight), var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.swarm-inline-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.swarm-inline-title {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.swarm-pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.swarm-member-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
}

.swarm-member-pill.coordinator {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.swarm-member-pill.running {
  border-color: rgba(34, 197, 94, 0.4);
}

.member-role {
  font-weight: 600;
  color: var(--text-primary);
}

.member-state {
  color: var(--text-secondary);
  font-size: 10.5px;
}

/* Agent Structured Reply */
.msg-agent {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--rim-highlight), var(--shadow-card);
}

.msg-agent-prose p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.62;
  color: var(--text-primary);
}

/* 3-Column Metrics Grid */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  position: relative;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.metric-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

.metric-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.2;
}

.metric-value.accent {
  color: var(--accent);
}

.metric-value.live {
  color: var(--status-live);
}

.metric-unit {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.metric-sub {
  font-size: 10.5px;
  color: var(--text-secondary);
}

/* Code Block */
.code-block {
  border-radius: var(--radius-md);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 11px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.code-lang {
  font-size: 11px;
  color: var(--text-secondary);
}

.code-pre {
  margin: 0;
  padding: 12px 14px;
  font-size: 11.8px;
  line-height: 1.6;
  overflow-x: auto;
  color: var(--text-primary);
}

.tok-kw { color: var(--accent); font-weight: 500; }
.tok-fn { color: var(--accent-2); }
.tok-type { color: var(--status-live); }
.tok-num { color: var(--status-warn); }
.tok-str { color: var(--status-live); }
.tok-cmt { color: var(--text-muted); font-style: italic; }

/* Interactive Approval Card */
.approval-card {
  position: relative;
  padding: 14px 15px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-left: 3px solid var(--status-warn);
  box-shadow: var(--rim-highlight), var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.approval-card.pulse-highlight {
  box-shadow: 0 0 0 2px var(--status-warn), var(--shadow-elevated);
}

.approval-card.approved {
  border-left-color: var(--status-live);
}

.approval-card.rejected {
  border-left-color: var(--status-danger);
}

.approval-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.approval-scope {
  font-size: 11px;
  color: var(--text-muted);
}

.approval-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.approval-specs {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
}

.spec-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.spec-k {
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 54px;
}

.spec-v {
  color: var(--text-secondary);
  word-break: break-all;
}

.approval-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.approval-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}

.approval-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  font-size: 12px;
  font-weight: 500;
}

.approval-result[hidden] {
  display: none;
}

.approval-card.approved .approval-result-text {
  color: var(--status-live);
}

.approval-card.rejected .approval-result-text {
  color: var(--status-danger);
}

/* ==========================================================================
   Bottom Composer
   ========================================================================== */
.composer-wrap {
  padding: 10px 20px 14px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.composer-box {
  max-width: 820px;
  margin: 0 auto;
  border-radius: var(--radius-lg);
  background: var(--bg-composer);
  border: 1px solid var(--border-default);
  box-shadow: var(--rim-highlight), var(--shadow-composer);
  padding: 10px 12px 9px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.composer-box:focus-within {
  border-color: var(--border-strong);
  box-shadow: var(--rim-highlight), var(--accent-glow), var(--shadow-composer);
}

.composer-input {
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-primary);
  min-height: 40px;
  max-height: 120px;
}

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

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.composer-tools-left,
.composer-tools-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tool-chip {
  height: 26px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.14s ease;
}

.tool-chip:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.tool-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--text-primary);
}

.tool-icon-btn {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.tool-icon-btn svg {
  width: 13px;
  height: 13px;
}

.tool-icon-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.composer-ctx {
  font-size: 10.5px;
  color: var(--text-muted);
}

.btn-send {
  height: 30px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  box-shadow: var(--accent-glow);
  transition: background 0.14s ease, transform 0.12s ease;
}

.btn-send svg {
  width: 13px;
  height: 13px;
}

.btn-send:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

/* ==========================================================================
   Right Unified Workbench (420px)
   ========================================================================== */
.workbench {
  width: 420px;
  flex-shrink: 0;
  background: var(--bg-workbench);
  border-left: 1px solid var(--border-subtle);
  overflow: hidden;
}

.os-shell.wb-collapsed .workbench {
  display: none;
}

.wb-tabs {
  height: 44px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.wb-tab {
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  border: 1px solid transparent;
  transition: all 0.14s ease;
}

.wb-tab:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

.wb-tab.active {
  color: var(--text-primary);
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.wb-panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 13px;
  flex-direction: column;
  gap: 12px;
}

.wb-panel.active {
  display: flex;
}

.wb-section-title {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Swarm Topology SVG */
.swarm-topology {
  position: relative;
  border-radius: var(--radius-md);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  padding: 10px;
  box-shadow: var(--rim-highlight);
}

.topo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.topo-title {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.topo-svg {
  width: 100%;
  height: auto;
  display: block;
}

.topo-edge {
  fill: none;
  stroke: var(--border-default);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
  animation: topoFlow 1.8s linear infinite;
}

.topo-edge.edge-active {
  stroke: var(--accent);
  stroke-width: 2;
}

.topo-edge.edge-cross {
  stroke: var(--accent-2);
  stroke-dasharray: 2 3;
}

.topo-node {
  cursor: pointer;
}

.topo-node rect {
  fill: var(--bg-surface);
  stroke: var(--border-default);
  stroke-width: 1.2;
  transition: stroke 0.16s ease, fill 0.16s ease;
}

.topo-node:hover rect {
  stroke: var(--accent);
}

.topo-node.coordinator rect {
  fill: var(--bg-elevated);
  stroke: var(--accent-border);
  stroke-width: 1.5;
}

.topo-node.active rect {
  stroke: var(--status-live);
  stroke-width: 1.6;
}

.node-dot.live {
  fill: var(--status-live);
}

.node-dot.done {
  fill: var(--accent);
}

.node-label {
  fill: var(--text-primary);
  stroke: none;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
}

.node-sub {
  fill: var(--text-secondary);
  stroke: none;
  font-family: var(--font-sans);
  font-size: 9.5px;
}

/* Worker Cards */
.worker-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.worker-card {
  padding: 10px 11px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--rim-highlight);
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.worker-card.active-worker,
.worker-card.selected-worker {
  border-color: var(--accent-border);
  background: var(--bg-surface-hover);
}

.worker-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.worker-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.worker-desc {
  margin: 0;
  font-size: 11.8px;
  line-height: 1.48;
  color: var(--text-secondary);
}

.worker-meta {
  font-size: 10.5px;
  color: var(--text-muted);
}

/* Board Feed */
.board-feed {
  border-radius: var(--radius-md);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
}

.board-msg {
  display: flex;
  gap: 6px;
  line-height: 1.45;
}

.board-seq {
  color: var(--text-muted);
  flex-shrink: 0;
}

.board-from {
  color: var(--accent);
  font-weight: 600;
  flex-shrink: 0;
}

.board-txt {
  color: var(--text-secondary);
}

/* Tab 2: Diff Viewer & Terminal */
.file-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.file-tab {
  height: 26px;
  padding: 0 9px;
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-secondary);
}

.file-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--text-primary);
}

.diff-viewer {
  border-radius: var(--radius-md);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  overflow-x: auto;
  font-size: 11px;
  line-height: 1.6;
}

.diff-hunk {
  padding: 4px 10px;
  background: var(--bg-surface);
  color: var(--accent-2);
  border-bottom: 1px solid var(--border-subtle);
}

.diff-line {
  display: flex;
  padding: 1px 10px;
  white-space: pre;
}

.diff-ln {
  width: 28px;
  color: var(--text-muted);
  user-select: none;
  flex-shrink: 0;
}

.diff-del {
  background: rgba(239, 68, 68, 0.13);
  color: var(--status-danger);
}

.diff-add {
  background: rgba(34, 197, 94, 0.13);
  color: var(--status-live);
}

.diff-ctx {
  color: var(--text-secondary);
}

.terminal-box {
  border-radius: var(--radius-md);
  background: var(--bg-recessed);
  border: 1px solid var(--border-default);
  padding: 10px 12px;
  font-size: 11px;
  line-height: 1.65;
  color: var(--text-secondary);
}

.term-prompt {
  color: var(--accent);
  font-weight: 600;
}

.term-ok {
  color: var(--status-live);
}

.term-cursor {
  display: inline-block;
  width: 7px;
  height: 12px;
  background: var(--accent);
  vertical-align: middle;
  animation: clarvyPulse 1s infinite;
}

/* Tab 3: Cloud Browser */
.browser-frame {
  border-radius: var(--radius-md);
  background: var(--bg-recessed);
  border: 1px solid var(--border-default);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.browser-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}

.browser-dots {
  display: flex;
  gap: 4px;
}

.browser-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-default);
}

.browser-url {
  flex: 1;
  min-width: 0;
  font-size: 10.5px;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.handoff-banner {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent-border);
  font-size: 11px;
  color: var(--text-primary);
}

.handoff-banner.human-active {
  background: rgba(245, 158, 11, 0.14);
  border-bottom-color: rgba(245, 158, 11, 0.4);
}

.handoff-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.handoff-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
}

.browser-viewport {
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.mock-site-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mock-site-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.mock-site-sub {
  font-size: 10.5px;
  color: var(--text-muted);
}

.mock-kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.mock-kpi {
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mock-kpi span {
  font-size: 10px;
  color: var(--text-muted);
}

.mock-kpi strong {
  font-size: 14px;
  color: var(--text-primary);
}

.mock-spark-wrap {
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.mock-spark-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.mock-spark-svg {
  width: 100%;
  height: auto;
  display: block;
}

.spark-grid {
  stroke: var(--border-subtle);
  stroke-dasharray: 2 3;
}

.spark-line-old {
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
}

.spark-line-new {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
}

.mock-nodes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 10.5px;
  color: var(--text-secondary);
}

.mock-node-row {
  display: grid;
  grid-template-columns: 112px 1fr 56px;
  align-items: center;
  gap: 8px;
}

.mock-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--bg-surface);
  overflow: hidden;
}

.mock-bar i {
  display: block;
  height: 100%;
  background: var(--status-live);
  border-radius: 999px;
}

/* Tab 4: Artifacts & Performance Chart */
.chart-box {
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--rim-highlight);
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.chart-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.chart-legend {
  display: flex;
  gap: 10px;
  font-size: 10.5px;
  color: var(--text-secondary);
}

.chart-legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}

.leg-old { background: var(--text-muted); opacity: 0.55; }
.leg-new { background: var(--accent); }

.perf-chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-grid { stroke: var(--border-subtle); stroke-dasharray: 2 3; }
.chart-axis { stroke: var(--border-default); }
.chart-ylabel, .chart-xlabel {
  fill: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
}
.chart-val-tag {
  fill: var(--accent);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
}
.bar-old { fill: var(--text-muted); opacity: 0.35; }
.bar-new { fill: var(--accent); }

.artifact-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.artifact-card {
  width: 100%;
  text-align: left;
  padding: 10px 11px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color 0.14s ease, background 0.14s ease;
}

.artifact-card:hover {
  border-color: var(--accent-border);
  background: var(--bg-surface-hover);
}

.artifact-icon {
  width: 38px;
  height: 30px;
  border-radius: var(--radius-xs);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.artifact-info {
  flex: 1;
  min-width: 0;
}

.artifact-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.artifact-meta {
  font-size: 10.5px;
  color: var(--text-muted);
}

.artifact-action {
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
  flex-shrink: 0;
}

.artifact-preview-box {
  padding: 11px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-recessed);
  border: 1px solid var(--accent-border);
  font-size: 11.8px;
  line-height: 1.55;
  color: var(--text-secondary);
}

/* ==========================================================================
   Shared Buttons & Semantic Badges (CONTRACT.md)
   ========================================================================== */
.btn-primary {
  height: 32px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 12.2px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: var(--accent-glow);
  transition: background 0.15s ease, transform 0.12s ease;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-outline {
  height: 32px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  font-size: 12.2px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.btn-outline:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 0.14s ease, color 0.14s ease;
}

.btn-ghost:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.btn-xs {
  height: 24px;
  padding: 0 8px;
  font-size: 11px;
}

.badge-live,
.badge-warn,
.badge-accent {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.badge-live {
  color: var(--status-live);
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge-warn {
  color: var(--status-warn);
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.34);
}

.badge-accent {
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
}

.pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-live);
  display: inline-block;
  flex-shrink: 0;
  animation: clarvyPulse 1.8s ease-in-out infinite;
}

/* ==========================================================================
   VIEW 2: 6-Style Gallery View (.gallery-view)
   ========================================================================== */
.gallery-view {
  height: calc(100vh - var(--studio-bar-h));
  overflow-y: auto;
  padding: 26px 28px 40px;
}

.gallery-inner {
  max-width: 1320px;
  margin: 0 auto;
}

.gallery-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.gallery-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.gallery-sub {
  margin: 0;
  max-width: 740px;
  font-size: 13px;
  color: var(--text-secondary);
}

.gallery-mode-pill {
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  font-size: 11px;
  color: var(--text-secondary);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.style-showcase-card {
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  box-shadow: var(--rim-highlight), var(--shadow-card);
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.style-showcase-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-border);
  box-shadow: var(--shadow-elevated);
}

.style-showcase-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow-elevated);
}

.mini-preview {
  height: 152px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  position: relative;
  display: flex;
  padding: 7px;
  gap: 5px;
}

.mini-col-side {
  width: 24%;
  border-radius: 5px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mini-col-main {
  flex: 1;
  border-radius: 5px;
  padding: 7px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mini-col-wb {
  width: 29%;
  border-radius: 5px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mini-bar {
  height: 6px;
  border-radius: 3px;
  opacity: 0.85;
}

.mini-card-block {
  border-radius: 4px;
  padding: 5px;
  flex: 1;
}

.showcase-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.showcase-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.showcase-en {
  font-size: 11px;
  color: var(--text-muted);
}

.showcase-desc {
  margin: 0;
  font-size: 12.2px;
  line-height: 1.52;
  color: var(--text-secondary);
}

.showcase-diff {
  font-size: 11.2px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.showcase-diff strong {
  color: var(--text-primary);
}

.swatch-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.swatch-chip {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid rgba(128, 128, 128, 0.35);
}

.showcase-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
  border-top: 1px solid var(--border-subtle);
}

.showcase-fit {
  font-size: 11px;
  color: var(--text-muted);
}

/* ==========================================================================
   VIEW 3: Design Token Inspector (.token-drawer)
   ========================================================================== */
.token-drawer {
  height: calc(100vh - var(--studio-bar-h));
  overflow-y: auto;
  padding: 26px 28px 44px;
}

.token-inner {
  max-width: 1240px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.token-hero {
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  box-shadow: var(--rim-highlight), var(--shadow-card);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.token-hero h2 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
}

.token-hero p {
  margin: 0;
  max-width: 720px;
  font-size: 13px;
  color: var(--text-secondary);
}

.token-section {
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.token-section h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.token-swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 10px;
}

.token-swatch-card {
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.14s ease;
}

.token-swatch-card:hover {
  border-color: var(--accent-border);
}

.token-color-box {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-default);
  flex-shrink: 0;
}

.token-meta {
  min-width: 0;
  flex: 1;
}

.token-var {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.token-val {
  font-size: 10.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ladder-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.ladder-step {
  padding: 14px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ladder-name {
  font-size: 11px;
  font-weight: 600;
}

.ladder-hex {
  font-size: 10.5px;
  color: var(--text-secondary);
}

.token-kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.token-kv-card {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-recessed);
  border: 1px solid var(--border-subtle);
}

.token-kv-k {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.token-kv-v {
  font-size: 12px;
  color: var(--text-primary);
  word-break: break-word;
}

/* ==========================================================================
   ⌘K Command Palette Modal
   ========================================================================== */
.cmd-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(2, 6, 14, 0.58);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
}

.cmd-overlay[hidden] {
  display: none;
}

.cmd-modal {
  width: min(560px, calc(100vw - 32px));
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-elevated);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.cmd-search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.cmd-search-bar svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.cmd-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  color: var(--text-primary);
}

.cmd-results {
  max-height: 360px;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cmd-group-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 6px 8px 3px;
}

.cmd-item {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-primary);
}

.cmd-item:hover,
.cmd-item.selected {
  background: var(--accent-soft);
  color: var(--text-primary);
}

.cmd-item-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.cmd-footer {
  padding: 7px 14px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-recessed);
  font-size: 10.5px;
  color: var(--text-muted);
  display: flex;
  gap: 14px;
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast-region {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.toast-item {
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  border: 1px solid var(--accent-border);
  box-shadow: var(--shadow-elevated);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  animation: toastIn 0.2s ease;
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes clarvyPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.84); }
}

@keyframes topoFlow {
  from { stroke-dashoffset: 16; }
  to { stroke-dashoffset: 0; }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Responsive Breakpoints (1280px, 1024px, 900px — zero horizontal overflow)
   ========================================================================== */
@media (max-width: 1500px) {
  .topbar-branch { display: none; }
}

@media (max-width: 1260px) {
  .sidebar { width: 228px; }
  .workbench { width: 368px; }
  .theme-tab { padding: 0 8px; font-size: 11.5px; }
  .studio-title { font-size: 12px; }
  .pill-telemetry { display: none; }
}

@media (max-width: 1080px) {
  .sidebar { width: 210px; }
  .workbench { width: 326px; }
  .studio-title { display: none; }
  .studio-divider { display: none; }
  .pill-telemetry { display: none; }
  .topbar-branch { display: none; }
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ladder-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 940px) {
  .sidebar { width: 196px; }
  .workbench { width: 300px; }
  .chat-stream { padding: 14px 12px 18px; }
  .composer-wrap { padding: 8px 12px 10px; }
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .metric-card { padding: 8px 9px; }
  .metric-value { font-size: 16px; }
  .view-btn { padding: 0 7px; font-size: 11px; }
  .mode-toggle .mode-label { display: none; }
  .approval-hint { margin-left: 0; width: 100%; }
}

@media (max-width: 780px) {
  .sidebar { display: none; }
  .workbench {
    position: fixed;
    top: var(--studio-bar-h);
    right: 0;
    bottom: 0;
    width: min(360px, 92vw);
    z-index: 45;
    box-shadow: var(--shadow-elevated);
  }
  .gallery-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: 1fr; }
}
