/*
 * chat-agent.css — AI Agent Chat UI (v5.0)
 * Emil Kowalski principles: spring physics, @starting-style entry, scale-on-press
 */

/* ── Easings ──────────────────────────────────────────────────────────────── */
:root {
  --spring:        cubic-bezier(.34, 1.56, .64, 1);
  --spring-soft:   cubic-bezier(.25, 1.25, .5,  1);
  --snap-out:      cubic-bezier(.22, 1,    .36, 1);
  --agent-brand:   #ff5000;
  --agent-surface: color-mix(in srgb, var(--surface, #fff) 94%, #ff5000 6%);
}

/* ══════════════════════════════════════════════════════════════════════════════
   CHAT WRAP
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Chat tab: full-height flex container ────────────────────────────────── */
/* .chat-bar is a sibling of #main (inserted before #bottom-nav in #app).  */
/* #main already has a constrained height = viewport - topbar - chatbar - nav */
/* We convert #main to a flex column so #tab-chat can use flex: 1 properly  */
#main:has(#tab-chat:not([hidden])) {
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
}

#tab-chat:not([hidden]) {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 1 0 !important;      /* 0-basis: must match .chat-wrap for proper height bounding */
  min-height: 0 !important;
  height: 0 !important;        /* iOS Safari fix: explicit height creates scroll context */
  margin: 0 !important;
  gap: 0 !important;
}

.chat-wrap {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;   /* 0-basis: prevents unbounded growth, fixes scroll in Chrome */
  min-height: 0;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  flex-shrink: 0;  /* never compress header, all extra space goes to .chat-messages */
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--divider, rgba(0,0,0,.08));
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg, #fafafa);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.chat-header-ico {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(135deg, #ff7a2f 0%, #ff5000 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(255,80,0,0.28);
}

.chat-header-ico svg { width: 18px; height: 18px; }

