/**
 * Stafferin Chat Widget - Clean Modern Design
 * Minimalist, professional chat interface
 */

/* ==================== VARIABLES ==================== */
:root {
  --chat-primary: #5B9BD5;
  --chat-primary-hover: #4A8BC4;
  --chat-dark: #3D4852;
  --chat-dark-secondary: #4A5568;
  --chat-text: #4A5568;
  --chat-text-secondary: #718096;
  --chat-text-muted: #A0AEC0;
  --chat-white: #FFFFFF;
  --chat-bg: #FAFBFD;
  --chat-border: #E8ECF1;
  --chat-border-light: #F4F6F9;
  --chat-success: #6ECFB8;
  --chat-shadow: 0 20px 50px -12px rgba(90, 107, 123, 0.15);
  --chat-shadow-sm: 0 1px 3px rgba(90, 107, 123, 0.06);
  --chat-radius: 20px;
  --chat-radius-sm: 12px;
  --chat-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ==================== CHAT BUTTON ==================== */
.chat-widget-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--chat-dark);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(90, 107, 123, 0.3);
  transition: all 0.2s ease;
  z-index: 9998;
}

.chat-widget-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 28px rgba(90, 107, 123, 0.4);
}

.chat-widget-btn:active {
  transform: scale(0.98);
}

.chat-widget-btn svg {
  width: 24px;
  height: 24px;
  fill: var(--chat-white);
  transition: all 0.2s ease;
}

.chat-widget-btn.active svg.chat-icon { display: none; }
.chat-widget-btn svg.close-icon { display: none; }
.chat-widget-btn.active svg.close-icon { display: block; }

/* Online indicator */
.chat-widget-btn::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: var(--chat-success);
  border-radius: 50%;
  border: 2px solid var(--chat-white);
}

/* Pulse animation */
.chat-widget-btn.pulse {
  animation: pulse 2s ease-in-out;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(90, 107, 123, 0.3); }
  50% { box-shadow: 0 4px 20px rgba(90, 107, 123, 0.3), 0 0 0 12px rgba(90, 107, 123, 0.1); }
}

/* ==================== TEASER MESSAGE ==================== */
.chat-teaser {
  position: fixed;
  bottom: 96px;
  right: 24px;
  background: var(--chat-white);
  padding: 16px 20px;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  max-width: 260px;
  z-index: 9997;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: all 0.2s ease;
  cursor: pointer;
}

.chat-teaser.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.chat-teaser-content {
  display: flex;
  align-items: center;
  gap: 14px;
}

.chat-teaser-avatar {
  width: 44px;
  height: 44px;
  background: var(--chat-dark);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chat-white);
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.chat-teaser-text {
  font-family: var(--chat-font);
  font-size: 0.9rem;
  color: var(--chat-text);
  line-height: 1.4;
}

.chat-teaser-text strong {
  display: block;
  font-size: 0.7rem;
  color: var(--chat-text-muted);
  font-weight: 500;
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chat-teaser-close {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  background: var(--chat-white);
  border: 1px solid var(--chat-border);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  box-shadow: var(--chat-shadow-sm);
}

.chat-teaser-close:hover {
  background: var(--chat-bg);
}

.chat-teaser-close svg {
  width: 10px;
  height: 10px;
  fill: var(--chat-text-secondary);
}

.chat-teaser::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 30px;
  width: 12px;
  height: 12px;
  background: var(--chat-white);
  transform: rotate(45deg);
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.04);
}

.chat-widget-btn.active ~ .chat-teaser {
  opacity: 0 !important;
  visibility: hidden !important;
}

/* ==================== CHAT POPUP ==================== */
.chat-widget-popup {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 340px;
  max-height: 480px;
  background: var(--chat-white);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  z-index: 9999;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.98);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-widget-popup.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ==================== CHAT HEADER ==================== */
.chat-header {
  background: var(--chat-dark);
  padding: 16px 18px;
  color: var(--chat-white);
}

.chat-header-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  background: var(--chat-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
}

.chat-header-info h4 {
  margin: 0 0 2px;
  font-family: var(--chat-font);
  font-size: 0.95rem;
  font-weight: 600;
}

.chat-header-info p {
  margin: 0;
  font-size: 0.75rem;
  opacity: 0.8;
}

