/* RedeCasas Floating Chat Widget */

.rc-chat-widget {
  --wa-dark: #075e54;
  --wa-teal: #128c7e;
  --wa-green: #25d366;
  --wa-bubble-user: #dcf8c6;
  --wa-bubble-ai: #ffffff;
  --wa-bg: #e5ddd5;
  --wa-header-bg: linear-gradient(180deg, #075e54 0%, #128c7e 100%);
  --wa-input-bg: #f0f0f0;
  --wa-text: #111b21;
  --wa-text-secondary: #667781;
  --wa-time: #667781;
  --wa-border: #d1d7db;

  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Toggle Button */
.rc-chat-widget__toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0f766e, #14b8a6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.35);
  border: none;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}

.rc-chat-widget__toggle:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 18px rgba(15, 118, 110, 0.45);
}

.rc-chat-widget__toggle:active {
  transform: scale(0.95);
}

.rc-chat-widget__toggle-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background: #ff3b30;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

.rc-chat-widget__toggle-badge.active {
  display: flex;
}

/* Engagement tooltip */
.rc-chat-widget__tooltip {
  position: absolute;
  bottom: 68px;
  right: 0;
  width: 260px;
  background: var(--surface-default);
  color: var(--text-primary);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  font-size: 0.9rem;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  transform-origin: bottom right;
  z-index: 1;
}

.rc-chat-widget__tooltip::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 20px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--surface-default);
}

.rc-chat-widget__tooltip--visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.rc-chat-widget__tooltip-text {
  display: block;
  margin-bottom: 10px;
}

.rc-chat-widget__tooltip-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.rc-chat-widget__tooltip-btn {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.2s;
}

.rc-chat-widget__tooltip-btn--primary {
  background: #0f766e;
  color: #fff;
}

.rc-chat-widget__tooltip-btn--primary:hover {
  background: #115e59;
}

.rc-chat-widget__tooltip-btn--ghost {
  background: transparent;
  color: var(--text-secondary);
}

.rc-chat-widget__tooltip-btn--ghost:hover {
  background: var(--surface-muted);
}

/* Panel */
.rc-chat-widget__panel {
  position: absolute;
  bottom: 68px;
  right: 0;
  width: 380px;
  height: 550px;
  background: var(--wa-bg);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  transform-origin: bottom right;
}

.rc-chat-widget__panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* WhatsApp dot pattern background */
.rc-chat-widget__panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d1d7db' fill-opacity='0.25'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  opacity: 0.6;
  pointer-events: none;
  z-index: 0;
}

/* Header */
.rc-chat-widget__header {
  background: var(--wa-header-bg);
  color: #fff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

.rc-chat-widget__header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.rc-chat-widget__header-info {
  flex: 1;
  min-width: 0;
}

.rc-chat-widget__header-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
}

.rc-chat-widget__header-status {
  font-size: 0.75rem;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 4px;
}

.rc-chat-widget__header-status::before {
  content: "";
  width: 7px;
  height: 7px;
  background: var(--wa-green);
  border-radius: 50%;
  display: inline-block;
}

.rc-chat-widget__header-close,
.rc-chat-widget__header-new {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.2s;
}

.rc-chat-widget__header-close:hover,
.rc-chat-widget__header-new:hover {
  background: rgba(255,255,255,0.15);
}

/* Messages */
.rc-chat-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
  z-index: 1;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Day separator */
.rc-chat-widget__day {
  align-self: center;
  background: rgba(225, 245, 254, 0.92);
  color: #54656f;
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 8px;
  margin: 6px 0;
  font-weight: 500;
  box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}

