/* TradePAT Admin Support Chat — Velonic theme */

:root {
  --tp-chat-primary: #3b30fc;
  --tp-chat-primary-hover: #2f25d4;
  --tp-chat-success: #0acf97;
  --tp-chat-danger: #fa5c7c;
  --tp-chat-bg: #ffffff;
  --tp-chat-surface: #f8f9fa;
  --tp-chat-border: #e3e6ea;
  --tp-chat-text: #313a46;
  --tp-chat-muted: #98a6ad;
  --tp-chat-shadow: 0 0 35px 0 rgba(154, 161, 171, 0.25);
}

.admin-chat-container {
  display: none !important;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 420px;
  max-width: calc(100vw - 40px);
  height: 620px;
  max-height: calc(100vh - 40px);
  background: var(--tp-chat-bg);
  border-radius: 0.5rem;
  box-shadow: var(--tp-chat-shadow);
  border: 1px solid var(--tp-chat-border);
  z-index: 10570;
  overflow: hidden;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  flex-direction: row;
  box-sizing: border-box;
}

.admin-chat-container.show {
  display: flex !important;
}

/* Sidebar */
.admin-chat-sidebar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 85vw;
  background: var(--tp-chat-bg);
  border-right: 1px solid var(--tp-chat-border);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  z-index: 9999;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.06);
  pointer-events: none;
}

.admin-chat-sidebar.open {
  transform: translateX(0);
  pointer-events: auto;
  z-index: 10010;
}

#admin-chat-toggle-sidebar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  pointer-events: auto;
}

/* Main header burger + avatar sit under the open sidebar — hide to prevent overlap */
.admin-chat-sidebar.open ~ .admin-chat-main .chat-header-info #admin-chat-toggle-sidebar,
.admin-chat-sidebar.open ~ .admin-chat-main .chat-header-info .chat-avatar {
  visibility: hidden;
  pointer-events: none;
}

.sidebar-header {
  padding: 14px 16px;
  background: var(--tp-chat-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  box-sizing: border-box;
}

.sidebar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 600;
  font-size: 0.9375rem;
  min-width: 0;
  flex: 1;
}

.sidebar-title i,
.sidebar-title .material-icons {
  font-size: 1.125rem;
  flex-shrink: 0;
  line-height: 1;
}

.sidebar-title span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-actions {
  display: flex;
  gap: 4px;
}

.sidebar-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  border-radius: 0.375rem;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}

.sidebar-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.sidebar-search {
  padding: 12px;
  border-bottom: 1px solid var(--tp-chat-border);
}

.sidebar-search input {
  width: 100%;
  box-sizing: border-box;
  background: var(--tp-chat-surface) !important;
  border: 1px solid var(--tp-chat-border);
  border-radius: 0.375rem;
  padding: 8px 12px;
  color: var(--tp-chat-text) !important;
  font-size: 0.875rem;
  outline: none;
}

.sidebar-search input::placeholder {
  color: var(--tp-chat-muted) !important;
}

.sidebar-search input:focus {
  border-color: var(--tp-chat-primary);
  box-shadow: 0 0 0 0.2rem rgba(59, 48, 252, 0.12);
}

.sidebar-users {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-users::-webkit-scrollbar {
  width: 6px;
}

.sidebar-users::-webkit-scrollbar-thumb {
  background: #dee2e6;
  border-radius: 3px;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
}

.user-item:hover {
  background: rgba(59, 48, 252, 0.06);
}

.user-item.active {
  background: rgba(59, 48, 252, 0.1);
}

.user-item-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tp-chat-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  font-size: 0.875rem;
  font-weight: 700;
}

.user-item-name {
  color: var(--tp-chat-text);
  font-weight: 600;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-item-status {
  font-size: 0.75rem;
  color: var(--tp-chat-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.user-item-unread {
  background: var(--tp-chat-danger);
  color: #fff;
  border-radius: 50%;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  font-weight: 700;
  flex-shrink: 0;
  padding: 0 4px;
}

.no-users-message,
.admin-chat-empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--tp-chat-muted);
}

.no-users-message i,
.admin-chat-empty-state i {
  font-size: 2.5rem;
  margin-bottom: 12px;
  display: block;
  color: var(--tp-chat-primary);
  opacity: 0.35;
}

.no-users-message p,
.admin-chat-empty-state p {
  margin: 0;
  font-size: 0.875rem;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--tp-chat-border);
  background: var(--tp-chat-surface);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--tp-chat-muted);
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-indicator.connected {
  background: var(--tp-chat-success);
}

.status-indicator.connecting {
  background: #f9bc0d;
  animation: tp-chat-pulse 1s ease-in-out infinite;
}

.status-indicator.disconnected {
  background: var(--tp-chat-danger);
}

@keyframes tp-chat-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Main chat */
.admin-chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

.chat-header-modern {
  background: var(--tp-chat-primary);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: none;
  flex-shrink: 0;
  min-height: 64px;
  box-sizing: border-box;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.chat-header-text {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.chat-name {
  color: #fff;
  font-weight: 600;
  font-size: 0.9375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tp-chat-success);
  display: inline-block;
}

.status-text {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.75rem;
}

.chat-header-actions {
  display: flex;
  gap: 4px;
}

.chat-header-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 0;
  border-radius: 0.375rem;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.chat-header-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.chat-header-btn .material-icons,
.chat-header-btn i {
  font-size: 1.125rem;
}

.chat-messages-modern {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--tp-chat-surface);
  min-height: 0;
  scroll-behavior: smooth;
}

.chat-messages-modern::-webkit-scrollbar {
  width: 6px;
}

.chat-messages-modern::-webkit-scrollbar-thumb {
  background: #dee2e6;
  border-radius: 3px;
}

