/* =============================================
   SmartSelfie - AI Filters & Branding Engine
   ============================================= */

/* ---- Selfie Booth Modal ---- */
.smart-selfie-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  flex-direction: column;
  animation: smartSelfieFadeIn 0.3s ease-out;
}

@keyframes smartSelfieFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.smart-selfie-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.5);
  flex-shrink: 0;
}

.smart-selfie-header h3 {
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.smart-selfie-close-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.smart-selfie-close-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ---- Live View Container ---- */
#smart-selfie-live-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* ---- Camera Viewport ---- */
.smart-selfie-viewport {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
}

.smart-selfie-viewport video {
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
}

.smart-selfie-viewport canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ---- Filter Carousel ---- */
.smart-selfie-filters {
  flex-shrink: 0;
  padding: 10px 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.smart-selfie-filter-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 16px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.smart-selfie-filter-scroll::-webkit-scrollbar {
  display: none;
}

.smart-selfie-filter-item {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.2s;
}

.smart-selfie-filter-item:active {
  transform: scale(0.93);
}

.smart-selfie-filter-thumb {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  overflow: hidden;
  border: 3px solid transparent;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.smart-selfie-filter-item.active .smart-selfie-filter-thumb {
  border-color: #3B82F6;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.5);
}

.smart-selfie-filter-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.smart-selfie-filter-thumb .filter-emoji {
  font-size: 28px;
  line-height: 1;
}

.smart-selfie-filter-name {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.7);
  text-align: center;
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.smart-selfie-filter-item.active .smart-selfie-filter-name {
  color: #3B82F6;
  font-weight: 600;
}

/* ---- Controls Bar ---- */
.smart-selfie-controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 20px 28px;
  background: rgba(0, 0, 0, 0.8);
  gap: 24px;
}

/* Timer + flip side buttons */
.smart-selfie-side-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  gap: 2px;
  flex-shrink: 0;
}

.smart-selfie-side-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.smart-selfie-side-btn svg {
  width: 20px;
  height: 20px;
}

.smart-selfie-side-btn .timer-label {
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
}

/* ---- Timer Countdown Overlay ---- */
.smart-selfie-timer-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  z-index: 15;
  pointer-events: none;
}

.smart-selfie-timer-overlay span {
  font-size: 96px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

@keyframes timerPulse {
  0% { transform: scale(1.3); opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}

/* Capture button */
.smart-selfie-capture-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: transparent;
  border: 4px solid rgba(255, 255, 255, 0.8);
  cursor: pointer;
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
  padding: 0;
}

.smart-selfie-capture-btn::after {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: #fff;
  transition: background 0.15s;
}

.smart-selfie-capture-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

.smart-selfie-capture-btn:active {
  transform: scale(0.92);
}

.smart-selfie-capture-btn:active::after {
  background: #e5e5e5;
}

/* Flip button */
.smart-selfie-flip-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.3s;
  flex-shrink: 0;
}

.smart-selfie-flip-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.smart-selfie-flip-btn:active {
  transform: rotate(180deg);
}

.smart-selfie-flip-btn svg {
  width: 20px;
  height: 20px;
}

/* ---- Review Screen (Post-Capture) ---- */
.smart-selfie-review {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #000;
}

.smart-selfie-review-image {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 0;
}

.smart-selfie-review-image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.smart-selfie-review-actions {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  padding: 16px 20px 28px;
  justify-content: center;
}

.smart-selfie-review-btn {
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.15s, opacity 0.15s;
}

.smart-selfie-review-btn:active {
  transform: scale(0.96);
}

.smart-selfie-review-btn.retake {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.smart-selfie-review-btn.retake:hover {
  background: rgba(255, 255, 255, 0.25);
}

.smart-selfie-review-btn.share {
  background: #3B82F6;
  color: #fff;
}

.smart-selfie-review-btn.share:hover {
  background: #2563EB;
}

.smart-selfie-review-btn.save {
  background: #22C55E;
  color: #fff;
}

.smart-selfie-review-btn.save:hover {
  background: #16A34A;
}

.smart-selfie-review-btn svg {
  width: 18px;
  height: 18px;
}

/* ---- Loading State ---- */
.smart-selfie-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  z-index: 10;
}

/* Camera viewfinder icon with scanning animation */
.smart-selfie-loading-spinner {
  width: 72px;
  height: 72px;
  position: relative;
}

.smart-selfie-loading-spinner::before,
.smart-selfie-loading-spinner::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: #3B82F6;
  border-style: solid;
}

