/* ═══════════════════════════════════════════════════════════════════════════
   DiagramViewer Component Styles
   ─────────────────────────────────────────────────────────────────────────
   Shared canvas for inspecting Mermaid diagrams: zoom, pan, fit-to-content.
   Applied via the .diagram-viewer class added by DiagramViewer.js.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Root canvas ──────────────────────────────────────────────────────────── */

.diagram-viewer {
  position: relative;
  overflow: hidden;
  background: var(--background-secondary, #1a2332);
  border-radius: var(--border-radius, 8px);
  cursor: grab;
  /* Prevent text selection while panning */
  user-select: none;
  /* Tell the browser not to handle touch-scroll, we handle it */
  touch-action: none;
}

.diagram-viewer.dv--dragging {
  cursor: grabbing;
}

/* ── Viewport (the CSS-transformed layer) ────────────────────────────────── */

.dv-viewport {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

/* ── Content wrapper (holds the rendered SVG) ────────────────────────────── */

.dv-content {
  display: inline-block;
  line-height: 0; /* Remove the descender gap below SVGs without sizing the SVG's text. */
}

.dv-content svg {
  display: block;
  line-height: normal;
  /* max-width is cleared programmatically after mermaid renders */
}

.dv-content svg foreignObject,
.dv-content svg foreignObject div,
.dv-content svg .label,
.dv-content svg .nodeLabel,
.dv-content svg .edgeLabel {
  line-height: normal;
}

/* ── Overlay states: loading / error / empty ─────────────────────────────── */

.dv-loading,
.dv-error,
.dv-empty {
  position: absolute;
  inset: 0;
  display: none; /* shown/hidden via JS */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  text-align: center;
  pointer-events: none;
}

.dv-loading {
  color: var(--text-secondary, #a0aec0);
  font-size: 0.9rem;
}

/* Subtle pulse animation for the loading text */
.dv-loading::before {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-color, rgba(0, 212, 170, 0.3));
  border-top-color: var(--primary-color, #00d4aa);
  border-radius: 50%;
  animation: dv-spin 0.8s linear infinite;
}

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

.dv-error {
  color: var(--danger-color, #ff6b6b);
  font-size: 0.9rem;
  /* Allow clicking links inside error messages */
  pointer-events: auto;
}

.dv-empty {
  color: var(--text-muted, #718096);
  font-size: 0.9rem;
}

/* ── Built-in toolbar (optional; enabled via opts.toolbar = true) ─────────── */

.dv-toolbar {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 10;
  display: flex;
  gap: 0.25rem;
  /* The toolbar container itself is click-through so pan still works
     between buttons. Only the buttons are interactive. */
  pointer-events: none;
}

.dv-toolbar-btn {
  pointer-events: auto;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-elevated, rgba(45, 55, 72, 0.92));
  backdrop-filter: blur(6px);
  border: 1px solid var(--border-color, rgba(0, 212, 170, 0.25));
  border-radius: var(--border-radius, 8px);
  color: var(--text-color, #e2e8f0);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition:
    background var(--transition-fast, 0.2s ease),
    border-color var(--transition-fast, 0.2s ease),
    color var(--transition-fast, 0.2s ease);
}

.dv-toolbar-btn:hover {
  background: var(--primary-color, #00d4aa);
  border-color: var(--primary-color, #00d4aa);
  color: #fff;
}

.dv-toolbar-btn:focus-visible {
  outline: 2px solid var(--primary-color, #00d4aa);
  outline-offset: 2px;
}

.dv-toolbar-btn:active {
  transform: scale(0.92);
}

/* ════════════════════════════════════════════════════════════════════════════
   Dashboard modal – external toolbar & title fixes
   ════════════════════════════════════════════════════════════════════════════ */

/*
 * The external zoom-controls row sits above the DiagramViewer canvas inside
 * .chart-preview-container.  Without an explicit rule it inherits block layout
 * and stretches to the container's full width.  Make it a compact inline-flex
 * group aligned to the right instead.
 */
.modal-zoom-controls {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  /* Shrink to hug the buttons – never stretch to fill the container */
  width: fit-content;
  /* Float the whole group to the right of the modal body */
  margin-left: auto;
  /* A little breathing room below the buttons before the canvas */
  padding-bottom: 0.4rem;
}

/*
 * When a diagram has a long title the h3 in the modal header can overflow and
 * get clipped by .modal-content { overflow: hidden }.  Constrain it to one
 * line with ellipsis so the ✕ close button is always reachable.
 */
#view-chart-modal .modal-header h3 {
  flex: 1;           /* Consume all available space… */
  min-width: 0;      /* …but allow the flex item to shrink below its content width */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 0.75rem;
}

/*
 * Chart card titles in grid / folder view – also single-line with ellipsis.
 * A full-width title inside a 280–300 px card wraps unpredictably; truncation
 * gives a cleaner look and the full name is shown in the modal on open.
 */
.chart-card h4 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* Show full title on mouse hover as a native tooltip */
}

/* ════════════════════════════════════════════════════════════════════════════
   Surface-specific sizing
   Each surface that embeds a DiagramViewer needs an explicit height so the
   viewer has a measurable container to fit the diagram into.
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Dashboard "view chart" modal ────────────────────────────────────────── */

/* The container that DiagramViewer renders into */
.view-chart-container {
  width: 100%;
  height: 55vh;
  min-height: 280px;
  border-radius: var(--border-radius, 8px);
  overflow: hidden;
}

/* In fullscreen the modal should expand to fill the viewport */
#view-chart-modal.fullscreen .modal-content {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
  display: flex;
  flex-direction: column;
}

#view-chart-modal.fullscreen .modal-body {
  flex: 1;
  min-height: 0;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
}

#view-chart-modal.fullscreen .chart-preview-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#view-chart-modal.fullscreen .view-chart-container {
  flex: 1;
  height: 100%;
  min-height: 0;
  border-radius: 0;
}

/* ── Gallery modal chart preview ─────────────────────────────────────────── */

/* Give the chart preview area a fixed height so DiagramViewer can measure it */
#modal-chart-preview {
  min-height: 320px;
  height: 42vh;
}

/* ── Share page ───────────────────────────────────────────────────────────── */

/* The mermaid-container div that DiagramViewer takes over */
#chart-content.diagram-viewer {
  height: 65vh;
  min-height: 300px;
}

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

@media (max-width: 600px) {
  .view-chart-container {
    height: 45vh;
    min-height: 200px;
  }

  #modal-chart-preview {
    height: 35vh;
    min-height: 180px;
  }

  #chart-content.diagram-viewer {
    height: 55vh;
  }
}
