/**
 * Sales Chat Widget Styles
 * Prefixed with scw- to avoid conflicts with page styles
 */

:root {
  --scw-accent: #2d6a4f;
  --scw-accent-hover: #245840;
  --scw-dark: #1a2634;
  --scw-bg: #f8f6f3;
  --scw-white: #ffffff;
  --scw-text: #1a2634;
  --scw-text-light: #6b7280;
  --scw-border: #e5e7eb;
  --scw-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  --scw-radius: 20px;
  --scw-radius-sm: 12px;
}

/* Container - holds button and panel */
.scw-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Floating chat button */
.scw-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--scw-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--scw-shadow);
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.scw-button:hover {
  background: var(--scw-accent-hover);
  transform: scale(1.05);
}

.scw-button svg {
  width: 28px;
  height: 28px;
  fill: var(--scw-white);
}

.scw-button--open .scw-icon-chat {
  display: none;
}

.scw-button--open .scw-icon-close {
  display: block;
}

.scw-button:not(.scw-button--open) .scw-icon-chat {
  display: block;
}

.scw-button:not(.scw-button--open) .scw-icon-close {
  display: none;
}

/* Pulse animation for button */
.scw-button::before {
  content: '';
  position: absolute;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--scw-accent);
  animation: scw-pulse 2s ease-out infinite;
  z-index: -1;
}

@keyframes scw-pulse {
  0% {
    transform: scale(1);
    opacity: 0.4;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}

/* Chat panel */
.scw-panel {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 380px;
  height: 520px;
  background: var(--scw-white);
  border-radius: var(--scw-radius);
  box-shadow: var(--scw-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.scw-panel--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Panel header */
.scw-header {
  background: linear-gradient(135deg, var(--scw-dark) 0%, #2a3f54 100%);
  color: var(--scw-white);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.scw-header-avatar {
  width: 44px;
  height: 44px;
  background: var(--scw-accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.scw-header-avatar svg {
  width: 24px;
  height: 24px;
  fill: var(--scw-white);
}

.scw-header-info {
  flex: 1;
}

.scw-header-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 2px 0;
}

.scw-header-subtitle {
  font-size: 13px;
  opacity: 0.85;
  margin: 0;
}

.scw-header-close {
  background: none;
  border: none;
  color: var(--scw-white);
  cursor: pointer;
  padding: 8px;
  margin: -8px;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.scw-header-close:hover {
  opacity: 1;
}

.scw-header-close svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Panel body */
.scw-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--scw-bg);
}

/* Contact form step */
.scw-contact-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.scw-form-intro {
  font-size: 15px;
  color: var(--scw-text);
  margin: 0 0 20px 0;
  line-height: 1.5;
}

.scw-form-group {
  margin-bottom: 16px;
}

.scw-form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--scw-text);
  margin-bottom: 6px;
}

.scw-form-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 14px;
  border: 1px solid var(--scw-border);
  border-radius: var(--scw-radius-sm);
  background: var(--scw-white);
  color: var(--scw-text);
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.scw-form-input:focus {
  outline: none;
  border-color: var(--scw-accent);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.1);
}

.scw-form-input::placeholder {
  color: var(--scw-text-light);
}

.scw-form-input--error {
  border-color: #ef4444;
}

.scw-form-error {
  font-size: 12px;
  color: #ef4444;
  margin-top: 4px;
}

.scw-form-spacer {
  flex: 1;
}

.scw-form-submit {
  width: 100%;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--scw-white);
  background: var(--scw-accent);
  border: none;
  border-radius: var(--scw-radius-sm);
  cursor: pointer;
  transition: background-color 0.2s;
}

.scw-form-submit:hover:not(:disabled) {
  background: var(--scw-accent-hover);
}

.scw-form-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Message input step */
.scw-message-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.scw-message-intro {
  font-size: 15px;
  color: var(--scw-text);
  margin: 0 0 8px 0;
  line-height: 1.5;
}

.scw-message-name {
  font-weight: 600;
  color: var(--scw-accent);
}

.scw-message-hint {
  font-size: 13px;
  color: var(--scw-text-light);
  margin: 0 0 16px 0;
}

.scw-message-textarea {
  flex: 1;
  width: 100%;
  padding: 14px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--scw-border);
  border-radius: var(--scw-radius-sm);
  background: var(--scw-white);
  color: var(--scw-text);
  resize: none;
  min-height: 120px;
  box-sizing: border-box;
}

