/* ===================================
   Gallery Layout Styles
   ================================= */

/* Layout Selector Component */
.layout-selector {
  position: relative;
  display: inline-block;
}

.layout-toggle-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  min-width: 140px;
}

.layout-toggle-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--color-primary);
}

.layout-toggle-btn .material-symbols-outlined {
  font-size: 1.1rem;
}

.layout-toggle-btn .dropdown-icon {
  margin-left: auto;
  transition: transform var(--transition-fast);
}

.layout-dropdown.active ~ .layout-toggle-btn .dropdown-icon {
  transform: rotate(180deg);
}

.layout-name {
  flex: 1;
  text-align: left;
  font-weight: 500;
}

/* Layout Dropdown */
.layout-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-large);
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--transition-medium);
  min-width: 280px;
  white-space: nowrap;
}

.layout-dropdown.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.layout-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition-fast);
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary, #ffffff) !important;
}

.layout-option:last-child {
  border-bottom: none;
}

.layout-option:hover {
  background: var(--bg-elevated);
}

.layout-option.active {
  background: var(--bg-primary);
  color: var(--color-primary);
}

.layout-option .material-symbols-outlined {
  font-size: 1.2rem;
  color: var(--text-secondary);
}

.layout-option.active .material-symbols-outlined {
  color: var(--color-primary);
}

.layout-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.layout-option-name {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--primary-text, #ffffff) !important;
}

/* Ensure current layout name is readable */
.layout-name {
  color: var(--primary-text, #ffffff) !important;
}

.layout-option-desc {
  font-size: 0.75rem;
  /* Follow UI guideline: use standard brightness for readability */
  color: var(--primary-text, #ffffff) !important;
  line-height: 1.3;
}

.check-icon {
  font-size: 1rem;
  color: var(--color-primary);
}

/* ===================================
   Gallery Layout Modes
   ================================= */

/* Base Gallery Grid - Lower specificity, will be overridden by layout classes */

/* Square Crop Layout */
.gallery-grid.layout-square-crop {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)) !important;
  gap: 1.5rem !important;
}

.layout-square-crop .gallery-card,
.layout-square-crop .image-card {
  aspect-ratio: 1 !important;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  height: auto !important;
}

.layout-square-crop .gallery-card img,
.layout-square-crop .image-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: transform var(--transition-medium);
  z-index: 1 !important;
}

/* Ensure filename is above the image in square crop */
.gallery-grid.layout-square-crop .image-info,
.gallery-grid.layout-square-crop .image-name,
.gallery-grid.layout-square-crop .image-meta,
.layout-square-crop .image-info,
.layout-square-crop .image-name,
.layout-square-crop .image-meta {
  position: relative !important;
  z-index: 100 !important;
  background: rgba(26, 26, 26, 0.9) !important;
  backdrop-filter: blur(12px) !important;
}

/* Force image to have lower z-index in square crop */
.gallery-grid.layout-square-crop .gallery-card img,
.gallery-grid.layout-square-crop .image-card img {
  position: absolute !important;
  z-index: 1 !important;
}

/* Image info container must be above image in square-crop */
.gallery-grid.layout-square-crop .image-info {
  position: absolute !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  z-index: 100 !important;
}

/* Fallback: if no class present, target last metadata div */
.gallery-grid.layout-square-crop .gallery-card > div:last-of-type,
.gallery-grid.layout-square-crop .image-card > div:last-of-type {
  position: absolute !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  z-index: 100 !important;
}

/* In square-crop, pin filename area to bottom of card */
.gallery-grid.layout-square-crop .gallery-card > div:last-of-type,
.gallery-grid.layout-square-crop .image-card > div:last-of-type {
  position: absolute !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
}

.layout-square-crop .gallery-card:hover img,
.layout-square-crop .image-card:hover img {
  transform: scale(1.05);
}

/* Square Fit Layout */
.gallery-grid.layout-square-fit {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)) !important;
  gap: 1.5rem !important;
}

.layout-square-fit .gallery-card,
.layout-square-fit .image-card {
  aspect-ratio: 1 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  padding: 0.5rem;
  overflow: visible !important;
  height: auto !important;
  position: relative !important; /* allow bottom-pinned filename */
}

.layout-square-fit .gallery-card > span,
.layout-square-fit .image-card > span {
  font-size: 0.8rem;
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  text-align: center;
  max-width: calc(100% - 1rem);
  max-height: calc(100% - 1rem);
  display: flex;
  align-items: center;
  justify-content: center;
}

