﻿.viewer3d {
    position: absolute;
    width: 100%;
    height: 100%;
}

/* Babylon makes the canvas focusable for keyboard/pointer input; suppress the browser's
   default focus ring so it doesn't read as a stray border around the viewport. */
canvas.viewer3d:focus {
    outline: none;
}

/* 3D load progress. Created by viewer3d.loading.js and hung off body. Centred on the viewport rather
   than measured against a layout element - the two layouts sit at different offsets, and anything
   measured is something that can be measured wrong. Above svg3d's radial menu overlay, which is 1001. */
#viewer3dloading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    z-index: 1100;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}

/* No opacity transition while active, so a load starting mid-fade-out appears at once. */
#viewer3dloading.viewer3d-loading-active {
    opacity: 1;
    transition: none;
}

#viewer3dloading > div {
    position: absolute;
    inset: 0;
    border-radius: 50%;
}

.viewer3d-loading-track {
    border: 4px solid var(--mud-palette-primary);
    opacity: 0.2;
}

/* The progress arc: a conic sweep clipped to a ring by the mask. --p is set from JS. */
.viewer3d-loading-fill {
    background: conic-gradient(var(--mud-palette-primary) calc(var(--p, 0) * 1turn), transparent 0);
    mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 4px));
    transition: --p 0.18s ease-out;
}

/* Transform-only, so it keeps spinning on the compositor while the synchronous mesh factory blocks
   the main thread - the conic arc above cannot update at all in that window. */
.viewer3d-loading-sheen {
    border: 4px solid transparent;
    border-top-color: var(--mud-palette-primary);
    opacity: 0.65;
}

#viewer3dloading.viewer3d-loading-active .viewer3d-loading-sheen {
    animation: viewer3d-loading-spin 0.9s linear infinite;
}

@keyframes viewer3d-loading-spin {
    to {
        transform: rotate(1turn);
    }
}

@property --p {
    syntax: '<number>';
    inherits: false;
    initial-value: 0;
}

.viewer2d {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    user-select : none;
}

/* Starts whenever Viewer2D flips the svg to visible, so a page open or refit fades in with no interop round trip.
   A zone-transition Web Animation overrides it while one runs. */
@media (prefers-reduced-motion: no-preference) {
    .viewer2d > svg[style*="visibility: visible"] {
        animation: view2d-reveal 240ms cubic-bezier(0.3, 0, 0.2, 1);
    }
}

@keyframes view2d-reveal {
    from { opacity: 0; }
}

/* viewTransition2d.js. Holds the new drawing hidden until its Web Animation takes over. */
.viewer2d.zone-transition {
    overflow: hidden;
}

.viewer2d.zone-transition > svg {
    transform-origin: 0 0;
    opacity: 0;
}

.zone-transition-overlay {
    position: absolute;
    inset: 0;
    transform-origin: 0 0;
    pointer-events: none;
}

.viewer2d svg {
    touch-action: none;
}

.bom-view-settings {
    display: block;
    align-items: center;
    position: absolute;
    left: 1rem;
    top: 1rem;
    z-index: 2;
}

.view-settings {
    display: block;
    align-items: center;
    position: absolute;
    left: 1rem;
    bottom: 1rem;
    z-index: 2;
}

/* 2D view mode indicator (js/Shared/statusPanel.js). Matches the split-button-card look:
   white fill, crisp grey border, no shadow. */
