/* Pour Decisions — design system. Cool winter palette, mobile-first (~390px). */

:root {
  /* Winter tones: frosted grounds, deep slate ink, glacial blue accent. */
  --frost: #eef3f7;
  --paper: #ffffff;
  --paper-sunk: #e2eaf1;
  --ink: #16222e;
  --ink-soft: #46586a;
  --ink-faint: #56687a;
  --accent: #37799f;
  --accent-deep: #1d5878;
  --accent-tint: #dceaf3;
  --pine: #2c5a4a;
  --silver: #8fa3b3;
  --positive: #2f6b52;
  --positive-tint: #dfeee7;
  --negative: #a8443c;
  --negative-tint: #f6e2df;
  --border: #cfdbe5;
  --border-soft: #e3ebf2;
  --shadow: 0 1px 2px rgba(22, 34, 46, 0.06), 0 8px 24px -12px rgba(22, 34, 46, 0.20);
  --shadow-sm: 0 1px 3px rgba(22, 34, 46, 0.10);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--frost);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
p { margin: 0 0 8px; }
a { color: var(--accent-deep); }
button { font-family: inherit; }
img { max-width: 100%; display: block; }
::selection { background: var(--accent-tint); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- app shell ---------- */

#app { min-height: 100%; display: flex; flex-direction: column; position: relative; }

.view { display: none; flex: 1; padding: 16px 16px calc(var(--nav-h) + var(--safe-bottom) + 24px); max-width: 720px; margin: 0 auto; width: 100%; }
.view.active { display: block; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(238, 243, 247, 0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-soft);
  padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar h1 { font-size: 20px; margin: 0; }
.topbar .eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); margin: 0; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--paper); display: flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: pointer; color: var(--ink);
}
.icon-btn:active { background: var(--paper-sunk); }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--paper); border-top: 1px solid var(--border);
  display: flex; align-items: stretch; justify-content: space-around;
  box-shadow: 0 -4px 16px rgba(22,34,46,0.06);
}
.nav-btn {
  background: none; border: none; flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; color: var(--ink-faint); font-size: 11px; cursor: pointer; padding: 6px 2px;
}
.nav-btn .nav-icon { font-size: 21px; line-height: 1; }
.nav-btn.active { color: var(--accent-deep); }
.nav-btn.scan-btn {
  position: relative; top: -14px; flex: 0 0 60px;
}
.nav-btn.scan-btn .nav-icon-circle {
  width: 52px; height: 52px; border-radius: 50%; background: linear-gradient(155deg, var(--accent), var(--accent-deep));
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 24px;
  box-shadow: 0 6px 16px -4px rgba(29, 88, 120, 0.45); margin-bottom: 2px;
}
.nav-btn.scan-btn.active .nav-icon-circle { box-shadow: 0 6px 20px -2px rgba(29, 88, 120, 0.6); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 999px; border: 1px solid transparent; padding: 12px 20px; font-size: 15px; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: transform 0.06s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: linear-gradient(155deg, var(--accent), var(--accent-deep)); color: #fff; }
.btn-secondary { background: var(--paper); color: var(--ink); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--accent-deep); padding: 10px 12px; }
.btn-danger { background: var(--negative-tint); color: var(--negative); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.quick-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 20px; }
.quick-action {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px;
  background: var(--paper); border: 1px solid var(--border-soft); border-radius: var(--radius-md); cursor: pointer;
  font-size: 12px; color: var(--ink); text-align: center;
}
.quick-action .qa-icon { font-size: 22px; }

/* ---------- cards ---------- */

.card { background: var(--paper); border-radius: var(--radius-lg); border: 1px solid var(--border-soft); box-shadow: var(--shadow-sm); padding: 16px; margin-bottom: 14px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 10px; }
.section-title h2 { font-size: 17px; }
.section-title .link { font-size: 13px; color: var(--accent-deep); cursor: pointer; }

.bottle-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.bottle-card {
  background: var(--paper); border-radius: var(--radius-md); border: 1px solid var(--border-soft);
  overflow: hidden; cursor: pointer; box-shadow: var(--shadow-sm); display: flex; flex-direction: column;
}
.bottle-card .thumb {
  aspect-ratio: 3/4; background: var(--paper-sunk); display: flex; align-items: center; justify-content: center;
  font-size: 34px; position: relative; overflow: hidden;
}
.bottle-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.bottle-card .match-pill {
  position: absolute; top: 6px; right: 6px; background: rgba(255,255,255,0.92); border-radius: 999px;
  font-size: 11px; font-weight: 700; padding: 3px 7px; color: var(--accent-deep);
}
.bottle-card .body { padding: 10px 10px 12px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.bottle-card .name { font-size: 13.5px; font-weight: 700; line-height: 1.25; }
.bottle-card .sub { font-size: 11.5px; color: var(--ink-soft); }
.bottle-card .meta-row { display: flex; align-items: center; justify-content: space-between; margin-top: auto; font-size: 12px; }

.bottle-row { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border-soft); cursor: pointer; }
.bottle-row:last-child { border-bottom: none; }
.bottle-row .thumb-sm { width: 46px; height: 60px; border-radius: 8px; background: var(--paper-sunk); flex-shrink: 0; overflow: hidden; display:flex; align-items:center; justify-content:center; font-size:20px; }
.bottle-row .thumb-sm img { width: 100%; height: 100%; object-fit: cover; }
.bottle-row .info { flex: 1; min-width: 0; }
.bottle-row .info .name { font-weight: 700; font-size: 14px; }
.bottle-row .info .sub { font-size: 12px; color: var(--ink-soft); }

