.chat-page {
  --chat-surface: #efeff0;
  --chat-card: #fff;
  --chat-ink: #202020;
  --chat-muted: #626267;
  --chat-line: #dedee1;
  --chat-online: #118449;
  width: min(100%, 690px);
  min-width: 0;
  margin-inline: auto;
  color: var(--chat-ink);
}

.chat-inbox { gap: 5px; }

.chat-inbox-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px 10px;
}
.chat-inbox-tools h1 {
  margin-inline-end: auto;
  font-size: 1.25rem;
}
.chat-inbox-tools input[type="search"] {
  min-width: 0;
  width: min(100%, 260px);
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--chat-line);
  border-radius: 99px;
  background: var(--chat-card);
  font-size: 1rem;
}

.chat-entries { display: grid; }
.chat-entry {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 68px;
  padding: 8px 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
}
.chat-entry:hover { background: #ffffff75; }
.chat-avatar,
.chat-portrait {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 42px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #dfdfe2;
  color: #37373a;
  font-weight: 700;
}
.chat-avatar img,
.chat-portrait img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}
.chat-avatar.official,
.chat-portrait.official {
  background: #272727;
  color: #fff;
}
.chat-presence {
  position: absolute;
  inset-inline-end: -1px;
  inset-block-end: -1px;
  width: 11px;
  height: 11px;
  border: 2px solid var(--chat-surface);
  border-radius: 50%;
  background: var(--chat-online);
}
.chat-entry-copy {
  display: grid;
  gap: 1px;
}
.chat-entry-copy > :is(strong, span) {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-entry-copy strong { font-size: .96rem; }
.chat-entry-copy > span {
  color: var(--chat-muted);
  font-size: .82rem;
}
.chat-entry-copy strong small {
  display: inline-block;
  padding: 1px 4px;
  border: 1px solid var(--chat-line);
  border-radius: 5px;
  color: var(--chat-muted);
  font-size: .65rem;
}
[data-chat-party="customer"] {
  --chat-party-ink: #194a7a;
  --chat-party-fill: #e9f3ff;
  --chat-party-line: #b3cbe9;
  --chat-party-edge: #5487bc;
}
[data-chat-party="companion"] {
  --chat-party-ink: #81410c;
  --chat-party-fill: #fff3e3;
  --chat-party-line: #e5c8a4;
  --chat-party-edge: #ae7634;
}
.chat-party-badge {
  display: inline-flex;
  align-items: center;
  flex: none;
  padding: 0 6px;
  border: 1px solid var(--chat-party-line);
  border-radius: 5px;
  background: var(--chat-party-fill);
  color: var(--chat-party-ink);
  font-size: .68rem;
  font-weight: 650;
  line-height: 1.55;
  white-space: nowrap;
}
.chat-entry[data-chat-party] {
  padding-inline-start: 10px;
  box-shadow: inset 3px 0 var(--chat-party-edge);
}
.chat-entry[data-chat-party]:hover { background: var(--chat-party-fill); }
.chat-entry-copy > .chat-entry-title {
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-entry-title > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-entry-aside {
  display: grid;
  align-content: center;
  justify-items: end;
  gap: 4px;
  color: var(--chat-muted);
  font-size: .72rem;
}
.chat-unread {
  display: grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  padding-inline: 4px;
  border-radius: 9px;
  background: #c52543;
  color: white;
  font-size: .65rem;
  font-weight: 680;
}

.chat-room {
  display: flex;
  flex-direction: column;
  height: min(calc(100dvh - 125px), 780px);
  min-height: 450px;
  overflow: hidden;
  border: 1px solid var(--chat-line);
  border-radius: 18px;
  background: var(--chat-surface);
}

.chat-title {
  display: grid;
  grid-template-columns: minmax(54px, 1fr) minmax(0, 3fr) minmax(54px, 1fr);
  align-items: center;
  flex-shrink: 0;
  min-height: 56px;
  padding: 4px 8px;
}
.chat-title > :first-child { justify-self: start; }
.chat-title-copy {
  grid-column: 2;
  display: grid;
  gap: 2px;
  text-align: center;
}
.chat-title h1 {
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-title-copy small {
  color: var(--chat-muted);
  font-size: .72rem;
}
.chat-title-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.chat-online {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
}
.chat-online::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-online);
}
.chat-profile-action {
  grid-column: 3;
  justify-self: end;
  min-height: 30px;
  padding: 3px 9px;
  border: 1px solid #6892c4;
  border-radius: 99px;
  background: transparent;
  color: #2d5988;
  font-size: .75rem;
}

.chat-context {
  display: grid;
  gap: 8px;
  flex-shrink: 0;
  padding: 0 11px 5px;
}
.chat-profile-card,
.chat-product-card {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: var(--chat-card);
  text-align: start;
}
.chat-context :is(.chat-profile-card, .chat-product-card) > img {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  object-fit: cover;
}
.chat-context :is(strong, small) { overflow-wrap: anywhere; }
.chat-context :is(.chat-profile-card, .chat-product-card) strong { font-size: .88rem; }
.chat-context :is(.chat-profile-card, .chat-product-card) small { color: var(--chat-muted); }
.chat-profile-card[data-chat-party] {
  border-inline-start: 3px solid var(--chat-party-edge);
  background: var(--chat-party-fill);
}
.chat-profile-card[data-chat-party] > div { min-width: 0; }
.chat-profile-card[data-chat-party] .chat-party-badge { margin-inline-start: auto; }
.chat-context :is(.chat-profile-card, .chat-product-card) .button {
  min-height: 32px;
  margin-inline-start: auto;
  padding: 4px 12px;
  border-radius: 8px;
  font-size: .75rem;
  white-space: nowrap;
}

.chat-log {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: stretch;
  gap: 11px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 10px 11px 16px;
  overflow-anchor: auto;
}
.chat-log .empty-state {
  width: 100%;
  border: 0;
  background: transparent;
  padding-block: 20px;
}
.chat-time {
  align-self: center;
  padding: 0 7px;
  border-radius: 6px;
  background: #ffffffa6;
  color: var(--chat-muted);
  font-size: .72rem;
}
.chat-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.chat-row.mine {
  flex-direction: row-reverse;
}
.chat-portrait {
  width: 33px;
  margin-top: 2px;
  font-size: .78rem;
}
.chat-portrait svg { width: 17px; }
.chat-bubble {
  display: grid;
  gap: 4px;
  min-width: 0;
  max-width: min(84%, 430px);
  overflow-wrap: anywhere;
}
.chat-bubble.mine { text-align: end; }
.chat-bubble > small {
  color: var(--chat-muted);
  font-size: .7rem;
}
.chat-bubble > p {
  padding: 7px 10px;
  border-radius: 3px 10px 10px;
  background: var(--chat-card);
  font-size: .91rem;
  white-space: pre-wrap;
}
.chat-bubble.mine > p {
  border-radius: 10px 3px 10px 10px;
  background: #e2e7e4;
  text-align: start;
}
.chat-row[data-chat-party] .chat-bubble > :is(p, .button),
.chat-row[data-chat-party] .chat-bubble:has(.chat-receipt) {
  border-color: var(--chat-party-line);
  background: var(--chat-party-fill);
}
.chat-row[data-chat-party] .chat-portrait {
  background: var(--chat-party-fill);
  color: var(--chat-party-ink);
}
.chat-event {
  align-self: center;
  color: var(--chat-muted);
  font-size: .83rem;
  text-align: center;
}
.chat-event small { font-size: .72rem; }

.chat-receipt {
  display: grid;
  gap: 7px;
  width: min(100%, 350px);
  padding: 8px;
  border: 1px solid #e7e7e9;
  border-radius: 8px;
  background: var(--chat-card);
}
.chat-bubble:has(.chat-receipt) {
  width: min(84%, 350px);
  padding: 6px;
  border-radius: 3px 10px 10px;
  background: var(--chat-card);
}
.chat-bubble.mine:has(.chat-receipt) { border-radius: 10px 3px 10px 10px; }
.chat-receipt-body {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: start;
}
.chat-receipt-body > img {
  width: 67px;
  height: 67px;
  flex: 0 0 67px;
  border-radius: 6px;
  object-fit: cover;
}
.chat-receipt-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
  flex: 1;
}
.chat-receipt-body strong {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 5px;
  font-size: .9rem;
}
.chat-receipt-body small,
.receipt-status {
  color: var(--chat-muted);
  font-size: .75rem;
}
.chat-receipt-price { color: #9b522e; }
.chat-receipt .button {
  justify-self: start;
  min-height: 33px;
  padding: 4px 9px;
  font-size: .75rem;
}

.chat-order-picker {
  --chat-muted: var(--muted);
  --chat-surface: var(--surface);
  display: grid;
  gap: 14px;
}
.chat-order-picker-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.chat-order-picker-list > li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.chat-order-picker-list > li > small { grid-column: 1 / -1; font-size: .75rem; }
.chat-order-picker-list .chat-receipt-body { align-items: center; min-height: 44px; overflow-wrap: anywhere; }
.chat-order-picker-list .chat-receipt-body > img { width: 42px; height: 42px; flex-basis: 42px; }
.chat-order-picker-list .chat-order-arrow { display: inline-flex; }
.chat-order-picker-list [data-action="chat-send-order"] { min-height: 44px; padding-inline: 10px; font-size: .81rem; white-space: nowrap; }

.chat-compose {
  display: grid;
  flex-shrink: 0;
  gap: 6px;
  padding: 7px 11px 8px;
  border-top: 1px solid var(--chat-line);
  background: #f7f7f8;
}
.chat-composer-bar {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  min-width: 0;
}
.chat-composer-bar :is(.chat-voice-toggle, .chat-emoji-toggle, .chat-more-toggle) {
  display: grid;
  place-items: center;
  flex: 0 0 40px;
  width: 40px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 13px;
  color: var(--chat-ink);
  background: transparent;
}
.chat-composer-bar :is(.chat-voice-toggle, .chat-emoji-toggle, .chat-more-toggle):hover,
.chat-composer-bar :is([aria-expanded="true"], [aria-pressed="true"]) {
  background: #e7e7ea;
}
.chat-input-field,
.chat-record-button {
  display: block;
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  min-height: 42px;
  margin: 0;
  border: 1px solid #e2e2e5;
  border-radius: 13px;
  background: var(--chat-card);
  color: var(--chat-ink);
}
.chat-input-field {
  max-height: 112px;
  padding: 9px 11px;
  overflow-y: auto;
  resize: none;
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
}
.chat-input-field::placeholder { color: #77777b; }
.chat-input-field:focus-visible { border-color: #77777b; outline: none; }
.chat-record-button {
  padding: 6px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  font-size: .92rem;
  font-weight: 650;
}
.chat-record-button[aria-pressed="true"] {
  border-color: #9e2249;
  background: #f9e8ef;
  color: #81223e;
}
.chat-composer-bar .chat-send {
  flex: 0 0 auto;
  min-width: 54px;
  min-height: 40px;
  margin-block: 1px;
  padding: 6px 11px;
  border: 0;
  border-radius: 12px;
  background: #252527;
  color: white;
  font-size: .9rem;
  font-weight: 650;
}
.chat-send:disabled { opacity: .45; }
.chat-quick-menu,
.chat-tools {
  min-width: 0;
  max-height: min(28vh, 180px);
  overflow-y: auto;
  padding: 9px 2px 2px;
}
.chat-quick-menu {
  display: grid;
  gap: 9px;
}
.chat-tools {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 5px 10px;
}
.chat-tools > :is(label, button) {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 5px;
  min-height: 60px;
  padding: 3px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--chat-muted);
  font-size: .72rem;
  cursor: pointer;
}
.chat-tools > :is(label, button) svg {
  box-sizing: content-box;
  padding: 8px;
  border: 1px solid var(--chat-line);
  border-radius: 11px;
  background: var(--chat-card);
  color: var(--chat-ink);
}
.chat-tools > :is(label, button):hover { background: #e9e9ec; }
.chat-tools label input {
  position: absolute;
  inset: 0;
  width: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.chat-tools label:focus-within { outline: 2px solid var(--chat-ink); }
.chat-chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
}
.chat-chips button {
  min-height: 34px;
  padding: 4px 8px;
  border: 1px solid var(--chat-line);
  border-radius: 99px;
  background: var(--chat-card);
  color: var(--chat-ink);
  font-size: .73rem;
}
.chat-quick-menu [data-action="chat-emoji"] {
  border-radius: 10px;
  font-size: 1.16rem;
}
.chat-attachment {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 1px 3px 1px 9px;
  border: 1px solid var(--chat-line);
  border-radius: 10px;
  background: var(--chat-card);
}
.chat-attachment [data-compose-note] {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-attachment button {
  flex-shrink: 0;
  min-height: 33px;
  padding: 3px 6px;
  border: 0;
  background: transparent;
  color: var(--chat-muted);
  font-size: .8rem;
}
.chat-compose small {
  color: var(--chat-muted);
  font-size: .72rem;
}
.chat-faq,
.chat-review,
.chat-login { padding: 10px 14px; }
.chat-room > .chat-faq {
  flex-shrink: 0;
  max-height: 124px;
  overflow-y: auto;
  padding-block: 4px;
  color: var(--chat-muted);
  font-size: .78rem;
}
.chat-faq details,
.chat-review article { padding-block: 7px; }
.chat-review,
.chat-login {
  border: 1px solid var(--chat-line);
  border-radius: 18px;
  background: var(--chat-card);
}
.chat-review p {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-page :is(.chat-bubble, .chat-review) > :is(img, video, audio),
.chat-review article > :is(img, video, audio) {
  width: min(100%, 280px);
  max-height: 230px;
  object-fit: contain;
}

@media (max-width: 700px) {
  body:is(.customer-shell, .staff-portal):has(.chat-room) {
    overflow: hidden;
    overscroll-behavior: none;
  }
  :is(.customer-shell, .staff-portal):has(.chat-room) :is(.app-header, .bottom-nav) { display: none; }
  :is(.customer-shell, .staff-portal):has(.chat-room) .app-main {
    width: 100%;
    min-height: 0;
    padding: 0;
  }
  :is(.customer-shell, .staff-portal) .chat-room {
    height: 100vh;
    height: var(--chat-visible-height, 100dvh);
    min-height: 0;
    border: 0;
    border-radius: 0;
  }
  :is(.customer-shell, .staff-portal) .chat-title {
    padding-top: max(4px, env(safe-area-inset-top));
  }
  :is(.customer-shell, .staff-portal) .chat-compose {
    padding-bottom: max(7px, env(safe-area-inset-bottom));
  }
  :is(.customer-shell, .staff-portal) .chat-room[data-keyboard-open] .chat-compose { padding-bottom: 5px; }
  :is(.customer-shell, .staff-portal) .chat-room[data-keyboard-open] .chat-context {
    max-height: 32%;
    overflow-y: auto;
  }
  :is(.customer-shell, .staff-portal):has(.chat-room) .notice {
    bottom: calc(71px + env(safe-area-inset-bottom));
  }
  .chat-inbox-tools { min-height: 42px; }
}

.chat-back {
  width: auto;
  gap: 2px;
  grid-auto-flow: column;
  justify-content: start;
}
.chat-back svg { transform: rotate(180deg); }
.chat-back small { font-size: .72rem; }
.chat-profile-card > div,
.chat-product-card > div { display: grid; gap: 2px; }
.chat-official-badge { font-size: .71rem; color: #316bb0; }
.chat-order-arrow { color: var(--chat-muted); }
.chat-receipt-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--chat-surface);
}
.chat-start { position: relative; }
.chat-start > summary { list-style: none; cursor: pointer; }
.chat-start > summary::-webkit-details-marker { display: none; }
.chat-start .chat-chips {
  position: absolute;
  z-index: 5;
  inset-inline-end: 0;
  width: 176px;
  padding: 9px;
  background: white;
  border: 1px solid var(--chat-line);
  border-radius: 12px;
}
.chat-context .chat-faq {
  max-height: 120px;
  overflow-y: auto;
  padding: 3px 7px;
  color: var(--chat-muted);
  font-size: .78rem;
}
.chat-order-row .chat-bubble { gap: 0; }
.chat-order-row .chat-bubble > p { border-radius: 8px 8px 0 0; font-size: .79rem; }
.chat-order-row .chat-receipt { border-start-start-radius: 0; border-start-end-radius: 0; }

.chat-page :is(.chat-entry, .chat-chips button, .chat-tools > :is(label, button)):active {
  background: #e7e7ea;
}
.chat-composer-bar .chat-send:active:not(:disabled) { background: #414145; }

@media (prefers-reduced-motion: no-preference) {
  .chat-page :is(.chat-entry, .chat-composer-bar button, .chat-chips button, .chat-tools > :is(label, button)) {
    transition: background-color 150ms ease-out, color 150ms ease-out, transform 135ms ease-out;
  }
  .chat-entry:active { transform: scale(.992); }
  .chat-page :is(.chat-composer-bar button, .chat-chips button, .chat-tools > :is(label, button)):active:not(:disabled) {
    transform: scale(.96);
  }
  .chat-more-toggle svg { transition: transform 160ms cubic-bezier(.2,.7,.3,1); }
  .chat-more-toggle[aria-expanded="true"] svg { transform: rotate(45deg); }
  .chat-page :is(.chat-attachment, .chat-quick-menu, .chat-tools, .chat-send):not([hidden]),
  .chat-start[open] .chat-chips {
    animation: chat-panel-reveal 165ms cubic-bezier(.2,.7,.3,1);
  }
  @keyframes chat-panel-reveal {
    from { opacity: .55; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

.chat-earlier {display:block;margin:4px auto 12px}
.chat-archive {background:#f4f4f4;border-radius:14px;padding:12px;min-width:0}
