.media-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .25rem;
  padding: .22rem;
  margin-bottom: .58rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--layer);
}

.media-filter {
  min-height: 2rem;
  padding: .25rem .24rem;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 670;
}

.media-filter:hover { color: var(--ink); background: var(--paper); }
.media-filter[aria-pressed="true"] {
  border-color: var(--teal-line);
  background: var(--paper);
  color: var(--teal-deep);
  font-weight: 740;
}

.media-list {
  display: grid;
  align-content: start;
  gap: .35rem;
  max-height: min(38rem, 66vh);
  padding: .18rem;
  overflow: auto;
  scrollbar-width: thin;
}

.media-card {
  display: grid;
  grid-template-columns: clamp(3.35rem, 5vw, 4.45rem) minmax(0, 1fr);
  align-items: center;
  gap: .58rem;
  min-width: 0;
  min-height: 3.6rem;
  padding: .35rem;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  text-align: start;
}

.media-card:hover { border-color: var(--line); background: var(--layer); }
.media-card[aria-pressed="true"] { border-color: var(--teal-line); background: var(--teal-soft); }
.media-card[aria-pressed="true"] .media-card-title { color: var(--teal-deep); }
.media-card:focus-visible { outline-offset: -3px; }

.media-thumb, .media-thumb-placeholder {
  width: 100%;
  min-width: 0;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #dce7ec;
}

.media-thumb { display: block; object-fit: cover; }
.media-thumb-placeholder {
  display: grid;
  place-items: center;
  background: #e0edf0;
  color: var(--teal-deep);
  font-size: .78rem;
  font-weight: 740;
}

.media-card-info { display: grid; gap: .21rem; min-width: 0; }
.media-card-title { overflow-wrap: anywhere; font-size: .88rem; font-weight: 720; line-height: 1.36; }
.media-card-meta { overflow-wrap: anywhere; color: var(--muted); font-size: .76rem; line-height: 1.35; }

.media-photo-stage, .media-video-stage {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: clamp(10rem, 29vh, 17rem);
  padding: clamp(.62rem, 2vw, 1.2rem);
  border-top: 1px solid var(--line);
  background: #dce7ec;
}

.media-zoom-target {
  display: block;
  max-width: 100%;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #bdcfd8;
  border-radius: 6px;
  background: var(--paper);
  box-shadow: var(--shadow);
  cursor: zoom-in;
}

.media-photo {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(64vh, 55rem);
  max-height: min(64dvh, 55rem);
  object-fit: contain;
}

.media-video {
  display: block;
  width: 100%;
  max-width: 68rem;
  max-height: min(64vh, 53rem);
  max-height: min(64dvh, 53rem);
  aspect-ratio: auto 16 / 9;
  border-radius: 7px;
  background: var(--navy);
  color: var(--navy-text);
}

.media-empty, .media-error {
  width: 100%;
  padding: 1rem;
  border: 1px dashed #afc2cb;
  border-radius: 8px;
  background: var(--layer);
  color: var(--muted);
  overflow-wrap: anywhere;
}

.media-empty h2, .media-empty h3 { margin-bottom: .35rem; color: var(--ink); font-size: 1.12rem; }
.documents-layout.single-document > .media-empty { grid-column: 1 / -1; }
.media-error { max-width: 34rem; }

dialog.media-lightbox {
  width: min(calc(100% - 1.4rem), 83rem);
  max-height: calc(100vh - 1.4rem);
  max-height: calc(100dvh - 1.4rem);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 15px 64px rgb(12 29 42 / 28%);
}

dialog.media-lightbox[open] { display: flex; flex-direction: column; }
dialog.media-lightbox::backdrop { background: rgb(10 27 40 / 67%); }

.media-lightbox-bar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: .65rem;
  padding: .65rem .85rem;
  border-bottom: 1px solid var(--line);
}

.media-lightbox-bar h2 { min-width: 0; overflow-wrap: anywhere; font-size: 1.07rem; }
.media-lightbox-bar button { flex: none; }

.media-lightbox-body {
  display: grid;
  place-items: center;
  min-height: 0;
  min-width: 0;
  padding: clamp(.45rem, 1.8vw, 1rem);
  overflow: auto;
  background: #dce7ec;
}

.media-lightbox-body img {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100vh - 6rem);
  max-height: calc(100dvh - 6rem);
  object-fit: contain;
}

.is-presenting .media-photo, .is-presenting .media-video { max-height: 72vh; max-height: 72dvh; }

@media (max-width: 780px) {
  .media-filters { width: min(100%, 17rem); margin-bottom: .4rem; }
  .media-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(9.5rem, min(51vw, 14rem));
    gap: .3rem;
    max-height: none;
    overflow-x: auto;
    overscroll-behavior-x: contain;
  }
  .media-card { grid-template-columns: 3.15rem minmax(0, 1fr); gap: .43rem; }
}

@media (pointer: coarse) {
  .media-filter, .media-card { min-height: 44px; }
}

@media print {
  .media-video-stage, .media-lightbox { display: none !important; }
  .media-photo-stage { min-height: 0; border: 0; background: var(--paper); break-inside: avoid; }
  .media-zoom-target { border: 0; box-shadow: none; }
  .media-photo, .is-presenting .media-photo { max-height: 220mm; }
}
