/* =========================================================================
 * Use-template modal — shared by /stage, /templates, and /stage/:id.
 *
 * Visual contract:
 *   • All surfaces & text use theme-aware tokens from variables.css so the
 *     modal renders identically in light + dark modes.
 *   • Footer CTAs reuse the canonical `.di-btn` family (designIdentity.css)
 *     instead of declaring private button styles, keeping it on-identity.
 *
 * Visibility: driven by the `hidden` attribute. Explicit
 * `[hidden] { display: none }` overrides exist because the modal host
 * uses `display: flex` for centering, which would otherwise win.
 * ========================================================================= */
.stage-use-modal {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.stage-use-modal[hidden] { display: none; }

/* Solid scrim only — no backdrop-filter. Full-viewport blur was forcing
   per-frame re-rasterisation of the whole page on mobile. */
.stage-use-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

/* No box-shadow — scrim + hairline border carry the visual separation;
   large-radius shadows force per-frame rasterisation on mobile. */
.stage-use-modal-card {
    position: relative;
    width: min(420px, 100%);
    background: var(--global-card-background);
    color: var(--global-text-color);
    border: 1px solid rgba(var(--global-text-color-rgb), 0.08);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 48px);
    overflow: hidden;
}

.stage-use-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 12px;
}
.stage-use-modal-head h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--global-text-color);
}
.stage-use-modal-close {
    background: transparent;
    border: none;
    padding: 6px;
    cursor: pointer;
    color: var(--global-text-color);
    border-radius: 8px;
    line-height: 0;
    transition: background 140ms ease;
}
.stage-use-modal-close:hover { background: var(--state-hover-bg); }

.stage-use-modal-body {
    padding: 4px 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
}

.stage-use-modal-hint {
    margin: 0;
    font-size: 13px;
    color: rgba(var(--global-text-color-rgb), 0.6);
}

.stage-use-modal-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
}
.stage-use-modal-field span {
    font-weight: 500;
    color: rgba(var(--global-text-color-rgb), 0.6);
}
.stage-use-modal-field select {
    padding: 9px 12px;
    border: 1px solid rgba(var(--global-text-color-rgb), 0.14);
    border-radius: 10px;
    background: var(--global-card-background);
    color: var(--global-text-color);
    font: inherit;
    font-size: 13.5px;
    transition: border-color 140ms ease, box-shadow 140ms ease;
}
.stage-use-modal-field select:focus {
    outline: none;
    border-color: rgb(var(--brand-violet-rgb));
    box-shadow: 0 0 0 3px rgba(var(--brand-violet-rgb), 0.14);
}

.stage-use-modal-error {
    font-size: 13px;
    color: #d33;
}
.stage-use-modal-error[hidden] { display: none; }

.stage-use-modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px 18px;
    border-top: 1px solid var(--global-border-color);
}

body.stage-use-modal-open { overflow: hidden; }

/* Mobile / touch — modal is suppressed entirely. Two conditions: a
   width ≤768px (phones + small tablets including iPad portrait) OR a
   primary input that's coarse with no hover (any touch device). Either
   alone misses cases — width misses large phones in landscape, touch
   misses certain Chromebooks. Together they catch every "mobile" user.
   `body.stage-use-modal-open` is neutralised in case JS opens the modal
   anyway (it stays display:none but doesn't scroll-lock the page). */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
    .stage-use-modal,
    .stage-use-modal[hidden] {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
    body.stage-use-modal-open { overflow: visible !important; }
}
