:root {
  --bg: #1a0f14;
  --bg-alt: #241318;
  --surface: #2a171d;
  --surface-hover: #351c24;
  --border: #3d2129;
  --text: #f5e6e0;
  --text-dim: #a89089;
  --wine: #8b1e3f;
  --wine-light: #c23b5e;
  --gold: #d4a24c;
  --danger: #c94a4a;
  --success: #5a9c5a;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-tap-highlight-color: rgba(194, 59, 94, 0.2);
  overscroll-behavior-y: contain;
}
button { -webkit-tap-highlight-color: transparent; }

/* Line-SVG icon base — used everywhere for a consistent, sleek look.
   Sized via font-size on the parent (1em square), colored via currentColor. */
.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}
.icon-lg { width: 1.5em; height: 1.5em; }
.icon-xl { width: 2em; height: 2em; vertical-align: -0.2em; }

.app-header {
  background: linear-gradient(180deg, #2e1319 0%, #1a0f14 100%);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: 0.5px; }
.logo { font-size: 22px; }

.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  border-radius: var(--radius);
  font-weight: 500;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
}
.tab .tab-icon { display: none; font-size: 18px; line-height: 1; }
.tab .tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.tab:hover { background: var(--surface); color: var(--text); }
.tab.active { background: var(--wine); color: white; }
.tab:active { transform: scale(0.97); }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* Toolbar / filters */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar input[type="search"], .toolbar select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 16px; /* 16px prevents iOS Safari zoom-on-focus */
  min-height: 44px;
}
.toolbar input[type="search"] { flex: 1; min-width: 200px; }
.view-toggle { display: flex; gap: 4px; }
.view-toggle button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 16px;
  min-width: 44px;
  min-height: 44px;
}
.view-toggle button.active { background: var(--wine); color: white; border-color: var(--wine); }

.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  white-space: nowrap;
}
.filter-chip:hover { background: var(--surface-hover); }
.filter-chip.active {
  background: var(--wine);
  border-color: var(--wine);
  color: white;
  max-width: min(100%, 320px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.filter-chip .remove { color: rgba(255,255,255,0.7); font-weight: bold; flex-shrink: 0; }

/* Collection stats strip */
.collection-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(139, 30, 63, 0.10), transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.collection-stats .cstat { text-align: center; padding: 2px 4px; }
.collection-stats .cstat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--wine-light);
  line-height: 1.15;
}
.collection-stats .cstat-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.collection-stats .cstat-meta .cstat-label.filtered { color: var(--gold); }

/* Wine cards grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.list { display: flex; flex-direction: column; gap: 8px; }
.list .wine-card { display: grid; grid-template-columns: 80px 1fr auto; align-items: center; }
.list .card-photo { height: 80px; }

.wine-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
}
.wine-card:hover { transform: translateY(-2px); border-color: var(--wine-light); }
.card-photo {
  height: 180px;
  background: #1a0a10 center/cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  color: var(--text-dim);
}
.card-body { padding: 12px 14px; flex: 1; display: flex; flex-direction: column; }
.card-title { margin: 0 0 4px 0; font-size: 15px; }
.card-meta { margin: 0; color: var(--text-dim); font-size: 13px; }
.card-sub { margin: 4px 0 0 0; color: var(--text-dim); font-size: 12px; }
.card-footer {
  margin-top: auto;
  padding-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.rating { color: var(--gold); }
.qty { background: var(--wine); color: white; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.qty.zero { background: var(--border); color: var(--text-dim); }

.empty { text-align: center; color: var(--text-dim); padding: 60px 20px; }
.empty a { color: var(--wine-light); }

/* Scan hero (photo-first add flow) */
.scan-panel {
  max-width: 620px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 24px 28px;
  text-align: center;
}
.scan-hero { margin-bottom: 24px; }
.scan-emoji { font-size: 56px; line-height: 1; margin-bottom: 8px; }
.scan-title { margin: 0 0 6px 0; font-size: 24px; font-weight: 600; }
.scan-sub { margin: 0; color: var(--text-dim); font-size: 15px; }
.scan-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.scan-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 18px 20px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  min-height: 56px;
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
}
.scan-btn:hover { border-color: var(--wine-light); }
.scan-btn:active { transform: scale(0.985); }
.scan-btn .scan-icon { font-size: 22px; }
.scan-primary {
  background: var(--wine);
  border-color: var(--wine);
  color: white;
  font-weight: 600;
}
.scan-primary:hover { background: var(--wine-light); border-color: var(--wine-light); }
.scan-link {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 12px 16px;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
}
.scan-link:hover { color: var(--text); }

