/**
 * Forovanta Community Software
 * Copyright (c) 2026 Zovanta Software Co. <sales@zovanta.dev> - https://zovanta.dev
 * Licensed under the Forovanta Free License Agreement. See LICENSE for details.
 *
 * Media Gallery add-on stylesheet.
 *
 * Loaded only while the add-on is enabled, and only ever against the classes the add-on's own
 * `pages.php` emits — every selector below starts with `.mg-`, so a gallery cannot restyle
 * anything that belongs to the board. The tokens it reads are the board's own
 * (`--surface`, `--border`, `--text`, `--muted`, `--accent`, `--radius`), which is what makes a
 * gallery follow the theme it is installed into rather than carrying a theme of its own.
 *
 * Two ideas do most of the work:
 *
 *  * **The grid is one custom property.** `pages.php` sets `--mg-columns` from the add-on's
 *    "grid columns" option, and every breakpoint below narrows it — so a board that asks for six
 *    columns gets six on a desktop, four on a laptop and two on a phone without a second rule
 *    being written for each.
 *  * **A tile is a picture with a caption, not a card with padding.** The media keeps its own
 *    aspect ratio and the caption sits over it, so a grid of photographs reads as a contact
 *    sheet rather than as a list of boxes.
 */

.mg-shell {
  display: grid;
  gap: 1.5rem;
  align-items: start;
}

.mg-shell--rail {
  grid-template-columns: minmax(0, 15rem) minmax(0, 1fr);
}

.mg-main {
  min-width: 0;
}

.mg-main--wide {
  max-width: 46rem;
}

/* ------------------------------------------------------------------ headings */

.mg-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.mg-head h1 {
  margin: 0.15rem 0 0;
  font-size: 1.65rem;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.mg-eyebrow {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.mg-blurb {
  margin: 0.35rem 0 0;
  max-width: 46rem;
  color: var(--muted);
}

.mg-back {
  display: inline-block;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
}

.mg-back:hover {
  color: var(--text);
}

.mg-byline {
  margin: -0.5rem 0 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.mg-hint {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
}

/* ------------------------------------------------------------------- buttons */

.mg-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 4px);
  background: var(--accent);
  padding: 0.5rem 0.95rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}

.mg-button:hover {
  filter: brightness(1.08);
}

.mg-button--wide {
  width: 100%;
}

.mg-button--quiet {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.mg-button--danger {
  border-color: color-mix(in srgb, #ef4444 45%, transparent);
  background: transparent;
  color: #ef4444;
}

.mg-link {
  display: inline-block;
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
}

/* ---------------------------------------------------------------------- rail */

.mg-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}

.mg-panel h2 {
  margin: 0 0 0.6rem;
  font-size: 0.95rem;
}

.mg-cats {
  margin: 0;
  padding: 0;
  list-style: none;
}

.mg-cat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border-radius: calc(var(--radius) - 6px);
  padding: 0.35rem 0.5rem;
  font-size: 0.875rem;
  color: var(--text);
  text-decoration: none;
}

.mg-cat:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.mg-cat--on {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  font-weight: 600;
}

.mg-cat__count {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.mg-people {
  margin: 0;
  padding: 0;
  list-style: none;
}

.mg-people li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.3rem 0;
  font-size: 0.85rem;
}

.mg-people__count {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* ---------------------------------------------------------------------- grid */

/*
 * A track is as wide as the chosen column count allows, but never narrower than a thumbnail.
 * That is what makes the grid responsive without a breakpoint per count: `auto-fill` fits as
 * many tracks as the row has room for, so a six-column board on a phone falls to two by itself,
 * and the number an administrator picked is a ceiling rather than something to fight.
 */
.mg-grid {
  --mg-track: calc((100% - (var(--mg-columns, 4) - 1) * 0.85rem) / var(--mg-columns, 4));
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(max(9rem, var(--mg-track)), 1fr));
  gap: 0.85rem;
}

.mg-tile {
  position: relative;
  display: block;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}

.mg-tile:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}

.mg-tile__media {
  display: block;
  aspect-ratio: 4 / 3;
  background: color-mix(in srgb, var(--text) 6%, transparent);
}

