/* ================= cart workbench ================= */
/* One screen: the cart as a card per food group, the assistant beside it. shadcn-style surfaces from ui.css tokens;
   each food group keeps one hue (--cat) that only tints headers, chips and small solid badges. Text on --cat is --cat-on. */

/* Category hues (--cat-<key>, --cat-on) and the .cat-<key> hooks live in ui.css; the cart softens tint and edge a little. */
.cat-card,
.cat-chip {
  --cat-tint: color-mix(in oklab, var(--cat) 8%, var(--card));
  --cat-edge: color-mix(in oklab, var(--cat) 22%, var(--border));
}

/* ---------- page shell ---------- */

main.bench {
  max-width: 112rem;
  padding: 0 16px 96px;
}
html:has(main.bench) {
  scroll-padding-top: 72px;
}
.bench-grid {
  display: grid;
  gap: 20px;
  margin-top: 16px;
}
.bench-left,
.bench-cart {
  display: grid;
  gap: 16px;
  min-width: 0;
  align-content: start;
}
.bench-left > *,
.bench-cart > * {
  min-width: 0;
}
.bench-left > .bench-notice {
  margin: 0;
}
.bench-cart .num {
  font-variant-numeric: tabular-nums;
}
.bench-cart p {
  margin: 0;
}
@media (min-width: 64rem) {
  main.bench {
    padding: 0 24px 24px;
  }
  .bench-grid {
    grid-template-columns: minmax(0, 1fr) clamp(21rem, 27vw, 27rem);
    gap: 24px;
    align-items: start;
  }
}

/* ---------- summary card ---------- */

