/* ==========================================================================
   Bero 驾驶舱 (Cockpit) 设计系统
   零内联样式 · 明暗双主题 · 移动优先响应式 · 严格兼容 CSP style-src 'self'
   ========================================================================== */

:root {
  color-scheme: light;
  --bg-canvas: #f4f5f8;
  --bg-surface: #ffffff;
  --bg-subtle: #eef0f5;
  --bg-elevated: #ffffff;
  --bg-rail: #11131a;
  --fg-rail: #e5e7ef;
  --fg-rail-muted: #9399ad;
  --bg-rail-active: rgba(99, 102, 241, 0.2);

  --fg-primary: #14161f;
  --fg-secondary: #4a5064;
  --fg-muted: #6e758c;
  --border-subtle: #e2e5ee;
  --border-strong: #c8cede;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.11);
  --accent-fg: #ffffff;

  --tone-success-bg: rgba(16, 185, 129, 0.12);
  --tone-success-fg: #047857;
  --tone-info-bg: rgba(59, 130, 246, 0.13);
  --tone-info-fg: #1d4ed8;
  --tone-warn-bg: rgba(245, 158, 11, 0.14);
  --tone-warn-fg: #b45309;
  --tone-danger-bg: rgba(239, 68, 68, 0.12);
  --tone-danger-fg: #b91c1c;
  --tone-muted-bg: rgba(107, 114, 128, 0.12);
  --tone-muted-fg: #4b5563;

  --code-bg: #161822;
  --code-fg: #e6e9f4;

  --shadow-sm: 0 1px 2px rgba(15, 18, 30, 0.05);
  --shadow-md: 0 6px 20px rgba(15, 18, 30, 0.08);
  --shadow-lg: 0 16px 40px rgba(15, 18, 30, 0.16);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg-canvas: #0c0e14;
  --bg-surface: #141720;
  --bg-subtle: #1c202d;
  --bg-elevated: #1b1f2c;
  --bg-rail: #090b10;
  --fg-rail: #eaedf7;
  --fg-rail-muted: #8b92a8;
  --bg-rail-active: rgba(129, 140, 248, 0.2);

  --fg-primary: #eef0f7;
  --fg-secondary: #b5bccf;
  --fg-muted: #838ba3;
  --border-subtle: #252a3a;
  --border-strong: #363d54;

  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-soft: rgba(99, 102, 241, 0.18);
  --accent-fg: #ffffff;

  --tone-success-bg: rgba(16, 185, 129, 0.18);
  --tone-success-fg: #34d399;
  --tone-info-bg: rgba(59, 130, 246, 0.2);
  --tone-info-fg: #60a5fa;
  --tone-warn-bg: rgba(245, 158, 11, 0.2);
  --tone-warn-fg: #fbbf24;
  --tone-danger-bg: rgba(239, 68, 68, 0.2);
  --tone-danger-fg: #f87171;
  --tone-muted-bg: rgba(156, 163, 175, 0.16);
  --tone-muted-fg: #9ca3af;

  --code-bg: #090b10;
  --code-fg: #e2e8f0;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.65);
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg-canvas);
  color: var(--fg-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Boot & Login */
.app-boot, .auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.boot-loader {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--fg-secondary);
  font-weight: 500;
}

.auth-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-md);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4f46e5, #10b981);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  flex-shrink: 0;
}

/* Shell Layout */
.cockpit-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100dvh;
}

.nav-rail {
  background: var(--bg-rail);
  color: var(--fg-rail);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 30;
}

.rail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 14px;
}

.rail-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rail-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
}

.rail-subtitle {
  font-size: 11px;
  color: var(--fg-rail-muted);
}

.rail-cta {
  width: 100%;
  margin-bottom: 14px;
  justify-content: center;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-rail-muted);
  padding: 12px 10px 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: var(--fg-rail-muted);
  font-weight: 500;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  transition: background 0.14s ease, color 0.14s ease;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  text-decoration: none;
}

.nav-link.is-active {
  background: var(--bg-rail-active);
  color: #fff;
}

