/* stage.css — WYSIWYG stage chrome. The edited real document lives in
 * #stage-frame (an <iframe> isolated by ForgeUI-Core). #stage-canvas carries
 * the zoom/pan transform + device-frame size. Adorners are drawn HERE, on top
 * of the iframe, so they never perturb the edited document's layout.
 */

.stage {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--bg-2);
}

.stage-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    height: 30px;
    padding: 0 10px;
    background: var(--bg-1);
    border-bottom: 1px solid rgba(65, 71, 85, 0.28);
    flex: 0 0 auto;
}
.stage-toolbar .spacer { flex: 1 1 auto; }

/* Slice 4 — the .stage-mode segment is no longer emitted by index.html: the
 * single header Run toggle (.run-toggle) owns edit ⇄ run. The rules below are
 * kept ONLY because a detached/floated stage clone or an older bundled shell
 * can still carry the markup; nothing in the shipped shell matches them. */
.stage-mode {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    height: 28px;
    padding: 2px;
    border: 1px solid rgba(65, 71, 85, 0.45);
    border-radius: 6px;
    background: var(--bg-3);
}
.stage-mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 22px;
    padding: 0 8px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-2);
    font: inherit;
    font-size: 11px;
    cursor: pointer;
}
.stage-mode-btn:hover { color: var(--text-0); }
.stage-mode-btn.active {
    background: rgba(33, 147, 251, 0.18);
    color: var(--primary);
}
.stage-mode-btn .ms-icon { font-size: 15px; }
.stage-tool-state {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 24px;
    padding: 0 8px;
    border: 1px solid rgba(120, 224, 168, 0.34);
    border-radius: 4px;
    background: rgba(120, 224, 168, 0.07);
    color: var(--text-1);
    font-size: 10px;
    font-weight: 700;
    white-space: nowrap;
}
.stage-tool-state .ms-icon {
    flex: 0 0 auto;
    color: var(--success);
    font-size: 14px;
}
.stage-move-mode {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 24px;
    min-width: 0;
    max-width: 128px;
    padding: 0 5px 0 7px;
    border: 1px solid var(--line-2);
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text-2);
    white-space: nowrap;
}
.stage-move-mode .ms-icon {
    flex: 0 0 auto;
    color: var(--text-3);
    font-size: 14px;
}
.stage-move-mode select {
    min-width: 0;
    width: 92px;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text-1);
    font: inherit;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
}
.stage-selection {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    min-width: 0;
    flex: 0 1 300px;
    max-width: 300px;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
    white-space: nowrap;
    color: var(--text-2);
    font-size: 11px;
    line-height: 1;
}
.stage-selection .crumb-seg {
    display: inline-flex;
    align-items: center;
    flex: 0 1 auto;
    min-height: 22px;
    background: none;
    border: 0;
    /* 22px minimum hit target (smoke clickability audit) while keeping the
       strip visually compact. Natural inline flow — no negative margins or
       flex, which made sibling crumbs intersect each other. */
    padding: 5px 3px;
    margin: 0;
    vertical-align: middle;
    color: var(--accent, #4f8cff);
    font: inherit;
    cursor: pointer;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.stage-selection .crumb-seg:hover { text-decoration: underline; }
.stage-selection .crumb-seg.current { color: var(--text-1); font-weight: 600; cursor: default; }
.stage-selection .crumb-sep {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    height: 22px;
    color: var(--text-3, var(--text-2));
    padding: 0 2px;
}
.stage-selection-actions {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-left: 4px;
    flex: 0 0 auto;
    min-width: 0;
}
.selection-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    height: 22px;
    width: 24px;
    min-width: 24px;
    padding: 0;
    border: 1px solid rgba(65, 71, 85, 0.38);
    border-radius: 4px;
    background: var(--bg-3);
    color: var(--text-1);
    font: inherit;
    font-size: 10px;
    cursor: pointer;
}
.selection-action-btn:hover:not(:disabled) {
    border-color: rgba(33, 147, 251, 0.55);
    color: var(--text-0);
}
.selection-action-btn:disabled {
    opacity: 0.42;
    cursor: default;
}
.selection-action-btn.danger:hover:not(:disabled) {
    border-color: rgba(244, 91, 105, 0.7);
    color: var(--danger);
}
.selection-action-btn .ms-icon { font-size: 14px; }
.selection-action-btn span:not(.ms-icon) { display: none; }
/* Align & Distribute cluster (Batch 2, multi-select) and Arrange/z-order
 * cluster (Batch 3b, single-select) — divided sub-groups of the strip. */
.selection-align-group,
.selection-arrange-group {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-left: 4px;
    padding-left: 4px;
    border-left: 1px solid rgba(65, 71, 85, 0.38);
}

.stage-selection-metrics {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    height: 22px;
    max-width: 150px;
    padding: 0 7px;
    border: 1px solid rgba(65, 71, 85, 0.38);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.025);
    color: var(--text-2);
    font: 10px/1.2 ui-monospace, "Cascadia Code", Consolas, monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stage-viewport {
    position: relative;
    flex: 1 1 auto;
    overflow: hidden;
    background:
        linear-gradient(45deg, rgba(255,255,255,0.012) 25%, transparent 25%) 0 0/24px 24px,
        linear-gradient(-45deg, rgba(255,255,255,0.012) 25%, transparent 25%) 0 0/24px 24px,
        var(--bg-0);
}

.stage-canvas {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    background: #000;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

#stage-frame {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: #000;
    pointer-events: none;
}

.stage-viewport.preview #stage-frame {
    pointer-events: auto;
}

