/* Chat Widget Styles */
#chat-widget-container {
  position: fixed !important;
  bottom: 20px !important;
  right: 20px !important;
  z-index: 99999 !important;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
  pointer-events: auto !important;
  /* Prevent tablet touch fixes from interfering */
  --no-touch-fix: true !important;
}

/* Floating Button */
.chat-widget-float {
  width: 60px !important;
  height: 60px !important;
  background: #007bff !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3) !important;
  transition: all 0.3s ease !important;
  position: relative !important;
  pointer-events: auto !important;
  z-index: 99999 !important;
  /* Prevent tablet touch fixes from interfering */
  --no-touch-fix: true !important;
}

.chat-widget-float:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4);
}

.chat-widget-icon {
  font-size: 24px;
  color: white;
}

.chat-widget-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #dc3545;
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
}

/* Widget Container */
.chat-widget-container {
  width: 350px !important;
  height: 500px !important;
  background: white !important;
  border-radius: 12px !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  position: relative !important;
  z-index: 99999 !important;
  pointer-events: auto !important;
  /* Fix the visibility issue! */
  visibility: visible !important;
  opacity: 1 !important;
  /* Prevent tablet touch fixes from interfering */
  --no-touch-fix: true !important;
}

/* Make the selector even more specific to override any other styles */
#chat-widget-container .chat-widget-container {
  visibility: visible !important;
  opacity: 1 !important;
  display: flex !important;
}

/* Header */
.chat-widget-header {
  background: #007bff;
  color: white;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-widget-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.chat-widget-controls {
  display: flex;
  gap: 8px;
}

.chat-widget-btn {
  background: none;
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background 0.2s;
}

.chat-widget-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Content */
.chat-widget-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Tabs */
.chat-widget-tabs {
  display: flex;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
}

.chat-widget-tab {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #6c757d;
  transition: all 0.2s;
}

.chat-widget-tab.active {
  color: #007bff;
  background: white;
  border-bottom: 2px solid #007bff;
}

.chat-widget-tab:hover {
  background: #e9ecef;
}

/* Tab Content */
.chat-widget-tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* List Items */
.chat-widget-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-widget-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-widget-item:hover {
  background: #f8f9fa;
}

.chat-widget-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-widget-item-content {
  flex: 1;
  min-width: 0;
}

.chat-widget-item-name {
  font-weight: 600;
  font-size: 14px;
  color: #212529;
  margin-bottom: 2px;
}

.chat-widget-item-message {
  font-size: 13px;
  color: #6c757d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-widget-item-time {
  font-size: 12px;
  color: #adb5bd;
  white-space: nowrap;
}

/* Empty State */
.chat-widget-empty {
  text-align: center;
  padding: 40px 20px;
  color: #6c757d;
}

.chat-widget-empty .chat-widget-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.chat-widget-empty p {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.chat-widget-empty span {
  font-size: 14px;
  opacity: 0.8;
}

/* Search */
.chat-widget-search {
  margin-bottom: 16px;
}

.chat-widget-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.chat-widget-search-input:focus {
  border-color: #007bff;
}

/* Chat Header */
.chat-widget-chat-header {
  background: #f8f9fa;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #e9ecef;
}

.chat-widget-back-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: #6c757d;
  transition: background 0.2s;
}

.chat-widget-back-btn:hover {
  background: #e9ecef;
}

.chat-widget-chat-info {
  flex: 1;
}

.chat-widget-chat-name {
  font-weight: 600;
  font-size: 14px;
  color: #212529;
  margin-bottom: 2px;
}

.chat-widget-chat-status {
  font-size: 12px;
  color: #28a745;
}

/* Messages */
.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-widget-message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}

.chat-widget-message.sent {
  align-self: flex-end;
}

.chat-widget-message.received {
  align-self: flex-start;
}

.chat-widget-message-content {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
}

.chat-widget-message.sent .chat-widget-message-content {
  background: #007bff;
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-widget-message.received .chat-widget-message-content {
  background: #f1f3f4;
  color: #212529;
  border-bottom-left-radius: 4px;
}

.chat-widget-message-time {
  font-size: 11px;
  color: #adb5bd;
  margin-top: 4px;
  align-self: flex-end;
}

.chat-widget-message.received .chat-widget-message-time {
  align-self: flex-start;
}

/* Loading State */
.chat-widget-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: #6c757d;
  text-align: center;
  font-size: 14px;
}

