/**
 * Shared media preview + courseware cards (Media Library, Admin Media Manager, reports).
 * Theme: pages set --accent, --text, --text-muted, --card-bg on :root.
 */

:root {
  --th-card-accent: var(--accent, #e4f91b);
  --th-mpv-radius: 10px;
  --th-card-max: 380px;
  --th-preview-max-h: 200px;
  --th-chip-drill-bg: rgba(245, 158, 11, 0.18);
  --th-chip-drill-fg: #fbbf24;
  --th-chip-drill-border: rgba(251, 191, 36, 0.35);
  --th-chip-common-bg: rgba(56, 189, 248, 0.12);
  --th-chip-common-fg: #7dd3fc;
  --th-chip-common-border: rgba(125, 211, 252, 0.3);
  --th-chip-personal-bg: rgba(228, 249, 27, 0.12);
  --th-chip-personal-fg: #e4f91b;
  --th-chip-personal-border: rgba(228, 249, 27, 0.35);
  --th-chip-match-bg: rgba(167, 139, 250, 0.14);
  --th-chip-match-fg: #c4b5fd;
  --th-chip-match-border: rgba(196, 181, 253, 0.35);
  --th-chip-shared-bg: rgba(52, 211, 153, 0.12);
  --th-chip-shared-fg: #6ee7b7;
  --th-chip-shared-border: rgba(110, 231, 183, 0.3);
}

/* ── ThMediaPlayback embed previews ── */

.th-mpv {
  position: relative;
  margin: 0;
  overflow: hidden;
  border-radius: var(--th-mpv-radius);
  background: rgba(0, 0, 0, 0.22);
  width: 100%;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.th-mpv--loading {
  min-height: 56px;
  aspect-ratio: 16 / 9;
  max-height: var(--th-preview-max-h);
}

.th-mpv--loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0.08) 45%, rgba(255,255,255,0.03) 90%);
  background-size: 200% 100%;
  animation: th-mpv-shimmer 1.3s ease-in-out infinite;
}

@keyframes th-mpv-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .th-mpv--loading::after { animation: none; background: rgba(255,255,255,0.05); }
}

.th-mpv__iframe {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  max-height: var(--th-preview-max-h);
  height: auto;
  min-height: 0;
  border: none;
  border-radius: var(--th-mpv-radius);
  background: #000;
  display: block;
}

.th-mpv--compact .th-mpv__iframe,
.th-mpv--compact.th-mpv--loading { max-height: 130px; }
.th-mpv--compact.th-mpv--loading { min-height: 48px; }

.th-mpv__iframe--doc { aspect-ratio: auto; min-height: 240px; max-height: min(50vh, 400px); }
.th-mpv__img { max-width: 100%; max-height: var(--th-preview-max-h); object-fit: contain; border-radius: var(--th-mpv-radius); display: block; margin: 0 auto; }
.th-mpv__audio { width: 100%; }

.th-mpv__fallback {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: var(--th-preview-max-h);
  border-radius: var(--th-mpv-radius);
  overflow: hidden;
  background: #111;
}

.th-mpv__poster { width: 100%; height: 100%; object-fit: cover; display: block; }

.th-mpv__play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-height: 36px;
  min-width: 36px;
  z-index: 2;
  cursor: pointer;
  border: none;
  border-radius: 999px;
  font-weight: 700;
  padding: 8px 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  background: rgba(255, 255, 255, 0.94);
  color: #111;
  font-size: 13px;
}
.th-mpv__play:focus-visible { outline: 2px solid var(--th-card-accent); outline-offset: 2px; }
.th-mpv__err { color: #f87171; font-size: 12px; padding: 10px; text-align: center; }

/* ── Source chips ── */

.th-media-card__source {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  line-height: 1.2;
}
.th-media-card__source svg { width: 11px; height: 11px; flex-shrink: 0; }

.th-media-card__source--drill   { background: var(--th-chip-drill-bg);    color: var(--th-chip-drill-fg);    border-color: var(--th-chip-drill-border); }
.th-media-card__source--common  { background: var(--th-chip-common-bg);   color: var(--th-chip-common-fg);   border-color: var(--th-chip-common-border); }
.th-media-card__source--personal{ background: var(--th-chip-personal-bg); color: var(--th-chip-personal-fg); border-color: var(--th-chip-personal-border); }
.th-media-card__source--match   { background: var(--th-chip-match-bg);    color: var(--th-chip-match-fg);    border-color: var(--th-chip-match-border); }
.th-media-card__source--shared  { background: var(--th-chip-shared-bg);   color: var(--th-chip-shared-fg);   border-color: var(--th-chip-shared-border); }

/* ── Courseware card — Material Design surface ── */

.cw-card {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.15);
  transition: box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              background 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.cw-card:hover {
  background: rgba(255, 255, 255, 0.09);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.32), 0 2px 4px rgba(0, 0, 0, 0.2);
  transform: translateY(-1px);
}

/* ── Visual area ── */

