/**
 * MyVideoStudio — Gallery v2 (v1.28.0)
 *
 * Vanilla JS gallery integrated in the portal shell.
 * Layout: filter bar on top + responsive grid + lightbox modal.
 *
 * Scope: .mvs-galleryv2 root — no leakage.
 */

.mvs-galleryv2 {
  --mvs-gv-brand: #3C50E0;
  --mvs-gv-brand-hover: #2F40C7;
  --mvs-gv-bg: #FFFFFF;
  --mvs-gv-bg-alt: #F8FAFC;
  --mvs-gv-text: #1C2434;
  --mvs-gv-text-muted: #64748B;
  --mvs-gv-text-faint: #94A3B8;
  --mvs-gv-border: #E2E8F0;
  --mvs-gv-border-strong: #CBD5E1;
  --mvs-gv-success: #10B981;
  --mvs-gv-success-bg: #ECFDF5;
  --mvs-gv-warning: #F0950C;
  --mvs-gv-warning-bg: #FFFAEB;
  --mvs-gv-danger: #DC2626;
  --mvs-gv-danger-bg: #FEF2F2;

  font-family: inherit;
  color: var(--mvs-gv-text);
}

.mvs-galleryv2 *,
.mvs-galleryv2 *::before,
.mvs-galleryv2 *::after {
  box-sizing: border-box;
}

/* =====================================================================
   FILTER BAR
   ===================================================================== */

.mvs-galleryv2__toolbar {
  background: white;
  border: 1px solid var(--mvs-gv-border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.mvs-galleryv2__filters {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  background: var(--mvs-gv-bg-alt);
  padding: 4px;
  border-radius: 9px;
}

.mvs-galleryv2__filter {
  padding: 7px 14px;
  border-radius: 7px;
  background: transparent;
  border: 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--mvs-gv-text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  white-space: nowrap;
}

.mvs-galleryv2__filter:hover {
  color: var(--mvs-gv-text);
}

.mvs-galleryv2__filter--active {
  background: white;
  color: var(--mvs-gv-text);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}

.mvs-galleryv2__filter-count {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  background: var(--mvs-gv-bg-alt);
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--mvs-gv-text-faint);
  vertical-align: 1px;
}

.mvs-galleryv2__filter--active .mvs-galleryv2__filter-count {
  background: var(--mvs-gv-bg-alt);
  color: var(--mvs-gv-text-muted);
}

.mvs-galleryv2__search {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}

.mvs-galleryv2__search-input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--mvs-gv-border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--mvs-gv-text);
  background: white;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.mvs-galleryv2__search-input:focus {
  outline: 0;
  border-color: var(--mvs-gv-brand);
  box-shadow: 0 0 0 3px rgba(60, 80, 224, 0.1);
}

.mvs-galleryv2__search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--mvs-gv-text-faint);
  pointer-events: none;
}

.mvs-galleryv2__sort {
  height: 36px;
  padding: 0 30px 0 12px;
  border: 1px solid var(--mvs-gv-border);
  border-radius: 8px;
  background: white;
  font-size: 13px;
  color: var(--mvs-gv-text);
  cursor: pointer;
  font-family: inherit;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  appearance: none;
}

.mvs-galleryv2__toolbar-spacer {
  flex: 1;
}

.mvs-galleryv2__bulk-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--mvs-gv-bg-alt);
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--mvs-gv-text);
}

.mvs-galleryv2__bulk-bar[data-visible="1"] {
  display: inline-flex;
}

.mvs-galleryv2__bulk-count {
  font-weight: 600;
}

/* =====================================================================
   GRID
   ===================================================================== */

.mvs-galleryv2__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.mvs-galleryv2__card {
  position: relative;
  background: white;
  border: 1px solid var(--mvs-gv-border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  flex-direction: column;
}

.mvs-galleryv2__card:hover {
  border-color: var(--mvs-gv-border-strong);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.06);
}

.mvs-galleryv2__card[data-selected="1"] {
  border-color: var(--mvs-gv-brand);
  box-shadow: 0 0 0 3px rgba(60, 80, 224, 0.15);
}

.mvs-galleryv2__card-media {
  position: relative;
  aspect-ratio: 9 / 16;
  background: #0F172A;
  overflow: hidden;
}

