/* ═══════════════════════════════════════════════════════════════════
   WASABI GALLERY — Premium Dark Theme
   ═══════════════════════════════════════════════════════════════════ */

/* ─── Design Tokens ───────────────────────────────────────────────── */
:root {
  --bg-primary: #07070e;
  --bg-secondary: #0e0e1a;
  --bg-surface: #13132200;
  --bg-surface-hover: #1a1a2e;
  --bg-elevated: #1e1e32;

  --accent-primary: #8b5cf6;
  --accent-secondary: #6366f1;
  --accent-gradient: linear-gradient(135deg, #8b5cf6 0%, #6366f1 50%, #3b82f6 100%);
  --accent-glow: rgba(139, 92, 246, 0.3);

  --text-primary: #e8eaf0;
  --text-secondary: #8b8fa8;
  --text-muted: #555872;

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(139, 92, 246, 0.3);

  --glass-bg: rgba(14, 14, 26, 0.8);
  --glass-border: rgba(255, 255, 255, 0.08);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px rgba(139, 92, 246, 0.15);

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Reset & Base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Subtle gradient background */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 0%, rgba(139, 92, 246, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 100%, rgba(59, 130, 246, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ─── Header ──────────────────────────────────────────────────────── */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border-bottom: 1px solid var(--glass-border);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  transition: opacity var(--transition-fast);
}

.logo:hover { opacity: 0.8; }

.logo-icon {
  font-size: 24px;
  filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.4));
}

/* ─── Breadcrumb ──────────────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: var(--text-secondary);
  overflow: hidden;
  white-space: nowrap;
}

.breadcrumb-sep {
  color: var(--text-muted);
  margin: 0 2px;
  flex-shrink: 0;
}

.breadcrumb a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast);
  overflow: hidden;
  text-overflow: ellipsis;
}

.breadcrumb a:hover { color: var(--accent-primary); }
.breadcrumb .current { color: var(--text-primary); font-weight: 500; }

/* ─── Cache Indicator ─────────────────────────────────────────────── */
.cache-indicator {
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-surface-hover);
  white-space: nowrap;
}

.cache-indicator.live { color: #34d399; }

/* ─── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.btn-primary:hover {
  box-shadow: 0 4px 20px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}
.btn-secondary:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-surface-hover); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-icon:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

/* ─── Main Content ────────────────────────────────────────────────── */
#main {
  position: relative;
  z-index: 1;
  max-width: 1440px;
  margin: 0 auto;
  padding: 32px 24px 120px;
  min-height: calc(100vh - 64px);
}

/* ─── Content Sections ────────────────────────────────────────────── */
.content-section { margin-bottom: 40px; }

.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.section-title svg { color: var(--accent-primary); }

.count-badge {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-surface-hover);
  padding: 2px 10px;
  border-radius: 20px;
}

/* ─── Folders Grid ────────────────────────────────────────────────── */
.folders-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.folder-card {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition-normal);
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
}

.folder-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  border-color: var(--border-accent);
}

.folder-cover {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--bg-surface-hover);
  display: block;
}

.folder-cover-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: linear-gradient(135deg, var(--bg-surface-hover) 0%, var(--bg-elevated) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.folder-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0.15) 40%, transparent 60%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 16px;
  transition: background var(--transition-normal);
}

.folder-card:hover .folder-overlay {
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.25) 50%, rgba(0, 0, 0, 0.1) 100%);
}

.folder-name {
  font-size: 15px;
  font-weight: 600;
  color: white;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.folder-meta {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.75);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* ─── Images Grid ─────────────────────────────────────────────────── */
.images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.image-card {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition-normal);
  border: 1px solid transparent;
  background: var(--bg-secondary);
  aspect-ratio: 1;
}

.image-card:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-md);
  border-color: var(--border-accent);
}

.image-card.selected {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-glow), var(--shadow-md);
}

.image-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--transition-slow);
}

.image-card:hover .image-thumb { transform: scale(1.05); }

.image-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 50%);
  opacity: 0;
  transition: opacity var(--transition-normal);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px;
}

.image-card:hover .image-overlay,
.image-card.selected .image-overlay { opacity: 1; }

.image-name {
  font-size: 12px;
  font-weight: 500;
  color: white;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-size {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  margin-top: 2px;
}

/* Checkbox */
.image-checkbox {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid rgba(255,255,255,0.5);
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all var(--transition-fast);
  z-index: 2;
  cursor: pointer;
}

.image-card:hover .image-checkbox,
.image-card.selected .image-checkbox { opacity: 1; }

.image-card.selected .image-checkbox {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.image-checkbox svg { display: none; }
.image-card.selected .image-checkbox svg { display: block; }

/* Placeholder for failed thumbnails */
.image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg-surface-hover), var(--bg-elevated));
  color: var(--text-muted);
}