.chat-online-status {
  display: flex !important;
  align-items: center;
  gap: 5px;
  color: var(--chat-success) !important;
  opacity: 1 !important;
  font-weight: 500;
  font-size: 0.75rem !important;
}

.chat-online-status .online-dot {
  width: 8px;
  height: 8px;
  background: var(--chat-success);
  border-radius: 50%;
  animation: blink 2s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.chat-tagline {
  font-family: var(--chat-font);
  font-size: 0.8rem;
  opacity: 0.85;
  margin: 0;
  line-height: 1.4;
}

/* ==================== CHAT BODY ==================== */
.chat-body {
  padding: 16px;
  max-height: 300px;
  overflow-y: auto;
  background: var(--chat-bg);
}

.chat-body::-webkit-scrollbar { width: 4px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }
.chat-body::-webkit-scrollbar-thumb { background: var(--chat-border); border-radius: 2px; }

/* ==================== QUICK REPLIES ==================== */
.chat-quick-replies {
  margin-bottom: 12px;
}

.quick-replies-label {
  margin: 0 0 8px;
  font-family: var(--chat-font);
  font-size: 0.65rem;
  color: var(--chat-text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.quick-replies-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quick-reply-btn {
  padding: 8px 12px;
  background: var(--chat-white);
  border: 1px solid var(--chat-border);
  border-radius: 100px;
  font-family: var(--chat-font);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--chat-text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.quick-reply-btn:hover {
  background: var(--chat-dark);
  border-color: var(--chat-dark);
  color: var(--chat-white);
}

/* ==================== CHAT FORM ==================== */
.chat-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--chat-white);
  padding: 14px;
  border-radius: var(--chat-radius-sm);
  border: 1px solid var(--chat-border-light);
}

.chat-input-group label {
  display: block;
  font-family: var(--chat-font);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--chat-text);
  margin-bottom: 4px;
}

.chat-input-group input,
.chat-input-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  font-family: var(--chat-font);
  font-size: 0.85rem;
  color: var(--chat-text);
  background: var(--chat-white);
  transition: all 0.15s ease;
  outline: none;
}

.chat-input-group input:focus,
.chat-input-group textarea:focus {
  border-color: var(--chat-primary);
  box-shadow: 0 0 0 3px rgba(91, 155, 213, 0.1);
}

.chat-input-group input::placeholder,
.chat-input-group textarea::placeholder {
  color: var(--chat-text-muted);
}

.chat-input-group textarea {
  resize: none;
  min-height: 60px;
  line-height: 1.4;
}

.chat-input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ==================== SUBMIT BUTTON ==================== */
.chat-submit-btn {
  width: 100%;
  padding: 12px;
  background: var(--chat-dark);
  color: var(--chat-white);
  border: none;
  border-radius: 8px;
  font-family: var(--chat-font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.chat-submit-btn:hover {
  background: var(--chat-dark-secondary);
}

.chat-submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-submit-btn svg {
  width: 16px;
  height: 16px;
}

.chat-submit-btn .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--chat-white);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: none;
}

.chat-submit-btn.loading .spinner { display: block; }
.chat-submit-btn.loading .btn-text,
.chat-submit-btn.loading .btn-icon { display: none; }

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

/* ==================== SUCCESS MESSAGE ==================== */
.chat-success-message {
  display: none;
  text-align: center;
  padding: 24px 16px;
  background: var(--chat-white);
  border-radius: var(--chat-radius-sm);
  border: 1px solid var(--chat-border-light);
}

.chat-success-message.show {
  display: block;
  animation: fadeIn 0.3s ease;
}

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

