:root {
  --sr-chat-accent: #460000;
  --sr-chat-radius: 14px;
  --sr-chat-z: 9999;
  --sr-chat-shadow: 0 8px 32px rgba(0,0,0,.18);
}

.sr-chat-widget--checking,
.sr-chat-widget--unavailable {
  display: none !important;
}

.sr-chat-bubble {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: var(--sr-chat-z);
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--sr-chat-accent);
  color: #fff;
  box-shadow: var(--sr-chat-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: transform .16s ease, box-shadow .16s ease;
}
.sr-chat-bubble::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 2px solid color-mix(in srgb, var(--sr-chat-accent), transparent 55%);
  border-radius: 50%;
  animation: sr-chat-pulse 2.4s infinite;
}
.sr-chat-bubble:hover { transform: translateY(-2px) scale(1.05); }
.sr-chat-bubble--active {
  box-shadow: 0 8px 32px rgba(0,0,0,.18), 0 0 0 4px color-mix(in srgb, var(--sr-chat-accent), transparent 82%);
}
.sr-chat-bubble--unread {
  animation: sr-chat-attention 1.8s ease-in-out infinite;
}
@keyframes sr-chat-pulse { 0%,100% { opacity: .2; transform: scale(.96); } 50% { opacity: .8; transform: scale(1.08); } }
@keyframes sr-chat-attention { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
[data-position="left"] .sr-chat-bubble { right: auto; left: 24px; }
.sr-chat-widget--open .sr-chat-bubble {
  display: none;
}

.sr-chat-unread {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  padding: 1px 6px;
  border-radius: 10px;
  background: #dc2626;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.sr-chat-status-dot {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  border: 1px solid #fff;
  box-shadow: 0 0 0 2px rgba(34,197,94,.25);
}

.sr-chat-window {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: var(--sr-chat-z);
  width: 360px;
  height: min(560px, calc(100dvh - 116px));
  background: #fff;
  border-radius: var(--sr-chat-radius);
  box-shadow: var(--sr-chat-shadow);
  flex-direction: column;
  overflow: hidden;
  animation: sr-chat-in .18s ease;
}
[data-position="left"] .sr-chat-window { right: auto; left: 24px; }
@keyframes sr-chat-in { from { opacity: 0; transform: translateY(12px); } }

.sr-chat-header {
  flex-shrink: 0;
  padding: 14px 16px;
  background: var(--sr-chat-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sr-chat-header-info strong { display: block; font-size: .95rem; }
.sr-chat-header-info span { display: block; font-size: .78rem; opacity: .88; }
.sr-chat-header-actions button {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
}

.sr-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sr-chat-welcome { text-align: center; padding: 24px 16px; color: #6b7280; }
.sr-chat-welcome p { margin: 0 0 6px; }
.sr-chat-welcome p:last-child { font-size: .85em; opacity: .75; }
.sr-chat-loading {
  margin: auto;
  text-align: center;
  color: #6b7280;
  font-size: .86rem;
}
.sr-chat-loading span {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 2px 8px;
  border-radius: 50%;
  background: var(--sr-chat-accent);
  animation: sr-bounce .9s infinite;
}
.sr-chat-loading span:nth-child(2) { animation-delay: .15s; }
.sr-chat-loading span:nth-child(3) { animation-delay: .3s; }
.sr-chat-loading p { margin: 0; }

.sr-msg {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: .88rem;
  line-height: 1.45;
  word-break: break-word;
}
.sr-msg-user { align-self: flex-end; border-bottom-right-radius: 4px; background: var(--sr-chat-accent); color: #fff; }
.sr-msg-admin { align-self: flex-start; border-bottom-left-radius: 4px; background: #f3f4f6; color: #111827; }
.sr-msg-bot { align-self: flex-start; border-bottom-left-radius: 4px; background: #f5f4f1; color: #111827; }
.sr-msg-system { align-self: center; border-radius: 20px; background: #fef9c3; color: #92400e; font-size: .78rem; }
.sr-msg-time { display: block; margin-top: 3px; font-size: .68rem; opacity: .65; }
.sr-msg-deleted { opacity: .72; font-style: italic; }
.sr-chat-bot-name { display: block; margin-bottom: 2px; font-size: .72rem; font-weight: 700; color: #6b7280; }
.sr-chat-bot-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sr-chat-bot-link {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #fff;
  color: var(--sr-chat-accent);
  font-size: .78rem;
  font-weight: 700;
  text-decoration: none;
  border: 1px solid rgba(0,0,0,.08);
}
.sr-chat-handoff { align-self: flex-start; }
.sr-chat-talk-human {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--sr-chat-accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.sr-msg-attachment,
.sr-link-preview {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  padding: 8px;
  border-radius: 10px;
  background: rgba(255,255,255,.18);
  color: inherit;
  text-decoration: none;
  border: 1px solid rgba(0,0,0,.08);
}
.sr-msg-admin .sr-msg-attachment,
.sr-msg-admin .sr-link-preview { background: #fff; }
.sr-msg-attachment-image {
  display: block;
  padding: 0;
  overflow: hidden;
}
.sr-msg-attachment-image img {
  display: block;
  max-width: 100%;
  max-height: 180px;
  object-fit: cover;
}
.sr-msg-attachment-image span { display: block; padding: 7px 9px; }
.sr-link-preview img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.sr-link-preview strong,
.sr-link-preview small { display: block; }
.sr-link-preview small { opacity: .72; margin-top: 2px; }

.sr-chat-typing { flex-shrink: 0; padding: 8px 16px; gap: 4px; align-items: center; }
.sr-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  animation: sr-bounce .9s infinite;
}
.sr-chat-typing span:nth-child(2) { animation-delay: .15s; }
.sr-chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes sr-bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

.sr-chat-identity-form {
  flex-shrink: 0;
  padding: 16px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  flex-direction: column;
  gap: 8px;
}
.sr-chat-identity-form p { margin: 0 0 4px; font-size: .84rem; color: #374151; font-weight: 600; }
.sr-chat-identity-form input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: .88rem;
}
.sr-chat-identity-form button {
  border: 0;
  border-radius: 8px;
  padding: 10px;
  background: var(--sr-chat-accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.sr-chat-composer {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #e5e7eb;
}
.sr-chat-file-input { display: none; }
.sr-chat-tool-btn {
  background: #f3f4f6 !important;
  color: #374151 !important;
}
.sr-chat-composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  font-size: .9rem;
  line-height: 1.4;
}
.sr-chat-composer textarea:focus,
.sr-chat-identity-form input:focus {
  outline: 2px solid var(--sr-chat-accent);
  border-color: transparent;
}
.sr-chat-composer button {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: var(--sr-chat-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.sr-chat-composer button:disabled,
.sr-chat-composer textarea:disabled {
  opacity: .6;
  cursor: not-allowed;
}
.sr-chat-selected-file {
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  font-size: .82rem;
}
.sr-chat-selected-file button {
  border: 0;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  color: #6b7280;
}

@media (max-width: 420px) {
  .sr-chat-bubble {
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(16px + env(safe-area-inset-bottom));
  }

  [data-position="left"] .sr-chat-bubble {
    left: max(16px, env(safe-area-inset-left));
    right: auto;
  }

  .sr-chat-window {
    right: max(12px, env(safe-area-inset-right));
    left: max(12px, env(safe-area-inset-left));
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: auto;
    height: min(620px, calc(100dvh - 96px - env(safe-area-inset-bottom)));
    min-height: 420px;
    border-radius: var(--sr-chat-radius);
  }

  [data-position="left"] .sr-chat-window {
    right: max(12px, env(safe-area-inset-right));
    left: max(12px, env(safe-area-inset-left));
  }

  .sr-chat-composer {
    padding: 10px 10px calc(12px + env(safe-area-inset-bottom));
  }

  .sr-chat-composer textarea {
    min-width: 0;
  }
}

@media (max-width: 420px) and (max-height: 560px) {
  .sr-chat-window {
    height: calc(100dvh - 48px - env(safe-area-inset-bottom));
    min-height: 0;
  }
}