/* Top-left and bottom-right corners */
.smart-selfie-loading-spinner::before {
  top: 0; left: 0;
  border-width: 3px 0 0 3px;
  border-radius: 4px 0 0 0;
  animation: ssCornerPulse 1.8s ease-in-out infinite;
}
.smart-selfie-loading-spinner::after {
  bottom: 0; right: 0;
  border-width: 0 3px 3px 0;
  border-radius: 0 0 4px 0;
  animation: ssCornerPulse 1.8s ease-in-out infinite;
}

/* Inner corners via the camera icon element */
.smart-selfie-loading-camera {
  position: absolute;
  inset: 0;
}
.smart-selfie-loading-camera::before,
.smart-selfie-loading-camera::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: #3B82F6;
  border-style: solid;
}
.smart-selfie-loading-camera::before {
  top: 0; right: 0;
  border-width: 3px 3px 0 0;
  border-radius: 0 4px 0 0;
  animation: ssCornerPulse 1.8s ease-in-out infinite 0.2s;
}
.smart-selfie-loading-camera::after {
  bottom: 0; left: 0;
  border-width: 0 0 3px 3px;
  border-radius: 0 0 0 4px;
  animation: ssCornerPulse 1.8s ease-in-out infinite 0.2s;
}

/* Scanning line sweeps down through the viewfinder */
.smart-selfie-loading-scanline {
  position: absolute;
  top: 0;
  left: 8px;
  right: 8px;
  height: 2px;
  background: linear-gradient(90deg, transparent, #3B82F6, transparent);
  border-radius: 1px;
  animation: ssScanline 2s ease-in-out infinite;
  opacity: 0.8;
}

/* Camera lens circle in center */
.smart-selfie-loading-lens {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  animation: ssLensPulse 2s ease-in-out infinite;
}
.smart-selfie-loading-lens::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 12px;
  height: 12px;
  background: rgba(59, 130, 246, 0.3);
  border-radius: 50%;
  animation: ssLensPulse 2s ease-in-out infinite 0.3s;
}

@keyframes ssCornerPulse {
  0%, 100% { border-color: #3B82F6; opacity: 0.6; }
  50% { border-color: #60A5FA; opacity: 1; }
}

@keyframes ssScanline {
  0% { top: 8px; opacity: 0; }
  10% { opacity: 0.8; }
  90% { opacity: 0.8; }
  100% { top: calc(100% - 10px); opacity: 0; }
}

@keyframes ssLensPulse {
  0%, 100% { transform: scale(1); opacity: 0.4; }
  50% { transform: scale(1.15); opacity: 0.7; }
}

.smart-selfie-loading-text {
  margin-top: 18px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 0.02em;
}

/* ---- Uploading Overlay ---- */
.smart-selfie-uploading {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #fff;
}

.smart-selfie-uploading-text {
  font-size: 16px;
  font-weight: 600;
}

.smart-selfie-upload-progress {
  width: 200px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  overflow: hidden;
}

.smart-selfie-upload-progress-bar {
  height: 100%;
  background: #3B82F6;
  border-radius: 4px;
  animation: smartSelfieProgress 2s ease-in-out infinite;
  width: 40%;
}

@keyframes smartSelfieProgress {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* ---- Frame Selection Screen (Post-Capture) ---- */
#smart-selfie-frame-select-screen {
  display: flex;
  flex-direction: column;
  background: #000;
  min-height: 0;
}

.smart-selfie-frame-grid-scroll {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
  align-content: start;
}

#smart-selfie-frame-select-screen .smart-selfie-frame-card {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid transparent;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
  aspect-ratio: auto;
}

#smart-selfie-frame-select-screen .smart-selfie-frame-card:hover {
  transform: translateY(-2px);
}

#smart-selfie-frame-select-screen .smart-selfie-frame-card.active {
  border-color: #3B82F6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

#smart-selfie-frame-select-screen .smart-selfie-frame-card-preview {
  padding: 0;
}

#smart-selfie-frame-select-screen .smart-selfie-frame-card-preview canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px 10px 0 0;
}

#smart-selfie-frame-select-screen .smart-selfie-frame-card-name {
  position: static;
  text-align: center;
  padding: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.7);
}

#smart-selfie-frame-select-screen .smart-selfie-frame-card.active .smart-selfie-frame-card-name {
  background: rgba(59, 130, 246, 0.85);
}

.smart-selfie-frame-select-actions {
  flex-shrink: 0;
  display: flex;
  gap: 12px;
  padding: 16px 20px 28px;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
}

/* ---- Admin: Frame Picker Grid ---- */
.smart-selfie-frame-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.smart-selfie-frame-card {
  position: relative;
  border: 2px solid transparent;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
  background: #f1f5f9;
  aspect-ratio: 3/4;
}

.dark-mode .smart-selfie-frame-card,
.dark .smart-selfie-frame-card {
  background: #1e293b;
}

.smart-selfie-frame-card:hover {
  transform: translateY(-2px);
}