.chat-success-message .success-icon {
  width: 48px;
  height: 48px;
  background: var(--chat-success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.chat-success-message .success-icon svg {
  width: 24px;
  height: 24px;
  fill: var(--chat-white);
}

.chat-success-message h4 {
  margin: 0 0 6px;
  font-family: var(--chat-font);
  font-size: 1rem;
  font-weight: 600;
  color: var(--chat-text);
}

.chat-success-message p {
  margin: 0;
  font-family: var(--chat-font);
  font-size: 0.8rem;
  color: var(--chat-text-secondary);
  line-height: 1.4;
}

.chat-new-message-btn {
  margin-top: 12px;
  padding: 8px 16px;
  background: var(--chat-bg);
  color: var(--chat-text);
  border: none;
  border-radius: 6px;
  font-family: var(--chat-font);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chat-new-message-btn:hover {
  background: var(--chat-border);
}

/* ==================== MESSAGES VIEW ==================== */
.chat-messages-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 180px;
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.chat-message {
  display: flex;
}

.chat-message.visitor { justify-content: flex-end; }
.chat-message.admin { justify-content: flex-start; }

.chat-message-bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 18px;
}

.chat-message.visitor .chat-message-bubble {
  background: var(--chat-dark);
  color: var(--chat-white);
  border-bottom-right-radius: 6px;
}

.chat-message.admin .chat-message-bubble {
  background: var(--chat-white);
  color: var(--chat-text);
  border: 1px solid var(--chat-border);
  border-bottom-left-radius: 6px;
}

.chat-message-text {
  font-family: var(--chat-font);
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.chat-message-time {
  font-family: var(--chat-font);
  font-size: 0.7rem;
  margin-top: 4px;
  opacity: 0.6;
}

.chat-message.visitor .chat-message-time { text-align: right; }

/* ==================== MESSAGE INPUT ==================== */
.chat-message-input {
  padding: 16px;
  background: var(--chat-white);
  border-top: 1px solid var(--chat-border-light);
}

.chat-message-input form {
  display: flex;
  gap: 10px;
  align-items: center;
}

.chat-message-input input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--chat-border);
  border-radius: 100px;
  font-family: var(--chat-font);
  font-size: 0.9rem;
  outline: none;
  transition: all 0.15s ease;
}

.chat-message-input input:focus {
  border-color: var(--chat-primary);
}

.chat-message-input button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--chat-dark);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.chat-message-input button:hover {
  background: var(--chat-dark-secondary);
}

.chat-message-input button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-message-input button svg {
  width: 18px;
  height: 18px;
  fill: var(--chat-white);
}

/* ==================== FOOTER ==================== */
.chat-footer {
  padding: 10px 16px;
  background: var(--chat-white);
  border-top: 1px solid var(--chat-border-light);
  text-align: center;
}

.chat-footer p {
  margin: 0;
  font-family: var(--chat-font);
  font-size: 0.65rem;
  color: var(--chat-text-muted);
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 480px) {
  .chat-widget-popup {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: 100vh;
    border-radius: 20px 20px 0 0;
  }

  .chat-widget-btn {
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
  }

  .chat-teaser {
    right: 16px;
    bottom: 84px;
    max-width: 240px;
  }

  .chat-header { padding: 20px; }
  .chat-body { padding: 16px; max-height: 50vh; }
  .chat-input-row { grid-template-columns: 1fr; }
}

/* ==================== DARK MODE ==================== */
@media (prefers-color-scheme: dark) {
  .chat-widget-popup { background: #4A5568; }
  .chat-body { background: #3D4852; }

  .chat-form,
  .chat-success-message {
    background: #4A5568;
    border-color: rgba(255, 255, 255, 0.08);
  }

  .chat-input-group input,
  .chat-input-group textarea {
    background: #3D4852;
    border-color: rgba(255, 255, 255, 0.12);
    color: #E8ECF1;
  }

  .chat-input-group label,
  .chat-success-message h4 { color: #E8ECF1; }
  .chat-footer { background: #4A5568; border-color: rgba(255, 255, 255, 0.08); }

  .quick-reply-btn {
    background: #3D4852;
    border-color: rgba(255, 255, 255, 0.12);
    color: #E8ECF1;
  }

  .chat-teaser {
    background: #4A5568;
    box-shadow: 0 4px 24px rgba(90, 107, 123, 0.25);
  }

  .chat-teaser::after { background: #4A5568; }
  .chat-teaser-text { color: #E8ECF1; }
  .chat-message-input { background: #4A5568; border-color: rgba(255, 255, 255, 0.08); }
  .chat-message-input input { background: #3D4852; border-color: rgba(255, 255, 255, 0.12); color: #E8ECF1; }
}

/* ==================== TYPING INDICATOR ==================== */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-top: 8px;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--chat-text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0s; }

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

.typing-text {
  font-family: var(--chat-font);
  font-size: 0.75rem;
  color: var(--chat-text-muted);
  font-style: italic;
}
