/*
 * Cave à vin — design épuré inspiré d'Apple (feuille autonome, sans framework).
 *
 * Principes : police système, beaucoup d'air, surfaces blanches très
 * arrondies sur fond gris clair, barres translucides floutées, boutons
 * pilule, contrôle segmenté. Mode sombre automatique (prefers-color-scheme).
 * Sémantique conservée : vert = entrées (STOCKER), orange = sorties (DÉSTOCKER).
 */

:root {
  color-scheme: light dark;

  --fond: #f5f5f7;
  --surface: #ffffff;
  --surface-2: rgba(120, 120, 128, 0.12);   /* remplissage discret (inputs, segments) */
  --texte: #1d1d1f;
  --texte-2: #86868b;
  --separateur: rgba(0, 0, 0, 0.08);
  --ombre: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.06);
  --flou-barre: saturate(180%) blur(20px);
  --barre: rgba(255, 255, 255, 0.78);

  --accent: #0071e3;                         /* bleu Apple */
  --vert: #34c759;
  --vert-fonce: #248a3d;
  --orange: #ff9500;
  --orange-fonce: #c93400;
  --rouge: #ff3b30;

  --rayon-carte: 18px;
  --rayon-champ: 12px;
  --hauteur-nav: 4.4rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #000000;
    --surface: #1c1c1e;
    --surface-2: rgba(120, 120, 128, 0.24);
    --texte: #f5f5f7;
    --texte-2: #98989d;
    --separateur: rgba(255, 255, 255, 0.12);
    --ombre: 0 1px 2px rgba(0, 0, 0, 0.4);
    --barre: rgba(22, 22, 23, 0.72);
    --accent: #0a84ff;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.0625rem;                       /* 17px, taille texte iOS */
  line-height: 1.47;
  color: var(--texte);
  background: var(--fond);
  padding-bottom: calc(var(--hauteur-nav) + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 700; letter-spacing: -0.022em; margin: 0 0 0.5rem; }
p { margin: 0.4rem 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
small { color: var(--texte-2); font-size: 0.85rem; }
code {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 0.1em 0.4em;
  border-radius: 6px;
}
ul { padding-left: 1.2rem; }
[hidden] { display: none !important; }

.conteneur {
  max-width: 640px;
  margin: 0 auto;
  padding: 0.9rem 1.1rem 2rem;
}

.titre-page { font-size: 1.7rem; margin: 0.6rem 0 1.1rem; }
.titre-section { font-size: 1.15rem; margin-top: 1.8rem; color: var(--texte); }
.lien-retour { display: inline-block; margin: 0.2rem 0 0.4rem; font-size: 0.95rem; }

/* ---------- Cartes ---------- */
article {
  background: var(--surface);
  border-radius: var(--rayon-carte);
  box-shadow: var(--ombre);
  padding: 1.2rem;
  margin: 0.9rem 0;
}

/* ---------- Barre supérieure (translucide, floutée) ---------- */
.entete {
  position: sticky; top: 0; z-index: 60;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.65rem 1.1rem;
  background: var(--barre);
  -webkit-backdrop-filter: var(--flou-barre);
  backdrop-filter: var(--flou-barre);
  border-bottom: 0.5px solid var(--separateur);
}
.entete-titre { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.form-deconnexion { margin: 0; }
.bouton-discret {
  background: none; border: none; cursor: pointer;
  color: var(--accent); font-size: 0.95rem;
  padding: 0.3rem 0.2rem; width: auto; margin: 0;
}

/* ---------- Navigation par onglets (translucide, bas d'écran) ---------- */
.nav-onglets {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  display: flex;
  height: calc(var(--hauteur-nav) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--barre);
  -webkit-backdrop-filter: var(--flou-barre);
  backdrop-filter: var(--flou-barre);
  border-top: 0.5px solid var(--separateur);
}
.nav-onglets a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.2rem;
  font-size: 0.72rem; font-weight: 500;
  color: var(--texte-2); text-decoration: none;
}
.nav-onglets a:hover { text-decoration: none; }
.nav-onglets a .icone { font-size: 1.45rem; line-height: 1; }
.nav-onglets a.actif { color: var(--accent); }

/* ---------- Formulaires ---------- */
label { display: block; margin-bottom: 0.9rem; font-size: 0.95rem; color: var(--texte); }

input, select, textarea {
  display: block; width: 100%;
  margin-top: 0.3rem;
  padding: 0.7rem 0.85rem;
  font: inherit; color: var(--texte);
  background: var(--surface-2);
  border: none; border-radius: var(--rayon-champ);
  outline: none;
  appearance: none; -webkit-appearance: none;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}
input[type="checkbox"] {
  display: inline-block; width: 1.15rem; height: 1.15rem;
  margin: 0 0.4rem 0 0; vertical-align: -0.2rem;
  accent-color: var(--vert);
  appearance: auto; -webkit-appearance: auto;
}
input::placeholder { color: var(--texte-2); }
select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--texte-2) 50%),
    linear-gradient(135deg, var(--texte-2) 50%, transparent 50%);
  background-position: calc(100% - 1.1rem) 55%, calc(100% - 0.75rem) 55%;
  background-size: 0.35rem 0.35rem;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