.chat-header-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--text, #111);
}
.chat-header-sub {
  font-size: 12px;
  color: var(--text-3, #aaa);
  margin-top: 1px;
}

/* Cart badge in header */
.chat-cart-badge {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 20px;
  background: var(--surface, #fff);
  border: 1.5px solid var(--divider, rgba(0,0,0,.1));
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2, #555);
  cursor: pointer;
  transition: transform 150ms var(--spring), box-shadow 150ms var(--snap-out), border-color 150ms ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.chat-cart-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,.10);
}
.chat-cart-badge:active {
  transform: scale(0.94);
  transition-duration: 80ms;
}
.chat-cart-badge.has-items {
  border-color: var(--agent-brand);
  color: var(--agent-brand);
  background: color-mix(in srgb, #fff 92%, #ff5000 8%);
}
.chat-cart-badge-count {
  font-size: 11px;
  font-weight: 800;
  background: var(--agent-brand);
  color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: badge-pop 280ms var(--spring) both;
}
@keyframes badge-pop {
  0%   { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ── Messages ────────────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1 1 0;   /* 0-basis is key: forces browser to honour the height bound */
  min-height: 0;
  padding: 12px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* Chrome ignores padding-bottom on flex+overflow-y containers.
   Use ::after spacer so the last message scrolls above the fixed chat-bar + nav. */
.chat-messages::after {
  content: '';
  display: block;
  flex-shrink: 0;
  height: calc(var(--nav-h, 56px) + 80px); /* nav + chat-bar height */
}

/* ── Row ─────────────────────────────────────────────────────────────────── */
.chat-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.chat-row-user { flex-direction: row-reverse; }

/* ── Avatar ──────────────────────────────────────────────────────────────── */
.chat-ava {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}
.chat-ava-assistant {
  background: linear-gradient(135deg, #ff7a2f, #ff5000);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(255,80,0,0.22);
}
.chat-ava-user {
  background: var(--surface, #f0f0f0);
  border: 1.5px solid var(--divider, rgba(0,0,0,.1));
  color: var(--text-2, #555);
}

/* ── Bubble base ─────────────────────────────────────────────────────────── */
.chat-msg-wrap {
  max-width: 80%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-row-user .chat-msg-wrap { align-items: flex-end; }

.chat-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;

  /* Entry animation via @starting-style */
  transition: opacity 200ms ease, transform 280ms var(--spring-soft);
}

@starting-style {
  .chat-bubble {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
}

.chat-row-assistant .chat-bubble {
  background: var(--surface, #fff);
  border: 1.5px solid var(--divider, rgba(0,0,0,.08));
  border-bottom-left-radius: 6px;
  color: var(--text, #111);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.chat-row-user .chat-bubble {
  background: var(--agent-brand);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 12px rgba(255,80,0,0.22);
}

/* ── Typing indicator ────────────────────────────────────────────────────── */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}
.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3, #aaa);
  animation: typing-dot 1.2s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typing-dot {
  0%, 60%, 100% { transform: translateY(0);   opacity: .4; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ── Image inside user bubble ────────────────────────────────────────────── */
.chat-bubble-img {
  max-width: 200px;
  border-radius: 12px;
  display: block;
  margin-bottom: 6px;
}

/* ── Search results bubble ───────────────────────────────────────────────── */
.chat-bubble-search {
  padding: 12px;
  max-width: 100%;
  background: var(--surface, #fff);
}
.src-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3, #aaa);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.src-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.src-gc {
  border-radius: 12px;
  border: 1.5px solid var(--divider, rgba(0,0,0,.08));
  overflow: hidden;
  background: var(--bg, #fafafa);
  transition: transform 180ms var(--spring-soft), box-shadow 180ms var(--snap-out);
}
.src-gc:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.10); }
.src-gc-hidden { display: none; }
.src-gc-img-wrap { aspect-ratio: 1; background: #f0f0f0; overflow: hidden; }
.src-gc-img-wrap.src-gc-nophoto { display: flex; align-items: center; justify-content: center; color: #ccc; font-size: 24px; }
.src-gc-img { width: 100%; height: 100%; object-fit: cover; transition: transform 300ms var(--spring-soft); }
.src-gc:hover .src-gc-img { transform: scale(1.06); }
.src-gc-body { padding: 8px; }
.src-gc-title { font-size: 12px; font-weight: 600; line-height: 1.4; color: var(--text, #111); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.src-gc-price { font-size: 13px; font-weight: 700; color: var(--agent-brand); margin-top: 3px; }
.src-gc-sales { font-size: 11px; color: var(--text-3, #aaa); margin-top: 1px; }
.src-gc-btns { display: flex; gap: 4px; margin-top: 8px; }
.src-gc-add {
  flex: 1;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--agent-brand);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: transform 100ms var(--spring), box-shadow 150ms ease;
}
.src-gc-add:active { transform: scale(0.92); transition-duration: 60ms; }
.src-gc-open { font-size: 12px; padding: 6px 8px; border-radius: 8px; border: 1.5px solid var(--divider, rgba(0,0,0,.1)); color: var(--text-2, #555); text-decoration: none; display: flex; align-items: center; }
.src-more-btn { width: 100%; margin-top: 8px; padding: 8px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--agent-brand); background: color-mix(in srgb, #fff 92%, #ff5000 8%); border: 1.5px solid var(--agent-brand); cursor: pointer; transition: transform 120ms var(--spring), opacity 120ms ease; }
.src-more-btn:active { transform: scale(0.96); }
.src-qrow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 3px 0; }
.src-q-tb { color: var(--agent-brand); font-weight: 600; cursor: pointer; font-size: 14px; text-decoration: none; border-bottom: 1.5px solid rgba(255,80,0,0.25); transition: border-color 150ms ease; }
.src-q-tb:hover { border-color: var(--agent-brand); }
.src-q-sep { color: var(--text-3, #aaa); font-size: 12px; }
.src-q-cn { color: var(--text-3, #aaa); font-size: 12px; }
.src-q-1688 { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: #e8f0fe; color: #2563eb; text-decoration: none; border: 1px solid rgba(37,99,235,.2); }

/* ══════════════════════════════════════════════════════════════════════════════
   PRODUCT CARD BUBBLE
   ══════════════════════════════════════════════════════════════════════════ */

.agent-product-card {
  background: var(--surface, #fff);
  border: 1.5px solid var(--divider, rgba(0,0,0,.08));
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  overflow: hidden;
  width: min(300px, 78vw);
  box-shadow: 0 2px 12px rgba(0,0,0,.08);

  transition: opacity 200ms ease, transform 320ms var(--spring-soft);
}
@starting-style {
  .agent-product-card {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
}

.agent-product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(0,0,0,.12);
}

.apc-img-wrap {
  aspect-ratio: 1;
  background: #f0f0f0;
  overflow: hidden;
  max-height: 200px;
}
.apc-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 350ms var(--spring-soft);
  display: block;
}
.agent-product-card:hover .apc-img { transform: scale(1.05); }

.apc-body { padding: 12px 14px; }

.apc-title {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text, #111);
  letter-spacing: -0.2px;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.apc-price {
  font-size: 20px;
  font-weight: 800;
  color: var(--agent-brand);
  letter-spacing: -0.5px;
  margin-bottom: 10px;
}

/* Variant chips */
.apc-variants { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.apc-variant-label { font-size: 11px; font-weight: 600; color: var(--text-3, #aaa); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.apc-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.apc-chip {
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1.5px solid var(--divider, rgba(0,0,0,.12));
  color: var(--text-2, #555);
  background: var(--bg, #fafafa);
  cursor: pointer;
  transition:
    transform    120ms var(--spring),
    border-color 120ms ease,
    background   120ms ease,
    color        120ms ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.apc-chip:active { transform: scale(0.91); transition-duration: 60ms; }
.apc-chip.selected {
  border-color: var(--agent-brand);
  background: color-mix(in srgb, #fff 88%, #ff5000 12%);
  color: var(--agent-brand);
  transform: scale(1.04);
}

/* Color chips with image */
.apc-chip-color {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
}
.apc-chip-color img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* Qty control */
.apc-qty {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.apc-qty-label { font-size: 12px; font-weight: 600; color: var(--text-3, #aaa); }
.apc-qty-controls { display: flex; align-items: center; gap: 0; border: 1.5px solid var(--divider, rgba(0,0,0,.12)); border-radius: 10px; overflow: hidden; }
.apc-qty-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-2, #555);
  background: none;
  border: none;
  cursor: pointer;
  transition: background 100ms ease, transform 100ms var(--spring);
}
.apc-qty-btn:active { transform: scale(0.85); background: var(--divider, rgba(0,0,0,.06)); }
.apc-qty-val { min-width: 28px; text-align: center; font-size: 14px; font-weight: 700; color: var(--text, #111); }

/* Add button */
.apc-add-btn {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  background: var(--agent-brand);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.2px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 4px 16px rgba(255,80,0,.28);
  transition:
    transform    120ms var(--snap-out),
    box-shadow   200ms var(--snap-out),
    background   120ms ease;
  animation: btn-enable 280ms var(--spring) both;
}
@keyframes btn-enable {
  0%   { transform: scale(0.92); opacity: 0; }
  100% { transform: scale(1);    opacity: 1; }
}
.apc-add-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(255,80,0,.38); }
.apc-add-btn:active { transform: scale(0.94) translateY(0) !important; box-shadow: 0 2px 8px rgba(255,80,0,.22); transition-duration: 70ms; }
.apc-add-btn:disabled { opacity: .5; cursor: not-allowed; }
.apc-add-btn.added {
  background: #22c55e;
  box-shadow: 0 4px 16px rgba(34,197,94,.28);
  animation: btn-added 400ms var(--spring) both;
}
@keyframes btn-added {
  0%   { transform: scale(1.05); }
  50%  { transform: scale(0.96); }
  100% { transform: scale(1); }
}

/* ══════════════════════════════════════════════════════════════════════════════
   CART WIDGET BUBBLE
   ══════════════════════════════════════════════════════════════════════════ */

.agent-cart-widget {
  background: var(--surface, #fff);
  border: 1.5px solid var(--divider, rgba(0,0,0,.08));
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  overflow: hidden;
  width: min(320px, 82vw);
  box-shadow: 0 2px 12px rgba(0,0,0,.08);

  transition: opacity 200ms ease, transform 300ms var(--spring-soft);
}
@starting-style {
  .agent-cart-widget {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
}

.acw-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--divider, rgba(0,0,0,.07));
}
.acw-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text, #111);
  letter-spacing: -0.2px;
}
.acw-count {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3, #aaa);
}

.acw-list {
  padding: 8px 0;
  max-height: 240px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.acw-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  transition: background 120ms ease;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.acw-item:hover { background: var(--bg, #fafafa); }
.acw-item:active { background: var(--divider, rgba(0,0,0,.05)); }

.acw-item-img {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: #f0f0f0;
  flex-shrink: 0;
}
.acw-item-info { flex: 1; min-width: 0; }
.acw-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #111);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.acw-item-sub { font-size: 11px; color: var(--text-3, #aaa); margin-top: 2px; }
.acw-item-price { font-size: 13px; font-weight: 700; color: var(--agent-brand); flex-shrink: 0; }

.acw-remove-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--text-3, #aaa);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 120ms ease, background 120ms ease, transform 100ms var(--spring);
  flex-shrink: 0;
}
.acw-remove-btn:hover { color: #ff3b30; background: rgba(255,59,48,.08); }
.acw-remove-btn:active { transform: scale(0.85); }

.acw-empty {
  padding: 20px 14px;
  text-align: center;
  font-size: 14px;
  color: var(--text-3, #aaa);
}

.acw-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--divider, rgba(0,0,0,.07));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.acw-total-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.acw-total-label { font-size: 13px; color: var(--text-3, #aaa); }
.acw-total-price { font-size: 20px; font-weight: 800; color: var(--agent-brand); letter-spacing: -0.5px; }
.acw-total-rub { font-size: 13px; color: var(--text-3, #aaa); margin-left: 4px; }

.acw-actions { display: flex; gap: 8px; }
.acw-btn-order {
  flex: 1;
  padding: 10px;
  border-radius: 12px;
  background: var(--agent-brand);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(255,80,0,.26);
  transition: transform 100ms var(--snap-out), box-shadow 150ms ease;
}
.acw-btn-order:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(255,80,0,.36); }
.acw-btn-order:active { transform: scale(0.95); transition-duration: 70ms; }

.acw-btn-edit {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--divider, rgba(0,0,0,.12));
  color: var(--text-2, #555);
  font-size: 14px;
  font-weight: 600;
  background: none;
  cursor: pointer;
  transition: border-color 120ms ease, transform 100ms var(--spring);
}
.acw-btn-edit:active { transform: scale(0.94); }

/* ══════════════════════════════════════════════════════════════════════════════
   ORDER CONFIRM BUBBLE
   ══════════════════════════════════════════════════════════════════════════ */

.agent-order-confirm {
  background: linear-gradient(135deg,
    color-mix(in srgb, #fff 92%, #22c55e 8%) 0%,
    color-mix(in srgb, #fff 96%, #22c55e 4%) 100%
  );
  border: 1.5px solid rgba(34,197,94,.25);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  padding: 16px;
  width: min(300px, 78vw);
  box-shadow: 0 4px 20px rgba(34,197,94,.12);

  transition: opacity 200ms ease, transform 320ms var(--spring);
}
@starting-style {
  .agent-order-confirm {
    opacity: 0;
    transform: scale(0.88) translateY(10px);
  }
}

.aoc-icon { font-size: 28px; margin-bottom: 8px; animation: success-pop 500ms var(--spring) both; }
@keyframes success-pop {
  0%   { transform: scale(0) rotate(-20deg); opacity: 0; }
  60%  { transform: scale(1.2) rotate(8deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.aoc-title { font-size: 16px; font-weight: 800; color: var(--text, #111); letter-spacing: -0.3px; margin-bottom: 4px; }
.aoc-sub { font-size: 13px; color: var(--text-3, #aaa); margin-bottom: 12px; line-height: 1.5; }
.aoc-details { font-size: 13px; color: var(--text-2, #555); margin-bottom: 12px; }
.aoc-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 12px;
  background: #22c55e;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(34,197,94,.28);
  transition: transform 100ms var(--snap-out), box-shadow 150ms ease;
  width: 100%;
  justify-content: center;
}
.aoc-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(34,197,94,.38); }
.aoc-btn:active { transform: scale(0.95); }

/* ══════════════════════════════════════════════════════════════════════════════
   CART ITEM DETAIL CARD (opened by tapping item in cart widget)
   ══════════════════════════════════════════════════════════════════════════ */

.agent-cart-item-card {
  background: var(--surface, #fff);
  border: 1.5px solid var(--divider, rgba(0,0,0,.08));
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  overflow: hidden;
  width: min(300px, 78vw);
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
  display: flex;
  flex-direction: column;
  transition: opacity 200ms ease, transform 320ms var(--spring-soft);
}
@starting-style {
  .agent-cart-item-card { opacity: 0; transform: translateY(10px) scale(0.96); }
}
.aci-photo {
  width: 100%;
  aspect-ratio: 1;
  max-height: 180px;
  object-fit: cover;
  display: block;
  background: var(--surface-2, #f0f0f0);
}
.aci-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.aci-title {
  font-size: 14px; font-weight: 700; color: var(--text, #111);
  line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.aci-price { font-size: 20px; font-weight: 800; color: var(--agent-brand, #ff5000); letter-spacing: -.5px; }
.aci-variants { display: flex; flex-direction: column; gap: 4px; margin: 2px 0; }
.aci-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.aci-row-label { color: var(--text-2, #888); }
.aci-row-price { font-weight: 600; color: var(--text, #111); }
.aci-actions { display: flex; gap: 8px; margin-top: 4px; }
.aci-btn-edit {
  flex: 1; padding: 9px 10px; border-radius: 12px; font-size: 13px; font-weight: 600;
  background: var(--surface-2, #f4f4f4); border: 1.5px solid var(--divider, rgba(0,0,0,.1));
  color: var(--text, #111); cursor: pointer;
  transition: background 120ms ease, transform 100ms var(--spring);
}
.aci-btn-edit:active { transform: scale(0.95); }
.aci-btn-del {
  padding: 9px 12px; border-radius: 12px; font-size: 13px; font-weight: 600;
  background: rgba(255,59,48,.08); border: 1.5px solid rgba(255,59,48,.2);
  color: #ff3b30; cursor: pointer;
  transition: background 120ms ease, transform 100ms var(--spring);
}
.aci-btn-del:active { transform: scale(0.95); background: rgba(255,59,48,.16); }

/* ══════════════════════════════════════════════════════════════════════════════
   CHAT INPUT BAR
   ══════════════════════════════════════════════════════════════════════════ */

.chat-bar {
  bottom: calc(var(--nav-h) + var(--safe-bot));
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: min(100%, var(--maxw));
  z-index: 100;
  padding: 8px 12px 8px;
  background: #fff;
  border-top: 1px solid rgba(0,0,0,.08);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.chat-image-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: var(--surface, #fff);
  border-radius: 12px;
  border: 1.5px solid var(--divider, rgba(0,0,0,.1));
}
.chat-image-preview img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
}
.chat-img-remove {
  margin-left: auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--divider, rgba(0,0,0,.1));
  color: var(--text-2, #555);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 100ms ease, transform 100ms var(--spring);
}
.chat-img-remove:active { transform: scale(0.88); }

.chat-bar-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-attach {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.10);
  border: 1.5px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.55);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 120ms ease, color 120ms ease, transform 100ms var(--spring);
  -webkit-tap-highlight-color: transparent;
}
.chat-attach:active { transform: scale(0.9); }
.chat-attach svg { width: 18px; height: 18px; }

.chat-input {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1.5px solid rgba(0,0,0,.12);
  background: #f5f5f5;
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  outline: none;
  color: #111;
  font-family: inherit;
  transition:
    border-color 150ms var(--snap-out),
    box-shadow   150ms var(--snap-out),
    min-height   250ms var(--snap-out);
}
.chat-input:focus {
  border-color: var(--agent-brand);
  box-shadow: 0 0 0 3px rgba(255,80,0,.10);
  background: #fff;
}
.chat-input::placeholder { color: #aaa; }

.chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--agent-brand);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(255,80,0,.30);
  transition:
    transform    120ms var(--spring),
    box-shadow   150ms var(--snap-out),
    opacity      120ms ease;
}
.chat-send:hover { transform: scale(1.08); box-shadow: 0 6px 18px rgba(255,80,0,.40); }
.chat-send:active { transform: scale(0.90); box-shadow: 0 2px 8px rgba(255,80,0,.22); transition-duration: 70ms; }
.chat-send:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.chat-send svg { width: 18px; height: 18px; }

/* ══════════════════════════════════════════════════════════════════════════════
   CART BANNER (in Cart tab)
   ══════════════════════════════════════════════════════════════════════════ */

.cart-chat-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: 20px;
  background: linear-gradient(135deg,
    color-mix(in srgb, #fff 90%, #ff5000 10%) 0%,
    color-mix(in srgb, #fff 96%, #ff5000 4%) 100%
  );
  border: 1.5px solid rgba(255,80,0,.18);
  margin-bottom: 4px;
  cursor: pointer;
  transition:
    transform    200ms var(--spring-soft),
    box-shadow   200ms var(--snap-out),
    border-color 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.cart-chat-banner:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(255,80,0,.14);
  border-color: rgba(255,80,0,.35);
}
.cart-chat-banner:active { transform: scale(0.97); transition-duration: 80ms; }

.cart-chat-banner-ico {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, #ff7a2f, #ff5000);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(255,80,0,.28);
}
.cart-chat-banner-body { flex: 1; }
.cart-chat-banner-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text, #111);
  letter-spacing: -0.2px;
}
.cart-chat-banner-sub {
  font-size: 12px;
  color: var(--text-3, #aaa);
  margin-top: 2px;
  line-height: 1.4;
}
.cart-chat-banner-arrow {
  font-size: 18px;
  color: var(--agent-brand);
  flex-shrink: 0;
}

/* ══════════════════════════════════════════════════════════════════════════════
   PARSING LOADING STATE
   ══════════════════════════════════════════════════════════════════════════ */

.chat-parse-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--surface, #fff);
  border: 1.5px solid var(--divider, rgba(0,0,0,.08));
  font-size: 13px;
  color: var(--text-3, #aaa);
  font-weight: 500;
}
.chat-parse-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--divider, rgba(0,0,0,.12));
  border-top-color: var(--agent-brand);
  animation: spin 700ms linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════════════════════════════════
   QUICK ACTIONS (hot commands)
   ══════════════════════════════════════════════════════════════════════════ */

.chat-quick-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;  /* never compress; all available space belongs to .chat-messages */
  padding: 8px 16px 0;
}
.chat-qa-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--divider, rgba(0,0,0,.12));
  color: var(--text-2, #555);
  background: var(--surface, #fff);
  cursor: pointer;
  white-space: nowrap;
  transition:
    transform    120ms var(--spring),
    border-color 120ms ease,
    background   120ms ease,
    color        120ms ease,
    box-shadow   120ms ease;
  -webkit-tap-highlight-color: transparent;
}
.chat-qa-btn:hover {
  border-color: var(--agent-brand);
  color: var(--agent-brand);
  background: color-mix(in srgb, #fff 92%, #ff5000 8%);
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(255,80,0,.12);
}
.chat-qa-btn:active { transform: scale(0.93); transition-duration: 70ms; }

/* ══════════════════════════════════════════════════════════════════════════════
   REDUCED MOTION
   ══════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ══════════════════════════════════════════════════════════════════════════════
   CHAT DATA CARDS (ORDER_STATUS / ORDERS_LIST / TRACKING)
   ══════════════════════════════════════════════════════════════════════════ */

.chat-data-card {
  background: var(--surface, #fff);
  border: 1.5px solid var(--divider, rgba(0,0,0,.08));
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  overflow: hidden;
  width: min(320px, 84vw);
  box-shadow: 0 2px 12px rgba(0,0,0,.07);
  transition: opacity 200ms ease, transform 320ms var(--spring-soft);
}
@starting-style {
  .chat-data-card {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
}

/* ── ORDER STATUS (.cos-*) ──────────────────────────────────────────────── */

.cos-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--divider, rgba(0,0,0,.07));
}
.cos-meta { flex: 1; min-width: 0; }
.cos-id {
  font-size: 12px;
  font-weight: 700;
  color: var(--text, #111);
  letter-spacing: -0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cos-date {
  font-size: 11px;
  color: var(--text-3, #aaa);
  margin-top: 1px;
}
.cos-status {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  background: color-mix(in srgb, #fff 88%, #ff5000 12%);
  color: var(--agent-brand);
  flex-shrink: 0;
  white-space: nowrap;
}

.cos-photos {
  display: flex;
  gap: 0;
  height: 80px;
  overflow: hidden;
}
.cos-photos img {
  flex: 1;
  width: 0;
  height: 100%;
  object-fit: cover;
  display: block;
  border-right: 2px solid var(--bg, #fafafa);
}
.cos-photos img:last-child { border-right: none; }

/* Payment + stage badges */
.cos-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.cos-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.cos-badge-ok {
  background: color-mix(in srgb, #fff 88%, #22c55e 12%);
  color: #16a34a;
  border: 1px solid rgba(34,197,94,.25);
}
.cos-badge-warn {
  background: color-mix(in srgb, #fff 88%, #f59e0b 12%);
  color: #d97706;
  border: 1px solid rgba(245,158,11,.25);
}
.cos-badge-stage {
  background: var(--bg, #f7f7f7);
  color: var(--text-2, #555);
  border: 1px solid var(--divider, rgba(0,0,0,.1));
}

/* Item stats */
.cos-stat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2, #555);
  margin-bottom: 3px;
}
.cos-stat-row.cos-stat-done { color: #16a34a; }
.cos-stat-ico { font-size: 14px; flex-shrink: 0; }

.cos-body {
  padding: 10px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cos-totals {
  font-size: 20px;
  font-weight: 800;
  color: var(--agent-brand);
  letter-spacing: -0.5px;
  line-height: 1.2;
}
.cos-totals span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3, #aaa);
  margin-left: 4px;
}
.cos-count {
  font-size: 12px;
  color: var(--text-3, #aaa);
}
.cos-event {
  font-size: 12px;
  color: var(--text-2, #555);
  background: var(--bg, #f7f7f7);
  border-radius: 8px;
  padding: 6px 10px;
  margin-top: 6px;
  line-height: 1.4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.cos-event-time {
  font-size: 11px;
  color: var(--text-3, #aaa);
  flex-shrink: 0;
}

.cos-actions {
  padding: 10px 14px 12px;
}
.cos-btn {
  width: 100%;
  padding: 10px;
  border-radius: 12px;
  background: var(--agent-brand);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(255,80,0,.22);
  transition: transform 100ms var(--snap-out), box-shadow 150ms ease;
}
.cos-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(255,80,0,.32); }
.cos-btn:active { transform: scale(0.95); transition-duration: 70ms; }

/* ── ORDERS LIST (.col-*) ───────────────────────────────────────────────── */

.col-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 14px 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text, #111);
  border-bottom: 1px solid var(--divider, rgba(0,0,0,.07));
}
.col-header span {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3, #aaa);
}

.col-list {
  overflow-y: auto;
  max-height: 260px;
  overscroll-behavior: contain;
}

.col-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 14px;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.col-row:not(:last-child) {
  border-bottom: 1px solid var(--divider, rgba(0,0,0,.05));
}
.col-row:hover { background: var(--bg, #f7f7f7); }
.col-row:active { background: color-mix(in srgb, #fff 88%, #ff5000 12%); }

.col-chevron {
  font-size: 20px;
  color: var(--text-3, #ccc);
  flex-shrink: 0;
  margin-left: auto;
  line-height: 1;
}

.col-photo {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: #f0f0f0;
}
.col-photo-empty {
  background: var(--bg, #f0f0f0);
  display: flex;
  align-items: center;
  justify-content: center;
}
.col-photo-empty::after { content: '📦'; font-size: 18px; }

.col-info { flex: 1; min-width: 0; }
.col-id {
  font-size: 12px;
  font-weight: 700;
  color: var(--text, #111);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-status {
  font-size: 11px;
  color: var(--text-3, #aaa);
  margin-top: 2px;
}

.col-right { flex-shrink: 0; text-align: right; }
.col-price {
  font-size: 13px;
  font-weight: 700;
  color: var(--agent-brand);
}
.col-date {
  font-size: 11px;
  color: var(--text-3, #aaa);
  margin-top: 2px;
}

.col-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--divider, rgba(0,0,0,.07));
}
.col-footer button {
  width: 100%;
  padding: 9px;
  border-radius: 12px;
  border: 1.5px solid var(--divider, rgba(0,0,0,.12));
  background: none;
  color: var(--text-2, #555);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease, transform 100ms var(--spring);
}
.col-footer button:hover { border-color: var(--agent-brand); color: var(--agent-brand); }
.col-footer button:active { transform: scale(0.96); }

/* ── TRACKING (.ctr-*) ──────────────────────────────────────────────────── */

.ctr-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 14px 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text, #111);
  border-bottom: 1px solid var(--divider, rgba(0,0,0,.07));
}
.ctr-header span {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3, #aaa);
}

.ctr-list {
  overflow-y: auto;
  max-height: 280px;
  overscroll-behavior: contain;
  padding: 4px 0;
}

.ctr-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
}
.ctr-row:not(:last-child) {
  border-bottom: 1px solid var(--divider, rgba(0,0,0,.05));
}

.ctr-photo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: #f0f0f0;
}
.ctr-photo-empty {
  background: var(--bg, #f0f0f0);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ctr-photo-empty::after { content: '📦'; font-size: 18px; }

.ctr-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ctr-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #111);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ctr-no {
  font-size: 11px;
  color: var(--text-3, #aaa);
  font-family: monospace;
  letter-spacing: 0.3px;
}
.ctr-status {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2, #555);
}
.ctr-event {
  font-size: 11px;
  color: var(--text-3, #aaa);
  line-height: 1.4;
}
