/* ========================================
   MODAL & CAROUSEL STYLES - LIBRARY SYSTEM
   Adapted from Portfolio Theme
   ======================================== */

/* ===== MODAL (LIBRARY ITEM QUICK VIEW) ===== */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 999;
  padding: 16px;
  align-items: center;
  justify-content: center;
}

.modal.open {
  display: flex;
}

.modal-card {
  width: min(1200px, 96vw);
  max-height: 90vh;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(10, 12, 18, 0.95);
  backdrop-filter: blur(16px);
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.7);
  overflow: hidden;
  max-width: 100%;
  display: flex;
  flex-direction: column;
}

.modal-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(11, 15, 22, 0.8);
}

.modal-title-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-left: 6px;
  flex: 1;
  min-width: 0;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-subtitle {
  font-size: 14px;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.xbtn {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 20px;
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
}

.xbtn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(1.05);
}

.modal-content-wrapper {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

.modal-media {
  display: grid;
  grid-template-columns: 1.6fr 0.4fr;
  gap: 0;
  flex: 1;
  min-height: 520px;
  overflow: hidden;
}

.modal-media.video-active {
  grid-template-columns: 1fr;
}

.modal-media.video-active .modal-side {
  display: none;
}

.modal-media.video-active .modal-main {
  min-height: 65vh;
}

.modal-main {
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.modal-main img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  max-height: 70vh;
  display: block;
  background: rgba(0, 0, 0, 0.3);
}

.modal-main video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  max-height: 70vh;
  background: #000;
}

/* Navigation buttons for image gallery */
.navbtn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 20px;
  transition: all 0.3s var(--ease);
  z-index: 10;
}

.navbtn:hover {
  background: rgba(125, 211, 252, 0.3);
  border-color: var(--accent);
  transform: translateY(-50%) scale(1.1);
}

.navbtn:active {
  transform: translateY(-50%) scale(0.95);
}

.navbtn.prev {
  left: 16px;
}

.navbtn.next {
  right: 16px;
}

.navbtn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

/* Sidebar thumbnails */
.modal-side {
  border-left: 1px solid rgba(255, 255, 255, 0.10);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(255, 255, 255, 0.02);
  overflow-y: auto;
  max-height: 100%;
}

.modal-side::-webkit-scrollbar {
  width: 6px;
}

.modal-side::-webkit-scrollbar-thumb {
  background: rgba(125, 211, 252, 0.3);
  border-radius: 3px;
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.tmini {
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 4 / 3;
  transition: all 0.3s var(--ease);
}

.tmini:hover {
  border-color: rgba(125, 211, 252, 0.5);
  transform: scale(1.05);
}

.tmini img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tmini.active {
  border-color: var(--accent);
  background: rgba(125, 211, 252, 0.15);
  box-shadow: 0 0 0 2px rgba(125, 211, 252, 0.3);
}

.side-note {
  color: var(--muted);
  font-size: 13px;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Modal footer with download action */
.modal-footer {
  padding: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(11, 15, 22, 0.8);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.modal-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-file-info {
  font-size: 14px;
  color: var(--muted);
}

.modal-file-size {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), rgba(125, 211, 252, 0.8));
  color: #000;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  border: none;
  transition: all 0.3s var(--ease);
  box-shadow: 0 4px 16px rgba(125, 211, 252, 0.3);
}

.download-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(125, 211, 252, 0.5);
}

.download-btn:active {
  transform: translateY(0);
}

.download-btn .icon {
  font-size: 18px;
}

/* Video Container */
#mVideoContainer {
  position: absolute;
  inset: 0;
  display: none;
  background: #000;
  z-index: 5;
}

#mVideoContainer.active {
  display: block;
}

#mVideoIframe {
  width: 100%;
  height: 100%;
  border: none;
  min-height: 600px;
}

/* ===== GLASS-BREAKING CAROUSEL ===== */
.carousel-container {
  position: relative;
  height: 100%;
  min-height: 480px;
  overflow: hidden;
  border-radius: var(--radius2);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.08);
  max-width: 100%;
  margin-bottom: 40px;
}

.carousel-track {
  position: relative;
  width: 100%;
  height: 100%;
}

.carousel-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s var(--ease);
}

.carousel-slide.active {
  opacity: 1;
  visibility: visible;
  z-index: 2;
}

.carousel-slide.revealing {
  z-index: 3;
  animation: revealSlide 1.2s var(--ease) forwards;
}

@keyframes revealSlide {
  from {
    opacity: 0;
    transform: scale(1.08);
    filter: blur(15px) brightness(1.2);
  }
  to {
    opacity: 1;
    transform: scale(1);
    filter: blur(0) brightness(1);
  }
}

.carousel-slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: saturate(1.08) contrast(1.04) brightness(0.92);
}

.carousel-slide.active:hover img {
  transform: scale(1.05);
  transition: transform 3s var(--ease);
}

.carousel-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.2) 40%, rgba(0,0,0,0.8) 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 32px;
  z-index: 1;
}

.carousel-content {
  background: rgba(11, 15, 22, 0.6);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  padding: 24px 28px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  max-width: 700px;
}

.carousel-slide.active .carousel-content {
  animation: slideUpFade 0.8s var(--ease) 0.3s both;
}

