/* css/features/debug-view.css: the normals debug view (docs/improvements/01-normals.md 3.1-3.5, 5.1; 01 F1-2).
   Linked in the css/features/* block of 07 C52's link order (after 11-export.css, before 12-responsive.css); it
   carries its own @media rules. Colours only through the role tokens of 02-tokens.css (spec 06 R-B1, 5.12 rule 4;
   06 T4a migrated this file from the legacy tokens); the legend swatches read --swatch, which DebugViewControls sets
   from theme.scene.debug.
   .view-btn.active is the .view-btn.active half of B-L24 (this file is its one named owner, 07 C52): #toggle-grid
   has toggled the class since the original page, but no rule styled it. 06 T4a maps it to role tokens (06 3.5: a
   strong border and a primary icon on the overlay chip) and landed the badge-overlap half in
   css/09-viewport-tools.css. */

/* ---- toolbar column ------------------------------------------------------------------------------ */

.view-btn.active {
    border-color: var(--color-border-strong);
    color: var(--color-text-primary);
}

/* 1 px line with 4 px margins: 9 px in the column (3.1 fit check). */
.view-divider {
    width: 100%;
    height: 1px;
    flex-shrink: 0;
    background: var(--color-border-strong);
    margin: 4px 0;
}

/* ---- popover (a direct child of .viewport-overlay; DebugViewControls sets its top) ------------- */

.debug-popover {
    position: absolute;
    top: 20px;
    right: 72px;
    width: 264px;
    max-height: calc(100% - 40px);
    overflow-y: auto;
    box-sizing: border-box;
    padding: 12px;
    background: var(--color-surface-1);
    border: 1px solid var(--color-border-subtle);
    border-radius: 8px;
    box-shadow: var(--shadow-overlay);
    color: var(--color-text-primary);
    font-size: 12px;
    pointer-events: all;
    z-index: 110;
}

.debug-popover[hidden],
.debug-legend[hidden],
.debug-legend-row[hidden] {
    display: none;
}

.debug-popover:focus {
    outline: none;
}

.debug-popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 24px;
    margin-bottom: 8px;
}

.debug-popover-title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-primary);
}

.debug-popover-close {
    width: 24px;
    height: 24px;
    padding: 0;
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--color-text-secondary);
    font: inherit;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.debug-popover-close:hover {
    border-color: var(--color-text-secondary);
    color: var(--color-text-primary);
}

.debug-popover-group {
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
}

.debug-popover-group + .debug-popover-group {
    margin-top: 8px;
}

.debug-popover-label {
    padding: 0;
    height: 20px;
    line-height: 20px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

.debug-popover-option {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 24px;
    cursor: pointer;
}

.debug-popover-option input,
.debug-popover-range input {
    margin: 0;
    accent-color: var(--color-accent);
    cursor: pointer;
}

.debug-popover-range {
    display: grid;
    grid-template-columns: auto auto 1fr;
    align-items: center;
    gap: 8px;
    min-height: 36px;
}

.debug-popover-range-value {
    min-width: 36px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--color-text-primary);
}

.debug-popover-range input {
    width: 100%;
}

/* Two lines are reserved (3.1: "stats up to 2 lines 32"), so the popover keeps its height (and an upward-opened
   popover keeps its bottom edge at the button) when the stats text appears, wraps or empties. */
.debug-normals-stats {
    min-height: 32px;
    margin: 8px 0 0;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 16px;
    color: var(--color-text-secondary);
}

.debug-normals-stats.warning {
    color: var(--color-warning);
}

/* ---- top-centre stack and legend (07 C51) --------------------------------------------------------- */

/* Holds, in order, 07's restore banner, 09's share banner and the debug legend; below the pilot banner while it shows
   (the DOM order #pilot-info, [.brand-watermark,] #viewport-top-stack makes the sibling selector work). */
#viewport-top-stack {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100% - 320px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.pilot-info.visible ~ #viewport-top-stack {
    top: 72px;
}

/* The legend takes pointer events (the overlay and the stack do not), so its title, the gl_FrontFacing caveat of
   01 11.1, shows on hover; a drag that starts on the chip does not orbit. */
.debug-legend {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px 12px;
    background: var(--color-surface-1);
    border: 1px solid var(--color-border-subtle);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--color-text-secondary);
    pointer-events: auto;
    cursor: help;
}

.debug-legend-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 12px;
    row-gap: 2px;
}

.debug-legend-name {
    color: var(--color-text-primary);
    font-weight: 600;
}

.debug-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.debug-legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    background: var(--swatch, var(--color-text-disabled));
}

/* The notes carry information (3.3: wireframe, camera preview), so they keep the secondary text colour
   (--color-text-secondary, 7.49:1 on --color-surface-1; the disabled text colour would fall below WCAG AA for 11 px
   text) and are set apart by italics. */
.debug-legend-note {
    font-style: italic;
}

/* ---- announcer ------------------------------------------------------------------------------------ */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---- column overflow fallback (3.1) --------------------------------------------------------------- */

/* Only where the column no longer fits the overlay: an overlay below 385 px (innerHeight - 60 in the wide layout,
   innerHeight - 410 in the <= 900 px layout). The 4 px padding keeps focus rings inside the scroll box. Spec 04's
   button raises both thresholds by 48 px (01 CR-7). Above them no rule applies. */
@media (max-height: 444px), (max-width: 900px) and (max-height: 794px) {
    .viewport-controls {
        max-height: calc(100% - 40px);
        overflow-y: auto;
        padding: 4px;
        margin: -4px;
    }

    .viewport-controls > * {
        flex-shrink: 0;
    }
}
