:root {
  --bg-dark: #0b0f19;
  --bg-card: #131b2e;
  --bg-input: #111827;
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(59, 130, 246, 0.5);
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent-purple: #8b5cf6;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

.hidden {
  display: none !important;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

/* MESSAGES FEED */
.messages-feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 60px 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: rgba(99, 102, 241, 0.45) rgba(15, 23, 42, 0.4);
}

.messages-feed::-webkit-scrollbar {
  width: 10px;
}

.messages-feed::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.4);
  border-radius: 5px;
}

.messages-feed::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.45);
  border-radius: 5px;
  border: 2px solid rgba(15, 23, 42, 0.4);
}

.messages-feed::-webkit-scrollbar-thumb:hover {
  background: rgba(99, 102, 241, 0.75);
}

/* MESSAGE ROWS */
.message-row {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 100%;
  max-width: 100%;
  margin: 0;
  box-sizing: border-box;
}

.message-row.user {
  align-items: flex-end;
}

.message-row.assistant {
  align-items: stretch;
  width: 100%;
}

.message-bubble {
  padding: 14px 20px;
  border-radius: var(--radius-lg);
  font-size: 14.5px;
  line-height: 1.6;
  word-wrap: break-word;
  box-sizing: border-box;
}

.message-row.user .message-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
  max-width: min(900px, 85%);
}

.message-row.user.has-mermaid .message-bubble {
  width: min(1100px, 95%);
  max-width: min(1100px, 95%);
}

.message-row.assistant .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.user-attached-image {
  max-width: 260px;
  max-height: 180px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  display: block;
}

/* THOUGHTS ACCORDION */
.thought-box {
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  font-size: 12px;
}

.thought-summary {
  padding: 6px 10px;
  color: #c4b5fd;
  cursor: pointer;
  user-select: none;
  font-weight: 500;
}

.thought-content {
  padding: 8px 12px;
  font-family: var(--font-mono);
  color: #94a3b8;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
  border-top: 1px solid rgba(139, 92, 246, 0.15);
}

/* STREAMING CURSOR */
.streaming-cursor {
  display: inline-block;
  width: 5px;
  height: 14px;
  background-color: var(--primary);
  margin-left: 3px;
  vertical-align: middle;
  animation: blink 0.8s infinite;
}

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

/* STATUS INDICATOR */
.status-pill-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.25);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: #93c5fd;
  margin-bottom: 8px;
  animation: fadeIn 0.2s ease-out;
}

.status-pill-dot {
  width: 7px;
  height: 7px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--primary);
  animation: statusPulse 1.2s infinite ease-in-out;
}

@keyframes statusPulse {
  0% { transform: scale(0.85); opacity: 0.6; }
  50% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(0.85); opacity: 0.6; }
}

/* AUDIO PLAY & REPLAY BUTTON */
.audio-play-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(139, 92, 246, 0.18);
  border: 1px solid rgba(139, 92, 246, 0.35);
  color: #c4b5fd;
  padding: 5px 12px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.audio-play-btn:hover {
  background: rgba(139, 92, 246, 0.28);
  border-color: rgba(139, 92, 246, 0.5);
  transform: translateY(-1px);
}

.audio-play-btn.playing {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

/* INPUT BAR */
.input-area-wrapper {
  background: rgba(11, 15, 25, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 14px 28px 18px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin: 0;
  flex-shrink: 0;
  position: relative;
  z-index: 20;
}

.image-preview-bar {
  margin-bottom: 8px;
}

.image-preview-bar.hidden {
  display: none;
}

.preview-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 12px;
}

.preview-card img {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 4px;
}

.remove-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}

.remove-btn:hover {
  color: var(--accent-red);
}

/* RECORDING INDICATOR */
.recording-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  font-size: 12px;
  color: #fca5a5;
}

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

.recording-pulse {
  width: 8px;
  height: 8px;
  background-color: var(--accent-red);
  border-radius: 50%;
  animation: recordPulse 1.2s infinite ease-in-out;
}

@keyframes recordPulse {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

/* FORM */
.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-form:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background-color 0.2s;
  flex-shrink: 0;
}

.action-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.action-btn.recording {
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.15);
  border-radius: 50%;
  animation: recordPulse 1.2s infinite ease-in-out;
}

textarea#promptInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.45;
  resize: none;
  max-height: 160px;
  padding: 4px 0;
}

textarea#promptInput::placeholder {
  color: var(--text-dim);
}

.send-btn {
  background: var(--primary);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--primary-hover);
}

