body.viewer-page {
  margin: 0;
  min-height: 100vh;
  background: var(--site-bg);
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

body.viewer-page .bg-gradient,
body.viewer-page .bg-pattern {
  display: none;
}

body.viewer-page [hidden] {
  display: none !important;
}

.viewer-main {
  flex: 1;
  padding-bottom: 42px;
}

.viewer-top-controls {
  width: 100%;
  max-width: none;
  margin: 0 0 20px;
  padding: 20px var(--page-gutter) 0;
  display: flex;
  align-items: center;
  gap: 16px;
}

.back-nav {
  width: auto;
  max-width: none;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: var(--radius-full);
  color: var(--gray-700);
  text-decoration: none;
  font-weight: 600;
  transition: var(--transition-base);
  border: 1px solid var(--glass-border);
}

.back-link:hover {
  background: white;
  color: var(--primary-600);
  transform: translateX(-4px);
}

[dir="rtl"] .back-link:hover {
  transform: translateX(4px);
}

.back-link svg {
  width: 18px;
  height: 18px;
}

.viewer-search-panel {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  z-index: 3;
}

.search-box {
  display: block;
  position: relative;
  width: 100%;
}

.search-box input {
  width: 100%;
  padding: 16px 140px 16px 18px;
  border: 1px solid #d7e0ea;
  border-radius: 14px;
  font-size: 1rem;
  transition: all 0.3s;
  background: #f8fafc;
  color: #0f172a;
  caret-color: #0f172a;
}

[dir="rtl"] .search-box input {
  padding: 16px 18px 16px 140px;
}

.search-box input::placeholder {
  color: #94a3b8;
}

.search-box input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

.search-box button {
  position: absolute;
  right: 6px;
  top: 6px;
  bottom: 6px;
  padding: 0 24px;
  background: linear-gradient(135deg, var(--brand-accent-400) 0%, var(--brand-accent-500) 100%);
  color: white;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

[dir="rtl"] .search-box button {
  right: auto;
  left: 6px;
}

.search-box button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgb(var(--brand-accent-500-rgb) / 0.5);
}

.search-dropdown {
  position: fixed;
  top: 0;
  left: 0;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.15);
  z-index: 50;
  display: none;
  max-height: 320px;
  overflow-y: auto;
}

.search-dropdown.active {
  display: block;
}

.search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  text-decoration: none;
  color: #0f172a;
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.2s ease;
}

.search-item:hover {
  background: #f8fafc;
}

.search-item:last-child {
  border-bottom: 0;
}

.search-item-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.search-item-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-item-meta {
  font-size: 0.82rem;
  color: #64748b;
}

.search-empty {
  padding: 14px 16px;
  color: #64748b;
  font-size: 0.9rem;
}

.viewer-shell {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0 var(--page-gutter);
}

.viewer-shell-header {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(203, 213, 225, 0.55);
  border-radius: 20px;
  padding: 18px clamp(16px, 2vw, 26px);
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.08);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.viewer-kicker {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 11px;
  font-size: var(--type-label);
  font-weight: 800;
  color: #0f4aa4;
  background: #dbeafe;
  border: 1px solid rgba(59, 130, 246, 0.25);
}

.viewer-shell-heading h1 {
  margin: 9px 0 4px;
  font-size: var(--type-section-title);
  line-height: 1.1;
  color: #0f172a;
}

.viewer-shell-heading p {
  margin: 0;
  font-size: var(--type-body);
  color: #475569;
}

.viewer-shell-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.viewer-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  height: 38px;
  border-radius: 999px;
  padding: 0 14px;
  background: #eff6ff;
  border: 1px solid rgba(59, 130, 246, 0.23);
  color: #0f3d8f;
  font-size: var(--type-body-sm);
  font-weight: 800;
}

.viewer-detail-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  border-radius: 999px;
  padding: 0 16px;
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
  color: #fff;
  text-decoration: none;
  font-size: var(--type-label);
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.33);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.viewer-detail-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 11px 24px rgba(37, 99, 235, 0.4);
}