.message-bubble {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  max-width: 82%;
}

.message-bubble.new-message {
  animation: tp-slide-in 0.25s ease-out;
}

@keyframes tp-slide-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-bubble.admin {
  margin-left: auto;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--tp-chat-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.message-bubble.admin .message-avatar {
  background: var(--tp-chat-success);
}

.message-sender {
  color: var(--tp-chat-muted);
  font-size: 0.6875rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.message-bubble.admin .message-sender {
  text-align: right;
}

.message-text {
  background: #fff;
  color: var(--tp-chat-text);
  border: 1px solid var(--tp-chat-border);
  border-radius: 0.5rem;
  padding: 8px 12px;
  font-size: 0.875rem;
  line-height: 1.45;
  word-wrap: break-word;
}

.message-bubble.admin .message-text {
  background: var(--tp-chat-primary);
  color: #fff;
  border-color: transparent;
  border-radius: 0.5rem 0.5rem 0.125rem 0.5rem;
}

.message-bubble.user .message-text {
  border-radius: 0.5rem 0.5rem 0.5rem 0.125rem;
}

.message-time {
  font-size: 0.6875rem;
  color: var(--tp-chat-muted);
  margin-top: 4px;
}

.message-bubble.admin .message-time {
  text-align: right;
}

.typing-dots {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--tp-chat-border);
  border-radius: 0.5rem;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tp-chat-muted);
  animation: tp-typing 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes tp-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-input-modern {
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid var(--tp-chat-border);
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-input-icon {
  background: none;
  border: none;
  color: var(--tp-chat-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-input-icon:hover {
  background: var(--tp-chat-surface);
  color: var(--tp-chat-primary);
}

.chat-input-container {
  position: relative;
  flex: 1;
}

.chat-input-field {
  width: 100%;
  background: var(--tp-chat-surface) !important;
  border: 1px solid var(--tp-chat-border) !important;
  color: var(--tp-chat-text) !important;
  font-size: 0.875rem;
  padding: 10px 14px;
  border-radius: 0.375rem;
  outline: none;
  box-sizing: border-box;
}

.chat-input-field:focus {
  border-color: var(--tp-chat-primary) !important;
  box-shadow: 0 0 0 0.2rem rgba(59, 48, 252, 0.12);
}

.chat-input-field::placeholder {
  color: var(--tp-chat-muted) !important;
}

.chat-send-btn {
  background: var(--tp-chat-primary);
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 10px;
  border-radius: 0.375rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.chat-send-btn:hover {
  background: var(--tp-chat-primary-hover);
}

.emoji-picker-modern {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: #fff;
  border: 1px solid var(--tp-chat-border);
  border-radius: 0.5rem;
  box-shadow: var(--tp-chat-shadow);
  padding: 10px;
  z-index: 10001;
  max-width: 280px;
  display: none;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.emoji-picker-modern.show {
  display: flex;
  visibility: visible;
  opacity: 1;
}

.emoji-item {
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 0.25rem;
}

.emoji-item:hover {
  background: var(--tp-chat-surface);
}

/* Settings */
.admin-chat-settings {
  position: absolute;
  inset: 0;
  background: rgba(49, 58, 70, 0.45);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-content {
  background: #fff;
  border-radius: 0.5rem;
  padding: 1.25rem;
  max-width: 360px;
  width: 90%;
  box-shadow: var(--tp-chat-shadow);
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--tp-chat-border);
}

.settings-header h3 {
  margin: 0;
  color: var(--tp-chat-text);
  font-size: 1rem;
  font-weight: 600;
}

.settings-close-btn {
  background: var(--tp-chat-surface);
  border: none;
  color: var(--tp-chat-text);
  cursor: pointer;
  padding: 6px;
  border-radius: 0.375rem;
}

.settings-item {
  margin-bottom: 16px;
}

.settings-item label {
  color: var(--tp-chat-text);
  font-size: 0.875rem;
}

.file-preview {
  background: var(--tp-chat-surface);
  border-radius: 0.375rem;
  padding: 8px 12px;
}

.file-name {
  color: var(--tp-chat-text);
}

.file-size {
  color: var(--tp-chat-muted);
}

/* Floating launcher */
.admin-floating-chat-icon-modern {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10560;
  cursor: pointer;
  display: block !important;
  transition: transform 0.2s ease;
}

.admin-floating-chat-icon-wrapper {
  position: relative;
  width: 56px;
  height: 56px;
}

.admin-floating-chat-icon-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--tp-chat-primary);
  opacity: 0.25;
  animation: tp-fab-pulse 2s ease-in-out infinite;
}

.admin-floating-chat-icon-button {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--tp-chat-primary);
  box-shadow: 0 4px 16px rgba(59, 48, 252, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.admin-floating-chat-icon-button i {
  color: #fff;
  font-size: 1.5rem;
}

.admin-floating-chat-icon-modern:hover {
  transform: translateY(-2px);
}

.admin-floating-chat-icon-modern:hover .admin-floating-chat-icon-button {
  box-shadow: 0 8px 24px rgba(59, 48, 252, 0.45);
  transform: scale(1.04);
}

@keyframes tp-fab-pulse {
  0%, 100% { transform: scale(1); opacity: 0.25; }
  50% { transform: scale(1.15); opacity: 0; }
}

@media (max-width: 768px) {
  .admin-chat-container {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    bottom: 0 !important;
    right: 0 !important;
    border-radius: 0 !important;
  }

  .admin-chat-sidebar {
    width: 85vw !important;
    max-width: 300px !important;
  }

  .message-bubble {
    max-width: 88%;
  }

  .admin-floating-chat-icon-modern {
    bottom: 20px !important;
    right: 20px !important;
  }
}