.layout-square-fit .gallery-card img,
.layout-square-fit .image-card img {
  position: static !important;
  top: auto !important;
  left: auto !important;
  max-width: calc(100% - 1rem) !important;
  max-height: calc(100% - 1rem) !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain !important;
  border-radius: var(--radius-sm);
  transition: transform var(--transition-medium);
}

/* Square Fit: unify filename bar with card background and pin to bottom */
.gallery-grid.layout-square-fit .image-info {
  position: absolute !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  z-index: 10 !important;
  background: var(--bg-card) !important;
  backdrop-filter: none !important;
  border-top: 1px solid var(--border-light) !important;
  padding: 0.4rem 0.6rem !important;
  display: flex !important;
  align-items: center !important;
  min-height: 2rem !important; /* consistent vertical rhythm */
}

.gallery-grid.layout-square-fit .image-name {
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  width: 100% !important;
  text-align: center !important;
}

/* Override the image container positioning for square-fit */
.layout-square-fit .image-container {
  position: static !important;
  width: 100% !important;
  padding-top: 0 !important;
  overflow: visible !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  height: 100% !important;
}

.layout-square-fit .gallery-card:hover img,
.layout-square-fit .image-card:hover img,
.layout-square-fit .gallery-card:hover > span,
.layout-square-fit .image-card:hover > span {
  transform: scale(1.02);
}

/* Masonry Layout - CSS Grid + JS approach */
.gallery-grid.layout-masonry {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)) !important;
  grid-auto-rows: 10px !important;
  gap: 2px !important;
}

.layout-masonry .gallery-card,
.layout-masonry .image-card {
  display: block !important;
  width: 100%;
  border-radius: 0 !important;
  overflow: visible !important;
  background: transparent !important;
  border: none !important;
  transition: transform var(--transition-medium);
  aspect-ratio: unset !important;
  height: auto !important;
  max-height: none !important;
  min-height: auto !important;
  box-sizing: border-box !important;
  padding: 0 !important;
  margin: 0 !important;
  position: relative !important;
}

/* Masonry card heights are now calculated dynamically by JavaScript */

.layout-masonry .gallery-card:hover,
.layout-masonry .image-card:hover {
  transform: translateY(-2px);
  box-shadow: none !important;
}

/* More specific selectors to override height: 200px */
.gallery-grid.layout-masonry .gallery-card .image-thumbnail,
.gallery-grid.layout-masonry .image-card .image-thumbnail,
.gallery-grid.layout-masonry .gallery-card img,
.gallery-grid.layout-masonry .image-card img {
  position: static !important;
  width: 100% !important;
  height: auto !important;
  display: block !important;
  aspect-ratio: unset !important;
  object-fit: cover !important;
  top: auto !important;
  left: auto !important;
  border-radius: 0 !important;
  max-height: none !important;
  min-height: auto !important;
  box-sizing: content-box !important;
}

/* Additional fallback with even higher specificity */
.gallery-grid.layout-masonry .image-card .image-thumbnail {
  height: auto !important;
}

/* Force override with maximum specificity */
div.gallery-grid.layout-masonry div.image-card img.image-thumbnail,
div.gallery-grid.layout-masonry div.gallery-card img.image-thumbnail,
.gallery-grid.layout-masonry .image-card img.image-thumbnail.loaded,
.gallery-grid.layout-masonry .image-card img.image-thumbnail.loading,
.gallery-grid.layout-masonry .image-card img.image-thumbnail.placeholder {
  height: auto !important;
  max-height: none !important;
  min-height: auto !important;
}

/* Override the image container positioning for masonry */
.layout-masonry .image-container {
  position: static !important;
  width: 100% !important;
  padding-top: 0 !important;
  overflow: visible !important;
}

/* Additional overrides to completely reset image positioning for all layouts */
.gallery-grid.layout-square-crop .image-container {
  position: relative !important;
  width: 100% !important;
  padding-top: 100% !important; /* 1:1 aspect ratio for square */
  overflow: hidden !important;
}

.gallery-grid.layout-square-crop .image-card img,
.gallery-grid.layout-square-crop .gallery-card img {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center !important;
}

.gallery-grid.layout-square-fit .image-container {
  position: static !important;
  width: 100% !important;
  padding-top: 0 !important;
  overflow: visible !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  height: 100% !important;
}

.gallery-grid.layout-masonry .image-container {
  position: static !important;
  width: 100% !important;
  padding-top: 0 !important;
  padding: 0 !important;
  overflow: visible !important;
  height: auto !important;
  display: block !important;
}

