:root {
  --diagram-violet: #6153d8;
  --diagram-blue: #246ed1;
  --diagram-green: #167d62;
  --diagram-orange: #b75c22;
  --diagram-pink: #b8417f;
}

[data-theme="dark"] {
  --diagram-violet: #a99aff;
  --diagram-blue: #75adff;
  --diagram-green: #65d7ad;
  --diagram-orange: #f4a66c;
  --diagram-pink: #f18fc3;
}

.has-immersive-diagram .app-main > :is(.board-tools-floating, .board-zoom-floating),
.has-immersive-diagram .sidebar .sidebar-board:not(.sidebar-diagrams) { display: none; }
.sidebar-diagrams small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diagram-view { position: relative; height: 100%; min-width: 0; }
.diagram-view { background: var(--canvas) radial-gradient(circle, var(--grid-dot) 1px, transparent 1.15px) 8px 8px / 18px 18px; }
.diagram-canvas, .diagram-viewport { position: absolute; inset: 0; }
.diagram-viewport { overflow: clip; overscroll-behavior: none; touch-action: none; user-select: none; cursor: grab; }
.diagram-viewport:focus-visible { outline-offset: -3px; }
.diagram-viewport.is-dragging, .diagram-viewport.is-dragging .diagram-node { cursor: grabbing; }
.diagram-world, .diagram-edges, .diagram-nodes { position: absolute; inset: 0 auto auto 0; width: 0; height: 0; transform-origin: 0 0; }
.diagram-world { will-change: transform; }
.diagram-nodes { z-index: 1; }
.diagram-edges { width: 1px; height: 1px; overflow: visible; pointer-events: none; }
.diagram-edges-over { z-index: 2; }
.diagram-edge { fill: none; stroke: currentColor; stroke-width: 2.6; opacity: .83; }
.diagram-edges-over .diagram-edge { stroke-dasharray: 6 5; opacity: .48; }
.diagram-edge.is-related { stroke-width: 3.3; opacity: 1; }
.diagram-edges-over .diagram-edge.is-related { opacity: .65; }
.diagram-edge.is-muted, .diagram-edges-over .diagram-edge.is-muted { opacity: .07; }
.diagram-node { display: flex; position: absolute; flex-direction: column; transform: translate(-50%, -50%); border: 1px solid var(--border-strong); border-radius: 4px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-card); overflow: hidden; cursor: default; }
.diagram-node:hover, .diagram-node.is-related { z-index: 1; }
.diagram-section-file.is-related, .diagram-section-frame.is-related, .diagram-node-file.is-related { outline: 1px solid var(--accent-border); }
.diagram-node.is-selected { z-index: 2; }
.diagram-nodes .is-selected { outline: 2px solid var(--accent); }
.diagram-nodes .is-muted { opacity: .23; }
.diagram-nodes .is-muted:hover, .diagram-nodes .is-muted:focus-within { opacity: .8; }
.diagram-node-title { display: flex; width: 100%; flex-shrink: 0; align-items: center; min-width: 0; gap: 6px; padding: 0 8px; border: 0; border-bottom: 1px solid var(--border); color: var(--text); text-align: left; font-size: 13px; font-weight: 740; }
.diagram-node-title { min-height: 31px; background: var(--surface-subtle); cursor: pointer; }
.diagram-node-title:focus-visible { outline-offset: -3px; }
.diagram-node-title > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diagram-node .icon { flex-shrink: 0; width: 15px; height: 15px; color: var(--accent-text); }
.diagram-canvas.is-free :is(.diagram-node, .diagram-section-file) > .diagram-node-title { cursor: grab; }
.diagram-viewport.is-dragging .diagram-node-title { cursor: grabbing; }
.diagram-resize { position: absolute; z-index: 3; right: 0; bottom: 0; display: grid; width: 24px; height: 24px; padding: 0; place-items: end; touch-action: none; border: 1px solid var(--accent-border); border-radius: 4px 0 0; background: var(--surface); color: var(--accent-text); opacity: 0; cursor: nwse-resize; }
.diagram-resize:focus-visible { outline-offset: -2px; }
.diagram-resize .icon { margin: 3px; }
:is(.diagram-node, .diagram-section-file, .diagram-section-frame):is(:hover, .is-selected, .is-editing) > .diagram-resize, .diagram-resize:focus-visible { opacity: 1; }
.diagram-text { min-width: 0; padding: 6px 8px; cursor: text; user-select: text; }
.diagram-text:focus-visible { outline-offset: -2px; }
.diagram-photo { display: grid; min-height: 0; flex: 1; grid-template: minmax(0, 1fr) / minmax(0, 1fr); padding: 4px; background: var(--surface-subtle); }
.diagram-photo img { display: block; width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.diagram-node-section, .diagram-section-frame { --section-line: color-mix(in srgb, var(--section-ink) 43%, var(--border)); border-color: var(--section-line); background: color-mix(in srgb, var(--section-ink) 7%, transparent); }
.diagram-node-section { overflow: visible; box-shadow: none; }
.diagram-node-section > .diagram-node-title, .diagram-section-frame > .diagram-node-title { background: color-mix(in srgb, var(--section-ink) 9%, var(--surface)); border-bottom-color: var(--section-line); border-radius: 4px 4px 0 0; }
.diagram-node-section > .diagram-node-title { z-index: 1; min-height: 0; height: var(--diagram-section-head); overflow: hidden; font-size: min(13px, calc(var(--diagram-section-head) * .72)); }
.diagram-node-section > .diagram-node-title .icon { width: min(15px, var(--diagram-section-head)); height: min(15px, var(--diagram-section-head)); }
.diagram-node-section > .diagram-node-title .icon, .diagram-section-frame .icon { color: color-mix(in srgb, var(--section-ink) 74%, var(--text)); }
.diagram-section-scene { position: absolute; inset: -1px auto auto -1px; }
.diagram-section-frame, .diagram-section-file { position: absolute; overflow: hidden; border-style: solid; border-width: 1px; border-radius: 4px; }
.diagram-section-frame > .diagram-node-title { min-height: 34px; }
.diagram-section-file { display: flex; z-index: 1; flex-direction: column; border-color: var(--border-strong); background: var(--surface); }
.diagram-section-file.is-selected { z-index: 2; }
.diagram-section-file.is-editing { z-index: 3; }
.diagram-section-file > .diagram-node-title { height: min(31px, 50%); min-height: 0; overflow: hidden; }
.diagram-connection-names { display: grid; position: absolute; inset: 70px 12px auto auto; z-index: 7; gap: 4px; width: max-content; max-width: min(420px, calc(100% - 24px)); max-height: min(23%, 190px); margin: 0; padding: 1px; overflow: auto; overscroll-behavior: contain; list-style: none; }
.diagram-connection-names li { display: flex; align-items: center; gap: 5px; min-width: 0; padding: 4px 7px; border: 1px solid var(--border); border-inline-start: 3px solid var(--connection-ink); border-radius: 4px; background: var(--surface); color: color-mix(in srgb, var(--connection-ink) 77%, var(--text)); font-size: 12px; }
.diagram-connection-names li > :is(strong, span:last-child) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diagram-connection-names li > span:last-child { color: var(--muted); }
.diagram-legend-line { width: 27px; height: 0; flex-shrink: 0; border-top: 3px solid currentColor; }
.diagram-empty { position: absolute; top: 50%; inset-inline: 20px; transform: translateY(-50%); color: var(--muted); text-align: center; pointer-events: none; }
.diagram-selection { display: flex; position: absolute; inset: auto 12px 12px; z-index: 8; align-items: center; gap: 5px; width: fit-content; max-width: calc(100% - 24px); padding: 4px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-card); }
.diagram-selection strong { overflow: hidden; margin-inline: 5px; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.diagram-selection button { flex-shrink: 0; }
.diagram-selection .icon-button { min-height: 35px; width: 35px; }

.diagram-checklist { min-width: 0; margin: 0; padding: 6px 10px 10px; border: 1px solid var(--border); border-radius: var(--radius); }
.diagram-checklist legend { padding-inline: 5px; font-size: 12px; font-weight: 700; }
.diagram-checklist-items { max-height: min(46dvh, 320px); overflow: auto; border-top: 1px solid var(--border); }
.diagram-checklist-items h3 { margin: 8px 0 3px; color: var(--muted); font-size: 11px; }
.diagram-check { display: flex; min-height: 36px; align-items: center; gap: 8px; margin-inline-start: calc(var(--depth, 0) * 10px); padding: 2px 5px; border-radius: 3px; font-size: 13px; overflow-wrap: anywhere; cursor: pointer; }
.diagram-check:hover, .diagram-check:focus-within { background: var(--surface-hover); }
.diagram-check input { flex-shrink: 0; width: 17px; height: 17px; accent-color: var(--accent); }
.diagram-check .icon { flex-shrink: 0; width: 15px; height: 15px; color: var(--muted); }
.diagram-check-all { font-weight: 700; }
.diagram-checklist .muted { font-size: 12px; }
.diagram-link-list { display: grid; gap: 5px; margin: 0 0 16px; padding: 0; list-style: none; }
.diagram-link-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; }
.diagram-link-row > div { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.diagram-link-row strong { display: block; font-size: 13px; }
.diagram-link-row small { color: var(--muted); }
.diagram-link-row button { flex-shrink: 0; }
.diagram-color-sample { display: inline-block; width: 10px; height: 10px; flex-shrink: 0; background: currentColor; border-radius: 2px; }
.diagram-link-form { padding-top: 12px; border-top: 1px solid var(--border); }
.diagram-link-form h3 { margin: 0 0 10px; font-size: 14px; }
.diagram-link-form .form-error { margin: 0 0 8px; }
.diagram-link-form .button + .button { margin-inline-start: 4px; }
.diagram-link-form .diagram-target-note { margin: -4px 0 10px; color: var(--muted); font-size: 12px; }
.diagram-custom-color:not([hidden]) { display: flex; gap: 8px; margin: 0 0 12px; }
.diagram-custom-color .field { margin: 0; }
.diagram-custom-color .field:last-child { width: min(180px, 100%); }
.diagram-custom-color input[type="color"] { min-width: 52px; width: 100%; cursor: pointer; }

@media (max-width: 760px), (max-width: 1024px) and (max-height: 600px) and (pointer: coarse) {
  .diagram-resize { --diagram-hit: clamp(27px, calc(36px / var(--diagram-zoom, 1)), 74px); width: var(--diagram-hit); height: var(--diagram-hit); pointer-events: none; }
  :is(.diagram-node, .diagram-section-file, .diagram-section-frame).is-selected > .diagram-resize { pointer-events: auto; }
  .diagram-resize .icon { width: 18px; height: 18px; }
  #diagram-menu { max-height: min(280px, max(94px, calc(var(--visible-height, 100dvh) - var(--safe-top) - 220px))); }
  #diagram-menu button { min-height: 44px; }
  .diagram-check { min-height: 42px; }
  .diagram-selection .button { min-height: 40px; }
  .diagram-selection .icon-button { min-height: 42px; width: 42px; }
  .diagram-selection { inset: auto max(10px, var(--safe-right)) 10px max(10px, var(--safe-left)); width: auto; max-width: none; }
  .diagram-selection strong { flex: 1; }
  .diagram-connection-names { inset: calc(68px + var(--safe-top)) max(10px, var(--safe-right)) auto max(10px, var(--safe-left)); max-width: calc(100% - max(10px, var(--safe-right)) - max(10px, var(--safe-left))); }
}
