/* Wijn — mobile-first, no framework. */

:root {
  --wine: #7a1230;
  --wine-dark: #4a0d20;
  --wine-soft: #f6e9ec;
  --bg: #faf7f5;
  --surface: #ffffff;
  --text: #241a1d;
  --muted: #7a6b70;
  --line: #e6dcdf;
  --danger: #b3261e;
  --ok: #1c7c4a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(40, 10, 20, .09), 0 6px 20px rgba(40, 10, 20, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --wine: #d4718c;
    --wine-dark: #1a1013;
    --wine-soft: #33212a;
    --bg: #161013;
    --surface: #211a1e;
    --text: #f2e9ec;
    --muted: #a89aa0;
    --line: #362b30;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

/* Several elements below set an explicit `display`, which would otherwise win
   over the user-agent rule for [hidden] and leave them stuck on screen. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding-bottom: 6rem;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h3 { margin: 1.5rem 0 .25rem; font-size: 1rem; }

/* ------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: max(.6rem, env(safe-area-inset-top)) .8rem .5rem;
  background: var(--wine-dark);
  color: #fff;
  box-shadow: var(--shadow);
}

.topbar-row { display: flex; align-items: center; gap: .5rem; }
.brand { font-size: 1.35rem; letter-spacing: .02em; }
.topbar-actions { margin-left: auto; display: flex; gap: .25rem; }

.icon-btn {
  background: transparent;
  border: 0;
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  padding: .45rem .5rem;
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .14); }
.dialog .icon-btn { color: var(--text); }
.dialog .icon-btn:hover { background: var(--line); }

/* ---------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  gap: .25rem;
  margin-top: .55rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  --tab-color: transparent;
  flex: none;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, .68);
  font: inherit;
  font-size: .9rem;
  padding: .4rem .7rem .5rem;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: #fff; }
.tab[aria-selected="true"] {
  color: #fff;
  font-weight: 600;
  border-bottom-color: #fff;
}

.tab-count {
  font-size: .7rem;
  font-weight: 600;
  background: rgba(255, 255, 255, .18);
  border-radius: 999px;
  padding: .05rem .4rem;
  margin-left: .15rem;
}

.search-row { display: flex; gap: .4rem; margin-top: .5rem; }

.search-row input {
  flex: 1;
  min-width: 0;
  padding: .6rem .75rem;
  font-size: 16px; /* keeps iOS from zooming on focus */
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .13);
  color: #fff;
}
.search-row input::placeholder { color: rgba(255, 255, 255, .6); }
.search-row input:focus { outline: 2px solid rgba(255, 255, 255, .5); }
.icon-btn.scan { background: rgba(255, 255, 255, .13); }

.filter-toggle-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .5rem;
}
.summary {
  font-size: .8rem;
  color: rgba(255, 255, 255, .75);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mini-select {
  /* Overrides the global `select { width: 100% }`, which would otherwise let
     the sort control swallow the whole row. */
  width: auto;
  flex: none;
  max-width: 45%;
  margin-top: 0;
  font-size: .8rem;
  padding: .3rem .4rem;
  border-radius: 8px;
  border: 0;
  background: rgba(255, 255, 255, .13);
  color: #fff;
}
.mini-select option { color: var(--text); background: var(--surface); }

/* ------------------------------------------------------------ filters */

.filters {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: .85rem;
  display: grid;
  gap: .85rem;
}
.filter-label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  display: block;
  margin-bottom: .35rem;
}
.chip-row { display: flex; flex-wrap: wrap; gap: .35rem; }

.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: .3rem .7rem;
  font-size: .82rem;
  cursor: pointer;
  white-space: nowrap;
}
.chip[aria-pressed="true"], .chip.active {
  background: var(--wine);
  border-color: var(--wine);
  color: #fff;
}
.chip-toggle { background: rgba(255, 255, 255, .13); border-color: transparent; color: #fff; }

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .6rem;
}
.filter-grid:empty { display: none; }

label { display: block; font-size: .8rem; color: var(--muted); }
label.req::after { content: " *"; color: var(--wine); }

input, select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .6rem;
  margin-top: .15rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--wine);
  outline-offset: -1px;
}
textarea { resize: vertical; }

label.inline, .inline {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: .85rem;
  color: var(--text);
}
label.inline input { width: auto; margin: 0; }

.filter-checks { display: flex; flex-wrap: wrap; align-items: center; gap: .9rem; }

/* --------------------------------------------------------------- list */

.list {
  display: grid;
  gap: .6rem;
  padding: .8rem;
  max-width: 900px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .75rem .85rem;
  display: grid;
  grid-template-columns: 4px 1fr auto;
  gap: .75rem;
  align-items: start;
  cursor: pointer;
}
.card.out-of-stock { opacity: .55; }
.card-stripe { grid-row: 1 / -1; border-radius: 3px; background: var(--wine); align-self: stretch; }

