:root {
  --bg: #faf7f5;
  --fg: #2a1f22;
  --muted: #7a6a6e;
  --card: #ffffff;
  --line: #eadfe2;
  --soft: #f3ebee;
  --accent: #7b1e3a;
  --accent-fg: #ffffff;
  --accent-soft: #f6e3e9;
  --star: #c9932b;
  --danger: #b3261e;
  --ok: #2e7d4f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(42, 31, 34, .06), 0 4px 16px rgba(42, 31, 34, .06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161113;
    --fg: #f3ecee;
    --muted: #b3a4a8;
    --card: #211a1d;
    --line: #3a2d31;
    --soft: #2b2226;
    --accent: #d9708f;
    --accent-fg: #1a0f13;
    --accent-soft: #3a222b;
    --star: #e3b04f;
    --danger: #f2827a;
    --ok: #6fcf97;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100dvh;
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

/* Layout */
.page { max-width: 640px; margin: 0 auto; padding: 12px 16px calc(96px + var(--safe-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 1.2rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  border: 0; background: transparent; padding: 8px; margin: -8px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; color: var(--fg); text-decoration: none;
}
.icon-btn svg { width: 24px; height: 24px; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 16px calc(6px + var(--safe-bottom));
}
.bottomnav-inner { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .75rem; color: var(--muted); text-decoration: none; padding: 4px; }
.bottomnav a.active { color: var(--accent); }
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav a.add {
  background: var(--accent); color: var(--accent-fg); width: 56px; height: 56px; border-radius: 50%;
  justify-content: center; margin-top: -24px; box-shadow: 0 4px 14px rgba(123, 30, 58, .35);
}
.bottomnav a.add svg { width: 28px; height: 28px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg);
  padding: 11px 16px; border-radius: 12px; cursor: pointer; font-weight: 600; text-decoration: none;
  min-height: 46px;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.whatsapp { background: #25d366; border-color: #25d366; color: #fff; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }
.linkbtn { border: 0; background: none; color: var(--accent); padding: 0; cursor: pointer; font-weight: 600; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 12px; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; font-weight: 700; }

/* Login */
.login { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 20px; text-align: center; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; }
.user-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 360px; }
.user-pick button { border: 2px solid var(--line); background: var(--card); border-radius: 16px; padding: 14px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px; font-weight: 600; }
.user-pick button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.pin-dots { display: flex; gap: 14px; justify-content: center; height: 20px; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent); }
.pin-dots span.on { background: var(--accent); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; justify-content: center; }
.keypad button { width: 72px; height: 72px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 1.6rem; cursor: pointer; }
.keypad button:active { background: var(--soft); }
.keypad button.ghost { border: 0; background: transparent; font-size: 1rem; }

/* Avatars */
.avatar {
  --c: var(--accent);
  width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--c); color: #fff; font-weight: 700; font-size: .8rem; flex: none;
}
.avatar.lg { width: 48px; height: 48px; font-size: 1.2rem; }
.avatar.u-angela { --c: #b5487a; }
.avatar.u-dorien { --c: #3f7d6e; }
.avatar.u-tije { --c: #4a63a8; }
.avatars { display: inline-flex; }
.avatars .avatar { width: 24px; height: 24px; font-size: .7rem; border: 2px solid var(--card); }
.avatars .avatar + .avatar { margin-left: -6px; }

/* Search & filters */
.searchrow { display: flex; gap: 8px; margin-bottom: 10px; }
.search { flex: 1; position: relative; }
.search input { width: 100%; padding: 11px 12px 11px 38px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); min-height: 46px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.filter-btn { position: relative; }
.filter-btn .count { position: absolute; top: -6px; right: -6px; background: var(--accent); color: var(--accent-fg); border-radius: 99px; font-size: .7rem; min-width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; padding: 0 5px; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.active-filters button { border: 0; background: var(--accent-soft); color: var(--fg); border-radius: 99px; padding: 5px 10px; font-size: .85rem; cursor: pointer; }
.listmeta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 10px; }
.listmeta select { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 6px 8px; font-size: .875rem; max-width: 60%; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 88dvh; overflow: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + var(--safe-bottom));
}
.sheet-inner { max-width: 640px; margin: 0 auto; }
.sheet-handle { width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 4px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.sheet-foot { position: sticky; bottom: calc(-16px - var(--safe-bottom)); background: var(--bg); padding: 12px 0 0; display: flex; gap: 10px; }
.sheet-foot .btn { flex: 1; }

/* Wine list */
.winelist { display: grid; gap: 10px; }
.winecard { display: flex; gap: 12px; padding: 10px; text-decoration: none; color: inherit; align-items: stretch; }
.winecard .thumb { width: 72px; height: 96px; border-radius: 10px; object-fit: cover; background: var(--soft); flex: none; }
.winecard .thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.winecard .info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.winecard .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.winecard .sub { color: var(--muted); font-size: .875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.winecard .bottom { margin-top: auto; display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.typedot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: 0; flex: none; }
.t-rood { background: #8e1b36; } .t-wit { background: #e9d98b; } .t-rosé { background: #f2a0b5; }
.t-mousserend { background: #d9c77a; box-shadow: inset 0 0 0 2px #fff8; } .t-oranje { background: #e0913f; }
.t-dessert { background: #c58a2b; } .t-versterkt { background: #5e1a2a; } .t-none { background: var(--line); }

.stars { color: var(--star); white-space: nowrap; letter-spacing: 1px; }
.stars .val { color: var(--muted); letter-spacing: 0; margin-left: 4px; font-size: .85rem; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty svg { width: 56px; height: 56px; margin: 0 auto 12px; opacity: .6; }

/* Detail */
.hero { margin: 0 -16px; background: var(--soft); }
.hero img { width: 100%; max-height: 62dvh; object-fit: contain; margin: 0 auto; cursor: zoom-in; }
.hero.noimg { height: 120px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.wine-head { margin-top: 14px; }
.wine-head .sub { color: var(--muted); margin-top: 4px; }
.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .95rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.ai-badge { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 2px 8px; }
.note-head { display: flex; align-items: center; gap: 10px; }
.note-head .who { flex: 1; min-width: 0; }
.note p { margin: 8px 0 0; white-space: pre-wrap; }
.scales { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; margin-top: 10px; font-size: .875rem; }
.bar { display: flex; gap: 3px; }
.bar i { height: 6px; flex: 1; border-radius: 3px; background: var(--line); }
.bar i.on { background: var(--accent); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { background: var(--soft); border-radius: 99px; padding: 3px 10px; font-size: .85rem; }

.lightbox { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox button { position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px; color: #fff; }

/* Forms */
.field { display: block; }
.field > .label { display: block; font-size: .875rem; font-weight: 600; margin-bottom: 6px; }
.field > .hint { display: block; font-size: .8rem; color: var(--muted); margin-top: 4px; }
.input, .field input[type="text"], .field input[type="date"], .field input[type="number"], .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); min-height: 46px;
}
.field textarea { min-height: 84px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip > span, .chip-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  border-radius: 99px; padding: 7px 13px; cursor: pointer; font-size: .9rem; user-select: none;
}
.chip input:checked + span, .chip-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chips.collapsed > .chip-btn:nth-child(n+17):not([aria-pressed="true"]) { display: none; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.starinput { display: inline-flex; gap: 4px; align-items: center; }
.starinput button { border: 0; background: none; padding: 2px; cursor: pointer; width: 42px; height: 42px; position: relative; }
.starinput svg { width: 38px; height: 38px; }
.starinput .val { margin-left: 8px; font-weight: 700; min-width: 3ch; }

.scale { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 8px; }
.scale + .scale { margin-top: 8px; }
.scale .opts { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.scale .opts button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; height: 36px; cursor: pointer; font-size: .8rem; }
.scale .opts button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.scale .ends { grid-column: 2; display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); margin-top: -4px; }

.taginput { border: 1px solid var(--line); border-radius: 12px; background: var(--card); padding: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.taginput .tag { display: inline-flex; align-items: center; gap: 4px; padding: 4px 6px 4px 10px; }
.taginput .tag button { border: 0; background: none; cursor: pointer; padding: 0 4px; color: var(--muted); font-size: 1rem; line-height: 1; }
.taginput input { flex: 1; min-width: 120px; border: 0; background: transparent; padding: 6px; outline: none; }

.photo-pick { display: grid; gap: 10px; }
.photo-preview { border-radius: var(--radius); overflow: hidden; background: var(--soft); position: relative; }
.photo-preview img { width: 100%; max-height: 50dvh; object-fit: contain; }
.scanning { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: rgba(0,0,0,.45); color: #fff; font-weight: 600; }
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.dark { border-color: var(--line); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.steps { display: flex; gap: 6px; margin: 4px 0 14px; }
.steps i { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.steps i.on { background: var(--accent); }

.notice { border-radius: 12px; padding: 10px 12px; background: var(--accent-soft); font-size: .9rem; }
.notice.warn { background: color-mix(in srgb, var(--star) 18%, var(--card)); }

#toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 100; max-width: calc(100% - 32px); text-align: center; font-size: .95rem;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.loading { display: flex; justify-content: center; padding: 48px; }

@media (min-width: 520px) {
  .winelist { grid-template-columns: 1fr 1fr; }
}
.chip input:checked + span .typedot, .chip-btn[aria-pressed="true"] .typedot { box-shadow: 0 0 0 2px #fff; }
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.slot .photo-preview img { height: 220px; max-height: none; object-fit: cover; }
.slot.empty { border: 2px dashed var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; justify-content: center; min-height: 220px; }
.slot-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.slot-foot label { cursor: pointer; }
.hero.gallery { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
.hero.gallery img { flex: 0 0 100%; scroll-snap-align: center; }
.gallery-hint { text-align: center; margin-top: 6px; }
