:root {
  --bg: #fbfaf8; --fg: #1a1a1a; --muted: #666; --accent: #8a5a2b;
  --border: #e6e1d8; --card: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110d; --fg: #ececec; --muted: #a6a6a6; --accent: #d9a066;
    --border: #2c2620; --card: #1d1812;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}
.wrap { max-width: 64rem; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
h1 { letter-spacing: -0.02em; margin: 0 0 0.25rem; }
.count, .empty { color: var(--muted); margin: 0 0 1.5rem; }
a { color: var(--accent); }

/* Public list controls */
.controls { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; margin: 0 0 2.25rem; }
.controls .filters { display: flex; gap: 1rem; margin-left: auto; flex-wrap: wrap; }
.controls label { display: flex; flex-direction: column; gap: 0.25rem;
  font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.controls select { font: inherit; padding: 0.4rem 0.5rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--card); color: var(--fg); }
.controls label.toggle { flex-direction: row; align-items: center; gap: 0.4rem;
  text-transform: none; letter-spacing: 0; font-size: 0.85rem; color: var(--fg); align-self: center; }
.controls label.toggle input { width: auto; }
.controls .toggles { display: flex; gap: 1rem; align-items: center; }
.controls .count { color: var(--muted); align-self: center; }
button.sort { font: inherit; cursor: pointer; background: none; border: 0; padding: 0;
  color: inherit; letter-spacing: inherit; text-transform: inherit; }
button.sort:hover { color: var(--fg); }
button.sort::after { content: ' \2195'; opacity: 0.35; }
button.sort[data-dir="asc"]::after { content: ' \2191'; opacity: 1; }
button.sort[data-dir="desc"]::after { content: ' \2193'; opacity: 1; }

/* Page header: title on the left, search (and admin's Add button) on the right */
.page-head { display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap; margin: 0 0 1rem; }
.page-head h1 { margin: 0; }
.page-head .head-actions { display: flex; gap: 0.75rem; align-items: center; }
.page-head .head-actions .btn { flex-shrink: 0; white-space: nowrap; }

/* Search box (admin + public): filters the rows currently shown */
.search { display: block; width: 100%; max-width: 22rem; font: inherit;
  padding: 0.5rem 0.7rem; margin: 0; border: 1px solid var(--border);
  border-radius: 8px; background: var(--card); color: var(--fg); }

/* Phones: stack the header and let the search go full-width again */
@media (max-width: 640px) {
  .page-head { flex-direction: column; align-items: stretch; gap: 0.75rem; }
  .page-head .head-actions { width: 100%; }
  .page-head .head-actions .search { flex: 1 1 auto; min-width: 0; }
  .search { max-width: none; }
}

/* Public list */
.tag { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent); padding: 0.08rem 0.45rem; border-radius: 999px; vertical-align: middle; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); }
table.list th { color: var(--muted); font-weight: 600; font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.03em; }
table.list th.num, table.list td.num { text-align: right; white-space: nowrap; }
table.list tbody tr:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
table.list td.name { font-weight: 500; }
table.list td.name a { color: inherit; text-decoration: none; }
table.list td.name a:hover { color: var(--accent); }
table.list td.name .tag { margin-left: 0.4rem; }
.status { font-size: 0.78rem; }
.status-open { color: var(--accent); font-weight: 600; }
.status-unopened { color: var(--muted); }
.m-meta { display: none; } /* mobile-only: one pipe-separated line under the name */

/* Phones: stack the controls and reflow the table into one card per bottle */
@media (max-width: 640px) {
  .wrap { padding: 1.5rem 1rem 3rem; }
  .controls { flex-direction: column; align-items: stretch; gap: 0.75rem; }
  .controls .count { order: -1; align-self: flex-start; }
  .controls .filters { margin-left: 0; flex-direction: column; gap: 0.75rem; width: 100%; }
  .controls label { width: 100%; }
  /* The two toggles share one row: past bottles left, reviews right */
  .controls .toggles { width: 100%; justify-content: space-between; }
  .controls .toggles label { width: auto; }
  .controls select { width: 100%; }

  table.list thead { display: none; }
  table.list, table.list tbody, table.list tr { display: block; width: 100%; }
  table.list tr { border: 1px solid var(--border); border-radius: 10px; background: var(--card);
    padding: 0.7rem 0.9rem; margin-bottom: 0.6rem; }
  table.list tr:hover { background: var(--card); }
  table.list td { display: none; border: 0; }         /* hide columns + drop the desktop cell divider */
  table.list td.name { display: block; font-size: 1.05rem; }
  .m-meta { display: block; margin-top: 0.3rem; font-size: 0.88rem; }
  .m-meta .sep { color: var(--muted); margin: 0 0.4rem; }
}

