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

:root {
  --primary: #0284c7;
  --primary-glow: rgba(2, 132, 199, 0.4);
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --bg-dark: #000000;
  --glass-bg: rgba(18, 24, 38, 0.75);
  --glass-border: rgba(255, 255, 255, 0.12);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#app-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* ================= VISEUR CAMÉRA ================= */
#viewfinder-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background-color: #000;
  overflow: hidden;
}

#viewfinder {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(1);
}

#viewfinder.mirror {
  transform: scaleX(-1);
}

/* Réticule de focus tactile */
#focus-reticle {
  position: absolute;
  width: 64px;
  height: 64px;
  border: 2px solid #fbbf24;
  border-radius: 8px;
  transform: translate(-50%, -50%) scale(1.4);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.2s ease;
  z-index: 5;
}

#focus-reticle.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Indicateur d'enregistrement vidéo */
#recording-hud {
  position: absolute;
  top: max(75px, calc(env(safe-area-inset-top) + 65px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  border: 1px solid rgba(239, 68, 68, 0.4);
  font-family: monospace;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  z-index: 10;
  animation: fadeIn 0.3s ease;
}

.rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--danger);
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* Toast de statut d'upload */
#status-toast {
  position: absolute;
  top: max(120px, calc(env(safe-area-inset-top) + 110px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(16px);
  border-radius: 24px;
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  font-size: 13px;
  font-weight: 500;
  color: #f1f5f9;
  z-index: 15;
  transition: all 0.3s ease;
}

.toast-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ================= BARRE SUPÉRIEURE ================= */
#top-bar {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px 14px;
  background: linear-gradient(180deg, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0) 100%);
}

#storage-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  backdrop-filter: blur(12px);
  cursor: pointer;
  flex-shrink: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: transform 0.15s ease, background 0.2s ease;
}

#storage-badge:active {
  transform: scale(0.96);
}

.badge-temp {
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid rgba(245, 158, 11, 0.5);
  color: #fbbf24;
}

.badge-r2 {
  background: rgba(249, 115, 22, 0.25);
  border: 1px solid rgba(249, 115, 22, 0.6);
  color: #fb923c;
}

.badge-mega {
  background: rgba(16, 185, 129, 0.2);
  border: 1px solid rgba(16, 185, 129, 0.5);
  color: #34d399;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease, background 0.2s ease;
}

.icon-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.15);
}

.icon-btn.active-pip {
  background: rgba(2, 132, 199, 0.45);
  border-color: #38bdf8;
  color: #38bdf8;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.5);
}

/* ================= BARRE INFÉRIEURE ================= */
#bottom-bar {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.4) 60%, rgba(0,0,0,0) 100%);
}

#mode-selector {
  display: flex;
  gap: 20px;
}

.mode-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.5px;
  padding: 6px 12px;
  cursor: pointer;
  transition: color 0.2s ease, transform 0.2s ease;
}

.mode-btn.active {
  color: #fbbf24;
  transform: scale(1.08);
  text-shadow: 0 0 12px rgba(251, 191, 36, 0.6);
}

#shutter-row {
  width: 100%;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 0 30px;
}

/* Bouton Déclencheur */
#shutter-btn {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  cursor: pointer;
  outline: none;
  border: 4px solid #ffffff;
  background-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, border-color 0.2s ease;
  position: relative;
}

#shutter-btn::after {
  content: "";
  display: block;
  border-radius: 50%;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Mode Photo */
#shutter-btn.shutter-photo::after {
  width: 60px;
  height: 60px;
  background-color: #ffffff;
}

#shutter-btn.shutter-photo:active::after {
  transform: scale(0.88);
}

/* Mode Vidéo - Prêt */
#shutter-btn.shutter-video::after {
  width: 60px;
  height: 60px;
  background-color: var(--danger);
}

/* Mode Vidéo - En cours d'enregistrement */
#shutter-btn.recording {
  border-color: rgba(255, 255, 255, 0.7);
  animation: pulseShutter 1.5s infinite;
}

#shutter-btn.recording::after {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background-color: var(--danger);
}

@keyframes pulseShutter {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Bouton Visionneuse Cloud */
.thumbnail-btn {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.thumb-box {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  overflow: hidden;
  transition: transform 0.15s ease;
}

.thumbnail-btn:active .thumb-box {
  transform: scale(0.92);
}

.count-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  border: 1.5px solid #000;
}

.bottom-spacer {
  width: 48px;
  height: 48px;
}

#privacy-pill {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  background: rgba(0, 0, 0, 0.45);
  padding: 4px 12px;
  border-radius: 12px;
  letter-spacing: 0.3px;
}

/* ================= MODALES ================= */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  background: #111827;
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  border: 1px solid var(--glass-border);
  padding: 24px 20px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
}

.modal-sub {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 4px;
}

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

/* Grille des fichiers */
.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 4px;
}

.file-card {
  background: #1f2937;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
}

.file-preview {
  width: 100%;
  height: 100px;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.file-preview img, .file-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-info {
  padding: 8px;
  font-size: 11px;
}

.file-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.file-meta {
  color: #9ca3af;
  font-size: 10px;
}

.file-actions {
  display: flex;
  justify-content: space-between;
  padding: 6px 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.file-btn {
  background: none;
  border: none;
  color: #38bdf8;
  font-size: 11px;
  cursor: pointer;
  text-decoration: none;
}

.file-btn.del {
  color: #f87171;
}

/* Formulaire Mega */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  color: #cbd5e1;
  font-weight: 500;
}

.form-group input {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #1e293b;
  color: #fff;
  font-size: 14px;
  outline: none;
}

.form-group input:focus {
  border-color: #38bdf8;
}

.primary-btn {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  background: #0284c7;
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.primary-btn:active {
  background: #0369a1;
}

.form-msg {
  padding: 10px;
  border-radius: 8px;
  font-size: 12px;
}

.form-msg.success {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.form-msg.error {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
}

.hidden {
  display: none !important;
}

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