/**
 * Live Chat Widget Styles
 * Premium dark theme with gold accents for auto auction platform
 */

/* ========================================
   CSS Variables & Base
   ======================================== */
:root {
  --chat-bg: #0d0d12;
  --chat-card: #16161f;
  --chat-card-hover: #1c1c28;
  --chat-border: rgba(193, 154, 107, 0.15);
  --chat-accent: #c19a6b;
  --chat-accent-glow: rgba(193, 154, 107, 0.3);
  --chat-text: #f5f5f5;
  --chat-muted: #8b8b9a;
  --chat-success: #22c55e;
  --chat-visitor-bg: #1e1e2a;
  --chat-admin-bg: linear-gradient(135deg, #c19a6b 0%, #a07d54 100%);
  --chat-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.5);
  --chat-radius: 16px;
  --chat-transition: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   Chat Toggle Button
   ======================================== */
.chat-widget-button {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-accent) 0%, #a07d54 100%);
  border: none;
  cursor: pointer;
  z-index: 99998;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 4px 20px rgba(193, 154, 107, 0.35),
    0 0 0 0 rgba(193, 154, 107, 0.4);
  transition: all 0.4s var(--chat-transition);
  animation: chatButtonPulse 3s ease-in-out infinite;
}

.chat-widget-button:hover {
  transform: scale(1.08);
  box-shadow:
    0 8px 30px rgba(193, 154, 107, 0.5),
    0 0 0 8px rgba(193, 154, 107, 0.1);
}

.chat-widget-button:active {
  transform: scale(0.95);
}

.chat-widget-button svg {
  width: 28px;
  height: 28px;
  color: #0d0d12;
  transition: transform 0.3s var(--chat-transition);
}

.chat-widget-button:hover svg {
  transform: rotate(-10deg) scale(1.1);
}

.chat-widget-button.active svg {
  transform: rotate(90deg);
}

/* Unread Badge */
.chat-widget-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: #ef4444;
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.5);
  animation: badgeBounce 0.5s var(--chat-transition);
  font-family: 'Inter', -apple-system, sans-serif;
}

@keyframes chatButtonPulse {
  0%, 100% {
    box-shadow:
      0 4px 20px rgba(193, 154, 107, 0.35),
      0 0 0 0 rgba(193, 154, 107, 0.4);
  }
  50% {
    box-shadow:
      0 4px 20px rgba(193, 154, 107, 0.35),
      0 0 0 12px rgba(193, 154, 107, 0);
  }
}

@keyframes badgeBounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ========================================
   Chat Window Container
   ======================================== */
.chat-widget-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 560px;
  max-height: calc(100vh - 140px);
  background: var(--chat-bg);
  border-radius: var(--chat-radius);
  border: 1px solid var(--chat-border);
  box-shadow: var(--chat-shadow);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: all 0.4s var(--chat-transition);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.chat-widget-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ========================================
   Chat Header
   ======================================== */
.chat-widget-header {
  padding: 20px;
  background: var(--chat-card);
  border-bottom: 1px solid var(--chat-border);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.chat-widget-avatar {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--chat-accent) 0%, #a07d54 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-widget-avatar svg {
  width: 24px;
  height: 24px;
  color: #0d0d12;
}

.chat-widget-header-info {
  flex: 1;
  min-width: 0;
}

.chat-widget-header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--chat-text);
  margin: 0 0 4px 0;
  letter-spacing: -0.02em;
}

.chat-widget-header-status {
  font-size: 13px;
  color: var(--chat-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-widget-header-status::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--chat-success);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--chat-success);
  animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.chat-widget-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid var(--chat-border);
  color: var(--chat-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-widget-close:hover {
  background: var(--chat-card-hover);
  color: var(--chat-text);
  border-color: var(--chat-accent);
}

.chat-widget-close svg {
  width: 18px;
  height: 18px;
}

/* ========================================
   Welcome Screen (Pre-chat form)
   ======================================== */
.chat-widget-welcome {
  flex: 1;
  padding: 24px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.chat-widget-welcome-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--chat-text);
  margin: 0 0 8px 0;
  letter-spacing: -0.03em;
}

.chat-widget-welcome-subtitle {
  font-size: 14px;
  color: var(--chat-muted);
  margin: 0 0 28px 0;
  line-height: 1.5;
}

.chat-widget-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-widget-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-widget-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--chat-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chat-widget-input {
  padding: 14px 16px;
  background: var(--chat-card);
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  color: var(--chat-text);
  font-size: 15px;
  font-family: inherit;
  transition: all 0.2s ease;
  outline: none;
}

.chat-widget-input::placeholder {
  color: var(--chat-muted);
}

.chat-widget-input:focus {
  border-color: var(--chat-accent);
  box-shadow: 0 0 0 3px var(--chat-accent-glow);
}

.chat-widget-checkbox-group {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--chat-card);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.chat-widget-checkbox-group:hover {
  background: var(--chat-card-hover);
}

.chat-widget-checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--chat-border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  margin-top: 2px;
  appearance: none;
  -webkit-appearance: none;
}

.chat-widget-checkbox:checked {
  background: var(--chat-accent);
  border-color: var(--chat-accent);
}

.chat-widget-checkbox:checked::after {
  content: '✓';
  color: #0d0d12;
  font-size: 12px;
  font-weight: 700;
}

