/*
 * The chat inside the widget's iframe (app/views/widget/frames/show.html.erb).
 * Its own small stylesheet, not the app's Tailwind build: this page loads
 * on other people's sites, and should weigh a few kilobytes.
 * --widget-color is the product's (the layout sets it).
 */
:root {
  --widget-color: #4f46e5;
  --widget-ink: #111827;
  --widget-muted: #6b7280;
  --widget-line: #e5e7eb;
  --widget-surface: #f3f4f6;
  --widget-danger: #b91c1c;
  --widget-radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--widget-ink);
  background: #fff;
}

[hidden] { display: none !important; }

.chat { display: flex; flex-direction: column; height: 100%; }

.chat__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 16px 14px; color: #fff; background: var(--widget-color);
}
.chat__title { margin: 0; font-size: 16px; font-weight: 600; }
.chat__status { margin: 2px 0 0; font-size: 13px; opacity: .9; }
.chat__close {
  display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0;
  color: inherit; background: transparent; border: 0; border-radius: 8px; cursor: pointer;
}
.chat__close:hover { background: rgb(255 255 255 / .16); }
.chat__close svg, .chat__button svg { width: 20px; height: 20px; fill: currentColor; }

.chat__closed { margin: 0; padding: 10px 16px; font-size: 13px; color: #374151; background: #f3f4f6; border-bottom: 1px solid #e5e7eb; }
.chat__away { margin: 0; padding: 10px 16px; font-size: 13px; color: #92400e; background: #fffbeb; border-bottom: 1px solid #fde68a; }

.chat__log {
  flex: 1; min-height: 0; margin: 0; padding: 16px; overflow-y: auto; list-style: none;
  display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain;
}
.chat__message { max-width: 84%; }
.chat__message p {
  margin: 0; padding: 9px 12px; border-radius: var(--widget-radius);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.chat__message small { display: block; margin: 3px 4px 0; font-size: 11px; color: var(--widget-muted); }
.chat__message--team { align-self: flex-start; }
.chat__message--team p { background: var(--widget-surface); border-bottom-left-radius: 4px; }
.chat__message--visitor { align-self: flex-end; }
.chat__message--visitor p { color: #fff; background: var(--widget-color); border-bottom-right-radius: 4px; }
.chat__message--visitor small { text-align: right; }
.chat__message--pending p { opacity: .65; }
.chat__message--failed p { background: var(--widget-danger); }
.chat__message button {
  padding: 0; font: inherit; font-size: 11px; color: var(--widget-danger); text-decoration: underline;
  background: none; border: 0; cursor: pointer;
}

.chat__email { padding: 12px 16px; background: var(--widget-surface); border-top: 1px solid var(--widget-line); }
.chat__email label { display: block; margin-bottom: 8px; font-size: 13px; }
.chat__row { display: flex; gap: 8px; }
.chat__email input {
  flex: 1; min-width: 0; padding: 8px 10px; font: inherit; color: inherit;
  background: #fff; border: 1px solid #d1d5db; border-radius: 8px;
}
.chat__error { margin: 6px 0 0; font-size: 12px; color: var(--widget-danger); }

.chat__composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--widget-line); }
.chat__composer textarea {
  flex: 1; min-width: 0; max-height: 120px; padding: 9px 12px; font: inherit; color: inherit; resize: none;
  background: var(--widget-surface); border: 1px solid transparent; border-radius: var(--widget-radius);
}
.chat__button {
  padding: 8px 12px; font: inherit; font-weight: 600; color: #fff; background: var(--widget-color);
  border: 0; border-radius: 8px; cursor: pointer;
}
.chat__button--send { display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0; border-radius: 50%; }
.chat__button:disabled { opacity: .5; cursor: default; }

.chat :focus-visible { outline: 2px solid var(--widget-color); outline-offset: 2px; }
.chat__head :focus-visible { outline-color: #fff; }

.chat__foot { padding: 6px 12px 10px; font-size: 11px; text-align: center; }
.chat__foot a { color: var(--widget-muted); text-decoration: none; }
.chat__foot a:hover { text-decoration: underline; }

.chat__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (prefers-reduced-motion: no-preference) {
  .chat__log { scroll-behavior: smooth; }
  .chat__message { animation: chat-in .16s ease-out; }
  @keyframes chat-in { from { opacity: 0; transform: translateY(4px); } }
}
