/* Customer Chat Widget Stylesheet */
:root {
  --widget-primary: #8b5cf6;
  --widget-primary-hover: #7c3aed;
  --widget-bg: #1e1b4b; /* deep violet background */
  --widget-surface: rgba(30, 27, 75, 0.85);
  --widget-text: #f8fafc;
  --widget-muted: #94a3b8;
  --widget-border: rgba(139, 92, 246, 0.2);
  --shadow-premium: 0 20px 40px -15px rgba(0, 0, 0, 0.5), 0 0 50px -10px rgba(139, 92, 246, 0.15);
}

.chat-widget-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 1000;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

.chat-mode-card {
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
}
.chat-mode-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(139, 92, 246, 0.18);
  filter: brightness(1.1);
}

/* Floating Chat Icon / Trigger */
.chat-trigger {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--widget-primary), #d946ef);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 25px -5px rgba(139, 92, 246, 0.5), 0 0 0 0 rgba(139, 92, 246, 0.4);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  animation: trigger-pulse 2.5s ease-in-out infinite;
}

.chat-trigger:hover {
  transform: scale(1.1) rotate(8deg);
  box-shadow: 0 15px 30px -5px rgba(139, 92, 246, 0.6), 0 0 20px 6px rgba(139, 92, 246, 0.35);
  animation: none;
}

.chat-trigger svg {
  width: 28px;
  height: 28px;
  transition: transform 0.3s ease;
}

.chat-trigger.active svg {
  transform: rotate(90deg);
}

/* Notification Badge */
.chat-trigger .unread-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #ef4444;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #0b0f19;
  animation: badge-bounce 0.5s ease infinite alternate;
}

/* Chat Main Window */
.chat-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 350px;
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--widget-surface);
  border: 1px solid var(--widget-border);
  border-radius: 1.25rem;
  box-shadow: var(--shadow-premium);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(20px);
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-window.active {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* Chat Header */
.chat-header {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.3), rgba(217, 70, 239, 0.1));
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--widget-border);
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--widget-primary);
  object-fit: cover;
}

.chat-header-meta h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--widget-text);
  margin: 0;
}

.chat-header-meta span {
  font-size: 0.75rem;
  color: var(--widget-muted);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
}

.status-dot.away { background: #f59e0b; }
.status-dot.busy { background: #ef4444; }
.status-dot.offline { background: #6b7280; }

.chat-header-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-header-action {
  background: rgba(255, 255, 255, 0.05);
  border: none;
  color: var(--widget-muted);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-header-action:hover {
  background: rgba(255, 255, 255, 0.15);
  color: var(--widget-text);
}

/* Chat Body (Holds views) */
.chat-body {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.chat-view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.chat-view.active-view {
  opacity: 1;
  pointer-events: all;
}

/* View 1: Pre-Chat Form */
.pre-chat-form {
  padding: 0.85rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  justify-content: flex-start;
  height: 100%;
  overflow-y: auto;
  background: radial-gradient(circle at top right, rgba(217, 70, 239, 0.05), transparent 60%);
}

.pre-chat-form::-webkit-scrollbar {
  width: 5px;
}
.pre-chat-form::-webkit-scrollbar-track {
  background: transparent;
}
.pre-chat-form::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.2);
  border-radius: 999px;
}
.pre-chat-form::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 92, 246, 0.4);
}

.pre-chat-intro h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.pre-chat-intro p {
  font-size: 0.78rem;
  color: var(--widget-muted);
  line-height: 1.35;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--widget-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input,
.form-group select {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--widget-border);
  color: white;
  padding: 0.55rem 0.75rem;
  border-radius: 0.375rem;
  outline: none;
  font-family: inherit;
  font-size: 0.825rem;
  transition: all 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--widget-primary);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.2);
  background: rgba(255, 255, 255, 0.05);
}

.form-group select option {
  background: #1e1b4b;
  color: white;
}

.btn-submit-chat {
  background: linear-gradient(135deg, var(--widget-primary), #d946ef);
  color: white;
  border: none;
  padding: 0.65rem 1.5rem;
  border-radius: 0.375rem;
  font-weight: 600;
  cursor: pointer;
  margin: 0.5rem auto 0 auto;
  font-size: 0.825rem;
  display: block;
  width: 85%;
  text-align: center;
  transition: all 0.3s ease;
  box-shadow: 0 10px 20px -10px rgba(139, 92, 246, 0.5);
}

.btn-submit-chat:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px -8px rgba(139, 92, 246, 0.6);
}

/* View 2: Live Chat Screen */
.chat-messages-container {
  flex: 1;
  padding: 0.85rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  scroll-behavior: smooth;
}

