/* ==========================================================================
   app-file.css — File picker
   --------------------------------------------------------------------------
   <input type="file"> renders a browser-owned "Choose File" button that no rule reaches. The input
   stays in the form under its own id and name, visually hidden but focusable; a <label for> styled
   as an app-btn is the visible control and the span shows the chosen name (global.js fills it on
   change, data-empty is the placeholder).

     <span class="app-file">
       <input class="app-file__input" type="file" id="x" name="x">
       <label class="app-btn app-btn--soft app-btn--sm" for="x">Browse files</label>
       <span class="app-file__name" data-empty="No file chosen"></span>
     </span>
   ========================================================================== */

.app-file {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    min-width: 0;
    /* Without this the picker shrinks below its own button in a flex row and the button overflows
       on top of whatever follows it - on the import pages it lay across the Upload button. The
       filename is what may be long, and it already truncates on its own max-width. */
    flex-shrink: 0;
}
.app-file__input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}
/* The readonly-name form puts the name field between the input and the browse button. */
.app-file__input:focus-visible + .app-btn,
.app-file__input:focus-visible ~ .app-file__browse {
    outline: 2px solid var(--color-focus-ring);
    outline-offset: 2px;
}
/* The submit that acts on the picked file: there is nothing to upload until one is chosen, so it
   stays out of the row until then (global.js reveals it on change). */
.app-file-submit.is-hidden,
.app-file__clear.is-hidden,
.app-file__browse.is-hidden,
input.app-file__name.is-hidden {
    display: none;
}

.app-file__name {
    font-size: var(--font-body-sm-size);
    color: var(--color-text-muted);
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-file__name:empty::before {
    content: attr(data-empty);
}

/* As a readonly input the name is a readout, not a control - it should not look focusable. Its
   width matches the other fields on the page rather than the 260px cap the span form carries. */
input.app-file__name {
    color: var(--color-text-muted);
    background: var(--bg-secondary);
    cursor: default;
    width: var(--app-file-name-width, 22rem);
    max-width: 100%;
}

/* In a labelled row the picked name takes what the row has left, as the inputs below it do, so the
   clear button, the submit and an info icon after it stay inside the column. */
.app-field--inline > .app-file:has(> input.app-file__name:not(.is-hidden)) {
    flex: 1 1 auto;
}
.app-field--inline > .app-file > input.app-file__name {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
}

/* A row a file is dragged over (global.js): dropping it there picks it, as the browser's own input did. */
.app-file-drop-target {
    /* The shadow carries the grey 4px past the row without moving it; the outline sits on its edge. */
    background: var(--neutral-100);
    box-shadow: 0 0 0 4px var(--neutral-100);
    outline: 1px dashed var(--color-focus-ring);
    outline-offset: 4px;
    border-radius: var(--radius-md);
}