.viewer-loading,
.viewer-empty {
  margin-top: 14px;
  border-radius: 20px;
  border: 1px solid rgba(203, 213, 225, 0.65);
  background: rgba(255, 255, 255, 0.95);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #334155;
}

.viewer-empty h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  color: #0f172a;
}

.viewer-empty p {
  margin: 0;
  max-width: 520px;
  line-height: 1.6;
}

.loading-spinner {
  width: 38px;
  height: 38px;
  border: 4px solid rgba(37, 99, 235, 0.14);
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.viewer-stage-wrap {
  margin-top: 14px;
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(203, 213, 225, 0.65);
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.14);
  background: #0f172a;
  min-height: min(72vh, 760px);
  display: flex;
  align-items: center;
}

.viewer-stage {
  width: 100%;
  margin: 0;
  display: grid;
  place-items: center;
  min-height: min(72vh, 760px);
  position: relative;
}

#viewer-image {
  width: 100%;
  height: min(72vh, 760px);
  object-fit: contain;
  display: block;
  opacity: 1;
  transition: opacity 0.22s ease;
}

#viewer-image.is-loading {
  opacity: 0.45;
}

.viewer-caption {
  position: absolute;
  left: 14px;
  bottom: 14px;
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #f8fafc;
  font-size: var(--type-label);
  font-weight: 700;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(15, 23, 42, 0.55);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 4;
  transition: transform 0.2s ease, background 0.2s ease;
}

.viewer-nav:hover {
  background: rgba(15, 23, 42, 0.72);
}

.viewer-nav:active {
  transform: translateY(-50%) scale(0.96);
}

.viewer-nav-prev {
  left: 14px;
}

.viewer-nav-next {
  right: 14px;
}

.viewer-nav:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.viewer-thumbs {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 2px 2px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(15, 23, 42, 0.35) transparent;
}

.viewer-thumbs::-webkit-scrollbar {
  height: 6px;
}

.viewer-thumbs::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.32);
  border-radius: 999px;
}

.viewer-thumb {
  width: 104px;
  min-width: 104px;
  height: 72px;
  border-radius: 12px;
  border: 2px solid transparent;
  padding: 0;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.08);
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.viewer-thumb:hover {
  transform: translateY(-1px);
  border-color: rgba(37, 99, 235, 0.4);
}

.viewer-thumb.is-active {
  border-color: rgba(37, 99, 235, 0.9);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

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

.viewer-thumb-index {
  position: absolute;
  right: 6px;
  bottom: 6px;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.62);
  color: #f8fafc;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

body[dir="rtl"] .viewer-shell,
body[dir="rtl"] .viewer-shell-header,
body[dir="rtl"] .viewer-empty,
body[dir="rtl"] .viewer-loading {
  text-align: right;
}

body[dir="rtl"] .viewer-caption {
  left: auto;
  right: 14px;
}

body[dir="rtl"] .viewer-thumb-index {
  right: auto;
  left: 6px;
}

@media (max-width: 920px) {
  .viewer-top-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding-top: 6px;
    margin-bottom: 12px;
  }

  .back-nav {
    width: 100%;
  }

  .search-box {
    display: block;
  }

  .viewer-shell-header {
    padding: 16px 14px;
  }

  .viewer-shell-meta {
    width: 100%;
    justify-content: space-between;
  }

  .viewer-stage-wrap,
  .viewer-stage {
    min-height: 56vh;
  }

  #viewer-image {
    height: 56vh;
  }

  .viewer-nav {
    width: 42px;
    height: 42px;
  }

  .viewer-thumb {
    width: 88px;
    min-width: 88px;
    height: 64px;
  }
}

@media (max-width: 640px) {
  body.viewer-page {
    --page-gutter: 16px;
  }

  .viewer-main {
    padding-bottom: 26px;
  }

  .viewer-detail-link,
  .viewer-count {
    min-height: 36px;
  }

  .viewer-shell-heading h1 {
    font-size: 1.55rem;
  }

  .viewer-caption {
    font-size: 0.75rem;
  }

  .viewer-nav-prev {
    left: 10px;
  }

  .viewer-nav-next {
    right: 10px;
  }
}