.nav-link-main {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.nav-count {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.nav-count.is-alert {
  background: #ef4444;
}

.rail-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sse-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--fg-rail-muted);
  padding: 0 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b7280;
  flex-shrink: 0;
}
.status-dot.is-ok { background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2); }
.status-dot.is-warn { background: #f59e0b; }
.status-dot.is-err { background: #ef4444; }

.rail-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.rail-icon-btn {
  background: rgba(255, 255, 255, 0.07);
  color: var(--fg-rail);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.rail-icon-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Main Content Area */
.cockpit-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 20;
}

.mobile-scrim {
  display: none;
}

.page-container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 32px 56px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: 4px 0 0;
  color: var(--fg-muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Cards & Grids */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-subtle {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.grid-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 12px;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-meta {
  font-size: 12px;
  color: var(--fg-secondary);
}

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

/* Health Strip */
.health-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.health-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--bg-subtle);
  font-size: 12px;
  font-weight: 500;
}

/* Badges & Tones */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--tone-success-bg); color: var(--tone-success-fg); }
.badge-info { background: var(--tone-info-bg); color: var(--tone-info-fg); }
.badge-warn { background: var(--tone-warn-bg); color: var(--tone-warn-fg); }
.badge-danger { background: var(--tone-danger-bg); color: var(--tone-danger-fg); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-muted { background: var(--tone-muted-bg); color: var(--tone-muted-fg); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--fg-primary);
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
  text-decoration: none;
}
.btn:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  background: var(--tone-danger-bg);
  border-color: transparent;
  color: var(--tone-danger-fg);
}
.btn-danger:hover:not(:disabled) {
  border-color: var(--tone-danger-fg);
}

.btn-sm {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 12px;
}

/* Quick Dispatch Composer */
.composer-card {
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
}

.agent-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.agent-tab {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.agent-tab:hover {
  border-color: var(--border-strong);
}
.agent-tab.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.agent-tab-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 6px;
}

.agent-tab-name {
  font-weight: 700;
  font-size: 13px;
}

.agent-tab-desc {
  font-size: 11.5px;
  color: var(--fg-muted);
  line-height: 1.4;
}

/* Forms & Inputs */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-secondary);
}

.field-hint {
  font-size: 12px;
  color: var(--fg-muted);
}

.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--fg-primary);
  transition: border-color 0.15s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea {
  min-height: 104px;
  resize: vertical;
  line-height: 1.55;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.inline-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

/* Collapsible Details */
.details-box {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  padding: 10px 14px;
}

.details-box > summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-secondary);
  user-select: none;
}

.details-body {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Lists & Rows */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  transition: border-color 0.14s ease, transform 0.14s ease;
  text-decoration: none;
  color: inherit;
}
.item-row:hover {
  border-color: var(--border-strong);
  text-decoration: none;
}

.item-main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.item-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.item-title {
  font-weight: 600;
  font-size: 14px;
  word-break: break-word;
}

.item-preview {
  font-size: 12.5px;
  color: var(--fg-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--fg-muted);
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.pill-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}

.pill-tab {
  border: none;
  background: transparent;
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-secondary);
  cursor: pointer;
}
.pill-tab.is-active {
  background: var(--bg-surface);
  color: var(--fg-primary);
  box-shadow: var(--shadow-sm);
}

.search-input {
  max-width: 280px;
}

/* Conversation & Streaming View */
.chat-stream {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg-bubble {
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.msg-user {
  background: var(--accent-soft);
  border-color: transparent;
  align-self: flex-end;
  max-width: min(86%, 760px);
}

.msg-assistant {
  background: var(--bg-surface);
  width: 100%;
}

.msg-role-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--fg-muted);
  font-weight: 600;
}

/* Tool Step Chips */
.step-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 12px;
}

.step-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--fg-secondary);
}

/* Markdown Body */
.md-body {
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}
.md-body > *:first-child { margin-top: 0; }
.md-body > *:last-child { margin-bottom: 0; }
.md-body p { margin: 0 0 10px; white-space: pre-wrap; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 {
  margin: 16px 0 8px;
  line-height: 1.35;
}
.md-body h1 { font-size: 18px; }
.md-body h2 { font-size: 16px; }
.md-body h3, .md-body h4 { font-size: 14.5px; }
.md-body ul, .md-body ol {
  margin: 0 0 10px;
  padding-left: 22px;
}
.md-body li { margin-bottom: 4px; }
.md-body blockquote {
  margin: 0 0 10px;
  padding: 6px 12px;
  border-left: 3px solid var(--accent);
  background: var(--bg-subtle);
  color: var(--fg-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.md-inline-code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
}

.code-block {
  margin: 10px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--border-subtle);
}
.code-block-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: #9ca3af;
}
.code-copy-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
  border: none;
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}
.code-copy-btn:hover { background: rgba(255, 255, 255, 0.2); }
.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
}