/* Hide image metadata in masonry layout for clean Pinterest look */
.layout-masonry .image-info,
.layout-masonry .image-name,
.layout-masonry .image-meta {
  display: none !important;
}

/* Hide the entire metadata container div but preserve checkboxes */
.gallery-grid.layout-masonry .image-card > div:not(:first-child):not(.optimized-checkbox),
.gallery-grid.layout-masonry .gallery-card > div:not(:first-child):not(.optimized-checkbox),
.gallery-grid.layout-masonry .image-card > div:last-child:not(.optimized-checkbox),
.gallery-grid.layout-masonry .gallery-card > div:last-child:not(.optimized-checkbox) {
  display: none !important;
}

/* Ensure checkboxes are always visible in masonry layout */
.gallery-grid.layout-masonry .optimized-checkbox {
  display: flex !important;
  z-index: 15 !important;
  position: absolute !important;
  top: 0px !important;
  left: 0px !important;
  width: 28px !important;
  height: 28px !important;
  align-items: center !important;
  justify-content: center !important;
  background: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  pointer-events: auto !important;
}

/* Higher specificity for masonry checkboxes */
.gallery-grid.layout-masonry .image-card .optimized-checkbox,
.gallery-grid.layout-masonry .gallery-card .optimized-checkbox {
  display: flex !important;
  z-index: 15 !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Hide any div that contains image info */
.layout-masonry div[style*="background: rgba(26, 26, 26"],
.layout-masonry div[style*="backdrop-filter"] {
  display: none !important;
}

/* Masonry selection styles */
.gallery-grid.layout-masonry .image-card.selected,
.gallery-grid.layout-masonry .gallery-card.selected {
  border: 3px solid #4CAF50 !important;
  border-radius: 2px !important;
  overflow: visible !important;
}

/* Masonry checkbox icon styling */
.gallery-grid.layout-masonry .optimized-checkbox .material-symbols-outlined {
  font-size: 24px !important;
  color: white !important;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.8)) !important;
}

/* Special styling for masonry-specific checkboxes */
.gallery-grid.layout-masonry .masonry-checkbox {
  display: flex !important;
  position: absolute !important;
  top: 2px !important;
  left: 2px !important;
  z-index: 20 !important;
  pointer-events: auto !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Masonry responsive column count */
@media (min-width: 1200px) {
  .gallery-grid.layout-masonry {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)) !important;
  }
}

@media (max-width: 768px) {
  .gallery-grid.layout-masonry {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)) !important;
  }
}

@media (max-width: 480px) {
  .gallery-grid.layout-masonry {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
  }
}

/* ===================================
   Image Thumbnail Enhancements
   ================================= */

/* Selection State */
.gallery-card.selected,
.image-card.selected {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--primary-color-alpha);
}

/* Disable CSS pseudo-element checkboxes - handled by JavaScript now */
.gallery-card.selected::after,
.image-card.selected::after {
  display: none !important;
}

.gallery-card.selected::before,
.image-card.selected::before {
  display: none !important;
}

