:root {
  --bg: #1c1014;
  --bg2: #26161c;
  --card: #2f1c23;
  --line: #4a2d37;
  --text: #f4ece6;
  --muted: #b9a59f;
  --wine: #9b2242;
  --wine2: #c23a5c;
  --gold: #d9b36c;
  --green: #6fbf8c;
  --red: #e06a6a;
  --rose: #f0a3b4;
  --white: #eee4c2;
  --radius: 14px;
  --font: "Inter", system-ui, sans-serif;
  --serif: "Fraunces", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
a { color: var(--gold); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* header + nav */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: rgba(28,16,20,.92);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { font-family: var(--serif); font-size: 1.25rem; color: var(--text); text-decoration: none; font-weight: 700; }
.brand-mark { color: var(--wine2); }
.icon-btn { color: var(--muted); text-decoration: none; font-size: 1.3rem; padding: 4px 8px; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--bg2); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted);
  text-decoration: none; font-size: .72rem; padding: 4px 0; }
.tabs a span { font-size: 1.25rem; line-height: 1.2; }
.tabs a.active { color: var(--text); }
.tabs a.active span { color: var(--wine2); }
.tab-main span { background: var(--wine); color: #fff !important; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; margin-top: -18px; box-shadow: 0 4px 14px rgba(0,0,0,.4); }

main { max-width: 760px; margin: 0 auto; padding: 16px; }

/* forms */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--wine2); }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: .8rem; color: var(--muted); margin: 10px 0 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--card); border-radius: 12px; padding: 10px 16px; cursor: pointer; text-decoration: none;
  color: var(--text); font-weight: 500; }
