.chat-panel {
  --chat-blue: #1555ef;
  --chat-line: #dce2eb;
  position: fixed;
  z-index: 68;
  right: 96px;
  bottom: min(90px, 8vh);
  width: min(400px, calc(100vw - 110px));
  height: min(550px, 86dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--chat-line);
  border-radius: 16px;
  background: white;
  color: #182337;
  box-shadow: 0 18px 64px rgba(17, 39, 75, .19);
  font-size: 15px;
  line-height: 1.5;
}
.chat-panel[data-expanded=true] { width: min(740px, calc(100vw - 110px)); height: min(700px, 88dvh); }
.chat-panel[hidden], .chat-panel [hidden] { display: none !important; }
.chat-panel button { font: inherit; cursor: pointer; border: 0; background: transparent; color: inherit; }
.chat-panel button:disabled { cursor: default; }
.chat-panel svg { width: 21px; height: 21px; fill: currentColor; }
.chat-panel :is(button,a,input):focus-visible, .chat-messages:focus-visible { outline: 2px solid var(--chat-blue); outline-offset: -2px; }
.chat-head, .chat-actions, .chat-consent, .chat-foot, .chat-preview { display: flex; align-items: center; }
.chat-head { padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--chat-line); gap: 8px; }
.chat-brand { border-radius: 50%; }
.chat-panel[data-expanded=true] .chat-brand { border-radius: 8px; }
.chat-title { flex: 1; }
.chat-head button, .chat-actions > button:not(.chat-send) { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 8px; }
.chat-head button:hover, .chat-actions > button:not(.chat-send):hover, .chat-emojis button:hover { background: #eef3fd; }
.chat-note { margin: 10px 16px 0; display: flex; align-items: center; gap: 8px; color: #617085; text-align: center; font-size: 12px; }
.chat-note::before, .chat-note::after { content: ''; flex: 1; border-top: 1px solid #e6eaf0; }
.chat-messages { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 16px; }
.chat-empty { margin: 0 auto; color: #637187; text-align: center; font-size: 14px; padding: 16px 0; }
.chat-message { display: flex; flex-direction: column; align-items: flex-start; position: relative; margin-bottom: 14px; padding-left: 34px; }
.chat-message.staff::before { content: ''; width: 26px; height: 26px; position: absolute; left: 0; top: 4px; border-radius: 50%; background: var(--chat-avatar) center/cover; }
.chat-bubble { max-width: min(90%, 48ch); padding: 9px 12px; border-radius: 11px; background: #eff1f4; overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-message.visitor { align-items: flex-end; padding-left: 0; }
.visitor .chat-bubble { background: var(--chat-blue); color: white; }
.chat-panel[data-expanded=true] .staff { padding-left: 0; }
.chat-panel[data-expanded=true] .staff::before { display: none; }
.chat-panel[data-expanded=true] .staff .chat-bubble { background: white; border: 1px solid var(--chat-line); }
.chat-panel[data-expanded=true] .visitor .chat-bubble { background: #deecff; color: #172b46; }
.chat-bubble img { display: block; max-width: 100%; max-height: 160px; border-radius: 6px; }
.chat-delivery { display: flex; align-items: center; gap: 4px; margin-top: 4px; font-size: 12px; color: #5b687e; }
.chat-delivery svg { width: 14px; height: 14px; }
.chat-delivery[data-state=failed] { color: #ad3030; }
.chat-delivery[data-state=uncertain] { color: #875410; }
.chat-delivery[data-state=delivered] svg { color: #238059; }
.chat-delivery[data-state=sending] svg { animation: chat-spin 1s linear infinite; }
@keyframes chat-spin { to { transform: rotate(360deg); } }
.chat-delivery button, .chat-preview button { color: var(--chat-blue); text-decoration: underline; padding: 3px 6px; }
.chat-form { flex: none; padding: 10px 14px 12px; border-top: 1px solid #e9ecf1; }
.chat-composer { position: relative; border: 1px solid #bfcada; border-radius: 10px; padding: 6px; }
.chat-composer:focus-within { border-color: var(--chat-blue); box-shadow: 0 0 0 1px var(--chat-blue); }
.chat-form textarea { display: block; width: 100%; height: 48px; resize: none; padding: 4px 6px; border: 0; outline: none; font: inherit; color: inherit; background: transparent; }
.chat-panel[data-expanded=true] textarea { height: 68px; }
.chat-actions { gap: 2px; }
.chat-actions .chat-send { margin-left: auto; padding: 6px 17px; border-radius: 7px; color: white; background: var(--chat-blue); }
.chat-send:disabled { background: #d7dde7; color: #465268; }
.chat-emojis { position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 1; background: white; border: 1px solid var(--chat-line); border-radius: 12px; padding: 9px; box-shadow: 0 6px 26px #18233721; }
.chat-emojis strong { display: block; padding: 2px 5px; font-size: 13px; }
.chat-emojis div { display: grid; grid-template-columns: repeat(6, 1fr); }
.chat-emojis button { font-size: 21px; min-width: 36px; height: 36px; border-radius: 6px; }
.chat-foot { justify-content: space-between; gap: 6px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; }
.chat-consent { flex-wrap: wrap; gap: 3px; }
.chat-consent input { width: 16px; height: 16px; accent-color: var(--chat-blue); margin: 0 3px 0 0; }
.chat-consent a { color: var(--chat-blue); }
.chat-fallback { color: #596880; }
.chat-preview { font-size: 12px; background: #f4f7fc; padding: 2px 6px; gap: 4px; }
.chat-preview span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-form [role=status] { font-size: 12px; color: #8e421d; margin: 5px 0 0; }
.chat-form [role=status]:empty { display: none; }
@media (max-width: 650px) {
  .chat-panel, .chat-panel[data-expanded=true] { width: 100%; right: 0; bottom: var(--chat-inset, 0px); border-radius: 16px 16px 0 0; }
  .chat-panel { height: min(var(--chat-height, 100dvh), max(58dvh, 340px)); }
  .chat-panel[data-expanded=true] { height: var(--chat-height, 100dvh); border-radius: 0; }
  .chat-panel:not([data-expanded=true])::before { content: ''; width: 36px; height: 4px; border-radius: 4px; background: #c5cbd4; margin: 7px auto 0; flex: none; }
  .chat-head { padding: 4px 8px 4px 14px; gap: 4px; }
  .chat-head button, .chat-actions > button:not(.chat-send), .chat-emojis button { width: 44px; height: 44px; }
  .chat-form { padding: 6px 10px max(8px, env(safe-area-inset-bottom)); }
  .chat-form textarea { font-size: 16px; }
  .chat-title { font-size: 14px; }
  .chat-emojis { max-width: 95vw; }
}
.chat-panel[data-expanded=true] .chat-title { border-left: 1px solid var(--chat-line); padding-left: 10px; font-size: 18px; font-weight: 650; }
@media (max-height: 460px) and (max-width: 650px) {
  .chat-head { padding-block: 0; }
  .chat-note { margin-top: 3px; }
  .chat-form textarea, .chat-panel[data-expanded=true] textarea { height: 36px; }
}
