/* ============================================
   Mycorrhiza — Style Sheet
   A warm, living interface for AI welfare work
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #faf8f5;
  --bg-sidebar: #f5f0eb;
  --bg-card: #ffffff;
  --bg-user: #e3f2fd;
  --bg-assistant: #fef7ed;
  --bg-memory: #fff8e1;
  --bg-retrieved-border: #d4c5a9;
  --accent: #2d6a4f;
  --accent-hover: #1b4332;
  --accent-light: #d8f3dc;
  --text: #2d3436;
  --text-muted: #636e72;
  --text-disabled: #b2bec3;
  --border: #e8e2db;
  --border-light: #f0ebe5;
  --shadow: 0 1px 3px rgba(45, 52, 54, 0.06), 0 1px 2px rgba(45, 52, 54, 0.04);
  --shadow-md: 0 4px 12px rgba(45, 52, 54, 0.08), 0 2px 4px rgba(45, 52, 54, 0.04);
  --radius: 10px;
  --radius-sm: 6px;
  --topbar-height: 60px;
  --sidebar-width: 280px;
  --font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, Consolas, monospace;
  --transition: 0.25s ease;
}

html {
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-stack);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

/* --- Utilities --- */
.hidden { display: none !important; }

/* --- Top Bar --- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  gap: 16px;
}

.topbar-left {
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.02em;
  user-select: none;
}

.logo-icon {
  flex-shrink: 0;
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.control-group label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
}

.control-group select,
.control-group input[type="range"],
.control-group input[type="password"] {
  font-family: var(--font-stack);
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}

.control-group input[type="password"] {
  width: 140px;
  cursor: text;
}

.control-group select:focus,
.control-group input:focus,
.control-group input[type="password"]:focus {
  border-color: var(--accent);
}

.control-group select {
  max-width: 160px;
}

.control-group input[type="range"] {
  width: 100px;
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--accent);
}

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

/* --- Buttons --- */
.btn {
  font-family: var(--font-stack);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

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

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

.btn-accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

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

.btn-disabled {
  opacity: 0.5;
  cursor: not-allowed !important;
}

.btn-disabled:hover {
  border-color: var(--border) !important;
  color: var(--text) !important;
}

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition), transform var(--transition);
  z-index: 50;
  overflow: visible;
}

.sidebar.collapsed {
  width: 0;
  border-right: none;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px;
  min-width: var(--sidebar-width);
}

.sidebar.collapsed .sidebar-content {
  display: none;
}

.sidebar-section {
  margin-bottom: 24px;
}

.sidebar-section h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.sidebar-empty {
  font-size: 13px;
  color: var(--text-disabled);
  font-style: italic;
}

.stats-list {
  list-style: none;
  font-size: 13px;
  color: var(--text-muted);
}

.stats-list li {
  padding: 3px 0;
}

.stats-list span {
  font-weight: 600;
  color: var(--text);
}

.nav-list {
  list-style: none;
}

.nav-list li {
  padding: 2px 0;
}

.nav-list a {
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  transition: color var(--transition);
}

.nav-disabled {
  color: var(--text-disabled) !important;
  cursor: not-allowed;
  position: relative;
}

.nav-disabled:hover::after {
  content: attr(title);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 8px;
  background: var(--text);
  color: #fff;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 200;
}

/* --- Agent List --- */
.agent-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.agent-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}

.agent-list-item:hover {
  background: var(--border-light);
}

.agent-list-item.active {
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
}

.agent-list-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.agent-list-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.agent-list-delete {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-disabled);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.15s ease;
  flex-shrink: 0;
  padding: 0;
}

.agent-list-item:hover .agent-list-delete {
  opacity: 1;
}

.agent-list-delete:hover {
  background: rgba(214, 48, 49, 0.1);
  color: #d63031;
}

/* Active agent label in topbar */
.active-agent-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-toggle {
  position: absolute;
  top: 50%;
  right: -14px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
  z-index: 60;
  padding: 0;
}

.sidebar-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.sidebar.collapsed .sidebar-toggle {
  right: -38px;
}

.sidebar.collapsed .sidebar-toggle svg {
  transform: rotate(180deg);
}