.btn.primary { background: var(--wine); border-color: var(--wine); color: #fff; }
.btn.danger { color: var(--red); border-color: #6b2a2a; background: transparent; }
.btn.big { width: 100%; padding: 16px; font-size: 1.05rem; border-radius: 14px; }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.stack > * + * { margin-top: 12px; }
.file-input { display: none; }

/* chips */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: transparent; border-radius: 99px; padding: 6px 12px;
  font-size: .85rem; color: var(--muted); cursor: pointer; }
.chip.on { background: var(--wine); border-color: var(--wine); color: #fff; }
.filters { display: grid; gap: 8px; margin-bottom: 12px; }
.filters .grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.filters select { padding: 8px; font-size: .85rem; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
.toggle input { width: auto; accent-color: var(--wine2); }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.list { display: grid; gap: 10px; }
.item { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; text-decoration: none;
  color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.item.out { opacity: .6; }
.thumb { width: 56px; height: 72px; border-radius: 8px; object-fit: cover; background: var(--bg2);
  display: grid; place-items: center; font-size: 1.5rem; }
.item-title { font-weight: 600; line-height: 1.25; }
.item-sub { color: var(--muted); font-size: .82rem; }
.stock { font-family: var(--serif); font-size: 1.4rem; text-align: center; min-width: 36px; }
.stock small { display: block; font-family: var(--font); font-size: .65rem; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.c-rouge { background: var(--wine2); } .c-blanc { background: var(--white); } .c-rose, .c-rosé { background: var(--rose); }
.c-orange { background: #e9a25b; }
.pill { display: inline-block; font-size: .7rem; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line);
  color: var(--muted); margin-left: 4px; }
.pill.ok { color: var(--green); border-color: #2f5a3f; }
.pill.wait { color: var(--gold); border-color: #6b5530; }
.pill.hurry { color: var(--red); border-color: #6b2a2a; }
.stars { color: var(--gold); letter-spacing: 1px; }
.summary { display: flex; gap: 16px; margin: 4px 0 14px; color: var(--muted); font-size: .9rem; }
.summary b { color: var(--text); font-family: var(--serif); font-size: 1.2rem; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }

/* fiche */
.hero { display: grid; grid-template-columns: 110px 1fr; gap: 14px; align-items: start; }
.hero img, .hero .ph { width: 110px; height: 150px; object-fit: cover; border-radius: 12px; background: var(--bg2);
  display: grid; place-items: center; font-size: 2.5rem; }
.stockbox { display: flex; align-items: center; justify-content: space-between; }
.stockbox .n { font-family: var(--serif); font-size: 2.4rem; }
.round { width: 48px; height: 48px; border-radius: 50%; font-size: 1.5rem; padding: 0; }
.rate { display: flex; gap: 4px; font-size: 2rem; }
.rate button { background: none; border: 0; color: var(--line); cursor: pointer; padding: 0 2px; }
.rate button.on { color: var(--gold); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .9rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { background: var(--bg2); border: 1px solid var(--line); border-radius: 99px; padding: 4px 10px; font-size: .82rem; }
.src { font-size: .7rem; color: var(--muted); border: 1px dashed var(--line); border-radius: 6px; padding: 1px 6px; }
details summary { cursor: pointer; color: var(--muted); }
.hist { font-size: .85rem; color: var(--muted); }
.hist div { padding: 4px 0; border-bottom: 1px solid var(--line); }

/* scan */
.scanner { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; }
.scanner video { display: block; width: 100%; height: auto; }
.scanner canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.scan-status { position: absolute; left: 10px; top: 10px; background: rgba(0,0,0,.6); padding: 4px 10px;
  border-radius: 99px; font-size: .8rem; }
.result { display: grid; grid-template-columns: 6px 1fr; gap: 10px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.result .bar { border-radius: 4px; }
.bar.en_cave { background: var(--green); } .bar.connue { background: var(--gold); } .bar.inconnue { background: var(--line); }
.legend { display: flex; gap: 12px; font-size: .78rem; color: var(--muted); flex-wrap: wrap; }

.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--wine2); border-radius: 50%;
  animation: spin 1s linear infinite; margin: 30px auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { text-align: center; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; opacity: 0;
  transition: .25s; pointer-events: none; z-index: 30; max-width: 90vw; text-align: center; font-weight: 500; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 20; display: grid; place-items: center;
  padding: 16px; overflow-y: auto; }
.modal { background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 20px 16px;
  max-width: 520px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.5); }

.qrbox { background: #fff; padding: 18px; border-radius: 12px; display: inline-block; }
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; }
  .top, .tabs, .no-print { display: none !important; }
  .print-only { display: block; }
  .qr-print { text-align: center; padding-top: 40px; }
}

/* Ajouter : deux photos (étiquette + contre-étiquette) */
.shots { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.shot { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 150px;
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--card); color: var(--text);
  padding: 10px; font: inherit; cursor: pointer; text-align: center; }
.shot.on { border-style: solid; border-color: var(--wine2); }
.shot img { width: 100%; max-height: 120px; object-fit: contain; border-radius: 8px; }
.shot-ico { font-size: 2rem; }
.shot small { color: var(--muted); font-size: .75rem; }
.hero .stack > * + * { margin-top: 8px; }

/* Historique */
.hist-mois { margin: 18px 0 6px; font-size: .95rem; color: var(--muted); text-transform: capitalize; }
.hist-line { display: grid; grid-template-columns: 48px 1fr; gap: 10px; align-items: center; padding: 8px 0;
  border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; }
.hist-line > span:last-child { display: grid; }
.hist-k { font-family: var(--serif); font-size: 1.15rem; text-align: center; border-radius: 10px; padding: 6px 0; }
.hist-k.in { color: var(--green); background: rgba(80, 160, 110, .12); }
.hist-k.out { color: var(--wine2); background: rgba(180, 60, 90, .12); }

/* Administration : photo de profil */
.top > span { display: flex; align-items: center; }
.avatar img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; vertical-align: middle; }
.profil { display: flex; gap: 16px; align-items: center; }
.avatar-big { flex: none; width: 88px; height: 88px; border-radius: 50%; background: var(--bg2); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 2.2rem; overflow: hidden; color: var(--muted); }
.avatar-big img { width: 100%; height: 100%; object-fit: cover; }
