/* ==========================================================================
   Notre espace — feuille de style mobile-first
   Palette : teal #1D9E75 (principal) / bleu #378ADD (secondaire)
   ========================================================================== */

:root {
  --teal: #1D9E75;
  --teal-dark: #157a5a;
  --blue: #378ADD;
  --bg: #f4faf8;
  --card: #ffffff;
  --text: #16332a;
  --text-muted: #5f7a71;
  --border: #dcebe5;
  --danger: #d9534f;
  --radius: 16px;
  --shadow: 0 4px 16px rgba(22, 51, 42, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Mode sombre (non bloquant, mais apprécié) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1a16;
    --card: #172621;
    --text: #e5f2ec;
    --text-muted: #8fa89e;
    --border: #24382f;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }
}

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

/* L'attribut hidden doit toujours gagner, même contre display:flex/grid
   défini par une classe (sinon la visionneuse et l'onglet masqué
   s'affichent au chargement). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-top: var(--safe-top);
}

/* --------------------------------------------------------------------------
   Boutons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  background: transparent;
  -webkit-tap-highlight-color: transparent;
  transition: transform .1s ease, opacity .15s ease;
}
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:disabled { opacity: .6; }
.btn-block { width: 100%; }
.btn-ghost { padding: 8px; color: var(--text-muted); }

.btn-round {
  width: 54px; height: 54px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  backdrop-filter: blur(6px);
}

/* --------------------------------------------------------------------------
   Page de connexion
   -------------------------------------------------------------------------- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--bg) 60%, rgba(55, 138, 221, .12));
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 36px 28px;
  text-align: center;
}

.login-logo {
  width: 64px; height: 64px;
  color: var(--teal);
  margin-bottom: 12px;
}

.login-card h1 { font-size: 1.6rem; margin-bottom: 4px; }
.login-subtitle { color: var(--text-muted); margin-bottom: 28px; }

.login-card form { text-align: left; }
.login-card label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 14px 0 6px;
}
.login-card input {
  width: 100%;
  padding: 13px 14px;
  font-size: 1rem;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.login-card input:focus { border-color: var(--teal); }
.login-card .btn-primary { margin-top: 24px; }

.error-msg {
  color: var(--danger);
  font-size: .9rem;
  margin-top: 14px;
  text-align: center;
}

/* --------------------------------------------------------------------------
   En-tête + onglets (galerie)
   -------------------------------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 8px;
}
.app-header h1 { font-size: 1.5rem; color: var(--teal); }
.header-actions { display: flex; align-items: center; gap: 6px; }
.me-name { color: var(--text-muted); font-size: .9rem; font-weight: 600; }

.tabs {
  display: flex;
  gap: 8px;
  padding: 8px 18px 14px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.tab {
  flex: 1;
  border: none;
  padding: 10px 0;
  border-radius: 999px;
  font-size: .95rem;
  font-weight: 600;
  background: var(--card);
  color: var(--text-muted);
  box-shadow: var(--shadow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab.active { background: var(--teal); color: #fff; }
#tab-received.active { background: var(--blue); }

.badge-count {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #fff;
  color: var(--blue);
  font-size: .75rem;
  margin-left: 4px;
}

/* --------------------------------------------------------------------------
   Grille photos
   -------------------------------------------------------------------------- */
.gallery-wrap { padding: 0 18px calc(110px + var(--safe-bottom)); }

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
@media (min-width: 600px) { .grid { grid-template-columns: repeat(4, 1fr); gap: 8px; } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(6, 1fr); } }

.tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
}
.tile img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

