/* Chat Widget Styles */

:root {
  --chat-primary: #3b82f6;
  --chat-primary-hover: #2563eb;
  --chat-bg: #ffffff;
  --chat-bg-subtle: #f3f4f6;
  --chat-text: #1f2937;
  --chat-text-subtle: #6b7280;
  --chat-border: #e5e7eb;
  --chat-message-guest-bg: #3b82f6;
  --chat-message-guest-text: #ffffff;
  --chat-message-nick-bg: #f3f4f6;
  --chat-message-nick-text: #1f2937;
  --chat-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

html.dark {
  --chat-primary: #60a5fa;
  --chat-primary-hover: #3b82f6;
  --chat-bg: #1f2937;
  --chat-bg-subtle: #374151;
  --chat-text: #f3f4f6;
  --chat-text-subtle: #9ca3af;
  --chat-border: #4b5563;
  --chat-message-guest-bg: #3b82f6;
  --chat-message-guest-text: #ffffff;
  --chat-message-nick-bg: #374151;
  --chat-message-nick-text: #f3f4f6;
  --chat-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

/* Container */
.chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Toggle Button */
.chat-button {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--chat-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--chat-shadow);
  transition: transform 0.2s ease, background-color 0.2s ease;
  position: relative;
}

.chat-button:hover {
  transform: scale(1.05);
  background: var(--chat-primary-hover);
}

.chat-button-hidden {
  display: none;
}

.chat-button svg {
  width: 24px;
  height: 24px;
  fill: white;
}

/* Notification Badge */
.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-badge.hidden {
  display: none;
}

.chat-badge::after {
  content: "";
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
}

/* Panel */
.chat-panel {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 375px;
  max-width: calc(100vw - 40px);
  height: 500px;
  max-height: calc(100vh - 100px);
  background: var(--chat-bg);
  border-radius: 16px;
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-panel-hidden {
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
}

.chat-panel-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Header */
.chat-header {
  padding: 16px;
  background: var(--chat-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.2);
}

.chat-header-text h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.chat-header-text p {
  margin: 2px 0 0;
  font-size: 12px;
  opacity: 0.9;
}

.chat-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.chat-close svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

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

.chat-messages:empty::before {
  content: "Send a message to start chatting!";
  color: var(--chat-text-subtle);
  text-align: center;
  padding: 40px 20px;
  font-size: 14px;
}

/* Message Bubbles */
.chat-message {
  max-width: 85%;
  animation: chatMessageIn 0.2s ease;
}

@keyframes chatMessageIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

.chat-message-content {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

.chat-message-guest .chat-message-content {
  background: var(--chat-message-guest-bg);
  color: var(--chat-message-guest-text);
  border-bottom-right-radius: 4px;
}

.chat-message-nick .chat-message-content {
  background: var(--chat-message-nick-bg);
  color: var(--chat-message-nick-text);
  border-bottom-left-radius: 4px;
}

/* Input Area */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-bg);
}

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

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--chat-border);
  border-radius: 24px;
  font-size: 14px;
  background: var(--chat-bg);
  color: var(--chat-text);
  outline: none;
  transition: border-color 0.2s;
}

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

.chat-input::placeholder {
  color: var(--chat-text-subtle);
}

.chat-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--chat-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, transform 0.1s;
}

.chat-send:hover {
  background: var(--chat-primary-hover);
}

.chat-send:active {
  transform: scale(0.95);
}

.chat-send svg {
  width: 18px;
  height: 18px;
  fill: white;
}

/* Mobile Responsive */
@media (max-width: 480px) {
  /* Lock body scroll when chat is open */
  body.chat-open {
    overflow: hidden;
    touch-action: none;
  }

  .chat-widget {
    bottom: 16px;
    right: 16px;
  }

  .chat-button {
    width: 56px;
    height: 56px;
  }

  /* Full-screen panel on mobile */
  .chat-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100dvw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border-radius: 0;
  }

  /* Fallback for browsers without dvh support */
  @supports not (height: 100dvh) {
    .chat-panel {
      height: -webkit-fill-available;
    }
  }

  /* Larger header for mobile */
  .chat-header {
    padding: 16px 20px;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    flex-shrink: 0;
  }

  /* Larger close button for easy tapping (min 44px touch target) */
  .chat-close {
    width: 44px;
    height: 44px;
    padding: 10px;
  }

  .chat-close svg {
    width: 24px;
    height: 24px;
  }

  /* More padding in messages area */
  .chat-messages {
    padding: 16px 20px;
  }

  /* Larger input area for mobile */
  .chat-input-area {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
  }

  .chat-input {
    padding: 14px 18px;
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  /* Larger send button for easy tapping */
  .chat-send {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
  }

  .chat-send svg {
    width: 22px;
    height: 22px;
  }

  /* Larger message bubbles for readability */
  .chat-message-content {
    padding: 12px 16px;
    font-size: 16px;
  }
}
