/* COSMO Unified Platform - Clean Modern Theme */

:root {
  /* Light backgrounds */
  --bg-primary: #ffffff;
  --bg-secondary: #fafafa;
  --bg-tertiary: #f5f5f5;
  --bg-hover: #eeeeee;

  /* Text colors */
  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #8a8a8a;
  --text-light: #b0b0b0;

  /* Accent - Refined Blue */
  --accent: #2563eb;
  --accent-light: #60a5fa;
  --accent-dark: #1d4ed8;
  --accent-bg: rgba(37, 99, 235, 0.08);

  /* Status colors */
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.1);

  /* Borders */
  --border: #e5e5e5;
  --border-light: #f0f0f0;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);

  /* Sidebar */
  --sidebar-width: 260px;
  --sidebar-bg: #fefefe;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

body.has-sidebar {
  display: flex;
}

/* ============================================
   App Sidebar
   ============================================ */

.app-sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-sidebar.collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-right: none;
}

.app-sidebar.collapsed .sidebar-inner {
  opacity: 0;
  pointer-events: none;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 20px 16px;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 4px 20px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 20px;
}

.sidebar-logo-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-collapse-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

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

.sidebar-expand-btn {
  position: fixed;
  left: 12px;
  top: 20px;
  z-index: 201;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  cursor: pointer;
  padding: 10px;
  border-radius: 8px;
  display: none;
  box-shadow: var(--shadow-md);
  transition: all 0.15s ease;
}

.sidebar-expand-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent);
}

body:has(.app-sidebar.collapsed) .sidebar-expand-btn {
  display: flex;
}

.sidebar-logo-icon {
  width: 32px;
  height: 32px;
  color: var(--accent);
}

.sidebar-logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

/* Sidebar User Section */
.sidebar-user {
  margin-bottom: 24px;
}

.sidebar-auth-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.sidebar-avatar-placeholder {
  width: 40px;
  height: 40px;
  background: var(--bg-tertiary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
}

.sidebar-guest {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-guest-info {
  display: flex;
  flex-direction: column;
}

.sidebar-guest-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
}

.btn-link:hover {
  text-decoration: underline;
}

.sidebar-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-avatar {
  width: 40px;
  height: 40px;
  background: var(--accent-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.sidebar-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
}

.sidebar-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-user-tier {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Sidebar Section Titles */
.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Sidebar Usage Dashboard */
.sidebar-usage {
  margin-bottom: 24px;
  padding: 16px;
  background: var(--bg-tertiary);
  border-radius: 12px;
}

.usage-item {
  margin-bottom: 16px;
}

.usage-item:last-of-type {
  margin-bottom: 0;
}

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

.usage-item-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.usage-item-label svg {
  color: var(--text-muted);
}

.usage-item-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.usage-item-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.usage-item-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease, background 0.3s ease;
}

.usage-item-fill.warning {
  background: var(--warning);
}

.usage-item-fill.danger {
  background: var(--error);
}

.usage-reset {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}

/* Sidebar API Key */
.sidebar-apikey {
  margin-bottom: 24px;
}

.sidebar-key-status {
  margin-bottom: 12px;
}

.key-status-none,
.key-status-active {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  font-size: 13px;
}

.key-status-none {
  color: var(--warning);
  background: var(--warning-bg);
}

.key-status-active {
  color: var(--success);
  background: var(--success-bg);
}

.sidebar-btn {
  width: 100%;
  justify-content: center;
}

/* Sidebar Connection */
.sidebar-connection {
  margin-top: auto;
  padding-top: 16px;
  margin-bottom: 16px;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
}

.connection-status.connected .connection-dot {
  background: var(--success);
}

.connection-status.connecting .connection-dot {
  background: var(--warning);
  animation: pulse 1.5s infinite;
}

/* Sidebar Footer */
.sidebar-footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.sidebar-footer-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

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

/* Sidebar Mobile Toggle */
.sidebar-toggle-mobile {
  display: none;
  position: fixed;
  left: 16px;
  top: 16px;
  width: 44px;
  height: 44px;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  align-items: center;
  justify-content: center;
  color: white;
  cursor: pointer;
  z-index: 201;
  box-shadow: var(--shadow-md);
}

.sidebar-toggle-mobile:active {
  transform: scale(0.95);
}

/* Mobile Header Bar - shows menu + sign-in on mobile */
.mobile-header-bar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  z-index: 200;
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
}

.mobile-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-menu-btn {
  width: 44px;
  height: 44px;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-menu-btn:active {
  transform: scale(0.95);
}

.mobile-logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.mobile-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-sign-in-btn {
  padding: 10px 16px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.mobile-sign-in-btn:active {
  transform: scale(0.98);
}

.mobile-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}

.mobile-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}


/* App Container */
.app-container {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Expand main content when sidebar is collapsed */
body:has(.app-sidebar.collapsed) .app-container {
  margin-left: 0;
}

@media (max-width: 900px) {
  /* Remove flex on body for mobile - sidebar is an overlay */
  body.has-sidebar {
    display: block;
  }

  /* Show mobile header bar */
  .mobile-header-bar {
    display: flex;
  }

  /* Hide the regular sidebar toggle */
  .sidebar-toggle-mobile {
    display: none;
  }

  .app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    visibility: hidden;
    opacity: 0;
    transition: transform 0.3s ease, visibility 0.3s, opacity 0.3s;
    z-index: 200;
  }
  
  .app-sidebar.open {
    transform: translateX(0);
    visibility: visible;
    opacity: 1;
  }
  
  .app-sidebar.open::before {
    content: '';
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: -1;
  }
  
  /* Ensure sidebar is truly hidden when not open */
  .app-sidebar:not(.open) {
    pointer-events: none;
  }
  
  .app-container {
    margin-left: 0;
    padding-top: 56px; /* Space for mobile header bar */
    width: 100%;
  }

  .header {
    position: relative;
    top: 0;
  }

  .nav {
    padding: 3px;
  }

  .nav-item {
    padding: 8px 14px;
    font-size: 13px;
  }

  .nav-item svg {
    display: none;
  }
}

/* ============================================
   Header
   ============================================ */

.header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  padding: 0 32px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav {
  display: flex;
  gap: 6px;
  background: var(--bg-tertiary);
  padding: 4px;
  border-radius: 12px;
}

.nav-item {
  position: relative;
  padding: 10px 20px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-item svg {
  opacity: 0.7;
}

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

.nav-item:hover svg {
  opacity: 1;
}

.nav-item.active {
  background: var(--bg-primary);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.nav-item.active svg {
  opacity: 1;
  color: var(--accent);
}

.nav-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  display: none;
  border: 2px solid var(--bg-primary);
}

.nav-badge.active {
  display: block;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.2); }
}

.header-actions {
  display: none;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
}

.status-indicator.connected .status-dot {
  background: var(--success);
}

/* ============================================
   Main Content
   ============================================ */

.main {
  min-height: calc(100vh - 56px);
}

.mode-panel {
  display: none;
}

.mode-panel.active {
  display: block;
}

/* Hub mode needs flex layout with fixed height for independent scrolling */
#hub-mode.active {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px); /* Full height minus header */
  overflow: hidden;
}

/* ============================================
   Launch Mode
   ============================================ */

/* Launch mode needs flex layout with fixed height for independent scrolling */
#launch-mode.active {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
  overflow: hidden;
}

.launch-container {
  display: flex;
  flex: 1;
  height: 100%;
  min-height: 0; /* Allow children to scroll */
  overflow: hidden;
}

/* Launch Sidebar - Brain List */
.launch-sidebar {
  width: 320px;
  min-width: 320px;
  height: 100%;
  border-right: 1px solid var(--border);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.launch-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.launch-sidebar-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.launch-brain-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.launch-brain-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 0; /* Allow flex item to scroll */
}

.launch-new-brain-btn {
  margin: 12px;
  padding: 12px 16px;
  border: 2px dashed var(--border);
  background: none;
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
}

.launch-new-brain-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}

/* Launch Main - Form Area */
.launch-main {
  flex: 1;
  overflow-y: auto;
  padding: 60px 32px 48px;
  min-height: 0; /* Allow independent scrolling */
}

.launch-header {
  text-align: center;
  margin-bottom: 48px;
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
}

.launch-header h1 {
  font-size: 36px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  letter-spacing: -1px;
  line-height: 1.2;
}

.launch-header p {
  font-size: 16px;
  color: var(--text-muted);
  max-width: 480px;
  margin: 0 auto;
}

.launch-form {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
}

/* Launch Brain Card (in sidebar) */
.launch-brain-card {
  background: var(--bg-primary);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}

.launch-brain-card:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.launch-brain-card.selected {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.launch-brain-card.active {
  border-color: var(--success);
  background: var(--success-bg);
}

.launch-brain-card .brain-card-main {
  flex: 1;
  min-width: 0;
}

.launch-brain-card .brain-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.launch-brain-card .brain-stats {
  font-size: 12px;
  color: var(--text-muted);
}

.launch-brain-card .brain-card-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.launch-brain-card:hover .brain-card-actions {
  opacity: 1;
}

.form-group {
  margin-bottom: 24px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.label-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 13px;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  font-size: 15px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-bg);
}