/* Banner & Alerts */
.banner {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.banner-warn { background: var(--tone-warn-bg); color: var(--tone-warn-fg); border-color: transparent; }
.banner-danger { background: var(--tone-danger-bg); color: var(--tone-danger-fg); border-color: transparent; }
.banner-info { background: var(--tone-info-bg); color: var(--tone-info-fg); border-color: transparent; }

/* Key-Value Metadata Grid */
.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px 18px;
}
.kv-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kv-key {
  font-size: 11.5px;
  color: var(--fg-muted);
}
.kv-val {
  font-size: 13px;
  font-weight: 500;
  word-break: break-all;
}
.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

/* Empty State */
.empty-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--fg-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

/* Progress Steps for Goals */
.goal-progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-subtle);
  overflow: hidden;
  margin: 8px 0;
}
.goal-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.25s ease;
}
.w-0 { width: 0%; }
.w-10 { width: 10%; }
.w-20 { width: 20%; }
.w-30 { width: 30%; }
.w-40 { width: 40%; }
.w-50 { width: 50%; }
.w-60 { width: 60%; }
.w-70 { width: 70%; }
.w-80 { width: 80%; }
.w-90 { width: 90%; }
.w-100 { width: 100%; }

/* Split Editor for Memory */
.memory-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

/* Toast Notifications & History Drawer */
.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  background: var(--bg-elevated);
  color: var(--fg-primary);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}
.toast-item.is-error { border-left-color: #ef4444; }
.toast-item.is-success { border-left-color: #10b981; }

.toast-close {
  background: transparent;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: 16px;
  line-height: 1;
}

/* Accessible Dialog */
.modal-dialog {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--fg-primary);
  padding: 24px;
  max-width: 460px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-lg);
}
.modal-dialog::backdrop {
  background: rgba(9, 11, 16, 0.55);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* Spinner */
.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.75s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* Responsive Tablet & Mobile */
@media (max-width: 1080px) and (min-width: 761px) {
  .cockpit-shell {
    grid-template-columns: 214px minmax(0, 1fr);
  }
  .page-container {
    padding: 22px 22px 48px;
  }
  .grid-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .cockpit-shell {
    grid-template-columns: 1fr;
  }
  .mobile-topbar {
    display: flex;
  }
  .nav-rail {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 268px;
    transform: translateX(-100%);
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.2s ease, visibility 0.2s ease;
  }
  .cockpit-shell.nav-open .nav-rail {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }
  .cockpit-shell.nav-open .mobile-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 25;
  }
  .page-container {
    padding: 18px 16px 48px;
  }
  .grid-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .agent-tabs, .grid-two, .memory-layout {
    grid-template-columns: 1fr;
  }
  .search-input {
    max-width: 100%;
  }
  .item-row {
    flex-direction: column;
  }
  .item-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 460px) {
  .grid-stats {
    grid-template-columns: 1fr;
  }
}

/* Muse v2 Extensions: Multimodal Attachments, Soul Center, Passkeys & Ecosystem */
.sr-file-input {
  display: none;
}

.composer-card.is-dragover {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.attachment-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.attachment-chip {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  margin-top: 10px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
}

.attachment-chip-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.ecosystem-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.eco-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--fg-muted);
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

.passkey-hero-btn {
  width: 100%;
  min-height: 44px;
  font-size: 14px;
}

.textarea-lg {
  min-height: 180px;
}

@media (max-width: 760px) {
  .ecosystem-grid {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Muse Conversation-First Stage & Sidebar Thread List
   ========================================================================== */
.rail-brand-link {
  text-decoration: none;
  color: inherit;
}
.rail-brand-link:hover {
  text-decoration: none;
  opacity: 0.92;
}

.rail-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 8px;
}

.rail-more-link {
  font-size: 11px;
  color: var(--fg-rail-muted);
  text-decoration: none;
}
.rail-more-link:hover {
  color: #fff;
}

.rail-threads {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 2px;
  margin-bottom: 6px;
}

.rail-empty-hint {
  font-size: 12px;
  color: var(--fg-rail-muted);
  padding: 6px 10px 10px;
  line-height: 1.45;
}

.thread-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--fg-rail-muted);
  font-size: 12.5px;
  text-decoration: none;
  transition: background 0.14s ease, color 0.14s ease;
  min-width: 0;
}
.thread-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  text-decoration: none;
}
.thread-link.is-active {
  background: var(--bg-rail-active);
  color: #fff;
  font-weight: 600;
}
.thread-link-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* Muse Full-Height Chat Stage */
.muse-stage {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 540px;
  background: var(--bg-canvas);
}