/* ─── Selection Toolbar ───────────────────────────────────────────── */
.selection-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border-top: 1px solid var(--glass-border);
  transform: translateY(100%);
  transition: transform var(--transition-normal);
}

.selection-toolbar.visible { transform: translateY(0); }

.toolbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.selection-count {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent-primary);
  margin-left: 8px;
}

/* ─── Lightbox ────────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.lightbox.visible {
  opacity: 1;
  visibility: visible;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(20px);
}

.lightbox-content {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.lightbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  z-index: 2;
}

.lightbox-info { display: flex; flex-direction: column; min-width: 0; }

.lightbox-filename {
  font-size: 14px;
  font-weight: 500;
  color: white;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox-meta {
  font-size: 12px;
  color: rgba(255,255,255,0.6);
}

.lightbox-actions {
  display: flex;
  gap: 4px;
}

.lightbox-actions .btn-icon {
  color: rgba(255,255,255,0.8);
}
.lightbox-actions .btn-icon:hover {
  color: white;
  background: rgba(255,255,255,0.1);
}

.lightbox-image-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 60px;
  min-height: 0;
  position: relative;
}

#lightbox-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity 0.3s ease;
}

#lightbox-image.loaded { opacity: 1; }

.lightbox-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  color: white;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.lightbox-nav:hover {
  background: rgba(255,255,255,0.15);
  transform: translateY(-50%) scale(1.1);
}

.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }

.lightbox-counter {
  text-align: center;
  padding: 8px;
  font-size: 13px;
  color: rgba(255,255,255,0.5);
}

/* ─── Loading ─────────────────────────────────────────────────────── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  gap: 16px;
  color: var(--text-secondary);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ─── Error & Empty States ────────────────────────────────────────── */
.error-state, .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  gap: 16px;
  text-align: center;
}

.error-state svg, .empty-state svg {
  color: var(--text-muted);
  margin-bottom: 8px;
}

.error-state h2, .empty-state h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.error-state p, .empty-state p {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 400px;
}

/* ─── Download Modal ──────────────────────────────────────────────── */
.download-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.download-modal.visible {
  opacity: 1;
  visibility: visible;
}

.download-modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 32px;
  min-width: 360px;
  text-align: center;
}

.download-modal-header h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

.download-progress {
  height: 6px;
  background: var(--bg-surface-hover);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}

.download-progress-bar {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease;
}

.download-status {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ─── Utility ─────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Animations ──────────────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.folder-card, .image-card {
  animation: fadeInUp 0.4s ease backwards;
}

/* Stagger animation for grid items */
.folder-card:nth-child(1), .image-card:nth-child(1) { animation-delay: 0.02s; }
.folder-card:nth-child(2), .image-card:nth-child(2) { animation-delay: 0.04s; }
.folder-card:nth-child(3), .image-card:nth-child(3) { animation-delay: 0.06s; }
.folder-card:nth-child(4), .image-card:nth-child(4) { animation-delay: 0.08s; }
.folder-card:nth-child(5), .image-card:nth-child(5) { animation-delay: 0.10s; }
.folder-card:nth-child(6), .image-card:nth-child(6) { animation-delay: 0.12s; }
.folder-card:nth-child(7), .image-card:nth-child(7) { animation-delay: 0.14s; }
.folder-card:nth-child(8), .image-card:nth-child(8) { animation-delay: 0.16s; }
.folder-card:nth-child(9), .image-card:nth-child(9) { animation-delay: 0.18s; }
.folder-card:nth-child(10), .image-card:nth-child(10) { animation-delay: 0.20s; }
.folder-card:nth-child(n+11), .image-card:nth-child(n+11) { animation-delay: 0.22s; }

/* ─── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .images-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
  .folders-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

@media (max-width: 768px) {
  .header-inner {
    padding: 10px 16px;
    height: auto;
    flex-wrap: wrap;
    gap: 6px;
  }
  .header-left { width: 100%; }
  .header-right { width: 100%; justify-content: flex-end; }
  #main { padding: 20px 16px 120px; }

  .images-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
  }
  .folders-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
  }

  .lightbox-image-wrapper { padding: 10px 10px; }
  .lightbox-nav { width: 36px; height: 36px; }
  .lightbox-prev { left: 4px; }
  .lightbox-next { right: 4px; }

  .toolbar-inner {
    flex-direction: column;
    gap: 8px;
    padding: 10px 16px;
  }

  .toolbar-left, .toolbar-right { width: 100%; justify-content: center; flex-wrap: wrap; }

  .breadcrumb { display: none; }
}

@media (max-width: 480px) {
  .images-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
  .folders-grid {
    grid-template-columns: 1fr;
  }
  .image-card { border-radius: var(--radius-sm); }
  .folder-card { border-radius: var(--radius-md); }
}