/* Message bubbles */
.rc-chat-widget__msg {
  max-width: 80%;
  padding: 7px 9px 5px 11px;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-break: break-word;
  position: relative;
  box-shadow: 0 1px 2px rgba(0,0,0,0.10), 0 0.5px 1px rgba(0,0,0,0.06);
  animation: rcMsgAppear 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes rcMsgAppear {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.rc-chat-widget__msg--user {
  align-self: flex-end;
  background: var(--wa-bubble-user);
  color: var(--wa-text);
  border-bottom-right-radius: 4px;
}

.rc-chat-widget__msg--ai {
  align-self: flex-start;
  background: var(--wa-bubble-ai);
  color: var(--wa-text);
  border-bottom-left-radius: 4px;
}

.rc-chat-widget__msg--system {
  align-self: center;
  background: rgba(241, 241, 241, 0.9);
  color: var(--wa-text-secondary);
  font-size: 0.78rem;
  padding: 4px 12px;
  border-radius: 12px;
  max-width: 90%;
  text-align: center;
}

.rc-chat-widget__msg-content a {
  color: #039be5;
  text-decoration: underline;
}

.rc-chat-widget__msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
}

.rc-chat-widget__msg-time {
  font-size: 0.68rem;
  color: var(--wa-time);
  white-space: nowrap;
}

.rc-chat-widget__msg-name {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--wa-teal);
  margin-bottom: 2px;
}

/* Typing */
.rc-chat-widget__typing {
  align-self: flex-start;
  background: var(--wa-bubble-ai);
  padding: 8px 12px;
  border-radius: 8px;
  border-bottom-left-radius: 2px;
  display: none;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.rc-chat-widget__typing.active {
  display: flex;
}

.rc-chat-widget__typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.rc-chat-widget__typing-dots span {
  width: 6px;
  height: 6px;
  background: #9ea7b0;
  border-radius: 50%;
  animation: rcTypingBounce 1.4s infinite ease-in-out both;
}

.rc-chat-widget__typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.rc-chat-widget__typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes rcTypingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input */
.rc-chat-widget__input-area {
  background: var(--wa-input-bg);
  padding: 8px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  border-top: 1px solid var(--wa-border);
}

.rc-chat-widget__input-wrap {
  flex: 1;
  background: #fff;
  border-radius: 20px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  min-height: 40px;
  max-height: 120px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.rc-chat-widget__input-wrap textarea {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.9rem;
  resize: none;
  max-height: 100px;
  line-height: 1.4;
  color: var(--wa-text);
}

.rc-chat-widget__input-wrap textarea::placeholder {
  color: var(--wa-text-secondary);
}

.rc-chat-widget__send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--wa-teal);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
  box-shadow: 0 2px 6px rgba(18, 140, 126, 0.35);
}

.rc-chat-widget__send-btn:hover {
  background: var(--wa-dark);
}

.rc-chat-widget__send-btn:active {
  transform: scale(0.92);
}

.rc-chat-widget__send-btn:disabled {
  background: #a5a5a5;
  cursor: not-allowed;
  box-shadow: none;
}

/* Scrollbar */
.rc-chat-widget__messages::-webkit-scrollbar {
  width: 4px;
}
.rc-chat-widget__messages::-webkit-scrollbar-track {
  background: transparent;
}
.rc-chat-widget__messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.18);
  border-radius: 10px;
}

/* Loading */
.rc-chat-widget__loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  color: var(--wa-text-secondary);
  font-size: 0.85rem;
  gap: 8px;
}

/* Mobile responsive */
@media (max-width: 480px) {
  .rc-chat-widget {
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
  }

  .rc-chat-widget__toggle {
    bottom: 16px;
    right: 16px;
    position: fixed;
    width: 50px;
    height: 50px;
    font-size: 1.2rem;
  }

  .rc-chat-widget__panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    transform: translateY(100%);
    transform-origin: bottom center;
  }

  .rc-chat-widget__panel.open {
    transform: translateY(0);
  }

  .rc-chat-widget__header {
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .rc-chat-widget__input-area {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .rc-chat-widget__panel {
    transition: none;
  }
  .rc-chat-widget__msg {
    animation: none;
  }
  .rc-chat-widget__typing-dots span {
    animation: none;
  }
}