/* Bottle detail */
.bigspecs { margin: 0; display: grid; gap: 0.2rem 1rem; }
.bigspecs div { display: flex; justify-content: space-between; gap: 1rem; }
.bigspecs dt { color: var(--muted); }
.bigspecs dt, .bigspecs dd { margin: 0; }
.detail .bigspecs { max-width: 28rem; margin-top: 1.5rem; font-size: 1.05rem; }
.back { text-decoration: none; }

/* Admin */
.adminbar { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap;
  padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--card); }
.adminbar a { text-decoration: none; font-weight: 500; }
.adminbar .logout { margin-left: auto; }
main.admin { max-width: 90rem; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.flash { background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.9rem; margin: 0 0 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
/* Keep the <td> a real table-cell (so its border collapses with the row);
   flex the inner wrapper, not the cell. */
.actions { white-space: nowrap; }
/* Inline-block so the link's padding counts toward row height — rows without a Kill
   button (killed/past bottles) stay the same height as rows with one. */
.actions .btn { display: inline-block; }
.act { display: flex; gap: 0.5rem; align-items: center; }
.act form { margin: 0; display: inline-flex; }
.act .btn, .act button { display: inline-flex; align-items: center; justify-content: center; line-height: 1.2; }

/* Admin bottles list: keep short cells on one line; let names wrap; tidy rows */
.admin-list td, .admin-list th { white-space: nowrap; vertical-align: middle; }
/* Match the public list's header treatment: small, muted, all-caps (button.sort inherits these). */
.admin-list th { color: var(--muted); font-weight: 600; font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.03em; }
/* Every column except Name shrinks to its content (width:1px + nowrap); Name is
   left unconstrained so it absorbs all the leftover width, wrapping only when
   the table runs out of room. */
.admin-list th:not(:first-child), .admin-list td:not(:first-child) { width: 1px; }
.admin-list td.b-name { white-space: normal; }
.admin-list .num { text-align: right; }
/* Hide past bottles (Killed/Given Away) before admin.js runs, so they don't flash in
   then out on load. admin.js strips .is-past and takes over visibility on first pass. */
.admin-list tr.is-past { display: none; }
/* When a saved non-default sort is pending, hide the rows until admin.js applies it, so the
   list doesn't paint in name order first. admin-presort.js sets .presort; admin.js clears it. */
html.presort .admin-list tbody { visibility: hidden; }
.controls label.sort-mobile { display: none; } /* desktop sorts via column headers */
.admin-list td.m-detail { display: none; } /* mobile-only: the card's pipe-separated detail line */
.eye-wrap { display: inline-flex; vertical-align: middle; margin-left: 0.35rem; color: var(--muted); }
.barrel { color: var(--muted); font-size: 0.88em; white-space: nowrap; } /* barrel # beside a name */
.note-mark { color: var(--muted); } /* ✎ beside the rating when tasting notes exist */
/* Rating score as a small outlined badge so it stands out from the other numbers */
.r-rating .score { display: inline-block; border: 1px solid var(--border); border-radius: 6px;
  padding: 0.05rem 0.4rem; font-weight: 600; font-size: 0.88em; }
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--border);
  background: var(--card); color: var(--fg); padding: 0.4rem 0.8rem; border-radius: 8px; text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: #b00020; border-color: #b0002033; }

/* Stats */
h2.stat-h { margin: 1.75rem 0 0; font-size: 0.8rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.stat-group { display: flex; flex-wrap: wrap; gap: 0.85rem; margin: 0.75rem 0 0.5rem; }
/* By status: force a 2-column grid (Open/Unopened over Killed/Given Away) */
.stat-group.by-status { display: grid; grid-template-columns: repeat(2, minmax(0, 12rem)); }
.stat-group.by-status .stat { min-width: 0; max-width: none; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.9rem 1.15rem; min-width: 8rem; flex: 1 1 8rem; max-width: 12rem; }
.stat-n { display: block; font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 0.85rem; }

/* Collection: each count tile paired with a click-to-reveal dollar tile below it */
.stat-col { display: flex; flex-direction: column; gap: 0.85rem; flex: 1 1 8rem; min-width: 8rem; max-width: 12rem; }
.stat-col .stat { width: 100%; max-width: none; flex: 0 0 auto; }
button.stat-money { text-align: left; cursor: pointer; color: var(--accent); }
.stat-money .stat-amount { display: none; }
.stat-money.revealed .stat-mask { display: none; }
.stat-money.revealed .stat-amount { display: block; }

/* Forms */
form.stack { display: grid; gap: 1rem; max-width: 32rem; }
form.stack label { display: grid; gap: 0.25rem; font-weight: 500; }
form.stack input, form.stack select, form.stack textarea {
  font: inherit; padding: 0.45rem 0.55rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--card); color: var(--fg); width: 100%; }
form.stack .check { display: flex; gap: 0.5rem; align-items: center; font-weight: 500; }
form.stack .check input { width: auto; }

/* Add/Edit: public fields and the private fieldset side by side; stack on small screens */
/* Add/Edit: the whole page block (heading, hint, form, delete) centers as one column */
main.admin.narrow { max-width: 60.5rem; } /* 58rem content + the 1.25rem side paddings */
form.form-grid { max-width: 58rem; grid-template-columns: 1fr 1fr; gap: 1.25rem 2rem; align-items: start; }
form.form-grid > .col-public { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-content: start; }
form.form-grid > .col-public > * { grid-column: 1 / -1; } /* fields are full-width by default… */
form.form-grid > .col-public > .field-age_years,
form.form-grid > .col-public > .field-age_months,
form.form-grid > .col-public > .field-proof,
form.form-grid > .col-public > .field-size_ml { grid-column: span 1; } /* …except these pairs, which share a row */
form.form-grid > .col-private { align-self: start; }
form.form-grid > .col-private .fields { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
form.form-grid > .col-private .fields > * { grid-column: 1 / -1; } /* full-width by default… */
form.form-grid > .col-private .fields > .field-date_purchased,
form.form-grid > .col-private .fields > .field-killed_date { grid-column: span 1; } /* …dates share a row */
details.tasting { margin-top: 0.5rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
details.tasting summary { cursor: pointer; font-size: 0.95rem; color: var(--muted); font-weight: 600; }
details.tasting .tasting-fields { display: grid; gap: 1rem; margin-top: 1rem; }
form.form-grid > .form-actions { grid-column: 1 / -1; display: flex; gap: 0.5rem; margin-top: 0.25rem; }
.actions .kill-form { display: inline-block; margin-left: 0.3rem; }
.lk-row .drag { cursor: grab; color: var(--muted); padding: 0 0.35rem; user-select: none; -webkit-user-select: none; }
.lk-row.dragging { opacity: 0.45; }
@media (max-width: 700px) { form.form-grid { grid-template-columns: 1fr; max-width: 34rem; } }
/* Right-aligned, away from Save/Cancel on the left, so it isn't clicked by accident. */
.delete-form { margin-top: 1.75rem; padding-top: 1.25rem; border-top: 1px solid var(--border); max-width: 58rem;
  display: flex; justify-content: flex-end; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin: 0; }
legend { color: var(--muted); padding: 0 0.4rem; }
.inline { display: flex; gap: 0.5rem; align-items: center; }
.muted { color: var(--muted); }

/* Phones: tighten admin chrome and reflow the bottles table into one card per bottle */
@media (max-width: 640px) {
  .adminbar { gap: 0.6rem 0.9rem; padding: 0.6rem 1rem; }
  main.admin { padding: 1.25rem 1rem 3rem; }
  .controls label.sort-mobile { display: flex; } /* headers are hidden, so sort via this */

  /* One card per bottle: full-width name on top; details and Edit share the row below */
  .admin-list thead { display: none; }
  .admin-list, .admin-list tbody, .admin-list tr { display: block; }
  .admin-list tr { border: 1px solid var(--border); border-radius: 10px; background: var(--card);
    padding: 0.6rem 0.85rem; margin-bottom: 0.55rem;
    display: grid; grid-template-columns: 1fr auto; column-gap: 0.75rem;
    grid-template-areas: "name score" "detail edit"; }
  .admin-list td { display: none; border: 0; } /* hide columns + the desktop row dividers */
  .admin-list td:not(:first-child) { width: auto; } /* undo desktop width:1px so grid items size right */
  .admin-list td.b-name { grid-area: name; display: block; white-space: normal;
    font-weight: 600; margin-bottom: 0.25rem; }
  .admin-list td.m-detail { grid-area: detail; display: block; min-width: 0; align-self: center; }
  /* Rating + notes mark: upper-right corner of the card */
  .admin-list td.r-rating { grid-area: score; display: block; align-self: start; text-align: right; }
  .admin-list td.m-detail .m-meta { display: block; margin-top: 0; font-weight: 400;
    color: var(--muted); font-size: 0.88rem; }
  .admin-list td.m-detail .m-meta + .m-meta { margin-top: 0.1rem; } /* tight 2nd detail row */
  /* Buttons stack (Kill on top), equal width, so they align and never crowd the details */
  .admin-list td.actions { grid-area: edit; display: flex; flex-direction: column;
    gap: 0.4rem; align-self: center; }
  .admin-list td.actions .kill-form { order: -1; margin-left: 0; }
  .admin-list td.actions .kill-form button { width: 100%; }
  .admin-list td.actions .btn { text-align: center; }

  .inline input { min-width: 0; flex: 1 1 auto; } /* let lookup name inputs shrink to fit */
}

/* Login: narrow the centered card. (Replaces an inline style — keeps CSP strict.) */
.wrap.narrow { max-width: 24rem; }

/* Types & Statuses (lookups) layout — moved off inline styles for a strict CSP. */
.lookups-grid { display: grid; gap: 2rem; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); }
.lk-row { margin-bottom: 0.4rem; }
.lk-add { margin-top: 0.8rem; }