.chat-widget-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid #007bff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 15px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Message status indicators */
.chat-widget-message.status-sending {
  opacity: 0.7;
}

.chat-widget-message.status-failed {
  color: #dc3545;
}

.chat-widget-message.status-failed::after {
  content: " ⚠️";
}

/* Input */
.chat-widget-input {
  padding: 12px 16px;
  background: #f8f9fa;
  border-top: 1px solid #e9ecef;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-widget-input-container {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.chat-widget-attach-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: #6c757d;
  transition: background 0.2s;
}

.chat-widget-attach-btn:hover {
  background: #e9ecef;
}

.chat-widget-message-input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid #e9ecef;
  border-radius: 20px;
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
  /* Ensure input is enabled and can receive text */
  background: white !important;
  color: #212529 !important;
  cursor: text !important;
  pointer-events: auto !important;
  -webkit-user-select: text !important;
  -khtml-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
  /* Prevent any interference */
  --no-touch-fix: true !important;
  touch-action: manipulation !important;
  min-height: 36px;
}

.chat-widget-message-input:focus {
  border-color: #007bff;
  /* Ensure focus state allows text input */
  background: white !important;
  color: #212529 !important;
  cursor: text !important;
  pointer-events: auto !important;
  -webkit-user-select: text !important;
  -khtml-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
}

.chat-widget-message-input:disabled {
  background: #f8f9fa !important;
  color: #6c757d !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
}

.chat-widget-send-btn {
  background: #007bff;
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s ease;
  min-width: 36px;
}

.chat-widget-send-btn:hover:not(:disabled) {
  background: #0056b3;
  transform: scale(1.05);
}

.chat-widget-send-btn:disabled,
.chat-widget-send-btn.disabled {
  background: #adb5bd;
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

/* Prevent any touch fixes on chat widget elements */
[data-chat-widget="true"],
[data-no-touch-fix="true"] {
  --no-touch-fix: true !important;
  touch-action: auto !important;
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  -khtml-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
  user-select: none !important;
}

/* Ensure chat widget elements are not affected by tablet touch fixes */
.chat-widget-container *,
.chat-widget-float * {
  --no-touch-fix: true !important;
  touch-action: auto !important;
}

/* Exception for input fields - allow text selection and input */
.chat-widget-message-input,
.chat-widget-search-input {
  --no-touch-fix: true !important;
  touch-action: auto !important;
  -webkit-user-select: text !important;
  -khtml-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
  cursor: text !important;
  pointer-events: auto !important;
}

/* Responsive */
@media (max-width: 480px) {
  .chat-widget-container {
    width: 100%;
    height: 100%;
    border-radius: 0;
    bottom: 0;
    right: 0;
  }
  
  .chat-widget-float {
    width: 50px;
    height: 50px;
  }
  
  .chat-widget-icon {
    font-size: 20px;
  }
}

/* File upload styles */
.chat-widget-input-container {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.chat-widget-files-preview {
  max-height: 120px;
  overflow-y: auto;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  background: #ffffff;
  margin-bottom: 8px;
  width: 100%;
  order: -1; /* Ensure it appears before the input container */
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  padding: 8px;
}

.chat-widget-input {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.chat-widget-attachment {
  margin: 4px 0;
}

.chat-widget-attachment-image {
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.chat-widget-attachment-image:hover {
  opacity: 0.8;
}

.chat-widget-attachment-file {
  display: flex;
  align-items: center;
  padding: 8px;
  background: #f8f9fa;
  border-radius: 8px;
  margin: 4px 0;
  cursor: pointer;
  transition: background-color 0.2s;
}

.chat-widget-attachment-file:hover {
  background: #e9ecef;
}

.chat-widget-message-text {
  margin-bottom: 4px;
}

.chat-widget-attach-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s ease;
  color: #6c757d;
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-widget-attach-btn:hover:not(:disabled) {
  background: #e9ecef;
  transform: scale(1.05);
}

.chat-widget-attach-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}