/* WeinScan – ruhige Oberfläche wie eine Weinkarte: Einträge mit feinen Linien,
   die Vivino-Bewertung als grosse Serifenziffer ist das einzige laute Element. */

:root {
  --bg: #F2F0F3;
  --surface: #FFFFFF;
  --ink: #241A1F;
  --ink-2: #6B5F66;
  --ink-3: #9A8F95;
  --rule: #DDD6DB;
  --accent: #8E1F3F;
  --accent-ink: #FFFFFF;
  --accent-soft: #F3E3E9;
  --warn: #A8641A;
  --bad: #B3261E;
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --tabs-h: 58px;
  --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: #1A1416;
    --surface: #251C20;
    --ink: #F1E9EC;
    --ink-2: #B5A6AD;
    --ink-3: #85767D;
    --rule: #3A2E33;
    --accent: #E07A96;
    --accent-ink: #1A1416;
    --accent-soft: #3A2129;
    --warn: #E0A458;
    --bad: #F2867E;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Grundgerüst ---------- */
main { position: fixed; inset: 0 0 calc(var(--tabs-h) + var(--safe-b)) 0; }
.view { position: absolute; inset: 0; display: none; flex-direction: column; background: var(--bg); padding-top: var(--safe-t); }
.view.active { display: flex; }
.view.overlay { z-index: 5; }
.view.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

.bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px 8px; min-height: 52px; flex: none;
}
.bar h1 { font: 600 22px/1.15 var(--serif); margin: 0; flex: 1; letter-spacing: -0.01em; }
.bar .icon-btn { margin-right: -8px; }
.bar .back { margin-left: -8px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--rule);
}
.tabs button {
  flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--ink-3); padding: 0;
}
.tabs button.active { color: var(--accent); }
.tabs svg { width: 25px; height: 25px; }

.icon-btn { border: 0; background: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 20px; color: var(--ink-2); padding: 0; flex: none; }
.icon-btn:active { background: var(--accent-soft); }

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; font-size: 16px;
  background: var(--accent); color: var(--accent-ink); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:disabled { opacity: .45; }
.btn.quiet { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: none; color: var(--accent); padding: 8px 4px; font-weight: 500; }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 9px; }
.btn.danger { background: none; color: var(--bad); }
.btn svg { width: 20px; height: 20px; }

.banner {
  position: fixed; top: calc(var(--safe-t) + 8px); left: 12px; right: 12px; z-index: 20;
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 12px 10px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 15px;
}

/* ---------- Scannen ---------- */
.scan-actions {
  flex: none; display: flex; gap: 10px; padding: 10px 16px 12px;
  border-top: 1px solid var(--rule); background: var(--bg);
}
.scan-actions .btn:first-child { flex: 1; }

.empty {
  flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 24px 28px 48px;
}
.empty h2 { font: 600 30px/1.1 var(--serif); margin: 0 0 12px; letter-spacing: -0.015em; }
.empty p { color: var(--ink-2); margin: 0 0 8px; max-width: 34ch; }
.empty .glass { color: var(--accent); width: 44px; height: 44px; margin-bottom: 18px; stroke-width: 1.2; }

/* ---------- Seiten zum Blättern ---------- */
.pager-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pager-head { display: flex; align-items: center; gap: 10px; padding: 0 16px 8px; flex: none; color: var(--ink-2); font-size: 13px; }
.dots { display: flex; gap: 5px; }
.dots i { width: 6px; height: 6px; border-radius: 3px; background: var(--rule); transition: width .2s, background .2s; }
.dots i.on { width: 16px; background: var(--accent); }
.pager {
  flex: 1; display: flex; overflow-x: auto; overflow-y: hidden; min-height: 0;
  scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain;
}
.pager::-webkit-scrollbar { display: none; }
.slide { flex: 0 0 100%; scroll-snap-align: start; scroll-snap-stop: always; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 24px; }

