/* ═══════════════════════════════════════════════
   Agri-découverte PWA — Styles
   Mobile-first, police système, palette verte
═══════════════════════════════════════════════ */

/* ── Variables ── */
:root {
  --vert-fonce:    #2D6A4F;
  --vert-moyen:    #40916C;
  --vert-clair:    #95D5B2;
  --vert-pale:     #D8F3DC;
  --fond:          #F8F9FA;
  --blanc:         #ffffff;
  --texte:         #1a2e1c;
  --texte-sec:     #5a7a62;
  --radius-carte:  20px;
  --radius-btn:    14px;
  --ombre:         0 4px 24px rgba(0,0,0,0.10);
  --font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden; /* Chaque vue gère son propre scroll */
  font-family: var(--font);
  background: var(--vert-fonce);
}

/* ── Système de vues ── */
.vue {
  position: fixed;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  overflow: hidden;
}
.vue.active {
  opacity: 1;
  pointer-events: all;
}

/* ══════════════════════════════════════════════
   VUE 1 — ACCUEIL
══════════════════════════════════════════════ */
#vue-accueil {
  background: linear-gradient(160deg, #1b4332 0%, var(--vert-fonce) 50%, var(--vert-moyen) 100%);
  display: flex;
  flex-direction: column;
}

/* Cercles décoratifs en fond */
.accueil-fond {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.accueil-cercle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.04);
}
.c1 { width: 300px; height: 300px; top: -80px; right: -80px; }
.c2 { width: 200px; height: 200px; bottom: 100px; left: -60px; }

/* Contenu principal */
.accueil-contenu {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: env(safe-area-inset-top, 20px) 28px env(safe-area-inset-bottom, 20px);
  padding-top: max(env(safe-area-inset-top), 20px);
  padding-bottom: max(env(safe-area-inset-bottom), 32px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
}
.logo-icone {
  font-size: 1.8rem;
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,0.12);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.logo-textes {
  display: flex;
  flex-direction: column;
}
.logo-nom {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}
.logo-tagline {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.65);
  margin-top: 1px;
}

/* Illustration centrale */
.accueil-central {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
}
.illustration-cercle {
  width: 120px;
  height: 120px;
  background: rgba(255,255,255,0.10);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  border: 2px solid rgba(255,255,255,0.15);
}
.illustration-emoji { font-size: 3.2rem; }

.accueil-titre {
  font-size: 1.9rem;
  font-weight: 800;
  color: #fff;
  line-height: 1.2;
  letter-spacing: -0.03em;
}
.accueil-desc {
  font-size: 0.92rem;
  color: rgba(255,255,255,0.75);
  line-height: 1.6;
  max-width: 300px;
}

/* Boutons d'accueil */
.accueil-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Boutons communs ── */
.btn-principal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 17px 24px;
  border-radius: var(--radius-btn);
  background: #fff;
  color: var(--vert-fonce);
  font-size: 1rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  transition: transform 0.12s, box-shadow 0.12s;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  text-decoration: none;
}
.btn-principal:active {
  transform: scale(0.97);
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}

.btn-secondaire {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 24px;
  border-radius: var(--radius-btn);
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.9);
  font-size: 0.92rem;
  font-weight: 600;
  border: 1.5px solid rgba(255,255,255,0.2);
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
  text-decoration: none;
}
.btn-secondaire:active { background: rgba(255,255,255,0.18); }

/* ══════════════════════════════════════════════
   VUE 2 — CAMÉRA
══════════════════════════════════════════════ */
#vue-camera {
  background: #000;
}

#video-camera {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}

/* Haut de la caméra */
.camera-haut {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
  padding-top: max(env(safe-area-inset-top), 16px);
}
.camera-instruction {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.85);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.btn-icon-camera {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(0,0,0,0.4);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.btn-icon-camera:active { background: rgba(0,0,0,0.6); }

/* Viseur */
.camera-viseur {
  flex: 1;
  position: relative;
  margin: 0 40px;
}
.viseur-coin {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: rgba(255,255,255,0.8);
  border-style: solid;
}
.viseur-coin.tl { top: 20%; left: 0; border-width: 2px 0 0 2px; border-radius: 4px 0 0 0; }
.viseur-coin.tr { top: 20%; right: 0; border-width: 2px 2px 0 0; border-radius: 0 4px 0 0; }
.viseur-coin.bl { bottom: 20%; left: 0; border-width: 0 0 2px 2px; border-radius: 0 0 0 4px; }
.viseur-coin.br { bottom: 20%; right: 0; border-width: 0 2px 2px 0; border-radius: 0 0 4px 0; }

/* Bas de la caméra */
.camera-bas {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 40px;
  padding-bottom: max(env(safe-area-inset-bottom), 24px);
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
}

/* Bouton capture (grand cercle blanc) */
.btn-capturer {
  position: relative;
  width: 72px;
  height: 72px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-capturer-anneau {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid #fff;
}
.btn-capturer-disque {
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.1s;
}
.btn-capturer:active .btn-capturer-disque {
  transform: scale(0.88);
}

/* Message erreur caméra */
.camera-erreur {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}
.camera-erreur-contenu {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: #fff;
}
.camera-erreur-contenu h3 { font-size: 1.1rem; font-weight: 700; }
.camera-erreur-contenu p { font-size: 0.88rem; color: rgba(255,255,255,0.7); line-height: 1.55; }

/* ══════════════════════════════════════════════
   VUE 3 — CHARGEMENT
══════════════════════════════════════════════ */
#vue-chargement {
  background: #000;
  display: flex;
  flex-direction: column;
}

.chargement-photo-zone {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.chargement-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(3px) brightness(0.5);
}
.chargement-photo-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 60%);
}