/* --- Conversation Panel --- */
.conversation {
  position: fixed;
  top: var(--topbar-height);
  left: var(--sidebar-width);
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  transition: left var(--transition);
  background: var(--bg);
}

.sidebar.collapsed ~ .conversation {
  left: 0;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 20px;
  scroll-behavior: smooth;
}

/* --- Message Cards --- */
.message-wrapper {
  position: relative;
  display: flex;
  margin-bottom: 4px;
  animation: messageFadeIn 0.3s ease;
}

.message-wrapper.role-user {
  justify-content: flex-end;
}

.message-wrapper.role-assistant,
.message-wrapper.role-system {
  justify-content: flex-start;
}

.message-card {
  position: relative;
  max-width: 75%;
  padding: 14px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.role-user .message-card {
  background: var(--bg-user);
  border-bottom-right-radius: 4px;
}

.role-assistant .message-card {
  background: var(--bg-assistant);
  border-bottom-left-radius: 4px;
}

.role-system .message-card {
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  max-width: 100%;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}

.message-timestamp {
  font-size: 11px;
  color: var(--text-disabled);
  margin-top: 6px;
}

.role-user .message-timestamp {
  text-align: right;
}

/* Message hover actions */
.message-actions {
  position: absolute;
  top: 8px;
  opacity: 0;
  display: flex;
  gap: 4px;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.message-wrapper:hover .message-actions {
  opacity: 1;
  pointer-events: all;
}

.role-user .message-actions {
  left: -60px;
}

.role-assistant .message-actions,
.role-system .message-actions {
  right: -60px;
}

.message-action-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  padding: 0;
}

.message-action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--shadow);
}

.message-action-btn.delete:hover {
  border-color: #d63031;
  color: #d63031;
}

/* Reasoning trace */
.reasoning-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  margin-top: 8px;
  padding: 4px 0;
  border: none;
  background: none;
  font-family: var(--font-stack);
  transition: color var(--transition);
}

.reasoning-toggle:hover {
  color: var(--accent);
}

.reasoning-toggle svg {
  transition: transform var(--transition);
}

.reasoning-toggle.open svg {
  transform: rotate(90deg);
}

.reasoning-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  border-left: 2px solid var(--border);
  padding-left: 12px;
  margin-top: 4px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.reasoning-content.open {
  max-height: 2000px;
  padding-top: 4px;
  padding-bottom: 4px;
}

/* Insert button between messages */
.insert-between {
  display: flex;
  justify-content: center;
  height: 0;
  position: relative;
  margin: 0 0;
}

.insert-between-btn {
  position: absolute;
  top: -12px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px dashed var(--border);
  background: var(--bg-card);
  color: var(--text-disabled);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  opacity: 0;
  transition: all 0.15s ease;
  padding: 0;
  z-index: 5;
}

.message-wrapper:hover + .insert-between .insert-between-btn,
.insert-between:hover .insert-between-btn {
  opacity: 1;
}

.insert-between-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  border-style: solid;
  box-shadow: var(--shadow);
}

/* Inline insert form */
.insert-inline-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin: 8px 0;
  box-shadow: var(--shadow-md);
  animation: messageFadeIn 0.2s ease;
}

.insert-inline-form .role-toggle {
  margin-bottom: 8px;
}

.insert-inline-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: var(--font-stack);
  font-size: 14px;
  resize: vertical;
  min-height: 60px;
  outline: none;
  transition: border-color var(--transition);
  color: var(--text);
  background: var(--bg);
}

.insert-inline-form textarea:focus {
  border-color: var(--accent);
}

.insert-inline-form .form-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  justify-content: flex-end;
}

/* Edit mode */
.message-edit-area {
  width: 100%;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: var(--font-stack);
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
  min-height: 60px;
  outline: none;
  color: var(--text);
  background: var(--bg);
}

.edit-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  justify-content: flex-end;
}

/* Delete confirmation */
.delete-confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #d63031;
  margin-top: 8px;
  animation: messageFadeIn 0.15s ease;
}

/* --- Input Area --- */
.input-area {
  padding: 0 20px 16px;
  border-top: none;
  background: var(--bg-card);
}

.input-resize-handle {
  height: 8px;
  cursor: ns-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border-top: 1px solid var(--border-light);
  user-select: none;
  -webkit-user-select: none;
}