/* ---------- badges / pills ---------- */

.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 3px 10px; font-size: 11.5px; font-weight: 600; }
.pill-favorite { background: var(--accent-tint); color: var(--accent-deep); }
.pill-dislike { background: var(--negative-tint); color: var(--negative); }
.pill-neutral { background: var(--paper-sunk); color: var(--ink-soft); }
.pill-want { background: #e6ecf2; color: #1d5878; }
.pill-own { background: var(--positive-tint); color: var(--positive); }
.status-pills { display: flex; flex-wrap: wrap; gap: 6px; }

.tag-chip {
  display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 12px; font-size: 12.5px;
  border: 1px solid var(--border); background: var(--paper); cursor: pointer; user-select: none;
}
.tag-chip.selected { background: var(--accent); color: #fff; border-color: var(--accent-deep); }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-group-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); margin: 12px 0 6px; }

.match-badge {
  display: inline-flex; align-items: center; justify-content: center; flex-direction: column;
  width: 76px; height: 76px; border-radius: 50%; background: conic-gradient(var(--accent) calc(var(--pct, 0) * 1%), var(--paper-sunk) 0);
  color: var(--ink); position: relative;
}
.match-badge::after { content: ""; position: absolute; inset: 6px; background: var(--paper); border-radius: 50%; }
.match-badge .pct { position: relative; font-weight: 800; font-size: 19px; z-index: 1; }
.match-badge .lbl { position: relative; font-size: 9px; z-index: 1; color: var(--ink-soft); }
.match-badge.small { width: 40px; height: 40px; }
.match-badge.small .pct { font-size: 12px; }
.match-badge.small .lbl { display: none; }

.decision-banner { border-radius: var(--radius-md); padding: 14px 16px; font-weight: 700; font-size: 15px; display: flex; align-items: center; justify-content: space-between; }
.decision-banner.buy { background: var(--positive-tint); color: var(--positive); }
.decision-banner.try { background: var(--accent-tint); color: var(--accent-deep); }
.decision-banner.skip { background: var(--negative-tint); color: var(--negative); }

.rating-display { font-family: var(--font-display); font-weight: 700; font-size: 26px; color: var(--accent-deep); }
.stars { color: var(--silver); letter-spacing: 1px; }

/* ---------- forms ---------- */

label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; margin-top: 14px; }
label:first-child { margin-top: 0; }
input[type="text"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 12px; font-size: 15px;
  background: var(--paper); color: var(--ink); font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-hint { font-size: 11.5px; color: var(--ink-faint); margin-top: 4px; }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

.rating-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.rating-picker button {
  border: 1px solid var(--border); background: var(--paper); border-radius: 8px; padding: 8px 0; width: 40px;
  font-size: 13px; font-weight: 700; cursor: pointer;
}
.rating-picker button.selected { background: var(--accent); color: #fff; border-color: var(--accent-deep); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.toggle { position: relative; width: 44px; height: 26px; border-radius: 999px; background: var(--border); border: none; cursor: pointer; }
.toggle.on { background: var(--accent); }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.toggle.on::after { transform: translateX(18px); }

/* ---------- sheet / modal ---------- */

.sheet-backdrop { position: fixed; inset: 0; background: rgba(22,34,46,0.45); z-index: 40; display: none; }
.sheet-backdrop.open { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92vh; overflow-y: auto;
  background: var(--frost); border-radius: 22px 22px 0 0; padding: 10px 18px calc(28px + var(--safe-bottom));
  transform: translateY(100%); transition: transform 0.22s ease; box-shadow: 0 -8px 30px rgba(0,0,0,0.2);
}
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; border-radius: 999px; background: var(--border); margin: 8px auto 14px; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-header h2 { font-size: 18px; }

@media (min-width: 640px) {
  .sheet { left: 50%; right: auto; bottom: 24px; width: 480px; margin-left: -240px; border-radius: 22px; max-height: 85vh; }
}

/* ---------- misc ---------- */

.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-soft); }
.empty-state .ee-icon { font-size: 36px; margin-bottom: 8px; }

.toast { position: fixed; bottom: calc(var(--nav-h) + var(--safe-bottom) + 14px); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 13.5px; z-index: 60; box-shadow: var(--shadow); }

.filter-bar { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 4px; scrollbar-width: none; }
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip { flex-shrink: 0; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--paper); font-size: 13px; cursor: pointer; white-space: nowrap; }
.filter-chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.search-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.search-bar input { flex: 1; }