.view-status-panel {
    position: absolute;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    padding: 0.375rem 0.75rem;
    background: #fff;
    border: 1px solid #A9A9A9;
    border-radius: 6px;
    font-size: 0.8125rem;
    line-height: 1.25rem;
    color: #424242;
    white-space: nowrap;
    /* Status only - every click belongs to the canvas underneath. */
    pointer-events: none;
    user-select: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

/* The panel stays in the DOM once created; this class is what makes it visible. */
.view-status-panel-visible {
    opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
    .view-status-panel {
        transition: none;
    }
}

/* The selected-tool marker from .toolbar-btn-selected (customStyles.css), on the panel's bottom
   edge - same red bar, same 18% inset, so an active mode reads the same wherever it's shown. */
.view-status-panel::before {
    content: "";
    position: absolute;
    border-radius: 1px;
    background-color: var(--mud-palette-error, rgb(225, 9, 21));
    left: 18%;
    right: 18%;
    bottom: 0;
    height: 2px;
}

.context-dim {
    display: block;
    align-items: center;
    position: absolute;
    top: 3.5rem; /* clears .view-status-panel above it */
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
}

/* Elevation comp resize grippers (CompGripper.razor + elevation2d.compResize.js).
   Visibility lives here, not in inline styles, because BOTH sides need a say: C# owns the
   selected state (data-selected) and JS owns the hover reveal. Sharing one style attribute meant
   whichever wrote last won permanently - Blazor only rewrites an attribute when its own computed
   value changes, so it could never repair a JS write. Two orthogonal channels instead: an
   attribute C# renders, and classes JS toggles. Ordered by ascending specificity. */
.comp-gripper-group .gripper {
    visibility: hidden;
}

/* A selected comp always shows all four handles. */
.comp-gripper-group[data-selected="true"] .gripper {
    visibility: visible;
}

/* Hover reveal: JS adds this to the single handle the pointer is near. */
.comp-gripper-group .gripper.gripper-revealed {
    visibility: visible;
}

/* During a resize drag only the dragged handle shows, even on a selected comp. Keyed off <body> so
   the marker never lands on a Blazor-managed node, and so a missed cleanup is repaired centrally
   (see the self-heal in _onGripperHoverMove) rather than leaving handles stuck hidden. */
body.comp-resizing .comp-gripper-group .gripper {
    visibility: hidden;
}

body.comp-resizing .comp-gripper-group .gripper.gripper-dragging {
    visibility: visible;
}

/* Text note resize handles (TextNoteComponent.razor + textNoteEditing.js), on the same two channels as the
   comp grippers above. Last: a note hidden for its resize drag hides its parts, which would otherwise win. */
.text-note-handle {
    visibility: hidden;
}

.text-note[data-selected="true"] .text-note-handle,
.text-note-handle.text-note-handle-revealed {
    visibility: visible;
}

/* A note's layer name: shown with its hover box (whose visibility textNoteEditing.js sets) or while it's selected.
   A revealed handle keeps both up: the pointer on a handle has left the note's hover target. */
.text-note-layer-label {
    visibility: hidden;
}

.text-note:has(.text-note-handle-revealed) .text-note-box,
.text-note:has(.text-note-handle-revealed) .text-note-layer-label,
.text-note[data-selected="true"] .text-note-layer-label,
.text-note-box[visibility="visible"] ~ .text-note-layer-label {
    visibility: visible;
}

.text-note[visibility="hidden"] .text-note-handle,
.text-note[visibility="hidden"] .text-note-box,
.text-note[visibility="hidden"] .text-note-layer-label {
    visibility: hidden;
}

/* The comp a placement preview is hovering over, i.e. the one a click would replace. */
.comp-replace-target {
    filter: grayscale(1);
    opacity: 0.35;
}

/* ---- Printing a 2D view (Ctrl+P on a Plan/Elevation page) ----
   printView.js clones the drawing SVG into #print-root on beforeprint, already stripped of what
   shouldn't print and with a viewBox cropped to the drawing (see the reasoning there). All this has
   to do is get the app out of the way: display:none on every other child of <body> is what keeps it
   to one sheet, since the app's layout is full-viewport and merely hiding it - visibility, opacity -
   still paginates a second empty page. */
#print-root {
    display: none;
}

@media print {
    html, body {
        height: 100%;
        margin: 0;
        overflow: hidden;
        background: #fff;
    }

    body > *:not(#print-root) {
        display: none !important;
    }

    /* Sized to the page area in both axes so preserveAspectRatio="xMidYMid meet" (printView.js) fits
       whichever edge is reached first; fitting width alone spilled a squarish drawing onto page 2. */
    #print-root {
        display: block;
        width: 100%;
        height: 100%;
        break-inside: avoid;
    }

    #print-root > svg {
        display: block;
        width: 100%;
        height: 100%;
    }

    @page {
        margin: 10mm;
    }
}