@keyframes slideUpFade {
  from {
    opacity: 0;
    transform: translateY(40px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.carousel-slide.shattering .carousel-content {
  animation: contentFade 1.0s var(--ease) forwards;
}

@keyframes contentFade {
  to {
    opacity: 0;
    transform: translateY(20px);
  }
}

.carousel-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 12px;
  letter-spacing: -0.5px;
  color: rgba(255, 255, 255, 0.98);
  line-height: 1.2;
}

.carousel-meta {
  font-size: 15px;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 16px;
}

.carousel-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.carousel-badge {
  font-size: 12px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(11, 15, 22, 0.6);
  backdrop-filter: blur(8px);
  color: rgba(255, 255, 255, 0.92);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.carousel-badge.featured {
  border-color: rgba(251, 191, 36, 0.5);
  background: rgba(251, 191, 36, 0.2);
  color: #fcd34d;
}

.carousel-badge.pdf {
  border-color: rgba(125, 211, 252, 0.4);
  background: rgba(125, 211, 252, 0.2);
  color: #7dd3fc;
}

.carousel-badge.video {
  border-color: rgba(167, 243, 208, 0.4);
  background: rgba(167, 243, 208, 0.2);
  color: #a7f3d0;
}

/* Glass Shattering Effect */
.glass-shards {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  overflow: hidden;
}

.glass-shard {
  position: absolute;
  background: linear-gradient(135deg, 
    rgba(125, 211, 252, 0.4), 
    rgba(167, 243, 208, 0.3),
    rgba(255, 255, 255, 0.2)
  );
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  box-shadow: 
    0 4px 16px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  opacity: 0;
  transform-origin: center;
}

.carousel-slide.shattering .glass-shard-out {
  animation: shatterOut 1.6s var(--ease) forwards;
}

.carousel-slide.shattering-in .glass-shard-in {
  animation: shatterIn 1.6s var(--ease) forwards;
}

@keyframes shatterOut {
  0% {
    opacity: 0;
    transform: translate(0, 0) rotate(0deg) scale(1);
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: 
      translate(var(--scatter-x), var(--scatter-y)) 
      rotate(var(--scatter-rotate)) 
      scale(0.2);
  }
}

@keyframes shatterIn {
  0% {
    opacity: 0;
    transform: 
      translate(var(--scatter-x), var(--scatter-y)) 
      rotate(var(--scatter-rotate)) 
      scale(0.2);
  }
  15% {
    opacity: 1;
  }
  70% {
    opacity: 1;
    transform: translate(0, 0) rotate(0deg) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(0, 0) rotate(0deg) scale(1.1);
  }
}

/* Carousel Navigation Buttons */
.carousel-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  width: 50px;
  height: 50px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(11, 15, 22, 0.7);
  backdrop-filter: blur(12px);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 24px;
  transition: all 0.25s var(--ease);
  user-select: none;
}

.carousel-nav:hover {
  background: rgba(125, 211, 252, 0.3);
  border-color: var(--accent);
  transform: translateY(-50%) scale(1.1);
  box-shadow: 0 8px 24px rgba(125, 211, 252, 0.4);
}

.carousel-nav:active {
  transform: translateY(-50%) scale(0.95);
}

.carousel-nav.prev {
  left: 20px;
}

.carousel-nav.next {
  right: 20px;
}

/* Carousel Indicators */
.carousel-indicators {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 20;
  background: rgba(11, 15, 22, 0.5);
  backdrop-filter: blur(12px);
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.carousel-indicator {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  transition: all 0.3s var(--ease);
}

.carousel-indicator:hover {
  background: rgba(255, 255, 255, 0.6);
  transform: scale(1.2);
}

.carousel-indicator.active {
  width: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 2px 12px rgba(125, 211, 252, 0.5);
}

/* Play/Pause Button */
.carousel-play-pause {
  position: absolute;
  top: 24px;
  right: 24px;
  z-index: 20;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(11, 15, 22, 0.7);
  backdrop-filter: blur(12px);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 18px;
  transition: all 0.25s var(--ease);
}

.carousel-play-pause:hover {
  background: rgba(125, 211, 252, 0.3);
  border-color: var(--accent);
  transform: scale(1.1);
}

.carousel-play-pause:active {
  transform: scale(0.95);
}

/* ===== RESPONSIVE - MODAL & CAROUSEL ===== */
@media (max-width: 980px) {
  .modal-media {
    grid-template-columns: 1fr;
  }
  
  .modal-side {
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.10);
    max-height: 200px;
  }
  
  .carousel-container {
    min-height: 360px;
  }
  
  .carousel-content {
    padding: 20px 24px;
  }
  
  .carousel-title {
    font-size: 20px;
  }
  
  .modal-title {
    font-size: 18px;
  }
}

@media (max-width: 560px) {
  .carousel-container {
    min-height: 320px;
  }
  
  .carousel-content {
    padding: 16px 20px;
  }
  
  .carousel-title {
    font-size: 18px;
  }
  
  .carousel-nav {
    width: 42px;
    height: 42px;
    font-size: 20px;
  }
  
  .carousel-overlay {
    padding: 20px;
  }
  
  .carousel-indicators {
    bottom: 16px;
    padding: 10px 12px;
  }
  
  .modal-card {
    border-radius: 16px;
  }
  
  .modal-top {
    padding: 12px 16px;
  }
  
  .modal-title {
    font-size: 16px;
  }
  
  .xbtn {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }
  
  .navbtn {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
  
  .modal-footer {
    padding: 16px;
    flex-direction: column;
    align-items: stretch;
  }
  
  .download-btn {
    width: 100%;
    justify-content: center;
  }
}

/* Loading Animation for Carousel */
@keyframes loading-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.carousel-container.loading {
  animation: loading-pulse 2s infinite;
}

/* Click-to-open cursor hint */
.carousel-slide {
  cursor: pointer;
}

.carousel-slide:hover {
  cursor: pointer;
}

.carousel-slide::after {
  content: 'Click to view details';
  position: absolute;
  top: 24px;
  left: 24px;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(11, 15, 22, 0.8);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.3s var(--ease);
  pointer-events: none;
  z-index: 15;
}

.carousel-slide:hover::after {
  opacity: 1;
}