/* Host guide show — Mermaid flow diagram + scroll viewport.
   View: app/views/host/guides/show.html.erb; Stimulus: guide_node_viewer_controller.js */
@layer components {

.guide-mermaid-diagram__panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
}

.guide-mermaid-diagram__panel-header .guide-mermaid-diagram__panel-title {
  margin: 0;
  flex: 1;
  min-width: min(12rem, 100%);
}

.guide-mermaid-diagram__zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: nowrap;
}

.guide-mermaid-diagram__zoom-btn {
  min-width: 2.25rem;
  padding-left: var(--space-2);
  padding-right: var(--space-2);
  font-weight: 700;
  color: var(--gi-fg);
  border-color: var(--gi-border);
  background: color-mix(in srgb, var(--gi-card) 76%, transparent);
}

.guide-mermaid-diagram__zoom-btn--reset {
  min-width: 4.5rem;
  font-variant-numeric: tabular-nums;
}

.guide-mermaid-diagram__zoom-btn:hover {
  color: var(--gi-fg);
  border-color: color-mix(in srgb, var(--color-primary) 40%, var(--gi-border));
  background: color-mix(in srgb, var(--color-primary) 14%, var(--gi-card));
}

/* Beat .host-page--guide-show .host-guide-interview-complete-panel__title margins on the same h2 */
.host-page--guide-show .guide-mermaid-diagram__panel-header .host-guide-interview-complete-panel__title {
  margin: 0;
}

/* Help control sits in the dark guide card; keep tooltip above diagram scroll area */
.guide-mermaid-diagram__help-tooltip {
  flex-shrink: 0;
  z-index: 2;
}

.guide-mermaid-diagram__help-btn {
  min-width: 2.25rem;
  padding-left: var(--space-2);
  padding-right: var(--space-2);
}

.guide-mermaid-diagram__help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  border: 1px solid var(--gi-border);
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1;
  color: var(--gi-fg-muted);
}

.guide-mermaid-diagram__viewport {
  display: block;
  width: 100%;
  box-sizing: border-box;
  overflow: auto;
  max-width: 100%;
  max-height: min(70vh, 42rem);
  min-height: 12rem;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-muted);
  touch-action: manipulation;
  text-align: center;
}

/* Guide show page: wider canvas — diagram uses intrinsic SVG size; scroll inside viewport */
.host-page--guide-show .guide-mermaid-diagram__viewport {
  max-height: min(82vh, 64rem);
  min-height: 14rem;
}

.guide-mermaid-diagram__mount {
  display: inline-block;
  box-sizing: border-box;
  vertical-align: top;
  /* Drill = navigation (distinct from primary/orange); leaf-only = subtle neutral ring */
  --guide-mermaid-drill-stroke: color-mix(in srgb, var(--color-info) 50%, var(--color-border));
  --guide-mermaid-drill-accent: var(--color-info);
  --guide-mermaid-leaf-stroke: color-mix(in srgb, var(--color-text-muted) 42%, var(--color-border));
}

.guide-mermaid-diagram__mount .mermaid {
  display: inline-block;
}

.guide-mermaid-diagram__mount svg {
  display: block;
  max-width: none;
  height: auto;
}

/* Diagram nodes: hand cursor on the whole shape (clicks still no-op on non-interactive nodes). */
.guide-mermaid-diagram__mount g.node,
.guide-mermaid-diagram__mount g.node * {
  cursor: pointer;
}

.guide-mermaid-diagram__mount g.node :is(text, tspan) {
  font-weight: 600;
  transition:
    fill var(--duration-normal) var(--ease-out),
    font-weight var(--duration-fast) var(--ease-out);
}

/* Mermaid htmlLabels put copy in nested spans (.nodeLabel, etc.); they set their own font-weight,
   so weight must apply to descendants, not only the wrapper div. */
.guide-mermaid-diagram__mount g.node foreignObject * {
  font-weight: 600;
  transition: font-weight var(--duration-fast) var(--ease-out);
}

