/* ===== LUXIE GALLERY — Clean Customer Experience CSS ===== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #f8f9fa;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f3f4;
  --text-primary: #202124;
  --text-secondary: #5f6368;
  --text-muted: #9aa0a6;
  --accent: #1a73e8;
  --accent-light: #e8f0fe;
  --border: #dadce0;
  --border-light: #e8eaed;
  --shadow-sm: 0 1px 2px rgba(60, 64, 67, 0.1);
  --shadow-md: 0 1px 3px rgba(60, 64, 67, 0.15), 0 4px 8px rgba(60, 64, 67, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --gap: 2px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

/* ===== LOADING SCREEN ===== */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  gap: 20px;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.loading-screen.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

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

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

.loading-text {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ===== PASSWORD MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: 24px;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.modal-icon { font-size: 48px; margin-bottom: 16px; }
.modal-card h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 8px; }
.modal-card p { color: var(--text-secondary); font-size: 0.875rem; margin-bottom: 24px; }

#password-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  margin-bottom: 16px;
}

#password-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.btn-primary:hover { background: #1765cc; }
.btn-primary:active { transform: scale(0.98); }
.error-text { color: #d93025; font-size: 0.8125rem; margin-top: 12px; }

/* ===== ERROR SCREEN ===== */
.error-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  padding: 24px;
  text-align: center;
  gap: 12px;
}

.error-icon { font-size: 64px; margin-bottom: 8px; }
.error-screen h2 { font-size: 1.25rem; font-weight: 600; }
.error-screen p { color: var(--text-secondary); font-size: 0.875rem; }

/* ===== TOP APP BAR ===== */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-light);
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.top-bar-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-bar-right {
  flex-shrink: 0;
}

.top-bar-meta {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.icon-btn:hover { background: var(--bg-surface-hover); }
.icon-btn .material-symbols-outlined { font-size: 24px; }

/* ===== ALBUM GRID ===== */
.album-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.album-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.album-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.album-card:active { transform: scale(0.98); }

.album-card-thumb {
  aspect-ratio: 4/3;
  width: 100%;
  object-fit: cover;
  background: var(--bg-primary);
}

.album-card-info { padding: 12px; }
.album-card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.album-card-count { font-size: 0.75rem; color: var(--text-muted); }

/* ===== EMPTY STATE & FOOTER ===== */
.empty-state { text-align: center; padding: 80px 24px; }
.empty-icon { font-size: 64px; color: var(--text-muted); margin-bottom: 16px; display: block; }
.empty-state h3 { font-size: 1.125rem; font-weight: 600; margin-bottom: 8px; }
.empty-state p { color: var(--text-secondary); font-size: 0.875rem; }

.gallery-footer {
  text-align: center;
  padding: 32px 16px calc(var(--safe-bottom) + 32px);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.gallery-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
}

.gallery-footer a:hover { color: var(--accent); }

/* ===== PHOTO GRID — Clean 3 Column ===== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 24px 16px calc(var(--safe-bottom) + 16px);
  max-width: 1200px;
  margin: 0 auto;
}

.grid-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--bg-primary);
  cursor: pointer;
  border-radius: 8px;
}

.grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease, opacity 0.3s ease;
  will-change: transform;
  -webkit-touch-callout: none; /* Prevent long-press save (low quality) */
  pointer-events: none; /* Context menu targets div, not img */
}

.grid-item img.loading { opacity: 0; }
.grid-item img.loaded { opacity: 1; }
.grid-item:active img { transform: scale(0.96); }

/* Shimmer placeholder */
.grid-item::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, var(--bg-primary) 8%, var(--bg-surface) 18%, var(--bg-primary) 33%);
  background-size: 200% 100%;
  animation: shimmer 1.5s linear infinite;
  z-index: 0;
}

.grid-item.loaded::before { display: none; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Video badge */
.grid-item .video-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  color: white;
  font-size: 0.625rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  z-index: 2;
  text-transform: uppercase;
}

/* Responsive */
@media (min-width: 600px) {
  .photo-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 20px 16px 32px; }
  .album-grid { grid-template-columns: repeat(3, 1fr); gap: 16px; padding: 16px 24px; }
  .top-bar { padding: calc(var(--safe-top) + 16px) 24px 16px; }
}

