/**
 * Comic Card V2 Styles
 *
 * Modern styling for the comic card system with responsive design,
 * proper hover effects, and accessibility support.
 *
 * @version 2.0.0
 * @author VeryOlivia Development Team
 * @since August 12, 2025
 */

/* ===== COMIC CARD STYLES ===== */

.comic-card-v2 {
  transition: all 0.3s ease;
  border: 1px solid rgb(0 0 0 / 12.5%);
  box-shadow: 0 2px 4px rgb(0 0 0 / 10%);
}

.comic-card-v2:hover {
  transform: scale(1.01) translateY(-1px);
  box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
}

.comic-card-v2 .card-img-top {
  transition: transform 0.3s ease;
  /* No height restriction - show natural aspect ratio like V1 */
  width: 100%;
  height: auto;
  /* Use object-fit: cover only when height is constrained */
}

/* Episode Buttons Container */
.comic-episodes-container .comic-episode-btn {
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  transition: all 0.3s ease;
}

.comic-episodes-container .comic-episode-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgb(0 0 0 / 20%);
}

/* Age rating badge positioning */
.comic-card-v2 .position-absolute {
  z-index: 2;
}

/* ===== COMIC MODAL STYLES ===== */

#comic-modal-v2 {
  z-index: 1055;
  /* Higher than Bootstrap's modal backdrop (1050) */
}

#comic-modal-v2 .modal-dialog {
  z-index: 1056;
  /* Ensure dialog is above everything */
  position: relative;
}

#comic-modal-v2 .modal-content {
  z-index: 1057;
  /* Ensure content is above everything */
  position: relative;
}

#comic-modal-v2 .modal-header {
  border-bottom-color: transparent;
}

#comic-modal-v2 .modal-footer {
  border-top-color: transparent;
}

#comic-modal-body {
  height: 70vh;
}

/* ===== SWIPER CUSTOMIZATION ===== */

/* Main swiper image fitting - prevent cropping, show full image */
.main-swiper .swiper-slide img,
.main-swiper .swiper-slide picture img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  /* Prevent drag but allow navigation clicks */
}

/* Ensure navigation elements are always clickable */
.main-swiper .swiper-button-next,
.main-swiper .swiper-button-prev,
.main-swiper .swiper-pagination,
.main-swiper .swiper-pagination-bullet,
.thumbs-swiper .swiper-slide,
.thumbs-swiper .swiper-slide img,
.thumbs-swiper .swiper-slide picture,
.thumbs-swiper .swiper-slide picture img {
  pointer-events: auto !important;
  z-index: 10;
}

/* ===== THUMBNAIL SWIPER STYLES ===== */

/* Minimal thumbnail customization - keep thumbnails clickable */
.thumbs-swiper .swiper-slide {
  width: auto;
  height: 100px;
  opacity: 0.4;
  cursor: pointer;
  margin-right: 10px;
  pointer-events: auto !important;
  transition: opacity 0.3s ease;
  touch-action: pan-x !important;
  user-select: none;
  flex-shrink: 0;
  /* Natural aspect ratio constraints for comic thumbnails */
  min-width: 60px;
  max-width: 120px;
  aspect-ratio: 3/4; /* Typical comic page ratio */
}

/* Ensure thumbnails swiper itself allows touch */
.thumbs-swiper {
  touch-action: pan-x !important;
  cursor: grab;
  padding: 0 15px;
  box-sizing: border-box;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
}

.thumbs-swiper .swiper-wrapper {
  max-width: 100%;
  overflow: visible;
  align-items: center;
}

.thumbs-swiper:active {
  cursor: grabbing;
}

.thumbs-swiper .swiper-slide-thumb-active {
  opacity: 1;
}

/* Comic Thumbnail Images - Maintain aspect ratio */
.comic-thumb-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid transparent;
  pointer-events: auto;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.thumbs-swiper .swiper-slide-thumb-active .comic-thumb-image {
  border-color: var(--bs-primary, #0d6efd);
}

.thumbs-swiper .swiper-slide-thumb-active .comic-thumb-image {
  border-color: var(--bs-primary, #0d6efd);
}

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

/* Bootstrap 5 aligned responsive adjustments */

/* Small devices (sm) - up to 576px */
@media (width < 576px) {
  #comic-modal-v2 .modal-header h5 {
    font-size: 1rem;
  }

  #comic-modal-v2 .modal-footer {
    padding: 0.5rem;
  }

  #comic-modal-v2 .modal-footer .btn {
    font-size: 0.75rem;
    padding: 0.375rem 0.75rem;
  }

  /* Small modal thumbnails - 3 per row */
  .thumbs-swiper .swiper-slide {
    height: 70px;
    min-width: 50px;
    max-width: 80px;
  }

  .thumbs-swiper {
    padding: 0 10px;
  }
}