/* AI status strip (spinner + text). Scoped to :not([hidden]) so the hidden
   attribute properly hides it (otherwise display:flex beats [hidden]{display:none}). */
.ai-status:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--wine-light);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  color: var(--text);
  font-size: 14px;
}
.ai-status.error { border-left-color: var(--danger); color: var(--danger); }
.ai-status.success { border-left-color: var(--success); }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--wine-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Photo strip at top of the form */
.form-photo-strip {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.form-photo-strip #photo-preview { margin: 0; flex: 1; }
.form-photo-strip #photo-preview img {
  max-width: 140px; max-height: 180px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.form-photo-actions { display: flex; flex-direction: column; gap: 8px; }
.photo-btn-sm {
  font-size: 13px;
  padding: 8px 12px;
  min-height: 36px;
}

/* Quick fill fieldset — the fields the user actually has to touch */
fieldset.quick-fill {
  margin: 0 0 16px;
  padding: 14px 16px 16px;
  border: 1px solid var(--wine);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(139, 30, 63, 0.08), transparent);
}
fieldset.quick-fill legend {
  color: var(--wine-light);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.quick-fill {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 14px;
  align-items: end;
}
.quick-fill label { display: flex; flex-direction: column; font-size: 13px; color: var(--text-dim); gap: 4px; }
.quick-fill label small { font-weight: 400; opacity: 0.7; margin-left: 4px; }
.quick-fill input {
  background: var(--bg-alt);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  min-height: 44px;
}

/* Quantity stepper */
.qty-stepper {
  display: inline-grid;
  grid-template-columns: 44px minmax(56px, 80px) 44px;
  gap: 0;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  height: 44px;
}
.qty-stepper input {
  border: none !important;
  background: transparent !important;
  border-radius: 0 !important;
  text-align: center;
  font-weight: 600;
  font-size: 18px !important;
  min-height: 0 !important;
  padding: 0 !important;
  -moz-appearance: textfield;
}
.qty-stepper input::-webkit-outer-spin-button,
.qty-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty-stepper .qty-btn {
  background: var(--surface-hover);
  border: none;
  color: var(--text);
  font-size: 22px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  min-height: 44px;
}
.qty-stepper .qty-btn:hover { background: var(--wine); color: white; }
.qty-stepper .qty-btn:active { background: var(--wine-light); }

/* Collapsible details section */
details.details-section {
  margin: 0 0 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-alt);
  overflow: hidden;
}
details.details-section > summary {
  cursor: pointer;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  user-select: none;
}
details.details-section > summary::-webkit-details-marker { display: none; }
details.details-section > summary::before {
  content: "▸";
  color: var(--text-dim);
  transition: transform 0.15s;
  margin-right: 8px;
  font-size: 12px;
}
details.details-section[open] > summary::before { transform: rotate(90deg); }
details.details-section > summary .details-summary-text { flex: 1; }
details.details-section > summary .details-hint {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
  font-style: italic;
}
details.details-section[open] > summary {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
details.details-section > .form-grid,
details.details-section > fieldset { margin: 16px; }
details.details-section > .form-grid { padding: 0; }

/* Form */
.wine-form, .settings-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 900px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.form-grid label, .settings-form label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  color: var(--text-dim);
  gap: 4px;
}
.form-grid label.span-2 { grid-column: span 2; }
.form-grid input, .form-grid select, .settings-form input, .settings-form select, .wine-form textarea {
  background: var(--bg-alt);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 16px; /* 16px prevents iOS Safari zoom-on-focus */
  font-family: inherit;
  min-height: 44px;
}
.form-grid input:focus, .settings-form input:focus, .wine-form textarea:focus {
  outline: none;
  border-color: var(--wine-light);
}

fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin: 20px 0; }
legend { padding: 0 8px; color: var(--text-dim); font-size: 13px; }