.form-input::placeholder {
  color: var(--text-light);
}

.form-input-lg {
  padding: 16px 20px;
  font-size: 17px;
  border-radius: 12px;
}

.form-textarea {
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}

.form-row {
  display: flex;
  gap: 12px;
}

.flex-1 {
  flex: 1;
}

/* Depth Selector */
.depth-selector {
  display: flex;
  gap: 10px;
}

.depth-option {
  flex: 1;
  padding: 16px 12px;
  background: var(--bg-primary);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.depth-option:hover {
  border-color: var(--accent-light);
  background: var(--accent-bg);
}

.depth-option.active {
  background: var(--accent-bg);
  border-color: var(--accent);
}

.depth-name {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.depth-option.active .depth-name {
  color: var(--accent);
}

.depth-desc {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.depth-option.active .depth-desc {
  color: var(--accent);
  opacity: 0.8;
}

/* Mode Selector (Guided vs Autonomous) */
.form-label-primary {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.mode-selector {
  display: flex;
  gap: 12px;
  margin-bottom: 4px;
}

.mode-option {
  flex: 1;
  padding: 20px;
  background: var(--bg-primary);
  border: 2px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 16px;
}

.mode-option:hover {
  border-color: var(--accent-light);
  background: var(--accent-bg);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.mode-option.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.mode-icon {
  font-size: 32px;
  line-height: 1;
}

.mode-content {
  flex: 1;
  text-align: left;
}

.mode-name {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.mode-option.active .mode-name {
  color: var(--accent);
}

.mode-desc {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

.mode-option.active .mode-desc {
  color: var(--accent);
  opacity: 0.9;
}

/* Execution Mode Selector (Guided mode only) */
.execution-mode-selector {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.execution-mode-option {
  flex: 1;
  cursor: pointer;
}

.execution-mode-option input[type="radio"] {
  display: none;
}

.execution-mode-card {
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: 10px;
  transition: all 0.2s;
  text-align: center;
}

.execution-mode-option:hover .execution-mode-card {
  border-color: var(--accent-light);
  background: var(--accent-bg);
}

.execution-mode-option input[type="radio"]:checked + .execution-mode-card {
  background: var(--accent-bg);
  border-color: var(--accent);
}

.execution-mode-name {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.execution-mode-option input[type="radio"]:checked + .execution-mode-card .execution-mode-name {
  color: var(--accent);
}

.execution-mode-desc {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.3;
}

.execution-mode-option input[type="radio"]:checked + .execution-mode-card .execution-mode-desc {
  color: var(--accent);
  opacity: 0.8;
}

/* Autonomous Mode Notice */
.autonomous-notice {
  display: flex;
  gap: 16px;
  padding: 20px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.05), rgba(139, 92, 246, 0.05));
  border: 2px solid rgba(37, 99, 235, 0.2);
  border-radius: 12px;
  margin-bottom: 20px;
}

.autonomous-notice-icon {
  font-size: 28px;
  line-height: 1;
}

.autonomous-notice-content strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.autonomous-notice-content p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}

/* Advanced Options */
.advanced-details {
  margin-top: 16px;
  margin-bottom: 20px;
}

.advanced-summary {
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px 0;
  list-style: none;
}

.advanced-summary::-webkit-details-marker {
  display: none;
}

.advanced-summary::before {
  content: '+';
  display: inline-block;
  width: 16px;
  font-weight: 500;
}

details[open] .advanced-summary::before {
  content: '-';
}

.advanced-content {
  padding: 16px;
  margin-top: 8px;
  background: var(--bg-secondary);
  border-radius: 8px;
}

.advanced-content .form-group {
  margin-bottom: 12px;
}

/* Toggle Items */
.toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.toggle-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: border-color 0.15s;
}

.toggle-item:hover {
  border-color: var(--text-light);
}

.toggle-item input[type="checkbox"] {
  display: none;
}

.toggle-check {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.toggle-check::after {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 2px;
  opacity: 0;
  transform: scale(0);
  transition: all 0.15s;
}

.toggle-item input:checked + .toggle-check {
  border-color: var(--accent);
}

.toggle-item input:checked + .toggle-check::after {
  opacity: 1;
  transform: scale(1);
}

.toggle-label {
  color: var(--text-secondary);
}

/* Section Labels */
.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin: 16px 0 8px 0;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-light);
}

/* Guided Section */
.guided-section {
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  margin-bottom: 12px;
}

/* Subsettings (e.g., Local LLM settings) */
.subsettings {
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  margin-top: 8px;
  margin-bottom: 12px;
}

/* Info Panels */
.info-panel {
  padding: 12px 14px;
  border-radius: 6px;
  margin-top: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.5;
}

.info-panel ul {
  margin: 8px 0 0 0;
  padding-left: 20px;
}

.info-panel li {
  margin: 4px 0;
}

.info-panel.info-warning {
  background: rgba(255, 193, 7, 0.1);
  border: 1px solid rgba(255, 193, 7, 0.3);
  color: #856404;
}

.info-panel.info-accent {
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: var(--accent);
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Flex utilities */
.flex-2 {
  flex: 2;
}

/* Label hints */
.label-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-lg {
  width: 100%;
  padding: 16px 28px;
  font-size: 16px;
  margin-top: 12px;
  border-radius: 12px;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  background: var(--bg-tertiary);
  border-color: var(--text-light);
}

.btn-secondary {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-danger-outline {
  background: transparent;
  border: 1px solid var(--error);
  color: var(--error);
}

.btn-danger-outline:hover {
  background: var(--error-bg);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 8px;
}

/* Recent Section */
.recent-section {
  margin-top: 32px;
}

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

.section-header .section-title {
  margin-bottom: 0;
}

.section-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-input-sm {
  padding: 6px 10px;
  font-size: 13px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.brains-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

.brain-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  gap: 12px;
}

.brain-card:hover {
  border-color: var(--accent-light);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.brain-card-content {
  flex: 1;
  min-width: 0;
}

.brain-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brain-card:active {
  transform: translateY(0);
}

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

.brain-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

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

.brain-domain {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 300px;
}

.brain-action {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.brain-action:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.empty-message {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ============================================
   Watch Mode
   ============================================ */

/* Watch mode needs flex layout with fixed height for independent scrolling */
#watch-mode.active {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
  overflow: hidden;
}

.watch-container {
  flex: 1;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  position: relative;
  overflow: hidden;
}

.watch-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.watch-info {
  flex: 0 0 auto;
  min-width: 200px;
}

.watch-info h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

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

.watch-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 800px;
}

.watch-action-preview {
  padding: 10px 24px;
  background: rgba(37, 99, 235, 0.08);
  border-bottom: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}

.watch-action-preview.hidden {
  display: none;
}

.watch-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 6px var(--sidebar-width, 340px);
  grid-template-rows: 1fr; /* Explicit row height to constrain children */
  gap: 0;
  padding: 16px 24px;
  overflow: hidden;
  min-height: 0; /* Important for flex child overflow */
}

.watch-activity {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding-right: 16px;
}

/* Resize handle between activity and sidebar */
.watch-resize-handle {
  width: 6px;
  background: transparent;
  cursor: col-resize;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s;
}

.watch-resize-handle:hover,
.watch-resize-handle.dragging {
  background: var(--accent);
}

.watch-resize-handle::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 40px;
  background: var(--border);
  border-radius: 1px;
}

.watch-resize-handle:hover::before,
.watch-resize-handle.dragging::before {
  background: var(--accent);
}

.watch-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  height: 100%; /* Fill grid cell */
  padding-left: 10px;
  padding-bottom: 20px; /* Space at bottom when scrolled */
}

.watch-panel {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
}

.panel-header h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-select {
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

/* Activity Stream */
.activity-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  min-height: 0; /* Important for flex scroll */
}

.activity-item {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--bg-secondary);
  border-radius: 6px;
  font-size: 13px;
}

.activity-time {
  color: var(--text-light);
  font-size: 11px;
  font-family: monospace;
  flex-shrink: 0;
}

.activity-icon {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.activity-content {
  flex: 1;
  color: var(--text-secondary);
  line-height: 1.4;
}

.activity-item.thought { border-left: 3px solid var(--accent); }
.activity-item.agent { border-left: 3px solid var(--warning); }
.activity-item.node { border-left: 3px solid var(--success); }
.activity-item.user { border-left: 3px solid #8b5cf6; background: rgba(139, 92, 246, 0.05); }
.activity-item.sleep { border-left: 3px solid #6366f1; background: rgba(99, 102, 241, 0.05); }

/* Current Thought */
.thought-box {
  padding: 16px;
  min-height: 80px;
}

.thought-text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  font-style: italic;
}

.thought-empty {
  color: var(--text-light);
  font-size: 13px;
}

/* Badges */
.badge {
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 500;
  background: var(--bg-tertiary);
  border-radius: 4px;
  color: var(--text-muted);
}

.badge-mode {
  background: var(--accent);
  color: white;
}

/* Metrics */
.metrics {
  padding: 16px;
}

.metric-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.metric-row:last-child {
  margin-bottom: 0;
}

.metric-label {
  width: 60px;
  font-size: 12px;
  color: var(--text-muted);
}

.metric-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.metric-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.metric-fill.metric-warn {
  background: var(--warning);
}

.metric-val {
  width: 32px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 16px;
  text-align: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-num {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Insights Panel */
.insights-list {
  max-height: 200px;
  overflow-y: auto;
  padding: 8px 12px;
}

.insights-empty {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 16px;
  margin: 0;
}

.insight-item {
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--bg-secondary);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}

.insight-content {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
  margin-bottom: 4px;
}

.insight-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.insight-novelty {
  color: var(--success);
  font-weight: 600;
}

/* Action Preview in Header */
.action-preview-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
  letter-spacing: 0.5px;
}

.action-preview-content {
  font-size: 12px;
  color: var(--accent);
  line-height: 1.4;
}

/* Action History Panel */
.action-history-content {
  padding: 12px;
}

.action-history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.action-history-empty {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
}

.action-history-item {
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
  transition: all 0.15s;
}

.action-history-item:hover {
  background: var(--bg-tertiary);
}

.action-history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 8px;
}

.action-history-item-time {
  color: var(--text-muted);
  font-size: 11px;
  font-family: monospace;
}

.action-history-item-type {
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.action-history-item-mission {
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.4;
}

/* Watch Placeholder */
.watch-placeholder {
  position: absolute;
  inset: 0;
  top: 53px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  text-align: center;
  padding: 40px;
}

.watch-placeholder.hidden {
  display: none;
}

.placeholder-icon {
  width: 64px;
  height: 64px;
  color: var(--text-light);
  margin-bottom: 16px;
}

.watch-placeholder h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.watch-placeholder p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ============================================
   Studio Mode
   ============================================ */

#studio-mode {
  height: calc(100vh - 56px);
  position: relative;
}

.studio-frame {
  width: 100%;
  height: 100%;
  border: none;
}

.studio-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  text-align: center;
  padding: 40px;
}

.studio-placeholder.hidden {
  display: none;
}

.studio-placeholder h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.studio-placeholder p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ============================================
   Toasts
   ============================================ */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  font-size: 14px;
  color: var(--text-primary);
  animation: slideIn 0.2s ease;
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.error {
  border-left: 3px solid var(--error);
}

.toast.info {
  border-left: 3px solid var(--accent);
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============================================
   Utilities
   ============================================ */

.hidden {
  display: none !important;
}

/* ============================================
   Responsive
   ============================================ */

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

  .watch-resize-handle,
  .watch-sidebar {
    display: none;
  }

  .watch-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .watch-actions {
    width: 100%;
    max-width: none;
  }

  .watch-actions select,
  .watch-actions input {
    flex: 1;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  .header-inner {
    padding: 0 16px;
  }

  .launch-container {
    padding: 24px 16px;
  }

  .launch-header h1 {
    font-size: 22px;
  }

  .depth-selector {
    flex-direction: column;
  }

  .toggle-grid {
    grid-template-columns: 1fr;
  }

  /* Mobile responsive for new mode selector */
  .mode-selector {
    flex-direction: column;
  }

  .mode-option {
    padding: 16px;
  }

  .mode-icon {
    font-size: 24px;
  }

  .execution-mode-selector {
    flex-direction: column;
  }

  .form-row {
    flex-direction: column;
  }

  .watch-grid {
    padding: 12px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}

/* ============================================
   Explore Mode
   ============================================ */

#explore-mode {
  height: calc(100vh - 56px);
}

.explore-container {
  display: flex;
  height: 100%;
  background: var(--bg-secondary);
}

/* Sidebar */
.explore-sidebar {
  width: var(--explore-sidebar-width, 280px);
  min-width: 60px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.2s ease;
}

.explore-sidebar.collapsed {
  width: 48px;
  min-width: 48px;
}

.explore-sidebar.collapsed .sidebar-header h3,
.explore-sidebar.collapsed .brain-list {
  display: none;
}

.explore-sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 12px 8px;
}

/* Sidebar resize handle */
.explore-sidebar-resize {
  width: 6px;
  background: transparent;
  cursor: col-resize;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s;
}

.explore-sidebar-resize:hover,
.explore-sidebar-resize.dragging {
  background: var(--accent);
}

.explore-sidebar-resize::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 40px;
  background: var(--border);
  border-radius: 1px;
}

.explore-sidebar-resize:hover::before,
.explore-sidebar-resize.dragging::before {
  background: var(--accent);
}

/* Sidebar toggle button */
.sidebar-toggle {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
  margin-right: 8px;
}

.sidebar-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.explore-sidebar.collapsed .sidebar-toggle {
  margin-right: 0;
}

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

.sidebar-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}

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

.brain-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.brain-list-item {
  padding: 12px;
  margin-bottom: 4px;
  background: var(--bg-secondary);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.brain-list-item:hover {
  border-color: var(--border);
  background: var(--bg-tertiary);
}

.brain-list-item.active {
  border-color: var(--accent);
  background: rgba(34, 139, 230, 0.08);
}

.brain-list-item .brain-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.brain-list-item .brain-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
}

.brain-list-item .brain-domain {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brain-list-item .brain-type {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  margin-bottom: 6px;
  display: inline-block;
}

.brain-list-item .brain-type.brain {
  background: rgba(34, 139, 230, 0.1);
  color: var(--accent);
}

.brain-list-item .brain-type.run {
  background: rgba(64, 192, 87, 0.1);
  color: var(--success);
}

.brain-list-item.running {
  border-color: var(--success);
  background: rgba(64, 192, 87, 0.05);
}

.brain-list-item .brain-type-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.brain-list-item .brain-active-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--success);
  color: white;
  animation: pulse-badge 2s ease-in-out infinite;
}

