 .mermaid-diagram {
  margin: 1.5rem 0;
  width: 100%;
}

.mermaid-diagram figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  width: 100%;
}

.mermaid-diagram .mermaid {
  --mermaid-fade: 0;
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: none;
  max-height: var(--mermaid-inline-height, 360px);
  overflow-y: hidden;
  overflow-x: auto;
  padding: 1rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(50, 62, 58, 0.18);
  background: linear-gradient(180deg, rgba(248, 250, 249, 0.94) 0%, rgba(255, 255, 255, 0.98) 100%);
  color: var(--ed-gray-dark, #2E2E2E);
  box-shadow: 0 3px 8px rgba(32, 38, 35, 0.16);
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  position: relative;
}

.mermaid-diagram .mermaid::after {
  content: '';
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  height: 36px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 70%, #ffffff 100%);
  pointer-events: none;
  opacity: var(--mermaid-fade, 1);
}

[data-bs-theme="dark"] .mermaid-diagram .mermaid::after {
  background: linear-gradient(180deg, rgba(14, 28, 24, 0) 0%, rgba(14, 28, 24, 0.75) 70%, rgba(14, 28, 24, 1) 100%);
}

[data-bs-theme="dark"] .mermaid-diagram .mermaid {
  background: linear-gradient(180deg, rgba(14, 28, 24, 0.94) 0%, rgba(20, 35, 31, 0.97) 100%);
  border-color: rgba(0, 218, 99, 0.25);
  color: #E4F8F0;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
}

.mermaid-inline-xs .mermaid {
  --mermaid-inline-height: 240px;
}

.mermaid-inline-sm .mermaid {
  --mermaid-inline-height: 320px;
}

.mermaid-inline-md .mermaid {
  --mermaid-inline-height: 400px;
}

.mermaid-inline-lg .mermaid {
  --mermaid-inline-height: 480px;
}

.mermaid-diagram .mermaid svg {
  height: auto;
  display: block;
}

.mermaid-diagram figcaption {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.mermaid-diagram .mermaid[role="button"] {
  cursor: zoom-in;
}

.mermaid-viewer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 18, 16, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 3rem clamp(1rem, 4vw, 3rem);
  flex-direction: column;
  gap: 0;
}

.mermaid-viewer-overlay.is-active {
  display: flex;
}

.mermaid-viewer {
  width: min(95vw, 1600px);
  max-height: 90vh;
  background: linear-gradient(180deg, rgba(248, 250, 249, 0.97) 0%, rgba(255, 255, 255, 0.99) 100%);
  border-radius: 0 0 0.75rem 0.75rem;
  border: 1px solid rgba(50, 62, 58, 0.22);
  border-bottom: none;
  border-top: none;
  box-shadow: 0 30px 60px rgba(14, 22, 19, 0.45);
  position: relative;
  padding: clamp(1.25rem, 3vw, 2rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mermaid-viewer__toolbar {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 0 1.5rem 0.35rem;
}

.mermaid-zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  border-radius: 0.5rem;
  background: rgba(240, 242, 241, 0.92);
  box-shadow: inset 0 0 0 1px rgba(50, 62, 58, 0.08);
}

.mermaid-zoom-btn,
.mermaid-zoom-reset {
  border: 1px solid rgba(50, 62, 58, 0.2);
  background: rgba(255, 255, 255, 0.9);
  color: #2A2E2C;
  border-radius: 0.35rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.mermaid-zoom-btn:hover,
.mermaid-zoom-reset:hover {
  background: rgba(240, 242, 241, 0.9);
  border-color: rgba(50, 62, 58, 0.35);
}

.mermaid-zoom-slider {
  width: 160px;
  accent-color: var(--ed-teal, #2C8370);
}

.mermaid-viewer__zoom-label {
  font-size: 0.85rem;
  color: #2A2E2C;
  min-width: 42px;
  text-align: right;
}

[data-bs-theme="dark"] .mermaid-viewer__toolbar .mermaid-zoom-controls {
  background: rgba(22, 36, 31, 0.9);
  box-shadow: inset 0 0 0 1px rgba(0, 218, 99, 0.25);
}

[data-bs-theme="dark"] .mermaid-zoom-btn,
[data-bs-theme="dark"] .mermaid-zoom-reset {
  background: rgba(22, 36, 31, 0.85);
  color: #F1FFF7;
  border-color: rgba(0, 218, 99, 0.25);
}

[data-bs-theme="dark"] .mermaid-zoom-btn:hover,
[data-bs-theme="dark"] .mermaid-zoom-reset:hover {
  background: rgba(0, 218, 99, 0.18);
}

[data-bs-theme="dark"] .mermaid-viewer__zoom-label {
  color: #CFFFE7;
}

.mermaid-viewer__close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  border: none;
  background: rgba(0, 0, 0, 0.08);
  color: #2E2E2E;
  width: 36px;
  height: 36px;
  border-radius: 18px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background 0.2s ease;
}

.mermaid-viewer__close:hover {
  background: rgba(0, 0, 0, 0.14);
}

[data-bs-theme="dark"] .mermaid-viewer {
  background: linear-gradient(180deg, rgba(14, 28, 24, 0.96) 0%, rgba(20, 35, 31, 0.98) 100%);
  color: #E4F8F0;
  border-color: rgba(0, 218, 99, 0.32);
}

[data-bs-theme="dark"] .mermaid-viewer__close {
  background: rgba(228, 248, 240, 0.1);
  color: #E4F8F0;
}

[data-bs-theme="dark"] .mermaid-viewer__close:hover {
  background: rgba(228, 248, 240, 0.18);
}

.mermaid-viewer__titlebar {
  min-width: min(95vw, 1600px);
  max-width: min(95vw, 1600px);
  padding: 0.35rem 1.5rem;
  text-align: center;
  font-weight: 600;
  color: #2A2E2C;
  background: rgba(240, 242, 241, 0.96);
  border-radius: 0.75rem 0.75rem 0 0;
  border: 1px solid rgba(50, 62, 58, 0.22);
  border-bottom: none;
  box-shadow: 0 4px 12px rgba(14, 22, 19, 0.18);
  margin-bottom: -1px;
  display: flex;
  justify-content: center;
  align-items: center;
}

[data-bs-theme="dark"] .mermaid-viewer__titlebar {
  background: rgba(22, 36, 31, 0.92);
  color: #F1FFF7;
  border: 1px solid rgba(0, 218, 99, 0.32);
  border-bottom: none;
}

.mermaid-viewer__body {
  width: 100%;
  flex: 1 1 auto;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 0.75rem;
}
.mermaid-viewer__canvas {
  width: auto;
  max-width: none;
  display: inline-block;
}

.mermaid-viewer__canvas svg {
  display: block;
}

[data-bs-theme="dark"] .mermaid-diagram figcaption {
  color: rgba(233, 255, 244, 0.78);
}

.mermaid .label foreignObject > div {
  display: flex;
  align-items: center;
}


.mermaid .nodeLabel {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  text-align: center;
}

.mermaid .nodeLabel > span,
.mermaid .nodeLabel > div {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0;
  margin: 0;
}

.mermaid .ph,
.mermaid .ph::before {
  font-family: "Phosphor" !important;
  font-size: 2rem;
  line-height: 1;
  font-weight: 600;
}

.mermaid .ph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  vertical-align: middle;
  color: var(--mermaid-icon-color, #2C8370) !important;
}

[data-bs-theme="dark"] .mermaid .ph {
  color: var(--mermaid-icon-color-dark, #7BFFE2) !important;
}

.mermaid .ph-cloud-arrow-down,
.mermaid .ph-plug,
.mermaid .ph-traffic-signal {
  color: #1B7F5E !important;
}

.mermaid .ph-circles-three-plus,
.mermaid .ph-wave-sine,
.mermaid .ph-list-checks {
  color: #0F766E !important;
}

.mermaid .ph-chart-line-up,
.mermaid .ph-chart-pie,
.mermaid .ph-pulse {
  color: #2563EB !important;
}

.mermaid .ph-file-text,
.mermaid .ph-file-code,
.mermaid .ph-copy {
  color: #7C3AED !important;
}

.mermaid .ph-bell-ringing,
.mermaid .ph-bell-simple-ringing,
.mermaid .ph-paper-plane-tilt,
.mermaid .ph-paper-plane-right {
  color: #EA580C !important;
}

.mermaid .ph-heartbeat,
.mermaid .ph-first-aid-kit {
  color: #DC2626 !important;
}

.mermaid .ph-fingerprint,
.mermaid .ph-gear-six,
.mermaid .ph-funnel-simple,
.mermaid .ph-codesandbox-logo,
.mermaid .ph-scroll,
.mermaid .ph-database,
.mermaid .ph-cloud {
  color: #6B21A8 !important;
}
.mermaid-viewer__body svg {
  width: 100%;
  height: auto;
}

/* Loading state */
.mermaid[data-loading="true"]::before {
  content: 'Loading diagram...';
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  color: var(--ed-gray, #6B7280);
  font-size: 0.9rem;
}

/* Fallback styles */
.mermaid-fallback {
  padding: 1.5rem;
  border-radius: 0.5rem;
  background: rgba(243, 244, 246, 0.8);
  border: 1px dashed rgba(156, 163, 175, 0.5);
  text-align: center;
}

[data-bs-theme="dark"] .mermaid-fallback {
  background: rgba(31, 41, 55, 0.8);
  border-color: rgba(75, 85, 99, 0.5);
}

.mermaid-fallback p {
  margin: 0 0 0.5rem;
  color: var(--ed-gray-dark, #374151);
}

[data-bs-theme="dark"] .mermaid-fallback p {
  color: var(--ed-gray-light, #D1D5DB);
}

.mermaid-fallback details {
  margin-top: 0.75rem;
}

.mermaid-fallback summary {
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--ed-teal, #2C8370);
}

[data-bs-theme="dark"] .mermaid-fallback summary {
  color: var(--ed-teal-light, #7BFFE2);
}

.mermaid-fallback pre {
  margin-top: 0.5rem;
  text-align: left;
  font-size: 0.8rem;
  overflow-x: auto;
}

/* Error state */
.mermaid-error {
  padding: 1rem;
  border-radius: 0.5rem;
  background: rgba(254, 226, 226, 0.8);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--ed-red, #DC2626);
  font-size: 0.875rem;
}

[data-bs-theme="dark"] .mermaid-error {
  background: rgba(127, 29, 29, 0.3);
  border-color: rgba(220, 38, 38, 0.5);
  color: var(--ed-red-light, #FCA5A5);
}