.card-title { font-weight: 620; line-height: 1.25; }
.card-vintage { color: var(--muted); font-weight: 400; }
.card-sub { font-size: .82rem; color: var(--muted); margin-top: .1rem; }
.card-meta { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .45rem; }

.tag {
  font-size: .7rem;
  padding: .12rem .5rem;
  border-radius: 999px;
  background: var(--wine-soft);
  color: var(--wine);
  white-space: nowrap;
}
.tag.cat { color: #fff; }
.tag.plain { background: var(--line); color: var(--muted); }

.card-side { display: grid; justify-items: center; gap: .35rem; }
.qty { font-size: 1.5rem; font-weight: 680; line-height: 1; }
.qty small { font-size: .62rem; font-weight: 400; color: var(--muted); display: block; text-align: center; }

.card-btns { display: flex; gap: .25rem; }
.mini-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 7px;
  width: 30px;
  height: 30px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.mini-btn:hover:not(:disabled) { border-color: var(--wine); color: var(--wine); }
.mini-btn:disabled { opacity: .35; cursor: default; }
.mini-btn.drink { background: var(--wine); border-color: var(--wine); color: #fff; width: auto; padding: 0 .5rem; }

.stars { color: var(--wine); font-size: .78rem; letter-spacing: .05em; }

.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }

/* ---------------------------------------------------------------- fab */

.fab {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--wine);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(122, 18, 48, .45);
  cursor: pointer;
  z-index: 30;
}

/* ------------------------------------------------------------ dialogs */

.dialog {
  border: 0;
  border-radius: 16px;
  padding: 0;
  width: min(560px, 100vw - 1.5rem);
  max-height: 88vh;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 12px 48px rgba(0, 0, 0, .3);
  overflow: hidden;
}
.dialog-sm { width: min(400px, 100vw - 1.5rem); }
.dialog::backdrop { background: rgba(20, 5, 12, .55); }
.dialog > form { display: contents; }

.dialog-head {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.dialog-head h2 { font-size: 1.05rem; flex: 1; }

.dialog-body {
  padding: 1rem;
  overflow-y: auto;
  max-height: calc(88vh - 8rem);
  display: grid;
  gap: .7rem;
  align-content: start;
}

.dialog-foot {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.spacer { flex: 1; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.row-3 { display: grid; grid-template-columns: 1fr .7fr .7fr; gap: .6rem; }

.hint { font-size: .74rem; color: var(--muted); font-weight: 400; margin: 0; }

.input-with-btn { display: flex; gap: .4rem; align-items: stretch; }
.input-with-btn input { flex: 1; min-width: 0; }
.input-with-btn .btn { margin-top: .15rem; white-space: nowrap; }

.fs { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; margin: 0; }
.fs legend { font-size: .74rem; color: var(--muted); padding: 0 .3rem; }

.btn {
  font: inherit;
  font-size: .9rem;
  padding: .5rem .9rem;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn-primary { background: var(--wine); border-color: var(--wine); color: #fff; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; }
.btn:hover { filter: brightness(.96); }

.drink-name { font-weight: 600; margin: 0; }

/* ------------------------------------------------------- admin lists */

.admin-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.admin-list li {
  display: flex;
  align-items: center;
  gap: .55rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: .5rem .6rem;
  font-size: .88rem;
}
.admin-list .grow { flex: 1; min-width: 0; }
.admin-list .sub { font-size: .74rem; color: var(--muted); }
.swatch { width: 16px; height: 16px; border-radius: 50%; flex: none; }

.admin-add {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  align-items: flex-start;
  margin-top: .5rem;
}
.admin-add input[type="color"] { width: 44px; padding: .2rem; flex: none; }
.admin-add input[type="text"], .admin-add input:not([type]) { flex: 1; min-width: 8rem; }
/* Overrides the global `select { width: 100% }` so the row can hold several controls. */
.admin-add select { flex: none; width: auto; max-width: 100%; }
.admin-add .btn { margin-top: .15rem; white-space: nowrap; }

/* -------------------------------------------------------------- scan */

#scan-video {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 10px;
  object-fit: cover;
}
.scan-status { font-size: .82rem; color: var(--muted); margin: 0; text-align: center; }

/* ------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--wine-dark);
  color: #fff;
  padding: .6rem 1rem;
  border-radius: 999px;
  font-size: .85rem;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: 90vw;
}
.toast.err { background: var(--danger); }

@media (min-width: 700px) {
  .topbar { padding: .7rem 1.2rem .6rem; }
  .filters { padding: 1rem 1.2rem; }
  .row-3 { grid-template-columns: 1fr 1fr 1fr; }
}
