:root {
  --bg-primary: #0a0b0e;
  --bg-secondary: #13151b;
  --bg-card: #181b24;
  --bg-card-hover: #222634;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-green: #10b981;
  --accent-green-glow: rgba(16, 185, 129, 0.25);
  --accent-blue: #3b82f6;
  --accent-gold: #f59e0b;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(255, 255, 255, 0.16);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Outfit', var(--font-sans);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ==========================================================================
   Header fixe & Glassmorphism
   ========================================================================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 11, 14, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.logo-mark {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1px solid var(--border-highlight);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #e2e8f0;
}

.app-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #ffffff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.app-subtitle {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Statut de connexion dynamique */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  transition: all 0.3s ease;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-live {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--accent-green);
}

.status-live .status-dot {
  background: var(--accent-green);
  box-shadow: 0 0 10px var(--accent-green);
  animation: pulseGlow 1.8s infinite ease-in-out;
}

.status-connecting {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--accent-gold);
}

.status-connecting .status-dot {
  background: var(--accent-gold);
}

.icon-button {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-button:active {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.12);
}

/* ==========================================================================
   Barre d'état & Statistiques
   ========================================================================== */
.stats-bar {
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.stats-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.counter-badge {
  color: var(--text-secondary);
  font-weight: 600;
}

.auto-update-hint {
  color: var(--accent-green);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ==========================================================================
   Grille de photos & Cartes
   ========================================================================== */
.gallery-container {
  flex: 1;
  max-width: 1300px;
  width: 100%;
  margin: 0 auto;
  padding: 14px 12px 40px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-flow: dense;
  gap: 12px;
}

@media (min-width: 640px) {
  .photo-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
  }
}

@media (min-width: 1024px) {
  .photo-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }
}

.photo-card {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.25s ease;
}

/* Format Paysage Horizontal (ratio natif Canon 3:2) */
.photo-card.is-landscape {
  aspect-ratio: 3 / 2;
}

/* Format Portrait Vertical (ratio natif Canon 2:3) */
.photo-card.is-portrait {
  aspect-ratio: 2 / 3;
}

.photo-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-highlight);
  box-shadow: 0 12px 24px -10px rgba(0, 0, 0, 0.6);
}

.photo-card:active {
  transform: scale(0.98);
}

.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #14171f;
  transition: opacity 0.3s ease;
}

.photo-card.is-new {
  animation: slideInDown 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  border-color: var(--accent-green);
  box-shadow: 0 0 20px var(--accent-green-glow);
}

.photo-badge-new {
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--accent-green);
  color: #042f1a;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.photo-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 10px;
  background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.8) 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.photo-time {
  font-size: 0.7rem;
  color: #e2e8f0;
  font-weight: 500;
}

.photo-quick-dl {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

/* ==========================================================================
   État Vide (Empty State)
   ========================================================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 55vh;
  padding: 24px;
}

.empty-pulse-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed var(--border-highlight);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  margin-bottom: 20px;
  animation: pulseRotate 6s infinite linear;
}

.empty-state h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  max-width: 380px;
  line-height: 1.5;
  margin-bottom: 24px;
}

.btn-test-upload {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-highlight);
  color: var(--text-primary);
  padding: 10px 18px;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-test-upload:hover {
  background: var(--bg-card-hover);
  border-color: #cbd5e1;
}

/* ==========================================================================
   Lightbox (Plein Écran & Téléchargement)
   ========================================================================== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.lightbox.active {
  opacity: 1;
  pointer-events: auto;
}

.lightbox-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 5, 8, 0.92);
  backdrop-filter: blur(12px);
}

.lightbox-content {
  position: relative;
  z-index: 201;
  width: 100%;
  max-width: 900px;
  height: 100%;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.lightbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
}

.lightbox-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.lightbox-close-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.lightbox-image-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.lightbox-image-wrapper img {
  max-width: 100%;
  max-height: 75vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

.lightbox-footer {
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  border: none;
  font-family: var(--font-sans);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 22px;
  border-radius: 9999px;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}

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

.btn-open-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-highlight);
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  padding: 11px 18px;
  border-radius: 9999px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-open-tab:hover {
  background: rgba(255, 255, 255, 0.16);
}

/* ==========================================================================
   Modal QR Code
   ========================================================================== */
.qr-modal {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.qr-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.qr-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
}

.qr-modal-box {
  position: relative;
  z-index: 211;
  background: var(--bg-card);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.qr-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
}

.qr-modal-box h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.qr-modal-box p {
  color: var(--text-secondary);
  font-size: 0.82rem;
  margin-bottom: 18px;
  line-height: 1.4;
}

.qr-code-wrapper {
  background: white;
  padding: 12px;
  border-radius: var(--radius-md);
  display: inline-block;
  margin-bottom: 14px;
}

.qr-code-wrapper img {
  width: 180px;
  height: 180px;
  display: block;
}

.qr-url-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  word-break: break-all;
}