@media (min-width: 1024px) {
  .photo-grid { grid-template-columns: repeat(6, 1fr); gap: 8px; padding: 20px 20px 48px; }
  .album-grid { grid-template-columns: repeat(4, 1fr); }
  .grid-item:hover img { transform: scale(1.03); }
}

/* ===== LIGHTBOX — Immersive Photo Viewer ===== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: #fff;
  animation: lightbox-in 0.25s ease;
}

@keyframes lightbox-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Main image — fills ALL space above thumbnail strip */
.lightbox-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 88px; /* Space for thumbnail strip (64px thumbs + padding) */
  display: grid;
  grid-template-rows: 100%;
  grid-template-columns: 100%;
  place-items: center;
  touch-action: none;
  overflow: hidden;
  cursor: pointer;
}

.lightbox-img {
  /* CSS Grid stacking: both images share same grid cell, centered naturally */
  grid-area: 1 / 1;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: default; /* Allow iOS long-press "Save to Photos" */
  transform-origin: center center;
  will-change: transform;
}

/* When zoomed in, remove CSS size constraints so browser renders native pixels */
.lightbox-img.zoomed {
  max-width: none;
  max-height: none;
  object-fit: fill; /* Explicit dimensions set by JS, no re-constraining */
}

/* HighRes layer sits on top of thumbnail */
.lightbox-img-highres {
  z-index: 1;
}

/* Top bar — auto-hide on tap */
.lightbox-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 6px) 8px 10px;
  z-index: 20;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.6) 50%, transparent 100%);
  transition: opacity var(--transition-normal), transform var(--transition-normal);
}

.lightbox-header.hidden {
  opacity: 0;
  transform: translateY(-20px);
  pointer-events: none;
}

.lightbox-header-left,
.lightbox-header-right {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* Absolute center so it stays centered regardless of left/right widths */
.lightbox-header-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: calc(var(--safe-top) + 6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
}

.lightbox-album-name {
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  text-align: center;
  letter-spacing: 0.02em;
}

.lightbox-photo-name {
  font-size: 0.8125rem;
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  text-align: center;
}

.lightbox-counter {
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ===== ACTION BAR — between photo and thumbs ===== */
.action-bar {
  position: absolute;
  bottom: 88px; /* above thumbnail strip */
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 15;
  padding: 4px 12px;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.action-bar.hidden {
  opacity: 0;
}

.action-bar > * {
  pointer-events: auto;
}

.lightbox-rating {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 10px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.rating-star {
  font-size: 1.35rem;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  line-height: 1;
}

.rating-clear {
  font-size: 1.1rem;
  margin-right: 2px;
  border-right: 1px solid rgba(0,0,0,0.1);
  padding-right: 6px;
  color: #9ca3af !important;
  opacity: 0.7 !important;
}

.rating-star:hover {
  transform: scale(1.15);
}

.rating-star:active {
  transform: scale(0.9);
}

/* ===== FILTER BAR — Photo Mechanic compact style ===== */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 4px 5px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.filter-bar-label {
  font-size: 0.675rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 4px;
  white-space: nowrap;
}

.filter-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 4px;
  border-radius: 5px;
  font-size: 0.825rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
  color: #f59e0b;
}

.filter-chip:hover {
  background: rgba(0, 0, 0, 0.08);
}

.filter-chip:active {
  transform: scale(0.9);
}

.filter-chip:not(.active) {
  opacity: 0.25;
  color: var(--text-muted);
}

/* Grid star badge */
.grid-star-badge {
  position: absolute;
  bottom: 4px;
  left: 4px;
  font-size: 0.6rem;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  color: #fbbf24;
  padding: 2px 4px;
  border-radius: 4px;
  z-index: 2;
  pointer-events: none;
  letter-spacing: -0.5px;
  white-space: nowrap;
}

/* Trash badge for deleted files — matches star badge style */
.grid-trash-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  font-size: 0.6rem;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  padding: 2px 4px;
  border-radius: 4px;
  z-index: 3;
  pointer-events: none;
  line-height: 1;
}

.thumb-trash-badge {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 0.5rem;
  background: rgba(0, 0, 0, 0.6);
  padding: 1px 3px;
  border-radius: 3px;
  pointer-events: none;
  z-index: 3;
  line-height: 1;
}

/* Thumbnail strip: dim filtered-out thumbs */
.thumb-item.filtered-out {
  opacity: 0.15 !important;
  pointer-events: none;
}

/* Thumbnail star badge */
.thumb-star-badge {
  position: absolute;
  bottom: 1px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.5625rem;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.6);
  color: #fbbf24;
  padding: 1px 4px;
  border-radius: 3px;
  pointer-events: none;
  white-space: nowrap;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

@media (min-width: 600px) {
  .lightbox-photo-name { max-width: 300px; font-size: 0.875rem; }
  .lightbox-counter { font-size: 0.75rem; }
}

@media (min-width: 1024px) {
  .lightbox-photo-name { max-width: 500px; font-size: 0.9375rem; }
}

.lightbox-icon-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.lightbox-icon-btn:hover { background: rgba(0, 0, 0, 0.05); }
.lightbox-icon-btn .material-symbols-outlined { font-size: 24px; }

/* Nav arrows — desktop only */
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 72px;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  z-index: 15;
  transition: background var(--transition-fast), opacity var(--transition-normal);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: var(--shadow-sm);
}

.lightbox-prev { left: 8px; }
.lightbox-next { right: 8px; }
.lightbox-nav .material-symbols-outlined { font-size: 32px; }

.lightbox-nav.hidden { opacity: 0; pointer-events: none; }

@media (min-width: 768px) {
  .lightbox-nav { display: flex; }
  .lightbox-nav:hover { background: rgba(255, 255, 255, 0.9); }
}

/* ===== THUMBNAIL STRIP ===== */
.thumbnail-strip {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 15;
  background: linear-gradient(0deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.8) 50%, transparent 100%);
  padding: 10px 0 calc(var(--safe-bottom) + 10px);
  transition: opacity var(--transition-normal);
}

