/* Shared customer and merchant messaging; scoped to preserve menu layouts. */
.topbar-chat { position: relative; flex: none; color: var(--ink-700); }
.topbar-chat .nav-count { position: absolute; top: 0; right: -3px; }
.messages-page { max-width: 960px; margin-inline: auto; }
.messages-page .page-head > div { min-width: 0; }
.messages-page .page-head p { overflow-wrap: anywhere; }
.messages-page .page-head > .button { flex: none; }
.chat-order-entry { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.chat-order-entry small { color: var(--ink-600); font-size: var(--text-xs); }
.links-card button[data-open-chat] { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 16px; color: var(--ink-900); border: 0; border-bottom: 1px solid var(--line-200); background: transparent; text-align: left; }
.links-card button[data-open-chat]:hover { background: var(--paper-100); }
.links-card button[data-open-chat] > .icon:last-child { margin-left: auto; color: var(--ink-400); }
.menu-layout.variant-b .services .menu-chat-entry { display: flex; }
.menu-layout.variant-b .menu-chat-entry .button { min-height: 44px; white-space: normal; text-align: left; }
.menu-layout.variant-b .menu-chat-entry .icon { margin: 0; }
.chat-dialog { --chat-control: 44px; --chat-gap: 8px; --chat-input-max: 132px; --chat-avatar: 32px; height: min(760px, calc(var(--chat-viewport-height, 100dvh) - 48px)); }
.chat-dialog .chat-back-icon { display: none; }
.chat-dialog .chat-inbox-link { flex: none; min-width: var(--chat-control); text-decoration: none; font-size: var(--text-sm); gap: 6px; }
.chat-dialog .dialog-head h2 { line-height: 1.35; }
.chat-dialog .dialog-body { display: flex; flex-direction: column; padding: 0; overflow: hidden; gap: 0; }
.chat-panel { display: grid; grid-template-rows: auto minmax(44px, 1fr) minmax(44px, auto); flex: 1; min-height: 0; min-width: 0; }
.chat-connection { padding: 10px 20px; border-bottom: 1px solid var(--line-200); color: var(--ink-600); font-size: var(--text-xs); line-height: 1.5; background: var(--paper-50); }
.chat-messages { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 20px; background: var(--paper-100); scrollbar-gutter: stable; }
.chat-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 160px; padding: 24px; text-align: center; color: var(--ink-600); }
.chat-empty > .icon { width: 32px; height: 32px; color: var(--ink-400); }
.chat-empty strong { color: var(--ink-700); font-size: var(--text-lg); }
.chat-empty p { max-width: 360px; font-size: var(--text-base); line-height: 1.6; }
.chat-message { display: grid; grid-template-columns: var(--chat-avatar) minmax(0, 1fr); grid-template-areas: "avatar meta" "avatar bubble"; gap: 4px var(--chat-gap); margin: 0 0 20px; min-width: 0; }
.chat-message.is-mine { grid-template-columns: minmax(0, 1fr) var(--chat-avatar); grid-template-areas: "meta avatar" "bubble avatar"; }
.chat-message-avatar { grid-area: avatar; display: grid; place-items: center; width: var(--chat-avatar); height: var(--chat-avatar); border-radius: var(--radius); color: var(--brand-700); background: var(--brand-50); }
.is-mine .chat-message-avatar { color: var(--ink-700); background: var(--paper-200); }
.chat-message-meta { grid-area: meta; display: flex; flex-wrap: wrap; gap: var(--chat-gap); color: var(--ink-600); font-size: var(--text-2xs); line-height: 1.5; }
.is-mine .chat-message-meta { justify-content: flex-end; }
.chat-bubble { grid-area: bubble; justify-self: start; width: max-content; max-width: 100%; min-width: 0; padding: 10px 13px; background: var(--paper-50); border: 1px solid var(--line-200); border-radius: 2px 12px 12px; }
.is-mine .chat-bubble { justify-self: end; }
.is-mine .chat-bubble { background: var(--brand-50); border-color: var(--brand-100); border-radius: 12px 2px 12px 12px; }
.chat-message-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.65; font-size: var(--text-base); }
.chat-image-link { display: block; max-width: 280px; border-radius: 6px; overflow: hidden; }
.chat-image-link img { display: block; width: auto; height: auto; max-width: 100%; max-height: min(320px, 45dvh); object-fit: contain; }
.chat-image-link + .chat-message-text, .chat-order-card + .chat-message-text, .chat-order-card + .chat-image-link { margin-top: 8px; }
.chat-image-failed { display: block; min-height: 44px; padding: 12px 0; font-size: var(--text-xs); }
.chat-order-card { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 10px; border: 1px solid var(--line-200); border-radius: var(--radius-sm); background: var(--paper-50); }
.chat-order-card > .icon { color: var(--brand-600); }
.chat-order-card > span { display: grid; gap: 3px; min-width: 0; flex: 1; overflow-wrap: anywhere; }
.chat-order-card strong { font-size: var(--text-sm); }
.chat-order-card small { color: var(--ink-600); font-size: var(--text-xs); }
.chat-order-card .text-button { font-size: var(--text-xs); flex: none; }
.chat-more { display: flex; justify-content: center; padding: 4px 0 12px; }
.chat-load-error { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--brand-700); font-size: var(--text-sm); }
.chat-composer { container-type: inline-size; container-name: chat-composer; padding: 12px 20px 14px; border-top: 1px solid var(--line-200); background: var(--paper-50); display: grid; gap: 8px; min-height: 0; min-width: 0; max-height: 65dvh; overflow-y: auto; }
.chat-input-row { display: flex; align-items: flex-end; gap: var(--chat-gap); min-width: 0; }
.chat-composer textarea { flex: 1; min-width: 0; resize: none; min-height: max(var(--chat-control), calc(1.5em + 20px)); max-height: var(--chat-input-max); font-size: var(--text-lg); line-height: 1.5; padding: 9px 12px; }
.chat-input-row > .button { flex: none; min-height: var(--chat-control); padding-inline: 14px; }
.chat-input-row > .icon-button { border-radius: var(--radius-full, 50%); }
.chat-input-row > .icon-button[aria-expanded="true"] { color: var(--brand-700); background: var(--brand-50); border-color: var(--brand-100); }
.chat-tools { display: flex; align-items: center; gap: 16px; padding: var(--chat-gap) 0; }
.chat-tools > p { max-width: 32ch; color: var(--ink-600); font-size: var(--text-xs); line-height: 1.5; }
.chat-composer-meta { display: flex; align-items: flex-start; gap: var(--chat-gap); }
.chat-composer-meta > small { flex: none; color: var(--ink-600); font-size: var(--text-2xs); margin-left: auto; }
.chat-upload { position: relative; overflow: hidden; cursor: pointer; min-width: 76px; min-height: 72px; display: flex; flex: none; flex-direction: column; gap: var(--chat-gap); }
.chat-upload > .icon { width: 24px; height: 24px; }
.chat-upload input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.chat-upload:has(input:focus-visible) { outline: 2px solid var(--brand-600); outline-offset: 2px; }
.chat-upload:has(input:disabled) { opacity: .55; cursor: default; }
.chat-composer-note { color: var(--ink-600); font-size: var(--text-2xs); line-height: 1.4; }
.chat-attachments { display: grid; gap: 8px; }
.chat-attachments:empty, .chat-send-error:empty { display: none; }
.chat-attachment { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border: 1px solid var(--line-200); border-radius: var(--radius-sm); color: var(--ink-600); font-size: var(--text-xs); }
.chat-attachment img { width: 48px; height: 48px; object-fit: cover; border-radius: 4px; }
.chat-attachment > span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
@container chat-composer (max-width: 17rem) {
  .chat-input-row { flex-wrap: wrap; }
  .chat-input-row textarea { flex-basis: calc(100% - var(--chat-control) - var(--chat-gap)); }
  .chat-input-row > [data-chat-send] { margin-left: auto; }
  .chat-tools { flex-wrap: wrap; }
}
.chat-send-error { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; color: var(--brand-700); font-size: var(--text-sm); }
.chat-inbox { overflow: hidden; }
.chat-inbox-error { padding: 12px 20px; border-bottom: 1px solid var(--line-200); }
.chat-conversations { display: grid; }
.chat-conversation { width: 100%; display: flex; align-items: center; gap: 14px; min-height: 86px; padding: 16px 20px; border: 0; border-bottom: 1px solid var(--line-200); background: var(--paper-50); text-align: left; color: var(--ink-900); }
.chat-conversation:last-child { border-bottom: 0; }
.chat-conversation:hover { background: var(--paper-50); }
.chat-conversation.has-unread { background: var(--brand-50); }
.chat-conversation:focus-visible { outline-offset: -3px; }
.chat-avatar { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--paper-200); color: var(--ink-700); }
.chat-conversation-copy { display: grid; gap: 5px; min-width: 0; flex: 1; }
.chat-conversation-copy strong { font-size: var(--text-base); overflow-wrap: anywhere; }
.chat-conversation-copy > span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: var(--text-sm); color: var(--ink-600); }
.chat-conversation-meta { display: grid; justify-items: end; gap: 8px; color: var(--ink-600); font-size: var(--text-2xs); flex: none; }
@media (max-width: 767px) {
  html:has(dialog.chat-dialog:modal) { scrollbar-gutter: auto; }
  .customer-app .header-end { gap: 2px; }
  .customer-app .site-header .container { gap: 8px; }
  .menu-layout.variant-b .services .menu-chat-entry { display: none; }
  .menu-layout.variant-b .menu-chat-entry .button { font-size: var(--text-2xs); padding: 4px 8px; max-width: 160px; }
  dialog.chat-dialog { inset: var(--chat-viewport-top, 0px) 0 auto; width: 100vw; height: var(--chat-viewport-height, 100dvh); max-height: var(--chat-viewport-height, 100dvh); margin: 0; border: 0; border-radius: 0; }
  .chat-dialog .dialog-head { padding-top: max(8px, env(safe-area-inset-top)); }
  .chat-dialog .dialog-head { padding-left: 8px; gap: var(--chat-gap); }
  .chat-dialog .dialog-head h2 { font-size: var(--text-lg); }
  .chat-dialog .dialog-head .close { order: -1; margin-left: 0; }
  .chat-dialog .chat-back-icon { display: block; }
  .chat-dialog .chat-close-icon { display: none; }
  .chat-dialog .chat-inbox-link { padding-inline: 8px; }
  .chat-dialog .chat-inbox-link > .icon { display: none; }
  .chat-connection { padding: 8px 14px; }
  .chat-messages { padding: 12px 14px; }
  .chat-bubble { max-width: 100%; }
  .chat-bubble .chat-order-card { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 4px var(--chat-gap); }
  .chat-bubble .chat-order-card > .icon { align-self: start; margin-top: 2px; }
  .chat-bubble .chat-order-card > .text-button { grid-column: 2; justify-self: start; }
  .chat-composer { padding: 10px 14px max(10px, env(safe-area-inset-bottom)); }
  .chat-conversation { padding: 14px 12px; gap: 10px; }
  .chat-conversation-meta time { max-width: 82px; text-align: right; line-height: 1.4; }
}
@media (prefers-reduced-motion: reduce) { .chat-dialog[open] { animation: none; } }

/* Distinguishing names remain fully readable on compact screens. */
.chat-conversation-copy strong { white-space: normal; overflow-wrap: anywhere; overflow: visible; }
.chat-customer-reference { color: var(--ink-600); font-size: var(--text-xs); overflow-wrap: anywhere; }
.chat-dialog .dialog-head h2, .chat-message-meta > span { overflow-wrap: anywhere; }
