/* Card engine — CORE layer (every vertical). Product grid, cart summary, order,
   category list, the shared add button + chips. Ported from the live app's style.css
   and re-tokenized so the injected brand tokens (--accent, --dark1/2, --price) drive
   them. The recipe-to-cart layer lives in shell_cards_recipe.css (grocery only).
   Scoped to card class names the shell chrome itself never uses. */

:root {
  --paper: #ffffff;
  --price: var(--ink);
  --error: #c2240a;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, #ffffff);
  --dark1: #2b2b30;          /* image placeholder gradient (neutral; server may override) */
  --dark2: #45454d;
  --hover-bg: #f0f0f2;
}

/* messages container already: #messages flex column gap; cards stretch full width */
#messages .product-grid-wrap,
#messages .cart-summary,
#messages .order-card,
#messages .list-card { align-self: stretch; }

/* ---------- product cards ---------- */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.product-card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; transition: border-color .15s, box-shadow .15s; }
.product-card:hover { border-color: var(--accent); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 12%, transparent); }
.product-card .image { background: linear-gradient(135deg, var(--dark1), var(--dark2)); aspect-ratio: 1.4/1; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.product-card .image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.product-card .image .placeholder { font-size: 22px; color: #fff; font-weight: 800; opacity: .55; }
.product-card .body { padding: 12px 13px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.product-card .name { font-size: 13.5px; font-weight: 600; line-height: 1.3; color: var(--ink); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.product-card .meta { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.product-card .price { font-size: 15px; font-weight: 700; color: var(--price); margin-top: auto; }
.product-card .price .range { font-weight: 500; color: var(--muted); font-size: 12px; }
.product-card .chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 999px; background: #eceef1; color: #3a3f47; font-weight: 600; }
.chip.new { background: #e7f7ec; color: #1a7f43; }
.chip.unavailable { background: #fdecea; color: var(--error); }
.chip.sale { background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.chip.lactose { background: #eef2f7; color: #2e4a73; }
.grid-note { font-size: 12px; color: var(--muted); margin-bottom: 8px; padding: 4px 2px; }
.sale-price { color: var(--accent); font-weight: 700; }
.range.strike { text-decoration: line-through; opacity: .6; }

/* shared add button (product card + lista rows) */
.add-btn { margin-top: 4px; min-height: 44px; border: none; background: var(--ink); color: var(--user-ink); font-weight: 600; font-size: 12.5px; padding: 9px 12px; border-radius: 8px; cursor: pointer; transition: background .15s, filter .15s; display: inline-flex; align-items: center; justify-content: center; text-align: center; }
.add-btn:hover { background: var(--accent); }
.add-btn:disabled { opacity: .5; cursor: not-allowed; }
.add-btn.added, .add-btn.added:disabled { background: #fff; color: var(--accent); border: 1.5px solid var(--accent); cursor: default; opacity: 1; }

/* ---------- cart summary (read-only) ---------- */
.cart-summary { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.cart-summary .title { font-size: 14px; font-weight: 700; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.cart-summary .title .badge { background: var(--accent); color: var(--user-ink); font-size: 11px; padding: 1px 7px; border-radius: 999px; font-weight: 600; }
.cart-summary .empty { color: var(--muted); font-style: italic; font-size: 13.5px; }
.cart-summary .items { display: flex; flex-direction: column; gap: 8px; }
.cart-summary .item { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cart-summary .item:last-of-type { border-bottom: none; }
.cart-summary .item .thumb { width: 44px; height: 44px; border-radius: 8px; overflow: hidden; background: var(--dark1); }
.cart-summary .item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.cart-summary .item .iname { font-size: 13px; font-weight: 600; }
.cart-summary .item .iqty { font-size: 11.5px; color: var(--muted); }
.cart-summary .item .iprice { font-size: 13px; font-weight: 600; color: var(--price); }
.cart-summary .totals { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.cart-summary .totals .row { display: flex; justify-content: space-between; }
.cart-summary .totals .row.total { font-weight: 700; font-size: 15px; margin-top: 4px; }
.cart-summary .totals .row.total .v { color: var(--accent); }
.cart-summary .note { margin-top: 8px; font-size: 11.5px; color: var(--muted); font-style: italic; }
.cart-summary .cart-checkout { width: 100%; margin-top: 12px; }

/* ---------- order ---------- */
.order-card { background: linear-gradient(135deg, #fff7f7 0%, var(--accent-soft) 100%); border: 1px solid var(--accent); border-radius: 14px; padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.order-card .title { font-weight: 800; font-size: 15px; color: var(--accent); }
.order-card .grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.order-card .k { color: var(--muted); }
.order-card .v { color: var(--ink); font-weight: 500; }
.order-card .note { font-size: 11.5px; color: var(--muted); font-style: italic; margin-top: 4px; }

/* ---------- list-card (categories) ---------- */
.list-card { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.list-card .title { font-weight: 700; margin-bottom: 8px; color: var(--ink); }
.list-card .row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.list-card .row:last-child { border-bottom: none; }

@media (max-width: 720px) {
  .product-grid { grid-template-columns: 1fr; }
  .product-card .body { gap: 9px; }
  .product-card .name { -webkit-line-clamp: 3; }
  .product-card .add-btn { width: 100%; }

  .cart-summary { padding: 14px; }
  .cart-summary .item { grid-template-columns: 44px minmax(0,1fr) auto; gap: 9px; }
}

/* ===== Glass: card surfaces inside the frosted panel (shell v2) ========== */
/* Same material as the shell (see the "Glass material" block in shell.css):
   translucent fill one step firmer than the panel (65%), and deliberately NO
   per-card backdrop-filter — cards sit in flow on the panel's uniform frost,
   so extra blur layers would look identical while costing GPU with many cards
   on screen. Solid --paper stays the no-support fallback. NB: light fills over
   the light frost need to run this transparent to be PERCEPTIBLE at all. */
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .product-card,
  .cart-summary,
  .list-card {
    background: color-mix(in srgb, var(--paper) 78%, transparent);
  }
  .order-card {
    background: linear-gradient(135deg,
      color-mix(in srgb, #fff7f7 80%, transparent) 0%,
      color-mix(in srgb, var(--accent-soft) 80%, transparent) 100%);
  }
}

/* ===== Floating window shell (cart window on every vertical; the grocery
   recipe-doc window reuses these + its own .doc-modal extras) ===== */
.cart-modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(17, 17, 17, 0.45);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; animation: cmFade 0.2s ease;
}
.cart-modal {
  background: #fff; border-radius: 18px; width: min(480px, 100%); max-height: 82vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
  animation: cmPop 0.26s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
.cart-modal.doc-modal { width: min(700px, 100%); }
.cm-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 0.5px solid var(--line); }
.cm-title { font-size: 15px; font-weight: 800; min-width: 0; flex: 1; }
.cm-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.cm-close {
  border: 0; background: #f3f3f4; color: var(--ink); border-radius: 999px;
  width: 30px; height: 30px; font-size: 18px; line-height: 1; cursor: pointer;
  transition: background 0.15s ease;
}
.cm-close:hover { background: var(--accent-soft); color: var(--accent); }
.cm-body { padding: 14px 18px 18px; overflow: auto; }
@keyframes cmFade { from { opacity: 0; } }
@keyframes cmPop { from { opacity: 0; transform: translateY(16px) scale(0.96); } }

/* ===== Cart window: staged editor rows (qty± / soft-remove / restore) =====
   Same row language as the lista card: .ci-main is one aligned rail
   [thumb · name · stepper · price stack]; Remove lives in a trailing .ci-acts
   layer — inline on desktop, swipe-revealed on mobile (see the 720px block). */
.cart-summary .item.editable,
.cart-summary .item.removed { display: flex; align-items: center; gap: 10px; grid-template-columns: none; }
.cart-summary .item .ci-main { flex: 1; min-width: 0; display: grid; grid-template-columns: 44px minmax(0,1fr) auto auto; gap: 10px; align-items: center; }
.cart-summary .item.removed .ci-main { grid-template-columns: 44px minmax(0,1fr) auto; }
.cart-summary .item .ci-qty { display: flex; align-items: center; gap: 6px; }
.cart-summary .item .qa {
  width: 22px; height: 24px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--paper); color: var(--ink); font-size: 14px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.cart-summary .item .qa:hover { border-color: var(--accent); color: var(--accent); }
.cart-summary .item .qv { min-width: 16px; text-align: center; font-size: 13px; font-weight: 600; }
.cart-summary .item .ci-price { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.3; white-space: nowrap; }
.cart-summary .item .ci-price .ip-total { font-size: 13px; font-weight: 600; color: var(--price); }
.cart-summary .item .ci-price .ip-unit { font-size: 10.5px; color: var(--muted); }
.cart-summary .item .ci-acts { display: flex; flex: none; align-items: center; }
.cart-summary .item .ci-remove {
  height: 24px; width: 24px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--paper); color: var(--muted); line-height: 1;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
}
.cart-summary .item .ci-remove svg { width: 13px; height: 13px; }
.cart-summary .item .ci-remove span { display: none; }
.cart-summary .item .ci-remove:hover { border-color: var(--error); color: var(--error); }
.cart-summary .item.removed { opacity: 0.5; }
.cart-summary .item.removed .iname { text-decoration: line-through; }
.cart-summary .item.removed .iqty { font-size: 11px; font-style: italic; color: var(--muted); }
.cart-summary .item .ci-restore { color: var(--accent); border-color: var(--accent); }
/* Long shelf names stay two lines — the row keeps its compact rail. */
.cart-summary .item.editable .iname { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cart-summary .cart-conferma { width: 100%; margin-top: 10px; }
.cart-summary .cart-conferma + .cart-checkout { margin-top: 8px; }
.cm-body .cart-summary { border: 0; padding: 0; background: transparent; }
.cm-body .cart-summary .title { display: none; } /* the window header owns the title */

/* ===== Glass: floating windows share the panel's frost ===== */
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  /* Free text sitting DIRECTLY on the panel frost (outside any bubble or
     card) has no surface of its own to lift it — run it much inkier than
     card-borne muted text. */
  .grid-note {
    color: color-mix(in srgb, var(--ink) 62%, var(--muted));
    font-weight: 500;
  }
  .cart-modal {
    background: color-mix(in srgb, var(--panel-bg, #f5f5f7) 80%, transparent);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    backdrop-filter: blur(24px) saturate(1.5);
    border: 1px solid rgba(255, 255, 255, 0.35);
  }
}

/* ===== Mobile: cart-window editor rows go compact + swipe =====
   Placed at the END of the file: earlier media blocks would lose the
   source-order tie against the base rules above. Same doctrine as the lista
   rows (shell_cards_recipe.css): the editable row is a horizontal scroll-snap
   container with two rest states — closed, or the red Remove tile revealed. */
@media (max-width: 720px) {
  .cm-close { width: 36px; height: 36px; font-size: 20px; }
  /* A bare 1fr can't shrink below the name's longest word — on narrow phones
     that pushed the row past the body and clipped the remove button. */
  .cart-summary .item { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .cart-summary .item .iname { overflow-wrap: anywhere; }
  .cart-summary .item.editable {
    align-items: stretch;
    gap: 0;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }
  .cart-summary .item.editable::-webkit-scrollbar { display: none; }
  .cart-summary .item.editable .ci-main { flex: 0 0 100%; scroll-snap-align: start; }
  /* Joined stepper capsule: − | qty | + in one bordered pill. */
  .cart-summary .item .ci-qty {
    gap: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: color-mix(in srgb, var(--paper) 78%, transparent);
    overflow: hidden;
  }
  .cart-summary .item .ci-qty .qa {
    width: 36px;
    height: 40px;
    border: none;
    border-radius: 0;
    background: transparent;
    font-size: 17px;
  }
  .cart-summary .item .ci-qty .qa.minus { border-right: 1px solid var(--line); }
  .cart-summary .item .ci-qty .qa.plus { border-left: 1px solid var(--line); }
  .cart-summary .item .ci-qty .qv { min-width: 30px; font-size: 14.5px; }
  .cart-summary .item .ci-price .ip-total { font-size: 14.5px; }
  .cart-summary .item .ci-price .ip-unit { font-size: 11px; }
  /* Swipe-revealed Remove: soft-red icon-over-label tile. */
  .cart-summary .item .ci-acts {
    flex: 0 0 auto;
    scroll-snap-align: end;
    margin-left: 10px;
    align-items: stretch;
  }
  .cart-summary .item .ci-acts .ci-remove {
    flex-direction: column;
    gap: 5px;
    width: 82px;
    height: auto;
    min-height: 56px;
    border: none;
    border-radius: 14px;
    padding: 8px 6px;
    background: #f9d9d4;
    color: var(--error);
    font-size: 11.5px;
    font-weight: 700;
  }
  .cart-summary .item .ci-acts .ci-remove svg { width: 20px; height: 20px; }
  .cart-summary .item .ci-acts .ci-remove span { display: inline; }
  .cart-summary .item .ci-restore { width: 40px; height: 40px; border-radius: 10px; font-size: 16px; }
}

/* Very narrow phones: the modal is ~270px wide at 320px viewports — one rail
   would crush the name. Stack like the lista: info on the first line, stepper
   left / price right on the second, thumb spanning both. */
@media (max-width: 360px) {
  .cart-summary .item.editable .ci-main {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    grid-template-areas:
      "thumb info info"
      "thumb qty  price";
    row-gap: 8px;
  }
  .cart-summary .item.editable .thumb { grid-area: thumb; align-self: start; }
  .cart-summary .item.editable .info { grid-area: info; }
  .cart-summary .item.editable .ci-qty { grid-area: qty; justify-self: start; }
  .cart-summary .item.editable .ci-price { grid-area: price; align-self: center; }
}

/* ===== Quick-answer question form (ask_followups) =====
   Follow-up questions render as controls instead of prose: chips for discrete
   choices, an accent slider for scales, a capsule stepper for numbers, a short
   field otherwise. Shared by both verticals; the composer stays the free-text
   fallback. */
.qform-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 12px;
  max-width: 92%;
}
.qform-intro { font-size: 13.5px; color: var(--muted); }
.qform-q { display: flex; flex-direction: column; gap: 8px; }
.qform-label { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.qform-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.qform-chip {
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 13px;
  cursor: pointer; transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.qform-chip:hover { border-color: var(--accent); color: var(--accent); }
.qform-chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink, #fff); }
.qform-scale { display: flex; align-items: center; gap: 12px; }
.qform-scale input[type="range"] { flex: 1; accent-color: var(--accent); }
.qform-val { min-width: 44px; text-align: right; font-size: 13px; font-weight: 700; color: var(--accent); }
.qform-ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.qform-stepper {
  display: inline-flex; align-items: center; width: max-content;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  background: color-mix(in srgb, var(--paper) 78%, transparent);
}
.qform-stepper .qa {
  width: 34px; height: 38px; border: none; background: transparent;
  font: inherit; font-size: 16px; cursor: pointer; color: var(--ink);
}
.qform-stepper .qs-minus { border-right: 1px solid var(--line); }
.qform-stepper .qs-plus { border-left: 1px solid var(--line); }
.qform-stepper input {
  width: 74px; border: none; background: transparent; text-align: center;
  font: inherit; font-size: 14px; -moz-appearance: textfield;
}
.qform-stepper input:focus { outline: none; }
.qform-stepper input::-webkit-outer-spin-button,
.qform-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qform-stepper .qs-unit { font-size: 12px; color: var(--muted); padding: 0 10px; }
.qform-text {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
  font: inherit; font-size: 13.5px; background: var(--paper); color: var(--ink);
}
.qform-text:focus { outline: none; border-color: var(--accent); }
.qform-foot { display: flex; }
.qform-send { flex: 1; }
.qform-card.sent .qform-chip,
.qform-card.sent input { opacity: 0.6; pointer-events: none; }
@media (max-width: 720px) {
  .qform-card { max-width: 100%; }
  .qform-chip { min-height: 42px; padding: 9px 15px; font-size: 13.5px; }
  .qform-stepper .qa { width: 40px; height: 44px; }
}