/* Overlay layer holding selection/hover adorners — pointer-events pass through
 * except on grab handles. */
.stage-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

/* Ruler gutters (Batch 3c) — static background bands along the top/left edge,
 * shown only when #stage-viewport has .rulers-on. The graduated ticks/labels
 * are pooled divs in #stage-overlay (which paints on top of these bands).
 * pointer-events:none so stage input passes through. */
.stage-ruler-top, .stage-ruler-left, .stage-ruler-corner {
    position: absolute;
    display: none;
    pointer-events: none;
    background: var(--bg-1, #14181f);
    z-index: 1;
}
.stage-ruler-top { top: 0; left: 0; right: 0; height: 18px; border-bottom: 1px solid var(--line-2, #2a2f3a); }
.stage-ruler-left { top: 0; left: 0; bottom: 0; width: 18px; border-right: 1px solid var(--line-2, #2a2f3a); }
.stage-ruler-corner { top: 0; left: 0; width: 18px; height: 18px; border-right: 1px solid var(--line-2, #2a2f3a); border-bottom: 1px solid var(--line-2, #2a2f3a); z-index: 2; }
.stage-viewport.rulers-on .stage-ruler-top,
.stage-viewport.rulers-on .stage-ruler-left,
.stage-viewport.rulers-on .stage-ruler-corner { display: block; }
/* Preview is a faithful WYSIWYG view — hide the gutter bands (the ticks
 * already self-hide via drawRulers' App.preview guard). */
.stage-viewport.preview .stage-ruler-top,
.stage-viewport.preview .stage-ruler-left,
.stage-viewport.preview .stage-ruler-corner { display: none; }
.adorner-rulertick {
    position: absolute;
    background: var(--text-3, #6b7280);
    pointer-events: none;
    z-index: 3;
}
.adorner-rulerlabel {
    position: absolute;
    font: 8px/1 ui-monospace, monospace;
    color: var(--text-2, #9aa4b2);
    pointer-events: none;
    white-space: nowrap;
    z-index: 3;
}

.adorner-box {
    position: absolute;
    border: 1px solid var(--primary-strong);
    box-shadow: 0 0 0 1px rgba(33, 147, 251, 0.25);
}
.adorner-box.hover {
    border-color: var(--primary);
    border-style: dashed;
}

/* Box-model overlay (P4/A10) — 4 nested translucent bands shown on
   hover; stacked outer→inner so each shows only its own band. */
.adorner-band {
    position: absolute;
    pointer-events: none;
}
.adorner-band.band-margin  { background: rgba(246, 178, 107, 0.30); }
.adorner-band.band-border  { background: rgba(255, 221, 128, 0.34); }
.adorner-band.band-padding { background: rgba(147, 196, 125, 0.32); }
.adorner-band.band-content { background: rgba(111, 168, 220, 0.34); }

/* Flex gap overlay (P4/A11) — the spacing between flex items, shown on
   hover of a flex container. */
.adorner-flexgap {
    position: absolute;
    pointer-events: none;
    background: rgba(190, 120, 224, 0.42);
}

/* Grid overlay (P4/A12) — track lines + cell-number labels, shown on
   hover of a grid container. A track line carries a near-zero inline
   width/height; the min-* floor keeps it visible at 1px. */
.adorner-gridline {
    position: absolute;
    pointer-events: none;
    background: rgba(120, 196, 224, 0.6);
    min-width: 1px;
    min-height: 1px;
}
.adorner-gridcell {
    position: absolute;
    pointer-events: none;
    margin: 2px 0 0 2px;
    padding: 0 3px;
    font-size: 9px;
    font-weight: 700;
    line-height: 13px;
    color: #06223c;
    background: rgba(120, 196, 224, 0.85);
    border-radius: 2px;
}

/* Focus-nav graph overlay (P5/A14) — the gamepad/keyboard focus order
   on the canvas: a numbered badge per focusable + a centre→centre arrow
   between consecutive entries. The edge div is rotated about its left
   edge; the ::after is its arrowhead. The wrap edge (last→first) is
   dashed. */
.adorner-focusedge {
    position: absolute;
    height: 2px;
    transform-origin: 0 50%;
    background: rgba(120, 224, 168, 0.85);
    pointer-events: none;
}
.adorner-focusedge::after {
    content: "";
    position: absolute;
    right: -1px;
    top: 50%;
    margin-top: -4px;
    width: 0;
    height: 0;
    border-left: 7px solid rgba(120, 224, 168, 0.95);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
}
.adorner-focusedge.wrap {
    background: repeating-linear-gradient(90deg,
        rgba(120, 224, 168, 0.85) 0 6px, transparent 6px 12px);
}
.adorner-focusnode {
    position: absolute;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    box-sizing: border-box;
    font-size: 9px;
    font-weight: 700;
    line-height: 14px;
    text-align: center;
    color: #06280f;
    background: rgba(120, 224, 168, 0.95);
    border-radius: 7px;
    pointer-events: none;
}

.adorner-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    margin: -6px 0 0 -6px;
    background: var(--bg-0);
    border: 1px solid var(--primary-strong);
    border-radius: 2px;
    box-shadow: 0 0 0 2px rgba(33, 147, 251, 0.16);
    pointer-events: auto;
}

.adorner-tag {
    position: absolute;
    transform: translateY(-100%);
    padding: 1px 6px;
    font-size: 10px;
    font-weight: 700;
    background: var(--primary-strong);
    color: #06223c;
    white-space: nowrap;
    border-radius: 3px 3px 0 0;
}
.adorner-hover-tag {
    position: absolute;
    transform: translateY(-100%);
    padding: 1px 6px;
    font-size: 10px;
    font-weight: 700;
    background: rgba(16, 20, 28, 0.92);
    color: var(--text-0);
    border: 1px solid rgba(33, 147, 251, 0.55);
    white-space: nowrap;
    border-radius: 3px 3px 0 0;
    pointer-events: none;
}

.adorner-toolbar {
    position: absolute;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    height: 28px;
    padding: 2px;
    border: 1px solid rgba(33, 147, 251, 0.45);
    border-radius: 4px;
    background: rgba(16, 20, 28, 0.95);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
    pointer-events: auto;
}
.adorner-tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 3px;
    background: transparent;
    color: var(--text-1);
    cursor: pointer;
}
.adorner-tool:hover {
    background: rgba(33, 147, 251, 0.18);
    color: var(--text-0);
}
.adorner-tool.active,
.adorner-tool[aria-pressed="true"] {
    color: var(--text-0);
    background: rgba(33, 147, 251, 0.24);
    box-shadow: inset 0 0 0 1px rgba(33, 147, 251, 0.72);
}
.adorner-tool .ms-icon { font-size: 15px; }
.adorner-tool-labeled {
    width: auto;
    min-width: 28px;
    padding: 0 6px;
    gap: 4px;
}
.adorner-tool-label {
    font-size: 10px;
    font-weight: 650;
    line-height: 1;
    white-space: nowrap;
}
.adorner-tool-drag { cursor: move; }

/* Snap alignment guides drawn during a resize drag (screen-space, on top
 * of the iframe; never perturb the edited layout). */
.adorner-guide {
    position: absolute;
    background: var(--danger);
    opacity: 0.9;
    pointer-events: none;
}

/* Distance/measurement pills (Batch 2) — the px gap to the nearest neighbor,
 * centered on the gap midpoint while dragging. */
.adorner-guide-label {
    position: absolute;
    pointer-events: none;
    padding: 0 4px;
    font-size: 9px;
    font-weight: 700;
    line-height: 14px;
    color: #fff;
    background: var(--danger);
    border-radius: 2px;
    transform: translate(-50%, -50%);
    white-space: nowrap;
    z-index: 4;
}

/* Anchor pins (P3) — a dot centered on each edge the selected element is
 * pinned to, so the active anchor (left/right + top/bottom) is visible. */
.adorner-pin {
    position: absolute;
    width: 7px;
    height: 7px;
    margin: -4px 0 0 -4px;
    border: 1px solid #fff;
    border-radius: 50%;
    background: var(--accent, #2f6fed);
    pointer-events: none;
    z-index: 4;
}

/* Stretch bars (Batch 3) — a thin connector between the two edge pins when an
 * axis is stretched (both edges held); sits below the dots (z-index 3) so the
 * round end pins cap it. Self-centers on the edge midline via margin. */
.adorner-stretch {
    position: absolute;
    pointer-events: none;
    background: var(--accent, #2f6fed);
    border-radius: 1px;
    z-index: 3;
}
.adorner-stretch.h { height: 3px; margin: -1.5px 0 0 0; }
.adorner-stretch.v { width: 3px; margin: 0 0 0 -1.5px; }

/* Inline text editor (double-click a text leaf). Interactive over the
 * pointer-events:none overlay; never perturbs the edited layout. */
.adorner-edit {
    position: absolute;
    pointer-events: auto;
    z-index: 5;
    margin: 0;
    padding: 0 1px;
    box-sizing: border-box;
    border: 1px solid var(--primary-strong);
    border-radius: 2px;
    background: transparent;
    color: var(--text-0);
    font: 13px/1.3 Inter, sans-serif;
    resize: none;
    overflow: auto;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

/* Rubber-band marquee (drag on empty stage) + the additive multi-select
 * outlines. Screen-space, on top of the iframe; never perturb layout. */
.marquee {
    position: absolute;
    border: 1px solid var(--primary);
    background: rgba(33, 147, 251, 0.12);
    pointer-events: none;
}
.multi-outline {
    position: absolute;
    border: 1px dashed var(--primary);
    pointer-events: none;
}
.multi-bounds {
    position: absolute;
    border: 1px solid rgba(120, 224, 168, 0.85);
    background: rgba(120, 224, 168, 0.04);
    box-shadow: 0 0 0 1px rgba(120, 224, 168, 0.16);
    pointer-events: none;
}

/* Pinegrow-style drag-drop insertion line / container highlight */
.drop-line {
    position: absolute;
    background: var(--tertiary);
    box-shadow: 0 0 6px rgba(239, 103, 25, 0.7);
    pointer-events: none;
}
.drop-line.horizontal { height: 2px; }
.drop-line.vertical { width: 2px; }
.drop-container {
    position: absolute;
    border: 2px solid var(--tertiary);
    background: rgba(239, 103, 25, 0.08);
    pointer-events: none;
}

/* Safe-area / device-frame guides (Phase 3 uses these; harmless when unset) */
.safe-area-guide {
    position: absolute;
    border: 1px dashed rgba(255, 255, 255, 0.25);
    pointer-events: none;
}
