/*
 * Local overrides for the vendored Uploadcare File Uploader theme.
 * Loaded from `client/head.html` immediately AFTER
 * `uc-file-uploader-regular-1.33.1.min.css`, which it exists to correct.
 *
 * ## Why a separate file rather than an edit to the vendored stylesheet
 *
 * The vendored file is a verbatim copy of the published 1.33.1 theme, pinned by
 * filename so the version is visible (see the note in `client/head.html`).
 * Editing it in place would make the next version bump — a re-download of the
 * upstream file — silently drop these rules with nothing to notice it. Keeping
 * them here means a bump replaces the theme and leaves the corrections intact,
 * and `git log` on this file records why each one exists.
 *
 * ## Why `:not(#\#)` five times
 *
 * That is the upstream theme's own specificity idiom — its rules carry three or
 * four of them (`[uc-file-uploader-minimal]:not(#\#):not(#\#):not(#\#):not(#\#)
 * uc-upload-list uc-activity-header`, specificity 4-1-2). `#\#` is an escaped
 * id selector that matches nothing, so each one buys an id's worth of
 * specificity while changing what is matched not at all. Five beats every
 * upstream rule these override without resorting to `!important`, which would
 * be unbeatable by anything downstream including the uploader's own state
 * handling.
 *
 * Both corrections below are for the `minimal` variant used by the comment form
 * (`client/lib/components/comments/commentInput.html`). Measured against
 * staging build 1007; see
 * `docs/solutions/design-patterns/uploadcare-file-uploader-verify-sdk-behaviour-at-runtime.md`.
 */

/* ---------------------------------------------------------------------------
 * 1. The uploading state had nowhere to appear.
 *
 * `uc-upload-list`'s activity header is the element that carries the live
 * status text ("Uploading 1 file", rendered into `.uc-header-text` with
 * `aria-live="polite"`), and the minimal theme hides the whole header:
 *
 *   [uc-file-uploader-minimal]…:not(#\#) uc-upload-list uc-activity-header
 *     { display: none }
 *
 * That leaves a rep with no indication an upload is running — measured at 8.8s
 * for a 3 MB file on staging with nothing on screen. The `regular` variant
 * shows this header inside its modal; `minimal` renders the list inline and
 * drops it.
 *
 * The header's close button is hidden separately and deliberately. It is the
 * reason the upstream rule hides the *whole* header rather than styling it: the
 * button calls the uploader's `*closeModal`, which means nothing for a list
 * rendered inline rather than in a modal. Only the status text is wanted here.
 * ------------------------------------------------------------------------- */

[uc-file-uploader-minimal]:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)
  uc-upload-list
  uc-activity-header {
  display: flex;
}

[uc-file-uploader-minimal]:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)
  uc-upload-list
  uc-activity-header
  .uc-close-btn {
  display: none;
}

/* ---------------------------------------------------------------------------
 * 2. "+ Add more" made the already-attached files disappear.
 *
 * The `+` button calls `api.initFlow(true)`, and that argument means "skip the
 * upload-list branch". With more than one entry in `source-list` (this form
 * offers `local, camera, url`) it falls through to publishing
 * `*currentActivity = start-from` and opening the source modal. The theme then
 * hides every activity that is not current:
 *
 *   :where([uc-wgt-common])…:not(#\#) [activity]:not([active], .active)
 *     { display: none }
 *
 * so the inline file list goes `display: flex` → `none` and the "Choose files"
 * start screen takes its place — reading, to the rep, as though the photo they
 * just uploaded had been dropped. The `uc-file-item` elements stay in the DOM
 * throughout; nothing is actually lost, and they return when the source modal
 * closes.
 *
 * Holding the list visible whenever it holds files, and keeping the inline
 * start screen out of the way while it does, makes `+` open the source modal
 * *over* the list instead of *instead of* it.
 *
 * `:has()` is what makes this expressible in CSS. Where it is unsupported the
 * whole rule is discarded as an invalid selector and the behaviour falls back
 * to the flicker described above — degraded, not broken, which is the right
 * failure for a cosmetic correction.
 *
 * Scoped with `>` on purpose: the modal contains its own `uc-start-from`, and
 * that one must keep working.
 * ------------------------------------------------------------------------- */

[uc-file-uploader-minimal]:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):has(
    uc-file-item
  )
  uc-upload-list {
  display: flex;
}

[uc-file-uploader-minimal]:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):has(
    uc-file-item
  )
  > uc-start-from {
  display: none;
}