.brain-list-item-main {
  flex: 1;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.brain-list-item-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.brain-list-item .brain-topic {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.loading-spinner {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Small inline spinner for buttons */
.spinner-small {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* Main Explore Area */
.explore-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.explore-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}

.explore-empty h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.explore-empty p {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 400px;
}

.explore-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.explore-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
}

.explore-title h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

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

.explore-details {
  display: flex;
  gap: 12px;
  margin-top: 4px;
}

.explore-details .explore-meta::before {
  content: '';
}

.explore-details .explore-meta:not(:first-child)::before {
  content: '·';
  margin-right: 12px;
  color: var(--text-light);
}

.explore-domain {
  font-size: 12px;
  color: var(--text-light);
  font-style: italic;
  margin-top: 4px;
}

.explore-actions {
  display: flex;
  gap: 8px;
}

/* Explore Layout */
.explore-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* Graph Container */
.explore-graph-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  min-width: 300px;
  overflow: hidden;
  position: relative;
}

/* Graph-Panel resize handle */
.explore-panel-resize {
  width: 6px;
  background: transparent;
  cursor: col-resize;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s;
}

.explore-panel-resize:hover,
.explore-panel-resize.dragging {
  background: var(--accent);
}

.explore-panel-resize::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 40px;
  background: var(--border);
  border-radius: 1px;
}

.explore-panel-resize:hover::before,
.explore-panel-resize.dragging::before {
  background: var(--accent);
}

.graph-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.graph-controls .form-input {
  flex: 1;
  max-width: 240px;
}

.graph-filters {
  display: flex;
  gap: 6px;
}

.filter-chip {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.filter-chip:hover {
  border-color: var(--text-light);
}

.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.knowledge-graph {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.graph-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* Node styling for D3 */
.knowledge-graph svg {
  width: 100%;
  height: 100%;
}

.knowledge-graph .node circle {
  stroke: var(--bg-primary);
  stroke-width: 2px;
  cursor: pointer;
  transition: r 0.2s;
}

.knowledge-graph .node circle:hover {
  stroke: var(--accent);
  stroke-width: 3px;
}

.knowledge-graph .node text {
  font-size: 10px;
  fill: var(--text-secondary);
  pointer-events: none;
}

.knowledge-graph .link {
  stroke: var(--border);
  stroke-opacity: 0.6;
}

/* Graph Zoom Controls */
.graph-zoom-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: var(--shadow-sm);
}

.zoom-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.zoom-btn:hover {
  background: var(--bg-tertiary);
  color: var(--accent);
  border-color: var(--accent);
}

.zoom-btn:active {
  transform: scale(0.95);
}

.zoom-btn svg {
  width: 16px;
  height: 16px;
}

/* Explore Panel */
.explore-panel {
  width: var(--explore-panel-width, 420px);
  min-width: 320px;
  max-width: 650px;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  overflow: hidden;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.panel-tab {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

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

.panel-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.panel-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow: hidden;
  min-height: 0;
}

.panel-content.hidden {
  display: none !important;
}

/* Query Panel */
.query-controls {
  margin-bottom: 12px;
}

.query-textarea {
  min-height: 80px;
  resize: vertical;
  margin-bottom: 12px;
}

.query-result {
  flex: 1;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
  margin-top: 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Query Panel - Full Implementation */
.query-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 0;
}

/* Query Input Section - Fixed at top */
.query-input-section {
  flex-shrink: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

.query-textarea {
  min-height: 70px;
  max-height: 120px;
  resize: vertical;
  margin-bottom: 10px;
}

.query-actions-compact {
  display: flex;
  gap: 8px;
  align-items: center;
}

.query-actions-compact .btn-primary {
  padding: 10px 20px;
}

.query-actions-compact .btn-sm {
  padding: 8px 12px;
}

/* Context Indicator */
.context-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 4px 10px;
  background: var(--success-bg);
  border: 1px solid var(--success);
  border-radius: 12px;
  font-size: 11px;
  color: var(--success);
  animation: fadeIn 0.3s ease;
}

.context-indicator.hidden {
  display: none;
}

.context-dot {
  width: 6px;
  height: 6px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

.context-text {
  font-weight: 500;
}

/* Collapsible Options Section */
.query-options-section {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-light);
}

.query-options-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  list-style: none;
  -webkit-user-select: none;
  user-select: none;
}

.query-options-toggle::-webkit-details-marker {
  display: none;
}

.query-options-toggle .toggle-icon {
  font-size: 10px;
  transition: transform 0.2s ease;
  color: var(--text-muted);
}

.query-options-section[open] .toggle-icon {
  transform: rotate(90deg);
}

.query-options-toggle .options-summary {
  margin-left: auto;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-light);
  background: var(--bg-secondary);
  padding: 3px 8px;
  border-radius: 4px;
}