/* ==========================================================================
   Toasts de notification
   ========================================================================== */
.toast-container {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: rgba(19, 21, 27, 0.95);
  border: 1px solid var(--accent-green);
  color: white;
  padding: 8px 16px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes slideInDown {
  0% {
    opacity: 0;
    transform: translateY(-24px) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pulseGlow {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(1.3);
  }
}

@keyframes pulseRotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s infinite linear;
  position: absolute;
}

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

/* ==========================================================================
   Reconnaissance Faciale par Selfie (Face Search)
   ========================================================================== */

/* Bouton Déclencheur dans l'En-tête */
.btn-face-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-face-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-face-action:active {
  transform: scale(0.97);
}

@media (max-width: 600px) {
  .btn-face-action span {
    display: none;
  }
  .btn-face-action {
    padding: 8px 10px;
  }
}

/* Bannière de Filtre Actif */
.filter-banner {
  max-width: 1300px;
  margin: 10px auto 0;
  padding: 0 12px;
  animation: slideInDown 0.3s ease;
}

.filter-banner-content {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.15) 0%, rgba(139, 92, 246, 0.15) 100%);
  border: 1px solid rgba(139, 92, 246, 0.35);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(8px);
}

.filter-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #e0e7ff;
  font-size: 0.9rem;
  font-weight: 600;
}

.btn-clear-filter {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.btn-clear-filter:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

/* Modale Reconnaissance Faciale */
.face-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.face-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.face-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 15, 0.85);
  backdrop-filter: blur(12px);
}

.face-modal-box {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: #141721;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.9);
  text-align: center;
  z-index: 2;
  transform: translateY(15px);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.face-modal.active .face-modal-box {
  transform: translateY(0);
}

.face-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #94a3b8;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.face-modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

/* Étapes dans la modale */
.face-step {
  display: none;
  animation: fadeIn 0.3s ease;
}

.face-step.active {
  display: block;
}

.face-hero-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2) 0%, rgba(139, 92, 246, 0.2) 100%);
  border: 1px solid rgba(139, 92, 246, 0.4);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #a5b4fc;
}

.face-hero-icon.result-success {
  font-size: 2rem;
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.4);
}

.face-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 8px;
}

.face-subtitle {
  font-size: 0.88rem;
  color: #94a3b8;
  line-height: 1.45;
  margin-bottom: 22px;
}

.face-choice-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.btn-face-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #ffffff;
  border: none;
  padding: 13px 20px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-face-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-face-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn-face-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
}

.btn-face-ghost {
  background: transparent;
  color: #94a3b8;
  border: none;
  padding: 10px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: var(--radius-md);
}

.btn-face-ghost:hover {
  color: #ffffff;
}

.face-privacy-notice {
  font-size: 0.75rem;
  color: #64748b;
  line-height: 1.4;
  margin: 0;
}

/* Caméra en Direct */
.camera-container {
  position: relative;
  width: 260px;
  height: 260px;
  margin: 0 auto 20px;
  border-radius: 50%;
  overflow: hidden;
  background: #000;
  border: 3px solid #6366f1;
  box-shadow: 0 0 25px rgba(99, 102, 241, 0.4);
}

.camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* Miroir naturel pour selfie */
}

.camera-oval-guide {
  position: absolute;
  inset: 15px;
  border: 2px dashed rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  pointer-events: none;
}

.camera-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

/* Animation Scanner IA */
.scanner-visual {
  position: relative;
  width: 160px;
  height: 160px;
  margin: 0 auto 20px;
  border-radius: 50%;
  overflow: hidden;
  background: #0f1319;
  border: 2px solid #6366f1;
}

.scanner-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-laser {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, #22c55e, #38bdf8, transparent);
  box-shadow: 0 0 15px #38bdf8;
  animation: laserSweep 1.8s infinite ease-in-out;
}

@keyframes laserSweep {
  0% { top: 0; opacity: 0; }
  20% { opacity: 1; }
  80% { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

.face-progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 8px;
}

.face-progress-inner {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #22c55e);
  border-radius: var(--radius-full);
  transition: width 0.25s ease;
}

.scan-counter-text {
  font-size: 0.8rem;
  color: #64748b;
  margin: 0;
}

