/* Cave — calcaire froid, encre, bordeaux.
   Le seul élément appuyé : le total et sa « strate » de couleurs de vin. */

/* Polices hébergées avec l'app : disponibles hors ligne dès la première visite. */
@font-face { font-family: 'Young Serif'; font-weight: 400; font-display: swap; src: url(fonts/young-serif-latin-400-normal.woff2) format('woff2'); }
@font-face { font-family: 'Hanken Grotesk'; font-weight: 400; font-display: swap; src: url(fonts/hanken-grotesk-latin-400-normal.woff2) format('woff2'); }
@font-face { font-family: 'Hanken Grotesk'; font-weight: 500; font-display: swap; src: url(fonts/hanken-grotesk-latin-500-normal.woff2) format('woff2'); }
@font-face { font-family: 'Hanken Grotesk'; font-weight: 600; font-display: swap; src: url(fonts/hanken-grotesk-latin-600-normal.woff2) format('woff2'); }

:root {
  --bg: #E9EBE6;          /* calcaire */
  --surface: #F4F5F1;
  --ink: #221B20;
  --muted: #6C666B;
  --line: #D2D4CD;
  --accent: #5E1B2C;      /* bordeaux */
  --accent-ink: #F6EEEF;
  --accent-soft: #E7D9DC;
  --danger: #9A2B1F;
  --ok: #3F6B4A;
  --warn: #9A6A17;

  --c-rouge: #7A1830;
  --c-blanc: #D6C27A;
  --c-rose: #E09C97;
  --c-bulles: #E5DBA6;
  --c-liquoreux: #C07B20;
  --c-autre: #9A969A;

  --serif: 'Young Serif', 'Iowan Old Style', Georgia, serif;
  --sans: 'Hanken Grotesk', -apple-system, 'Helvetica Neue', system-ui, sans-serif;

  --r-sm: 10px;
  --r-lg: 22px;
  --gutter: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1B171A;        /* la cave, lumière basse */
    --surface: #241F23;
    --ink: #EEE7E6;
    --muted: #A19A9E;
    --line: #3A3338;
    --accent: #D98EA0;
    --accent-ink: #2A1219;
    --accent-soft: #3B262D;
    --danger: #E8836F;
    --ok: #8CC09A;
    --warn: #E2B45E;
    --c-rouge: #A8344E;
    --c-blanc: #D9C886;
    --c-rose: #E7A7A2;
    --c-bulles: #EDE3B4;
    --c-liquoreux: #D99236;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 var(--gutter) calc(120px + var(--safe-b));
}

/* --- Barre du haut ------------------------------------------------------ */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  max-width: 640px; margin: 0 auto;
  padding: calc(10px + var(--safe-t)) var(--gutter) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.status {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 36px; padding: 0 14px 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-size: 14px; color: var(--muted);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-state="ok"] .status-dot { background: var(--ok); }
.status[data-state="syncing"] .status-dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.status[data-state="offline"] .status-dot { background: var(--warn); }
.status[data-state="error"] .status-dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; color: var(--ink);
}
.icon-btn:active { background: var(--line); }

/* --- Total et strate ------------------------------------------------------ */
.summary { padding: 18px 0 26px; }
.total {
  margin: 0;
  /* Chiffres en grotesque : les chiffres elzéviriens du serif rendent « 1 » ambigu. */
  font: 500 clamp(80px, 27vw, 132px)/.84 var(--sans);
  letter-spacing: -0.055em;
  font-variant-numeric: lining-nums tabular-nums;
  margin-left: -0.04em;
}
.total-sub { margin: 8px 0 22px; color: var(--muted); font-size: 17px; }

.strata {
  display: flex; gap: 3px; height: 18px;
  border-radius: 4px; overflow: hidden;
}
.strata:empty { background: var(--line); }
.strata span {
  min-width: 6px;
  background: var(--wine);
  transition: flex-grow .5s cubic-bezier(.2,.7,.2,1);
}
.strata span[data-color="bulles"],
.wine[data-color="bulles"]::before,
.swatch[data-color="bulles"] {
  background-image: radial-gradient(circle at 50% 50%, rgb(255 255 255 / .75) 1.2px, transparent 1.6px);
  background-size: 6px 6px;
}
.legend {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  margin: 12px 0 0; padding: 0; list-style: none;
  font-size: 14px; color: var(--muted);
}
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend b { color: var(--ink); font-weight: 600; }
.swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  background-color: var(--wine);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 14%, transparent);
}

/* --- Outils --------------------------------------------------------------- */
.tools { display: grid; gap: 12px; margin-bottom: 8px; }
.search {
  display: flex; align-items: center; gap: 10px;
  height: 48px; padding: 0 14px;
  border-radius: var(--r-sm); background: var(--surface);
  border: 1px solid var(--line); color: var(--muted);
}
.search:focus-within { border-color: var(--ink); }
.search input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; background: transparent; outline: none;
  color: var(--ink); font-size: 17px;
}
.search input::placeholder { color: var(--muted); }

.chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: transparent; font-size: 15px; color: var(--ink);
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip .swatch { width: 9px; height: 9px; border-radius: 50%; }

.sortrow { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.select select {
  appearance: none; -webkit-appearance: none;
  border: 0; background: transparent; padding: 6px 18px 6px 0;
  font-size: 14px; color: var(--muted);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 6px center, right 2px center;
  background-size: 4px 4px; background-repeat: no-repeat;
}
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

/* --- Liste ---------------------------------------------------------------- */
.list { list-style: none; margin: 0; padding: 0; }
.wine {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0 14px 18px;
  border-bottom: 1px solid var(--line);
}
.wine::before {
  content: ''; position: absolute; left: 0; top: 14px; bottom: 14px;
  width: 5px; border-radius: 3px; background-color: var(--wine);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 10%, transparent);
}
.wine.is-empty { opacity: .5; }
.wine-main {
  flex: 1; min-width: 0; display: grid; gap: 2px;
  border: 0; background: none; padding: 0; text-align: left;
}
.wine-name {
  font: 400 19px/1.25 var(--serif);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
}
.wine-name small { font: 400 15px var(--sans); color: var(--muted); margin-left: 6px; }
.wine-meta { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  justify-self: start; margin-top: 4px;
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.badge.late { background: transparent; color: var(--danger); padding-left: 0; }

.qty { display: flex; align-items: center; flex: none; }
.qty output {
  min-width: 2.2ch; text-align: center;
  font: 500 22px/1 var(--sans); font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.qty button {
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; font-size: 22px; line-height: 1; color: var(--muted);
}
.qty button:active { background: var(--accent-soft); color: var(--accent); }
.qty button:disabled { opacity: .25; }

.empty { padding: 48px 0; text-align: center; color: var(--muted); }
.empty h2 { margin: 0 0 6px; font: 400 24px var(--serif); color: var(--ink); }
.empty p { margin: 0 auto; max-width: 32ch; }

/* --- Bouton d'ajout ------------------------------------------------------- */
.fab {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px;
  height: 54px; padding: 0 24px 0 20px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 16px; font-weight: 600;
  box-shadow: 0 10px 30px -10px color-mix(in srgb, var(--accent) 70%, transparent);
}
.fab:active { transform: translateX(-50%) scale(.97); }

/* --- Feuilles (dialogues) ------------------------------------------------- */
.sheet {
  width: 100%; max-width: 640px; max-height: 94dvh;
  margin: auto auto 0; padding: 0;
  border: 0; border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--surface); color: var(--ink);
}
.sheet[open] { animation: rise .32s cubic-bezier(.2,.8,.2,1); }
.sheet::backdrop { background: rgb(20 12 16 / .45); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) {
  .sheet { margin: auto; border-radius: var(--r-lg); max-height: 88vh; }
}
.sheet form, .sheet .sheet-form { display: flex; flex-direction: column; max-height: inherit; }
.sheet-form .sheet-body { padding-bottom: calc(20px + var(--safe-b)); }
.sheet-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 12px 6px var(--gutter);
}
.sheet-head h2 { margin: 0; font: 400 26px/1.1 var(--serif); }
.sheet-body { overflow-y: auto; padding: 8px var(--gutter) 16px; display: grid; gap: 16px; }
.sheet-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 12px var(--gutter) calc(14px + var(--safe-b));
  border-top: 1px solid var(--line);
}
.sheet-foot .btn-primary { flex: 1; }
@media (min-width: 700px) { .sheet-foot .btn-primary { flex: none; } }

.field { display: grid; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field > span, .field > legend { font-size: 13px; font-weight: 500; color: var(--muted); padding: 0; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--bg); font-size: 17px; /* ≥16px : évite le zoom auto sur iPhone */
}
.field textarea { resize: vertical; min-height: 84px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--ink); }
.field input[name="name"] { font: 400 20px var(--serif); }

/* Suggestion de nom : le texte grisé prolonge la saisie, Tab l'accepte. */
.ghost-wrap { position: relative; display: block; }
.ghost {
  position: absolute; inset: 0; padding: 11px 13px; /* padding + bordure de l'input */
  font: 400 20px var(--serif); line-height: normal;
  display: flex; align-items: center; white-space: pre; overflow: hidden;
  pointer-events: none;
}
.ghost-typed { visibility: hidden; }
.field input[name="producer"] ~ .ghost { font: 400 17px var(--sans); }
.ghost-rest { color: var(--muted); opacity: .7; pointer-events: auto; cursor: pointer; }