.query-options-content {
  padding: 12px 0 16px;
}

.query-options-content .quick-prompts {
  margin: 0 0 12px 0;
}

.query-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 8px;
}

.query-option-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.query-option-group label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-select-sm {
  padding: 6px 10px;
  font-size: 13px;
}

.query-mode-hint {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  padding: 6px 0;
}

/* Response Section - Takes remaining space */
.query-response-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 200px;
  padding-top: 12px;
  overflow: hidden;
}

/* Quick Prompts */
.quick-prompts {
  margin: 0 0 12px 0;
  padding: 10px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  border: 1px solid var(--border-light);
}

/* Quick prompts when inside options section */
.query-options-content .quick-prompts {
  margin: 0 0 12px 0;
}

.quick-prompts-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.quick-prompts-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quick-prompt-btn {
  padding: 6px 10px;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.quick-prompt-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Query Suggestions */
.query-suggestions {
  margin: 8px 0;
}

.query-suggestions .quick-prompts-grid {
  gap: 4px;
}

.query-suggestions .quick-prompt-btn {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.2);
  color: var(--accent);
}

.query-enhancements,
.query-context-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 0;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.toggle-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* Legacy query actions - hidden (replaced by compact version) */
.query-actions {
  display: none;
}

.query-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 24px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-radius: 10px;
  flex: 1;
}

.query-loading .loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.query-loading .loading-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* Response Area - Main reading space */
.query-result {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
}

.query-result.hidden {
  display: none;
}

.query-result.has-content {
  background: var(--bg-secondary);
}

/* Placeholder when no results */
.query-result-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  min-height: 180px;
  color: var(--text-muted);
  padding: 24px;
}

.query-result-placeholder svg {
  color: var(--text-light);
  margin-bottom: 16px;
  opacity: 0.6;
}

.query-result-placeholder p {
  margin: 0 0 4px 0;
  font-size: 14px;
}

.query-result-placeholder .hint {
  font-size: 12px;
  color: var(--text-light);
}

/* Error state */
.query-result .error-message {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  background: var(--error-bg);
  border: 1px solid var(--error);
  border-radius: 8px;
  color: var(--error);
  font-size: 14px;
}

/* Query result with content */
.query-result.has-content {
  background: var(--bg-secondary);
  padding: 24px;
}

.query-result .answer-header {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.query-result .answer-content {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
}

.query-result .answer-content h1,
.query-result .answer-content h2,
.query-result .answer-content h3 {
  margin-top: 16px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.query-result .answer-content code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', monospace;
  font-size: 13px;
}

.query-result .answer-content pre {
  background: var(--bg-tertiary);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
}

.query-result .answer-metadata {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.query-result .evidence-panel,
.query-result .synthesis-panel {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-size: 13px;
}

.query-result .panel-title {
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

/* Query History - Collapsible section at bottom */
.query-history-section {
  flex-shrink: 0;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}

.query-history-section.hidden {
  display: none !important;
}

.history-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  list-style: none;
  -webkit-user-select: none;
  user-select: none;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.history-toggle:hover {
  background: var(--bg-tertiary);
}

.history-toggle::-webkit-details-marker {
  display: none;
}

.history-toggle::before {
  content: '▶';
  font-size: 10px;
  margin-right: 8px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.query-history-section[open] .history-toggle::before {
  transform: rotate(90deg);
}

.query-history-list {
  padding: 8px 0;
  max-height: 180px;
  overflow-y: auto;
}

/* Legacy support */
.query-history {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
}

.btn-text:hover {
  text-decoration: underline;
}

.history-item {
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.history-item:hover {
  background: var(--accent-bg);
  border-color: var(--accent-light);
}

.history-item:active {
  transform: scale(0.99);
}

.history-query {
  font-size: 13px;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  align-items: center;
}

.history-meta::after {
  content: 'Click to use as context';
  margin-left: auto;
  font-size: 10px;
  color: var(--text-light);
  font-style: italic;
}
}

/* Chat Panel - Full Implementation */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  min-height: 200px;
}

.chat-welcome {
  text-align: center;
  padding: 24px;
  color: var(--text-secondary);
}

.chat-welcome h4 {
  margin-bottom: 8px;
  color: var(--text-primary);
}

.chat-welcome p {
  font-size: 13px;
}

.chat-message {
  margin-bottom: 12px;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
}

.chat-message.user {
  background: var(--accent);
  color: white;
  margin-left: 40px;
}

.chat-message.assistant {
  background: var(--bg-secondary);
  color: var(--text-primary);
  margin-right: 40px;
}

.chat-message.system {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  margin: 8px 40px;
}

.chat-message .message-content {
  white-space: pre-wrap;
}

.chat-input-area {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.chat-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
}

.chat-input-row textarea {
  flex: 1;
  resize: none;
}

/* Outputs Panel */
.outputs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.output-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.output-item:hover {
  background: var(--bg-tertiary);
}

.output-icon {
  font-size: 18px;
}

.output-name {
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
}

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

/* Output Tree Structure */
.output-section {
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.output-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.output-section-header:hover {
  background: var(--bg-tertiary);
}

.section-icon {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s;
  width: 12px;
}

.output-section:not(.collapsed) .section-icon {
  transform: rotate(90deg);
}

.section-label {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.section-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 10px;
}

.output-section-content {
  background: var(--bg-primary);
  padding: 4px;
}

.output-section.collapsed .output-section-content {
  display: none;
}

/* Folder Tree */
.folder-node {
  margin-bottom: 2px;
}

.folder-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s;
}

.folder-header:hover {
  background: var(--bg-tertiary);
}

.folder-icon {
  font-size: 9px;
  color: var(--text-muted);
  transition: transform 0.2s;
  width: 10px;
}

.folder-node:not(.collapsed) .folder-icon {
  transform: rotate(90deg);
}

.folder-name {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
}

.folder-count {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 1px 6px;
  border-radius: 8px;
}

.folder-content {
  margin-left: 8px;
  border-left: 1px solid var(--border);
  padding-left: 4px;
}

.folder-node.collapsed .folder-content {
  display: none;
}

/* Output Items in Tree */
.outputs-list .output-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}

.outputs-list .output-item:hover {
  background: var(--bg-tertiary);
}

.output-name {
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Responsive */
@media (max-width: 1100px) {
  .explore-layout {
    flex-direction: column;
  }

  .explore-panel-resize {
    display: none;
  }

  .explore-panel {
    width: 100% !important;
    max-width: none;
    border-top: 1px solid var(--border);
    max-height: 300px;
  }

  .explore-graph-container {
    min-height: 300px;
  }
}

@media (max-width: 768px) {
  .explore-sidebar,
  .explore-sidebar-resize {
    display: none;
  }
}

/* ============================================
   Run Details Modal
   ============================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  position: relative;
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  background: var(--bg-primary);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
}

.modal-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.modal-footer {
  display: flex;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  justify-content: space-between;
}

.modal-footer-left {
  display: flex;
  gap: 8px;
}

.modal-footer-right {
  display: flex;
  gap: 12px;
}

/* Detail Sections */
.detail-section {
  margin-bottom: 20px;
}

.detail-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.detail-value {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
}

.detail-value.topic-value {
  font-size: 16px;
  font-weight: 500;
}

/* Stats Grid in Modal */
.detail-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
  margin-bottom: 20px;
}

.detail-stat {
  text-align: center;
}

.detail-stat .stat-number {
  display: block;
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

.detail-stat .stat-name {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 2px;
}

/* Settings in Modal */
.detail-settings {
  margin-bottom: 20px;
}

.detail-settings summary {
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px 0;
}

.detail-settings summary::-webkit-details-marker {
  display: none;
}

.detail-settings summary::before {
  content: '▶';
  display: inline-block;
  width: 16px;
  font-size: 10px;
  transition: transform 0.15s;
}

.detail-settings[open] summary::before {
  transform: rotate(90deg);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 12px;
  margin-top: 8px;
  background: var(--bg-secondary);
  border-radius: 8px;
}

.setting-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.setting-item .setting-icon {
  width: 16px;
  text-align: center;
}

.setting-item.enabled .setting-icon {
  color: var(--success);
}

.setting-item.disabled .setting-icon {
  color: var(--text-light);
}

/* Outputs Preview in Modal */
.outputs-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.outputs-preview .output-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border-radius: 16px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.outputs-preview .output-chip:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.outputs-preview .no-outputs {
  font-size: 13px;
  color: var(--text-muted);
}

/* Modal responsive */
@media (max-width: 640px) {
  .modal-content {
    width: 95%;
    max-height: 90vh;
  }

  .modal-header {
    padding: 16px 20px;
  }

  .modal-body {
    padding: 20px;
  }

  .modal-footer {
    flex-direction: column;
    padding: 16px 20px;
  }

  .modal-footer .btn {
    width: 100%;
  }

  .detail-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================
   Graph Legend
   ============================================ */

.graph-legend {
  position: absolute;
  bottom: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--border);
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.legend-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ============================================
   Node Detail Panel (Slide-in from right)
   ============================================ */

#node-detail-modal {
  position: fixed;
  top: 56px; /* Below header */
  right: 0;
  bottom: 0;
  width: 450px;
  max-width: 90vw;
  background: var(--bg-primary);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

#node-detail-modal:not(.hidden) {
  transform: translateX(0);
}

#node-detail-modal .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

#node-detail-modal .modal-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

#node-detail-modal .modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 20px;
  line-height: 1;
  transition: all 0.15s;
}

#node-detail-modal .modal-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

#node-detail-modal .modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

#node-detail-modal .modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  display: flex;
  gap: 12px;
}

.node-detail-modal {
  /* Legacy class - keep for compatibility */
  max-width: 600px;
  width: 90%;
}

.node-detail-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.node-type-badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 12px;
  background: var(--accent);
  color: white;
}