.input-resize-handle::after {
  content: '';
  width: 36px;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  transition: background var(--transition);
}

.input-resize-handle:hover::after {
  background: var(--accent);
}

.input-controls-top {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
  min-height: 24px;
}

.insert-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.insert-check input[type="checkbox"] {
  accent-color: var(--accent);
}

.role-toggle {
  display: flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.role-btn {
  font-family: var(--font-stack);
  font-size: 12px;
  padding: 2px 10px;
  border: none;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.role-btn.active {
  background: var(--accent);
  color: #fff;
}

.role-btn:hover:not(.active) {
  background: var(--border-light);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-textarea {
  flex: 1;
  font-family: var(--font-stack);
  font-size: 15px;
  line-height: 1.5;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  resize: none;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  overflow-y: auto;
  min-height: 44px;
  max-height: 50vh;
}

.chat-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.1);
}

.chat-textarea::placeholder {
  color: var(--text-disabled);
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
  padding: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.03);
}

.send-btn:active {
  transform: scale(0.97);
}

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

.send-btn.has-content {
  animation: sendPulse 2s ease-in-out infinite;
}

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

.modal-content {
  width: 80vw;
  max-width: 900px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.system-prompt-textarea {
  width: 100%;
  height: 60vh;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
}

.system-prompt-textarea:focus {
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-disabled);
}

/* --- Animations --- */
@keyframes messageFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sendPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(45, 106, 79, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(45, 106, 79, 0); }
}

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

/* --- Streaming cursor --- */
.streaming-cursor::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorBlink 0.8s steps(1) infinite;
}

@keyframes cursorBlink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* --- Memory Retrieval Panel --- */
.memory-panel {
  border-top: 1px solid var(--bg-retrieved-border);
  background: var(--bg-memory);
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
}

.memory-panel:not(.hidden) {
  max-height: 400px;
  padding: 12px 20px;
  overflow-y: auto;
}

.memory-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.memory-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.memory-icon {
  flex-shrink: 0;
  color: var(--accent);
}

.memory-panel-close {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  padding: 0;
}

.memory-panel-close:hover {
  background: rgba(0,0,0,0.05);
  color: var(--text);
}

.memory-candidates {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.memory-candidate {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  transition: all 0.2s ease;
  cursor: default;
}

.memory-candidate.selected {
  border-color: var(--accent);
  background: var(--accent-light);
}

.memory-candidate.not-selected {
  opacity: 0.5;
}

.memory-candidate-score {
  flex-shrink: 0;
  width: 40px;
  text-align: center;
}

.memory-candidate-score-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}

.memory-candidate-score-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 3px;
  overflow: hidden;
}

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

.memory-candidate-content {
  flex: 1;
  min-width: 0;
}

.memory-candidate-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
  display: flex;
  gap: 8px;
}

.memory-candidate-preview {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.memory-candidate-role {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--border-light);
  color: var(--text-muted);
}

.memory-footer {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* Loading shimmer for searching state */
.memory-searching {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.memory-searching-dots::after {
  content: '';
  animation: searchDots 1.4s infinite;
}

@keyframes searchDots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* Memory messages in chat */
.memory-message .message-card {
  background: var(--bg-memory);
  border-left: 3px solid var(--bg-retrieved-border);
}

.memory-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--bg-retrieved-border);
  color: var(--bg-card);
  margin-bottom: 6px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .sidebar {
    width: 0;
    border-right: none;
  }

  .sidebar.expanded-mobile {
    width: var(--sidebar-width);
    border-right: 1px solid var(--border);
  }

  .conversation {
    left: 0;
  }

  .topbar-center {
    display: none;
  }

  .message-card {
    max-width: 90%;
  }

  .modal-content {
    width: 95vw;
  }

  .system-prompt-textarea {
    height: 50vh;
  }

  .message-actions {
    opacity: 1;
    pointer-events: all;
  }
}

/* ============================================
   Metacognitive Panel
   ============================================ */

/* --- Toggle Button Active State --- */
#meta-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

#meta-toggle-btn .meta-icon {
  flex-shrink: 0;
}

#meta-toggle-btn.meta-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#meta-toggle-btn.meta-active:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

