.chat-image-thumb {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 0;
  border: 1px solid var(--line, #ccc);
  border-radius: 10px;
  overflow: hidden;
  background: var(--cream, #eee);
  cursor: zoom-in;
}
.chat-image-thumb img {
  display: block;
  width: 160px;
  height: 112px;
  object-fit: contain;
}
.chat-image-viewer {
  width: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 60px 12px 12px;
  border: 0;
  background: #111;
}
.chat-image-viewer img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.chat-image-viewer button {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid #fff6;
  border-radius: 10px;
  background: #222;
  color: #fff;
}
.chat-file-input {
  display: block;
  width: 100%;
  margin: 4px 0 8px;
}

.chat-survey {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100dvh - 32px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
}
.chat-survey::backdrop { background: #0008; }
.chat-survey h2 { font-size: 1.65rem; margin-bottom: 14px; }
.chat-survey form > label, .offline-chat-contact > label { display: grid; gap: 5px; margin-block: 12px; }
.chat-survey form > label :is(input, textarea), .offline-chat-contact input {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}
.chat-survey legend { font-size: 1rem; }
.chat-survey-stars { display: flex; gap: 4px; }
.chat-survey-stars label { position: relative; }
.chat-survey-stars input { position: absolute; opacity: 0; }
.chat-survey-stars span {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 1.7rem;
  cursor: pointer;
}
.chat-survey-stars .selected span { color: #a96600; }
.chat-survey-stars input:focus-visible + span { outline: 2px solid var(--wine); }
.chat-survey form > button { margin: 6px 8px 0 0; }

.chat-emoji-picker { margin-block: 6px; }
.chat-emoji-picker > summary {
  width: fit-content;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  list-style: none;
  cursor: pointer;
}
.chat-emoji-picker > summary::after { content: none; }
.chat-emoji-grid { display: grid; grid-template-columns: repeat(6, 36px); gap: 4px; margin-top: 5px; }
.chat-emoji-grid button {
  padding: 0;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  font-size: 1.15rem;
}
.chat-emoji-grid button:hover { background: var(--cream); }
.chat-color-emoji {
  display: inline-block;
  width: 1.2em;
  height: 1.2em;
  vertical-align: -.2em;
  object-fit: contain;
}
.chat-emoji-credit { display: inline-block; margin-top: 4px; font-size: .7rem; }
.visitor-thread-history span {
  font-family: system-ui, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

.visitor-chat-toolbar {
  display: flex;
  align-items: start;
  flex-wrap: wrap;
  gap: 8px;
}
.visitor-chat-toolbar .chat-emoji-picker { margin: 0; }
.visitor-chat-toolbar .chat-emoji-picker > summary,
.chat-attachment-toggle {
  display: grid;
  place-items: center;
  min-height: 46px;
}
.chat-attachment-toggle {
  min-width: 46px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}
.chat-attachment-toggle:hover,
.chat-attachment-toggle[aria-expanded="true"] { background: var(--cream); }
.visitor-chat-files { margin-top: 10px; }

.offline-chat-trigger {
  position: fixed;
  inset: auto auto max(16px, env(safe-area-inset-bottom)) 16px;
  z-index: 850;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 6px 20px #0002;
  font-size: .875rem;
}
.offline-chat-dialog button[type="submit"] { gap: 8px; }
.offline-chat-dialog button[type="submit"]:disabled {
  cursor: wait;
  opacity: .8;
}
.offline-send-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-inline-end-color: transparent;
  border-radius: 50%;
  animation: offline-send-spin .75s linear infinite;
}
@keyframes offline-send-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .offline-send-spinner { animation: none; }
}

.offline-chat-trigger[hidden] { display: none; }
.offline-chat-trigger.is-online { color: #167244; }
[data-bs-theme="dark"] .offline-chat-trigger.is-online { color: #79e6a7; }
.offline-chat-dialog input[type="checkbox"] { width: auto; }

.chat-message-actions { display: inline-flex; flex-wrap: wrap; gap: .5rem; vertical-align: middle; }
.chat-message-action {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  min-height: 36px;
  border: 0;
  border-radius: .3rem;
  color: inherit;
  background: transparent;
  cursor: pointer;
}
.chat-message-action:hover, .chat-message-action:focus-visible { background: #8882; }
@media (pointer: coarse) {
  .chat-message-action { min-width: 44px; min-height: 44px; }
}
.chat-quote {
  display: block;
  max-width: 100%;
  margin: .2rem 0;
  padding: .2rem .45rem;
  border: 0;
  border-inline-start: 2px solid currentColor;
  background: #8881;
  color: inherit;
  opacity: .72;
  text-align: start;
  font-size: .85em;
  overflow-wrap: anywhere;
}
button.chat-quote { cursor: pointer; }
[data-chat-line]:focus { outline: 2px solid currentColor; outline-offset: -2px; }