.muse-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.muse-topbar-left,
.muse-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.muse-brand-pill {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.muse-status-subtle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--fg-muted);
  padding: 3px 9px;
  background: var(--bg-subtle);
  border-radius: 999px;
}

.muse-thread-title {
  font-weight: 700;
  font-size: 15px;
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muse-mini-select {
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  color: var(--fg-secondary);
  font-size: 12px;
  font-weight: 600;
  max-width: 220px;
  cursor: pointer;
}

/* Muse Empty-Thread Welcome Home */
.muse-home-wrap {
  flex: 1;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 24px 48px;
}

.muse-home-center {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.muse-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  margin-bottom: 4px;
}

.muse-orb {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, #4f46e5, #06b6d4, #10b981);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 28px rgba(79, 70, 229, 0.28);
  margin-bottom: 4px;
}

.muse-greeting {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.muse-vibe {
  margin: 0;
  color: var(--fg-muted);
  font-size: 13.5px;
  max-width: 560px;
}

/* Muse Floating Omnibox Composer */
.muse-omnibox {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 14px 16px 12px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.muse-omnibox:focus-within,
.muse-omnibox.is-dragover {
  border-color: var(--accent);
  box-shadow: 0 8px 30px rgba(79, 70, 229, 0.15), 0 0 0 3px var(--accent-soft);
}

.muse-omnibox-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--fg-primary);
  font-size: 15px;
  line-height: 1.6;
  resize: none;
  padding: 2px 2px;
  min-height: 52px;
  max-height: 220px;
}
.muse-omnibox-input:focus {
  outline: none;
}

.muse-omnibox-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.muse-omnibox-tools,
.muse-omnibox-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.muse-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  color: var(--fg-secondary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}
.muse-tool-btn:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--fg-primary);
}

.muse-send-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.14s ease, opacity 0.14s ease;
}
.muse-send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}
.muse-send-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.muse-att-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
}

/* Muse Starter Prompt Cards */
.muse-starters-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.muse-starter-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 13px 15px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.muse-starter-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.muse-starter-head {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--fg-primary);
}

.muse-starter-desc {
  font-size: 12px;
  color: var(--fg-muted);
}

/* Muse Active Conversation Scroll Stream */
.muse-thread {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 18px;
}

.muse-thread-inner {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.muse-turn {
  display: flex;
  gap: 14px;
}

.muse-turn-user {
  justify-content: flex-end;
}

.muse-user-bubble {
  max-width: min(82%, 620px);
  padding: 12px 16px;
  border-radius: 18px 18px 4px 18px;
  background: var(--accent);
  color: var(--accent-fg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.muse-user-att {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 12px;
}

.muse-user-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
  line-height: 1.55;
}

.muse-turn-ai {
  align-items: flex-start;
}

.muse-ai-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4f46e5, #10b981);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.muse-ai-avatar.is-pulsing {
  animation: musePulse 1.6s ease-in-out infinite;
}

@keyframes musePulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.06); opacity: 0.82; }
}

.muse-ai-main {
  flex: 1;
  min-width: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 4px 18px 18px 18px;
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
}

.muse-ai-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--fg-muted);
  margin-bottom: 8px;
}

.muse-copy-msg-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--fg-muted);
  font-size: 11.5px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 5px;
}
.muse-copy-msg-btn:hover {
  background: var(--bg-subtle);
  color: var(--fg-primary);
}

.muse-steps-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.muse-bottom-dock {
  padding: 10px 20px 18px;
  background: linear-gradient(180deg, transparent, var(--bg-canvas) 24%);
  flex-shrink: 0;
}

.muse-bottom-inner {
  max-width: 800px;
  margin: 0 auto;
}

@media (max-width: 760px) {
  .muse-stage {
    height: calc(100dvh - 55px);
  }
  .muse-topbar {
    padding: 10px 14px;
  }
  .muse-greeting {
    font-size: 21px;
  }
  .muse-starters-grid {
    grid-template-columns: 1fr;
  }
  .muse-thread {
    padding: 16px 12px;
  }
  .muse-bottom-dock {
    padding: 8px 12px 14px;
  }
  .muse-thread-title {
    max-width: 190px;
  }
}
