/**
 * AI Chatbot Widget Styles
 *
 * @package DemocraticServices
 * @since 2.6.0
 */

/* CSS Variables for Chatbot - GOV.UK Colors */
:root {
  --color-white: #ffffff;
  /* --color-gov-primary inherited from theme Customizer */
  /* --color-gov-primary-dark inherited from theme Customizer */
  --color-gov-text: #0b0c0c;
  --color-gray-50: #f8f8f8;
  --color-gray-200: #e5e7eb;
  --color-gray-300: #b1b4b6;
  --color-gray-400: #8a9094;
  --color-text-primary: #0b0c0c;
  --color-text-muted: #505a5f;
  --color-error: #d4351c;
  --color-error-light: #f8d7da;
}

/* Screen reader only - for accessibility labels */
#democratic-chatbot-container .sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Chatbot Container */
#democratic-chatbot-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
    Cantarell, "Helvetica Neue", sans-serif;
}

/* Toggle Button */
.chatbot-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--color-gov-primary);
  border: none;
  box-shadow: 0 4px 20px rgba(11, 12, 12, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  position: relative;
}

.chatbot-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(11, 12, 12, 0.5);
}

.chatbot-toggle:active {
  transform: scale(0.95);
}

.chatbot-toggle svg {
  width: 28px;
  height: 28px;
  color: #ffffff;
  stroke: #ffffff !important;
  fill: none;
  transition: opacity 0.2s ease;
}

.chatbot-toggle .chatbot-icon {
  opacity: 1;
}

.chatbot-toggle .chatbot-close-icon {
  position: absolute;
  opacity: 0;
}

.chatbot-toggle.open .chatbot-icon {
  opacity: 0;
}

.chatbot-toggle.open .chatbot-close-icon {
  opacity: 1;
}

/* Chat Window */
.chatbot-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--color-white);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  display: none;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.chatbot-window.chatbot-visible {
  display: flex;
  opacity: 1;
}

/* Header */
.chatbot-header {
  background: var(--color-gov-primary);
  color: #ffffff !important;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chatbot-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #ffffff !important;
}

.chatbot-header-actions {
  display: flex;
  gap: 8px;
}

.chatbot-minimize,
.chatbot-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.chatbot-minimize:hover,
.chatbot-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.chatbot-minimize svg,
.chatbot-close svg {
  width: 18px;
  height: 18px;
  color: #ffffff;
  stroke: #ffffff !important;
  fill: none;
}

/* Messages Area */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--color-gray-50);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Individual Message */
.chatbot-message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: fadeIn 0.3s ease;
}

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

.bot-message {
  align-self: flex-start;
}

.user-message {
  align-self: flex-end;
}

.message-content {
  padding: 12px 16px;
  border-radius: 12px;
  word-wrap: break-word;
  line-height: 1.6;
  font-size: 14px;
  white-space: pre-line;
}

.bot-message .message-content {
  background: var(--color-white);
  color: var(--color-text-primary);
  color: #0b0c0c !important;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.user-message .message-content {
  background: var(--color-gov-primary);
  color: var(--color-white);
  border-bottom-right-radius: 4px;
}

.error-message .message-content {
  background: var(--color-error-light);
  color: var(--color-error);
  border: 1px solid var(--color-error-light);
}

.message-timestamp {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.user-message .message-timestamp {
  text-align: right;
}

/* Typing Indicator */
.typing-indicator .message-content {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--color-gray-400);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}

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

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

@keyframes typingBounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-10px);
  }
}

/* Sources */
.chatbot-sources {
  background: var(--color-white);
  padding: 12px;
  border-radius: 8px;
  border-left: 3px solid var(--color-gov-primary);
  margin: 0;
  max-width: 80%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.sources-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-gov-primary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chatbot-sources ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.chatbot-sources li {
  margin: 4px 0;
  padding: 0;
}

.chatbot-sources a {
  color: var(--color-gov-primary);
  text-decoration: none;
  font-size: 13px;
  transition: color 0.2s ease;
}

.chatbot-sources a:hover {
  color: var(--color-gov-primary-dark);
  text-decoration: underline;
}

/* Input Container */
.chatbot-input-container {
  display: flex;
  gap: 10px;
  padding: 16px;
  background: var(--color-white);
  border-top: 1px solid var(--color-gray-200);
  flex-shrink: 0;
}

.chatbot-input {
  flex: 1;
  padding: 10px 12px;
  border: 2px solid var(--color-gray-200);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.2s ease;
  max-height: 120px;
  overflow-y: auto;
  background: var(--color-white);
  color: var(--color-text-primary);
}

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

.chatbot-send {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--color-gov-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chatbot-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(11, 12, 12, 0.3);
}

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

.chatbot-send svg {
  width: 20px;
  height: 20px;
  color: #ffffff;
  stroke: #ffffff !important;
  fill: none;
}

/* Scrollbar Styling */
.chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--color-gray-300);
  border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: var(--color-gray-400);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  #democratic-chatbot-container {
    bottom: 10px;
    right: 10px;
  }

  .chatbot-window {
    width: calc(100vw - 20px);
    height: calc(100vh - 100px);
    bottom: 70px;
    right: -10px;
  }

  .chatbot-toggle {
    width: 56px;
    height: 56px;
  }

  .chatbot-toggle svg {
    width: 24px;
    height: 24px;
  }
}

/* Accessibility */
.chatbot-toggle:focus,
.chatbot-send:focus,
.chatbot-input:focus,
.chatbot-minimize:focus,
.chatbot-close:focus {
  outline: 2px solid var(--color-focus-outline);
  outline-offset: 2px;
}

/* Print Hiding */
@media print {
  #democratic-chatbot-container {
    display: none !important;
  }
}