.spec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; font-size: 13.5px; }
.spec-grid dt { color: var(--ink-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.spec-grid dd { margin: 2px 0 0; font-weight: 600; }

.timeline-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border-soft); }
.timeline-item .td-rating { font-weight: 800; color: var(--accent-deep); font-size: 16px; width: 40px; flex-shrink: 0; }
.timeline-item .td-body { flex: 1; }
.timeline-item .td-meta { font-size: 12px; color: var(--ink-soft); }

.insight-card { background: linear-gradient(160deg, var(--accent-tint), var(--paper)); border: 1px solid var(--border-soft); }

.profile-chip {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--paper); color: var(--ink);
  padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.profile-chip:active { background: var(--paper-sunk); }

.wine-dim { padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.wine-dim:last-child { border-bottom: none; }
.wine-dim-unknown { opacity: 0.72; }
.wine-dim-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13.5px; font-weight: 600; gap: 10px; }
.wine-dim-conf { color: var(--ink-soft); font-weight: 500; font-size: 12px; letter-spacing: 0.5px; }
.wine-scale {
  position: relative; height: 8px; border-radius: 999px; margin: 7px 0 3px;
  background: linear-gradient(90deg, var(--paper-sunk), var(--accent-tint));
}
.wine-scale-marker {
  position: absolute; top: 50%; width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent-deep); border: 2px solid #fff; transform: translate(-50%, -50%);
  box-shadow: 0 1px 3px rgba(22,34,46,0.3);
}
.wine-scale-ends { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--ink-faint); }

.ext-rating { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.ext-rating:last-of-type { border-bottom: none; }
.ext-score { font-weight: 800; color: var(--accent-deep); margin-left: 6px; }

.wine-input { padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.wine-input:last-child { border-bottom: none; }
.wine-range { width: 100%; accent-color: var(--accent-deep); margin: 6px 0 2px; }
.wine-range.unset { opacity: 0.45; }
.wine-range:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

.hero-photo {
  position: relative; height: 240px; border-radius: var(--radius-lg); overflow: hidden;
  background: var(--paper-sunk); margin-bottom: 12px; display: flex; align-items: center; justify-content: center;
}
.hero-photo img { width: 100%; height: 100%; object-fit: cover; }
.hero-photo-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.hero-photo-btn {
  position: absolute; right: 10px; bottom: 10px; border: 1px solid var(--border);
  background: rgba(255,255,255,0.94); color: var(--ink); border-radius: 999px;
  padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.hero-photo-btn:active { background: var(--paper-sunk); }

#mapCanvas { width: 100%; height: 56vh; border-radius: var(--radius-lg); overflow: hidden; background: var(--paper-sunk); }
.map-legend { display: flex; gap: 14px; font-size: 12px; margin: 8px 0; color: var(--ink-soft); }
.map-legend span { display: inline-flex; align-items: center; gap: 5px; }
.map-toggle-row { display: flex; gap: 8px; margin-bottom: 10px; }
.maplibregl-popup-content { border-radius: 14px !important; font-family: var(--font-ui) !important; padding: 14px !important; }

.compare-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.compare-table th, .compare-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.compare-table th { font-weight: 600; color: var(--ink-soft); width: 110px; }
.compare-scroll { overflow-x: auto; }

.scan-frame { position: relative; border-radius: var(--radius-lg); overflow: hidden; background: #000; aspect-ratio: 3/4; }
.scan-frame video { width: 100%; height: 100%; object-fit: cover; }
.scan-torch {
  position: absolute; right: 10px; bottom: 10px; z-index: 2;
  border: 1px solid rgba(255,255,255,0.5); background: rgba(22,34,46,0.55);
  color: #fff; border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.scan-torch.on { background: var(--accent-deep); border-color: var(--accent); }

.scan-reticle { position: absolute; inset: 18% 12%; border: 2px solid rgba(255,255,255,0.85); border-radius: 16px; box-shadow: 0 0 0 999px rgba(0,0,0,0.28); }

.splash { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 32px; background: linear-gradient(180deg, var(--frost), var(--accent-tint)); }
.splash h1 { font-size: 34px; }
.splash p { color: var(--ink-soft); max-width: 320px; }

.offline-banner { background: var(--negative-tint); color: var(--negative); font-size: 12.5px; padding: 8px 16px; text-align: center; }

@media (min-width: 720px) {
  .bottle-grid { grid-template-columns: repeat(3, 1fr); }
  .quick-actions { grid-template-columns: repeat(4, 1fr); max-width: 480px; }
}
