.media-folders-browser {
  --mf-border: #e0e2e7;
  --mf-bg: #ffffff;
  --mf-bg-hover: #f6f8fa;
  --mf-accent: #434e2f;
  --mf-text: #1a1d21;
  --mf-text-muted: #6b7280;
  --mf-radius: 5px;

}

.paragraph--type--media-folders {
  margin-bottom: 40px;
  margin-top: 40px;
}

.media-folders-browser h2 {
  margin: 0 0 1rem;
}

/* Breadcrumb */
.media-folders-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 1.25rem;
  font-size: 0.85rem;
}

.media-folders-breadcrumb .media-folders-crumb-link {
  color: var(--mf-accent);
  text-decoration: none;
}

.media-folders-breadcrumb .media-folders-crumb-link:hover {
  text-decoration: underline;
}

.media-folders-breadcrumb .media-folders-crumb-current {
  color: var(--mf-text-muted);
  font-weight: 600;
}

.media-folders-breadcrumb .media-folders-crumb-sep {
  color: var(--mf-border);
}

/* Search */
.media-folders-search {
  margin-bottom: 1.5rem;
}

.media-folders-search .views-exposed-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem;
}

.media-folders-search .views-exposed-form .form--inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.media-folders-search .form-item {
  margin: 0;
  flex: 1 1 240px;
}

.media-folders-search label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--mf-text-muted);
  margin-bottom: 0.25rem;
}

.media-folders-search input[type='text'] {
  width: 100%;
  box-sizing: border-box;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--mf-border);
  border-radius: var(--mf-radius);
  font-size: 0.95rem;
}

.media-folders-search input[type='text']:focus {
  outline: none;
  border-color: var(--mf-accent);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.15);
}

.media-folders-search input[type='submit'] {
  flex: 0 0 auto;
  padding: 0.55rem 1.25rem;
  border: 1px solid var(--mf-accent);
  background: var(--mf-accent);
  color: #fff;
  border-radius: var(--mf-radius);
  cursor: pointer;
  font-weight: 600;
}

.media-folders-search input[type='submit']:hover {
  filter: brightness(1.08);
}

/*
 * The search view's exposed form (the box + button above) and its results
 * are siblings inside the same Views wrapper — the results need the same
 * tile grid as the folder browser, but turning the *whole view* into a
 * grid would pull the form in alongside the result tiles as its own cell.
 * Target the results container directly instead, and leave the form
 * completely untouched.
 */
.view-media-folders-search .view-content {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  grid-auto-rows: 160px;
  gap: 1rem;
  align-items: stretch;
  margin-top: 1rem;
}

.view-media-folders-search .view-content .views-row {
  display: contents;
}

.view-media-folders-search .view-content .media-folders-empty {
  grid-column: 1 / -1;
  height: auto;
  padding: 0;
  color: var(--mf-text-muted);
  font-style: italic;
}

/* Fold the two separate Views outputs (folders + items) into one grid. */
.media-folders-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  grid-auto-rows: 160px;
  gap: 1rem;
  align-items: stretch;
}

/*
 * drupal_view()/buildRenderable() wrap each embedded view in a
 * ".views-element-container" div, so it sits between ".media-folders-grid"
 * and ".view" rather than being a direct child. Collapse every layer down
 * to the actual row so the two separate Views outputs (folders + items)
 * fold into one grid instead of becoming two grid cells.
 */
.media-folders-grid > .views-element-container,
.media-folders-grid .view,
.media-folders-grid .view-content,
.media-folders-grid .views-row,
.media-folders-grid .views-field-name,
.media-folders-grid .views-field-name .field-content {
  display: contents;
}

/*
 * Same trick for the "up one level" slot: the wrapper is always present
 * (so AJAX has a stable target to replace) but only contains a tile when
 * not already at the root, and display:contents means an empty wrapper
 * contributes nothing to the grid.
 */
.media-folders-up-slot {
  display: contents;
}

a.media-folder-tile {
  display: flex;
  height: 160px;
  box-sizing: border-box;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.25rem 0.75rem;
  border: 1px solid var(--mf-border);
  border-radius: var(--mf-radius);
  background: var(--mf-bg);
  text-decoration: none;
  color: var(--mf-text);
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.3;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    transform 0.1s ease;
}

a.media-folder-tile::before {
  content: '';
  display: block;
  width: 48px;
  height: 38px;
  background: no-repeat center / contain
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 20'%3E%3Cpath fill='%23f2b632' d='M1 3.5C1 2.12 2.12 1 3.5 1H9l2 2h9.5C21.88 3 23 4.12 23 5.5v11c0 1.38-1.12 2.5-2.5 2.5h-17A2.5 2.5 0 0 1 1 16.5v-13Z'/%3E%3Cpath fill='%23f6c65a' d='M1 7h22v9.5c0 1.38-1.12 2.5-2.5 2.5h-17A2.5 2.5 0 0 1 1 16.5V7Z'/%3E%3C/svg%3E");
}