/* Boutons : pilule pleine largeur par défaut, à la iOS */
button, a[role="button"] {
  display: block; width: 100%;
  padding: 0.85rem 1.2rem;
  font: inherit; font-weight: 600; text-align: center;
  color: #fff; background: var(--accent);
  border: none; border-radius: 980px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  margin: 0.4rem 0;
}
a[role="button"] { text-decoration: none; }
a[role="button"]:hover { text-decoration: none; }
button:active, a[role="button"]:active { opacity: 0.75; transform: scale(0.985); }
button:disabled { opacity: 0.4; cursor: default; }

/* Variante secondaire : remplissage gris teinté, texte accent (style iOS) */
button.secondary, a[role="button"].secondary {
  background: var(--surface-2);
  color: var(--accent);
}
a[role="button"].outline {
  background: transparent;
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--separateur);
}

.bouton-large { margin-top: 1rem; }
.erreur-champ { color: var(--rouge); display: block; font-size: 0.85rem; margin-top: 0.25rem; }
.grille-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.8rem; }

/* details / summary épurés */
details { margin: 1rem 0; }
summary {
  cursor: pointer;
  color: var(--accent); font-weight: 600; font-size: 0.95rem;
  list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: "›"; display: inline-block; margin-left: 0.35em; transition: transform 0.2s; }
details[open] summary::after { transform: rotate(90deg); }
details > *:not(summary) { margin-top: 0.7rem; }