.guide-mermaid-diagram__mount g.node foreignObject > div {
  transition: transform var(--duration-normal) var(--ease-spring);
}

/*
 * Never set CSS `transform` on Mermaid flow shapes (rect/polygon/path/…). Mermaid relies on the
 * SVG `transform` attribute for layout; a CSS transform replaces it and breaks decision diamonds
 * (empty polygon, label detached) and similar nodes.
 */
.guide-mermaid-diagram__mount g.node :is(rect, polygon, circle, ellipse, path) {
  transition:
    filter var(--duration-normal) var(--ease-out),
    stroke-width var(--duration-fast) var(--ease-out);
}

.guide-mermaid-diagram__mount g.node:not(.guide-mermaid-node--returning):not(.guide-mermaid-node--selected):hover :is(rect, polygon, circle, ellipse, path) {
  filter: drop-shadow(0 5px 16px color-mix(in srgb, var(--color-text) 12%, transparent))
    drop-shadow(0 2px 8px color-mix(in srgb, var(--color-text) 7%, transparent));
}

.guide-mermaid-diagram__mount g.node.guide-mermaid-node--selected:not(.guide-mermaid-node--returning):hover :is(rect, polygon, circle, ellipse, path) {
  filter:
    drop-shadow(0 0 6px color-mix(in srgb, var(--color-primary) 35%, transparent))
    drop-shadow(0 4px 14px color-mix(in srgb, var(--color-primary) 22%, transparent));
}

.guide-mermaid-diagram__mount g.node:not(.guide-mermaid-node--returning):not(.guide-mermaid-node--selected):hover :is(text, tspan) {
  fill: color-mix(in srgb, var(--color-text) 92%, var(--color-primary) 8%) !important;
  font-weight: 800 !important;
}

.guide-mermaid-diagram__mount g.node.guide-mermaid-node--selected:not(.guide-mermaid-node--returning):hover :is(text, tspan) {
  font-weight: 800 !important;
}

.guide-mermaid-diagram__mount g.node:not(.guide-mermaid-node--returning):hover .guide-mermaid-drill-marker text {
  fill: color-mix(in srgb, var(--guide-mermaid-drill-accent) 88%, var(--color-text) 12%) !important;
}

/* Nudge HTML labels only on box nodes; diamonds use polygon + foreignObject positioning — translateY skews decision labels */
.guide-mermaid-diagram__mount g.node:not(.guide-mermaid-node--returning):not(:has(polygon)):hover foreignObject > div {
  transform: translateY(-2px);
}

.guide-mermaid-diagram__mount g.node:not(.guide-mermaid-node--returning):hover foreignObject * {
  font-weight: 800 !important;
}

/* Drill-in hint (injected by guide_node_viewer_controller); pointer-events none on the marker group */
.guide-mermaid-diagram__mount .guide-mermaid-drill-marker text {
  fill: var(--guide-mermaid-drill-accent);
  font-size: 15px;
  font-weight: 800;
  dominant-baseline: alphabetic;
}

/* Leaf-only: open aside notes — muted outline (not primary) */
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--leaf:not(.guide-mermaid-node--drillable):not(.guide-mermaid-node--selected) rect,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--leaf:not(.guide-mermaid-node--drillable):not(.guide-mermaid-node--selected) polygon,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--leaf:not(.guide-mermaid-node--drillable):not(.guide-mermaid-node--selected) circle,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--leaf:not(.guide-mermaid-node--drillable):not(.guide-mermaid-node--selected) ellipse {
  stroke: var(--guide-mermaid-leaf-stroke) !important;
  stroke-width: 2px !important;
}

/* Drillable (with or without leaf notes): sub-page navigation — info palette, not orange */
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--drillable:not(.guide-mermaid-node--selected) rect,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--drillable:not(.guide-mermaid-node--selected) polygon,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--drillable:not(.guide-mermaid-node--selected) circle,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--drillable:not(.guide-mermaid-node--selected) ellipse {
  stroke: var(--guide-mermaid-drill-stroke) !important;
  stroke-width: 3px !important;
}

