/* ============================================================
   VARIABLES & RESET
   ============================================================ */
:root {
  --bg-page: #1a1a2e;
  --bg-header: #16213e;
  --bg-card: #0f3460;
  --bg-lightbox: rgba(0, 0, 0, 0.92);
  --bg-selection-bar: #e94560;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --text-primary: #eaeaea;
  --text-secondary: #a0a0b0;
  --border-radius: 8px;
  --transition-fast: 0.2s ease;
  --transition-med: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  --header-height: 64px;
  --selection-bar-height: 56px;
  --font-family: 'Roboto', system-ui, -apple-system, sans-serif;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   HEADER
   ============================================================ */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--bg-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
}

.header__left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header__icon {
  color: var(--accent);
}

.header__title {
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.header__right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: var(--border-radius);
  transition: background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
  user-select: none;
  white-space: nowrap;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn:active {
  transform: scale(0.96);
}

.btn--icon {
  padding: 8px;
  border-radius: 50%;
}

.btn--icon .btn__label {
  display: none;
}

@media (min-width: 600px) {
  .btn--icon .btn__label {
    display: inline;
  }
  .btn--icon {
    border-radius: var(--border-radius);
    padding: 8px 14px;
  }
}

.btn--primary {
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn--ghost {
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn--ghost:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn--light {
  color: #fff;
}

.btn--light:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn.active {
  background: var(--accent);
  color: #fff;
}

/* ============================================================
   SELECTION BAR
   ============================================================ */
.selection-bar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  z-index: 99;
  height: var(--selection-bar-height);
  background: var(--bg-selection-bar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  transform: translateY(-100%);
  opacity: 0;
  transition: transform var(--transition-med), opacity var(--transition-med);
  pointer-events: none;
}

.selection-bar.visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.selection-bar__count {
  font-weight: 500;
  font-size: 0.95rem;
}

.selection-bar__actions {
  display: flex;
  gap: 8px;
}

/* ============================================================
   GALLERY GRID
   ============================================================ */
.gallery {
  padding-top: calc(var(--header-height) + 16px);
  padding-left: 8px;
  padding-right: 8px;
  padding-bottom: 32px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 4px;
  transition: padding-top var(--transition-med);
}

body.selecting .gallery {
  padding-top: calc(var(--header-height) + var(--selection-bar-height) + 16px);
}

@media (min-width: 600px) {
  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 6px;
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (min-width: 1024px) {
  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 6px;
    padding-left: 24px;
    padding-right: 24px;
  }
}

/* ============================================================
   PHOTO CARD
   ============================================================ */
.photo-card {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: var(--border-radius);
  cursor: pointer;
  background: var(--bg-card);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.photo-card:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  z-index: 2;
}

.photo-card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.photo-card__img.loaded {
  opacity: 1;
}

/* Skeleton shimmer while loading */
.photo-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    110deg,
    var(--bg-card) 25%,
    rgba(255, 255, 255, 0.04) 37%,
    var(--bg-card) 63%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
  z-index: 1;
  transition: opacity 0.3s ease;
}

.photo-card.loaded::before {
  opacity: 0;
  pointer-events: none;
}

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

/* Selection checkbox overlay */
.photo-card__check {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.25);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity var(--transition-fast), transform var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
  pointer-events: none;
}

.photo-card__check svg {
  width: 16px;
  height: 16px;
  stroke: #fff;
  stroke-width: 3;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

body.selecting .photo-card__check {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.photo-card.selected .photo-card__check {
  background: var(--accent);
  border-color: var(--accent);
}

.photo-card.selected .photo-card__check svg {
  opacity: 1;
}

.photo-card.selected::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(233, 69, 96, 0.15);
  border: 3px solid var(--accent);
  border-radius: var(--border-radius);
  z-index: 3;
  pointer-events: none;
}

/* ============================================================
   LIGHTBOX
   ============================================================ */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-med), visibility var(--transition-med);
}

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

.lightbox__overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-lightbox);
}

.lightbox__toolbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 10;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.6), transparent);
}

.lightbox__counter {
  font-size: 0.9rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
}

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

.lightbox__arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(0, 0, 0, 0.35);
  border: none;
  color: #fff;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.lightbox__arrow:hover {
  background: rgba(255, 255, 255, 0.15);
}

.lightbox__arrow:active {
  transform: translateY(-50%) scale(0.92);
}

.lightbox__arrow--prev {
  left: 12px;
}

.lightbox__arrow--next {
  right: 12px;
}

.lightbox__image-wrap {
  position: relative;
  z-index: 5;
  max-width: calc(100vw - 120px);
  max-height: calc(100vh - 100px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox__image {
  max-width: 100%;
  max-height: calc(100vh - 100px);
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  transition: opacity 0.25s ease;
  user-select: none;
  -webkit-user-drag: none;
}

/* Mobile adjustments for lightbox */
@media (max-width: 600px) {
  .lightbox__image-wrap {
    max-width: 100vw;
    max-height: calc(100vh - 80px);
  }

  .lightbox__arrow {
    width: 40px;
    height: 40px;
  }

  .lightbox__arrow--prev {
    left: 4px;
  }

  .lightbox__arrow--next {
    right: 4px;
  }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-page);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-header);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 28px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  z-index: 2000;
  opacity: 0;
  transition: transform var(--transition-med), opacity var(--transition-med);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   PASSWORD GATE
   ============================================================ */
.password-gate {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 46, 0.7);
  backdrop-filter: blur(2px);
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.password-gate.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.password-gate__card {
  background: var(--bg-header);
  border-radius: 16px;
  padding: 48px 40px 40px;
  width: 90%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
}

.password-gate__icon {
  color: var(--accent);
  margin-bottom: 16px;
}

.password-gate__title {
  font-size: 1.6rem;
  font-weight: 500;
  margin-bottom: 6px;
}

.password-gate__subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.password-gate__form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.password-gate__input-wrap {
  position: relative;
}

.password-gate__input {
  width: 100%;
  padding: 14px 48px 14px 16px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.password-gate__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.2);
}

.password-gate__toggle-eye {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-fast), background var(--transition-fast);
}

.password-gate__toggle-eye:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.password-gate__toggle-eye .eye-closed {
  display: none;
}

.password-gate__toggle-eye.showing .eye-open {
  display: none;
}

.password-gate__toggle-eye.showing .eye-closed {
  display: block;
}

.password-gate__input.error {
  border-color: #ff4757;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

.password-gate__error {
  color: #ff4757;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  height: 0;
  margin: 0;
  overflow: hidden;
  transition: opacity var(--transition-fast), height var(--transition-fast), margin var(--transition-fast);
}

.password-gate__error.visible {
  opacity: 1;
  height: 1.2em;
  margin: 4px 0;
}

.password-gate__btn {
  padding: 14px;
  border: none;
  border-radius: var(--border-radius);
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.password-gate__btn:hover {
  background: var(--accent-hover);
}

.password-gate__btn:active {
  transform: scale(0.97);
}

/* Blur app content until authenticated */
body.locked .header,
body.locked .gallery {
  filter: blur(2px) brightness(0.9);
  pointer-events: none;
  user-select: none;
}

body.locked .selection-bar {
  display: none;
}

/* ============================================================
   NO-SCROLL UTILITY
   ============================================================ */
body.no-scroll {
  overflow: hidden;
}