.node-type-badge.research { background: #228be6; }
.node-type-badge.insight { background: #40c057; }
.node-type-badge.agent { background: #fab005; color: #000; }
.node-type-badge.curiosity { background: #7950f2; }
.node-type-badge.critic { background: #fa5252; }

.node-date {
  font-size: 12px;
  color: var(--text-muted);
}

.node-detail-section {
  margin-bottom: 20px;
}

.node-detail-section h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.node-content-box {
  padding: 14px;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.6;
  max-height: 200px;
  overflow-y: auto;
}

.node-connections-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.node-connection-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.node-connection-chip:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.node-connection-chip .conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.node-metadata-box {
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
}

.node-metadata-box .meta-row {
  display: flex;
  padding: 4px 0;
  border-bottom: 1px solid var(--border-light);
}

.node-metadata-box .meta-row:last-child {
  border-bottom: none;
}

.node-metadata-box .meta-key {
  flex: 0 0 100px;
  font-weight: 500;
  color: var(--text-secondary);
}

.node-metadata-box .meta-value {
  flex: 1;
  color: var(--text-primary);
}

/* ============================================
   Intelligence Detail Drawer
   ============================================ */

#intelligence-detail-drawer {
  position: fixed;
  top: 56px;
  right: 0;
  bottom: 0;
  width: 520px;
  max-width: 95vw;
  background: var(--bg-primary);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  z-index: 150;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

#intelligence-detail-drawer:not(.hidden) {
  transform: translateX(0);
}

#intelligence-detail-drawer .drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  gap: 12px;
}

#intelligence-detail-drawer .drawer-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

#intelligence-detail-drawer .drawer-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Breadcrumb styles */
.drawer-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: thin;
}

.breadcrumb-item {
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s;
}

.breadcrumb-item:hover {
  color: var(--accent);
}

.breadcrumb-item.current {
  color: var(--text-primary);
  font-weight: 500;
  cursor: default;
}

.breadcrumb-separator {
  color: var(--text-light);
}

.drawer-subheader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-light);
}

.drawer-back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.drawer-back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.entity-type-badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-radius: 12px;
  background: var(--accent);
  color: white;
}

