.diagram-viewer-source {
  cursor: zoom-in;
}

.diagram-viewer-host {
  position: relative;
}

.diagram-viewer-open,
.diagram-viewer-close {
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(127, 137, 151, .42);
  background: rgba(255, 255, 255, .92);
  color: #1b2431;
  box-shadow: 0 6px 18px rgba(20, 27, 36, .16);
  cursor: pointer;
  font: 700 .78rem/1 ui-sans-serif, system-ui, sans-serif;
}

.diagram-viewer-open {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  opacity: .82;
  transition: opacity .16s ease, transform .16s ease;
}

.diagram-viewer-host:hover .diagram-viewer-open,
.diagram-viewer-open:focus-visible {
  opacity: 1;
  transform: translateY(-1px);
}

.diagram-viewer-open:focus-visible,
.diagram-viewer-close:focus-visible {
  outline: 3px solid rgba(79, 157, 148, .45);
  outline-offset: 3px;
}

.diagram-viewer {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--canvas, var(--bg, #eef1f6));
  color: var(--ink, #1b2431);
}

.diagram-viewer::backdrop {
  background: rgba(12, 16, 21, .82);
  backdrop-filter: blur(8px);
}

.diagram-viewer[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.diagram-viewer-bar {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px clamp(14px, 3vw, 34px);
  border-bottom: 1px solid var(--line, #d7dde5);
  background: var(--paper, var(--panel, rgba(255, 255, 255, .9)));
}

.diagram-viewer-title {
  overflow: hidden;
  margin: 0;
  font: 750 clamp(.92rem, 2vw, 1.08rem)/1.3 ui-sans-serif, system-ui, sans-serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diagram-viewer-close {
  grid-auto-flow: column;
  gap: 8px;
  min-height: 40px;
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 0 15px;
}

.diagram-viewer-canvas {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: clamp(14px, 4vw, 48px);
}

.diagram-viewer-canvas > svg,
.diagram-viewer-canvas > img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 100%;
  margin: auto;
  object-fit: contain;
}

.diagram-viewer-canvas > svg {
  width: min(80vw, 760px);
  height: min(78vh, 760px);
}

.diagram-viewer-canvas > img {
  width: 100%;
}

body.diagram-viewer-active {
  overflow: hidden;
}

@media (max-width: 560px) {
  .diagram-viewer-open { top: 7px; right: 7px; }
  .diagram-viewer-close span:last-child { display: none; }
  .diagram-viewer-close { width: 40px; padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .diagram-viewer-open { transition: none; }
}