.scw-message-textarea:focus {
  outline: none;
  border-color: var(--scw-accent);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.1);
}

.scw-message-textarea::placeholder {
  color: var(--scw-text-light);
}

.scw-message-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.scw-message-back {
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--scw-text);
  background: var(--scw-white);
  border: 1px solid var(--scw-border);
  border-radius: var(--scw-radius-sm);
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}

.scw-message-back:hover {
  background: var(--scw-bg);
  border-color: var(--scw-text-light);
}

.scw-message-send {
  flex: 1;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--scw-white);
  background: var(--scw-accent);
  border: none;
  border-radius: var(--scw-radius-sm);
  cursor: pointer;
  transition: background-color 0.2s;
}

.scw-message-send:hover:not(:disabled) {
  background: var(--scw-accent-hover);
}

.scw-message-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Chat interface */
.scw-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.scw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Message bubbles */
.scw-msg {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

.scw-msg--visitor {
  align-self: flex-end;
  background: var(--scw-accent);
  color: var(--scw-white);
  border-bottom-right-radius: 4px;
}

.scw-msg--team {
  align-self: flex-start;
  background: var(--scw-white);
  color: var(--scw-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.scw-msg-sender {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  opacity: 0.7;
}

.scw-msg-time {
  font-size: 10px;
  margin-top: 4px;
  opacity: 0.6;
}

/* Typing indicator */
.scw-typing {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--scw-white);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.scw-typing-dot {
  width: 8px;
  height: 8px;
  background: var(--scw-text-light);
  border-radius: 50%;
  animation: scw-typing 1.4s ease-in-out infinite;
}

.scw-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.scw-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes scw-typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* Reply input */
.scw-reply {
  padding: 12px 16px;
  background: var(--scw-white);
  border-top: 1px solid var(--scw-border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.scw-reply-input {
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--scw-border);
  border-radius: 20px;
  background: var(--scw-bg);
  color: var(--scw-text);
  resize: none;
  max-height: 100px;
  overflow-y: auto;
  box-sizing: border-box;
}

.scw-reply-input:focus {
  outline: none;
  border-color: var(--scw-accent);
}

.scw-reply-input::placeholder {
  color: var(--scw-text-light);
}

.scw-reply-send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--scw-accent);
  color: var(--scw-white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.2s;
}

.scw-reply-send:hover:not(:disabled) {
  background: var(--scw-accent-hover);
}

.scw-reply-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.scw-reply-send svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Timeout notice */
.scw-timeout {
  background: #fef3c7;
  border-top: 1px solid #fcd34d;
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.scw-timeout-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  fill: #d97706;
}

.scw-timeout-text {
  font-size: 13px;
  color: #92400e;
  line-height: 1.4;
  margin: 0;
}

/* Loading spinner */
.scw-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: scw-spin 0.8s linear infinite;
  display: inline-block;
  vertical-align: middle;
}

@keyframes scw-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Connection status */
.scw-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--scw-text-light);
  background: var(--scw-white);
  border-bottom: 1px solid var(--scw-border);
}

.scw-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.scw-status-dot--connected {
  background: #22c55e;
}

.scw-status-dot--connecting {
  background: #f59e0b;
  animation: scw-pulse-dot 1s ease-in-out infinite;
}

.scw-status-dot--disconnected {
  background: #ef4444;
}

@keyframes scw-pulse-dot {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

/* Mobile responsiveness */
@media (max-width: 440px) {
  .scw-container {
    bottom: 0;
    right: 0;
    left: 0;
  }

  .scw-button {
    position: fixed;
    bottom: 16px;
    right: 16px;
  }

  /* Hide floating button on mobile when panel is open (use header close button instead) */
  .scw-button--open {
    display: none;
  }

  .scw-panel {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    max-height: 100vh;
    max-height: 100dvh;
  }

  .scw-panel--open {
    transform: translateY(0);
  }
}

/* Print - hide widget */
@media print {
  .scw-container {
    display: none !important;
  }
}
