/* Screenshot editor — chrome for the product feedback form's "Add
 * screenshot" control (screenshot.js), shipped by laravel-support and loaded
 * by the top-nav feedback button for the viewers who are shown it. Those
 * viewers need not hold `ui::use-admin-bar`, so the bar's :root variables are
 * usually absent and the fallbacks below are what most people see; an admin
 * who also has the bar gets the bar's palette.
 *
 * ── Stacking ───────────────────────────────────────────────────────────────
 * The editor is a native <dialog> opened with showModal(), so it renders in
 * the browser top layer — above the admin bar (9000), the AI FAB/panel
 * (10000/10001) and the drawer stack (10050+) with NO z-index declared
 * anywhere in this file. Do not add one; the top layer is the mechanism. */

/* ── Capture and support ─────────────────────────────────────────────── */

/* While a capture is being taken the form drawer is hidden — backdrop and
 * panel together — so the image shows the page the feedback is about rather
 * than the form covering it. visibility rather than display keeps everything
 * the user has typed in place for when it comes back.
 *
 * Transitions are switched off for the same moment: a control whose
 * `transition` covers visibility (the drawer's buttons do) stays painted for
 * the length of it, and a capture accepted without a picker lands inside that
 * window — the form's buttons appeared in the shot while the rest of the
 * drawer did not. */
html.ui-screenshot-capturing .ui-drawer,
html.ui-screenshot-capturing .ui-drawer * {
    visibility: hidden !important;
    transition: none !important;
}

/* No getDisplayMedia (insecure origin, most mobile browsers): no trigger. A
 * class on <html> rather than a sweep on load, because the trigger arrives
 * in a drawer fetched later. */
html.ui-screenshot-unsupported [data-screenshot-trigger] {
    display: none !important;
}

.ui-screenshot {
    padding: 0;
    border: 0;
    border-radius: 10px;
    width: min(96vw, 1280px);
    max-height: 92vh;
    overflow: hidden;
    background: var(--ui-admin-bar-bg, #1f2937);
    color: var(--ui-admin-bar-fg, #e5e7eb);
    font-family: inherit;
    font-size: 12.5px;
    line-height: 1.2;
}

/* Only when open: an unconditional display would defeat the closed state. */
.ui-screenshot[open] {
    display: flex;
    flex-direction: column;
}

.ui-screenshot::backdrop {
    background: rgba(3, 7, 18, 0.72);
}

/* ── Toolbar ───────────────────────────────────────────────────────────── */

.ui-screenshot__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--ui-admin-bar-border, rgba(255, 255, 255, 0.1));
    flex: none;
}

.ui-screenshot__group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ui-screenshot__actions {
    margin-left: auto;
}

/* The `!important` mirrors the bar's own defence: styles.css pins a brand
 * radius on every <button> with !important, which would turn these into
 * floating lozenges on pill-button brands. */