.mvs-galleryv2__card-media video,
.mvs-galleryv2__card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.mvs-galleryv2__card-media-empty {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.4);
}

/* Play overlay shown on hover */
.mvs-galleryv2__card-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, transparent 50%, rgba(0,0,0,0.6) 100%);
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.mvs-galleryv2__card:hover .mvs-galleryv2__card-play {
  opacity: 1;
}

.mvs-galleryv2__card-play-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--mvs-gv-brand);
}

/* Selection checkbox */
.mvs-galleryv2__card-check {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 2;
  color: white;
}

.mvs-galleryv2__card:hover .mvs-galleryv2__card-check,
.mvs-galleryv2__card[data-selected="1"] .mvs-galleryv2__card-check {
  opacity: 1;
}

.mvs-galleryv2__card[data-selected="1"] .mvs-galleryv2__card-check {
  background: var(--mvs-gv-brand);
  border-color: var(--mvs-gv-brand);
}

/* Status badge */
.mvs-galleryv2__card-status {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  z-index: 1;
  backdrop-filter: blur(4px);
}

.mvs-galleryv2__card-status--completed {
  background: rgba(16, 185, 129, 0.9);
}

.mvs-galleryv2__card-status--processing {
  background: rgba(240, 149, 12, 0.9);
}

.mvs-galleryv2__card-status--failed {
  background: rgba(220, 38, 38, 0.9);
}

/* Card info */
.mvs-galleryv2__card-info {
  padding: 10px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mvs-galleryv2__card-prompt {
  font-size: 12.5px;
  color: var(--mvs-gv-text);
  margin: 0;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  text-overflow: ellipsis;
  min-height: 35px;
}

.mvs-galleryv2__card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  color: var(--mvs-gv-text-faint);
  margin-top: auto;
}

.mvs-galleryv2__card-meta-dot {
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: var(--mvs-gv-text-faint);
}

/* =====================================================================
   LOAD MORE
   ===================================================================== */

.mvs-galleryv2__load-more {
  display: flex;
  justify-content: center;
  margin-top: 22px;
}

.mvs-galleryv2__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 18px;
  height: 40px;
  border-radius: 8px;
  border: 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  font-family: inherit;
  white-space: nowrap;
}

.mvs-galleryv2__btn--primary {
  background: var(--mvs-gv-brand);
  color: white;
}

.mvs-galleryv2__btn--primary:hover {
  background: var(--mvs-gv-brand-hover);
}

.mvs-galleryv2__btn--outline {
  background: white;
  border: 1px solid var(--mvs-gv-border);
  color: var(--mvs-gv-text);
}

.mvs-galleryv2__btn--outline:hover {
  border-color: var(--mvs-gv-border-strong);
}

.mvs-galleryv2__btn--danger {
  background: var(--mvs-gv-danger);
  color: white;
}

.mvs-galleryv2__btn--ghost {
  background: transparent;
  color: var(--mvs-gv-text-muted);
}

.mvs-galleryv2__btn--ghost:hover {
  background: var(--mvs-gv-bg-alt);
  color: var(--mvs-gv-text);
}

.mvs-galleryv2__btn--sm {
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

.mvs-galleryv2__btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.mvs-galleryv2__spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: mvs-gv-spin 0.7s linear infinite;
}

.mvs-galleryv2__btn[data-busy] .mvs-galleryv2__spinner {
  display: inline-block;
}

@keyframes mvs-gv-spin {
  to { transform: rotate(360deg); }
}

/* =====================================================================
   EMPTY STATE / LOADING
   ===================================================================== */

.mvs-galleryv2__empty {
  background: white;
  border: 1px dashed var(--mvs-gv-border-strong);
  border-radius: 14px;
  padding: 56px 24px;
  text-align: center;
  color: var(--mvs-gv-text-muted);
}

.mvs-galleryv2__empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--mvs-gv-bg-alt);
  color: var(--mvs-gv-text-faint);
  margin-bottom: 16px;
}

.mvs-galleryv2__empty-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--mvs-gv-text);
}

.mvs-galleryv2__empty-body {
  font-size: 13.5px;
  margin: 0 0 20px;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.5;
}