/* Photo verrouillée : floutée + cadenas + bouton Déverrouiller */
.tile.locked img { filter: blur(14px) brightness(.85); transform: scale(1.1); }
.tile .lock-badge {
  position: absolute;
  top: 6px; right: 6px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
}
.tile .unlock-btn {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  border: none;
  background: rgba(29, 158, 117, .92);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  padding: 8px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.tile .unlock-btn:active { transform: translate(-50%, -50%) scale(.95); }

/* Bouton menu ⋯ sur mes photos */
.tile .menu-btn {
  position: absolute;
  bottom: 6px; right: 6px;
  width: 30px; height: 30px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Badge minuteur (temps restant avant auto-suppression) */
.tile .timer-badge {
  position: absolute;
  left: 6px; bottom: 6px;
  max-width: calc(100% - 44px);
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: .62rem;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
  font-size: .95rem;
}

/* Bouton flottant caméra */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + var(--safe-bottom));
  width: 62px; height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--blue));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(29, 158, 117, .45);
  z-index: 10;
}

/* Visionneuse plein écran */
.viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.viewer img { max-width: 100%; max-height: 100%; }
.viewer-close {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: 16px;
  width: 40px; height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   Page capture
   -------------------------------------------------------------------------- */
.capture-page {
  background: #000;
  color: #fff;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.capture-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  z-index: 5;
}
.capture-back { color: #fff; }
.capture-hint {
  font-size: .82rem;
  color: rgba(255, 255, 255, .85);
  background: rgba(255, 255, 255, .12);
  border-radius: 999px;
  padding: 6px 12px;
}

.camera-wrap {
  position: relative;
  flex: 1;
  overflow: hidden;
  border-radius: 20px;
  margin: 0 10px;
}
.camera-wrap video {
  width: 100%; height: 100%;
  object-fit: cover;
}
.camera-wrap video.mirror { transform: scaleX(-1); } /* caméra avant : effet miroir */

.camera-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
  color: rgba(255, 255, 255, .9);
}
.camera-error .small { font-size: .85rem; color: rgba(255, 255, 255, .6); }

/* Flash blanc bref à la capture */
.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.flash.on { animation: flashAnim .25s ease-out; }
@keyframes flashAnim { 0% { opacity: .9; } 100% { opacity: 0; } }

.capture-controls {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 22px 30px calc(22px + var(--safe-bottom));
}

.shutter {
  width: 76px; height: 76px;
  border-radius: 50%;
  border: 5px solid #fff;
  background: transparent;
  position: relative;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.shutter::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: #fff;
  transition: transform .1s ease;
}
.shutter:active::after { transform: scale(.85); }
.shutter:disabled { opacity: .5; }

/* --------------------------------------------------------------------------
   Bottom-sheet (menu d'actions par photo)
   -------------------------------------------------------------------------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: flex-end;
  z-index: 60;
}
.sheet {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(16px + var(--safe-bottom));
  animation: sheetUp .18s ease-out;
}
@keyframes sheetUp { from { transform: translateY(30%); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-title {
  text-align: center;
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.sheet-actions { display: flex; flex-direction: column; gap: 8px; }
.sheet-actions .btn {
  background: var(--bg);
  justify-content: flex-start;
  font-weight: 600;
}
.sheet-actions .btn.danger { color: var(--danger); }
.sheet-cancel { width: 100%; margin-top: 10px; color: var(--text-muted); }

/* --------------------------------------------------------------------------
   Modale de confirmation
   -------------------------------------------------------------------------- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 70;
}
.confirm-box {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border-radius: 20px;
  padding: 22px 20px;
  text-align: center;
  box-shadow: var(--shadow);
}
.confirm-box p { font-weight: 600; }
.confirm-sub {
  font-weight: 400 !important;
  font-size: .85rem;
  color: var(--text-muted);
  margin-top: 6px;
}
.confirm-btns { display: flex; gap: 10px; margin-top: 18px; }
.confirm-btns .btn { flex: 1; background: var(--bg); }
.btn-danger { background: var(--danger) !important; color: #fff; }

/* --------------------------------------------------------------------------
   Toast (messages éphémères)
   -------------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}
.capture-page .toast { background: rgba(255, 255, 255, .92); color: #111; }
