/* ── mermaid.css ──────────────────────────────────────────────────
   Mermaid Diagrams guide page - aligned with knowledge_graph_update.css
   design language. Purple accent via global --purple token (style.css).
   ──────────────────────────────────────────────────────────────── */

/* SVG icon helper */
.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  stroke-width: 0;
  stroke: currentColor;
  fill: currentColor;
}
.icon-lucide {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Override base content max-width */
.mg-content {
  max-width: 960px !important;
}

/* ── Header Actions ──────────────────────────────────────────────── */

.header-actions {
  position: absolute;
  top: 1.5rem;
  left: 1.5rem;
  right: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
}

/* Match pill style from index.html */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-accent);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-2);
  background: var(--bg-card);
  border: 1px solid var(--border-mid);
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  transition: color 0.15s, border-color 0.15s, background 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.back-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--bg-subtle);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.back-btn .icon { width: 0.8rem; height: 0.8rem; flex-shrink: 0; }

/* ── Page Header ─────────────────────────────────────────────────── */

.mg-header {
  text-align: center;
  margin-bottom: 2rem;
  padding-top: 4rem;
}

.mg-header__title {
  font-size: clamp(1.8rem, 4vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text);
  margin: 0 0 0.75rem;
}

.mg-header__title span { color: var(--purple); }

.mg-header__sub {
  font-size: 0.875rem;
  color: var(--text-2);
  line-height: 1.65;
  font-weight: 300;
  max-width: 560px;
  margin: 0 auto 1.5rem;
}

/* ── Stats bar ───────────────────────────────────────────────────── */

.mg-stats {
  display: inline-flex;
  align-items: center;
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.625rem 0;
  box-shadow: var(--shadow-card);
}

.mg-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 1.5rem;
  gap: 0.1rem;
}

.mg-stat__val {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--purple);
  font-variant-numeric: tabular-nums;
}

.mg-stat__lbl {
  font-size: 0.68rem;
  color: var(--text-3);
  font-weight: 400;
  white-space: nowrap;
}

.mg-stat__sep {
  width: 1px;
  height: 2rem;
  background: var(--border);
  flex-shrink: 0;
}

/* ── Feature Section Layout ──────────────────────────────────────── */

.mg-features {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

/* 2-column row */
.mg-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* Base feature card - matches .kg-feat */
.mg-feat {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.125rem 1.25rem;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.25s, border-color 0.25s;
}

.mg-feat:hover {
  box-shadow: var(--shadow-hover);
  border-color: var(--border-mid);
}

/* Card header row: icon + title + step num */
.mg-feat__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.mg-feat__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 9px;
  flex-shrink: 0;
}

.mg-feat__icon .icon { width: 1rem; height: 1rem; }

.mg-feat__title {
  font-family: var(--font-accent);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.mg-feat__text {
  font-size: 0.795rem;
  color: var(--text-2);
  line-height: 1.65;
  font-weight: 300;
}

/* Step number badge */
.mg-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  border: 1px solid rgba(147, 51, 234, 0.35);
  background: rgba(147, 51, 234, 0.06);
  color: var(--purple);
  font-size: 0.68rem;
  font-weight: 700;
  flex-shrink: 0;
  font-family: var(--font-mono);
}

.dark .mg-step-num {
  border-color: rgba(192, 132, 252, 0.35);
  background: rgba(192, 132, 252, 0.08);
}

/* ── Highlight box ───────────────────────────────────────────────── */

.mg-highlight {
  background: rgba(147, 51, 234, 0.05);
  border: 1px solid rgba(147, 51, 234, 0.18);
  border-radius: 10px;
  padding: 0.875rem 1rem;
}

.mg-highlight__title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--purple);
  margin-bottom: 0.4rem;
}

.mg-highlight__title .icon { width: 0.9rem; height: 0.9rem; }

.mg-highlight p {
  font-size: 0.795rem;
  color: var(--text-2);
  line-height: 1.65;
  font-weight: 300;
  margin: 0;
}

/* ── Subsection heading inside a feat card ──────────────────────── */

.mg-sub-heading {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.795rem;
  font-weight: 600;
  color: var(--text);
  margin: 0.5rem 0 0.35rem;
}

.mg-sub-heading .icon {
  width: 0.85rem;
  height: 0.85rem;
  color: var(--purple);
  flex-shrink: 0;
}

/* ── Trigger keyword tags ────────────────────────────────────────── */

.mg-trigger-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-left: 3px solid rgba(147, 51, 234, 0.45);
  border-radius: 8px;
  padding: 0.75rem 0.875rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin: 0.35rem 0;
}

.mg-tag {
  background: var(--bg-card);
  border: 1px solid rgba(147, 51, 234, 0.22);
  color: var(--purple);
  padding: 0.2rem 0.55rem;
  border-radius: 5px;
  font-size: 0.765rem;
  font-weight: 500;
  font-family: var(--font-accent);
  white-space: nowrap;
}

.dark .mg-tag {
  border-color: rgba(192, 132, 252, 0.25);
}

/* ── Image gallery ───────────────────────────────────────────────── */

.mg-image-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.mg-image-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-subtle);
}

.mg-image-card img {
  width: 100%;
  height: auto;
  display: block;
}

.mg-image-caption {
  padding: 0.55rem 0.875rem;
  font-size: 0.72rem;
  color: var(--text-3);
  text-align: center;
  border-top: 1px solid var(--border);
  line-height: 1.45;
}

