:root {
  --bg: #1a0f12;
  --panel: #241419;
  --panel-2: #2d1a20;
  --ink: #f3e7e1;
  --muted: #a89089;
  --accent: #b3434a;
  --accent-2: #d97a73;
  --border: #3a2128;
  --good: #6cae6c;
  --bad: #d97a73;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.45;
}
a { color: var(--accent-2); }
a:hover { color: var(--ink); }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0.6em 0 0.4em; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.error { background: #4a1d1d; color: #ffcfcf; padding: 0.6em 0.8em; border-radius: 6px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); font-size: 0.8em; }

.nav {
  display: flex; align-items: center; gap: 1em; padding: 0.7em 1.2em;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.nav a { color: var(--ink); text-decoration: none; padding: 0.3em 0.5em; border-radius: 4px; }
.nav a:hover { background: var(--panel-2); }
.nav .brand { font-weight: 700; color: var(--accent-2); }
.nav-spacer { flex: 1; }

.container { max-width: 1200px; margin: 0 auto; padding: 1.4em 1.2em 4em; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 1em 1.2em; margin: 0.8em 0; }
.narrow { max-width: 420px; margin: 3em auto; }

form label { display: block; margin: 0.6em 0; font-size: 0.9em; color: var(--muted); }
form label input, form label select, form label textarea {
  display: block; width: 100%; margin-top: 0.25em; padding: 0.5em 0.6em;
  background: var(--bg); color: var(--ink); border: 1px solid var(--border); border-radius: 5px; font: inherit;
}
form input[type=file] { padding: 0.3em 0; }
button, .primary { background: var(--accent); color: white; border: 0; padding: 0.55em 1.1em; border-radius: 5px; font: inherit; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .primary:hover { background: var(--accent-2); color: var(--bg); }
button.link { background: none; color: var(--accent-2); padding: 0; }
button.danger { background: #6b2a2a; }
button.danger:hover { background: var(--bad); color: var(--bg); }
.inline { display: inline; }

.filters { display: flex; flex-wrap: wrap; gap: 0.5em; align-items: center; margin: 0.8em 0 1.2em; }
.filters input, .filters select { padding: 0.45em 0.6em; background: var(--panel); color: var(--ink); border: 1px solid var(--border); border-radius: 5px; font: inherit; }
.filters input[type=search] { min-width: 240px; flex: 1; }
.inline-check { display: flex; align-items: center; gap: 0.4em; color: var(--muted); font-size: 0.9em; }

table.bottles { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
table.bottles th, table.bottles td { padding: 0.55em 0.7em; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.bottles thead th { background: var(--panel-2); font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
table.bottles tr:last-child td { border-bottom: 0; }
table.bottles tr.drunk td { opacity: 0.55; }
.thumb { width: 36px; height: 48px; object-fit: cover; border-radius: 3px; background: var(--panel-2); }

.bottle-detail { display: grid; grid-template-columns: 220px 1fr; gap: 2em; margin-top: 1em; }
.bottle-detail .bottle-img img { width: 100%; border-radius: 6px; background: var(--panel-2); }
.bottle-detail .placeholder { width: 100%; aspect-ratio: 3/4; display: flex; align-items: center; justify-content: center; background: var(--panel-2); border-radius: 6px; color: var(--muted); font-size: 0.85em; }
dl.kv { display: grid; grid-template-columns: 130px 1fr; row-gap: 0.3em; column-gap: 1em; margin: 0.8em 0; }
dl.kv dt { color: var(--muted); }
.notes { white-space: pre-wrap; background: var(--panel); padding: 0.8em 1em; border-radius: 6px; border: 1px solid var(--border); }
.actions { display: flex; gap: 0.6em; align-items: center; margin-top: 1em; }

.bottle-form fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 0.5em 1em 1em; margin: 1em 0; background: var(--panel); }
.bottle-form legend { padding: 0 0.4em; color: var(--muted); }
.method-chooser { display: flex; flex-wrap: wrap; gap: 0.5em; margin: 0.8em 0; }
.method-btn { background: var(--panel-2); color: var(--ink); border: 1px solid var(--border); font-weight: 500; }
.method-btn:hover { background: var(--panel); color: var(--accent-2); }
.method-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.scan-video { width: 100%; max-width: 360px; margin-top: 0.6em; border-radius: 6px; background: #000; aspect-ratio: 4 / 3; object-fit: cover; }
.more-details > summary { cursor: pointer; color: var(--accent-2); padding: 0.55em 0; font-size: 0.95em; list-style-position: inside; }
.more-details > summary:hover { color: var(--ink); }
.more-details[open] > summary { color: var(--muted); }
.row { display: flex; gap: 0.5em; align-items: center; flex-wrap: wrap; }
.row input { padding: 0.45em 0.6em; background: var(--bg); color: var(--ink); border: 1px solid var(--border); border-radius: 5px; font: inherit; }
.ml { margin-left: 1em; }

.summary { display: flex; gap: 1.5em; margin: 1em 0; }
.summary div { background: var(--panel); border: 1px solid var(--border); padding: 0.6em 1em; border-radius: 6px; }
.summary strong { font-size: 1.4em; color: var(--accent-2); display: block; }
.compact { padding-left: 1.2em; }
.compact li { margin: 0.15em 0; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1em; margin: 1em 0; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 1em; }
.stat .num { font-size: 1.7em; font-weight: 600; color: var(--accent-2); text-align: left; }
.stat .label { color: var(--muted); font-size: 0.9em; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1em; }
.grid-2 section { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.8em 1em; }
ul.bars { list-style: none; padding: 0; margin: 0; }
ul.bars li { display: flex; justify-content: space-between; padding: 0.25em 0; border-bottom: 1px dotted var(--border); }
ul.bars li:last-child { border-bottom: 0; }

.cellar-header { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 0.5em 1.2em; margin: 0.6em 0 0.4em; }
.cellar-header h1 { margin: 0; }
.cellar-totals { display: flex; gap: 1.2em; flex-wrap: wrap; color: var(--muted); font-size: 0.95em; }
.cellar-totals strong { color: var(--accent-2); font-size: 1.1em; }

.match-grid { display: grid; grid-template-columns: 360px 1fr; gap: 1.2em; align-items: start; margin-top: 1em; }
.match-thumb { width: 80px; height: 100px; object-fit: contain; background: var(--panel-2); border-radius: 4px; }
.candidate { padding: 0.7em 0.9em; }
.candidate-row { display: flex; gap: 0.8em; align-items: flex-start; }
.candidate-row .grow { flex: 1; min-width: 0; }
.match-actions { display: flex; gap: 0.7em; align-items: center; flex-wrap: wrap; margin-top: 0.6em; }
.candidate-list { display: flex; flex-direction: column; gap: 0.5em; }
.candidate-pick { display: block; cursor: pointer; padding: 0.7em 0.9em; }
.candidate-pick input[type=radio] { margin-right: 0.5em; vertical-align: top; }
.candidate-pick:has(input[type=radio]:checked) { border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2); }
.candidate-pick.subtle { background: var(--panel-2); }

/* "Get label" image picker */
.label-choice-grid { display: flex; flex-wrap: wrap; gap: 0.6em; margin: 0.4em 0 0.6em; }
.label-choice { margin: 0; }
.label-choice button {
  display: flex; flex-direction: column; align-items: center; gap: 0.3em;
  width: 120px; padding: 0.4em; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
  color: var(--ink); font: inherit; text-align: center;
}
.label-choice button:hover { border-color: var(--accent-2); }
.label-choice img { width: 100%; height: 110px; object-fit: contain; }
.label-choice .small { width: 100%; line-height: 1.2; overflow-wrap: anywhere; }  /* show the full name (wrap, don't truncate) */

/* Searchable "copy from existing wine" list */
.copy-filter { width: 100%; box-sizing: border-box; padding: 0.45em 0.6em; background: var(--bg); color: var(--ink); border: 1px solid var(--border); border-radius: 5px; font: inherit; margin-bottom: 0.5em; }
.copy-list { list-style: none; margin: 0; padding: 0; max-height: 15rem; overflow-y: auto; border: 1px solid var(--border); border-radius: 5px; }
.copy-list li { border-bottom: 1px solid var(--border); }
.copy-list li:last-child { border-bottom: none; }
.copy-list a { display: block; padding: 0.5em 0.7em; color: var(--ink); text-decoration: none; }
.copy-list a:hover { background: var(--panel-2); }
label.block { display: block; margin: 0.2em 0; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
.lcbo-panel { background: var(--panel-2); }
.lcbo-section { padding-top: 1em; border-top: 1px solid var(--border); }

@media (max-width: 720px) {
  .match-grid { grid-template-columns: 1fr; }
  .container { padding: 0.8em 0.7em 4em; }
  .nav { gap: 0.4em; padding: 0.6em 0.8em; flex-wrap: wrap; font-size: 0.95em; }
  .nav-spacer { display: none; }

  .bottle-detail { grid-template-columns: 1fr; }
  .bottle-detail .bottle-img img { max-width: 220px; }
  dl.kv { grid-template-columns: 110px 1fr; }

  .filters { flex-direction: column; align-items: stretch; gap: 0.45em; }
  .filters input, .filters select, .filters input[type=search] { width: 100%; min-width: 0; padding: 0.7em 0.7em; font-size: 1em; }
  .mobile-only-hide { display: none; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat .num { font-size: 1.3em; }

  .bottle-form fieldset { padding: 0.4em 0.7em 0.7em; }

  /* Table → cards (shared by all .bottles lists: cellar, lcbo/vivino match,
     imports). The first cell sits in a 48px left column; details on the right. */
  table.bottles, table.bottles thead, table.bottles tbody, table.bottles tr, table.bottles td { display: block; width: 100%; }
  table.bottles { border: 0; background: transparent; }
  table.bottles thead { display: none; }
  table.bottles tr {
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    padding: 0.7em 0.9em; margin-bottom: 0.6em;
    display: grid; grid-template-columns: 48px 1fr; column-gap: 0.8em; row-gap: 0.2em;
  }
  table.bottles tr td { border: 0; padding: 0; }
  table.bottles td[data-label="Wine"] { font-size: 1.05em; font-weight: 600; }
  table.bottles td[data-label=""]:first-child { grid-row: 1 / span 4; }
  table.bottles td[data-label=""]:first-child .thumb { width: 48px; height: 64px; }
  table.bottles td[data-label=""]:last-child { grid-column: 1 / -1; text-align: right; }
  table.bottles td[data-label]:not([data-label=""]):not([data-label="Wine"])::before {
    content: attr(data-label) ": "; color: var(--muted); font-size: 0.85em; margin-right: 0.3em;
  }
  table.bottles td.num { text-align: left; }
  table.bottles td:empty { display: none; }

  /* Cellar list only: make the label image fill the left ~44% of the card, with
     the details flowing to its right and then below it (a float), removing the
     dead space a small thumbnail left beside a long grape list. Overrides the
     shared grid above; the other lists keep it. */
  table.bottles.cellar tr { display: block; overflow: hidden; }  /* float context, not grid */
  table.bottles.cellar tr td { padding: 0.08em 0; }
  table.bottles.cellar td[data-label=""]:first-child {
    float: left; width: 44%; margin: 0.1em 0.9em 0.3em 0;
  }
  table.bottles.cellar td[data-label=""]:first-child .thumb {
    width: 100%; height: auto; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 5px;
  }
  table.bottles.cellar td[data-label="Wine"] { font-size: 1.15em; }
  table.bottles.cellar td[data-label=""]:last-child { clear: both; text-align: right; padding-top: 0.4em; }
}

@media (max-width: 420px) {
  .stat-grid { grid-template-columns: 1fr; }
}