.sum {
  container-type: inline-size;
  display: grid;
  gap: 16px;
  padding: 24px;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.sum-top {
  display: grid;
  gap: 16px 32px;
  align-items: start;
}
@container (min-width: 44rem) {
  .sum-top {
    grid-template-columns: minmax(13rem, auto) minmax(0, 1fr);
  }
}
.sum-label {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4286;
  letter-spacing: 0;
}
.sum-big {
  margin-top: 4px;
  font-size: 2.5rem;
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.sum-cur {
  color: var(--muted-foreground);
  font-size: 0.5em;
  font-weight: 500;
  letter-spacing: 0;
}
.sum-sub {
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  line-height: 1.45;
}
.sum-total .sum-sub {
  margin-top: 6px;
}
.sum-shops {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.sum-shop {
  display: grid;
  gap: 6px;
  align-content: start;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: color-mix(in oklab, var(--muted) 45%, transparent);
}
.sum-shop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  white-space: nowrap;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.3;
}
.sum-shop-head b {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.sum-kicker {
  font-size: 0.875rem;
  font-weight: 500;
}
.sum-of {
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  font-weight: 400;
}
.sum-alert {
  padding: 8px 10px;
  font-size: 0.8125rem;
}
.sum-alert .ui-alert__title {
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.sum-missing {
  padding: 10px 14px;
}
.sum-note {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  color: var(--muted-foreground);
  font-size: 0.8125rem;
}
.sum-note svg {
  flex: none;
  width: 14px;
  height: 14px;
  margin-top: 2px;
}
.sum-note a {
  color: var(--foreground);
  text-decoration: underline;
  text-underline-offset: 3px;
}
/* The sweets budget is a progress bar in the sweets hue; it turns destructive once over. */
.sweets-meter {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  height: 8px;
  margin-top: 2px;
  overflow: hidden;
  border: 0;
  border-radius: 9999px;
  background: color-mix(in oklab, var(--cat-sweets) 18%, transparent);
  color: var(--cat-sweets);
}
.sweets-meter::-webkit-progress-bar {
  border-radius: 9999px;
  background: color-mix(in oklab, var(--cat-sweets) 18%, transparent);
}
.sweets-meter::-webkit-progress-value {
  border-radius: 9999px;
  background: var(--cat-sweets);
}
.sweets-meter::-moz-progress-bar {
  border-radius: 9999px;
  background: var(--cat-sweets);
}
.sum-sweets.over .sweets-meter {
  background: color-mix(in oklab, var(--destructive) 18%, transparent);
}
.sum-sweets.over .sweets-meter::-webkit-progress-bar {
  background: color-mix(in oklab, var(--destructive) 18%, transparent);
}
.sum-sweets.over .sweets-meter::-webkit-progress-value {
  background: var(--destructive);
}
.sum-sweets.over .sweets-meter::-moz-progress-bar {
  background: var(--destructive);
}

/* Where the money goes: one segment per group, as wide as its share. */
.spend {
  display: block;
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 9999px;
}
.spend rect {
  fill: var(--cat);
}

/* Category strip: tinted chips with the group's solid count badge and its subtotal. */
.cats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cat-n {
  display: inline-grid;
  place-items: center;
  flex: none;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 9999px;
  background: var(--cat);
  color: var(--cat-on);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 10px 0 6px;
  border: 1px solid var(--cat-edge);
  border-radius: var(--radius-md);
  background: var(--cat-tint);
  color: var(--foreground);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition:
    border-color var(--dur, 150ms) var(--ease, ease),
    box-shadow var(--dur, 150ms) var(--ease, ease);
}
.cat-chip:hover {
  border-color: color-mix(in oklab, var(--cat) 55%, var(--border));
}
.cat-chip:focus-visible {
  outline: none;
  border-color: var(--cat);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--cat) 30%, transparent);
}
.cat-chip-sum {
  color: var(--muted-foreground);
  font-weight: 400;
}

.sum-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.sum-actions form {
  display: flex;
}
.sum-view {
  margin-right: 4px;
}
.sum-view .ui-tabs__trigger {
  padding-inline: 12px;
}
.sum-new {
  margin-left: auto;
}

@media (max-width: 47.99rem) {
  .sum {
    padding: 16px;
  }
  .sum-big {
    font-size: 2.25rem;
  }
  /* One swipeable row keeps the cards close to the top. */
  .cats {
    flex-wrap: nowrap;
    margin: 0 -16px;
    padding: 0 16px 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .sum-new {
    margin-left: 0;
  }
}

/* ---------- category cards ---------- */

/* Masonry columns: 1 on phones, up to 4 on wide screens. */
.cards {
  columns: 19rem;
  column-gap: 16px;
}
.cat-card {
  container-type: inline-size;
  break-inside: avoid;
  margin: 0 0 16px;
  overflow: hidden;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--cat-edge);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.cat-card:target {
  outline: 2px solid var(--cat);
  outline-offset: 2px;
}
.cat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--cat-tint);
  border-bottom: 1px solid var(--cat-edge);
}
.cat-head h2 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cat-sum {
  flex: none;
  margin: 0 0 0 auto;
  font-size: 0.9375rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

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

/* One item row: photo tile, 2-line title and facts, line total; controls underneath. */
.ln {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  grid-template-areas:
    "pic main"
    "pic cost"
    "ctl ctl";
  gap: 4px 12px;
  padding: 14px 16px 12px;
  border-top: 1px solid var(--border);
  scroll-margin-top: 80px;
}
.ln:first-child {
  border-top: 0;
}
.ln:target {
  background: var(--cat-tint);
}
.ln-pic {
  grid-area: pic;
  align-self: start;
  border-radius: var(--radius-lg);
}
.ln-main {
  grid-area: main;
  min-width: 0;
}
.ln-cost {
  grid-area: cost;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 8px;
}
.ln-ctl {
  grid-area: ctl;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
  min-width: 0;
  margin-top: 8px;
}
.ln-ctl > form {
  flex: none;
}
/* A roomy card puts the total on the right and the controls beside the photo. */
@container (min-width: 25rem) {
  .ln {
    grid-template-columns: 88px minmax(0, 1fr) auto;
    grid-template-areas:
      "pic main cost"
      "pic ctl ctl";
  }
  .ln-cost {
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
  }
  .ln-ctl {
    align-self: end;
  }
}

/* Product photo tile (also used by the chat panel). */
.ln-img {
  display: block;
  flex: none;
  width: 80px;
  height: 80px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #fff;
  object-fit: contain;
}
img.ln-img {
  padding: 4px;
}
.ln .ln-img {
  width: 88px;
  height: 88px;
}
.ln-img-none {
  border-style: dashed;
  border-color: var(--cat-edge, var(--border));
  background: var(--cat-tint, var(--muted));
}
.ln-pic:hover .ln-img {
  border-color: color-mix(in oklab, var(--foreground) 20%, var(--border));
}

.ln-title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  color: var(--foreground);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.ln-title:focus-visible {
  outline-offset: -2px;
  border-radius: 4px;
}
.ln-title:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.ln-sub {
  overflow: hidden;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ln-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin-top: 6px;
  font-size: 0.75rem;
}
.ln-pack {
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  font-weight: 500;
}
.ln-none {
  color: var(--destructive);
}
.ln-total {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}
.ln-unit {
  color: var(--muted-foreground);
  font-size: 0.75rem;
  white-space: nowrap;
}

/* A deal wears the shelf-edge yellow, like everywhere else in the app (also used by the chat cards). */
.off {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--shelf, #ffd84a);
  color: var(--shelf-ink, #17201b);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.3333;
  font-variant-numeric: tabular-nums;
}

/* Quantity: an input group with − count + (each button posts and the cart re-renders). */
.ln-step.ui-input-group {
  width: auto;
  height: 32px;
  flex: none;
}
.ln-step .ln-step-btn {
  width: 30px;
  height: 30px;
  border-radius: calc(var(--radius-md) - 1px);
}
.ln-step .ln-step-btn svg {
  width: 14px;
  height: 14px;
}
.ln-step-n {
  min-width: 2.25ch;
  padding: 0 2px;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
}
.ln-ctl > .ln-pin {
  display: flex;
  flex: 0 1 auto;
  min-width: 5.75rem;
}
.ln-pin .ui-select {
  min-width: 0;
}
.ln-pin .ui-select__control {
  width: 100%;
  min-width: 0;
  max-width: 7.5rem;
  padding-right: 28px;
  padding-left: 10px;
  font-size: 0.8125rem;
  text-overflow: ellipsis;
}
.ln-pin .ui-select__icon {
  right: 9px;
}
.ln-ctl > .ln-swap {
  margin-left: auto;
}
.ln-swap .ln-act {
  padding-inline: 8px;
  gap: 4px;
}
.ln-act {
  color: var(--muted-foreground);
}
/* A narrow card keeps one control row: Swap drops its visible word (the button keeps its aria-label). */
@container (max-width: 20.5rem) {
  .ln-act-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}
.ln-act:hover {
  color: var(--foreground);
}
.ln-rm:hover {
  background: color-mix(in oklab, var(--destructive) 10%, transparent);
  color: var(--destructive);
}
@media (pointer: coarse) {
  .ln-step.ui-input-group {
    height: 40px;
  }
  .ln-step .ln-step-btn {
    width: 38px;
    height: 38px;
  }
  .ln-act,
  .ln-pin .ui-select__control {
    height: 40px;
  }
  .ln-rm {
    width: 40px;
  }
}

/* ---------- where to order ---------- */

.plan {
  container-type: inline-size;
  display: grid;
  gap: 16px;
  padding: 24px;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.plan-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
}
.plan-reason {
  margin-top: 4px;
  color: var(--muted-foreground);
  font-size: 0.875rem;
}
.plan-note {
  color: var(--muted-foreground);
  font-size: 0.8125rem;
}
.plan-note a {
  color: var(--foreground);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.plan-table th,
.plan-table td {
  vertical-align: top;
  padding-block: 12px;
}
.plan-table thead th {
  padding-block: 0;
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  vertical-align: middle;
}
.plan-name {
  min-width: 11rem;
  font-weight: 500;
  text-align: left;
  white-space: normal;
}
.plan-label {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}
.plan-ok {
  display: block;
  margin-top: 4px;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 400;
}
.plan-miss {
  margin-top: 6px;
}
.plan-miss summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  list-style: none;
}
.plan-miss summary::-webkit-details-marker {
  display: none;
}
.plan-show {
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 400;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.plan-miss summary:hover .plan-show {
  color: var(--foreground);
}
.plan-miss[open] .plan-show {
  visibility: hidden;
}
.plan-miss ul {
  margin: 6px 0 0;
  padding-left: 16px;
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  font-weight: 400;
}
.plan-shops {
  white-space: normal;
}
.plan-shop {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}
.plan-shop + .plan-shop {
  margin-top: 6px;
}
.plan-min {
  border-color: color-mix(in oklab, var(--destructive) 40%, transparent);
  color: var(--destructive);
}
.plan-dep,
.plan-delta {
  display: block;
  color: var(--muted-foreground);
  font-size: 0.75rem;
}
.plan-total {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
}
.plan-delta-less {
  color: var(--cat-veg);
}
.plan-act {
  text-align: right;
}
.plan-act form {
  display: inline-flex;
}
.plan-rec {
  background: color-mix(in oklab, var(--muted) 35%, transparent);
}
/* A narrow card stacks each option into a small block instead of a scrolling table. */
@container (max-width: 40rem) {
  .plan-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
  .plan-table,
  .plan-table tbody {
    display: block;
  }
  .plan-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name price"
      "shops shops"
      "items act"
      "fees act";
    gap: 6px 12px;
    padding: 12px 4px;
  }
  .plan-table td,
  .plan-table th {
    padding: 0;
  }
  .plan-name {
    grid-area: name;
    min-width: 0;
  }
  .plan-price {
    grid-area: price;
  }
  .plan-shops {
    grid-area: shops;
  }
  .plan-items {
    grid-area: items;
  }
  .plan-fees {
    grid-area: fees;
  }
  .plan-items,
  .plan-fees {
    color: var(--muted-foreground);
    font-size: 0.8125rem;
    text-align: left;
  }
  .plan-items::before,
  .plan-fees::before {
    content: attr(data-label) " ";
  }
  .plan-items .plan-dep {
    display: inline;
    margin-left: 4px;
  }
  .plan-act {
    grid-area: act;
    align-self: end;
  }
}

/* ---------- checklist ---------- */

.bench-check {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr));
  gap: 16px;
  align-items: start;
}
.chk-intro,
.chk-missing {
  grid-column: 1 / -1;
}
.chk-intro {
  color: var(--muted-foreground);
  font-size: 0.875rem;
}
.chk-shop {
  padding-top: 20px;
  overflow: hidden;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.chk-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
}
.chk-head h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.3;
}
.chk-sum {
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
}
.chk-progress {
  width: calc(100% - 40px);
  height: 6px;
  margin: 12px 20px;
}
.chk-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.chk {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-top: 1px solid var(--border);
}
.chk-form {
  display: flex;
}
.chk-tick {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--input);
  border-radius: 6px;
  background: var(--field-bg, transparent);
  color: var(--primary-foreground);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  transition: box-shadow var(--dur, 150ms) var(--ease, ease);
}
.chk-tick svg {
  width: 14px;
  height: 14px;
}
.chk-tick[aria-checked="true"] {
  border-color: var(--primary);
  background: var(--primary);
}
.chk-tick:focus-visible {
  outline: none;
  border-color: var(--ring);
  box-shadow:
    0 0 0 3px var(--ring-50, color-mix(in oklab, var(--ring) 50%, transparent)),
    var(--shadow-xs);
}
@media (pointer: coarse) {
  .chk-tick {
    width: 28px;
    height: 28px;
  }
}
.chk-main {
  min-width: 0;
}
.chk-title {
  display: block;
  overflow: hidden;
  color: var(--foreground);
  font-size: 0.875rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chk-title:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.chk-meta {
  display: block;
  color: var(--muted-foreground);
  font-size: 0.75rem;
}
.chk-cost {
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
}
.chk.done .chk-title {
  color: var(--muted-foreground);
  text-decoration: line-through;
}
.chk.done .chk-cost {
  color: var(--muted-foreground);
}
.chk-missing ul {
  margin: 0;
  padding-left: 16px;
}
.chk-why {
  opacity: 0.8;
}

/* ---------- empty cart ---------- */

.bench-empty {
  background: var(--card);
}
.bench-empty .ui-empty__title {
  margin: 0;
}
.bench-empty-actions {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 34rem;
}
.bench-empty-actions form {
  display: flex;
}

@media (pointer: coarse) {
  .cat-chip {
    height: 40px;
  }
  .ln-step.ui-input-group {
    height: 42px;
  }
  .ln-step .ln-step-btn {
    width: 40px;
    height: 40px;
  }
}