.page-head { display: flex; gap: 12px; align-items: flex-start; padding: 4px 0 14px; border-bottom: 1px solid var(--rule); }
.page-thumb { width: 54px; height: 72px; border-radius: 6px; object-fit: cover; background: var(--rule); border: 0; padding: 0; flex: none; overflow: hidden; }
.page-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.page-meta { flex: 1; min-width: 0; }
.page-meta .when { font-weight: 600; font-size: 15px; }
.page-meta .where, .page-meta .count { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.page-meta .where { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sortbar { display: flex; gap: 6px; padding: 12px 0 2px; }
.chip { border: 1px solid var(--rule); background: none; border-radius: 16px; padding: 5px 12px; font-size: 13px; color: var(--ink-2); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.progress { display: flex; align-items: center; gap: 12px; padding: 28px 0; color: var(--ink-2); }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--rule); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.page-error { padding: 20px 0; }
.page-error p { color: var(--bad); margin: 0 0 12px; }
.page-note { font-size: 13px; color: var(--ink-2); padding: 12px 0 0; }

/* ---------- Wein-Eintrag ---------- */
.wine { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; padding: 16px 0; border-bottom: 1px solid var(--rule); align-items: start; }
.wine .bottle { width: 44px; height: 88px; display: grid; place-items: center; }
.wine .bottle img { max-width: 100%; max-height: 100%; object-fit: contain; }
.wine .bottle svg { color: var(--ink-3); width: 26px; height: 26px; }
.wine-main { min-width: 0; }
.producer { font-size: 13px; color: var(--ink-2); }
.wine-name { font: 600 18px/1.25 var(--serif); margin: 1px 0 2px; }
.origin { font-size: 13px; color: var(--ink-3); }
.cardline { font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.note { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }
.confirmed { display: inline-flex; align-items: center; gap: 3px; font-size: 12.5px; color: var(--accent); margin-top: 4px; }
.confirmed svg { width: 14px; height: 14px; stroke-width: 2.2; }

.score { text-align: right; min-width: 56px; }
.score .num { font: 600 32px/1 var(--serif); letter-spacing: -0.02em; font-variant-numeric: lining-nums; }
.score .num.top { color: var(--accent); }
.score .num.mid { color: var(--ink); }
.score .num.low { color: var(--ink-3); }
.score .of { font-size: 11.5px; color: var(--ink-3); margin-top: 3px; line-height: 1.3; }
.score .none { font-size: 12px; color: var(--ink-3); }
.wine .icon-btn { width: 32px; height: 32px; margin: 6px -6px 0 auto; }

/* nicht identifizierte Einträge: Kartentext wie gedruckt, gedämpft */
.wine.open .raw { font: italic 16px/1.35 var(--serif); color: var(--ink); }
.status { font-size: 12.5px; font-weight: 600; margin-bottom: 3px; }
.status.ambiguous { color: var(--warn); }
.status.notFound, .status.insufficient { color: var(--ink-3); }
.status.error { color: var(--bad); }

.cands { margin-top: 10px; }
.cands summary { font-size: 13.5px; color: var(--accent); cursor: pointer; list-style: none; }
.cands summary::-webkit-details-marker { display: none; }
.cand { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 10px 0 0; }
.cand img { width: 28px; height: 48px; object-fit: contain; }
.cand .t { font-size: 14px; line-height: 1.3; }
.cand .r { font-size: 12.5px; color: var(--ink-2); }
.cand .acts { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

/* ---------- Historie ---------- */
.jump { display: flex; align-items: center; gap: 8px; padding: 0 16px 12px; }
.jump label { font-size: 14px; color: var(--ink-2); }
.jump input { font: inherit; font-size: 15px; border: 1px solid var(--rule); background: var(--surface); color: var(--ink); border-radius: 9px; padding: 6px 8px; }
.month { font: 600 15px/1.2 var(--serif); color: var(--ink-2); padding: 18px 16px 6px; }
.day {
  display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: center; width: 100%;
  border: 0; background: none; text-align: left; padding: 10px 16px; border-bottom: 1px solid var(--rule);
}
.day:active { background: var(--accent-soft); }
.day img, .day .ph { width: 44px; height: 58px; object-fit: cover; border-radius: 5px; background: var(--rule); }
.day .d { font-weight: 600; }
.day .s { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.day .p { font-size: 13px; color: var(--ink-3); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Karte ---------- */
#map { flex: 1; min-height: 0; }
.map-empty { position: absolute; left: 16px; right: 16px; top: calc(var(--safe-t) + 64px); z-index: 500; margin: 0; background: var(--surface); padding: 10px 14px; border-radius: 10px; font-size: 14px; color: var(--ink-2); }
.pin { width: 30px; height: 30px; border-radius: 15px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); font: 600 13px var(--sans); }
.pin svg { width: 17px; height: 17px; stroke-width: 1.8; }
.leaflet-popup-content { margin: 12px 14px; font: 14px/1.35 var(--sans); }
.leaflet-popup-content .pt { font-weight: 600; margin-bottom: 2px; }
.leaflet-popup-content .ps { color: #6B5F66; margin-bottom: 8px; }

/* ---------- Einstellungen ---------- */
.settings { padding: 0 16px 40px; }
.group { margin: 18px 0 0; }
.group h2 { font: 600 17px/1.2 var(--serif); margin: 0 0 6px; }
.rows { background: var(--surface); border-radius: 12px; overflow: hidden; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--rule); min-height: 48px; }
.row:last-child { border-bottom: 0; }
.row .k { flex: 1; }
.row .v { color: var(--ink-2); text-align: right; }
.row select, .row input[type=date] { font: inherit; font-size: 15px; color: var(--ink); background: none; border: 0; text-align: right; max-width: 60%; }
.row.btnrow { padding: 4px 6px; }
.row.btnrow .btn { width: 100%; justify-content: flex-start; }
.help { font-size: 13px; color: var(--ink-3); margin: 6px 4px 0; }
.result { font-size: 13px; color: var(--ink-2); padding: 0 14px 12px; white-space: pre-line; }
.switch { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 15px; background: var(--rule); position: relative; transition: background .2s; flex: none; margin: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px; border-radius: 13px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

/* ---------- Dialoge ---------- */
dialog { border: 0; padding: 0; color: var(--ink); }
dialog::backdrop { background: rgba(20, 10, 14, .45); }
.sheet {
  width: 100%; max-width: 560px; margin: auto auto 0; border-radius: 16px 16px 0 0; background: var(--surface);
  padding: 8px 16px calc(16px + var(--safe-b));
}
.sheet h3 { font: 600 17px/1.3 var(--serif); margin: 10px 4px 10px; }
.sheet .sub { font-size: 13px; color: var(--ink-2); margin: -4px 4px 10px; }
.sheet .act { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 14px 4px; font-size: 17px; border-top: 1px solid var(--rule); color: var(--ink); }
.sheet .act.destructive { color: var(--bad); }
.sheet .act.cancel { color: var(--ink-2); }
.sheet textarea { width: 100%; font: 16px/1.4 var(--sans); color: var(--ink); background: var(--bg); border: 1px solid var(--rule); border-radius: 10px; padding: 10px; resize: vertical; min-height: 70px; }
.sheet .raw-box { font: italic 15px/1.35 var(--serif); color: var(--ink-2); margin: 0 4px 12px; }
.sheet .buttons { display: flex; gap: 10px; margin-top: 14px; }
.sheet .buttons .btn { flex: 1; }

.viewer { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; background: #000; }
.viewer .scroller { position: absolute; inset: 0; overflow: auto; -webkit-overflow-scrolling: touch; }
.viewer img { display: block; width: 100%; height: auto; }
.viewer.zoom img { width: 240%; }
.viewer .close { position: fixed; top: calc(var(--safe-t) + 10px); right: 12px; z-index: 2; background: rgba(0,0,0,.55); color: #fff; }
.viewer .hint { position: fixed; bottom: calc(var(--safe-b) + 14px); left: 0; right: 0; text-align: center; color: rgba(255,255,255,.7); font-size: 13px; pointer-events: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 14px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