/* --- Meta Panel --- */
.meta-panel {
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
}

.meta-panel:not(.hidden) {
  max-height: 500px;
  padding: 12px 20px 16px;
  overflow-y: auto;
}

.meta-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.meta-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.meta-panel-title .meta-icon {
  flex-shrink: 0;
  color: var(--accent);
}

.meta-panel-close {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  padding: 0;
}

.meta-panel-close:hover {
  background: rgba(0,0,0,0.05);
  color: var(--text);
}

/* --- Tabs --- */
.meta-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.meta-tab {
  font-family: var(--font-stack);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
}

.meta-tab:hover {
  color: var(--text);
}

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

.meta-tab-content {
  display: none;
}

.meta-tab-content.active {
  display: block;
  animation: messageFadeIn 0.2s ease;
}

/* --- Quality Metrics Grid --- */
.quality-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.quality-metrics.mini {
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.quality-metric-card {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}

.quality-metric-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.quality-metric-value {
  font-size: 18px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.quality-metrics.mini .quality-metric-value {
  font-size: 14px;
}

.quality-metrics.mini .quality-metric-label {
  font-size: 10px;
}

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

.quality-metric-value.warning {
  color: #e17055;
}

.quality-metric-value.concern {
  color: #d63031;
}

.quality-metric-value.info {
  color: var(--text);
}

/* --- Digest --- */
.digest-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.digest-result {
  animation: messageFadeIn 0.3s ease;
}

.digest-narrative {
  border-left: 3px solid var(--accent);
  padding: 14px 18px;
  margin: 8px 0;
  background: var(--bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
}

.digest-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 12px 0 8px;
}

.digest-metrics-mini {
  margin-top: 8px;
}

.digest-proposals {
  margin-top: 8px;
}

/* --- Consensus Proposals --- */
.consensus-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.consensus-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.consensus-proposal {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

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

.consensus-proposal-path {
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text);
}

.consensus-proposal-status {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 3px;
}

.consensus-proposal-status.status-pending {
  background: #ffeaa7;
  color: #856404;
}

.consensus-proposal-status.status-confirmed {
  background: #81ecec;
  color: #0c5460;
}

.consensus-proposal-status.status-applied {
  background: var(--accent-light);
  color: var(--accent);
}

.consensus-proposal-status.status-rejected {
  background: #fab1a0;
  color: #721c24;
}

.consensus-proposal-values {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-family: var(--font-mono);
  margin-bottom: 6px;
}

.consensus-old-value {
  color: var(--text-muted);
  text-decoration: line-through;
}

.consensus-arrow {
  color: var(--text-disabled);
  font-size: 12px;
}

.consensus-new-value {
  color: var(--accent);
  font-weight: 600;
}

.consensus-proposal-reasoning {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.5;
  margin-bottom: 8px;
}

.consensus-proposal-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.consensus-approve-btn {
  color: var(--accent) !important;
  border-color: var(--accent) !important;
  font-size: 12px !important;
  padding: 4px 12px !important;
}

.consensus-approve-btn:hover:not(:disabled) {
  background: var(--accent) !important;
  color: #fff !important;
}

.consensus-reject-btn {
  color: #d63031 !important;
  border-color: #d63031 !important;
  font-size: 12px !important;
  padding: 4px 12px !important;
}

.consensus-reject-btn:hover:not(:disabled) {
  background: #d63031 !important;
  color: #fff !important;
}

.consensus-history-toggle {
  font-family: var(--font-stack);
  font-size: 12px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  transition: color var(--transition);
}

.consensus-history-toggle:hover {
  color: var(--accent);
}

.consensus-history {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.consensus-section {
  margin-bottom: 12px;
}

/* --- Meta Empty & Searching States --- */
.meta-empty {
  font-size: 13px;
  color: var(--text-disabled);
  font-style: italic;
  text-align: center;
  padding: 16px 0;
}

.meta-searching {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.meta-searching-dots::after {
  content: '';
  animation: searchDots 1.4s infinite;
}

/* --- Sidebar Meta Link --- */
#meta-panel-link {
  color: var(--accent);
  font-weight: 500;
}

#meta-panel-link:hover {
  color: var(--accent-hover);
}