/* Favorite Indicator */
.gallery-card .favorite-indicator,
.image-card .favorite-indicator {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  width: 1.5rem;
  height: 1.5rem;
  background: rgba(255, 215, 0, 0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.gallery-card .favorite-indicator .material-symbols-outlined,
.image-card .favorite-indicator .material-symbols-outlined {
  font-size: 1rem;
  color: #fff;
}

/* Image Loading State */
.gallery-card img[src=""],
.image-card img[src=""] {
  background: var(--bg-skeleton);
  animation: skeleton-loading 1.5s ease-in-out infinite alternate;
}

@keyframes skeleton-loading {
  0% { opacity: 0.6; }
  100% { opacity: 1; }
}

/* ===================================
   Mobile Optimizations
   ================================= */

.gallery-grid.mobile-layout.layout-square-crop,
.gallery-grid.mobile-layout.layout-square-fit {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
  gap: 0.75rem !important;
  padding: 0.75rem;
}

/* Layout Selector Mobile */
@media (max-width: 768px) {
  .layout-toggle-btn {
    min-width: 120px;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
  }
  
  .layout-toggle-btn .layout-name {
    display: none;
  }
  
  .layout-dropdown {
    min-width: 250px;
  }
  
  .layout-option {
    padding: 0.6rem;
  }
  
  .layout-option-desc {
    font-size: 0.7rem;
  }
}

@media (max-width: 480px) {
  .layout-toggle-btn .layout-name {
    display: none;
  }
  
  .layout-dropdown {
    right: 0;
    left: auto;
    min-width: 220px;
  }
}

/* ===================================
   Performance Optimizations
   ================================= */

/* GPU acceleration for smooth animations */
.gallery-card,
.image-card,
.layout-dropdown {
  transform: translateZ(0);
  will-change: transform;
  /* パフォーマンス最適化 */
  contain: layout style paint;          /* 要素の変更をコンテナ内に制限 */
  backface-visibility: hidden;          /* 裏面を非表示にして描画負荷軽減 */
}

/* Gallery Grid - パフォーマンス最適化 */
.gallery-grid {
  /* パフォーマンス最適化 */
  contain: layout style paint; /* CSS containment で描画最適化 */
  transform: translateZ(0);    /* GPU レイヤー作成を強制 */
  /* will-change: contents; チカチカの原因の可能性があるためコメントアウト */
  
  /* レイアウト安定化 */
  min-height: 200px; /* 最小高さを確保してレイアウトシフトを防止 */
}

/* Image Thumbnails - 高速描画最適化 */
.image-thumbnail {
  /* 画像描画最適化 */
  image-rendering: -webkit-optimize-contrast; /* Webkit最適化 */
  image-rendering: crisp-edges;               /* エッジをシャープに */
  transform: translateZ(0);                   /* GPU層に配置 */
  backface-visibility: hidden;                /* 描画負荷軽減 */
}

.image-thumbnail.placeholder {
  /* プレースホルダー状態の最適化 */
  content-visibility: auto;    /* 必要に応じて描画 */
  contain-intrinsic-size: 200px 200px; /* サイズヒント */
}

.image-thumbnail.loading {
  /* ローディング中の最適化 */
  content-visibility: auto;    /* 必要に応じて描画 */
  contain-intrinsic-size: 200px 200px; /* サイズヒント */
}

.image-thumbnail.loaded {
  /* 読み込み完了後の最適化 */
  image-rendering: auto;       /* 通常の画質に戻す */
}

/* Gallery Loading State - パフォーマンス最適化 */
.gallery-loading {
  /* ローディング中はレンダリング負荷を最小化 */
  pointer-events: none;        /* マウスイベントを無効化 */
  user-select: none;          /* テキスト選択を無効化 */
  contain: strict;            /* 最大限のcontainment */
}

.gallery-loading .image-card {
  /* ローディング中のカードは簡素化 */
  will-change: auto;          /* アニメーション予告を無効化 */
  transform: none;            /* GPU層を一時解除 */
}

/* レンダリング完了後の最適化復活 */
.gallery-grid:not(.gallery-loading) .image-card {
  transform: translateZ(0);           /* GPU層を再有効化 */
  will-change: transform, opacity;    /* アニメーション予告を再有効化 */
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  .gallery-card,
  .image-card,
  .layout-dropdown,
  .layout-toggle-btn {
    transition: none;
  }
  
  .gallery-card:hover img,
  .image-card:hover img,
  .layout-square-crop .gallery-card:hover img,
  .layout-square-crop .image-card:hover img,
  .layout-square-fit .gallery-card:hover img,
  .layout-square-fit .image-card:hover img {
    transform: none;
  }
}

/* ===================================
   Additional Image Card Styles
   ================================= */

/* 強制的にチェックボックスの色を設定 */
.optimized-checkbox.checked {
  background: transparent !important;
  background-color: transparent !important;
  border: none !important;
}

.optimized-checkbox:not(.checked) {
  background: transparent !important;
  background-color: transparent !important;
  border: none !important;
}

/* Gallery Container */
.gallery-container {
  padding: 2rem;
}

.gallery-empty {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.gallery-empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}

.gallery-empty h3 {
  font-size: var(--font-size-xl);
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.gallery-empty p {
  font-size: var(--font-size-md);
  margin-bottom: 2rem;
}

/* Compare mode first image */
.image-card.compare-first-image {
  border-color: #ff9800;
  box-shadow: 0 0 20px rgba(255, 152, 0, 0.5);
}

.image-card.compare-first-image::before {
  content: "1st";
  position: absolute;
  top: 10px;
  right: 10px;
  background: #ff9800;
  color: white;
  font-weight: bold;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  z-index: 10;
}

/* Cover Image Badge */
.cover-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: linear-gradient(135deg, #ffd700, #ffb347);
  /* color統一をTailwindCSSで管理 */
  padding: 0.3rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.4), 0 1px 4px rgba(255, 215, 0, 0.6);
  border: 2px solid #fff;
}

.cover-badge .material-symbols-outlined {
  font-size: 1rem;
}

/* Image Card Extended Styles */
.image-card {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 15px;
  cursor: pointer;
  border: 2px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
}

.image-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6), 0 0 20px rgba(139, 233, 253, 0.3);
  border-color: rgba(139, 233, 253, 0.7);
}

