/* Chatbot Widget Styles */
/* Matches existing Bridge Basketball website design patterns */

/* CSS Variables - using existing site colors */
:root {
  --chat-primary: var(--color-primary, #c13a34);
  --chat-primary-contrast: var(--color-primary-contrast, #ffffff);
  --chat-surface: var(--color-surface, #ffffff);
  --chat-text: var(--color-text, #1f1f1f);
  --chat-muted: var(--color-muted, #5a5a5a);
  --chat-border: var(--color-border, #d8d2cf);
  --chat-bg: var(--color-bg, #f5f5f5);
  --chat-shadow: rgba(0, 0, 0, 0.1);
  --chat-shadow-hover: rgba(0, 0, 0, 0.15);
}

/* Fallback colors if CSS variables are not available */
.chatbot-widget {
  --chat-primary: #c13a34;
  --chat-primary-contrast: #ffffff;
  --chat-surface: #ffffff;
  --chat-text: #1f1f1f;
  --chat-muted: #5a5a5a;
  --chat-border: #d8d2cf;
  --chat-bg: #f5f5f5;
  --chat-shadow: rgba(0, 0, 0, 0.1);
  --chat-shadow-hover: rgba(0, 0, 0, 0.15);
}

/* Screen Reader Only - Accessibility */
.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;
}

/* Main Widget Container */
.chatbot-widget {
  position: fixed !important;
  bottom: 20px !important;
  right: 20px !important;
  z-index: 10000 !important;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Ensure chat interface is hidden by default on mobile */
@media (max-width: 768px) {
  .chat-interface {
    display: none !important;
  }
}

/* Ensure chat interface is hidden by default on all devices */
.chat-interface {
  display: none !important;
}

.chat-interface.open {
  display: flex !important;
}

/* Floating Chat Bubble */
.chat-bubble {
  width: 60px;
  height: 60px;
  background: var(--chat-primary);
  color: var(--chat-primary-contrast);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--chat-shadow);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  touch-action: manipulation;
}

.chat-bubble:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px var(--chat-shadow-hover);
}

.chat-bubble:focus {
  outline: 2px solid var(--chat-primary);
  outline-offset: 2px;
}

.chat-bubble-icon {
  margin-bottom: 0;
}

/* Chat Interface */
.chat-interface {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 350px;
  height: 500px;
  background: var(--chat-surface);
  border-radius: 16px;
  box-shadow: 0 8px 32px var(--chat-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: chatSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: calc(100vh - 120px);
  transform-origin: bottom right;
  touch-action: pan-y;
}

.chat-interface.open {
  display: flex;
}

@keyframes chatSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Chat Header */
.chat-header {
  background: var(--chat-primary);
  color: var(--chat-primary-contrast);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 16px 16px 0 0;
  position: relative;
  z-index: 10;
}

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

.chat-header-avatar {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-icon {
  font-size: 20px;
}

.chat-header-info h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
}

.chat-header-info p {
  margin: 2px 0 0 0;
  font-size: 12px;
  opacity: 0.9;
  line-height: 1.2;
}

.chat-action-btn {
  background: none;
  border: none;
  color: var(--chat-primary-contrast);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.2s ease;
  position: relative;
  z-index: 100;
  pointer-events: auto;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.05);
}

.chat-action-btn:active {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0.95);
}

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

.message {
  display: flex;
  gap: 12px;
  max-width: 100%;
}

.message.user-message {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-message .message-avatar {
  background: var(--chat-primary);
  color: var(--chat-primary-contrast);
}

.ai-message .message-avatar {
  background: var(--chat-bg);
  color: var(--chat-text);
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-text {
  background: var(--chat-bg);
  padding: 12px 16px;
  border-radius: 18px;
  border-top-left-radius: 4px;
  color: var(--chat-text);
  word-wrap: break-word;
  line-height: 1.4;
}

.user-message .message-text {
  background: var(--chat-primary);
  color: var(--chat-primary-contrast);
  border-radius: 18px;
  border-top-right-radius: 4px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  color: var(--chat-muted);
  font-size: 14px;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.dot {
  width: 8px;
  height: 8px;
  background: var(--chat-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

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

.chat-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
}

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

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

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

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

.chat-send-btn:hover {
  transform: scale(1.05);
}

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

.chat-input-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--chat-muted);
}



/* Error Display */
.chat-error {
  position: absolute;
  bottom: 80px;
  right: 0;
  background: #fee;
  border: 1px solid #fcc;
  color: #c33;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 300px;
  animation: errorSlideIn 0.3s ease;
}

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

.error-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.error-icon {
  font-size: 16px;
}

.error-retry-btn {
  background: #c33;
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  margin-left: auto;
}

.error-retry-btn:hover {
  background: #a22;
}

/* Responsive Design */
@media (max-width: 768px) {
  .chatbot-widget {
    bottom: 10px;
    right: 10px;
  }
  
  .chat-interface {
    width: 320px;
    height: 400px;
    bottom: 80px;
    right: 10px;
    border-radius: 12px;
    max-width: calc(100vw - 20px);
    max-height: calc(100vh - 120px);
    /* Preserve display property - don't override it */
  }
  
  .chat-header {
    border-radius: 12px 12px 0 0;
  }
}

@media (max-width: 480px) {
  .chat-bubble {
    width: 56px;
    height: 56px;
  }
  
  .chat-bubble-text {
    font-size: 9px;
  }
  
  .chat-interface {
    width: 300px;
    height: 350px;
    bottom: 70px;
    right: 10px;
    max-width: calc(100vw - 20px);
    max-height: calc(100vh - 100px);
    /* Preserve display property - don't override it */
  }
}

/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
  .chat-interface,
  .chat-bubble,
  .chat-send-btn {
    animation: none;
    transition: none;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  .chat-bubble {
    border: 2px solid var(--chat-primary-contrast);
  }
  
  .chat-interface {
    border: 2px solid var(--chat-text);
  }
  
  .message-text {
    border: 1px solid var(--chat-border);
  }
}

/* Demo question buttons */
.demo-questions {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.demo-question-btn {
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  padding: 12px 16px;
  text-align: left;
  font-size: 14px;
  color: var(--chat-text);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.demo-question-btn:hover {
  background: var(--chat-primary);
  color: var(--chat-primary-contrast);
  border-color: var(--chat-primary);
}

.demo-question-btn:focus {
  outline: 2px solid var(--chat-primary);
  outline-offset: 2px;
}

/* Prevent keyboard from opening on bubble click */
.chat-bubble {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.chat-bubble:focus {
  outline: 2px solid var(--chat-primary);
  outline-offset: 2px;
}

/* Demo question buttons */
.demo-questions {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.demo-question-btn {
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  padding: 12px 16px;
  text-align: left;
  font-size: 14px;
  color: var(--chat-text);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.demo-question-btn:hover {
  background: var(--chat-primary);
  color: var(--chat-primary-contrast);
  border-color: var(--chat-primary);
}

.demo-question-btn:focus {
  outline: 2px solid var(--chat-primary);
  outline-offset: 2px;
}

/* Prevent keyboard from opening on bubble click */
.chat-bubble {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.chat-bubble:focus {
  outline: 2px solid var(--chat-primary);
  outline-offset: 2px;
}

/* Typing indicator */
.typing-indicator .typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-indicator .typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--chat-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator .typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator .typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .chatbot-widget {
    bottom: 16px;
    right: 16px;
  }
  
  .chat-bubble {
    width: 56px;
    height: 56px;
  }
  
  .chat-interface {
    width: calc(100vw - 32px);
    max-width: 400px;
    height: 450px;
    bottom: 80px;
    right: 16px;
    left: 16px;
    margin: 0 auto;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
  }
  
  .chat-messages {
    padding: 12px;
    gap: 12px;
  }
  
  .chat-input-container {
    padding: 12px;
  }
  
  .chat-input-wrapper {
    gap: 8px;
  }
  
  .chat-input {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 12px 16px;
  }
  
  .chat-send {
    width: 44px;
    height: 44px;
  }
  
  .demo-questions {
    padding: 12px;
    gap: 6px;
  }
  
  .demo-question-btn {
    padding: 10px 14px;
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .chatbot-widget {
    bottom: 12px;
    right: 12px;
  }
  
  .chat-bubble {
    width: 52px;
    height: 52px;
  }
  
  .chat-interface {
    width: calc(100vw - 24px);
    height: 400px;
    bottom: 70px;
    right: 12px;
    left: 12px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
  }
  
  .chat-header {
    padding: 12px;
  }
  
  .chat-title {
    font-size: 16px;
  }
  
  .chat-subtitle {
    font-size: 12px;
  }
  
  .chat-messages {
    padding: 10px;
    gap: 10px;
  }
  
  .chat-input-container {
    padding: 10px;
  }
  
  .chat-input {
    padding: 10px 14px;
    font-size: 16px;
  }
  
  .chat-send {
    width: 40px;
    height: 40px;
  }
}

/* Extra small screens and landscape orientation fixes */
@media (max-width: 360px) {
  .chat-interface {
    width: calc(100vw - 16px);
    height: 350px;
    bottom: 60px;
    right: 8px;
    left: 8px;
    max-height: calc(100vh - 80px);
  }
  
  .chat-bubble {
    width: 48px;
    height: 48px;
  }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
  .chat-interface {
    height: calc(100vh - 120px);
    max-height: calc(100vh - 120px);
    bottom: 70px;
  }
}