/* Chat Message Bubbles */
.message-bubble {
  max-width: 80%;
  display: flex;
  flex-direction: column;
  animation: msg-slide 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.message-bubble.visitor {
  align-self: flex-end;
}

.message-bubble.agent {
  align-self: flex-start;
}

.message-bubble.system {
  align-self: center;
  max-width: 95%;
  animation: fade-in 0.4s ease forwards;
}

.msg-sender {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--widget-muted);
  margin-bottom: 0.25rem;
  margin-left: 0.25rem;
}

.visitor .msg-sender {
  text-align: right;
  margin-right: 0.25rem;
}

.msg-text-wrapper {
  padding: 0.55rem 0.8rem;
  border-radius: 0.75rem;
  font-size: 0.78rem;
  line-height: 1.35;
  word-break: break-word;
  position: relative;
}

.visitor .msg-text-wrapper {
  background: linear-gradient(135deg, var(--widget-primary), #8b5cf6);
  color: white;
  border-bottom-right-radius: 0.25rem;
}

.agent .msg-text-wrapper {
  background: rgba(255, 255, 255, 0.06);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-bottom-left-radius: 0.25rem;
}

.system .msg-text-wrapper {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--widget-muted);
  padding: 0.4rem 1rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  text-align: center;
}

.msg-meta {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 0.25rem;
  display: flex;
  gap: 0.25rem;
  align-self: flex-end;
}

.agent .msg-meta {
  align-self: flex-start;
}

/* File Attachment UI inside message */
.attachment-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.5rem;
  border-radius: 0.5rem;
  margin-top: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.attachment-preview svg {
  width: 20px;
  height: 20px;
  color: var(--widget-primary);
}

.attachment-details {
  display: flex;
  flex-direction: column;
}

.attachment-name {
  font-size: 0.75rem;
  font-weight: 600;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-size {
  font-size: 0.65rem;
  color: var(--widget-muted);
}

/* Typing Indicator */
.typing-indicator-container {
  padding: 0.5rem 1rem;
  align-self: flex-start;
  display: none;
}

.typing-indicator-container.active {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.typing-text {
  font-size: 0.75rem;
  color: var(--widget-muted);
}

.typing-bubble {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 0.6rem 0.8rem;
  border-radius: 1rem;
  border-bottom-left-radius: 0.25rem;
  display: flex;
  align-items: center;
  gap: 4px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--widget-primary);
  animation: dot-bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

/* Chat Footer / Input Panel */
.chat-footer {
  padding: 0.55rem 0.8rem;
  border-top: 1px solid var(--widget-border);
  background: rgba(15, 23, 42, 0.3);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  position: relative;
}

.chat-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--widget-border);
  border-radius: 0.5rem;
  padding: 0.3rem 0.6rem;
  transition: border-color 0.3s ease;
}

.chat-input-wrapper:focus-within {
  border-color: var(--widget-primary);
}

.chat-input-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: white;
  font-family: inherit;
  font-size: 0.8rem;
  resize: none;
  max-height: 80px;
  height: 26px;
  padding-top: 0.3rem;
  overflow-y: auto;
}

.chat-input-actions {
  display: flex;
  gap: 0.25rem;
}

.btn-input-action {
  background: transparent;
  border: none;
  color: var(--widget-muted);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-input-action:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--widget-text);
}

.btn-input-action.active {
  color: var(--widget-primary);
}

.btn-send-message {
  background: var(--widget-primary);
  color: white;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-send-message:hover {
  background: var(--widget-primary-hover);
  transform: scale(1.05);
}

/* Emoji Popover */
.emoji-popover {
  position: absolute;
  bottom: 65px;
  right: 1rem;
  background: #1e1b4b;
  border: 1px solid var(--widget-border);
  border-radius: 0.75rem;
  padding: 0.5rem;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.25rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  z-index: 1010;
  display: none;
}

.emoji-popover.active {
  display: grid;
}

.emoji-btn {
  font-size: 1.25rem;
  background: transparent;
  border: none;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
  transition: background 0.2s ease;
}

.emoji-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* Mock File Upload Progress */
.upload-progress-container {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 0.5rem;
  padding: 0.5rem;
  border: 1px solid var(--widget-border);
  display: none;
}

.upload-progress-container.active {
  display: flex;
}

.upload-progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--widget-muted);
}

.upload-progress-bar-wrapper {
  background: rgba(255, 255, 255, 0.1);
  height: 4px;
  border-radius: 9999px;
  overflow: hidden;
}

.upload-progress-bar {
  background: var(--widget-primary);
  width: 0%;
  height: 100%;
  transition: width 0.1s linear;
}

