@font-face {
  font-family: "Kittithada";
  src: url("font/PSL-Kittithada.woff2") format("woff2"),
    url("font/PSL-Kittithada.woff") format("woff");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Kittithada";
  background: #1a1a1a;
  padding: 20px;
  min-height: 100vh;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
}

.header {
  text-align: center;
  margin-bottom: 40px;
}

h1 {
  color: white;
  font-size: 4.5em;
  margin-bottom: 10px;
}

.subtitle {
  color: #999;
  font-size: 2.1em;
}

.folder-info {
  background: #2a2a2a;
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 30px;
  color: white;
  text-align: center;
}

.folder-info strong {
  color: #4caf50;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.btn {
  font-family: "Kittithada";
  background: #333;
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.25em;
  transition: background 0.3s ease;
  text-transform: uppercase;
  font-weight: 600;
}

.btn:hover {
  background: #555;
}

.btn.active {
  background: #4caf50;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 40px;
}

.gallery-item {
  background: #2a2a2a;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  position: relative;
}

.gallery-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 30px rgba(255, 255, 255, 0.1);
}

.gallery-item img {
  width: 100%;
  height: 350px;
  object-fit: contain;
  display: block;
  background: #f0f0f0;
  transition: opacity 0.3s ease;
  image-rendering: auto;
}

/* สำหรับมือถือให้ลดความละเอียดก่อน */
@media (max-width: 768px) {
  .gallery-item img {
    height: 250px;
    image-rendering: -webkit-optimize-contrast;
  }
}

.gallery-item img.loading {
  opacity: 0.3;
}

.gallery-item img.loaded {
  opacity: 1;
}

.page-number {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9em;
}

.image-name {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 1em;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 1em;
  font-weight: bold;
  text-transform: uppercase;
}

.hidden {
  display: none !important;
}

/* Lightbox Modal */
.lightbox {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
}

.lightbox-container {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.lightbox-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 20px;
}

.lightbox-content {
  max-width: 90%;
  max-height: 90vh;
  position: relative;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
  transition: opacity 0.2s ease;
  will-change: transform;
}

.lightbox-content img.loading {
  opacity: 0.5;
}

.lightbox-content .loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  border: 5px solid #333;
  border-top: 5px solid #4caf50;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  z-index: 10;
}

@keyframes spin {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }

  100% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* ปรับปรุงประสิทธิภาพ */
.lightbox-main {
  transform: translateZ(0);
  backface-visibility: hidden;
}

.thumbnail-item {
  will-change: transform;
}

.close-lightbox {
  position: absolute;
  top: 10px;
  right: 10px;
  color: white;
  font-size: 40px;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  padding: 5px 15px;
  border-radius: 8px;
  z-index: 1001;
}

.close-lightbox:hover {
  background: rgba(0, 0, 0, 0.8);
}

.lightbox-sidebar {
  width: 300px;
  background: #1a1a1a;
  height: 100%;
  overflow-y: auto;
  border-left: 2px solid #333;
  padding: 20px;
  transition: transform 0.3s ease;
}

.lightbox-sidebar.hidden {
  transform: translateX(100%);
}

.lightbox-sidebar h3 {
  color: white;
  margin-bottom: 15px;
  font-size: 1.2em;
  position: sticky;
  top: 0;
  background: #1a1a1a;
  padding: 10px 0;
  z-index: 10;
}

.thumbnail-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.thumbnail-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: #2a2a2a;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.thumbnail-item:hover {
  background: #333;
  border-color: #667eea;
}

.thumbnail-item.active {
  background: #333;
  border-color: #4caf50;
  box-shadow: 0 0 10px rgba(76, 175, 80, 0.3);
}

.thumbnail-item img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
}

.thumbnail-info {
  flex: 1;
  overflow: hidden;
}

.thumbnail-info .name {
  color: white;
  font-size: 1.25em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumbnail-info .category {
  color: #4caf50;
  font-size: 1em;
  text-transform: uppercase;
  margin-top: 2px;
}

.toggle-sidebar {
  position: fixed;
  right: 320px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border: none;
  padding: 15px 10px;
  cursor: pointer;
  border-radius: 8px 0 0 8px;
  font-size: 20px;
  z-index: 1002;
  transition: right 0.3s ease, background 0.3s ease;
}

.toggle-sidebar:hover {
  background: rgba(0, 0, 0, 0.9);
}

.toggle-sidebar.sidebar-hidden {
  right: 20px;
}

.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: none;
  font-size: 30px;
  padding: 20px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.3s ease;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.prev-btn {
  left: 20px;
}

.next-btn {
  right: 20px;
}

.page-info {
  text-align: center;
  color: white;
  margin-top: 20px;
  font-size: 1.1em;
}

.error {
  background: #f44336;
  color: white;
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 20px;
  text-align: center;
}

@media (max-width: 768px) {
  .gallery {
    grid-template-columns: repeat(1, 1fr) !important;
    gap: 15px;
  }

  .gallery-item img {
    height: 300px;
  }

  h1 {
    font-size: 2em;
  }

  .nav-btn {
    padding: 15px;
    font-size: 24px;
  }

  .lightbox-sidebar {
    display: none !important;
  }

  .toggle-sidebar {
    display: none !important;
  }

  .lightbox-main {
    padding: 10px;
  }

  .lightbox-container {
    overflow: hidden;
  }
}
