/*
 * File: /assets/css/videos.css
 * Version: 4.2 (patched)
 * Scope: .videos-page
 * Description: Video grid & player styles (YouTube-like, SEO/UX optimized)
 */

/* ===============================================
 * 1. LAYOUT & GRID SYSTEM
 * =============================================== */
.videos-page .video-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-lg);
  margin: 0;
  padding: 0;
}

@media (max-width: 1400px) {
  .videos-page .video-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 992px) {
  .videos-page .video-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-md); }
}
@media (max-width: 560px) {
  .videos-page .video-grid { grid-template-columns: 1fr; gap: var(--space-md); }
}

/* Hide hero image on video detail page */
.videos-page .entry-image { display: none; }

/* ===============================================
 * 2. VIDEO CARD COMPONENT
 * =============================================== */
.videos-page .video-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  cursor: pointer;
  border-radius: var(--border-radius-lg);
  transition: transform var(--transition-duration-base) var(--transition-timing-function),
              box-shadow var(--transition-duration-base) var(--transition-timing-function);
}
.videos-page .video-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--box-shadow-md);
}

/* Thumbnail */
.videos-page .post_thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--border-radius-lg);
  background-color: var(--color-background-alt);
  overflow: hidden;
}
.videos-page .post_thumb img,
.videos-page .post_thumb picture {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-duration-base) ease,
              filter var(--transition-duration-base) ease;
  will-change: transform;
}
.videos-page .video-card:hover .post_thumb img {
  transform: scale(1.03);
  filter: saturate(1.05);
}

/* Play overlay */
.videos-page .post_thumb .play {
  position: absolute;
  pointer-events: none;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(transparent 45%, rgba(0,0,0,0.25));
  opacity: 0;
  transition: opacity var(--transition-duration-base);
}
.videos-page .video-card:hover .post_thumb .play { opacity: 1; }
.videos-page .post_thumb .play svg {
  width: 56px; height: 56px;
  fill: var(--color-white);
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.6));
}

/* Duration badge (for video cards) */
.videos-page .video-card .duration_video {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background-color: rgba(var(--color-black-rgb), 0.75);
  color: var(--color-white);
  font-size: var(--font-size-sm);
  padding: 3px 6px;
  border-radius: var(--border-radius-sm);
}

/* ===============================================
 * 3. VIDEO DETAILS
 * =============================================== */
.videos-page .video-details {
  display: flex;
  flex-direction: column;
  gap: var(--space-xxs);
  padding: 0 var(--space-xs);
}
.videos-page h2.post_title {
  font-size: 1rem;
  font-weight: var(--font-weight-semibold);
  line-height: 1.4;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: calc(2 * 1.4em);
}
.videos-page h2.post_title a {
  color: var(--color-heading);
  text-decoration: none;
  transition: color var(--transition-duration-fast);
}
.videos-page .video-text-meta {
  display: flex;
  flex-direction: column;
  gap: var(--space-xxs);
}
.videos-page .channel-name {
  font-size: var(--font-size-sm);
  color: var(--color-grey);
  margin: 0;
}
.videos-page .video-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-size-sm);
  color: var(--color-grey);
  line-height: 1.4;
}
.videos-page .video-meta .views::after {
  content: "•";
  margin: 0 4px;
}

/* ===============================================
 * 4. ACCESSIBILITY & INTERACTIONS
 * =============================================== */
.videos-page .video-card a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--border-radius-sm);
}
.videos-page .post_thumb .play:focus-visible,
.videos-page .post_thumb button.play:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 50%;
}

/* ===============================================
 * 5. RELATED VIDEOS SECTION
 * =============================================== */
.videos-page .related-videos {
  margin-top: var(--space-xl);
}
.videos-page .related-videos h2 {
  font-size: 1rem;
  font-weight: var(--font-weight-semibold);
  line-height: 1.4;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: calc(2 * 1.4em);
}

/* ===============================================
 * 6. LOADING & SENTINEL HELPERS
 * =============================================== */
.videos-page .video-grid[aria-busy="true"]::after {
  content: "";
  display: block;
  width: 32px; height: 32px;
  margin: var(--space-md) auto;
  border-radius: 50%;
  border: 3px solid rgba(0,0,0,0.15);
  border-top-color: var(--color-primary);
  animation: vg-spin 0.8s linear infinite;
  will-change: transform;
}
.videos-page .video-grid[aria-busy="true"]::before {
  content: "Đang tải thêm video…";
  display: block;
  text-align: center;
  color: var(--color-grey);
  margin-bottom: var(--space-md);
}
@keyframes vg-spin { to { transform: rotate(360deg); } }

.videos-page .video-grid > div[aria-hidden="true"],
.videos-page #related-container > div[aria-hidden="true"] {
  height: 1px !important;
  visibility: hidden !important;
  margin: 0 !important;
  width: 100% !important;
}

/* ===============================================
 * 7. PLAYER
 * =============================================== */
.video-player {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background-color: #000;
}
.video-player picture,
.video-player img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.video-player iframe {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  border: none;
}
.video-player .play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 2;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  pointer-events: auto;
  transition: background-color 0.2s ease;
}
.video-player .play svg {
  width: 64px;
  height: 64px;
  fill: white;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.6));
  transition: transform 0.2s ease;
}
.video-player:hover .play {
  background: radial-gradient(circle, transparent 40%, rgba(0,0,0,0.3));
}
.video-player .play:hover svg,
.video-player .play:focus-visible svg {
  transform: scale(1.1);
}

/* Duration badge for player (NEW) */
.video-player .duration_video {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background-color: rgba(0,0,0,0.75);
  color: #fff;
  font-size: var(--font-size-sm);
  padding: 3px 6px;
  border-radius: var(--border-radius-sm);
  z-index: 3;
}

/* ===============================================
 * 8. MINOR TWEAKS
 * =============================================== */
@media (prefers-reduced-motion: reduce) {
  .videos-page .video-card,
  .videos-page .post_thumb img,
  .videos-page .post_thumb .play,
  .video-player .play svg {
    transition: none;
  }
}

/* Utility margins for article body */
.videos-page .article-body .mt-4 { margin-top: var(--space-md); }
.videos-page .article-body .mt-5 { margin-top: var(--space-xl); }

/* ===============================================
 * 9. PAGE-SPECIFIC SEARCH
 * =============================================== */
.videos-page .video-search-section {
    margin-top: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.videos-page .video-page-search-form {
    margin-left: auto;
    margin-right: auto;
    max-width: 600px;
    display: flex;
    gap: var(--space-xs);
}
.videos-page .video-page-search-form input[type="search"] {
    flex: 1;
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-base);
}
.videos-page .video-page-search-form button {
    background-color: var(--color-primary);
    color: var(--color-white);
    border: none;
    border-radius: var(--border-radius-sm);
    padding: 0 var(--space-sm);
    cursor: pointer;
    transition: background-color var(--transition-duration-fast);
}
.videos-page .video-page-search-form button:hover {
    background-color: var(--color-primary-dark);
}