.mg-media {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mg-media--audio {
  height: auto;
  padding: 1.5rem 0.75rem;
}

.mg-media--file {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 1rem;
  font-size: 0.85rem;
  text-align: center;
}

.mg-missing {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 1rem;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.mg-tile__kind {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.6);
  padding: 0.1rem 0.5rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
}

.mg-tile__body {
  display: block;
  padding: 0.55rem 0.65rem 0.7rem;
}

.mg-tile__title {
  display: block;
  overflow: hidden;
  font-size: 0.875rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mg-tile__meta {
  display: block;
  margin-top: 0.15rem;
  overflow: hidden;
  font-size: 0.75rem;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* -------------------------------------------------------------------- albums */

.mg-section {
  margin-bottom: 1.75rem;
}

.mg-section h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.mg-albums {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 0.7rem;
}

.mg-album {
  display: block;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  background: var(--surface);
  padding: 0.7rem 0.8rem;
  color: inherit;
  text-decoration: none;
}

.mg-album:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.mg-album__title {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
}

.mg-album__meta {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.mg-chip {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  font-size: 0.7rem;
  color: var(--muted);
}

.mg-chip--quiet {
  margin-top: 0.3rem;
}

/* --------------------------------------------------------------------- empty */

.mg-empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.25rem;
  text-align: center;
}

.mg-empty h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.mg-empty p {
  margin: 0 0 1rem;
  color: var(--muted);
}

.mg-alert {
  border: 1px solid color-mix(in srgb, #ef4444 45%, transparent);
  border-radius: calc(var(--radius) - 4px);
  background: color-mix(in srgb, #ef4444 10%, transparent);
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

/* -------------------------------------------------------------------- paging */

.mg-pages {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 1.5rem;
}

.mg-page {
  min-width: 2rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 6px);
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  text-align: center;
  color: var(--text);
  text-decoration: none;
}

.mg-page--on {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

/* -------------------------------------------------------------------- detail */

.mg-detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 17rem);
  gap: 1.5rem;
  align-items: start;
  margin-bottom: 2rem;
}

.mg-detail__media {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--text) 5%, transparent);
}

.mg-detail__media .mg-media {
  width: 100%;
  height: auto;
  max-height: 34rem;
  object-fit: contain;
}

.mg-owner {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.9rem;
}

.mg-owner img,
.mg-owner__initial {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  font-weight: 600;
  object-fit: cover;
}

.mg-owner strong {
  display: block;
  font-size: 0.9rem;
}

.mg-owner span {
  font-size: 0.78rem;
  color: var(--muted);
}

.mg-rating {
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  padding: 0.6rem 0.75rem;
  margin-bottom: 1rem;
}

.mg-stars {
  letter-spacing: 0.08em;
  font-size: 0.95rem;
}

.mg-star {
  color: color-mix(in srgb, var(--muted) 45%, transparent);
  font-style: normal;
}

.mg-star--on {
  color: #f59e0b;
}

.mg-rate__set {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 0.1rem;
  border: 0;
  margin: 0.5rem 0 0;
  padding: 0;
}

.mg-rate__set legend {
  padding: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.mg-rate__set button {
  border: 0;
  background: none;
  padding: 0 0.05rem;
  font-size: 1.15rem;
  line-height: 1;
  color: color-mix(in srgb, var(--muted) 55%, transparent);
  cursor: pointer;
}

.mg-rate__set button:hover,
.mg-rate__set button:hover ~ button {
  color: #f59e0b;
}

.mg-facts {
  margin: 0;
  font-size: 0.82rem;
}

.mg-facts > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0;
}

.mg-facts > div:last-child {
  border-bottom: 0;
}

.mg-facts dt {
  color: var(--muted);
}

.mg-facts dd {
  margin: 0;
  text-align: right;
}

.mg-facts a {
  color: var(--accent);
}

/* ------------------------------------------------------------------ comments */

.mg-comments {
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
}

.mg-comments h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.mg-comment-list {
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}

.mg-comment {
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 0;
}

.mg-comment__who {
  font-size: 0.85rem;
  font-weight: 600;
}

.mg-comment__when {
  margin-left: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.mg-comment__body {
  margin-top: 0.2rem;
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------- forms */

.mg-form {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1.1rem 1.2rem;
  display: grid;
  gap: 0.9rem;
}

.mg-form--comment {
  display: block;
}

.mg-form--comment textarea,
.mg-form--comment button {
  margin-top: 0.5rem;
}

.mg-form label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.mg-field {
  min-width: 0;
}

.mg-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.9rem;
}

.mg-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 6px);
  background: var(--surface);
  padding: 0.5rem 0.6rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
}

.mg-input:focus {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 1px;
}

.mg-danger {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 60rem) {
  .mg-shell--rail {
    grid-template-columns: minmax(0, 1fr);
  }

  .mg-detail {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 44rem) {
  .mg-tile__media {
    aspect-ratio: 1 / 1;
  }

  .mg-head h1 {
    font-size: 1.35rem;
  }
}
