/* =========================================
   X78 Chat - Custom Styles
   ========================================= */

/* ----- Reset & Base ----- */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

#app {
  height: 100%;
}

/* ----- Scrollbar Styling ----- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

/* ----- Chat Message Bubbles ----- */
.msg-row {
  margin-bottom: 8px;
}

.msg-row-right {
  text-align: right;
}

.msg-wrap {
  display: inline-block;
  max-width: 75%;
  text-align: left;
}

.msg-agent {
  background-color: #dbeafe;
  border-radius: 12px 12px 4px 12px;
  padding: 8px 12px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.msg-contact {
  background-color: #f3f4f6;
  border-radius: 12px 12px 12px 4px;
  padding: 8px 12px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.msg-system {
  background-color: #fef3c7;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.75rem;
  color: #92400e;
  text-align: center;
  max-width: 90%;
  margin: 4px auto;
}

/* Message timestamp */
.msg-time {
  font-size: 0.65rem;
  color: #9ca3af;
  margin-top: 2px;
}

/* ----- Sidebar ----- */
.sidebar-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  border-left: 3px solid transparent;
}

.sidebar-item:hover {
  background-color: #f1f5f9;
}

.sidebar-item.active {
  background-color: #eff6ff;
  border-left-color: #3b82f6;
}

.sidebar-item.active .sidebar-item-title {
  color: #1d4ed8;
  font-weight: 600;
}

/* Conversation list item */
.conversation-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  transition: background-color 0.15s ease;
}

.conversation-item:hover {
  background-color: #f8fafc;
}

.conversation-item.active {
  background-color: #eff6ff;
}

.conversation-item .unread-badge {
  background-color: #3b82f6;
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* ----- Typing Indicator ----- */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 8px 14px;
  background-color: #f3f4f6;
  border-radius: 12px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background-color: #9ca3af;
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}

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

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

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-6px);
  }
}

/* ----- Toast Notifications ----- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}

.toast {
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: toast-slide-in 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
  font-size: 0.875rem;
}

.toast-success {
  background-color: #10b981;
}

.toast-error {
  background-color: #ef4444;
}

.toast-info {
  background-color: #3b82f6;
}

.toast-warning {
  background-color: #f59e0b;
}

.toast.removing {
  animation: toast-slide-out 0.3s ease-in forwards;
}

@keyframes toast-slide-in {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes toast-slide-out {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* ----- Modal Overlay ----- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: modal-fade-in 0.2s ease-out;
}

.modal-content {
  background-color: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  max-width: 520px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  animation: modal-scale-in 0.2s ease-out;
}

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

@keyframes modal-scale-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ----- Status Indicator Dots ----- */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  border: 2px solid white;
}

.status-dot.online {
  background-color: #22c55e;
}

.status-dot.offline {
  background-color: #9ca3af;
}

.status-dot.busy {
  background-color: #eab308;
}

.status-dot.away {
  background-color: #f97316;
}

.status-dot-sm {
  width: 8px;
  height: 8px;
  border-width: 1.5px;
}

/* ----- Widget Preview ----- */
.widget-preview {
  width: 360px;
  height: 520px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background-color: white;
}

.widget-preview-header {
  padding: 16px 20px;
  color: white;
  display: flex;
  align-items: center;
  gap: 12px;
}

.widget-preview-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background-color: #f9fafb;
}

.widget-preview-input {
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  gap: 8px;
}

.widget-bubble {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: transform 0.2s ease;
}

.widget-bubble:hover {
  transform: scale(1.1);
}

/* ----- Loading Spinner ----- */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e5e7eb;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-sm {
  width: 18px;
  height: 18px;
  border-width: 2px;
}

.spinner-lg {
  width: 48px;
  height: 48px;
  border-width: 4px;
}

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

/* Full-page loading state */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  color: #6b7280;
}

/* ----- Avatar ----- */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  color: white;
  flex-shrink: 0;
  text-transform: uppercase;
}

.avatar-sm {
  width: 32px;
  height: 32px;
  font-size: 0.75rem;
}

