.media-workspace {
  position: relative;
  min-height: 100vh;
  overflow: auto;
  padding: clamp(24px, 4vw, 52px);
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 12%, rgba(115, 122, 72, 0.16), transparent 30%),
    linear-gradient(rgba(239, 220, 178, 0.94), rgba(221, 194, 139, 0.96)),
    url('/assets/images/parchment.png') center / 520px;
}

.media-workspace::before {
  position: fixed;
  right: -110px;
  bottom: -90px;
  width: min(42vw, 520px);
  height: min(42vw, 520px);
  opacity: 0.1;
  background: url('/assets/images/heritage-tree-transparent.png') center / contain no-repeat;
  content: '';
  pointer-events: none;
}

.media-header,
.media-toolbar,
.media-results,
.media-status {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin-right: auto;
  margin-left: auto;
}

.media-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 24px;
  padding-bottom: 25px;
  border-bottom: 1px solid rgba(83, 64, 36, 0.28);
}

.media-header .eyebrow { margin: 0 0 4px; }
.media-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(38px, 5vw, 58px);
  font-weight: 500;
  line-height: 0.98;
}
.media-header p:last-child { margin: 8px 0 0; color: #705b3b; }
.media-header .button { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.media-header .button svg { width: 15px; height: 15px; }
.media-mobile-menu { display: none; }

.media-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(140px, auto) auto;
  gap: 12px;
  margin-top: 22px;
}

.media-search { position: relative; }
.media-search svg {
  position: absolute;
  top: 50%;
  left: 13px;
  z-index: 1;
  width: 17px;
  height: 17px;
  transform: translateY(-50%);
  pointer-events: none;
}
.media-search input { width: 100%; padding-left: 40px; }
.media-toolbar select { min-width: 150px; height: 42px; }

.media-view-toggle {
  display: flex;
  padding: 3px;
  border: 1px solid rgba(88, 64, 29, 0.28);
  border-radius: 9px;
  background: rgba(250, 235, 200, 0.36);
}
.media-view-toggle button {
  min-width: 70px;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  font-size: 11px;
  background: transparent;
}
.media-view-toggle button.active { background: rgba(81, 89, 53, 0.18); box-shadow: inset 0 0 0 1px rgba(75, 77, 44, 0.18); }

.media-status { min-height: 40px; padding: 14px 2px 8px; color: #6e5a3d; font-size: 12px; }
.media-status[data-error='true'] { color: #813e31; }
.media-status button { margin-left: 8px; color: inherit; text-decoration: underline; background: transparent; }

.media-results.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 18px;
}

.media-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(83, 61, 29, 0.3);
  border-radius: 13px;
  text-align: left;
  background: rgba(249, 233, 195, 0.5);
  box-shadow: 0 5px 15px rgba(61, 43, 21, 0.1);
  transition: transform 150ms ease, box-shadow 150ms ease;
}
.media-card:hover { transform: translateY(-2px); box-shadow: 0 9px 22px rgba(61, 43, 21, 0.15); }
.media-card:focus-visible { outline: 3px solid rgba(92, 99, 56, 0.55); outline-offset: 3px; }
.media-card-preview {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-bottom: 1px solid rgba(83, 61, 29, 0.22);
  color: #5e633c;
  background: linear-gradient(135deg, rgba(255,255,255,.25), rgba(101, 106, 63, .1));
}
.media-card-preview img { width: 100%; height: 100%; object-fit: cover; }
.media-document-mark { display: grid; place-items: center; width: 68px; height: 84px; border: 1px solid rgba(76, 79, 46, .36); border-radius: 5px; font: 600 14px/1 var(--font-body); background: rgba(248, 236, 204, .65); box-shadow: 5px 5px 0 rgba(83, 75, 45, .08); }
.media-card-copy { display: block; padding: 13px 14px 14px; }
.media-card-copy strong,
.media-card-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-card-copy strong { font-family: var(--font-display); font-size: 17px; font-weight: 500; }
.media-card-copy small { margin-top: 4px; color: #735f40; font-size: 10px; }

.media-results.media-list { display: grid; gap: 8px; }
.media-list .media-card { display: grid; grid-template-columns: 74px minmax(0, 1fr) auto; align-items: center; border-radius: 9px; }
.media-list .media-card-preview { aspect-ratio: 1; border: 0; border-right: 1px solid rgba(83, 61, 29, .2); }
.media-list .media-document-mark { width: 38px; height: 48px; font-size: 9px; }
.media-list .media-card-copy { min-width: 0; }
.media-list .media-card::after { margin-right: 17px; color: #756341; content: 'View details  ›'; font-size: 10px; }

.media-empty,
.media-loading {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 340px;
  padding: 45px;
  border: 1px dashed rgba(87, 64, 31, .36);
  border-radius: 16px;
  text-align: center;
  background: rgba(250, 236, 201, .22);
}
.media-empty svg { width: 42px; height: 42px; margin-bottom: 12px; color: #747847; }
.media-empty h2 { margin: 0; font-family: var(--font-display); font-size: 28px; font-weight: 500; }
.media-empty p { max-width: 410px; margin: 8px 0 18px; color: #725e3e; }
.media-loading::before { width: 28px; height: 28px; border: 3px solid rgba(84, 91, 52, .18); border-top-color: #62683f; border-radius: 50%; animation: media-spin .75s linear infinite; content: ''; }
@keyframes media-spin { to { transform: rotate(360deg); } }

.media-detail {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 50;
  width: min(480px, 100vw);
  overflow-y: auto;
  padding: 28px;
  border-left: 1px solid rgba(80, 58, 28, .36);
  background: linear-gradient(rgba(242, 224, 184, .98), rgba(226, 201, 151, .98)), url('/assets/images/parchment.png') center / 520px;
  box-shadow: -16px 0 40px rgba(47, 34, 19, .24);
}
.media-detail-close { position: sticky; top: 0; float: right; display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border-radius: 50%; background: rgba(246, 231, 195, .9); }
.media-detail-preview { clear: both; display: grid; place-items: center; min-height: 250px; max-height: 55vh; overflow: hidden; margin: 22px 0; border: 1px solid rgba(80, 58, 28, .3); border-radius: 10px; background: rgba(69, 61, 43, .1); }
.media-detail-preview img { width: 100%; max-height: 55vh; object-fit: contain; }
.media-detail-preview .media-document-mark { width: 92px; height: 118px; font-size: 18px; }
.media-detail h2 { overflow-wrap: anywhere; margin: 0; font-family: var(--font-display); font-size: 30px; font-weight: 500; }
.media-detail-caption { margin: 10px 0 18px; white-space: pre-wrap; }
.media-detail dl { display: grid; gap: 9px; margin: 0; padding: 15px 0; border-top: 1px solid rgba(80, 58, 28, .2); border-bottom: 1px solid rgba(80, 58, 28, .2); }
.media-detail dl div { display: grid; grid-template-columns: 105px 1fr; gap: 10px; }
.media-detail dt { color: #755f3e; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.media-detail dd { margin: 0; overflow-wrap: anywhere; font-size: 12px; }
.media-detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.media-detail-actions a { text-decoration: none; }
.media-detail-actions .button-danger { margin-left: auto; }

.media-dialog textarea { resize: vertical; }
.media-dialog label > span small,
.media-dialog legend small { display: inline; color: #775f3e; font-size: 9px; font-weight: 400; }
.media-file-field input { padding: 10px; border: 1px dashed rgba(84, 62, 31, .44); background: rgba(255, 244, 216, .2); }
.media-people-field { margin: 0; padding: 0; border: 0; }
.media-people-field legend { margin-bottom: 7px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
#media-people-options { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-height: 145px; overflow-y: auto; padding: 10px; border: 1px solid rgba(86, 63, 31, .24); border-radius: 9px; background: rgba(255, 246, 222, .2); }
#media-people-options label { display: flex; flex-direction: row; align-items: center; gap: 7px; min-width: 0; font-size: 11px; }
#media-people-options input { width: auto; margin: 0; }
#media-people-options span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-upload-progress { display: grid; gap: 6px; }
.media-upload-progress span { position: relative; height: 4px; overflow: hidden; border-radius: 4px; background: rgba(79, 84, 47, .16); }
.media-upload-progress span::after { position: absolute; inset: 0; width: 35%; background: #727747; animation: media-progress 1s ease-in-out infinite alternate; content: ''; }
.media-upload-progress p { margin: 0; color: #705b3c; font-size: 10px; }
@keyframes media-progress { to { transform: translateX(190%); } }

@media (max-width: 960px) {
  .media-mobile-menu { display: grid; align-self: start; }
  .media-header { grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; }
}

@media (max-width: 700px) {
  .media-workspace { padding: 18px 14px 30px; }
  .media-header { grid-template-columns: auto minmax(0, 1fr); gap: 12px; }
  .media-header h1 { font-size: 38px; }
  .media-header p:last-child { font-size: 11px; }
  .media-header .button { grid-column: 1 / -1; justify-content: center; width: 100%; }
  .media-toolbar { grid-template-columns: 1fr 1fr; }
  .media-search { grid-column: 1 / -1; }
  .media-toolbar select { width: 100%; min-width: 0; }
  .media-view-toggle button { min-width: 0; flex: 1; }
  .media-results.media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .media-card-copy { padding: 10px; }
  .media-card-copy strong { font-size: 14px; }
  .media-list .media-card { grid-template-columns: 62px minmax(0, 1fr); }
  .media-list .media-card::after { display: none; }
  .media-detail { top: auto; width: 100%; max-height: 92vh; padding: 20px; border-top: 1px solid rgba(80, 58, 28, .36); border-left: 0; border-radius: 20px 20px 0 0; }
  .media-detail-preview { min-height: 190px; }
  #media-people-options { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .media-results.media-grid { grid-template-columns: 1fr; }
}