.critic-row, .note-row {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.critic-row { grid-template-columns: 1fr 90px 90px 2fr auto; }
.note-row { grid-template-columns: 140px 1fr 100px auto; }
.critic-row input, .note-row input, .note-row textarea, .critic-row select, .note-row select {
  background: var(--bg-alt);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  min-height: 40px;
}
.row-remove {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 20px;
  padding: 4px 8px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 6px;
}
.row-remove:active { background: rgba(201, 74, 74, 0.15); }

.photo-inputs { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  flex-direction: row !important;
}
.photo-btn:hover { border-color: var(--wine-light); }

#photo-preview { margin-top: 14px; }
#photo-preview img { max-width: 260px; max-height: 260px; border-radius: 8px; border: 1px solid var(--border); }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

button.primary, button.secondary, button.danger, .ghost-btn {
  min-height: 44px;
}
button.primary {
  background: var(--wine);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 15px;
}
button.primary:hover { background: var(--wine-light); }
button.primary:active { transform: scale(0.98); }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
}
button.secondary:hover { border-color: var(--wine-light); }
button.secondary:active { transform: scale(0.98); }
button.ghost {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  min-height: 40px;
}
button.ghost:hover { color: var(--text); border-color: var(--text-dim); }
button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
}
button.danger:hover { background: var(--danger); color: white; }
button.danger:active { transform: scale(0.98); }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.ghost-btn:hover { border-color: var(--wine-light); }

/* Analysis */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--wine-light); }
.stat-label { font-size: 13px; color: var(--text-dim); margin-top: 4px; }

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.chart-card h3 { margin: 0 0 10px 0; font-size: 14px; color: var(--text-dim); font-weight: 500; }
.chart-card canvas { max-height: 240px; }

.drink-now {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.drink-now h3 { margin-top: 0; }
.drink-now-item {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.drink-now-item:last-child { border-bottom: none; }
.drink-now-item .urgency { font-size: 12px; color: var(--gold); }
.drink-now-item .urgency.past { color: var(--danger); }
.ai-section ul { margin: 4px 0; padding-left: 20px; }

/* Settings */
.settings-form label { max-width: 480px; margin-bottom: 16px; }
.settings-form small { color: var(--text-dim); font-size: 12px; margin-top: 4px; }
.settings-form small a { color: var(--wine-light); }
.settings-note {
  max-width: 640px;
  margin: 0 0 18px;
  padding: 12px 14px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--wine-light);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}
.settings-note strong { color: var(--wine-light); }
.data-ops {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 24px;
  max-width: 900px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.data-ops h3 { margin: 0 20px 0 0; width: 100%; }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--wine);
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 120;
  font-size: 14px;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }

/* Bottom sheet (used on mobile for the filter picker) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: sheet-fade 0.18s ease-out;
}
.sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: 70vh;
  overflow: auto;
  padding: 8px 8px calc(16px + env(safe-area-inset-bottom, 0px));
  animation: sheet-up 0.22s cubic-bezier(.2,.9,.3,1);
}
.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 8px auto 12px;
}
.sheet-title {
  font-size: 13px;
  color: var(--text-dim);
  padding: 0 12px 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.sheet-item {
  padding: 14px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text);
}
.sheet-item:active { background: var(--surface-hover); }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes sheet-fade { from { opacity: 0; } to { opacity: 1; } }

/* About this wine (AI deep-dive for saved wines) */
.about-section {
  margin: 0 0 20px;
  padding: 0;
}
.about-actions {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 12px;
}
#tell-more-btn {
  padding: 12px 18px;
  font-size: 15px;
  min-height: 48px;
}
.about-output:empty { display: none; }
.about-output {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  line-height: 1.55;
}
.about-output h4 {
  margin: 0 0 6px 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--wine-light);
  font-weight: 600;
}
.about-output .about-block { margin-bottom: 18px; }
.about-output .about-block:last-child { margin-bottom: 0; }
.about-output p { margin: 0 0 10px; color: var(--text); }
.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.profile-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.profile-cell .profile-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 4px;
}
.profile-cell .profile-value { font-size: 14px; color: var(--text); }
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip-row .chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
}
.drink-window-callout {
  background: var(--surface);
  border-left: 3px solid var(--gold);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
}
.review-list {
  display: grid;
  gap: 10px;
}
.review-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.review-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.review-source { font-weight: 600; font-size: 14px; color: var(--text); }
.review-reviewer { font-size: 12px; color: var(--text-dim); }
.review-score {
  background: var(--wine);
  color: white;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.review-quote {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
  border-left: 2px solid var(--border);
  padding-left: 10px;
}

/* Per-wine sommelier mini-chat (on the wine page) */
.wsomm-section {
  margin: 0 0 20px;
  padding: 18px 20px 16px;
  background: linear-gradient(180deg, rgba(139, 30, 63, 0.08), transparent);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.wsomm-title { margin: 0 0 4px; font-size: 16px; color: var(--text); }
.wsomm-sub { margin: 0 0 12px; color: var(--text-dim); font-size: 13px; }
.wsomm-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.wsomm-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 8px 0;
  max-height: 520px;
  overflow-y: auto;
}
.wsomm-messages:empty { display: none; }
.wsomm-composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-top: 6px;
}
.wsomm-input {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
}

