/* ===== <x-file-info> — standard "file loaded" card =====
   Owns the visual shell. Data is filled progressively by tool-file-info.js.
   Works in dark (default) and light themes via CSS variables from app.css. */

.tool-file-info {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 14px 16px;
    align-items: center;
    padding: 14px 18px;
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 14px;
    position: relative;
    transition: border-color .18s, background .18s;
}
.tool-file-info[hidden] { display: none; }
.tool-file-info.tfi-drag-over { border-color: var(--accent); background: rgba(56,189,248,.06); }

.tfi-icons {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
    color: var(--accent);
}
.tfi-icons svg { width: 28px; height: 28px; opacity: .9; }
.tfi-icons:empty { display: none; }

.tfi-main {
    min-width: 0;   /* lets flex children truncate */
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tfi-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.25;
}

.tfi-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 10px;
    line-height: 1.35;
}
.tfi-meta-primary .tfi-chip { color: var(--text-secondary); }
.tfi-meta-secondary .tfi-chip { color: var(--text-muted); font-size: 13px; }

.tfi-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    position: relative;
}
.tfi-chip[hidden] { display: none; }
.tfi-chip + .tfi-chip::before {
    content: '·';
    margin-inline-end: 8px;
    opacity: .5;
    color: var(--text-muted);
}
/* Separator belongs between two VISIBLE chips. When the immediate predecessor
   is [hidden] (duration/fps/codec not yet probed), the next visible chip would
   otherwise show a leading "· " — drop it. */
.tfi-chip[hidden] + .tfi-chip::before { content: none; }

