:root {
  --vin: #5c1a2e;
  --vin-clair: #8b2942;
  --creme: #faf6f0;
  --carte: #ffffff;
  --texte: #2d2025;
  --texte-doux: #8a7a80;
  --bordure: #e8dfe2;
  --vert: #2e7d4f;
  --rouge-vin: #9c2b3b;
  --blanc-vin: #c9a227;
  --rose-vin: #e08098;
  --efferv: #7b9acc;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--creme);
  color: var(--texte);
  padding-bottom: 90px;
}

header {
  background: var(--vin);
  color: #fff;
  padding: 16px 20px 12px;
}
header h1 { font-size: 1.3rem; font-weight: 700; }
.stats { font-size: 0.85rem; opacity: 0.85; margin-top: 4px; }

.ligne-entete { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.choix-cave { display: flex; gap: 6px; align-items: center; }
#selecteur-cave {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  padding: 7px 8px;
  font-size: 0.88rem;
  max-width: 170px;
}
#selecteur-cave option { color: var(--texte); }
#btn-gerer-caves {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 0.95rem;
}

.tabs {
  display: flex;
  background: var(--vin);
  padding: 0 12px;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 0;
  border-bottom: 3px solid transparent;
  cursor: pointer;
}
.tab.active { color: #fff; border-bottom-color: #fff; }

main { padding: 14px; max-width: 640px; margin: 0 auto; }

.ligne-recherche { display: flex; gap: 8px; margin-bottom: 14px; }
#recherche {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--bordure);
  border-radius: 12px;
  font-size: 1rem;
  background: var(--carte);
}
#btn-mode {
  width: 46px;
  border: 1px solid var(--bordure);
  border-radius: 12px;
  background: var(--carte);
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

/* Mode liste compacte */
.mode-liste { gap: 6px !important; }
.ligne-vin {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--carte);
  border: 1px solid var(--bordure);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}
.ligne-vin .l-infos {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.92rem;
}
.ligne-vin .l-nom { font-weight: 700; }
.ligne-vin .l-detail { color: var(--texte-doux); }
.ligne-vin .l-qte { font-weight: 800; min-width: 22px; text-align: center; }
.ligne-vin .l-qte.zero { color: var(--texte-doux); }
.btn-stock.petit { width: 30px; height: 30px; font-size: 1.05rem; border-radius: 8px; }

.ligne-outils { display: flex; gap: 10px; margin-bottom: 12px; }
.ligne-outils .btn-evaluer { margin-bottom: 0; }

.apercus { display: flex; gap: 8px; justify-content: center; align-items: flex-start; }
.apercus img { max-height: 180px; max-width: 48%; border-radius: 12px; margin-bottom: 10px; }

.btn-evaluer {
  width: 100%;
  padding: 10px;
  margin-bottom: 12px;
  border: 1px solid var(--bordure);
  border-radius: 12px;
  background: var(--carte);
  color: var(--texte);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-evaluer:disabled { opacity: 0.6; cursor: wait; }
#statut-evaluation { margin-bottom: 12px; }

.liste-vins { display: flex; flex-direction: column; gap: 10px; }

.carte-vin {
  display: flex;
  gap: 12px;
  background: var(--carte);
  border: 1px solid var(--bordure);
  border-radius: 14px;
  padding: 10px;
  cursor: pointer;
}
.carte-vin .vignette {
  width: 62px;
  height: 82px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--creme);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
}
.carte-vin .infos { flex: 1; min-width: 0; }
.carte-vin .nom { font-weight: 700; font-size: 1rem; }
.carte-vin .sous-titre { color: var(--texte-doux); font-size: 0.85rem; margin-top: 1px; }
.carte-vin .details { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; }

.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  color: #fff;
}
.badge.rouge { background: var(--rouge-vin); }
.badge.blanc { background: var(--blanc-vin); }
.badge.rose { background: var(--rose-vin); }
.badge.effervescent { background: var(--efferv); }
.badge.autre { background: var(--texte-doux); }
.badge.gris { background: none; color: var(--texte-doux); border: 1px solid var(--bordure); font-weight: 500; }
.badge.contenance { background: #4a3728; }

.colonne-stock {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-shrink: 0;
}
.qte { font-weight: 800; font-size: 1.15rem; }
.qte.zero { color: var(--texte-doux); }
.boutons-stock { display: flex; gap: 6px; }
.btn-stock {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
}
.btn-stock.entree { background: var(--vert); }
.btn-stock.sortie { background: var(--vin-clair); }
.btn-stock:disabled { opacity: 0.35; }

.vide { text-align: center; color: var(--texte-doux); margin-top: 50px; line-height: 1.6; }

/* Historique */
.liste-mouvements { display: flex; flex-direction: column; gap: 8px; }
.mouvement {
  background: var(--carte);
  border: 1px solid var(--bordure);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.mouvement .m-infos { min-width: 0; }
.mouvement .m-vin { font-weight: 600; font-size: 0.92rem; }
.mouvement .m-date { color: var(--texte-doux); font-size: 0.78rem; margin-top: 2px; }
.mouvement .m-qte { font-weight: 800; white-space: nowrap; }
.mouvement .m-qte.entree { color: var(--vert); }
.mouvement .m-qte.sortie { color: var(--vin-clair); }

/* FAB */
.fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--vin);
  color: #fff;
  font-size: 2rem;
  border: none;
  box-shadow: 0 4px 14px rgba(92, 26, 46, 0.4);
  cursor: pointer;
  z-index: 50;
}