.ui-screenshot__tool,
.ui-screenshot__button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: transparent;
    border: 0;
    border-radius: 4px !important;
    color: var(--ui-admin-bar-fg, #e5e7eb);
    font-family: inherit;
    font-size: inherit;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.ui-screenshot__button {
    border: 1px solid var(--ui-admin-bar-border, rgba(255, 255, 255, 0.1));
}

.ui-screenshot__tool:hover,
.ui-screenshot__button:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* "Raise product feedback" deliberately has NO styling of its own. It is one
 * of the action buttons and sits in their row, so it takes their treatment —
 * an accent fill made it read as a different kind of control, and pinned it to
 * a brand colour that goes almost black on some brands. */

.ui-screenshot__tool:focus-visible,
.ui-screenshot__button:focus-visible,
.ui-screenshot__swatch:focus-visible {
    outline: 2px solid var(--brand-primary-colour, #6366f1);
    outline-offset: -2px;
}

/* Selected tool/mode — the bar's inverted light-chip treatment, which stays
 * legible regardless of how dark the brand colour runs. */
.ui-screenshot__tool[aria-pressed="true"] {
    background: #f9fafb;
    color: #111827;
    box-shadow: inset 0 2px 0 var(--brand-primary-colour, #6366f1);
}

.ui-screenshot__tool[aria-pressed="true"]:hover {
    background: #fff;
}

/* ── Colour swatches & stroke width ────────────────────────────────────── */

.ui-screenshot__swatch {
    width: 18px;
    height: 18px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 50% !important;
    cursor: pointer;
}

.ui-screenshot__swatch[aria-pressed="true"] {
    border-color: #f9fafb;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.ui-screenshot__stroke {
    width: 90px;
    accent-color: var(--brand-primary-colour, #6366f1);
}

/* ── Stage — frozen frame (crop) or working canvas (annotate) ──────────── */

.ui-screenshot__stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: #111827;
    overflow: hidden;
}

.ui-screenshot__frame,
.ui-screenshot__canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    cursor: crosshair;
    box-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
    /* Drags must reach the pointer handlers, not scroll the page. */
    touch-action: none;
}

/* Region-selection marquee, drawn in display pixels over the scaled frame.
 *
 * The marquee floats over CAPTURED PAGE CONTENT, so it cannot assume a
 * background: a white dashed edge on a white page is invisible, which is
 * exactly how the first cut read. Contrast therefore comes from two places
 * that no single background can defeat:
 *
 *   1. DUAL-TONE EDGE — light dashes sandwiched between two dark hairlines
 *      (one inset, one outset). Light content leaves the hairlines showing,
 *      dark content leaves the dashes showing.
 *   2. DIMMED SURROUND — everything outside the selection darkens, the
 *      standard capture affordance. The selection then reads as the bright
 *      region rather than as its outline, whatever it contains. The spread
 *      is clipped by the stage's own overflow, so it never escapes. */
.ui-screenshot__marquee {
    position: absolute;
    box-sizing: border-box;
    border: 2px dashed #f9fafb;
    background: transparent;
    box-shadow:
        inset 0 0 0 1px rgba(3, 7, 18, 0.9),
        0 0 0 1px rgba(3, 7, 18, 0.9),
        0 0 0 100vmax rgba(3, 7, 18, 0.45);
    pointer-events: none;
}

/* ── Crop footer ───────────────────────────────────────────────────────── */

.ui-screenshot__bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-top: 1px solid var(--ui-admin-bar-border, rgba(255, 255, 255, 0.1));
    flex: none;
}

.ui-screenshot__hint {
    margin-right: auto;
    color: var(--ui-admin-bar-fg-muted, #9ca3af);
}

/* ── Text tool input, positioned over the click point ──────────────────── */

.ui-screenshot__text-input {
    position: absolute;
    min-width: 140px;
    padding: 2px 6px;
    background: rgba(17, 24, 39, 0.55);
    border: 1px dashed currentColor;
    border-radius: 3px;
    color: inherit; /* overridden inline with the selected colour */
    font: 600 14px system-ui, sans-serif;
    outline: none;
}

/* ── Transient notices (capture cancelled, copied, fallback…) ──────────── */

/* position:fixed works from both hosts: inside the open dialog it stays in
 * the top layer; on <body> (capture failed before the dialog existed, or the
 * feedback form has just been saved) it floats over the page.
 *
 * The z-index is only needed for the second case, and it matters: a capture
 * notice can be raised with the form drawer open on top of everything, and
 * without this it would render behind it and tell the user nothing. Above the
 * drawer stack (10050+) and the AI panel (10001). */
.ui-screenshot__notice {
    position: fixed;
    z-index: 2147483000;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    max-width: min(90vw, 480px);
    padding: 9px 14px;
    background: #111827;
    border: 1px solid var(--ui-admin-bar-border, rgba(255, 255, 255, 0.1));
    border-radius: 6px;
    color: var(--ui-admin-bar-fg, #e5e7eb);
    font-size: 12.5px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    pointer-events: none;
}