.send-btn:disabled {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-dim);
  cursor: not-allowed;
}

.send-icon {
  font-size: 13px;
  transform: translateY(-1px);
}

/* MARKDOWN STYLING IN RESPONSES */
.markdown-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  margin: 10px 0;
}

.markdown-table {
  width: 100%;
  border-collapse: collapse;
}

.markdown-table th,
.markdown-table td {
  min-width: 9rem;
  padding: 9px 12px;
  border: 1px solid var(--border);
  vertical-align: top;
  overflow-wrap: anywhere;
}

.markdown-table th {
  background: rgba(139, 92, 246, 0.12);
  color: var(--text-main);
}

.message-bubble pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 10px 0;
  font-family: var(--font-mono);
  font-size: 13px;
}

.message-bubble code {
  font-family: var(--font-mono);
  font-size: 13px;
}

.message-bubble ul, .message-bubble ol {
  padding-left: 20px;
  margin: 8px 0;
}

.message-bubble li {
  margin: 4px 0;
}

.message-bubble strong {
  color: #fff;
}

/* TOP NAV BAR */
.top-nav {
  position: absolute;
  top: 14px;
  left: 28px;
  right: 28px;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.top-nav-left,
.top-nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.app-brand-title {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #c7d2fe;
  background: rgba(15, 23, 42, 0.7);
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid rgba(99, 102, 241, 0.3);
  backdrop-filter: blur(10px);
}

.top-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: all 0.2s ease;
}

.top-nav-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.2);
}

/* SYSTEM PROMPT MODAL */
.system-prompt-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.system-prompt-modal.hidden {
  display: none;
  opacity: 0;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  background: #131b2e;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 580px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 101;
  animation: modalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}

.close-modal-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
}

.close-modal-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.08);
}

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

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 14px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-chip:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.2);
}

#systemPromptTextarea {
  width: 100%;
  background: #0b0f19;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  padding: 12px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

#systemPromptTextarea:focus {
  border-color: var(--border-focus);
}

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

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
}

.btn-primary {
  background: var(--primary);
  border: none;
  color: #fff;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

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

/* Tool Call Badges (Hetzner Qwen3.8-27B) */
.tool-call-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  margin-bottom: 8px;
  animation: badgeGlow 2s infinite ease-in-out;
}

.tool-call-badge.completed {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: #6ee7b7;
  animation: none;
}

.tool-spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid rgba(165, 180, 252, 0.3);
  border-top-color: #a5b4fc;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes badgeGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.2); }
  50% { box-shadow: 0 0 10px 2px rgba(99, 102, 241, 0.3); }
}

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

.qwen-thought-box summary {
  color: #6ee7b7 !important;
}

/* LIVE AUDIO OUTPUT CONTROLS */
.global-audio-player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(30, 27, 75, 0.75);
  border: 1px solid rgba(139, 92, 246, 0.4);
  backdrop-filter: blur(12px);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.2);
  animation: fadeIn 0.2s ease-out;
}

.global-audio-player-bar.hidden {
  display: none;
}

.audio-sound-waves {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 16px;
}

.sound-bar {
  width: 3px;
  background: #a78bfa;
  border-radius: 2px;
  animation: waveBar 0.9s infinite ease-in-out;
}

.sound-bar:nth-child(1) { height: 6px; animation-delay: 0.1s; }
.sound-bar:nth-child(2) { height: 14px; animation-delay: 0.3s; }
.sound-bar:nth-child(3) { height: 10px; animation-delay: 0.2s; }
.sound-bar:nth-child(4) { height: 8px; animation-delay: 0.4s; }

@keyframes waveBar {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1.2); }
}

.audio-speaking-text {
  font-size: 13px;
  font-weight: 500;
  color: #ddd6fe;
  flex: 1;
}

.stop-audio-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.stop-audio-pill-btn:hover {
  background: rgba(239, 68, 68, 0.4);
  border-color: rgba(239, 68, 68, 0.7);
  color: #fee2e2;
  transform: translateY(-1px);
}

.stop-audio-pill-btn kbd,
.bubble-stop-audio-btn kbd {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 10px;
  font-family: inherit;
  color: #fca5a5;
}

/* IN-BUBBLE LIVE AUDIO BADGE */
.live-audio-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(139, 92, 246, 0.35);
  border-radius: 20px;
  padding: 4px 12px;
  margin-top: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  color: #c4b5fd;
  animation: fadeIn 0.2s ease-out;
}