.smart-selfie-frame-card.active {
  border-color: #3B82F6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.smart-selfie-frame-card-preview {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.smart-selfie-frame-card-preview canvas {
  width: 100%;
  height: 100%;
  border-radius: 6px;
}

.smart-selfie-frame-card-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

.smart-selfie-frame-card.active .smart-selfie-frame-card-name {
  background: rgba(59, 130, 246, 0.8);
}

/* ---- Admin: Filter Checkbox Grid ---- */
.smart-selfie-filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.smart-selfie-filter-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  transition: border-color 0.2s;
  font-size: 13px;
}

.dark-mode .smart-selfie-filter-toggle,
.dark .smart-selfie-filter-toggle {
  border-color: #334155;
}

.smart-selfie-filter-toggle:hover {
  border-color: #3B82F6;
}

.smart-selfie-filter-toggle input[type="checkbox"] {
  accent-color: #3B82F6;
}

/* ---- Premium Badge ---- */
.smart-selfie-premium-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #a855f7, #6366f1);
  color: #fff;
}

/* ---- Responsive ---- */
@media (min-width: 768px) {
  .smart-selfie-capture-btn {
    width: 76px;
    height: 76px;
  }

  .smart-selfie-filter-thumb {
    width: 64px;
    height: 64px;
  }

  .smart-selfie-filter-name {
    font-size: 11px;
  }

  .smart-selfie-frame-grid-scroll {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Safe area insets for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .smart-selfie-controls {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }

  .smart-selfie-review-actions {
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
  }

  .smart-selfie-frame-select-actions {
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
  }
}

/* ---- Landscape Mode (Mobile) ---- */
@media (orientation: landscape) and (max-height: 500px) {
  /* Hide header completely — close btn repositioned below */
  .smart-selfie-header {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 20;
    background: transparent;
    padding: 8px;
  }

  .smart-selfie-header h3 {
    display: none;
  }

  /* Live-view switches to row layout: camera left, sidebar right */
  #smart-selfie-live-view {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0;
  }

  /* Camera viewport fills left side */
  .smart-selfie-viewport {
    flex: 1;
    min-height: 0;
    min-width: 0;
  }

  .smart-selfie-viewport canvas {
    object-fit: cover;
  }

  /* Right sidebar: filters + controls stacked vertically */
  .smart-selfie-filters {
    padding: 6px 4px;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    width: auto;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 100%;
  }

  .smart-selfie-filter-scroll {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 4px 6px;
    gap: 6px;
    max-height: 100%;
  }

  .smart-selfie-filter-thumb {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .smart-selfie-filter-name {
    font-size: 8px;
    max-width: 44px;
  }

  /* Controls bar: vertical column on the right edge */
  .smart-selfie-controls {
    flex-direction: column;
    padding: 10px 8px;
    gap: 12px;
    width: auto;
    background: rgba(0, 0, 0, 0.85);
  }

  .smart-selfie-capture-btn {
    width: 52px;
    height: 52px;
  }

  .smart-selfie-side-btn {
    width: 36px;
    height: 36px;
  }

  .smart-selfie-side-btn svg {
    width: 15px;
    height: 15px;
  }

  .smart-selfie-side-btn .timer-label {
    font-size: 7px;
  }

  .smart-selfie-flip-btn {
    width: 36px;
    height: 36px;
  }

  .smart-selfie-flip-btn svg {
    width: 15px;
    height: 15px;
  }

  /* Review screen: row layout in landscape */
  .smart-selfie-review {
    flex-direction: row;
  }

  .smart-selfie-review-image {
    flex: 1;
    min-width: 0;
  }

  .smart-selfie-review-actions {
    flex-direction: column;
    padding: 12px;
    gap: 8px;
    justify-content: center;
  }

  .smart-selfie-review-btn {
    padding: 8px 14px;
    font-size: 13px;
  }

  /* Frame selection: row layout — grid left, actions right */
  #smart-selfie-frame-select-screen {
    flex-direction: row;
  }

  .smart-selfie-frame-grid-scroll {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 8px;
    flex: 1;
    min-width: 0;
  }

  .smart-selfie-frame-select-actions {
    flex-direction: column;
    padding: 12px;
    justify-content: center;
    gap: 8px;
  }

  /* Timer overlay: smaller text */
  .smart-selfie-timer-overlay span {
    font-size: 64px;
  }
}

/* Safe area insets for landscape notched phones */
@media (orientation: landscape) and (max-height: 500px) {
  @supports (padding-left: env(safe-area-inset-left)) {
    .smart-selfie-viewport {
      padding-left: env(safe-area-inset-left);
    }

    .smart-selfie-controls {
      padding-right: env(safe-area-inset-right);
    }
  }
}