.avatar-lg {
  width: 48px;
  height: 48px;
  font-size: 1rem;
}

.avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* ----- Chat Area ----- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.chat-input-area {
  border-top: 1px solid #e5e7eb;
  padding: 12px 16px;
  background-color: white;
}

.chat-input-area textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 8px 12px;
  resize: none;
  font-size: 0.875rem;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s ease;
}

.chat-input-area textarea:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

/* ----- Empty States ----- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #9ca3af;
  gap: 12px;
  padding: 32px;
  text-align: center;
}

.empty-state svg {
  width: 64px;
  height: 64px;
  opacity: 0.5;
}

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  outline: none;
}

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

.btn-primary {
  background-color: #3b82f6;
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background-color: #2563eb;
}

.btn-secondary {
  background-color: #f1f5f9;
  color: #475569;
}

.btn-secondary:hover:not(:disabled) {
  background-color: #e2e8f0;
}

.btn-danger {
  background-color: #ef4444;
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background-color: #dc2626;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
}

.btn-icon {
  padding: 6px;
  border-radius: 6px;
  background: transparent;
  color: #6b7280;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease;
}

.btn-icon:hover {
  background-color: #f1f5f9;
  color: #374151;
}

/* ----- Badge ----- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
}

.badge-blue {
  background-color: #dbeafe;
  color: #1d4ed8;
}

.badge-green {
  background-color: #dcfce7;
  color: #15803d;
}

.badge-red {
  background-color: #fee2e2;
  color: #b91c1c;
}

.badge-yellow {
  background-color: #fef3c7;
  color: #92400e;
}

.badge-gray {
  background-color: #f3f4f6;
  color: #4b5563;
}

/* ----- Dropdown Menu ----- */
.dropdown-menu {
  position: absolute;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  border: 1px solid #e5e7eb;
  padding: 4px 0;
  z-index: 50;
  min-width: 180px;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 0.875rem;
  color: #374151;
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.dropdown-item:hover {
  background-color: #f3f4f6;
}

.dropdown-divider {
  height: 1px;
  background-color: #e5e7eb;
  margin: 4px 0;
}

/* ----- Form Elements ----- */
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 4px;
}

.form-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.form-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.form-input::placeholder {
  color: #9ca3af;
}

.form-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.875rem;
  outline: none;
  background-color: white;
  cursor: pointer;
}

.form-select:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

/* ----- Tabs ----- */
.tab-bar {
  display: flex;
  border-bottom: 1px solid #e5e7eb;
}

.tab-item {
  padding: 10px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s ease;
}

.tab-item:hover {
  color: #374151;
}

.tab-item.active {
  color: #3b82f6;
  border-bottom-color: #3b82f6;
}

/* ----- Tag / Chip ----- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background-color: #e5e7eb;
  border-radius: 4px;
  font-size: 0.75rem;
  color: #4b5563;
}

.tag-remove {
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.1s;
}

.tag-remove:hover {
  opacity: 1;
}

/* ----- Responsive Adjustments ----- */
@media (max-width: 768px) {
  .sidebar-desktop {
    display: none;
  }

  .sidebar-mobile {
    position: fixed;
    inset: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar-mobile.open {
    transform: translateX(0);
  }

  .msg-wrap {
    max-width: 85%;
  }

  .widget-preview {
    width: 100%;
    height: 400px;
  }

  .modal-content {
    width: 95%;
    max-height: 90vh;
  }

  .toast-container {
    left: 16px;
    right: 16px;
    max-width: none;
  }
}

@media (max-width: 640px) {
  .conversation-list-panel {
    width: 100% !important;
  }

  .chat-panel {
    position: fixed;
    inset: 0;
    z-index: 50;
  }
}

/* ----- Utility ----- */
.truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.no-select {
  user-select: none;
  -webkit-user-select: none;
}

/* Fade transition */
.fade-in {
  animation: fade-in 0.2s ease-out;
}

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

/* Pulse for unread indicator */
.pulse {
  animation: pulse-ring 2s ease-in-out infinite;
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(59, 130, 246, 0); }
  100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}