/* Linkified wine names inside any sommelier chat */
.wine-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--gold);
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
  cursor: pointer;
  padding: 0 1px;
  border-radius: 3px;
  transition: background 0.12s;
}
.wine-link:hover { background: rgba(212, 162, 76, 0.18); }
.somm-msg.assistant .wine-link { color: var(--wine-light); font-weight: 500; }

/* Stock / consumption log */
.stock-section {
  margin: 0 0 20px;
  padding: 20px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.stock-title {
  margin: 0 0 4px;
  font-size: 17px;
  color: var(--text);
}
.stock-sub {
  margin: 0 0 14px;
  color: var(--text-dim);
  font-size: 13px;
}

.stock-history-count {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  margin-left: 6px;
}
.stock-history:empty { display: none; }
.stock-history { display: flex; flex-direction: column; gap: 6px; }
.stock-history-empty {
  color: var(--text-dim);
  font-size: 13px;
  padding: 12px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.stock-history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  font-size: 14px;
}
.stock-history-date { color: var(--text-dim); font-size: 13px; white-space: nowrap; }
.stock-history-count-pill {
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.stock-history-count-pill.out { background: var(--wine); }
.stock-history-count-pill.in  { background: var(--success); }
.stock-history-note { color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.stock-history-rating { color: var(--gold); font-size: 13px; white-space: nowrap; }
.stock-history-remove {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 16px;
  line-height: 1;
}
.stock-history-remove:hover { color: var(--danger); background: rgba(201, 74, 74, 0.1); }

/* Stock-adjust bottom sheet (triggered by −/+ on existing wines) */
.stock-adjust-sheet .stock-adjust-title {
  margin: 0 0 4px;
  padding: 0 12px;
  font-size: 18px;
  color: var(--text);
}
.stock-adjust-sheet .stock-adjust-lead {
  margin: 0 0 14px;
  padding: 0 12px;
  color: var(--text-dim);
  font-size: 13px;
}
.stock-adjust-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 12px 8px;
}
.stock-adjust-form .note-cell { grid-column: 1 / 3; }
.stock-adjust-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-dim); }
.stock-adjust-form label small { font-weight: 400; opacity: 0.7; margin-left: 4px; }
.stock-adjust-form input, .stock-adjust-form select {
  background: var(--bg-alt);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  min-height: 44px;
}
.stock-adjust-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
}
.stock-adjust-actions button { width: 100%; min-height: 46px; }

/* Sommelier chat */
/* Scope to :not([hidden]) so the hidden attribute properly hides the view.
   Without this scoping, display:flex beats the UA's default [hidden] rule. */
#view-sommelier:not([hidden]) {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 180px);
}
.somm-intro {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(139, 30, 63, 0.10), transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.somm-avatar {
  font-size: 32px;
  line-height: 1;
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  background: var(--surface);
  border-radius: 50%;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.somm-intro-text { flex: 1; min-width: 0; }
.somm-intro-text h2 { margin: 0 0 2px; font-size: 18px; color: var(--text); }
.somm-intro-text p { margin: 0; color: var(--text-dim); font-size: 13px; }
.somm-reset { flex-shrink: 0; font-size: 13px; }

.somm-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0 8px;
  min-height: 120px;
}
.somm-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  padding: 30px 20px;
  font-style: italic;
}
.somm-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.somm-msg.user {
  background: var(--wine);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.somm-msg.assistant {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.somm-msg.pending { opacity: 0.7; font-style: italic; }
.somm-msg strong { color: inherit; }
.somm-msg ul { margin: 6px 0; padding-left: 20px; }
.somm-msg li { margin: 2px 0; }
.somm-msg p { margin: 0 0 6px; }
.somm-msg p:last-child { margin-bottom: 0; }

.somm-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 10px;
}
.somm-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  min-height: 36px;
  white-space: nowrap;
}
.somm-chip:hover { border-color: var(--wine-light); }
.somm-chip:active { transform: scale(0.97); }

