.dicom-viewport {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.dicom-viewport-canvas {
    /* Positioning context for the loading overlay below. */
    position: relative;
    width: 100%;
    /* A HEIGHT, NOT AN ASPECT RATIO. `aspect-ratio: 1/1` plus `max-height` fight each other: on a
       wide monitor max-height wins, the box is short and non-square, and Cornerstone letterboxes
       inside it — the exact outcome an aspect ratio was meant to avoid. A viewport height that tracks
       the window lets Cornerstone fit the image itself, which it already does correctly. */
    height: min(70vh, 720px);
    min-height: 320px;
    background: #000;
    border: 1px solid var(--line);
    /* Cornerstone attaches its own canvas as a child and sizes it from getBoundingClientRect at
       FIRST creation only, reusing that canvas forever after. The component therefore defers
       enableElement until this element has a non-zero size — see its mount effect. */
    overflow: hidden;
}

.dicom-viewport-canvas:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Overlay, not a sibling block: a spinner below the canvas adds a 320px band that collapses when
   loading finishes, snapping the toolbar up the page. */
.dicom-viewport-overlay {
    position: absolute;
    inset: 0;
    /* LOAD-BEARING. enableElement appends its own div.viewport-element (inline position:relative)
       and immediately fills its canvas with OPAQUE BLACK. On first mount the spinner is already a
       child, so it comes first in tree order and — with both at z-index auto — the black canvas
       paints on top of it. The spinner would flash, then vanish behind a black box for the whole
       frame fetch. It only looked correct on the second study, where React re-inserts the overlay
       after the canvas. */
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    color: var(--primary-foreground);
    text-align: center;
    padding: 16px;
}

.dicom-viewport-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.dicom-viewport-slice {
    /* inline-block so min-width applies — __experimentalText renders a span, and min-width is inert
       on a non-replaced inline element, letting the hint text reflow as the counter grows. */
    display: inline-block;
    font-variant-numeric: tabular-nums;
    min-width: 9ch;
}

.dicom-viewport-hint {
    color: var(--ink-muted);
    font-size: 12px;
}

.dicom-viewport-autosave-status {
    display: inline-block;
    font-size: 12px;
    min-width: 7ch;
}

.dicom-viewport-autosave-status-saving {
    color: var(--ink-muted);
}

.dicom-viewport-autosave-status-error {
    color: var(--danger);
}

/* imaging.html's viewer: the image with its bar and controls, the measurements beside it. Layout only:
   the film ground is the canvas's own black, and the tools stay on the page's light tokens. */
.dicom-viewport-stage {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.dicom-viewport-side {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

/* Side by side only where the column is wide enough for both; a phone stacks them. */
@container imaging-study (min-width: 680px) {
    .dicom-viewport--with-side {
        display: grid;
        grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr);
        align-items: start;
        gap: 16px;
    }

    .dicom-viewport--with-side .dicom-viewport-canvas {
        height: min(62vh, 600px);
    }
}

.dicom-viewport-bar {
    display: flex;
    align-items: baseline;
    gap: 10px;
    font-size: 12px;
    color: var(--ink);
}

.dicom-viewport-ref {
    margin-left: auto;
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-muted);
}