/* Modales */
.modale {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modale[hidden] { display: none; }
.modale-contenu {
  background: var(--carte);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 18px;
}
.modale-contenu.petite { border-radius: 20px; margin-bottom: 30vh; width: calc(100% - 32px); }
.modale-entete { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modale-entete h2 { font-size: 1.15rem; }
.btn-fermer {
  background: var(--creme);
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
}

/* Photo */
.zone-photo { text-align: center; margin-bottom: 16px; }
#apercu-photo { max-height: 180px; max-width: 100%; border-radius: 12px; margin-bottom: 10px; }
.placeholder-photo {
  background: var(--creme);
  border: 2px dashed var(--bordure);
  border-radius: 12px;
  padding: 24px;
  font-size: 2rem;
  color: var(--texte-doux);
  margin-bottom: 10px;
}
.placeholder-photo span { font-size: 0.9rem; }
.boutons-photo { display: flex; gap: 10px; justify-content: center; }
.statut-analyse {
  margin-top: 10px;
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 0.88rem;
  background: #f0e9f5;
  color: #5b3a7e;
}
.statut-analyse.erreur { background: #fdeaea; color: #a33; }
.statut-analyse.ok { background: #e8f5ec; color: var(--vert); }

/* Panneau doublon */
.panneau-doublon {
  background: #f5efdf;
  border: 1px solid #e2d5b0;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
  text-align: center;
}
.doublon-titre { font-weight: 800; margin-bottom: 6px; }
.doublon-texte { color: var(--texte-doux); font-size: 0.92rem; margin-bottom: 14px; }
.boutons-doublon { display: flex; gap: 10px; justify-content: center; }
.boutons-doublon .btn { flex: 1; max-width: 160px; }
.lien-doublon {
  background: none;
  border: none;
  color: var(--texte-doux);
  text-decoration: underline;
  font-size: 0.85rem;
  margin-top: 12px;
  cursor: pointer;
}

/* Formulaire */
form label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--texte-doux); margin-bottom: 10px; }
form input, form select, form textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--bordure);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--texte);
}
.ligne { display: flex; gap: 10px; }
.ligne label { flex: 1; }

.btn {
  display: inline-block;
  border: none;
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-primaire { background: var(--vin); color: #fff; }
.btn-secondaire { background: var(--creme); color: var(--texte); border: 1px solid var(--bordure); font-size: 0.85rem; padding: 9px 12px; }
.btn-danger { background: #fdeaea; color: #a33; }
.pleine-largeur { width: 100%; margin-top: 10px; }
.actions-formulaire { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; }
.actions-formulaire .btn-primaire { flex: 1; }

/* Compteur mouvement */
.mouvement-vin { color: var(--texte-doux); margin-bottom: 14px; }
.compteur { display: flex; align-items: center; justify-content: center; gap: 24px; margin-bottom: 14px; }
#compteur-valeur { font-size: 2rem; font-weight: 800; min-width: 50px; text-align: center; }
.btn-compteur {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--bordure);
  background: var(--creme);
  font-size: 1.5rem;
  cursor: pointer;
}
#mouvement-note { width: 100%; padding: 10px 12px; border: 1px solid var(--bordure); border-radius: 10px; font-size: 0.95rem; }

/* Prix Wine-Searcher */
.champ-prix { display: flex; gap: 6px; align-items: center; }
.champ-prix input { flex: 1; }
.btn-chercher-prix {
  margin-top: 4px;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border: 1px solid var(--bordure);
  border-radius: 10px;
  background: var(--creme);
  font-size: 1.05rem;
  cursor: pointer;
}
.btn-chercher-prix:disabled { opacity: 0.5; }

/* Gestion des caves */
.liste-caves { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.ligne-cave {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--creme);
  border: 1px solid var(--bordure);
  border-radius: 10px;
  padding: 9px 12px;
}
.ligne-cave .cave-nom { flex: 1; font-weight: 600; min-width: 0; }
.ligne-cave .cave-detail { color: var(--texte-doux); font-size: 0.78rem; white-space: nowrap; }
.btn-cave {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 4px;
}
.ajout-cave { display: flex; gap: 8px; }
.ajout-cave input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--bordure);
  border-radius: 10px;
  font-size: 0.95rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--texte);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.9rem;
  z-index: 200;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 640px) {
  .modale { align-items: center; }
  .modale-contenu { border-radius: 20px; }
}