.guide-mermaid-diagram__mount g.node.guide-mermaid-node--selected rect,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--selected polygon,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--selected circle,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--selected ellipse {
  stroke: var(--color-primary) !important;
  stroke-width: 4px !important;
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--color-primary) 35%, transparent));
}

/* Return flash: stroke + glow only (no transform scale — same attribute-clobber issue as diamonds). */
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--returning rect,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--returning polygon,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--returning circle,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--returning ellipse {
  stroke: var(--color-primary) !important;
  stroke-width: 5px !important;
  filter: drop-shadow(0 0 14px color-mix(in srgb, var(--color-primary) 55%, transparent));
  animation: guide-mermaid-node-return-glow 2200ms var(--ease-out) 1;
}

.guide-mermaid-diagram__mount g.node.guide-mermaid-node--returning text,
.guide-mermaid-diagram__mount g.node.guide-mermaid-node--returning tspan {
  fill: color-mix(in srgb, white 88%, var(--color-primary)) !important;
}

@keyframes guide-mermaid-node-return-glow {
  0% {
    stroke-width: 4px;
    filter: drop-shadow(0 0 0 color-mix(in srgb, var(--color-primary) 0%, transparent));
  }

  20% {
    stroke-width: 6px;
    filter: drop-shadow(0 0 18px color-mix(in srgb, var(--color-primary) 70%, transparent));
  }

  100% {
    stroke-width: 5px;
    filter: drop-shadow(0 0 10px color-mix(in srgb, var(--color-primary) 35%, transparent));
  }
}

@media (prefers-reduced-motion: reduce) {
  .guide-mermaid-diagram__mount g.node.guide-mermaid-node--returning,
  .guide-mermaid-diagram__mount g.node.guide-mermaid-node--returning rect,
  .guide-mermaid-diagram__mount g.node.guide-mermaid-node--returning polygon,
  .guide-mermaid-diagram__mount g.node.guide-mermaid-node--returning circle,
  .guide-mermaid-diagram__mount g.node.guide-mermaid-node--returning ellipse {
    animation: none;
  }

  .guide-mermaid-diagram__mount g.node :is(rect, polygon, circle, ellipse, path) {
    transition: none;
  }

  .guide-mermaid-diagram__mount g.node:not(.guide-mermaid-node--returning):not(.guide-mermaid-node--selected):hover :is(rect, polygon, circle, ellipse, path),
  .guide-mermaid-diagram__mount g.node.guide-mermaid-node--selected:not(.guide-mermaid-node--returning):hover :is(rect, polygon, circle, ellipse, path) {
    filter: none;
  }

  .guide-mermaid-diagram__mount g.node:not(.guide-mermaid-node--returning):not(:has(polygon)):hover foreignObject > div {
    transform: none;
  }

  .guide-mermaid-diagram__mount g.node:not(.guide-mermaid-node--returning):hover foreignObject * {
    font-weight: 600 !important;
  }

  .guide-mermaid-diagram__mount g.node:not(.guide-mermaid-node--returning):not(.guide-mermaid-node--selected):hover :is(text, tspan),
  .guide-mermaid-diagram__mount g.node.guide-mermaid-node--selected:not(.guide-mermaid-node--returning):hover :is(text, tspan) {
    transition: none;
    font-weight: 600 !important;
  }
}

@media (max-width: 640px) {
  .guide-mermaid-diagram__panel-header {
    gap: var(--space-2);
  }

  .guide-mermaid-diagram__zoom-controls {
    order: 3;
    width: 100%;
    justify-content: flex-end;
  }

  .guide-mermaid-diagram__viewport {
    max-height: min(62vh, 34rem);
    padding: var(--space-2);
  }
}

}