.cw-card__visual {
  position: relative;
  width: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cw-card__visual--av {
  aspect-ratio: 16 / 9;
  background: rgba(0, 0, 0, 0.3);
}
.cw-card__visual--compact {
  height: 68px;
}
.cw-card__visual--compact > svg {
  width: 26px;
  height: 26px;
  opacity: 0.6;
}
.cw-card__visual--audio-bg {
  background: linear-gradient(135deg, rgba(251, 146, 60, 0.14) 0%, rgba(217, 119, 6, 0.06) 100%);
  color: #fdba74;
}
.cw-card__visual--doc-bg {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.1) 0%, rgba(99, 102, 241, 0.05) 100%);
  color: #7dd3fc;
}
.cw-card__visual--pdf-bg {
  background: linear-gradient(135deg, rgba(248, 113, 113, 0.12) 0%, rgba(239, 68, 68, 0.04) 100%);
  color: #fca5a5;
}

.cw-card__visual iframe,
.cw-card__visual video {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  object-fit: contain;
}
.cw-card__visual img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.cw-card__visual audio {
  width: calc(100% - 16px);
  margin: 0 8px;
  display: block;
}

.cw-card__visual--loading { min-height: 44px; }
.cw-card__visual--loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 0%, rgba(255,255,255,0.04) 45%, transparent 90%);
  background-size: 200% 100%;
  animation: th-mpv-shimmer 1.3s ease-in-out infinite;
  pointer-events: none;
}

/* ThMediaPlayback widget inside visual — override its sizing */
.cw-card__visual .th-mpv {
  border-radius: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: unset;
  max-height: none;
  min-height: 0;
  background: transparent;
}
.cw-card__visual .th-mpv--loading {
  aspect-ratio: unset;
  max-height: none;
  min-height: 0;
}
.cw-card__visual .th-mpv--loading::after { display: none; }
.cw-card__visual .th-mpv__iframe,
.cw-card__visual .th-mpv__img { max-height: none; border-radius: 0; }
.cw-card__visual .th-mpv__fallback { max-height: none; aspect-ratio: unset; }
.cw-card__visual .th-mpv__audio { width: calc(100% - 16px); margin: 0 8px; }

/* ── Info header ── */

.cw-card__header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px 4px;
}

.cw-card__icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cw-card__icon svg { width: 15px; height: 15px; }
.cw-card__icon--video    { background: rgba(139, 92, 246, 0.2); color: #c4b5fd; }
.cw-card__icon--audio    { background: rgba(251, 146, 60, 0.2); color: #fdba74; }
.cw-card__icon--image    { background: rgba(34, 197, 94, 0.18); color: #86efac; }
.cw-card__icon--document { background: rgba(56, 189, 248, 0.16); color: #7dd3fc; }
.cw-card__icon--pdf      { background: rgba(248, 113, 113, 0.18); color: #fca5a5; }

.cw-card__text { flex: 1; min-width: 0; }

.cw-card__title {
  font-weight: 600;
  font-size: 12.5px;
  line-height: 1.3;
  color: var(--text, #fff);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.cw-card__meta {
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.4);
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}

/* ── Actions — Material text-button style ── */

.cw-card__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 2px 8px 8px;
  margin-top: auto;
}

.cw-card__actions a,
.cw-card__actions button {
  font-size: 10.5px;
  padding: 4px 8px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: color-mix(in srgb, var(--accent, #e4f91b) 85%, white);
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.3;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  transition: background 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}
.cw-card__actions a:hover,
.cw-card__actions button:hover {
  background: rgba(255, 255, 255, 0.08);
}
.cw-card__actions .cw-action--danger {
  color: #fca5a5;
}
.cw-card__actions .cw-action--danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* ── Courseware grid ── */

.cw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: 12px;
  align-items: start;
}

/* ── Legacy compat: old class names still used in reports ── */

.th-media-card,
.media-manager-card.th-media-card {
  background: rgba(0, 0, 0, 0.34);
  border-radius: 12px;
  padding: 12px 12px 10px;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.2);
  max-width: var(--th-card-max);
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.th-media-card:hover,
.media-manager-card.th-media-card:hover {
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.28);
}

.th-media-card__icon, .media-manager-card-icon { flex-shrink: 0; width: 28px; height: 28px; min-width: 28px; display: flex; align-items: center; justify-content: center; font-size: 14px; line-height: 1; background: rgba(255,255,255,0.06); border-radius: 6px; border: 1px solid rgba(255,255,255,0.06); }
.th-media-card__body, .media-manager-card-body { flex: 1; min-width: 0; }
.th-media-card__source-row { margin-bottom: 6px; }
.th-media-card__title, .media-manager-card-title { font-weight: 600; font-size: 0.95rem; margin-bottom: 2px; word-break: break-word; line-height: 1.3; }
.th-media-card__meta, .media-manager-card-meta { font-size: 11px; color: rgba(255,255,255,0.55); margin-bottom: 6px; line-height: 1.35; }
.th-media-card__media, .media-manager-preview { margin: 6px 0 0; overflow: hidden; border-radius: var(--th-mpv-radius); width: 100%; max-width: 100%; }
.th-media-card__actions, .media-manager-card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.th-media-grid, .media-manager-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: clamp(12px, 1.5vw, 18px); justify-items: stretch; }

/* ── Report video embeds ── */

.th-report-video { width: 100%; max-width: min(100%, 720px); margin: 0 auto; border-radius: var(--th-mpv-radius); overflow: hidden; background: #000; }
.th-report-video__iframe, .expert-video-wrapper.th-report-video iframe { display: block; width: 100%; aspect-ratio: 16 / 9; max-height: min(50vh, 360px); border: none; border-radius: var(--th-mpv-radius); background: #000; }