.thumbnail-strip.hidden {
  opacity: 0;
  pointer-events: none;
}

.thumbnail-strip-inner {
  display: flex;
  gap: 3px;
  padding: 0 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  /* 'safe center' falls back to 'start' when content overflows.
     Chrome/Chromium with plain 'center' pushes overflow into unreachable negative scroll. */
  justify-content: safe center;
}

.thumbnail-strip-inner::-webkit-scrollbar { display: none; }

.thumb-item {
  position: relative;
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color var(--transition-fast), opacity var(--transition-fast), box-shadow var(--transition-fast);
  opacity: 0.9;
}

.thumb-item:hover { opacity: 1; }

.thumb-item.active {
  border-color: var(--accent);
  opacity: 1;
  box-shadow: 0 0 0 1px var(--accent), 0 0 6px rgba(37, 99, 235, 0.4);
}

.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-touch-callout: none; /* Prevent long-press save (low quality) */
}

/* Desktop: larger thumbnails */
@media (min-width: 768px) {
  .lightbox-container { bottom: 104px; } /* 80px thumbs + padding */
  .thumbnail-strip-inner { gap: 4px; }
  .thumb-item { width: 80px; height: 80px; border-radius: 5px; }
  .action-bar { bottom: 118px; }
  .thumb-star-badge { font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; bottom: 2px; }
}

/* ===== EXIF INFO PANEL ===== */
.exif-panel {
  position: absolute;
  bottom: 130px; /* above action bar + thumbnail strip + gap */
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 18;
  min-width: 160px;
  max-width: 260px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.6);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
}

.exif-panel.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.exif-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 1px 0;
  font-size: 0.6875rem;
  color: var(--text-primary);
  font-weight: 400;
  line-height: 1.3;
  white-space: nowrap;
}

.exif-row.exif-camera {
  font-weight: 600;
  font-size: 0.75rem;
}

.exif-row.exif-lens {
  color: var(--text-secondary);
  font-size: 0.625rem;
}

.exif-icon {
  flex-shrink: 0;
  width: 14px;
  text-align: center;
  font-size: 0.6875rem;
}

/* Info button active state */
.lightbox-icon-btn.active {
  background: var(--accent-light);
  color: var(--accent);
}

/* Desktop: keep compact EXIF, just raise above larger thumbnails + action bar */
@media (min-width: 768px) {
  .exif-panel {
    bottom: 160px; /* above action bar (118px) + gap */
  }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 0; height: 0; }