/* View 3: Post-Chat Feedback / CSAT */
.post-chat-view {
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1.5rem;
  background: radial-gradient(circle at bottom left, rgba(217, 70, 239, 0.05), transparent 60%);
}

.feedback-success-icon {
  width: 64px;
  height: 64px;
  background: rgba(16, 185, 129, 0.1);
  border: 2px solid #10b981;
  color: #10b981;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin-bottom: 0.5rem;
  animation: scale-up 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.feedback-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.feedback-subtitle {
  font-size: 0.85rem;
  color: var(--widget-muted);
  line-height: 1.5;
}

/* Stars Rating */
.star-rating-container {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.star-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.15);
  font-size: 2rem;
  transition: transform 0.2s ease, color 0.2s ease;
}

.star-btn:hover {
  transform: scale(1.15);
}

.star-btn.selected {
  color: #fbbf24; /* amber */
}

.feedback-textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--widget-border);
  color: white;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  outline: none;
  font-family: inherit;
  font-size: 0.85rem;
  resize: none;
  height: 70px;
  transition: all 0.3s ease;
}

.feedback-textarea:focus {
  border-color: var(--widget-primary);
  background: rgba(255, 255, 255, 0.05);
}

.btn-submit-feedback {
  width: 100%;
  background: #10b981;
  color: white;
  border: none;
  padding: 0.8rem;
  border-radius: 0.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-submit-feedback:hover {
  background: #059669;
  box-shadow: 0 10px 20px -10px rgba(16, 185, 129, 0.5);
}

.btn-start-new-chat {
  background: transparent;
  border: 1px solid var(--widget-border);
  color: var(--widget-muted);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-start-new-chat:hover {
  color: var(--widget-text);
  background: rgba(255, 255, 255, 0.03);
}

/* Animations */
@keyframes badge-bounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-4px); }
}

@keyframes msg-slide {
  0% { opacity: 0; transform: translateY(10px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scale-up {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

@keyframes trigger-pulse {
  0%   { box-shadow: 0 10px 25px -5px rgba(139,92,246,0.5), 0 0 0 0 rgba(139,92,246,0.4); }
  60%  { box-shadow: 0 10px 25px -5px rgba(139,92,246,0.5), 0 0 0 14px rgba(139,92,246,0); }
  100% { box-shadow: 0 10px 25px -5px rgba(139,92,246,0.5), 0 0 0 0 rgba(139,92,246,0); }
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

.widget-trigger-label {
  position: absolute;
  top: -28px;
  left: -28px;
  width: 120px;
  height: 120px;
  pointer-events: none;
  overflow: visible;
  z-index: 9;
  animation: fadeSlideIn 0.4s ease;
}

.widget-trigger-label svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Mobile View Optimization for Chat Widget */
@media (max-width: 500px) {
  .chat-widget-container {
    bottom: 1rem !important;
    right: 1.25rem !important;
    left: auto !important;
    width: auto !important;
  }

  .widget-trigger-label {
    width: 100px !important;
    height: 100px !important;
    top: -22px !important;
    left: -22px !important;
  }
  
  .chat-window {
    width: calc(100vw - 2rem) !important;
    height: 520px !important;
    max-height: calc(100vh - 100px) !important;
    bottom: 72px !important;
    right: 0 !important;
    left: auto !important;
    border-radius: 1rem !important;
  }

  .pre-chat-form {
    padding: 0.5rem 0.85rem !important;
    gap: 0.5rem !important;
    overflow-y: hidden !important;
  }

  .pre-chat-intro {
    margin-bottom: 0.1rem !important;
  }

  .pre-chat-intro h2 {
    font-size: 0.95rem !important;
    margin-bottom: 0.1rem !important;
  }

  .pre-chat-intro p {
    font-size: 0.72rem !important;
    line-height: 1.25 !important;
  }

  .form-group {
    gap: 0.15rem !important;
  }

  .form-group label {
    font-size: 0.65rem !important;
    margin-bottom: 0.1rem !important;
  }

  .form-group input,
  .form-group select {
    padding: 0.45rem 0.6rem !important;
    font-size: 0.78rem !important;
  }

  .chat-mode-card {
    padding: 0.25rem 0.2rem !important;
    gap: 0.1rem !important;
  }

  .chat-mode-card span {
    font-size: 0.68rem !important;
  }

  .btn-submit-chat {
    padding: 0.55rem 1.25rem !important;
    margin-top: 0.25rem !important;
    font-size: 0.78rem !important;
    width: 90% !important;
  }
  
  .chat-header-avatar, #widgetHeaderLogo {
    width: 32px !important;
    height: 32px !important;
  }
  
  .chat-trigger {
    width: 56px !important;
    height: 56px !important;
  }
}
