:root {
  color-scheme: light;
  --bg: #fff;
  --surface: #f4f1ec;
  --surface-strong: #e8e2d9;
  --text: #161412;
  --text-muted: #625d57;
  --hairline: #d8d2ca;
  --focus-ring: #7b4f2a;
  --error: #a12f25;
}

* { box-sizing: border-box; }
html { -webkit-tap-highlight-color: rgba(22, 20, 18, 0.12); }
body {
  margin: 0;
  padding: 0 max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--text);
  font-family: 'Radio Canada', system-ui, -apple-system, sans-serif;
  line-height: 1.45;
}
body.dialog-open { overflow: hidden; }
::selection { background: var(--text); color: var(--bg); }
button, input { font: inherit; }
a { color: inherit; text-underline-offset: 0.18em; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 3px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header,
.controls,
main,
.site-footer,
.rule {
  width: min(100%, 1200px);
  margin-inline: auto;
}
.site-header {
  padding: 1.25rem 0 1rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.brand { display: flex; align-items: center; }
.logo { width: auto; height: 36px; display: block; }
.logo-fallback {
  font-family: 'Radio Canada Big', 'Radio Canada', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
}
.heading-block { text-align: right; }
.price-heading {
  margin: 0;
  font-family: 'Radio Canada Big', 'Radio Canada', sans-serif;
  font-size: clamp(1.35rem, 5vw, 1.8rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.035em;
  text-transform: uppercase;
}
.subtitle { margin: 0.35rem 0 0; color: var(--text-muted); font-size: 0.8rem; }
.rule { height: 0; border: 0; border-top: 1px solid var(--hairline); }

.controls {
  padding: 0.9rem 0 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.search-field { flex: 1; min-width: 0; }
#search {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.1rem;
  color: var(--text);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  border-radius: 0;
  font-size: 1rem;
}
#search::placeholder { color: var(--text-muted); opacity: 1; }
.manage-link,
.back-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  color: var(--text-muted);
  font-size: 0.84rem;
  font-weight: 500;
  white-space: nowrap;
}

main { min-height: 45vh; padding: 0.15rem 0 3rem; }
.status { margin: 0; padding: 1rem 0; color: var(--text-muted); }
.status.error { color: var(--error); }
.catalog-section { margin: 0; }
.section-heading-row {
  margin: 0 0 0.8rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.section-heading,
.other-products summary {
  font-family: 'Radio Canada Big', 'Radio Canada', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.section-heading { margin: 0; }
.section-count {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  font-weight: 400;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 10px;
}
.card {
  min-width: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.card-media {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  overflow: hidden;
  background: var(--surface);
}
.card-media img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 180ms cubic-bezier(.16, 1, .3, 1);
}
.card-body {
  padding-top: 0.52rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.12rem 0.45rem;
}
.card-title {
  min-width: 0;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.18;
  overflow-wrap: anywhere;
}
.card-price {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.18;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.card-weight {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 0.76rem;
}
.card:active .card-media img { transform: scale(0.985); }
.other-products {
  margin-top: 2.25rem;
  border-top: 1px solid var(--hairline);
}
.other-products summary {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
  list-style: none;
}
.other-products summary::-webkit-details-marker { display: none; }
.other-products summary::after {
  content: "+";
  margin-left: auto;
  font-size: 1.45rem;
  font-weight: 300;
  line-height: 1;
}
.other-products[open] summary::after { content: "−"; }
.other-products .section-count { margin-left: 0.3rem; }
.other-grid { padding: 0.45rem 0 1rem; }
.site-footer {
  padding: 1.4rem 0 2rem;
  border-top: 1px solid var(--hairline);
  color: var(--text-muted);
  font-size: 0.78rem;
}
.site-footer p { margin: 0; }

.qr-dialog {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.qr-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  background: rgba(16, 14, 12, 0.9);
  border: 0;
}
.qr-panel {
  position: relative;
  width: min(100%, 560px);
  min-height: min(92vh, 700px);
  padding: clamp(1.25rem, 4vw, 2rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.3);
}
.qr-close {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  width: 48px;
  height: 48px;
  padding: 12px;
  display: grid;
  place-items: center;
  color: var(--text);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.qr-close svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.qr-copy { margin-bottom: 0.9rem; text-align: center; }
.qr-copy h2 {
  margin: 0;
  font-family: 'Radio Canada Big', 'Radio Canada', sans-serif;
  font-size: clamp(1.25rem, 6vw, 2rem);
  line-height: 1.1;
  letter-spacing: -0.025em;
}
.qr-price { margin: 0.35rem 0 0; font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.qr-image { width: min(78vw, 430px); height: min(78vw, 430px); display: block; object-fit: contain; }
.qr-hint { margin: 0.8rem 0 0; color: var(--text-muted); font-size: 0.85rem; }

/* Management page */
.manage-main { width: min(100%, 720px); }
.manage-header { align-items: center; }
.manage-intro { margin: 1.4rem 0 1.15rem; }
.manage-title {
  margin: 0;
  font-family: 'Radio Canada Big', 'Radio Canada', sans-serif;
  font-size: clamp(1.6rem, 7vw, 2.6rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
}
.manage-intro p { max-width: 60ch; margin: 0.7rem 0 0; color: var(--text-muted); }
.product-list { border-top: 1px solid var(--hairline); }
.product-toggle {
  min-height: 74px;
  padding: 0.6rem 0;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 50px;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--hairline);
  cursor: pointer;
}
.product-toggle > img { width: 54px; height: 54px; display: block; object-fit: cover; background: var(--surface); }
.product-toggle-copy { min-width: 0; display: flex; flex-direction: column; }
.product-toggle-copy strong { font-size: 0.95rem; font-weight: 500; }
.product-toggle-copy span { color: var(--text-muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.product-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-control {
  width: 46px;
  height: 28px;
  position: relative;
  justify-self: end;
  background: var(--surface-strong);
  border-radius: 999px;
  transition: background 140ms ease-out;
}
.toggle-control::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  background: var(--bg);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(22, 20, 18, 0.24);
  transition: transform 140ms cubic-bezier(.16, 1, .3, 1);
}
.product-toggle input:checked + .toggle-control { background: var(--text); }
.product-toggle input:checked + .toggle-control::after { transform: translateX(18px); }
.product-toggle input:focus-visible + .toggle-control { outline: 3px solid var(--focus-ring); outline-offset: 3px; }
.manage-actions {
  position: sticky;
  bottom: 0;
  padding: 1rem 0 max(1rem, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  background: linear-gradient(to top, var(--bg) 75%, rgba(255,255,255,0));
}
.primary-action,
#reset-selection {
  min-height: 48px;
  padding: 0.7rem 1rem;
  border: 1px solid var(--text);
  cursor: pointer;
}
.primary-action { color: var(--bg); background: var(--text); }
#reset-selection { color: var(--text); background: var(--bg); }
.primary-action:disabled,
#reset-selection:disabled { opacity: 0.45; cursor: not-allowed; }

@media (hover: hover) {
  .card:hover .card-media img { transform: scale(1.025); }
  .manage-link:hover, .back-link:hover { color: var(--text); }
}

@media (max-width: 640px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .site-header { gap: 0.65rem; }
  .heading-block { max-width: 68%; }
  .controls { align-items: stretch; flex-direction: column; gap: 0.45rem; }
  .manage-link { align-self: flex-end; }
  .qr-dialog { padding: 0; }
  .qr-panel { width: 100%; min-height: 100dvh; }
  .qr-image { width: min(86vw, 430px); height: min(86vw, 430px); }
}

@media (min-width: 641px) {
  body { padding-inline: 24px; }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px 20px; }
  .card-title, .card-price { font-size: 0.92rem; }
  .card-weight { font-size: 0.84rem; }
}

@media (min-width: 960px) {
  body { padding-inline: 40px; }
  .site-header { padding-block: 1.75rem 1.25rem; }
  .logo { height: 44px; }
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 34px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
