/* Card engine — RECIPE layer (grocery vertical only). The recipe-to-cart "lista"
   card (ingredient rows with qty/swap/remove + pairings), the recipe-doc document,
   and the recipe window modal + PDF. Loaded by the server only when the brand's
   vertical is "grocery" (see docs/VERTICALS.md). Depends on tokens defined in
   shell_cards_core.css (--dark1/2, --price, --accent-soft), which loads first. */

#messages .recipe-card,
#messages .recipe-doc { align-self: stretch; }

/* ---------- recipe card (lista) ---------- */
.recipe-card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; transition: border-color .15s, box-shadow .15s; }
.recipe-card:hover { border-color: var(--accent); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 12%, transparent); }
.recipe-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 9px; }
.recipe-head .recipe-dish { font-size: 15.5px; font-weight: 800; color: var(--ink); }
.recipe-head .recipe-serv { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.recipe-note { font-size: 12.5px; color: var(--muted); margin-top: -2px; }
.recipe-rows { display: flex; flex-direction: column; }
/* One aligned rail per row: [thumb | info | stepper | price] live in .ing-main;
   Swap/Remove live in a trailing .ing-actions layer. Desktop shows the actions
   inline; mobile turns the row into a scroll-snap container and a left swipe
   reveals them (see the 720px block below). */
.ingredient-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ingredient-row:last-child { border-bottom: none; }
.ingredient-row .ing-main { flex: 1; min-width: 0; display: grid; grid-template-columns: 40px minmax(0,1fr) auto auto; gap: 10px; align-items: center; }
.ingredient-row .ing-thumb { width: 40px; height: 40px; border-radius: 8px; overflow: hidden; background: linear-gradient(135deg, var(--dark1), var(--dark2)); display: flex; align-items: center; justify-content: center; flex: none; }
.ingredient-row .ing-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ingredient-row .ing-thumb .ph { color: #fff; font-size: 11px; font-weight: 700; opacity: .85; }
.ingredient-row .ing-info { min-width: 0; }
.ingredient-row .ing-label { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.ingredient-row .ing-prod { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ingredient-row .ing-qty { display: flex; align-items: center; gap: 6px; }
.ingredient-row .ing-qty .qa, .ingredient-row .ling-restore { 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; }
.ingredient-row .ing-qty .qa:hover { border-color: var(--accent); color: var(--accent); }
.ingredient-row .ing-qty .qv { min-width: 16px; text-align: center; font-size: 13px; font-weight: 600; }
/* Price stack: bold line total over a muted unit breakdown, right-aligned. */
.ingredient-row .ing-price { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.3; white-space: nowrap; }
.ingredient-row .ing-price .ip-total { font-size: 13px; font-weight: 700; color: var(--price); }
.ingredient-row .ing-price .ip-unit { font-size: 10.5px; color: var(--muted); }
.ingredient-row .ing-actions { display: flex; gap: 4px; align-items: center; flex: none; }
.ingredient-row .ing-actions button { height: 24px; border-radius: 6px; border: 1px solid var(--line); background: var(--paper); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 5px; line-height: 1; }
.ingredient-row .ing-actions .ling-swap { padding: 0 8px; font-size: 11px; font-weight: 600; color: var(--muted); }
.ingredient-row .ing-actions .ling-swap svg { width: 12px; height: 12px; }
.ingredient-row .ing-actions .ling-swap:hover { border-color: var(--accent); color: var(--accent); }
.ingredient-row .ing-actions .ling-remove { width: 24px; padding: 0; color: var(--ink); }
.ingredient-row .ing-actions .ling-remove span { display: none; }
.ingredient-row .ing-actions .ling-remove svg { width: 13px; height: 13px; }
.ingredient-row .ing-actions .ling-remove:hover { border-color: var(--error); color: var(--error); }
.ingredient-row .ling-restore { color: var(--accent); }
.ingredient-row.removed .ing-thumb, .ingredient-row.removed .ing-info, .ingredient-row.removed .ing-price { opacity: .45; filter: grayscale(1); }
.ingredient-row.removed .ing-label { text-decoration: line-through; font-weight: 500; }
.recipe-empty { font-size: 12.5px; color: var(--muted); font-style: italic; padding: 8px 0; }
.recipe-totals { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; }
.recipe-totals .rt-count { color: var(--muted); }
.recipe-totals .rt-total { font-weight: 600; }
.recipe-totals .rt-total b { color: var(--accent); font-size: 15px; margin-left: 4px; }
.recipe-actions { display: flex; gap: 8px; }
.recipe-actions .recipe-addall { flex: 1; margin-top: 0; }
.recipe-createdoc { min-height: 44px; border: 1.5px solid var(--accent); background: #fff; color: var(--accent); font-weight: 700; font-size: 12.5px; padding: 9px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; transition: background .15s, transform .15s; }
.recipe-createdoc:hover { background: var(--accent-soft); transform: translateY(-1px); }
.recipe-pairings { border-top: 1px solid var(--line); padding-top: 10px; }
.recipe-pairings .rp-title { font-size: 12px; font-weight: 700; color: var(--ink); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .03em; }
.recipe-pairings .rp-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.recipe-pairings .rp-chip { min-height: 44px; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 12px; font-size: 12.5px; font-weight: 600; color: var(--ink); cursor: pointer; transition: border-color .15s, box-shadow .15s, color .15s; }
.recipe-pairings .rp-chip:hover { border-color: var(--accent); }
.recipe-pairings .rp-chip.open { border-color: var(--accent); color: var(--accent); box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 12%, transparent); }
.recipe-pairings .rp-caret { font-size: 10px; opacity: .6; transition: transform .15s; }
.recipe-pairings .rp-chip.open .rp-caret { transform: rotate(180deg); }
.recipe-pairings .rp-added { display: none; color: #1a7f37; font-weight: 800; }
.recipe-pairings .rp-chip.added .rp-added { display: inline; }
.recipe-pairings .rp-chip.added { border-color: #1a7f37; }
.recipe-pairings .rp-count { font-size: 10.5px; font-weight: 700; color: var(--accent); opacity: .85; }
.recipe-pairings .rp-expand { margin-top: 10px; }
.recipe-pairings .rp-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }

/* ---------- recipe doc (steps) ---------- */
.recipe-doc { background: var(--paper); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 14px; padding: 16px 18px; }
.recipe-doc .rd-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.recipe-doc .rd-title { font-size: 16px; font-weight: 800; }
.recipe-doc .rd-meta { display: flex; gap: 14px; margin-top: 6px; color: var(--muted); font-size: 12.5px; }
.recipe-doc .rd-cols { display: grid; grid-template-columns: minmax(150px,1fr) 1.7fr; gap: 18px; margin-top: 14px; }
@media (max-width: 560px) { .recipe-doc .rd-cols { grid-template-columns: 1fr; } }
.recipe-doc .rd-sec { font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.recipe-doc .rd-ings ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.recipe-doc .rd-ings li { font-size: 13px; border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.recipe-doc .rd-ings li b { color: var(--accent); font-weight: 700; }
.recipe-doc .rd-steps ol { margin: 0; padding: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 10px; }
.recipe-doc .rd-steps li { counter-increment: step; font-size: 13.5px; line-height: 1.5; display: flex; gap: 10px; }
.recipe-doc .rd-steps li::before { content: counter(step); flex: 0 0 22px; height: 22px; border-radius: 999px; background: var(--accent); color: var(--user-ink); font-size: 12px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; margin-top: 1px; }
.recipe-doc .rd-tip { margin-top: 14px; background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; font-size: 12.5px; line-height: 1.5; }
.recipe-doc .rd-download { margin-top: 14px; width: auto; padding: 8px 14px; }

@media (max-width: 720px) {
  .recipe-card { padding: 13px 14px 15px; }
  .recipe-head { align-items: flex-start; flex-direction: column; gap: 2px; }
  .recipe-head .recipe-serv { white-space: normal; }
  /* Compact aligned row (one rail: thumb · info · stepper · price) with the
     Swap/Remove actions BEHIND a left swipe — the row is a horizontal
     scroll-snap container with exactly two rest states (closed / actions
     revealed), so no JS is needed and vertical panel scrolling is untouched. */
  .ingredient-row {
    align-items: stretch;
    gap: 0;
    padding: 9px 0;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }
  .ingredient-row::-webkit-scrollbar { display: none; }
  .ingredient-row .ing-main {
    flex: 0 0 100%;
    scroll-snap-align: start;
    grid-template-columns: 44px minmax(0,1fr) auto auto;
    gap: 10px;
  }
  .ingredient-row .ing-thumb {
    width: 44px;
    height: 44px;
  }
  .ingredient-row .ing-prod { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  /* Joined stepper capsule: − | qty | + in one bordered pill. */
  .ingredient-row .ing-qty {
    gap: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: color-mix(in srgb, var(--paper) 78%, transparent);
    overflow: hidden;
  }
  .ingredient-row .ing-qty .qa {
    width: 36px;
    height: 40px;
    border: none;
    border-radius: 0;
    background: transparent;
    font-size: 17px;
  }
  .ingredient-row .ing-qty .qa.minus { border-right: 1px solid var(--line); }
  .ingredient-row .ing-qty .qa.plus { border-left: 1px solid var(--line); }
  .ingredient-row .ing-qty .qv { min-width: 30px; font-size: 14.5px; }
  .ingredient-row .ing-price .ip-total { font-size: 14.5px; }
  .ingredient-row .ing-price .ip-unit { font-size: 11px; }
  /* Swipe-revealed actions: icon-over-label tiles (amber Swap, soft-red Remove). */
  .ingredient-row .ing-actions {
    flex: 0 0 auto;
    scroll-snap-align: end;
    margin-left: 10px;
    gap: 8px;
    align-items: stretch;
  }
  .ingredient-row .ing-actions button {
    flex-direction: column;
    gap: 5px;
    width: 82px;
    height: auto;
    min-height: 56px;
    border: none;
    border-radius: 14px;
    padding: 8px 6px;
    font-size: 11.5px;
    font-weight: 700;
  }
  .ingredient-row .ing-actions button svg { width: 20px; height: 20px; }
  .ingredient-row .ing-actions .ling-swap { background: #f5d75a; color: #5b4a10; padding: 8px 6px; }
  .ingredient-row .ing-actions .ling-remove { background: #f9d9d4; color: var(--error); width: 82px; }
  .ingredient-row .ing-actions .ling-remove span { display: inline; }
  .ingredient-row .ling-restore {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 16px;
  }
  .recipe-totals { align-items: flex-start; flex-direction: column; gap: 3px; }
  .recipe-actions { flex-direction: column; }
  .recipe-createdoc,
  .recipe-actions .recipe-addall,
  .recipe-doc .rd-download { width: 100%; }
  .recipe-pairings .rp-chips { align-items: stretch; }
  .recipe-pairings .rp-chip { justify-content: center; }
}

/* Very narrow phones: one rail would crush the name column (thumb + stepper +
   price leave it ~10px at 320px). Keep the alignment by stacking: info on the
   first line, stepper left / price right on the second, thumb spanning both. */
@media (max-width: 360px) {
  .ingredient-row .ing-main {
    grid-template-columns: 44px minmax(0,1fr) auto;
    grid-template-areas:
      "thumb info info"
      "thumb qty  price";
    row-gap: 8px;
  }
  .ingredient-row .ing-thumb { grid-area: thumb; align-self: start; }
  .ingredient-row .ing-info { grid-area: info; }
  .ingredient-row .ing-qty { grid-area: qty; justify-self: start; }
  .ingredient-row .ing-price { grid-area: price; align-self: center; }
  .ingredient-row.removed .ing-main {
    grid-template-columns: 44px minmax(0,1fr) auto;
    grid-template-areas: none;
  }
  .ingredient-row.removed .ing-thumb,
  .ingredient-row.removed .ing-info,
  .ingredient-row.removed .ing-price,
  .ingredient-row .ling-restore { grid-area: auto; }
}

/* ---------- Recipe window (Create-recipe opens OVER the chat) ---------- */
/* (modal shell styles — .cart-modal-overlay/.cart-modal/.cm-* — moved to
   shell_cards_core.css: the cart window needs them on EVERY vertical) */
.cm-body .recipe-doc { border: 0; border-left: 0; border-radius: 0; padding: 2px 2px 6px; background: transparent; }
.cm-body .recipe-doc .rd-title { display: none; } /* the window header owns the title */
.rd-download-head { margin: 0; width: auto; padding: 8px 13px; font-size: 12px; white-space: nowrap; }
/* (cmFade/cmPop keyframes moved to shell_cards_core.css with the window shell) */

/* Re-open chip left in the chat after the window closes */
.recipe-doc-chip {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 10px;
  background: var(--paper); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 12px; padding: 10px 14px;
}
.recipe-doc-chip .rdc-ico { font-size: 18px; }
.recipe-doc-chip .rdc-name { font-size: 13.5px; font-weight: 700; }
.recipe-doc-chip .rdc-open {
  border: 1.5px solid var(--accent); background: #fff; color: var(--accent);
  font-weight: 700; font-size: 12px; padding: 6px 12px; border-radius: 999px;
  cursor: pointer; white-space: nowrap; transition: background 0.15s ease;
}
.recipe-doc-chip .rdc-open:hover { background: var(--accent-soft); }

/* "Chef is writing" loading state (reuses the shared `spin` keyframe from shell.css) */
.rd-loading { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 56px 24px; }
.rd-spin { width: 36px; height: 36px; border: 3.5px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 999px; animation: spin 0.8s linear infinite; }
.rd-loading-label { color: var(--muted); font-size: 14px; font-weight: 600; }

@media (max-width: 480px) {
  .doc-modal .cm-head { align-items: flex-start; }
  .doc-modal .cm-title { font-size: 14px; line-height: 1.25; }
  .rd-download-head { padding: 7px 10px; font-size: 11.5px; }
}

/* ===== Glass: recipe surfaces (shell v2 — same doctrine as core cards) === */
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .recipe-card,
  .recipe-doc,
  .recipe-doc-chip {
    background: color-mix(in srgb, var(--paper) 78%, transparent);
  }
}