.entity-type-badge.agent { background: #fab005; color: #000; }
.entity-type-badge.goal { background: #228be6; }
.entity-type-badge.insight { background: #40c057; }
.entity-type-badge.thought { background: #7950f2; }
.entity-type-badge.dream { background: #be4bdb; }
.entity-type-badge.review { background: #fd7e14; }
.entity-type-badge.trace { background: #20c997; }

#intelligence-detail-drawer .drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

#intelligence-detail-drawer .drawer-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

/* Detail sections within drawer */
.intel-detail-section {
  margin-bottom: 20px;
}

.intel-detail-section h4 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.intel-detail-content {
  padding: 14px;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Clickable entity links */
.intel-entity-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  margin: 4px;
}

.intel-entity-link:hover {
  background: rgba(37, 99, 235, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}

.intel-entity-link .link-icon {
  font-size: 14px;
}

/* Related entities section */
.intel-related-entities {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

/* Stats grid in drawer */
.intel-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.intel-stat-item {
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
  text-align: center;
  border: 1px solid var(--border);
}

.intel-stat-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}

.intel-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 4px;
}

/* Results list */
.intel-results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.intel-result-item {
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  font-size: 13px;
}

.intel-result-item .result-type {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.intel-result-item .result-content {
  color: var(--text-secondary);
  line-height: 1.5;
  max-height: 100px;
  overflow-y: auto;
}

/* Progress reports in agent detail */
.intel-progress-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.intel-progress-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.intel-progress-item .progress-percent {
  flex: 0 0 40px;
  font-weight: 600;
  color: var(--accent);
}

/* Clickable table rows */
.intelligence-clickable-row {
  cursor: pointer;
  transition: background 0.15s;
}

.intelligence-clickable-row:hover {
  background: var(--bg-hover) !important;
}

/* ============================================
   IDE Mode
   ============================================ */

.ide-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
  background: var(--bg-primary);
}

.ide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ide-brain-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ide-label {
  font-size: 13px;
  color: var(--text-muted);
}

.ide-brain-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.ide-actions {
  display: flex;
  gap: 8px;
}

.ide-frame-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.ide-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
}

.ide-loading-content {
  text-align: center;
}

.ide-loading-content .spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.ide-loading-content p {
  margin: 8px 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.ide-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: var(--bg-primary);
}

.ide-frame.hidden {
  display: none;
}

/* IDE loading states */
.ide-loading.launching .spinner {
  border-top-color: var(--success);
}

.ide-loading.launching p:first-of-type {
  color: var(--success);
}

.ide-loading.error .spinner {
  border-top-color: var(--error);
  animation: none;
}

.ide-loading.error p:first-of-type {
  color: var(--error);
}

/* ============================================
   Auth UI (Week 1 MVP)
   ============================================ */

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

.auth-loading {
  font-size: 12px;
  color: var(--text-muted);
}

.auth-signed-out,
.auth-signed-in {
  display: flex;
  align-items: center;
  gap: 8px;
}

#user-button {
  display: flex;
  align-items: center;
}

/* ============================================
   Settings Mode (Week 1 MVP)
   ============================================ */

.settings-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 24px;
}

.settings-header {
  margin-bottom: 40px;
}

.settings-header h1 {
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 12px;
  letter-spacing: -0.5px;
}

.settings-header p {
  color: var(--text-muted);
  font-size: 16px;
}

.settings-auth-required {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
}

.auth-required-content {
  text-align: center;
  max-width: 400px;
}

.auth-required-content .auth-icon {
  color: var(--text-muted);
  margin-bottom: 24px;
}

.auth-required-content h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.auth-required-content p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.settings-section {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.settings-section h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.settings-section .section-desc {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
  line-height: 1.6;
}

/* API Keys */
.api-keys-list {
  margin-bottom: 24px;
}

.no-keys {
  text-align: center;
  padding: 32px;
  color: var(--text-secondary);
}

.no-keys p {
  margin: 4px 0;
}

.api-key-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
}

.api-key-item.inactive {
  opacity: 0.6;
}

.key-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.key-prefix {
  font-family: monospace;
  font-size: 14px;
  background: var(--bg-tertiary);
  padding: 4px 8px;
  border-radius: 4px;
}

.key-provider {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
}

.badge-openai {
  background: rgba(16, 163, 127, 0.2);
  color: #10a37f;
}

.badge-anthropic {
  background: rgba(204, 147, 102, 0.2);
  color: #cc9366;
}

.badge-xai {
  background: rgba(88, 166, 255, 0.2);
  color: #58a6ff;
}

.key-status {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
}

.key-status.active {
  background: rgba(64, 192, 87, 0.2);
  color: var(--success);
}

.key-status.inactive {
  background: rgba(134, 142, 150, 0.2);
  color: var(--text-muted);
}

.key-meta {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
  text-align: center;
}

.key-actions {
  display: flex;
  gap: 8px;
}

.add-key-form {
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.key-input-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.key-input-row .form-input:first-child {
  flex: 2;
  min-width: 300px;
}

.key-input-row .form-select-sm {
  min-width: 120px;
}

/* Usage Stats */
.usage-stats {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.usage-stat {
  padding: 16px;
  background: var(--bg-primary);
  border-radius: 8px;
}

.usage-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.usage-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.usage-value {
  font-size: 14px;
  font-weight: 500;
}

.usage-bar {
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}

.usage-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.usage-fill.warning {
  background: var(--warning);
}

.usage-reset-info {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Account */
.account-info {
  margin-bottom: 20px;
}

.account-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.account-row:last-child {
  border-bottom: none;
}

.account-label {
  color: var(--text-secondary);
}

.account-value {
  font-weight: 500;
}

.account-actions {
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.profile-form {
  max-width: 800px;
}

.profile-form .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.profile-form textarea.form-input {
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
}

.form-actions {
  display: flex;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: 24px;
}

.form-actions button {
  min-width: 120px;
}

@media (max-width: 768px) {
  .profile-form .form-row {
    grid-template-columns: 1fr;
  }
}

.tier-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--accent);
  color: white;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

/* Button variants */
.btn-danger-outline {
  border: 1px solid var(--error);
  color: var(--error);
  background: transparent;
}

.btn-danger-outline:hover {
  background: rgba(250, 82, 82, 0.1);
}

/* ============================================
   Launch Limits Bar (Week 1 MVP)
   ============================================ */

.launch-limits-bar {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 20px;
}

.limits-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.limits-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.limits-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.limits-link:hover {
  text-decoration: underline;
}

.limits-items {
  display: flex;
  gap: 24px;
}

.limit-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.limit-label {
  font-size: 12px;
  color: var(--text-muted);
}

.limit-value {
  font-size: 12px;
  font-weight: 500;
  min-width: 50px;
}

.limit-bar {
  width: 60px;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.limit-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.limit-fill.warning {
  background: var(--warning);
}

.limit-fill.danger {
  background: var(--error);
}

.no-key-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 8px 12px;
  background: rgba(250, 176, 5, 0.1);
  border: 1px solid rgba(250, 176, 5, 0.3);
  border-radius: 6px;
  font-size: 13px;
  color: var(--warning);
}

.no-key-warning a {
  color: var(--warning);
  font-weight: 500;
}

.no-key-warning svg {
  flex-shrink: 0;
}

/* ============================================
   HUB MODE STYLES
   ============================================ */

.hub-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: 100%;
  min-height: 0; /* Allow children to scroll */
  background: var(--bg-primary);
  overflow: hidden;
}

.hub-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-secondary);
}

.hub-header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.hub-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hub-badge {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.hub-badge-accent {
  color: var(--accent);
  background: var(--accent-bg);
  border-color: var(--accent-light);
}

.hub-actions {
  display: flex;
  gap: 8px;
}

.hub-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  height: 100%;
  min-height: 0; /* Critical for flex children to respect overflow */
}

.hub-sidebar {
  width: 320px;
  min-width: 320px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  overflow: hidden; /* Sidebar container doesn't scroll */
  height: 100%;
}

.hub-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.hub-search input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
}

.hub-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.hub-list-header {
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.hub-list-header span {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hub-list-header button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.hub-list-header button:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.hub-brain-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 0; /* Allow flex item to shrink and scroll */
}

.hub-section-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 8px 12px;
  margin: 8px 0 4px 0;
  background: var(--bg-tertiary);
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hub-brain-item {
  padding: 14px 16px;
  margin: 4px 0;
  background: var(--bg-primary);
  border-radius: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s ease;
}

.hub-brain-item:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.hub-brain-item.selected {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.hub-brain-item.previewing {
  background: var(--bg-tertiary);
}

.hub-brain-item-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
}

.hub-brain-item-info {
  flex: 1;
  min-width: 0;
}

.hub-brain-item-name {
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.hub-brain-item-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Package-specific styling - make .brain files obvious */
.hub-package-filename {
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  background: var(--accent-bg);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
}

.hub-brain-item-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.hub-brain-item-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.hub-brain-item input[type="checkbox"] {
  cursor: pointer;
  margin-left: 8px;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.hub-visibility-badge {
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

.hub-visibility-badge.public {
  background: var(--success-bg);
  color: var(--success);
}

.hub-visibility-badge.unlisted {
  background: var(--warning-bg);
  color: var(--warning);
}

.hub-visibility-badge.private {
  background: var(--bg-tertiary);
  color: var(--text-muted);
}

.hub-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
  height: 100%;
  min-height: 0; /* Allow flex item to respect overflow */
}

.hub-preview-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  min-height: 0; /* Allow content to scroll independently */
}

.hub-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 40px;
  color: var(--text-muted);
}

.hub-empty-state svg {
  opacity: 0.4;
  margin-bottom: 20px;
}

.hub-empty-state h3 {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.hub-empty-state p {
  font-size: 14px;
}

.hub-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
  gap: 12px;
}

.hub-status {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  background: var(--bg-secondary);
}

/* Hub Details Panel */
.hub-details-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 24px;
}

.hub-details-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hub-details-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.hub-details-type {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.hub-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.hub-stat-card {
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: 12px;
  text-align: center;
  border: 1px solid var(--border);
}

.hub-stat-value {
  font-size: 32px;
  font-weight: 700;
}

.hub-stat-value.nodes { color: var(--accent); }
.hub-stat-value.edges { color: var(--success); }
.hub-stat-value.cycles { color: var(--warning); }
.hub-stat-value.outputs { color: var(--text-primary); }

.hub-stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 6px;
}

.hub-metadata-card {
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.hub-metadata-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin: 0 0 14px 0;
  font-weight: 500;
}

.hub-metadata-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  font-size: 14px;
}

.hub-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hub-topic-tag {
  background: var(--bg-tertiary);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 13px;
  color: var(--text-primary);
}

/* Hub Modal */
.hub-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.hub-modal {
  background: var(--bg-primary);
  border-radius: 16px;
  padding: 28px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.hub-modal h3 {
  margin: 0 0 24px 0;
  color: var(--text-primary);
  font-size: 20px;
}

.hub-form-group {
  margin-bottom: 20px;
}

.hub-form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 8px;
}

.hub-form-input,
.hub-form-select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
}

.hub-form-input:focus,
.hub-form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.hub-form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.hub-status-message {
  padding: 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}

.hub-status-message.info {
  background: var(--accent-bg);
  color: var(--accent);
}

.hub-status-message.success {
  background: var(--success-bg);
  color: var(--success);
}

.hub-status-message.error {
  background: var(--error-bg);
  color: var(--error);
}

.hub-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 28px;
}

/* Merge Preview */
.hub-merge-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hub-merge-source-tag {
  background: var(--bg-tertiary);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
}

.hub-merge-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.hub-merge-preview-box {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid var(--border);
}

.hub-merge-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.hub-merge-preview-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin: 0;
  font-weight: 500;
}

.hub-merge-preview-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.hub-merge-stat {
  text-align: center;
  padding: 16px;
  background: var(--bg-primary);
  border-radius: 8px;
}

.hub-merge-stat-value {
  font-size: 28px;
  font-weight: 700;
}

.hub-merge-stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Hub Tabs */
.hub-tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.hub-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s ease;
}

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

.hub-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.hub-tab svg {
  width: 16px;
  height: 16px;
}

.hub-tab-content {
  display: none;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.hub-tab-content.active {
  display: flex;
  flex-direction: column;
  min-height: 0; /* Critical for nested flex scroll */
}

/* Discover Tab */
.discover-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow: hidden;
}

.discover-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.discover-search {
  display: flex;
  gap: 8px;
  flex: 1;
  max-width: 500px;
}

.discover-search input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
}

.discover-search input:focus {
  outline: none;
  border-color: var(--accent);
}

.discover-filters {
  display: flex;
  gap: 8px;
}

.discover-filters select {
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
}

/* Package Grid */
.discover-packages-grid,
.stars-packages-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  overflow-y: auto;
  padding-bottom: 24px;
}

