:root {
  --chat-red: #d60000;
  --chat-red-dark: #a90000;
  --chat-bg: #f8fafc;
  --chat-surface: #ffffff;
  --chat-panel: #0f172a;
  --chat-border: #e2e8f0;
  --chat-text: #111827;
  --chat-muted: #64748b;
}

body.chat-open {
  overflow: hidden;
}

#visitorChat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99999;
  pointer-events: none;
}

#visitorChatWidget {
  pointer-events: auto;
}

#visitorChatToggle {
  border: 0;
  width: 64px;
  height: 64px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--chat-red), var(--chat-red-dark));
  color: #fff;
  box-shadow: 0 20px 50px rgba(220, 38, 38, 0.28);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

#visitorChatToggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 26px 60px rgba(220, 38, 38, 0.34);
}

#visitorChatPanel {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
  display: none;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 16px;
}

#visitorChatPanel.open {
  display: flex;
}

#visitorChatPanel .chat-panel-shell {
  width: min(440px, 100%);
  height: min(720px, 100%);
  border-radius: 26px;
  overflow: hidden;
  background: var(--chat-surface);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
  display: flex;
  flex-direction: column;
}

#visitorChatHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--chat-panel), #172033);
  color: #fff;
}

.chat-header-title {
  font-size: 1rem;
  font-weight: 700;
}

.chat-header-subtitle {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.72);
  margin-top: 2px;
}

.chat-close-btn {
  border: 0;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
}

#visitorChatBody {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: linear-gradient(180deg, #f8fafc 0%, #fefefe 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-empty,
.chat-welcome {
  margin: auto;
  max-width: 320px;
  text-align: center;
  color: var(--chat-muted);
}

.chat-empty-title,
.chat-welcome h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--chat-text);
  margin-bottom: 6px;
}

.chat-empty-copy,
.chat-welcome p {
  font-size: 0.92rem;
  line-height: 1.5;
}

.chat-welcome-badge {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(214, 0, 0, 0.09);
  color: var(--chat-red);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin-bottom: 10px;
}

.chat-setup-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.chat-setup-form input,
#visitorChatInput {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--chat-border);
  border-radius: 999px;
  padding: 0 14px;
  outline: none;
  background: #fff;
  color: var(--chat-text);
}

.chat-setup-form input:focus,
#visitorChatInput:focus {
  border-color: var(--chat-red);
  box-shadow: 0 0 0 3px rgba(214, 0, 0, 0.12);
}

.chat-action-btn,
#visitorChatSend {
  border: 0;
  min-height: 46px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--chat-red), var(--chat-red-dark));
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

#visitorChatSend {
  padding: 0 16px;
}

.chat-bubble {
  max-width: 86%;
  border-radius: 16px 16px 16px 6px;
  padding: 11px 12px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  line-height: 1.45;
}

.chat-bubble.mine {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--chat-red), var(--chat-red-dark));
  color: #fff;
  border-radius: 16px 16px 6px 16px;
}

.chat-bubble.other {
  align-self: flex-start;
  background: #fff;
  color: var(--chat-text);
}

.chat-bubble-text {
  font-size: 0.95rem;
  white-space: pre-wrap;
}

.chat-bubble-meta {
  margin-top: 6px;
  font-size: 0.72rem;
  opacity: 0.8;
}

#visitorChatFooter {
  padding: 12px 12px 14px;
  border-top: 1px solid var(--chat-border);
  background: #fff;
}

#visitorChatStatus {
  font-size: 0.8rem;
  color: var(--chat-muted);
  margin-bottom: 8px;
}

#visitorChatStatus.info::before,
#visitorChatStatus.success::before,
#visitorChatStatus.error::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  margin-right: 6px;
  vertical-align: middle;
}

#visitorChatStatus.info::before {
  background: #38bdf8;
}

#visitorChatStatus.success::before {
  background: #22c55e;
}

#visitorChatStatus.error::before {
  background: #ef4444;
}

#visitorChatForm {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

@media (max-width: 640px) {
  body.chat-open {
    overflow: hidden;
  }

  #visitorChat {
    right: 14px;
    bottom: 14px;
  }

  #visitorChatPanel {
    inset: 0;
    padding: 0;
  }

  #visitorChatPanel .chat-panel-shell {
    width: 100%;
    height: 100%;
    max-width: 100%;
    border-radius: 0;
  }

  #visitorChatToggle {
    width: 58px;
    height: 58px;
  }
}