.image-container {
  position: relative;
  width: 100%;
  padding-top: 66.67%; /* 3:2 aspect ratio */
  overflow: hidden;
}

.image-card img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.3s ease;
  background: var(--bg-surface);
  border-radius: 0;
}

.image-overlay .image-actions {
  display: none;
}

/* 古い image-checkbox スタイルを完全に無効化 */
.image-card .image-checkbox,
.gallery-card .image-checkbox,
input[type="checkbox"].image-checkbox {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}

/* Image Card States */
.image-card.selected {
  border-color: var(--primary-accent);
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.3);
}

.image-card.favorite {
  border-color: rgba(251, 191, 36, 0.6) !important;
  box-shadow: 0 0 25px rgba(251, 191, 36, 0.4), 0 8px 32px rgba(0, 0, 0, 0.3) !important;
}

.image-card.favorite::before {
  content: '⭐';
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  color: #fbbf24;
  font-size: var(--font-size-lg);
  z-index: 10;
  text-shadow: 0 0 10px rgba(251, 191, 36, 1);
}

.image-card.favorite:hover {
  border-color: rgba(251, 191, 36, 0.8) !important;
  box-shadow: 0 0 35px rgba(251, 191, 36, 0.6), 0 15px 40px rgba(0, 0, 0, 0.6) !important;
  transform: translateY(-5px);
}

.image-card.trash-image {
  opacity: 0.5;
}

.image-card.has-note::after {
  content: 'description';
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  color: white;
  font-family: 'Material Symbols Outlined';
  font-size: 1.2rem;
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

/* Image Loading States */
.image-loading-spinner {
  position: absolute;
  inset: 0;
  display: none !important; /* スピナー完全無効化 */
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3); /* 半透明背景 */
  backdrop-filter: blur(2px); /* ぼかし効果 */
}

.image-loading-spinner::before {
  content: '';
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--primary-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.image-error-message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f4f6;
  color: #9ca3af;
  font-size: var(--font-size-sm);
}

.image-error-message::before {
  content: '⚠️ 読み込みエラー';
}

/* Image Metadata */
.image-info {
  padding: 0.75rem;
  background: rgba(var(--secondary-bg), 0.5);
  backdrop-filter: blur(12px);
}

.image-name {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-meta {
  display: flex;
  justify-content: space-between;
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.image-size,
.image-date {
  color: var(--text-muted);
}

/* Lazy Loading - スムーズな画像切り替え */
.image-card img {
  opacity: 1;
  /* トランジションは読み込み状態の時のみ適用 */
}

.image-card img.placeholder {
  /* プレースホルダー状態では透明にしない */
  opacity: 1;
}

.image-card img.loading {
  /* プレースホルダー状態では透明にしない */
  opacity: 1;
}

.image-card img.actual-loading {
  /* 実際の読み込み中のみトランジション適用 - ちらつき軽減のため無効化 */
  opacity: 1;
  transition: none; /* opacity 0.15s ease-in-out; */
}

.image-card img.loaded {
  /* 読み込み完了後はトランジション無効化 */
  opacity: 1;
  transition: none; /* 重要: 完了後はトランジション停止 */
}

.image-card img.error {
  opacity: 1;
  transition: none;
}

/* Selection Mode */
.gallery-grid.selection-mode .image-card .optimized-checkbox {
  opacity: 1;
}

.gallery-grid.selection-mode .image-card {
  cursor: pointer;
}

/* ===================================
   Dark Mode Support
   ================================= */

@media (prefers-color-scheme: dark) {
  .layout-toggle-btn {
    background: var(--dark-card-bg, #2a2a2a);
    border-color: var(--dark-border-color, #404040);
    color: var(--dark-text-primary, #ffffff);
  }
  
  .layout-dropdown {
    background: var(--dark-card-bg, #2a2a2a);
    border-color: var(--dark-border-color, #404040);
  }
  
  .gallery-card,
  .image-card {
    background: var(--dark-card-bg, #2a2a2a);
    border-color: var(--dark-border-light, #404040);
  }
}