.discover-package-card {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.discover-package-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.package-card-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.package-card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.package-card-author {
  font-size: 13px;
  color: var(--text-muted);
}

.package-card-description {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.package-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.package-card-tags .hub-topic-tag {
  padding: 4px 10px;
  font-size: 12px;
}

.package-card-tags .hub-topic-tag.domain {
  background: var(--accent-bg);
  color: var(--accent);
}

.package-card-stats {
  display: flex;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.package-card-stats span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.package-card-engagement {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.package-card-engagement span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.package-license {
  margin-left: auto;
  font-size: 11px;
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 4px;
}

.package-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.package-card-actions .btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* Pagination */
.discover-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
}

.pagination-info {
  font-size: 13px;
  color: var(--text-muted);
}

/* Stars Tab */
.stars-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow: hidden;
}

.stars-header {
  margin-bottom: 24px;
}

.stars-header h2 {
  margin: 0 0 8px 0;
  font-size: 20px;
  color: var(--text-primary);
}

.stars-header .text-muted {
  color: var(--text-muted);
  font-size: 14px;
}

/* Package Detail Modal */
.package-detail {
  color: var(--text-primary);
}

.package-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 20px;
}

.package-detail-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.package-detail-meta {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.package-detail-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

.package-section {
  margin-bottom: 24px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.package-section h4 {
  margin: 0 0 12px 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.package-section p {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
}

.merge-sources-list {
  margin: 8px 0 0 0;
  padding-left: 20px;
}

.merge-sources-list li {
  margin: 6px 0;
  font-size: 14px;
}

.merge-quality {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Button Variants for Hub */
.btn-warning {
  background: var(--warning);
  color: #000;
  border-color: var(--warning);
}

.btn-warning:hover {
  background: var(--warning);
  opacity: 0.9;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
}

/* Attribution Notice */
.attribution-notice {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Icon Buttons */
.btn-icon {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  color: var(--text-primary);
}

.btn-icon:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-icon.btn-danger:hover {
  background: var(--error-bg);
  border-color: var(--error);
  color: var(--error);
}

.btn-icon:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

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

/* ============================================
   Pricing & Subscription Styles
   ============================================ */

.pricing-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  margin-top: 24px;
}

.pricing-card {
  background: var(--bg-primary);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 32px 24px;
  text-align: center;
  transition: all 0.2s ease;
  position: relative;
  display: flex;
  flex-direction: column;
}

.pricing-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.pricing-card-featured {
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
  box-shadow: var(--shadow);
}

.pricing-card-current {
  opacity: 0.8;
  border-color: var(--success);
}

.pricing-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--success);
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.pricing-tier-name {
  margin: 0 0 16px 0;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.pricing-price {
  font-size: 56px;
  font-weight: 800;
  margin: 16px 0 24px 0;
  color: var(--accent);
  line-height: 1;
}

.pricing-free {
  font-size: 36px;
  color: var(--text-secondary);
}

.pricing-interval {
  font-size: 18px;
  font-weight: 400;
  color: var(--text-secondary);
}

.pricing-features {
  list-style: none;
  padding: 0;
  margin: 24px 0;
  text-align: left;
  flex: 1;
}

.pricing-features li {
  padding: 10px 0;
  color: var(--text-secondary);
  font-size: 14px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.pricing-features li:before {
  content: "✓";
  color: var(--success);
  font-weight: bold;
  font-size: 16px;
  flex-shrink: 0;
  margin-top: -2px;
}

.pricing-card .btn {
  width: 100%;
  margin-top: auto;
  padding: 12px 24px;
  font-weight: 600;
}

.current-plan-info {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 24px;
}

.subscription-status {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.subscription-status.status-active {
  background: var(--success-bg);
  color: var(--success);
}

.subscription-status.status-canceled,
.subscription-status.status-cancelled {
  background: var(--error-bg);
  color: var(--error);
}

.subscription-status.status-past_due {
  background: var(--warning-bg);
  color: var(--warning);
}

.subscription-status.status-trialing {
  background: var(--accent-bg);
  color: var(--accent);
}

/* Inject Documents Modal */
.inject-preview {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.inject-preview.hidden {
  display: none;
}

.inject-file-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.inject-file-item {
  padding: 8px 10px;
  margin-bottom: 4px;
  background: var(--bg-primary);
  border-radius: 4px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.inject-file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
}

.inject-file-type {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
}

.inject-file-type.text {
  background: rgba(37, 99, 235, 0.1);
  color: var(--accent);
}

.inject-file-type.binary {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning);
}

.inject-file-size {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
}

.inject-stats {
  padding: 10px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.info-banner {
  padding: 12px 16px;
  background: var(--accent-bg);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

.info-banner strong {
  color: var(--accent);
  display: block;
  margin-bottom: 4px;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .pricing-container {
    grid-template-columns: 1fr;
  }

  .pricing-card {
    max-width: 400px;
    margin: 0 auto;
  }
}

/* ============================================
   INTELLIGENCE MODE STYLES
   ============================================ */

#intelligence-mode.active {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.intelligence-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.intelligence-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.intelligence-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.intelligence-header h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
}

.intelligence-brain-indicator {
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-size: 13px;
}

.intelligence-brain-indicator .no-brain {
  color: var(--text-muted);
  font-style: italic;
}

.intelligence-brain-indicator .brain-name {
  color: var(--accent);
  font-weight: 500;
}

.intelligence-reviews-container,
.intelligence-trace-container,
.intelligence-insights-container,
.intelligence-performance-container,
.intelligence-goals-container,
.intelligence-thoughts-container,
.intelligence-dreams-container {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.intelligence-section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

/* Intelligence Table */
.intelligence-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-secondary);
  border-radius: 8px;
  overflow: hidden;
}

.intelligence-table th,
.intelligence-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.intelligence-table th {
  background: var(--bg-tertiary);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.intelligence-table td {
  font-size: 14px;
  color: var(--text-primary);
}

.intelligence-table tbody tr {
  cursor: pointer;
  transition: background 0.15s ease;
}

.intelligence-table tbody tr:hover {
  background: var(--bg-hover);
}

.intelligence-table .w-60 { width: 60px; }
.intelligence-table .w-80 { width: 80px; }
.intelligence-table .w-100 { width: 100px; }
.intelligence-table .w-120 { width: 120px; }

/* Score badges */
.score {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.score.high {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

.score.medium {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warning);
}

.score.low {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

/* Intelligence Filters */
.intelligence-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
}

.intelligence-filters .filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.intelligence-filters .filter-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.intelligence-filters select,
.intelligence-filters input,
.intelligence-filters input.trace-input {
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  min-width: 150px;
}

/* Stats Bar */
.intelligence-stats-bar {
  display: flex;
  gap: 24px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
  margin-bottom: 24px;
}

.intelligence-stats-bar .stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.intelligence-stats-bar .stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

.intelligence-stats-bar .stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

/* View link in table */
.text-view-link {
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
}

/* Intelligence Modal */
.intelligence-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.intelligence-modal {
  background: var(--bg-primary);
  border-radius: 12px;
  border: 1px solid var(--border);
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.intelligence-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.intelligence-modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.intelligence-modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.intelligence-modal-body .markdown-content {
  line-height: 1.7;
}

.intelligence-modal-body .markdown-content h1,
.intelligence-modal-body .markdown-content h2,
.intelligence-modal-body .markdown-content h3 {
  margin-top: 24px;
  margin-bottom: 12px;
}

.intelligence-modal-body .markdown-content p {
  margin-bottom: 12px;
}

.intelligence-modal-body .markdown-content ul,
.intelligence-modal-body .markdown-content ol {
  margin-bottom: 12px;
  padding-left: 24px;
}

.intelligence-modal-body .markdown-content code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.intelligence-modal-body .markdown-content pre {
  background: var(--bg-tertiary);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
}

/* Provenance items */
.intelligence-provenance-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Goals List */
.intelligence-goals-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.intelligence-goal-card {
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

.intelligence-goal-card .goal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.intelligence-goal-card .goal-description {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
}

/* Thoughts List */
.intelligence-thoughts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.intelligence-thought-card {
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
}

.intelligence-thought-card .thought-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.intelligence-thought-card .thought-role {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.intelligence-thought-card .thought-role.role-analyst {
  background: rgba(37, 99, 235, 0.15);
  color: var(--accent);
}

.intelligence-thought-card .thought-role.role-curiosity {
  background: rgba(168, 85, 247, 0.15);
  color: #a855f7;
}

.intelligence-thought-card .thought-role.role-critic {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

.intelligence-thought-card .thought-role.role-other {
  background: var(--bg-tertiary);
  color: var(--text-muted);
}

.intelligence-thought-card .thought-content {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
}

/* Dreams Grid */
.intelligence-dreams-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.intelligence-dream-card {
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.intelligence-dream-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.intelligence-dream-card .dream-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.intelligence-dream-card .dream-cycle {
  font-size: 12px;
  color: var(--text-muted);
}

.intelligence-dream-card .dream-badge {
  padding: 2px 6px;
  background: rgba(168, 85, 247, 0.15);
  color: #a855f7;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}

.intelligence-dream-card .dream-content {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.provenance-item {
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}

.provenance-name {
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.provenance-meta {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ============================================
   COMPREHENSIVE MOBILE RESPONSIVE STYLES
   ============================================ */

/* Tablet breakpoint: 900px */
@media (max-width: 900px) {
  /* Launch Mode - Stack sidebar above form */
  .launch-container {
    flex-direction: column;
  }

  .launch-sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .launch-sidebar-header {
    padding: 12px 16px;
  }

  .launch-brain-list {
    max-height: 120px;
  }

  .launch-new-brain-btn {
    display: none; /* Hide on mobile, use main form */
  }

  .launch-main {
    padding: 24px 20px;
    overflow-y: auto;
  }

  /* Hub Mode - Stack sidebar */
  .hub-content {
    flex-direction: column;
  }

  .hub-sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    max-height: 220px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .hub-brain-list {
    max-height: 140px;
  }

  .hub-preview {
    flex: 1;
    min-height: 300px;
  }

  .hub-header {
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px;
  }

  .hub-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .hub-actions .btn {
    flex: 1;
    min-width: 120px;
  }

  .hub-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Explore Mode - Stack sidebar */
  .explore-container {
    flex-direction: column;
  }

  .explore-sidebar {
    display: flex !important;
    width: 100%;
    min-width: 100%;
    height: auto;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .explore-sidebar-resize {
    display: none;
  }

  .explore-brain-list {
    max-height: 120px;
  }

  .explore-main {
    flex: 1;
    min-height: 400px;
  }

  /* IDE Mode - Stack */
  .ide-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
  }

  .ide-brain-info {
    flex: 1 1 100%;
  }

  .ide-actions {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .ide-actions .btn {
    flex: 1;
  }

  /* Intelligence Mode */
  .intelligence-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
  }

  .intelligence-header-left {
    flex-wrap: wrap;
    width: 100%;
  }

  .intelligence-header h1 {
    font-size: 18px;
  }

  .intelligence-tabs {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    gap: 4px;
    padding-bottom: 8px;
  }

  .intelligence-tab {
    flex-shrink: 0;
    padding: 10px 16px;
    font-size: 13px;
    white-space: nowrap;
  }

  /* Settings Mode */
  .settings-layout {
    flex-direction: column;
  }

  .settings-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    overflow-x: auto;
    padding: 8px;
  }

  .settings-menu {
    display: flex;
    gap: 4px;
    flex-direction: row;
  }

  .settings-menu-item {
    white-space: nowrap;
    padding: 8px 16px;
  }

  .settings-content {
    padding: 20px;
  }

  /* General adjustments */
  .modal-content {
    width: 95%;
    max-width: none;
  }

  /* Intelligence tables - make scrollable */
  .intelligence-reviews-container,
  .intelligence-trace-container,
  .intelligence-insights-container,
  .intelligence-performance-container,
  .intelligence-goals-container,
  .intelligence-thoughts-container,
  .intelligence-dreams-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
  }

  .intelligence-table {
    min-width: 600px;
  }

  /* Intelligence detail drawer - full screen on mobile */
  #intelligence-detail-drawer {
    width: 100%;
    max-width: 100%;
    top: 56px;
  }
}

/* Mobile breakpoint: 640px */
@media (max-width: 640px) {
  /* Header navigation - stack and make scrollable */
  .nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    max-width: 100vw;
    padding: 3px;
    gap: 2px;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    padding: 8px 12px;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Launch Mode */
  .launch-main {
    padding: 20px 16px;
  }

  .launch-header {
    margin-bottom: 24px;
  }

  .launch-header h1 {
    font-size: 20px;
  }

  .launch-header p {
    font-size: 14px;
  }

  .launch-form {
    padding: 20px;
    border-radius: 12px;
  }

  .form-group {
    margin-bottom: 16px;
  }

  .form-input {
    padding: 10px 14px;
    font-size: 16px; /* Prevents iOS zoom */
  }

  .form-input-lg {
    padding: 12px 16px;
  }

  /* Mode selector */
  .mode-selector {
    flex-direction: column;
    gap: 8px;
  }

  .mode-option {
    padding: 14px;
  }

  /* Execution mode selector */
  .execution-mode-selector {
    flex-direction: column;
    gap: 8px;
  }

  .execution-mode-card {
    padding: 12px;
  }

  /* Depth selector */
  .depth-selector {
    flex-direction: column;
    gap: 8px;
  }

  .depth-option {
    padding: 12px 16px;
  }

  /* Toggle grid */
  .toggle-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  /* Form rows */
  .form-row {
    flex-direction: column;
    gap: 16px;
  }

  /* Hub Mode */
  .hub-header {
    padding: 16px;
  }

  .hub-header h1 {
    font-size: 16px;
  }

  .hub-preview-content {
    padding: 16px;
  }

  .hub-stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .hub-stat-card {
    padding: 12px;
  }

  .hub-stat-value {
    font-size: 24px;
  }

  .hub-metadata-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .hub-details-title {
    font-size: 18px;
  }

  /* Hub actions */
  .hub-actions {
    flex-wrap: wrap;
  }

  /* Watch Mode */
  .watch-grid {
    padding: 12px;
    gap: 12px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .stat-card {
    padding: 12px;
  }

  .stat-value {
    font-size: 20px;
  }

  /* Explore Mode */
  .explore-header {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .explore-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .explore-panel {
    max-height: 250px;
  }

  /* Intelligence Mode */
  .intelligence-container {
    padding: 0;
  }

  .intelligence-header {
    padding: 12px 16px;
    gap: 8px;
  }

  .intelligence-header h1 {
    font-size: 16px;
  }

  .intelligence-brain-indicator {
    font-size: 11px;
    padding: 4px 8px;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .intelligence-section-title {
    font-size: 14px;
    margin-bottom: 12px;
  }

  .intelligence-reviews-container,
  .intelligence-trace-container,
  .intelligence-insights-container,
  .intelligence-performance-container,
  .intelligence-goals-container,
  .intelligence-thoughts-container,
  .intelligence-dreams-container {
    padding: 12px;
  }

  /* Intelligence filters - stack vertically */
  .intelligence-filters {
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    margin-bottom: 12px;
  }

  .intelligence-filters select,
  .intelligence-filters input {
    width: 100%;
    font-size: 14px;
  }

  /* Intelligence tabs - scrollable */
  .intelligence-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding: 0 12px 8px;
    gap: 4px;
    margin: 0 -12px;
    scrollbar-width: none;
  }

  .intelligence-tabs::-webkit-scrollbar {
    display: none;
  }

  .intelligence-tab {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 12px;
    min-height: 36px;
  }

  /* Intelligence detail drawer */
  #intelligence-detail-drawer {
    width: 100%;
    max-width: 100vw;
    top: 56px;
  }

  /* Dreams grid */
  .intelligence-dreams-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .intelligence-dreams-stats,
  .intelligence-stats-bar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    font-size: 12px;
  }

  /* Goals and thoughts lists */
  .intelligence-goals-list,
  .intelligence-thoughts-list {
    gap: 12px;
  }

  .intelligence-goal-card,
  .intelligence-thought-card,
  .intelligence-dream-card {
    padding: 12px;
  }

  /* Intelligence table */
  .intelligence-table {
    font-size: 12px;
  }

  .intelligence-table th,
  .intelligence-table td {
    padding: 8px 12px;
  }

  /* Settings Mode */
  .profile-form .form-row {
    grid-template-columns: 1fr;
  }

  /* Pricing */
  .pricing-container {
    padding: 16px;
  }

  .pricing-card {
    padding: 20px;
  }

  /* Modals */
  .modal-content {
    margin: 16px;
    max-height: calc(100vh - 32px);
  }

  .modal-header {
    padding: 16px 20px;
  }

  .modal-body {
    padding: 16px 20px;
  }

  /* Buttons */
  .btn {
    padding: 10px 16px;
    font-size: 14px;
  }

  .btn-sm {
    padding: 8px 12px;
    font-size: 13px;
  }

  /* Advanced details */
  .advanced-content {
    padding: 16px;
  }

  .section-label {
    margin-top: 16px;
  }

  /* Plan review section */
  .plan-section {
    padding: 16px;
  }

  /* Footer actions */
  .launch-form > .btn-primary {
    padding: 14px 20px;
    font-size: 15px;
  }
}

/* Extra small devices: 480px */
@media (max-width: 480px) {
  /* Further reduce spacing */
  .launch-main {
    padding: 16px 12px;
  }

  .launch-header h1 {
    font-size: 18px;
    line-height: 1.3;
  }

  .launch-form {
    padding: 16px;
  }

  /* Header adjustments */
  .header-inner {
    padding: 0 8px;
  }

  .nav {
    padding: 2px;
  }

  .nav-item {
    padding: 6px 10px;
    font-size: 11px;
  }

  /* Hub */
  .hub-stats-grid {
    grid-template-columns: 1fr;
  }

  /* Stats grid */
  .stats-grid {
    grid-template-columns: 1fr;
  }

  /* Sidebar mobile toggle position */
  .sidebar-toggle-mobile {
    left: 8px;
    top: 8px;
    width: 40px;
    height: 40px;
  }

  /* Make sure inputs don't zoom on iOS */
  input, select, textarea {
    font-size: 16px;
  }
}

/* Mobile sidebar backdrop */
.mobile-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 140;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-backdrop.visible {
  display: block;
  opacity: 1;
}

/* Sidebar header actions (group buttons) */
.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}



/* Touch-friendly tap targets */
@media (pointer: coarse) {
  .btn, button {
    min-height: 44px;
  }

  .nav-item {
    min-height: 44px;
  }

  .toggle-item {
    min-height: 44px;
  }

  .launch-brain-card {
    min-height: 50px;
  }

  .hub-brain-card {
    min-height: 50px;
  }
}

/* Safe area insets for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
  .app-sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .sidebar-footer {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .modal-content {
    margin-bottom: env(safe-area-inset-bottom);
  }
}

/* Landscape mobile adjustments */
@media (max-width: 900px) and (orientation: landscape) {
  .launch-header {
    margin-bottom: 16px;
  }

  .launch-header h1 {
    font-size: 20px;
  }

  .launch-main {
    padding: 16px 24px;
  }

  .hub-stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .launch-sidebar,
  .hub-sidebar,
  #intelligence-detail-drawer,
  .mobile-backdrop {
    transition: none;
  }

  .nav-badge.active {
    animation: none;
  }
}