.somm-composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 0 4px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.somm-input {
  flex: 1;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 16px;
  font-family: inherit;
  resize: none;
  min-height: 44px;
  max-height: 140px;
  line-height: 1.4;
}
.somm-input:focus { outline: none; border-color: var(--wine-light); }
.somm-send {
  min-height: 44px;
  padding: 10px 18px;
  flex-shrink: 0;
}

/* ======================================================
   MOBILE (≤ 700px) — bottom nav, responsive form, etc.
   ====================================================== */
@media (max-width: 700px) {
  /* keep content away from the fixed bottom nav */
  body {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  .app-header {
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    gap: 8px;
  }
  .app-header .brand h1 { font-size: 18px; }

  /* Move tabs to a fixed bottom bar */
  .app-header .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    background: var(--bg-alt);
    border-top: 1px solid var(--border);
    padding: 6px 4px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 2px;
    z-index: 50;
    justify-content: space-around;
    backdrop-filter: blur(10px);
  }
  .tab {
    flex: 1;
    flex-direction: column;
    gap: 2px;
    padding: 6px 4px;
    min-height: 52px;
    font-size: 11px;
    border-radius: 8px;
  }
  .tab .tab-icon { display: block; font-size: 20px; }
  .tab.active {
    background: transparent;
    color: var(--wine-light);
  }
  .tab.active .tab-icon { transform: translateY(-1px); }

  main { padding: 14px; padding-bottom: 14px; }

  /* Toolbar becomes a single horizontal scrollable line on tiny screens */
  .toolbar { gap: 8px; }
  .toolbar input[type="search"] { width: 100%; min-width: 0; flex-basis: 100%; }
  .toolbar select { flex: 1; min-width: 0; }
  .view-toggle { margin-left: auto; }

  .filter-bar {
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    margin: 0 -14px 12px;
    padding: 2px 14px 8px;
    scrollbar-width: none;
  }
  .filter-bar::-webkit-scrollbar { display: none; }

  /* Wine cards — tighter on mobile */
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .card-photo { height: 140px; font-size: 40px; }
  .card-body { padding: 10px 12px; }
  .card-title { font-size: 14px; }

  /* Form — stack cleanly */
  .wine-form, .settings-form { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .form-grid label.span-2 { grid-column: auto; }

  .critic-row, .note-row {
    grid-template-columns: 1fr 40px;
    grid-auto-rows: auto;
    row-gap: 6px;
    padding: 10px;
    background: var(--bg-alt);
    border-radius: 8px;
  }
  .critic-row input[name="source"]  { grid-column: 1 / 2; }
  .critic-row .row-remove            { grid-column: 2 / 3; grid-row: 1 / 2; justify-self: end; align-self: start; }
  .critic-row input[name="score"]    { grid-column: 1 / 2; }
  .critic-row input[name="outOf"]    { grid-column: 2 / 3; }
  .critic-row input[name="summary"]  { grid-column: 1 / 3; }

  .note-row input[name="date"]       { grid-column: 1 / 2; }
  .note-row .row-remove              { grid-column: 2 / 3; grid-row: 1 / 2; justify-self: end; align-self: start; }
  .note-row input[name="note"]       { grid-column: 1 / 3; }
  .note-row select[name="rating"]    { grid-column: 1 / 3; }

  /* Form actions flow naturally at the end of the form (no sticky/floating bar).
     Primary sits on its own row for easy thumb access; Cancel/Delete share the next row. */
  .form-actions {
    margin-top: 20px;
    gap: 8px;
  }
  .form-actions button.primary { flex: 1 1 100%; order: -1; }
  .form-actions button.secondary { flex: 1 1 calc(50% - 4px); }
  .form-actions button.ghost, .form-actions button.danger { flex: 1 1 calc(50% - 4px); }

  /* Photo buttons fill width on mobile for easier tapping */
  .photo-inputs { flex-direction: column; gap: 8px; }
  .photo-btn { justify-content: center; padding: 12px 14px; font-size: 14px; }
  #photo-preview img { max-width: 100%; max-height: 320px; }

  /* Stats + charts stack to single column on narrow screens */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px 10px; }
  .stat-value { font-size: 22px; }
  .charts-grid { grid-template-columns: 1fr; gap: 12px; }
  .chart-card { padding: 12px; }
  .chart-card canvas { max-height: 220px; }

  /* Settings data-ops — buttons stack */
  .data-ops { padding: 14px; gap: 8px; }
  .data-ops h3 { margin: 0 0 4px 0; }
  .data-ops > button, .data-ops > label.ghost-btn { width: 100%; justify-content: center; }

  /* Tap feedback for cards */
  .wine-card:active { transform: scale(0.98); border-color: var(--wine-light); }
  .wine-card:hover { transform: none; }

  /* Toast sits above the bottom nav */
  .toast { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }

  /* Scan hero sized for phones */
  .scan-panel { padding: 32px 18px 20px; border-radius: 12px; }
  .scan-emoji { font-size: 48px; }
  .scan-title { font-size: 22px; }
  .scan-sub { font-size: 14px; }
  .scan-btn { padding: 16px 18px; min-height: 60px; font-size: 16px; }
  .scan-primary { box-shadow: 0 2px 12px rgba(139, 30, 63, 0.35); }

  /* Photo strip stacks image above the retake/change buttons on mobile */
  .form-photo-strip { flex-direction: column; align-items: stretch; }
  .form-photo-strip #photo-preview { text-align: center; }
  .form-photo-strip #photo-preview img { max-width: 200px; max-height: 240px; }
  .form-photo-actions { flex-direction: row; justify-content: center; }
  .photo-btn-sm { flex: 1; max-width: 160px; justify-content: center; }

  /* Quick fill stacks on mobile; the qty stepper gets a full row */
  .quick-fill { grid-template-columns: 1fr; gap: 12px; }
  .qty-cell { order: -1; }
  .qty-stepper { width: 100%; grid-template-columns: 56px 1fr 56px; height: 52px; }
  .qty-stepper .qty-btn { min-height: 52px; font-size: 24px; }

  /* Details summary sized for tap */
  details.details-section > summary { min-height: 56px; padding: 14px 14px; }
  details.details-section > .form-grid,
  details.details-section > fieldset { margin: 12px; }

  /* Collection stats — tighten numbers on mobile so nothing wraps */
  .collection-stats { padding: 10px 12px; gap: 6px; }
  .collection-stats .cstat-value { font-size: 18px; }
  .collection-stats .cstat-label { font-size: 10px; letter-spacing: 0.3px; }

  /* Sommelier — composer stays above the bottom nav; messages scroll */
  #view-sommelier { min-height: calc(100vh - 120px); }
  .somm-intro { padding: 12px 14px; gap: 10px; }
  .somm-avatar { width: 42px; height: 42px; font-size: 26px; }
  .somm-intro-text h2 { font-size: 16px; }
  .somm-intro-text p { font-size: 12px; }

  .somm-suggestions {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    margin: 0 -14px;
    padding: 6px 14px 10px;
    scrollbar-width: none;
  }
  .somm-suggestions::-webkit-scrollbar { display: none; }

  .somm-composer { padding: 10px 0 4px; border-top: 1px solid var(--border); margin-top: 6px; }
  .somm-send { padding: 10px 14px; }
  .somm-msg { max-width: 88%; font-size: 15px; }

  /* Per-wine chat: roomier on mobile */
  .wsomm-section { padding: 14px 14px 12px; }
  .wsomm-messages { max-height: 420px; }

  /* Stock history items stack the note on its own line on mobile */
  .stock-section { padding: 16px; }
  .stock-history-item {
    grid-template-columns: auto auto 1fr auto;
    row-gap: 4px;
  }
  .stock-history-note { grid-column: 1 / 5; grid-row: 2; font-size: 13px; color: var(--text-dim); }
  .stock-history-remove { grid-row: 1; }
}

/* Very narrow (old small phones) */
@media (max-width: 360px) {
  .tab .tab-label { font-size: 10px; }
  .grid { grid-template-columns: 1fr; }
}