/* Medium devices (md) - 576px to 768px */
@media (576px <= width < 768px) {
  /* Default modal size thumbnails - 5 per row */
  .thumbs-swiper .swiper-slide {
    height: 80px;
    min-width: 55px;
    max-width: 90px;
  }
}

/* Large devices (lg) - 768px to 992px */
@media (768px <= width < 992px) {
  #comic-modal-v2 .modal-body {
    padding: 0;
  }

  #comic-modal-v2 .modal-footer {
    padding: 0.75rem;
  }

  #comic-modal-v2 .modal-footer .btn {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
  }

  /* Large modal size thumbnails - 6 per row */
  .thumbs-swiper .swiper-slide {
    height: 90px;
    min-width: 60px;
    max-width: 100px;
  }
}

/* Extra large devices (xl) - 992px to 1200px */
@media (992px <= width < 1200px) {
  /* XL modal approaching full width - 7 per row */
  .thumbs-swiper .swiper-slide {
    height: 95px;
    min-width: 65px;
    max-width: 110px;
  }
}

/* XXL devices (xxl) - 1200px and up */
@media (width >= 1200px) {
  /* XL modal at full 1140px width - 9-10 per row */
  .thumbs-swiper .swiper-slide {
    height: 100px;
    min-width: 70px;
    max-width: 120px;
  }

  .thumbs-swiper {
    padding: 0 20px;
  }
}

/* ===== ACCESSIBILITY ===== */

.comic-card-v2 .comic-card-btn:focus {
  box-shadow: 0 0 0 0.2rem rgb(0 123 255 / 25%);
}

/* ===== LOADING STATES ===== */

.comic-card-v2.loading {
  opacity: 0.7;
  pointer-events: none;
}

.comic-card-v2.loading .comic-card-btn {
  position: relative;
}

.comic-card-v2.loading .comic-card-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid transparent;
  border-top-color: currentcolor;
  border-radius: 50%;
  animation: comic-loading 1s linear infinite;
}

@keyframes comic-loading {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* ===== ERROR STATES ===== */

.comic-card-v2.error {
  border-color: #dc3545;
}

.comic-card-v2.error .card-body {
  text-align: center;
}

/* ===== UTILITY CLASSES ===== */

.comic-card-v2.compact .card-body {
  padding: 1rem 0.75rem;
}

.comic-card-v2.compact .card-title {
  font-size: 1rem;
}

.comic-card-v2.compact .card-text {
  font-size: 0.875rem;
}

/* Dark mode support
@media (prefers-color-scheme: dark) {
  .comic-card-v2 {
    background-color: #2d2d2d;
    border-color: #404040;
    color: #fff;
  }

  .comic-card-v2 .text-muted {
    color: #b6b6b6 !important;
  }

  .comic-card-v2:hover {
    border-color: #505050;
  }
} */

/* ===== COMIC MODAL V2 STYLES - BOOTSTRAP XL + FIXED LAYOUT ===== */

/* Style the picture element to work with flex layout */
.main-swiper .swiper-slide picture {
  display: flex;
  height: 100%;
  width: auto;
  align-items: center;
  justify-content: center;
}

/* Swiper Container - Full height layout */
.swiper-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Important for flex child */
  overflow: hidden;
  width: 100%;
  max-width: 100%;
}

/* Main Swiper - Explicit height calculation */
.main-swiper {
  flex: 1;
  width: 100%;
  min-height: 0;
  /* Critical for flex child to shrink properly */
  height: calc(100% - 120px);
  /* Explicit: total height minus thumbnail area */
  /* Leverage bootstrap theme token to swiper css */
  --swiper-theme-color: var(--bs-primary);
  --swiper-pagination-bullet-inactive-color: var(--bs-secondary);
}

/* Main Swiper Slides - Proper image containment */
.main-swiper .swiper-slide {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  background-color: #f8f9fa;
  padding: 15px;
  height: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

/* Grid container for image containment - override flex layout */
.main-swiper .swiper-slide .comic-image-grid {
  display: grid !important;
  width: 100%;
  height: 100%;
  place-items: center;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  min-height: 0;
  min-width: 0;
  flex: none;
}

/* Position the picture element in the grid */
.comic-image-grid picture {
  grid-area: 1 / 1;
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
}

/* Custom image styling - optimal display with full size */
.comic-main-image {
  /* Height-first approach: let image determine its own height within container */
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  display: block;
}

/* Responsive */
@media (width <=768px) {
  #comic-modal-v2 .modal-dialog {
    max-width: 95vw;
    margin: 0.5rem;
  }

  #comic-modal-v2 .modal-body {
    height: 60vh;
  }

  .thumbs-swiper {
    height: 80px;
  }
}