/* ---------- Écran scan ---------- */
/* Bascule STOCKER / DÉSTOCKER façon contrôle segmenté */
.bascule-mode {
  display: flex; gap: 2px;
  margin: 0.6rem 0 1.1rem;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 14px;
}
.bouton-mode {
  flex: 1; width: auto; margin: 0;
  padding: 0.8rem 0.4rem;
  font-size: 0.95rem; font-weight: 700; letter-spacing: 0.02em;
  background: transparent; color: var(--texte-2);
  border-radius: 11px;
}
.bouton-mode.mode-stocker.actif { background: var(--vert); color: #fff; box-shadow: var(--ombre); }
.bouton-mode.mode-destocker.actif { background: var(--orange); color: #fff; box-shadow: var(--ombre); }

#zone-camera {
  position: relative;
  border-radius: var(--rayon-carte); overflow: hidden;
  background: #000;
  min-height: 250px;
  box-shadow: var(--ombre);
}
#lecteur video { width: 100% !important; display: block; }
.cadre-visee {
  position: absolute; top: 50%; left: 50%;
  width: min(280px, 80%); height: 140px;
  transform: translate(-50%, -50%);
  border: 2.5px solid rgba(255, 255, 255, 0.9);
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.alerte-camera { border-left: 4px solid var(--orange); }
.saisie-secours form { display: flex; gap: 0.6rem; align-items: center; }
.saisie-secours input { margin: 0; }
.saisie-secours button { width: auto; margin: 0; padding: 0.7rem 1.3rem; }

/* Panneaux de scan (fiche inconnue, confirmation de sortie) */
.panneau-scan header { display: grid; gap: 0.15rem; margin-bottom: 0.9rem; }
.panneau-sortie { border-left: 4px solid var(--orange); }
.actions-panneau { display: flex; gap: 0.7rem; margin-top: 0.6rem; }
.actions-panneau button { margin: 0; }

/* ---------- Toasts ---------- */
#zone-flash {
  position: sticky; top: calc(env(safe-area-inset-top) + 3.2rem); z-index: 100;
  padding: 0 1.1rem; max-width: 640px; margin: 0 auto;
}
.toast {
  display: grid; gap: 0.1rem;
  padding: 0.85rem 1.1rem; margin: 0.6rem 0;
  border-radius: 14px;
  background: var(--surface); color: var(--texte);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.16);
  border-left: 5px solid var(--texte-2);
  animation: toast-apparait 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  transition: opacity 0.4s;
}
.toast-disparu { opacity: 0; }
.toast-succes { border-left-color: var(--vert); }
.toast-sortie { border-left-color: var(--orange); }
.toast-erreur { border-left-color: var(--rouge); }
.toast-avertissement { border-left-color: #ffcc00; }
@keyframes toast-apparait {
  from { transform: translateY(-10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---------- Inventaire ---------- */
.grille-filtres {
  display: grid; grid-template-columns: 1fr 1fr auto;
  gap: 0.6rem; align-items: center;
  margin-top: 0.6rem;
}
.grille-filtres select { margin: 0; font-size: 0.92rem; padding: 0.65rem 1.8rem 0.65rem 0.7rem; }
.case-stock { font-size: 0.85rem; white-space: nowrap; margin: 0; }
.resume-inventaire { color: var(--texte-2); font-size: 0.85rem; margin: 0.6rem 0 0.9rem; }

.liste-bouteilles { list-style: none; padding: 0; margin: 0; }
.liste-bouteilles li { margin-bottom: 0.7rem; }
.carte-bouteille {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.95rem 1.1rem;
  background: var(--surface);
  border-radius: var(--rayon-carte);
  box-shadow: var(--ombre);
  color: inherit; text-decoration: none;
  min-height: 3.6rem;                        /* cible tactile confortable */
  transition: transform 0.1s;
}
.carte-bouteille:hover { text-decoration: none; }
.carte-bouteille:active { transform: scale(0.985); }
.infos-bouteille { flex: 1; display: grid; gap: 0.1rem; min-width: 0; }
.infos-bouteille strong { font-weight: 600; letter-spacing: -0.01em; }
.infos-bouteille small {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Pastilles de couleur du vin */
.pastille {
  flex-shrink: 0;
  width: 0.85rem; height: 0.85rem; border-radius: 50%;
}
.couleur-rouge { background: #9f1d35; }
.couleur-blanc { background: #ecdc9a; }
.couleur-rose { background: #f2a0b2; }
.couleur-effervescent { background: #e3c860; }
.couleur-autre { background: #98989d; }

.badge-quantite {
  flex-shrink: 0;
  min-width: 2.3rem; padding: 0.35rem 0.55rem;
  border-radius: 980px;
  background: var(--vert); color: #fff;
  font-weight: 700; font-size: 0.95rem; text-align: center;
  font-variant-numeric: tabular-nums;
}
.badge-quantite.stock-vide { background: var(--surface-2); color: var(--texte-2); }
.badge-quantite.grand { font-size: 1.4rem; min-width: 3.2rem; padding: 0.5rem 0.8rem; }

.liste-vide { color: var(--texte-2); padding: 2rem 1rem; text-align: center; }
.bloc-export form { margin-top: 0.5rem; }
.bloc-export input[type="file"] { padding: 0.55rem 0.85rem; }

/* ---------- Fiche bouteille ---------- */
.fiche-bouteille header { display: grid; gap: 0.2rem; margin-bottom: 1rem; }
.fiche-bouteille h1 { font-size: 1.45rem; margin: 0; }
.fiche-bouteille .sous-titre { color: var(--texte-2); margin: 0; }
.fiche-bouteille .pastille { width: 1rem; height: 1rem; }
.details-bouteille {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem;
  margin: 1rem 0;
}
.details-bouteille > div { min-width: 0; }
.details-bouteille dt {
  font-size: 0.72rem; font-weight: 600;
  color: var(--texte-2); text-transform: uppercase; letter-spacing: 0.04em;
}
.details-bouteille dd { margin: 0.1rem 0 0; font-weight: 500; overflow-wrap: break-word; }
.note-bouteille { color: var(--texte-2); font-style: italic; }

.bloc-stock {
  display: flex; align-items: center; gap: 0.8rem;
  margin: 1.2rem 0;
}
.bloc-stock form { flex: 1; margin: 0; }
.bloc-stock button { margin: 0; }

/* Boutons d'action stock : pilules pleines vert / orange */
.bouton-stocker-plein,
.bouton-destocker-plein {
  width: 100%;
  padding: 0.9rem 1rem;
  font-size: 1.05rem; font-weight: 700; color: #fff;
  border: none; border-radius: 980px;
}
.bouton-stocker-plein { background: var(--vert); }
.bouton-stocker-plein:active { background: var(--vert-fonce); }
.bouton-destocker-plein { background: var(--orange); }
.bouton-destocker-plein:active { background: var(--orange-fonce); }

/* ---------- Historique ---------- */
.filtres-historique {
  background: var(--surface);
  border-radius: var(--rayon-carte);
  box-shadow: var(--ombre);
  padding: 1rem 1.1rem 0.6rem;
  margin-bottom: 1.1rem;
}
.filtres-historique .grille-2 { align-items: end; }

.liste-mouvements { list-style: none; padding: 0; margin: 0.5rem 0; }
.liste-mouvements li {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.75rem 0.2rem;
  border-bottom: 0.5px solid var(--separateur);
}
.liste-mouvements li:last-child { border-bottom: none; }
.infos-mouvement { display: grid; gap: 0.05rem; min-width: 0; }
.liste-mouvements time { font-size: 0.8rem; color: var(--texte-2); font-variant-numeric: tabular-nums; }
.liste-mouvements small { font-style: italic; }

.badge-mouvement {
  flex-shrink: 0;
  min-width: 2.7rem; padding: 0.35rem 0.5rem;
  border-radius: 980px;
  font-weight: 700; font-size: 0.95rem; text-align: center; color: #fff;
  font-variant-numeric: tabular-nums;
}
.badge-mouvement.type-entree { background: var(--vert); }
.badge-mouvement.type-sortie { background: var(--orange); }

.pagination {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.6rem; margin-top: 1.2rem;
  color: var(--texte-2); font-size: 0.9rem;
}
.pagination a { width: auto; margin: 0; padding: 0.6rem 1.1rem; }

/* ---------- Auth / erreurs ---------- */
.carte-auth { max-width: 420px; margin: 2.5rem auto; }
.carte-auth h1 { font-size: 1.5rem; }
.carte-erreur { text-align: center; margin-top: 2.5rem; }

@media (min-width: 768px) {
  .conteneur { padding-top: 1.6rem; }
}

/* ---------- Photo de bouteille ---------- */
.photo-bouteille {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: cover;
  border-radius: var(--rayon-carte);
  margin: 0.9rem 0 0.4rem;
  background: var(--surface-2);
}
.champ-photo {
  border: 0.5px solid var(--separateur);
  border-radius: var(--rayon-carte);
  padding: 0.8rem 0.9rem;
  margin: 0.4rem 0;
}
.champ-photo legend { padding: 0 0.4rem; color: var(--texte-2); font-size: 0.9rem; }
.champ-photo input[type="file"] { width: 100%; margin: 0.4rem 0; }
.photo-actuelle {
  display: block;
  max-width: 160px; max-height: 160px;
  object-fit: cover;
  border-radius: 0.6rem;
  margin-bottom: 0.5rem;
}
.case-supprimer {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.9rem; color: var(--texte-2);
}
.case-supprimer input { width: auto; }

/* ---------- Bannière d'installation (PWA) ---------- */
#install-banner {
  display: flex; align-items: center; gap: 0.6rem;
  margin: 0.6rem auto 0; max-width: 640px;
  padding: 0.7rem 0.9rem;
  background: var(--surface);
  border: 0.5px solid var(--separateur);
  border-radius: var(--rayon-carte);
  box-shadow: var(--ombre);
  font-size: 0.92rem; color: var(--texte);
}
#install-banner[hidden] { display: none; }
.install-icone { font-size: 1.2rem; }
#install-texte { flex: 1; }
#install-bouton {
  flex-shrink: 0; width: auto; margin: 0;
  padding: 0.5rem 1rem; border: none; border-radius: 980px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
#install-fermer {
  flex-shrink: 0; width: auto; margin: 0; padding: 0.3rem 0.5rem;
  background: none; border: none; color: var(--texte-2);
  font-size: 1.1rem; cursor: pointer;
}
