/* Wine Cellar: mobile-first, light/dark via prefers-color-scheme. */

:root {
  --bg: #f7f4f1;
  --surface: #ffffff;
  --text: #1f1a17;
  --muted: #6f655e;
  --border: #e4ddd6;
  --accent: #7b1e3a;
  --accent-text: #ffffff;
  --accent-soft: #f3e6ea;
  --danger: #b42318;
  --success: #2e7d4f;
  --radius: 14px;
  --tap: 44px;

  --wine-red: #8e1b33;
  --wine-white: #e9d27a;
  --wine-rose: #f19bb0;
  --wine-sparkling: #d9c58b;
  --wine-dessert: #c9822b;
  --wine-fortified: #5b2333;
  --wine-orange: #e08a3c;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161312;
    --surface: #211d1b;
    --text: #f1ebe6;
    --muted: #a99d94;
    --border: #36302c;
    --accent: #d16b88;
    --accent-text: #1a0d12;
    --accent-soft: #3a2229;
    --danger: #f97066;
    --success: #6ccf96;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }
h1, h2 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }

/* Layout */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1rem;
  padding-top: max(.75rem, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__icon { display: block; width: 32px; height: 32px; border-radius: 8px; }
.topbar__name { display: flex; flex-direction: column; line-height: 1.15; }
.topbar__totals { font-size: .78rem; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }

.topbar__brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  white-space: nowrap;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1rem calc(2rem + env(safe-area-inset-bottom));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.muted { color: var(--muted); }
.stack > * + * { margin-top: .75rem; }

/* Flash */

.flash {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin: 0 0 1rem;
}
.flash--notice { background: color-mix(in srgb, var(--success) 15%, var(--surface)); }
.flash--alert { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); }

/* Buttons */

/* No double-tap zoom on taps (e.g. quick −/+ presses); pinch zoom still works. */
button, .button, input[type="submit"], a { touch-action: manipulation; }

.button, input[type="submit"], button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 1.1rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button--small { min-height: 36px; padding: 0 .9rem; font-size: .9rem; }
.button--ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
.button--danger { background: transparent; color: var(--danger); border: 1px solid var(--border); }
.button--block, .form input[type="submit"] { width: 100%; }
button:disabled { opacity: .35; cursor: default; }

/* Wine list */

.wine-list { list-style: none; margin: 0; padding: 0; }

.wine-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .5rem;
}
.wine-row__main { flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.wine-row__title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wine-row__meta { color: var(--muted); font-size: .85rem; }

.dot {
  display: inline-block;
  width: .65rem;
  height: .65rem;
  border-radius: 50%;
  margin-right: .3rem;
  background: var(--border);
  vertical-align: baseline;
}
.dot--red { background: var(--wine-red); }
.dot--white { background: var(--wine-white); }
.dot--rosé { background: var(--wine-rose); }
.dot--sparkling { background: var(--wine-sparkling); }
.dot--dessert { background: var(--wine-dessert); }
.dot--fortified { background: var(--wine-fortified); }
.dot--orange { background: var(--wine-orange); }

.empty { text-align: center; padding: 2.5rem 1rem; }

/* List controls: search, sort, type chips, drink soon */

.list-controls { display: flex; gap: .5rem; margin-bottom: .75rem; }
.list-controls input[type="search"] { flex: 1; min-width: 0; }
.list-controls select { width: auto; flex-shrink: 0; }

.chips {
  display: flex;
  gap: .4rem;
  overflow-x: auto;
  margin: 0 -1rem 1rem;
  padding: 0 1rem;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  flex-shrink: 0;
  min-height: 36px;
  padding: 0 .85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: .9rem;
  text-decoration: none;
  white-space: nowrap;
}
.chip span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip .dot { margin-right: .1rem; }
.chip--active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip--active span:last-child { color: inherit; opacity: .8; }

.drink-by {
  display: inline-block;
  margin-left: .35rem;
  padding: 0 .4rem;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .75rem;
  font-weight: 600;
}
.drink-by--late { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); color: var(--danger); }
.wine-row--finished { opacity: .55; }

/* Bottle counter */

.counter { display: inline-flex; align-items: center; gap: .25rem; flex-shrink: 0; }
.counter form { margin: 0; }
.counter button {
  width: var(--tap);
  padding: 0;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.3rem;
  line-height: 1;
}
.counter__value { min-width: 2ch; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Wine detail */

.wine-header__producer { color: var(--muted); margin: 0; }
.wine-header__line { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.wine-header__links { margin-bottom: 0; }
.facts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .75rem 1rem;
  margin: 1rem 0 0;
}
.facts dt { color: var(--muted); font-size: .8rem; }
.facts dd { margin: 0; font-weight: 500; }

.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: flex;
  gap: .75rem;
  align-items: flex-start;
  padding: .65rem 0;
  border-top: 1px solid var(--border);
}
.entry:first-child { border-top: 0; }
.entry__main { flex: 1; min-width: 0; }
.entry__big { font-weight: 700; font-variant-numeric: tabular-nums; }
.entry form { margin: 0; }
.entry button { min-height: 32px; padding: 0 .7rem; font-size: .8rem; background: transparent; color: var(--muted); border: 1px solid var(--border); }

details > summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  padding: .5rem 0;
  list-style: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "+ "; }
details[open] > summary::before { content: "− "; }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.actions form { margin: 0; }

/* Label scanning */

.topbar__actions { display: flex; gap: .5rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.scan { text-align: center; }
.scan__button { min-height: 64px; font-size: 1.15rem; margin: .5rem 0; }
.scan__button.is-busy { opacity: .6; pointer-events: none; }
.scan__alt { margin-bottom: 0; }
/* Natural aspect ratio; tall (portrait) photos are capped so they don't fill the screen. */
.label-photo {
  display: block;
  max-width: 100%;
  height: auto;
  max-height: 70vh;
  margin: 0 auto 1rem;
  border-radius: calc(var(--radius) - 4px);
}

/* Research */

.section-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .5rem; }
.section-header h2 { margin: 0; }
.section-header form { margin: 0; }
.section-actions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.verdict {
  margin: 0 0 1rem;
  padding: .75rem 1rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  background: var(--accent-soft);
  font-weight: 500;
}
.report-section { margin-bottom: 1rem; }
.report-section h3 {
  margin: 0 0 .35rem;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.report-section ul { margin: 0; padding-left: 1.1rem; }
.report-section li { margin-bottom: .3rem; }
.report-section li::marker { color: var(--accent); }
.sources { margin: 0; padding-left: 1.2rem; font-size: .9rem; }
.sources li { margin-bottom: .35rem; overflow-wrap: anywhere; }
.research-meta { font-size: .8rem; margin-bottom: 0; }
.research-status { display: flex; gap: .75rem; align-items: flex-start; margin: 0; }
.tag {
  display: inline-block;
  padding: 0 .4rem;
  margin-left: .25rem;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .7rem;
  font-weight: 600;
  vertical-align: middle;
}
.valuation-note summary { font-size: .85rem; padding: .25rem 0; }
.valuation-note p { font-size: .85rem; margin: .25rem 0 0; }
.spinner {
  flex-shrink: 0;
  width: 1.1rem;
  height: 1.1rem;
  margin-top: .15rem;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Passkeys */

.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 0 1rem calc(1.5rem + env(safe-area-inset-bottom)); }
.inline-form { display: inline; }
.link-button { all: unset; color: var(--accent); text-decoration: underline; cursor: pointer; }
.passkey-page { text-align: center; }
.passkey-page .button { margin-top: .5rem; }
.passkey-error { color: var(--danger); margin: .75rem 0 0; }

/* Bottles stepper on the wine form */

.stepper { display: flex; align-items: center; gap: .35rem; }
.stepper button {
  flex-shrink: 0;
  width: var(--tap);
  padding: 0;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.3rem;
  line-height: 1;
}
.stepper input { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 0; }

/* Forms */

.form .field { margin-bottom: .9rem; }
.form label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

input[type="text"], input[type="search"], input[type="number"], input[type="url"], input[type="date"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
}
textarea { min-height: 5rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.errors { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; }
.errors ul { margin: .25rem 0 0; padding-left: 1.2rem; }

@media (min-width: 640px) {
  .facts { grid-template-columns: repeat(3, 1fr); }
}

/* Desktop wine table (hidden on phones, which get the card list) */

.wine-table {
  display: none;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: .95rem;
}
.wine-table th, .wine-table td { padding: .55rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.wine-table tbody tr:last-child td { border-bottom: 0; }
.wine-table th { font-size: .75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.wine-table th a { color: inherit; text-decoration: none; }
.wine-table th.is-sorted a { color: var(--accent); }
.wine-table th.is-sorted a::after { content: " ↓"; }
.wine-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wine-table tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }
.wine-table tr.is-finished { opacity: .5; }
.wine-table .is-late { color: var(--danger); font-weight: 600; }
.wine-table__wine a { display: block; color: inherit; text-decoration: none; }
.wine-table__producer { display: block; color: var(--muted); font-size: .8rem; }
.wine-table__name { font-weight: 600; }
.wine-table .counter { justify-content: flex-end; }
.wine-table .counter button { width: 30px; min-height: 30px; font-size: 1rem; }

/* Desktop layout */

@media (min-width: 1024px) {
  .topbar { padding-inline: max(2rem, calc((100% - 1200px) / 2 + 2rem)); }
  .page { max-width: 1200px; padding: 1.5rem 2rem 3rem; }
  .page--narrow { max-width: 720px; }

  #wines { display: none; }
  .wine-table { display: table; }
  .list-controls { max-width: 720px; }

  .wine-layout { display: grid; grid-template-columns: minmax(340px, 420px) 1fr; gap: 1.5rem; align-items: start; }
  .wine-layout__main { position: sticky; top: 5.5rem; }
  .wine-layout__main .label-photo { max-height: 45vh; }
  .wine-layout__main .facts { grid-template-columns: repeat(2, 1fr); }
}
