/* tokens: runeui */
/* Media: every library and its files, a client's library (folders down the side, the open
/* folder's folders and files as icons or a list), its tab on the client, and the client's Library
/* in the portal. runeui's tokens only (shadcn's names, its --ui-* scale, and Runwell's
/* --faint-foreground and brand tints): --primary is the brand's colour, --accent the hover fill. */
@layer components {
  /* One column, with the search on the same row as the kinds and views (--media-search-row: the
  /* first row on Media, the second on a library, under its header). The search stays out of the
  /* results frame, which redraws as you type, so it keeps its text and focus; the frame lays its
  /* contents straight into this grid, its toolbar beside the search and the rest below. */
  .media-library { --media-search-row: 1; --media-search-width: min(20rem, 40%); display: grid; grid-template-columns: minmax(0, 1fr); row-gap: 1rem; min-width: 0; }
  .media-library__main { --media-search-row: 2; display: grid; grid-template-columns: minmax(0, 1fr); row-gap: 1rem; min-width: 0; }
  .media-library__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; }
  .media-library__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
  /* Rename or move opens its form under the actions, on the right, the crumbs staying where they are. */
  .media-library__head:has(.media-library__rename[open]) { align-items: flex-start; }
  .media-library__head:has(.media-library__rename[open]) .media-library__actions { flex: 1; justify-content: flex-end; }
  .media-library__rename[open] { display: flex; flex-basis: 100%; flex-direction: column; align-items: flex-end; }
  .media-library__rename > summary { list-style: none; }
  .media-library__rename > summary::-webkit-details-marker { display: none; }
  .media-library__rename[open] > .media-form { width: min(24rem, 100%); padding-top: 0.75rem; }
  .media-inline-form { display: inline-flex; margin: 0; }

  /* A form of the plugin's own: fields stacked, the button under them. */
  .media-form { display: flex; flex-direction: column; gap: 0.75rem; margin: 0; }

  /* The folders in the sidebar (inside the core's section nav): nested lists, each folder a link
  /* with its count, and a drop target while a file is dragged. */
  .media-nav__list { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
  .media-nav__list--nested { margin-left: 0.6rem; padding: 2px 0 0 0.25rem; border-left: 1px solid var(--border); }
  /* Each library, and each folder with folders inside, is a drop-down: the caret opens and closes
  /* it, the link beside it opens the library or folder. */
  .media-nav__branch > summary { list-style: none; }
  .media-nav__branch > summary::-webkit-details-marker { display: none; }
  .media-nav__summary { display: flex; align-items: center; gap: 2px; min-width: 0; }
  .media-nav__summary .media-nav__link { flex: 1; min-width: 0; }
  .media-nav__toggle { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 1.1rem; height: var(--ui-h); border-radius: var(--ui-radius-md); color: var(--faint-foreground); }
  .media-nav__branch > summary .media-nav__toggle { cursor: pointer; }
  .media-nav__branch > summary .media-nav__toggle:hover { background: var(--accent); color: var(--accent-foreground); }
  .media-nav__toggle .icon { width: 0.85rem; height: 0.85rem; transform: rotate(-90deg); transition: transform 120ms ease; }
  .media-nav__branch[open] > summary .media-nav__toggle .icon { transform: none; }
  .media-nav__branch > .media-nav__new { margin-left: 1.3rem; }
  @media (prefers-reduced-motion: reduce) { .media-nav__toggle .icon { transition: none; } }
  /* A link reads as the section nav's own (ghost buttons): the hover fill, the brand's tint for
  /* the page on screen. */
  .media-nav__link { display: flex; align-items: center; gap: 6px; min-height: var(--ui-h); padding: 0 0.5rem; border-radius: var(--ui-radius-md); color: var(--foreground); font-size: var(--ui-text-sm); text-decoration: none; cursor: pointer; }
  .media-nav__link:hover { background: var(--accent); color: var(--accent-foreground); }
  .media-nav__link:focus-visible { outline: none; box-shadow: var(--ui-focus-ring); }
  .media-nav__link[aria-current="page"] { background: var(--brand-tint); font-weight: 500; }
  .media-nav__link[aria-current="page"] .icon { color: var(--primary); }
  .media-nav__link .icon { flex: none; width: 1rem; height: 1rem; color: var(--muted-foreground); }
  .media-nav__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .media-nav__count { color: var(--faint-foreground); font-size: var(--ui-text-xs); font-variant-numeric: tabular-nums; }
  .media-nav__new > summary { list-style: none; color: var(--muted-foreground); }
  .media-nav__new > summary::-webkit-details-marker { display: none; }
  .media-nav__form { display: flex; flex-direction: column; gap: 0.5rem; margin: 0; padding: 0.5rem 0.75rem; }
  .media-nav__hint { margin: 0; color: var(--muted-foreground); font-size: var(--ui-text-xs); }
  .media-drop--target { outline: 1px dashed var(--input); outline-offset: -1px; }
  .media-drop--over, .media-dragging .media-drop--over { background: var(--brand-tint-strong) !important; outline: 2px solid var(--primary) !important; }

  /* Where the folder on screen sits: runeui's breadcrumb, a size up. */
  .media-crumbs { font-size: var(--ui-text-sm); font-weight: 500; }

  /* The toolbar: the search, then a tab per kind of file and icons or list. The results under it
  /* are a frame (search redraws only it). */
  .media-search { position: relative; display: flex; flex-direction: row; align-items: center; margin: 0; }
  .media-search > .icon { position: absolute; left: 0.625rem; width: 1rem; height: 1rem; color: var(--muted-foreground); pointer-events: none; }
  .media-search [data-slot="input-group"], .media-search [data-slot="input"] { flex: 1; min-width: 0; }
  .media-search input.ui-input { padding-inline-start: 2rem; }
  /* runeui's clear button stands in for the browser's own. */
  .media-search input::-webkit-search-cancel-button { display: none; }
  .media-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; }
  .media-toolbar__kinds { flex: 0 1 auto; width: auto; min-width: 0; }
  .media-toolbar__kinds [data-slot="tabs-list"] { flex-wrap: wrap; height: auto; }
  .media-toolbar__view .icon { width: 1rem; height: 1rem; }
  .media-count { min-width: 1.125rem; padding: 0 6px; border-radius: var(--ui-radius-full); background: color-mix(in oklab, var(--foreground) 8%, var(--muted)); color: var(--muted-foreground); font-size: var(--ui-text-xs); font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.125rem; text-align: center; }
  .media-results { display: contents; }
  /* The toolbar comes after the search and shares its cell, so it lets clicks through where it's
  /* empty (its padding would otherwise take the search's), and only its own controls take them.
  /* No z-index: the drawer over the page must stay above the search. */
  .media-library .media-search { grid-row: var(--media-search-row); grid-column: 1; justify-self: end; width: var(--media-search-width); }
  .media-library .media-toolbar { grid-row: var(--media-search-row); grid-column: 1; padding-inline-end: calc(var(--media-search-width) + 0.75rem); pointer-events: none; }
  .media-library .media-toolbar > * { pointer-events: auto; }
  @media (max-width: 640px) {
    .media-library .media-search { grid-row: auto; justify-self: stretch; width: auto; }
    .media-library .media-toolbar { grid-row: auto; padding-inline-end: 0; }
  }
  .media-section { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
  .media-section__title { margin: 0; color: var(--muted-foreground); font-size: var(--ui-text-xs); font-weight: 500; }
  .media-section__more { margin: 0; color: var(--muted-foreground); font-size: var(--ui-text-xs); }
  .media-section__more a { color: var(--foreground); text-underline-offset: 3px; }

  .media-folders, .media-files { display: grid; gap: 0.75rem; margin: 0; padding: 0; list-style: none; }
  .media-folders { grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: 0.5rem; }
  .media-files { grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); }

  /* A folder as an icon (a folder, a lock on it when it's kept from the client), its name under it;
  /* in a list (.media-folders--list), a row. */
  .media-folder { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; padding: 0.75rem 0.5rem; border: 1px solid transparent; border-radius: var(--ui-radius-xl); color: var(--foreground); font-size: var(--ui-text-sm); text-align: center; text-decoration: none; }
  .media-folder:hover { background: var(--accent); }
  .media-folder:focus-visible { outline: none; box-shadow: var(--ui-focus-ring); }
  .media-folder__icon { position: relative; display: grid; place-items: center; margin-bottom: 0.25rem; color: var(--primary); }
  .media-folder__icon .media-icon--folder { width: 3.5rem; height: 3.5rem; fill: var(--brand-tint); stroke-width: 1; }
  .media-folder__mark { position: absolute; right: -2px; bottom: 2px; display: grid; place-items: center; width: 1.25rem; height: 1.25rem; border: 1px solid var(--border); border-radius: var(--ui-radius-full); background: var(--background); color: var(--muted-foreground); }
  .media-folder__mark .icon { width: .75rem; height: .75rem; }
  .media-folder__name { max-width: 100%; overflow: hidden; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
  .media-folder__meta { max-width: 100%; overflow: hidden; color: var(--muted-foreground); font-size: var(--ui-text-xs); text-overflow: ellipsis; white-space: nowrap; }

  .media-folders--list { grid-template-columns: minmax(0, 1fr); gap: 0; border: 1px solid var(--border); border-radius: var(--ui-radius-xl); background: var(--card); overflow: hidden; }
  .media-folders--list > li + li { border-top: 1px solid var(--border); }
  .media-folders--list .media-folder { flex-direction: row; gap: 0.75rem; padding: 0.5rem 0.75rem; border: 0; border-radius: 0; text-align: left; }
  .media-folders--list .media-folder__icon { margin: 0; }
  .media-folders--list .media-folder__icon .media-icon--folder { width: 1.5rem; height: 1.5rem; stroke-width: 1.4; }
  .media-folders--list .media-folder__mark { right: -6px; bottom: -4px; width: 1rem; height: 1rem; }
  .media-folders--list .media-folder__mark .icon { width: .625rem; height: .625rem; }
  .media-folders--list .media-folder__name { flex: 1; }

  /* Files in a list: a row each, a small preview at its start. */
  .media-files--list { grid-template-columns: minmax(0, 1fr); gap: 0; border: 1px solid var(--border); border-radius: var(--ui-radius-xl); background: var(--card); overflow: hidden; }
  .media-files--list .media-file { flex-direction: row; align-items: center; border: 0; border-radius: 0; }
  .media-files--list .media-file + .media-file { border-top: 1px solid var(--border); }
  .media-files--list .media-file:hover { background: var(--accent); }
  .media-files--list .media-file__open { flex: 1; flex-direction: row; align-items: center; gap: 0.75rem; min-width: 0; padding: 0.5rem 0.75rem; }
  .media-files--list .media-file__preview { flex: none; width: 2.5rem; height: 2.5rem; aspect-ratio: auto; overflow: hidden; border-radius: var(--ui-radius-md); }
  .media-files--list .media-file__type { padding: 0 4px; font-size: var(--ui-text-xs); }
  .media-files--list .media-file__body { flex: 1; padding: 0; }
  .media-files--list .media-file__badges { position: static; padding-right: 0.75rem; }

  .media-file { position: relative; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border); border-radius: var(--ui-radius-xl); background: var(--card); color: var(--card-foreground); cursor: grab; }
  .media-file:hover { border-color: var(--input); }
  .media-file--dragging { opacity: .45; }
  .media-file__open { display: flex; flex-direction: column; color: inherit; text-decoration: none; }
  .media-file__open:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--ring); }
  .media-file__badges { position: absolute; top: 0.5rem; right: 0.5rem; display: flex; gap: 4px; pointer-events: none; }
  .media-file__badges .icon { width: .75rem; height: .75rem; }
  /* Over a preview the badges need a ground of their own: runeui's outline and tinted ones are see-through. */
  .media-file__badges [data-slot="badge"][data-variant="outline"] { background: var(--background); }
  .media-file__badges [data-slot="badge"][data-variant="success"] { background: color-mix(in oklab, var(--success) 14%, var(--background)); }
  .media-file__caption { margin: 2px 0 0; color: var(--muted-foreground); font-size: var(--ui-text-xs); }
  .media-file__preview { display: grid; place-items: center; aspect-ratio: 4 / 3; background: color-mix(in oklab, var(--muted) 50%, var(--background)); text-decoration: none; }
  .media-file__image { width: 100%; height: 100%; object-fit: cover; }
  .media-file__type { padding: 4px 8px; border-radius: var(--ui-radius-sm); background: var(--background); color: var(--muted-foreground); font-size: var(--ui-text-xs); font-weight: 500; text-transform: uppercase; }
  .media-file__body { display: flex; flex-direction: column; gap: 2px; padding: 0.5rem 0.75rem 0.75rem; min-width: 0; font-size: var(--ui-text-sm); }
  .media-file__name { display: block; overflow: hidden; color: var(--foreground); font-weight: 500; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
  .media-file__name:hover { text-decoration: underline; text-underline-offset: 3px; }
  .media-file__meta { display: block; margin: 0; overflow: hidden; color: var(--muted-foreground); font-size: var(--ui-text-xs); text-overflow: ellipsis; white-space: nowrap; }
  .media-file__move-form { display: flex; flex-direction: row; gap: 0.5rem; align-items: center; margin: 0; }

  /* A file's sheet: in runeui's drawer from the right (its large size), its details a form. */
  .media-sheet { display: flex; flex-direction: column; gap: 1rem; padding: 0.25rem 0 1.5rem; }
  .media-sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding-inline-end: 2rem; }
  .media-sheet__title { display: block; margin: 0; min-width: 0; overflow-wrap: anywhere; color: var(--foreground); font-size: var(--ui-text); font-weight: 600; }
  /* The preview: the image itself, a PDF's pages, a player, or a card naming the type. */
  .media-sheet__preview { display: flex; flex-direction: column; align-items: stretch; overflow: hidden; border-radius: var(--ui-radius-xl); background: color-mix(in oklab, var(--muted) 50%, var(--background)); }
  .media-sheet__image-link { display: flex; align-items: center; justify-content: center; min-height: 10rem; }
  .media-sheet__image { display: block; width: auto; max-width: 100%; height: auto; max-height: 26rem; object-fit: contain; }
  .media-sheet__frame { display: block; width: 100%; height: 30rem; border: 0; background: var(--background); }
  .media-sheet__video { display: block; width: 100%; max-height: 26rem; background: black; }
  .media-sheet__audio { display: block; width: 100%; padding: 0.75rem; }
  .media-sheet__card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; min-height: 10rem; padding: 1rem; color: inherit; text-align: center; text-decoration: none; }
  .media-sheet__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
  .media-sheet__actions .icon { width: 1rem; height: 1rem; }
  .media-sheet__hint { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--muted-foreground); font-size: var(--ui-text-xs); }
  .media-sheet__hint .icon { flex: none; width: .875rem; height: .875rem; }
  .media-sheet__filename { display: flex; align-items: center; gap: 0.5rem; }
  .media-sheet__filename [data-slot="input"] { flex: 1; min-width: 0; }
  .media-sheet__extension { color: var(--muted-foreground); font-size: var(--ui-text-sm); }
  .media-sheet__note { display: flex; align-items: center; gap: 6px; margin: 0; font-size: var(--ui-text-xs); }
  .media-sheet__note .icon { width: .875rem; height: .875rem; }
  .media-sheet__note--ok { color: var(--success); }
  .media-sheet__note--error { color: var(--destructive); }
  .media-sheet__section { display: flex; flex-direction: column; gap: 0.5rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
  .media-sheet__section form { margin: 0; }
  .media-sheet__danger { align-items: flex-start; }
  .media-sheet__delete.ui-button { color: var(--destructive); }
  .media-sheet__delete.ui-button:hover { background: color-mix(in oklab, var(--destructive) 10%, transparent); color: var(--destructive); }
  .media-sheet__heading { margin: 0; color: var(--muted-foreground); font-size: var(--ui-text-xs); font-weight: 500; }
  /* What it is and where it's kept: a label column and its values. */
  .media-sheet__facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.375rem 1rem; margin: 0; font-size: var(--ui-text-xs); }
  .media-sheet__facts dt { color: var(--muted-foreground); }
  .media-sheet__facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
  .media-sheet__facts a { color: var(--foreground); text-underline-offset: 3px; }
}