.mvs-galleryv2__loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--mvs-gv-text-muted);
  font-size: 13px;
}

.mvs-galleryv2__loading-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--mvs-gv-border);
  border-top-color: var(--mvs-gv-brand);
  border-radius: 50%;
  animation: mvs-gv-spin 0.7s linear infinite;
  margin-bottom: 10px;
}

/* =====================================================================
   LIGHTBOX MODAL
   ===================================================================== */

.mvs-galleryv2__modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(6px);
  z-index: 9999;
  padding: 24px;
  align-items: center;
  justify-content: center;
  overscroll-behavior: contain;
}

.mvs-galleryv2__modal[data-open="1"] {
  display: flex;
}

.mvs-galleryv2__modal-content {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 980px;
  max-height: calc(100vh - 48px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
}

.mvs-galleryv2__modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  border: 0;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: background 0.15s ease;
}

.mvs-galleryv2__modal-close:hover {
  background: rgba(0, 0, 0, 0.85);
}

.mvs-galleryv2__modal-media {
  background: #0F172A;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  position: relative;
}

.mvs-galleryv2__modal-media video,
.mvs-galleryv2__modal-media img {
  max-width: 100%;
  max-height: 70vh;
  display: block;
  object-fit: contain;
}

.mvs-galleryv2__modal-side {
  padding: 24px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.mvs-galleryv2__modal-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--mvs-gv-bg-alt);
  color: var(--mvs-gv-text-muted);
  margin-bottom: 14px;
  align-self: flex-start;
}

.mvs-galleryv2__modal-status--completed { background: var(--mvs-gv-success-bg); color: #065F46; }
.mvs-galleryv2__modal-status--processing { background: var(--mvs-gv-warning-bg); color: #92400E; }
.mvs-galleryv2__modal-status--failed { background: var(--mvs-gv-danger-bg); color: var(--mvs-gv-danger); }

.mvs-galleryv2__modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--mvs-gv-text-muted);
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mvs-galleryv2__modal-prompt {
  font-size: 14px;
  color: var(--mvs-gv-text);
  margin: 0 0 18px;
  line-height: 1.55;
  background: var(--mvs-gv-bg-alt);
  padding: 12px 14px;
  border-radius: 9px;
  border-left: 3px solid var(--mvs-gv-brand);
}

.mvs-galleryv2__modal-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  margin-bottom: 22px;
}

.mvs-galleryv2__modal-meta-item {
  font-size: 12px;
}

.mvs-galleryv2__modal-meta-label {
  color: var(--mvs-gv-text-faint);
  font-weight: 500;
  margin-bottom: 2px;
}

.mvs-galleryv2__modal-meta-value {
  color: var(--mvs-gv-text);
  font-weight: 600;
}

.mvs-galleryv2__modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */

@media (max-width: 1199px) {
  .mvs-galleryv2__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 899px) {
  .mvs-galleryv2__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .mvs-galleryv2__modal-content {
    grid-template-columns: 1fr;
    max-height: calc(100vh - 24px);
  }
  .mvs-galleryv2__modal-media {
    min-height: 280px;
  }
  .mvs-galleryv2__modal-media video,
  .mvs-galleryv2__modal-media img {
    max-height: 50vh;
  }
  .mvs-galleryv2__modal-side {
    padding: 18px;
  }
}

@media (max-width: 599px) {
  .mvs-galleryv2__toolbar {
    padding: 12px;
    gap: 8px;
  }
  .mvs-galleryv2__filters {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .mvs-galleryv2__search {
    max-width: none;
  }
  .mvs-galleryv2__grid {
    gap: 10px;
  }
  .mvs-galleryv2__card-prompt {
    font-size: 12px;
  }
  .mvs-galleryv2__modal {
    padding: 0;
  }
  .mvs-galleryv2__modal-content {
    border-radius: 0;
    max-height: 100vh;
    height: 100vh;
  }
  /* iOS anti-zoom */
  .mvs-galleryv2__search-input,
  .mvs-galleryv2__sort {
    font-size: 16px;
  }
}

@media (max-width: 379px) {
  .mvs-galleryv2__grid {
    grid-template-columns: 1fr;
  }
}