/* "Up one level" tile: same shape as a folder tile, distinct icon. */
a.media-folder-up::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%238b93a1' d='M12 3.5 20 12h-5v8H9v-8H4Z'/%3E%3C/svg%3E");
}

a.media-folder-tile:hover,
a.media-folder-tile:focus {
  background: var(--mf-bg-hover);
  border-color: var(--mf-accent);
  transform: translateY(-2px);
}

/* Media (file) tiles: the image field is the cover. */
article.media--view-mode-folder {
  display: flex;
  flex-direction: column;
  height: 160px;
  box-sizing: border-box;
  overflow: hidden;
  border: 1px solid var(--mf-border);
  border-radius: var(--mf-radius);
  background: var(--mf-bg);
  transition: border-color 0.15s ease, transform 0.1s ease,
    box-shadow 0.15s ease;
}

article.media--view-mode-folder:hover {
  border-color: var(--mf-accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

/*
 * The whole tile is wrapped in a link (modal trigger for video/image,
 * direct file link for manual/downloads). display:contents keeps it from
 * disrupting the article's own flex layout while still making the entire
 * card clickable.
 */
article.media--view-mode-folder a.media-folders-item-link {
  display: contents;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

article.media--view-mode-folder .field--name-field-media-image {
  position: relative;
  margin: 0;
  aspect-ratio: 4 / 3;
  background: #eef0f3;
}

article.media--view-mode-folder .field--name-field-media-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Fallback cover for items with no field_media_image (common on downloads). */
article.media--view-mode-folder:not(:has(.field--name-field-media-image))::before {
  content: '';
  display: block;
  aspect-ratio: 4 / 3;
  background: #eef0f3
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23a6acb8' d='M6 2c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12a2 2 0 0 0 2-2V8l-6-6H6Zm7 1.5L18.5 9H14a1 1 0 0 1-1-1V3.5Z'/%3E%3C/svg%3E")
    no-repeat center / 40px 40px;
}

article.media--view-mode-folder .field--name-name {
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  color: var(--mf-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* File-type badge over the cover, for types that aren't self-evidently images. */
article.media--type-video .field--name-field-media-image::after,
article.media--type-manual .field--name-field-media-image::after,
article.media--type-downloads .field--name-field-media-image::after {
  content: '';
  position: absolute;
  right: 0.4rem;
  bottom: 0.4rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.6);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 13px 13px;
}

article.media--type-video .field--name-field-media-image::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23fff' d='M3 2.2c0-.9 1-1.4 1.7-.9l9.6 6.3c.6.4.6 1.3 0 1.7L4.7 15.6c-.7.5-1.7 0-1.7-.9V2.2Z'/%3E%3C/svg%3E");
}

article.media--type-manual .field--name-field-media-image::after,
article.media--type-downloads .field--name-field-media-image::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23fff' d='M3.5 1A1.5 1.5 0 0 0 2 2.5v11A1.5 1.5 0 0 0 3.5 15h9a1.5 1.5 0 0 0 1.5-1.5V6.4a1.5 1.5 0 0 0-.44-1.06L9.66 1.44A1.5 1.5 0 0 0 8.6 1H3.5Zm5 1.1 3.4 3.4H9.75a1.25 1.25 0 0 1-1.25-1.25V2.1Z'/%3E%3C/svg%3E");
}

/* Modal preview (image/video) contents. */
.media-folders-modal img,
.media-folders-modal video {
  display: block;
  width: 100%;
  height: auto;
  max-height: 75vh;
  object-fit: contain;
  margin: 0 auto;
}

/*
 * jQuery UI's dialog close button relies on the theme providing CSS that
 * centers its icon glyph within the button (core themes like Claro ship
 * this; theme_bre's dialog.css doesn't). Without it the icon renders
 * offset from the circular button background. Rather than edit the
 * theme's site-wide dialog CSS, replace the icon just for this modal
 * with a self-contained one, matching the same dark circular badge style
 * already used on the folder/file tiles.
 */
.media-folders-modal .ui-dialog-titlebar-close {
  position: absolute;
  inset-inline-end: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
}

.media-folders-modal .ui-dialog-titlebar-close:hover {
  background: rgba(0, 0, 0, 0.8);
}

.media-folders-modal .ui-dialog-titlebar-close .ui-icon,
.media-folders-modal .ui-dialog-titlebar-close .ui-button-icon-space {
  display: none;
}

.media-folders-modal .ui-dialog-titlebar-close .ui-button-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.media-folders-modal .ui-dialog-titlebar-close::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  transform: translate(-50%, -50%);
  background: no-repeat center / contain
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath stroke='%23fff' stroke-width='2.5' stroke-linecap='round' d='M5 5l14 14M19 5L5 19'/%3E%3C/svg%3E");
}