.chargement-zone {
  padding: 36px 28px max(env(safe-area-inset-bottom), 48px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Spinner */
.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--vert-clair);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chargement-texte {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}
.chargement-sous {
  font-size: 0.84rem;
  color: rgba(255,255,255,0.55);
}

/* Points animés */
.points-anim::after {
  content: '';
  animation: points 1.4s steps(4, end) infinite;
}
@keyframes points {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
}

/* ══════════════════════════════════════════════
   VUE 4 — RÉSULTAT
══════════════════════════════════════════════ */
#vue-resultat {
  background: var(--fond);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* En-tête vert */
.resultat-header {
  background: linear-gradient(135deg, #1b4332, var(--vert-fonce));
  padding: max(env(safe-area-inset-top), 16px) 20px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.btn-retour-resultat {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.resultat-photo-mini {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
}

.resultat-header-info {
  flex: 1;
  min-width: 0;
}
.resultat-badge {
  display: inline-block;
  background: rgba(255,255,255,0.15);
  color: var(--vert-clair);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 5px;
}
.resultat-titre-h {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Corps du résultat — scrollable */
.resultat-corps {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.resultat-section {}
.section-titre {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--texte-sec);
  margin-bottom: 10px;
}
.resultat-texte {
  font-size: 0.92rem;
  color: var(--texte);
  line-height: 1.65;
}
.resultat-texte p + p { margin-top: 10px; }

/* Fait surprenant */
.resultat-fait {
  background: linear-gradient(135deg, #f0fdf4, #dcfce7);
  border: 1px solid #bbf7d0;
  border-radius: 16px;
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.fait-icone {
  font-size: 1.4rem;
  flex-shrink: 0;
  margin-top: 2px;
}
.fait-titre {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--vert-fonce);
  margin-bottom: 5px;
}
.fait-texte {
  font-size: 0.88rem;
  color: #166534;
  line-height: 1.55;
}

/* Tags régions */
.regions-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.region-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: var(--blanc);
  border: 1.5px solid #dde8df;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--vert-fonce);
}
.region-tag::before {
  content: '📍';
  font-size: 0.75rem;
}

/* Footer résultat */
.resultat-footer {
  padding: 16px 20px max(env(safe-area-inset-bottom), 20px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid #eee;
  background: var(--blanc);
  flex-shrink: 0;
}
.resultat-footer .btn-principal {
  background: var(--vert-fonce);
  color: #fff;
  box-shadow: 0 4px 16px rgba(45,106,79,0.3);
}
.resultat-footer .btn-secondaire {
  background: transparent;
  color: var(--texte-sec);
  border-color: #dde8df;
}

/* ── Bouton Partager ── */
.btn-partager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--vert-moyen);
  font-size: 0.92rem;
  font-weight: 600;
  border: 1.5px solid #c7e8d2;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
}
.btn-partager:active { background: var(--vert-pale); }

/* ── Bouton scanner accueil ── */
.btn-galerie-lien {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.45);
  font-size: 0.82rem;
  cursor: pointer;
  padding: 6px;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ── Vue Scanner ── */
#vue-scanner { background: #000; }

#scanner-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-zone-centrale {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

/* Cadre viseur rectangle pour code-barres */
.scanner-cadre {
  width: 260px;
  height: 100px;
  position: relative;
}

/* Quatre coins du cadre */
.scanner-cadre::before,
.scanner-cadre::after,
.scanner-coin-tr,
.scanner-coin-bl {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border-color: rgba(255,255,255,0.9);
  border-style: solid;
}
.scanner-cadre::before { top: 0; left: 0; border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.scanner-cadre::after  { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }
.scanner-coin-tr { top: 0; right: 0; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.scanner-coin-bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }

/* Laser animé */
.scanner-laser {
  position: absolute;
  left: 8px;
  right: 8px;
  height: 2px;
  background: linear-gradient(to right, transparent, var(--vert-clair), transparent);
  box-shadow: 0 0 8px var(--vert-clair);
  animation: laser 2s ease-in-out infinite;
}
@keyframes laser {
  0%, 100% { top: 12%; }
  50%       { top: 82%; }
}

.scanner-hint {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.6);
  text-align: center;
  letter-spacing: 0.04em;
}

.scanner-statut {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.75);
  font-weight: 500;
  text-align: center;
}

/* ── Historique des scans ── */
.section-historique {
  margin-bottom: 16px;
}

.historique-entete {
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.historique-liste {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: 4px;
}
.historique-liste::-webkit-scrollbar { display: none; }

.historique-carte {
  flex: 0 0 130px;
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.historique-carte:active {
  transform: scale(0.96);
  background: rgba(255,255,255,0.16);
}

.historique-miniature {
  width: 100%;
  height: 80px;
  object-fit: cover;
  display: block;
}
.historique-miniature-vide {
  width: 100%;
  height: 80px;
  background: rgba(255,255,255,0.06);
}

.historique-info {
  padding: 8px 8px 10px;
}
.historique-filiere-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--vert-clair);
  background: rgba(149,213,178,0.15);
  border-radius: 4px;
  padding: 2px 6px;
  margin-bottom: 4px;
}
.historique-nom {
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}
.historique-date {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.4);
}
