:root {
  --wine: #6e1a37;
  --wine-2: #8c2a4c;
  --wine-soft: #f6e9ee;
  --bg: #f7f3ee;
  --card: #ffffff;
  --ink: #2a1f23;
  --muted: #85767b;
  --line: #e8dfd9;
  --gold: #c9962b;
  --ok: #2f7d4f;
  --err: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 20, 30, .06), 0 4px 14px rgba(60, 20, 30, .05);
  --c-rouge: #7d1d3a;
  --c-blanc: #e6d27a;
  --c-rose: #f0a3b4;
  --c-effervescent: #f2e6b0;
  --c-liquoreux: #d39a2c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html, body { overflow-x: hidden; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, .brand span, .stat b { font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; }
h1 { font-size: 1.7rem; margin: .3em 0 .5em; line-height: 1.15; }
h2 { font-size: 1.15rem; margin: 0 0 .6em; }
a { color: var(--wine); }
.muted { color: var(--muted); }
.container { max-width: 980px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.prewrap { white-space: pre-line; margin: 0; }

/* ---------- barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--wine); color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-size: 1.25rem; }
.brand img { width: 28px; height: 28px; background: #fff; border-radius: 8px; padding: 2px; }
.mainnav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.mainnav a { color: #f3dfe6; text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.mainnav a.on, .mainnav a:hover { background: rgba(255,255,255,.14); color: #fff; }
.mainnav .btn { background: #fff; color: var(--wine); margin-left: 6px; }
.usermenu { position: relative; }
.usermenu summary {
  list-style: none; cursor: pointer; width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,.2); display: grid; place-items: center; font-weight: 700;
}
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu .menu {
  position: absolute; right: 0; top: 44px; min-width: 200px; background: #fff; color: var(--ink);
  border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18); overflow: hidden;
}
.menu-head { padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
.menu-head small { display: block; color: var(--muted); font-weight: 400; }
.menu a, .menu button {
  display: block; width: 100%; text-align: left; padding: 11px 14px; color: var(--ink);
  text-decoration: none; background: none; border: 0; font: inherit; cursor: pointer;
}
.menu a:hover, .menu button:hover { background: var(--wine-soft); }

/* ---------- boutons & champs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--wine); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--wine-2); }
.btn-sm { padding: 6px 10px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--wine); box-shadow: inset 0 0 0 1.5px var(--wine); }
.btn-ghost:hover { background: var(--wine-soft); }
.btn-danger-ghost { background: transparent; color: var(--err); box-shadow: inset 0 0 0 1.5px var(--err); }
.btn-danger-ghost:hover { background: #fbeceb; }
.linkbtn { background: none; border: 0; color: var(--wine); font: inherit; font-weight: 600; cursor: pointer; padding: 0; }
label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-size: 16px;
  color: var(--ink); background: #fff; border: 1.5px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--wine); box-shadow: 0 0 0 3px var(--wine-soft); }
textarea { resize: vertical; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
label.check input { width: auto; margin: 0; }
fieldset { border: 0; min-width: 0; }
fieldset.card legend { font-family: Georgia, serif; font-size: 1.05rem; font-weight: 700; color: var(--ink); padding: 0; float: left; width: 100%; margin-bottom: 12px; }
fieldset.card legend + * { clear: both; }
.grid2, .grid3 { display: grid; gap: 0 12px; grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: 1fr 1fr 1fr; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-weight: 500; }
.flash.ok { background: #e7f4ec; color: var(--ok); }
.flash.error { background: #fbeceb; color: var(--err); }

/* ---------- statistiques */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 8px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; text-align: center; color: inherit; text-decoration: none; }
.stat b { display: block; font-size: 1.5rem; color: var(--wine); }
.stat span { font-size: .8rem; color: var(--muted); }
.stat.alert b { color: var(--gold); }
.colorbar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; margin: 0 0 14px; gap: 2px; }
.bg-rouge { background: var(--c-rouge); } .bg-blanc { background: var(--c-blanc); } .bg-rose { background: var(--c-rose); }
.bg-effervescent { background: var(--c-effervescent); } .bg-liquoreux { background: var(--c-liquoreux); }