.tfi-warn {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    color: var(--warning, #f59e0b);
    font-size: 13px;
}
/* display:flex above outranked the HTML hidden attribute — explicitly re-hide */
.tfi-warn[hidden] { display: none; }
.tfi-chip[hidden] { display: none; }

.tfi-remove {
    align-self: center;
    background: var(--glass-hover, rgba(0, 0, 0, .04));
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color .15s, background .15s, border-color .15s, transform .12s;
}
.tfi-remove:hover {
    color: var(--danger, #ef4444);
    background: rgba(239, 68, 68, .1);
    border-color: rgba(239, 68, 68, .35);
    transform: rotate(90deg);
}
.tfi-remove:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.tfi-remove svg { width: 18px; height: 18px; stroke-width: 2.2; }

.tfi-drop-hint {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(56, 189, 248, .10);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    border-radius: var(--radius-lg);
    color: var(--accent);
    font-weight: 600;
    font-size: 14px;
    pointer-events: none;
    z-index: 2;
}
.tool-file-info.tfi-drag-over .tfi-drop-hint { display: flex; }

/* Narrow mobile — stack icon+text and push remove button to the top-right corner */
@media (max-width: 520px) {
    .tool-file-info {
        grid-template-columns: auto 1fr;
        gap: 10px 12px;
    }
    .tfi-remove {
        position: absolute;
        top: 6px;
        inset-inline-end: 6px;
    }
    .tfi-name { padding-inline-end: 36px; }
    .tfi-meta { font-size: 13px; }
    .tfi-meta-secondary { font-size: 12px; }
}

[data-theme=light] .tool-file-info { background: rgba(0,0,0,.02); }
[data-theme=light] .tool-file-info.tfi-drag-over { background: rgba(56,189,248,.08); }


/* ===== <x-tool-uploader> auto-rendered content (when tool doesn't pass a slot) =====
   Lives here rather than in a per-tool stylesheet so every upload zone looks the
   same regardless of which tool embeds the component. Tools that pass a slot
   keep their own CSS. */

/* The element is role="button" tabindex="0" — it must feel clickable.
   Before this rule only the underlying hidden <input type=file> carried
   cursor:pointer, which users never see because the input is display:none. */
.tool-uploader {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    position: relative;  /* anchors .tu-label-overlay */
}

/* Native fallback: a transparent <label for=tuStaticInput> covers the whole
   drop zone. Browsers open the OS file picker on click of any <label>
   pointing at a file <input>, with zero JS involved. This rescues users on
   slow connections who rage-clicked while defer-loaded tool-uploader.js was
   still in flight (74% of rage-click sessions never recovered to a
   file_select event in 30-day telemetry). When the JS does load, its drag/
   drop/keyboard/paste/telemetry hooks layer on top — both paths use the
   same <input>, so change events and validation stay unified. */
.tool-uploader .tu-static-input {
    position: absolute;
    width: 1px; height: 1px;
    opacity: 0; pointer-events: none;
    overflow: hidden; clip: rect(0,0,0,0); clip-path: inset(50%);
}
.tool-uploader .tu-label-overlay {
    position: absolute;
    inset: 0;
    cursor: pointer;
    z-index: 1;
    /* Visually invisible — it's the click capture layer only. The visible
       UI lives below it (tu-content) and above it (tu-reject, overlay slot
       with cancel button) per their own z-index. */
}
/* Visible content sits below the label-overlay so the overlay catches the
   click. Inert by design — prevents text selection from hijacking taps,
   prevents children from intercepting the file-picker click on iOS where
   <label> click bubbles weirdly through pointer-events: none descendants. */
.tool-uploader .tu-content {
    position: relative;
    z-index: 0;
}
/* Rejection banner + overlay slot need to sit ABOVE the label so their own
   buttons (Cancel upload, Use Microphone instead) stay clickable without
   triggering the file picker. */
.tool-uploader .tu-reject,
.tool-uploader .upload-progress-overlay {
    position: relative;
    z-index: 2;
}
.tool-uploader:active { transform: scale(.998); }
.tool-uploader:focus-visible {
    outline: 2px solid var(--accent, #38bdf8);
    outline-offset: 2px;
}

/* ───── Per-kind palette ──────────────────────────────────────────────
   The component sets data-colour-kind on the wrapper to one of
   audio | video | image | model (av tools map to video). Colour-coding
   the drop zone by kind gives the site a consistent visual language:
   every video zone looks the same across tools, every audio zone looks
   the same, etc.

   Each kind defines an --tu-accent RGB triplet; the rules below consume
   it to tint border + fill + icon. Per-tool CSS can still override via
   higher specificity (e.g. `.vr-app .vr-upload`).

   Note: `data-kind` on the wrapper is the SIZE kind for the JS size-gate
   (models route through the image size budget). `data-colour-kind` is
   independent so the palette stays truthful even when size routes
   through another bucket.

   Specificity .tool-uploader[data-colour-kind=X] = (0,2,0) beats the
   typical per-tool `.xx-upload` (0,1,0), so these colours reliably win
   over the common `border: 2px dashed var(--border)` pattern every tool
   copies. */
.tool-uploader[data-colour-kind=video] { --tu-accent: 249,115,22; }   /* orange-500  — dynamic media */
.tool-uploader[data-colour-kind=audio] { --tu-accent: 245,158,11; }   /* amber-500   — sound/waveform */
.tool-uploader[data-colour-kind=image] { --tu-accent: 20,184,166; }   /* teal-500    — visual static */
.tool-uploader[data-colour-kind=model] { --tu-accent: 139,92,246; }   /* violet-500  — 3D/mesh/g-code */

.tool-uploader[data-colour-kind] {
    border: 2px dashed rgba(var(--tu-accent), .35);
    background: rgba(var(--tu-accent), .02);
    transition: border-color .3s ease, background .3s ease;
}
.tool-uploader[data-colour-kind]:hover,
.tool-uploader[data-colour-kind].dragover {
    border-color: rgba(var(--tu-accent), .7);
    background: rgba(var(--tu-accent), .05);
}
.tool-uploader[data-colour-kind] .tu-icons,
.tool-uploader[data-colour-kind] .tu-icon { color: rgb(var(--tu-accent)); }
/* Light theme needs slightly stronger border contrast on white bg. */
[data-theme=light] .tool-uploader[data-colour-kind] { border-color: rgba(var(--tu-accent), .3); }
[data-theme=light] .tool-uploader[data-colour-kind]:hover,
[data-theme=light] .tool-uploader[data-colour-kind].dragover { border-color: rgba(var(--tu-accent), .6); }

/* Children inside the zone should not steal the pointer cursor unless they're
   themselves interactive — otherwise large icon/title areas feel dead. */
.tool-uploader .tu-icons,
.tool-uploader .tu-icon,
.tool-uploader .tu-title,
.tool-uploader .tu-formats,
.tool-uploader .tu-hint,
.tool-uploader .tu-content { cursor: inherit; pointer-events: none; }
/* …but an interactive child (cancel button in the overlay slot) needs pointer
   events and its own cursor back. */
.tool-uploader button,
.tool-uploader a,
.tool-uploader input,
.tool-uploader label { pointer-events: auto; cursor: pointer; }

.tool-uploader .tu-icons {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
    color: var(--text-muted);
}
.tool-uploader .tu-icon {
    width: 36px;
    height: 36px;
    transition: color .2s;
}
/* Per-kind rules above set icon colour permanently; this generic
   hover rule is the fallback for uploaders without data-colour-kind
   (shouldn't happen — blade always sets it — but kept as safety net). */
.tool-uploader:not([data-colour-kind]):hover .tu-icon,
.tool-uploader:not([data-colour-kind]).dragover .tu-icon {
    color: var(--accent);
}

.tool-uploader .tu-title {
    font-size: 15px;
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 4px;
    line-height: 1.35;
}

.tool-uploader .tu-formats {
    font-size: 13px;
    color: var(--text-muted);
    opacity: .75;
}

/* Inline rejection banner — visible inside the zone instead of a
   disconnected toast, so the error stays with the thing the user was
   just interacting with. */
.tool-uploader .tu-reject {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 12px;
    background: color-mix(in srgb, var(--danger, #ef4444) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--danger, #ef4444) 25%, transparent);
    border-radius: var(--radius-sm, 6px);
    color: var(--danger, #ef4444);
    font-size: 13px;
    line-height: 1.4;
    text-align: start;
}
.tool-uploader .tu-reject[hidden] { display: none; }
.tool-uploader .tu-reject-icon { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }

/* Shake animation — runs once on reject, reduced-motion users get no
   motion but still see the banner. */
@keyframes tu-shake {
    0%, 100% { transform: translateX(0); }
    15%, 45%, 75% { transform: translateX(-6px); }
    30%, 60%, 90% { transform: translateX(6px); }
}
.tool-uploader.tu-shaking { animation: tu-shake .4s ease-in-out; }
@media (prefers-reduced-motion: reduce) {
    .tool-uploader.tu-shaking { animation: none; }
}

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