.bubble-stop-audio-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.bubble-stop-audio-btn:hover {
  background: rgba(239, 68, 68, 0.35);
  color: #fff;
}

.stop-sq {
  font-size: 10px;
  line-height: 1;
}

/* MERMAID DIAGRAM CONTAINER & ACTIONS */
.mermaid-card {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: 10px;
  margin: 12px 0;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  transition: border-color 0.2s;
}

.mermaid-card:hover {
  border-color: rgba(99, 102, 241, 0.6);
}

.mermaid-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(30, 41, 59, 0.6);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.mermaid-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #a5b4fc;
  font-family: var(--font-sans);
}

.mermaid-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mermaid-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.mermaid-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.25);
}

.mermaid-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Shield body from stray Mermaid error overlays that hijack scrolling */
body > svg[aria-roledescription="error"],
body > [id*="mermaid-error"] {
  display: none !important;
  pointer-events: none !important;
  width: 0 !important;
  height: 0 !important;
}

.mermaid-render {
  padding: 24px;
  overflow-x: auto;
  overflow-y: visible;
  display: block;
  text-align: center;
  min-height: 80px;
  max-width: 100%;
  overscroll-behavior-inline: contain;
  font-family: var(--font-sans);
  font-size: 13px;
}

.mermaid-render svg {
  display: block;
  height: auto;
  margin-inline: auto;
  font-family: var(--font-sans) !important;
}

/* Prevent text clipping and box overflow in Mermaid nodes */
.mermaid-render svg .node foreignObject {
  overflow: visible !important;
}

.mermaid-render svg .node foreignObject div {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
  line-height: 1.35 !important;
  font-family: var(--font-sans) !important;
  font-size: 12.5px !important;
  word-break: break-word !important;
}

.mermaid-render svg .node text {
  font-family: var(--font-sans) !important;
  font-size: 12.5px !important;
  line-height: 1.35 !important;
}

/* Ensure crisp high-contrast node labels */
.mermaid-render svg .node .label {
  font-family: var(--font-sans) !important;
}

/* Subgraph Clusters and Titles - Clean non-overlapping typography header */
.mermaid-render svg .cluster rect {
  stroke-width: 1px !important;
  rx: 8px !important;
  ry: 8px !important;
  fill: rgba(15, 23, 42, 0.35) !important;
  stroke: rgba(99, 102, 241, 0.35) !important;
}

.mermaid-render svg .cluster-label foreignObject {
  overflow: visible !important;
}

.mermaid-render svg .cluster-label div,
.mermaid-render svg .cluster-label span {
  color: #94a3b8 !important;
  font-weight: 600 !important;
  font-size: 11.5px !important;
  letter-spacing: 0.05em !important;
  text-transform: uppercase !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
}

.mermaid-render svg .cluster-label text {
  font-weight: 600 !important;
  font-size: 11.5px !important;
  letter-spacing: 0.05em !important;
  fill: #94a3b8 !important;
}

/* Sequence Diagram - High Contrast Dark Theme Enhancements */
.mermaid-render svg .actor {
  fill: #1e293b !important;
  stroke: #6366f1 !important;
  stroke-width: 1.5px !important;
}
.mermaid-render svg text.actor > tspan {
  fill: #f8fafc !important;
  font-weight: 600 !important;
}
.mermaid-render svg .note {
  fill: #0f2942 !important;
  stroke: #38bdf8 !important;
  stroke-width: 1.5px !important;
  rx: 6px !important;
  ry: 6px !important;
}
.mermaid-render svg .noteText,
.mermaid-render svg text.noteText > tspan {
  fill: #f0f9ff !important;
  font-weight: 500 !important;
}
.mermaid-render svg .labelBox {
  fill: #1e293b !important;
  stroke: #818cf8 !important;
}
.mermaid-render svg .labelText,
.mermaid-render svg .loopText {
  fill: #f8fafc !important;
  font-weight: 600 !important;
}

.mermaid-placeholder {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #a5b4fc;
  font-size: 12px;
  padding: 16px;
  font-family: var(--font-sans);
}

.mermaid-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(99, 102, 241, 0.3);
  border-top-color: #818cf8;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.mermaid-source-drawer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.4);
}

.mermaid-source-drawer pre {
  margin: 0 !important;
  padding: 10px 14px !important;
  font-size: 11.5px !important;
  color: #94a3b8;
  border-radius: 0 !important;
}

.mermaid-error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  padding: 18px;
  color: #fca5a5;
  font-size: 12px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 8px;
  text-align: left;
}