/* Liste des suggestions : sous le champ, par-dessus les champs suivants. */
.suggest-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5;
  display: block; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: 0 10px 28px rgb(20 12 16 / .16);
  max-height: min(50vh, 340px); overflow-y: auto; overscroll-behavior: contain;
}
.suggest-list[hidden] { display: none; }
.suggest-item {
  display: flex; flex-direction: column; gap: 1px;
  padding: 9px 10px; border-radius: 7px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.suggest-item[aria-selected="true"] { background: var(--accent-soft); }
.suggest-name { font: 400 17px/1.25 var(--serif); color: var(--ink); overflow-wrap: anywhere; }
.suggest-name mark { background: none; color: inherit; font-weight: 600; }
.suggest-meta { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.suggest-meta .swatch { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--wine); }
.suggest-meta .in-cellar { color: var(--ok); font-weight: 500; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }

.colors { display: flex; flex-wrap: wrap; gap: 8px; }
.colors label { position: relative; }
.colors input { position: absolute; opacity: 0; inset: 0; }
.colors span {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 14px 0 10px;
  border: 1px solid var(--line); border-radius: 999px; font-size: 15px;
}
.colors .swatch { width: 14px; height: 14px; border-radius: 50%; }
.colors input:checked + span { border-color: var(--ink); background: var(--bg); box-shadow: inset 0 0 0 1px var(--ink); }
.colors input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.qty-field { grid-template-columns: 1fr auto; align-items: center; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg); font-size: 22px;
}
.stepper input {
  width: 64px; min-height: 46px; text-align: center; border: 0; background: transparent;
  font: 500 24px var(--sans); font-variant-numeric: tabular-nums;
}

.btn-primary, .btn-ghost {
  min-height: 50px; padding: 0 20px; border-radius: 999px; font-weight: 600; font-size: 16px;
}
.btn-primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.btn-ghost { border: 1px solid var(--line); background: transparent; }
.danger { color: var(--danger); }
.form-error { margin: 0; color: var(--danger); font-size: 14px; min-height: 1em; }
.form-error:empty { display: none; }

.hint { margin: 0; color: var(--muted); font-size: 15px; max-width: 46ch; }
.stack { display: grid; gap: 10px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 4px 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; }

/* --- Toast ---------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  width: max-content; max-width: calc(100% - 2 * var(--gutter));
  padding: 10px 10px 10px 18px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-size: 15px; z-index: 20;
}
.toast[hidden] { display: none; }
.toast button {
  border: 0; background: transparent; color: var(--bg); font-weight: 600;
  padding: 8px 10px; border-radius: 8px; text-decoration: underline; text-underline-offset: 3px;
}
.toast button:empty { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Compte en lecture seule */
.readonly .fab,
.readonly .qty button { display: none; }
.readonly .qty output { min-width: 3ch; }

/* --- Photo de l'étiquette ------------------------------------------------------- */
.scan { display: grid; gap: 10px; }
.scan-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; width: 100%; padding: 0 16px;
  border: 1.5px dashed var(--line); border-radius: var(--r-sm);
  background: transparent; color: var(--ink); font-size: 16px; font-weight: 500; cursor: pointer;
}
.scan-btn:active { background: var(--accent-soft); }
.scan-btn svg { color: var(--accent); flex: none; }
.scan-status {
  display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: start;
  padding: 10px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg);
}
.scan-status[hidden] { display: none; }
.scan-status img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: var(--line); }
.scan-body { display: grid; gap: 8px; min-width: 0; }
.scan-msg { margin: 0; font-size: 15px; line-height: 1.35; }
.scan-msg strong { font-weight: 600; }
.scan-status progress {
  width: 100%; height: 4px; border: 0; border-radius: 2px; appearance: none; -webkit-appearance: none;
  background: var(--line); overflow: hidden;
}
.scan-status progress::-webkit-progress-bar { background: var(--line); }
.scan-status progress::-webkit-progress-value { background: var(--accent); transition: width .2s; }
.scan-status progress::-moz-progress-bar { background: var(--accent); }
.scan-status progress[hidden] { display: none; }
.scan-alts { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.scan-alts:empty { display: none; }
.scan-alts > span { font-size: 13px; color: var(--muted); }
.scan-alts button {
  min-height: 34px; padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink); font-size: 14px; cursor: pointer; text-align: left;
}
.scan-alts button:active { background: var(--accent-soft); }

/* --- Connexion ---------------------------------------------------------------- */
.login { display: none; min-height: 100dvh; place-items: center; padding: 24px var(--gutter) calc(24px + var(--safe-b)); }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 16px; }
.login-card h1 { margin: 0; font: 400 44px/1 var(--serif); }
body.logged-out .login { display: grid; }
body.logged-out > :is(header, main, .fab) { display: none; }
