/* --- Modal base --- */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  padding-top: 150px;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.9);
  box-sizing: border-box;
}

.close {
  position: absolute;
  top: 20px;
  right: 35px;
  color: #f1f1f1;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
  z-index: 1200;
}

.close:hover,
.close:focus {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;
}

/* --- Media container inside modal --- */
.media-container .modal-content,
.media-container video,
.media-container img.modal-content {
  margin: auto;
  display: block;
  object-fit: contain;
  max-width: 80%;
  max-height: calc(70vh - 120px); /* leave room for caption + previews */
  width: auto;
  height: auto;
  margin-bottom: 10px;
}

.media-container video {
  background: black;
}

/* --- Caption --- */
#caption {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
  text-align: center;
  color: #ccc;
  padding: 10px 0;
  height: 150px;
}

.modal-content, #caption {
  animation-name: zoom;
  animation-duration: 0.6s;
}

@keyframes zoom {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* --- Gallery (page thumbnails) --- */
.gallery {
  margin-top: 5px;
  margin-bottom: 5px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow-x: auto;        /* enable horizontal scrolling */
  scroll-behavior: smooth; /* smooth scrolling */
  overflow-y: hidden;
}

.gallery-image {
  max-height: 85%;
  min-height: 100px;
  margin-right: 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: 0.3s;
  border: 0.5px solid lightgray;
}

.gallery-image:hover {
  opacity: 0.7;
}

.gallery-image:last-child {
  margin-right: 0px;
}

/* --- Preview thumbnails inside modal --- */
#preview-container {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: 80%;
  max-width: 700px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 12px;
  box-sizing: border-box;
  z-index: 1100;
  background: rgba(0,0,0,0.35);
  border-radius: 8px;
}

.preview-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 4px;
  transition: transform 0.15s, border-color 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.preview-thumb:hover {
  transform: scale(1.05);
  border-color: #aaa;
}

.active-thumb {
  border-color: #007bff;
  box-shadow: 0 2px 6px rgba(0,123,255,0.15);
}

/* --- Responsive adjustments --- */
@media only screen and (max-width: 700px){
  .modal-content, .media-container video {
    width: 100%;
  }
}

@media only screen and (max-width: 480px) {
  #preview-container {
    width: 92%;
    bottom: 12px;
    padding: 6px 8px;
    gap: 8px;
  }

  .preview-thumb {
    width: 44px;
    height: 44px;
  }

  #caption {
    height: auto;
    padding: 8px 0;
  }

  .modal-content, .media-container video {
    max-height: calc(65vh - 120px);
  }
}