/* ---------- filtres */
.filters { margin-bottom: 6px; }
.searchrow { display: flex; gap: 8px; }
.searchrow input { margin: 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 6px 12px;
  border-radius: 99px; background: var(--card); box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink); font-size: .9rem; cursor: pointer; user-select: none;
}
.chip input { display: none; }
.chip.on { background: var(--wine); color: #fff; box-shadow: none; }
.selects { display: flex; gap: 8px; margin-top: 6px; }
.selects select { margin: 0; padding: 8px 10px; font-size: 15px; }
.count { font-size: .85rem; margin: 8px 2px; }

/* ---------- liste */
.winelist { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) { .winelist { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.wine { display: flex; align-items: center; gap: 10px; padding: 10px; margin: 0; }
.wine.empty-stock { opacity: .62; }
.wine-link { display: flex; gap: 12px; flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.thumb { width: 58px; height: 80px; flex: none; border-radius: 8px; object-fit: cover; background: var(--wine-soft); }
.nophoto { display: grid; place-items: center; }
.nophoto svg { width: 40%; fill: #d8b8c4; }
.wine-info { min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.wine-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cuvee { font-weight: 400; color: var(--muted); }
.wine-sub, .wine-meta { font-size: .88rem; color: var(--muted); display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
.wine-sub { color: var(--ink); gap: 0 4px; }
.quote { font-style: italic; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; margin-right: 4px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.dot-rouge { background: var(--c-rouge); } .dot-blanc { background: var(--c-blanc); } .dot-rose { background: var(--c-rose); }
.dot-effervescent { background: var(--c-effervescent); } .dot-liquoreux { background: var(--c-liquoreux); }
.stars { color: var(--gold); letter-spacing: 1px; }
.stars.big { font-size: 1.4rem; margin: 4px 0 12px; }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #eee; color: #555; }
.g-jeune { background: #e8eef8; color: #2d5394; }
.g-pret { background: #e7f4ec; color: var(--ok); }
.g-vite { background: #fbf1dc; color: #9a6a0a; }
.g-passe { background: #fbeceb; color: var(--err); }
.t-badge-entree { background: #e7f4ec; color: var(--ok); }
.t-badge-sortie { background: var(--wine-soft); color: var(--wine); }
.t-badge-correction { background: #eef0f3; color: #555; }

/* ---------- compteur +/- */
.qty { display: flex; align-items: center; gap: 4px; flex: none; }
.qnum { min-width: 28px; text-align: center; font-weight: 700; font-size: 1.1rem; }
.qbtn {
  width: 34px; height: 34px; border-radius: 50%; border: 0; cursor: pointer; font-size: 1.2rem; line-height: 1;
  background: var(--wine-soft); color: var(--wine); display: grid; place-items: center;
}
.qbtn:hover:not(:disabled) { background: var(--wine); color: #fff; }
.qbtn:disabled { opacity: .35; cursor: default; }
.qty.big .qbtn { width: 42px; height: 42px; font-size: 1.4rem; }
.qty.big .qnum { font-size: 1.8rem; min-width: 44px; font-family: Georgia, serif; }
.qty.busy { opacity: .5; pointer-events: none; }

/* ---------- fiche */
.back { display: inline-block; margin: 2px 0 10px; text-decoration: none; font-weight: 600; }
.detail { display: grid; gap: 18px; margin-bottom: 14px; }
@media (min-width: 760px) { .detail { grid-template-columns: 300px 1fr; align-items: start; } .detail-photo { position: sticky; top: 76px; } }
.detail-photo img, .bigthumb { width: 100%; max-height: 460px; object-fit: contain; border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); display: block; }
.bigthumb { height: 260px; }
@media (max-width: 759px) { .detail-photo img { max-height: 320px; } .bigthumb { height: 160px; } }
.eyebrow { margin: 0; color: var(--muted); font-size: .9rem; display: flex; align-items: center; }
.detail h1 { margin: .15em 0 0; font-size: 2rem; }
.cuvee-big { margin: 0; font-size: 1.15rem; color: var(--muted); font-style: italic; }
.appellation { margin: .2em 0 0; font-size: 1.1rem; }
.stockbox { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 4px 0 16px; }
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; }
.reco { background: linear-gradient(135deg, #fbf6ea, #fff); border-left: 4px solid var(--gold); }
.comment { border-left: 4px solid var(--wine); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions form { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0 10px 16px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.timeline li.t-sortie::before { background: var(--wine); }
.timeline li.t-entree::before { background: var(--ok); }
.timeline p { margin: 4px 0 0; color: var(--ink); }
.t-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.t-del { margin-left: auto; }
.t-del button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .9rem; }
.t-del button:hover { color: var(--err); }

/* ---------- formulaire */
.wineform { max-width: 720px; }
.photo-pick { display: flex; gap: 14px; align-items: center; }
.photo-preview { width: 90px; height: 120px; border-radius: 10px; background: var(--wine-soft); display: grid; place-items: center; overflow: hidden; flex: none; font-size: .75rem; color: var(--muted); text-align: center; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.filebtn { color: var(--wine); margin-bottom: 8px; white-space: normal; text-align: center; }
.photo-pick > div { min-width: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.starinput { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; border: 0; padding: 0; }
.starinput legend, .starinput .lbl { font-size: .88rem; color: var(--muted); float: left; margin-right: 6px; }
.starinput input { display: none; }
.stars-group { display: inline-flex; flex-direction: row-reverse; }
.stars-group label { font-size: 2rem; color: #ddd3cf; cursor: pointer; margin: 0; padding: 0 2px; line-height: 1; transition: color .1s; }
.stars-group label:hover, .stars-group label:hover ~ label, .stars-group input:checked ~ label { color: var(--gold); }
.nonote { margin: 0; font-size: .8rem; padding: 4px 10px; border-radius: 99px; box-shadow: inset 0 0 0 1px var(--line); cursor: pointer; }
.starinput input:checked + .nonote { background: var(--wine-soft); color: var(--wine); box-shadow: none; }

/* ---------- dialogues */
dialog { border: 0; border-radius: 18px; padding: 20px; width: min(480px, calc(100% - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(30, 10, 18, .45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- divers */
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; margin: 18px 0; color: var(--muted); }
.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr.inactive td { opacity: .5; }
.table select { margin: 0; padding: 6px 8px; font-size: 14px; }
form.inline { margin: 0; }
.pwreset summary { cursor: pointer; color: var(--wine); font-size: .9rem; }
.pwreset form { display: flex; gap: 6px; margin-top: 6px; }
.pwreset input { margin: 0; padding: 6px 8px; }
.narrow { max-width: 440px; }
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login { width: min(380px, 100%); text-align: center; padding: 28px 22px; }
.login label { text-align: left; }
.login-logo { width: 64px; height: 64px; }
.login h1 { margin-top: 6px; color: var(--wine); }
.fab {
  display: none; position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 30;
  width: 58px; height: 58px; border-radius: 50%; background: var(--wine); color: #fff;
  font-size: 2rem; text-decoration: none; place-items: center; box-shadow: 0 6px 20px rgba(110, 26, 55, .45);
}

@media (max-width: 640px) {
  .container { padding: 12px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat b { font-size: 1.3rem; }
  .add-desktop { display: none !important; }
  .fab { display: grid; }
  .selects { flex-wrap: wrap; }
  .selects select { flex: 1 1 45%; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .detail h1 { font-size: 1.6rem; }
  .table thead { display: none; }
  .table tr { display: grid; grid-template-columns: 1fr auto; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .table td { border: 0; padding: 4px 6px; }
  .winelist { padding-bottom: 70px; }
}