.chat-widget-checkbox-label {
  font-size: 13px;
  color: var(--chat-muted);
  line-height: 1.5;
}

.chat-widget-checkbox-label a {
  color: var(--chat-accent);
  text-decoration: none;
}

.chat-widget-checkbox-label a:hover {
  text-decoration: underline;
}

.chat-widget-start-btn {
  margin-top: 8px;
  padding: 16px 24px;
  background: linear-gradient(135deg, var(--chat-accent) 0%, #a07d54 100%);
  border: none;
  border-radius: 10px;
  color: #0d0d12;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.3s var(--chat-transition);
  letter-spacing: -0.01em;
}

.chat-widget-start-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(193, 154, 107, 0.4);
}

.chat-widget-start-btn:active:not(:disabled) {
  transform: translateY(0);
}

.chat-widget-start-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========================================
   Chat Screen Container
   ======================================== */
.chat-widget-chat {
  /* display controlled by JS: none/flex */
  flex-direction: column;
  flex: 1;
  min-height: 0; /* Critical for flex children to shrink */
  overflow: hidden;
}

/* ========================================
   Chat Messages Area
   ======================================== */
.chat-widget-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  min-height: 0; /* Allow shrinking */
}

.chat-widget-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-widget-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-widget-messages::-webkit-scrollbar-thumb {
  background: var(--chat-border);
  border-radius: 3px;
}

.chat-widget-messages::-webkit-scrollbar-thumb:hover {
  background: var(--chat-accent);
}

/* Message Bubbles */
.chat-message {
  max-width: 85%;
  animation: messageSlide 0.3s var(--chat-transition);
}

@keyframes messageSlide {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message-visitor {
  align-self: flex-end;
}

.chat-message-admin {
  align-self: flex-start;
}

.chat-message-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-message-visitor .chat-message-bubble {
  background: var(--chat-visitor-bg);
  color: var(--chat-text);
  border-bottom-right-radius: 4px;
}

.chat-message-admin .chat-message-bubble {
  background: var(--chat-admin-bg);
  color: #0d0d12;
  border-bottom-left-radius: 4px;
}

.chat-message-time {
  font-size: 11px;
  color: var(--chat-muted);
  margin-top: 6px;
  padding: 0 4px;
}

.chat-message-visitor .chat-message-time {
  text-align: right;
}

.chat-message-admin .chat-message-time {
  text-align: left;
}

.chat-message-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--chat-accent);
  margin-bottom: 4px;
  padding: 0 4px;
}

/* Typing Indicator */
.chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--chat-card);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.chat-typing-dot {
  width: 8px;
  height: 8px;
  background: var(--chat-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s ease-in-out infinite;
}

.chat-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ========================================
   Chat Input Area
   ======================================== */
.chat-widget-input-area {
  padding: 16px 20px;
  background: var(--chat-card);
  border-top: 1px solid var(--chat-border);
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-shrink: 0;
}

.chat-widget-textarea {
  flex: 1;
  padding: 12px 16px;
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  color: var(--chat-text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.4;
  outline: none;
  transition: all 0.2s ease;
}

.chat-widget-textarea::placeholder {
  color: var(--chat-muted);
}

.chat-widget-textarea:focus {
  border-color: var(--chat-accent);
  box-shadow: 0 0 0 3px var(--chat-accent-glow);
}

.chat-widget-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--chat-accent) 0%, #a07d54 100%);
  border: none;
  color: #0d0d12;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s var(--chat-transition);
  flex-shrink: 0;
}

.chat-widget-send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(193, 154, 107, 0.4);
}

.chat-widget-send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.chat-widget-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-widget-send-btn svg {
  width: 20px;
  height: 20px;
}

/* ========================================
   Empty State / Connection Status
   ======================================== */
.chat-widget-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
}

.chat-widget-empty-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--chat-card);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.chat-widget-empty-icon svg {
  width: 32px;
  height: 32px;
  color: var(--chat-accent);
}

.chat-widget-empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--chat-text);
  margin: 0 0 8px 0;
}

.chat-widget-empty-text {
  font-size: 14px;
  color: var(--chat-muted);
  margin: 0;
  line-height: 1.5;
}

/* ========================================
   Responsive Styles
   ======================================== */
@media (max-width: 480px) {
  .chat-widget-button {
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
  }

  .chat-widget-button svg {
    width: 24px;
    height: 24px;
  }

  .chat-widget-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }

  .chat-widget-window.open {
    border-radius: 0;
  }

  .chat-widget-header {
    padding: 16px;
  }

  .chat-widget-welcome {
    padding: 20px;
  }

  .chat-widget-messages {
    padding: 16px;
  }

  .chat-widget-input-area {
    padding: 12px 16px;
  }
}

/* ========================================
   Animations
   ======================================== */
@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.chat-widget-loading {
  background: linear-gradient(
    90deg,
    var(--chat-card) 25%,
    var(--chat-card-hover) 50%,
    var(--chat-card) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

/* Sound notification animation */
.chat-widget-button.has-notification {
  animation: notificationShake 0.5s var(--chat-transition);
}

@keyframes notificationShake {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-8deg); }
  40% { transform: rotate(8deg); }
  60% { transform: rotate(-5deg); }
  80% { transform: rotate(5deg); }
}