/* ── Diagram Types Grid ──────────────────────────────────────────── */

.mg-diag-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.mg-diag-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.875rem 0.8rem;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.mg-diag-item:hover {
  border-color: rgba(147, 51, 234, 0.35);
  background: rgba(147, 51, 234, 0.03);
  box-shadow: 0 2px 10px rgba(147, 51, 234, 0.07);
}

.dark .mg-diag-item:hover {
  background: rgba(192, 132, 252, 0.05);
  border-color: rgba(192, 132, 252, 0.3);
}

.mg-diag-item__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 7px;
  background: rgba(147, 51, 234, 0.08);
  color: var(--purple);
  margin-bottom: 0.2rem;
  flex-shrink: 0;
}

.dark .mg-diag-item__icon {
  background: rgba(192, 132, 252, 0.1);
}

.mg-diag-item__icon .icon { width: 0.9rem; height: 0.9rem; }

.mg-diag-item__name {
  font-size: 0.77rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.mg-diag-item__desc {
  font-size: 0.695rem;
  color: var(--text-3);
  line-height: 1.45;
  font-weight: 300;
}

/* ── Use Case Grid ───────────────────────────────────────────────── */

.mg-usecase-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.mg-usecase-item {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.875rem 1rem;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.mg-usecase-item:hover {
  border-color: rgba(147, 51, 234, 0.3);
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(147, 51, 234, 0.07);
}

.mg-usecase-item__title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.795rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.mg-usecase-item__title .icon {
  width: 0.85rem;
  height: 0.85rem;
  color: var(--purple);
  flex-shrink: 0;
}

.mg-usecase-item p {
  font-size: 0.755rem;
  color: var(--text-2);
  line-height: 1.55;
  font-weight: 300;
  margin: 0;
}

/* ── Diagram Type Tabs ───────────────────────────────────────────── */

.mg-diag-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}

.mg-diag-tab {
  font-family: var(--font-accent);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.28rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-2);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.mg-diag-tab:hover {
  color: var(--text);
  background: var(--bg-card);
  border-color: var(--border-mid);
}

.mg-diag-tab.active {
  background: rgba(147, 51, 234, 0.1);
  border-color: rgba(147, 51, 234, 0.4);
  color: var(--purple);
  font-weight: 600;
}

.dark .mg-diag-tab.active {
  background: rgba(192, 132, 252, 0.12);
  border-color: rgba(192, 132, 252, 0.4);
}

/* ── Live Preview Panel ──────────────────────────────────────────── */

.mg-diag-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  min-height: 240px;
}

/* Mermaid SVG preview area */
.mg-diag-panel__preview {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow: hidden;
  min-height: 200px;
}

/* Scale SVG to fit */
.mg-diag-panel__preview svg {
  max-width: 100%;
  max-height: 280px;
  height: auto;
}

/* Code pane */
.mg-diag-panel__code {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.mg-diag-panel__code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.875rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.mg-diag-panel__code-label {
  font-family: var(--font-accent);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--purple);
}

/* Copy button */
.mg-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-accent);
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-2);
  background: transparent;
  border: 1px solid var(--border-mid);
  padding: 0.2rem 0.55rem;
  border-radius: 5px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.mg-copy-btn:hover {
  color: var(--purple);
  border-color: rgba(147, 51, 234, 0.35);
  background: rgba(147, 51, 234, 0.05);
}

/* Code block */
.mg-diag-panel__pre {
  flex: 1;
  margin: 0;
  padding: 0.875rem;
  overflow: auto;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.72rem;
  line-height: 1.6;
  color: var(--text-2);
  background: transparent;
  white-space: pre;
}

/* Error fallback */
.mg-diag-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-3);
  padding: 1.5rem 1rem;
  height: 100%;
  gap: 0;
}

/* Loading state */
.mg-diag-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 0.75rem;
  color: var(--text-3);
  gap: 0.4rem;
}

.mg-diag-loading::before {
  content: '';
  display: inline-block;
  width: 0.875rem;
  height: 0.875rem;
  border: 2px solid rgba(147, 51, 234, 0.25);
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: mg-spin 0.7s linear infinite;
}

.dark .mg-diag-loading::before {
  border-color: rgba(192, 132, 252, 0.2);
  border-top-color: var(--purple);
}

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

/* ── Responsive ─────────────────────────────────────────────────── */

@media (max-width: 700px) {
  .mg-2col { grid-template-columns: 1fr; }
  .mg-diag-grid { grid-template-columns: repeat(3, 1fr); }
  .mg-usecase-grid { grid-template-columns: 1fr 1fr; }
  .mg-diag-panel { grid-template-columns: 1fr; }
}

@media (max-width: 580px) {
  .header-actions {
    top: 1rem;
    left: 1rem;
    right: 1rem;
  }

  .mg-header { padding-top: 3.5rem; }

  .mg-stats {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
  }

  .mg-stat__sep { display: none; }
  .mg-stat { padding: 0 0.875rem; }

  .mg-diag-grid { grid-template-columns: repeat(2, 1fr); }
  .mg-usecase-grid { grid-template-columns: 1fr; }
  .mg-image-grid { grid-template-columns: 1fr; }
  .mg-diag-panel { grid-template-columns: 1fr; }

  .mg-feat {
    padding: 1.125rem 1.125rem;
  }
}