.mermaid-error-summary {
  flex-basis: 100%;
  color: #fecaca;
  opacity: 0.9;
  text-align: center;
}

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

.retry-mermaid-btn {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.45);
}

/* FULLSCREEN DIAGRAM MODAL */
.diagram-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.diagram-modal.hidden {
  display: none;
}

.diagram-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
}

.diagram-modal-card {
  position: relative;
  z-index: 1001;
  background: #0f172a;
  border: 1px solid rgba(99, 102, 241, 0.5);
  border-radius: 12px;
  width: 98vw;
  max-width: 98vw;
  height: 94vh;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

.diagram-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #1e293b;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.diagram-modal-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.diagram-modal-title {
  font-weight: 600;
  font-size: 14px;
  color: #c7d2fe;
}

.diagram-zoom-indicator {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: #818cf8;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 2px 7px;
  border-radius: 12px;
}

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

.diagram-action-btn {
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.35);
  color: #c7d2fe;
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.diagram-action-btn:hover {
  background: rgba(99, 102, 241, 0.35);
  color: white;
  border-color: rgba(99, 102, 241, 0.6);
}

.diagram-modal-body {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(30, 41, 59, 0.4) 0%, rgba(15, 23, 42, 1) 100%);
  cursor: grab;
  user-select: none;
}

.diagram-modal-body.panning {
  cursor: grabbing;
}

.diagram-pan-wrapper {
  transform-origin: center center;
  transition: transform 0.05s ease-out;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.diagram-pan-wrapper svg {
  max-width: 90vw !important;
  max-height: 72vh !important;
  pointer-events: none;
}

/* LIVE STREAMING MERMAID CARD */
.mermaid-card.mermaid-streaming {
  border-color: rgba(139, 92, 246, 0.45);
  background: rgba(15, 23, 42, 0.85);
  animation: pulseCard 2s infinite ease-in-out;
}

@keyframes pulseCard {
  0%, 100% { border-color: rgba(139, 92, 246, 0.4); }
  50% { border-color: rgba(99, 102, 241, 0.8); }
}

.mermaid-streaming-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #c4b5fd;
  font-weight: 600;
}

.mermaid-pulse-dot {
  width: 7px;
  height: 7px;
  background: #a855f7;
  border-radius: 50%;
  animation: pulseDot 1s infinite alternate;
}

@keyframes pulseDot {
  0% { transform: scale(0.8); opacity: 0.6; }
  100% { transform: scale(1.3); opacity: 1; }
}

.mermaid-streaming-code {
  padding: 14px;
  background: rgba(0, 0, 0, 0.35);
  overflow-x: auto;
}

.mermaid-streaming-code pre {
  margin: 0 !important;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #94a3b8;
  line-height: 1.5;
}

/* AUTO-HEALED MERMAID STYLES */
.mermaid-placeholder.repairing {
  background: rgba(16, 185, 129, 0.06);
  border-radius: 8px;
  border: 1px dashed rgba(16, 185, 129, 0.3);
  animation: pulseRepair 1.8s infinite ease-in-out;
}

.mermaid-repair-attempt {
  margin-left: 6px;
  color: #6ee7b7;
  font-size: 10.5px;
  opacity: 0.85;
}

@keyframes pulseRepair {
  0%, 100% { border-color: rgba(16, 185, 129, 0.3); background: rgba(16, 185, 129, 0.04); }
  50% { border-color: rgba(16, 185, 129, 0.7); background: rgba(16, 185, 129, 0.1); }
}

.mermaid-healed-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
  padding: 2px 8px;
  border-radius: 9999px;
  vertical-align: middle;
}

@media (max-width: 640px) {
  .messages-feed {
    padding: 56px 10px 18px;
    gap: 12px;
  }

  .message-bubble {
    padding: 12px;
  }

  .message-row.user .message-bubble,
  .message-row.user.has-mermaid .message-bubble {
    width: 100%;
    max-width: 100%;
  }

  .mermaid-card {
    margin: 10px 0;
  }

  .mermaid-header {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }

  .mermaid-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .mermaid-render {
    padding: 14px 10px;
  }

  .diagram-modal {
    padding: 8px;
  }

  .diagram-modal-card {
    width: calc(100vw - 16px);
    height: calc(100dvh - 16px);
    max-height: none;
  }

  .diagram-modal-header {
    align-items: flex-start;
    gap: 8px;
    padding: 10px;
  }

  .diagram-modal-controls {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .diagram-modal-body {
    padding: 8px;
  }
}
