/* Kaizen Karate Chat Widget - Professional Production CSS */

/* Widget Configuration Variables */
:root {
  --primary-color: #c41e3a;      /* Kaizen Red */
  --primary-dark: #a01729;       /* Darker red for hover */
  --secondary-color: #2c3e50;    /* Professional dark blue-gray */
  --background-color: #ffffff;   /* Clean white */
  --text-color: #333333;         /* Dark gray text */
  --border-color: #e1e5e9;       /* Light border */
  --shadow-color: rgba(0, 0, 0, 0.15);
  --bot-message-bg: #f8f9fa;     /* Light gray for bot messages */
  --user-message-bg: var(--primary-color);
  --success-color: #28a745;
  --error-color: #dc3545;
  --widget-size: 60px;
  --widget-border-radius: 50%;
  --chat-width: 380px;
  --chat-height: 500px;
}

/* Widget Bubble (Chat Icon) */
#kaizen-chat-widget {
  position: fixed;
  bottom: 20px;  /* Back to bottom corner */
  right: 20px;
  width: var(--widget-size);
  height: var(--widget-size);
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  border-radius: var(--widget-border-radius);
  cursor: pointer;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px var(--shadow-color);
  transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  animation: chatWidgetPulse 4s ease-in-out infinite;
}

#kaizen-chat-widget:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 30px rgba(196, 30, 58, 0.4);
  cursor: pointer;
}

#kaizen-chat-widget.active {
  transform: scale(0.95);
}

/* Widget Icon */
#kaizen-chat-icon {
  color: white;
  font-size: 24px;
  transition: transform 0.3s ease;
}

#kaizen-chat-widget.chat-open #kaizen-chat-icon {
  transform: rotate(45deg);
}

/* Chat Window Container */
#kaizen-chat-container {
  position: fixed;
  bottom: 90px;  /* Adjusted to match widget position */
  right: 20px;
  width: var(--chat-width);
  height: var(--chat-height);
  background: var(--background-color);
  border-radius: 12px;
  box-shadow: 0 8px 40px var(--shadow-color);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

#kaizen-chat-container.visible {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
}

/* Chat Header */
#kaizen-chat-header {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 12px 12px 0 0;
}

#kaizen-chat-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

#kaizen-chat-close {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

#kaizen-chat-close:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

/* Chat Messages Area */
#kaizen-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--background-color);
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

#kaizen-chat-messages::-webkit-scrollbar {
  width: 6px;
}

#kaizen-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#kaizen-chat-messages::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 3px;
}

/* Message Styles */
.kaizen-message {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  animation: fadeInUp 0.3s ease;
}

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

.kaizen-message.user {
  align-items: flex-end;
}

.kaizen-message.bot {
  align-items: flex-start;
}

.kaizen-message-bubble {
  max-width: 280px;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

.kaizen-message.user .kaizen-message-bubble {
  background: var(--user-message-bg);
  color: white;
  border-bottom-right-radius: 6px;
}

.kaizen-message.bot .kaizen-message-bubble {
  background: var(--bot-message-bg);
  color: var(--text-color);
  border-bottom-left-radius: 6px;
  border: 1px solid var(--border-color);
}

/* Message Links */
.kaizen-message-bubble a {
  color: inherit;
  text-decoration: underline;
  font-weight: 500;
}

.kaizen-message.user .kaizen-message-bubble a {
  color: rgba(255, 255, 255, 0.9);
}

.kaizen-message.bot .kaizen-message-bubble a {
  color: var(--primary-color);
}

/* Text Formatting */
.kaizen-message-bubble strong {
  font-weight: 600;
  color: inherit;
}

.kaizen-message-bubble em {
  font-style: italic;
  color: inherit;
}

.kaizen-message.bot .kaizen-message-bubble strong {
  color: var(--primary-color);
}

/* Typing Indicator */
#kaizen-typing-indicator {
  display: none;
  align-items: flex-start;
  margin-bottom: 16px;
}

#kaizen-typing-indicator.visible {
  display: flex;
}

.kaizen-typing-bubble {
  background: var(--bot-message-bg);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.3s ease;
  min-height: 44px;
}

.kaizen-typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-color);
  border-radius: 50%;
  opacity: 0.4;
  animation: typingAnimation 1.4s infinite;
}

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

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

@keyframes typingAnimation {
  0%, 60%, 100% {
    opacity: 0.4;
    transform: scale(1);
  }
  30% {
    opacity: 1;
    transform: scale(1.2);
  }
}

/* Dynamic Loading Messages */
.dynamic-loading-text {
  font-size: 13px;
  color: var(--text-color);
  font-weight: 500;
  margin-right: 8px;
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.kaizen-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.kaizen-typing-dots .kaizen-typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-color);
  border-radius: 50%;
  opacity: 0.4;
  animation: typingAnimation 1.4s infinite;
}

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

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

/* Input Area */
#kaizen-chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  background: var(--background-color);
}

#kaizen-chat-input-container {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: var(--background-color);
  border: 2px solid var(--border-color);
  border-radius: 24px;
  padding: 8px 16px;
  transition: border-color 0.2s ease;
}

#kaizen-chat-input-container.focused {
  border-color: var(--primary-color);
}

#kaizen-chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-color);
  resize: none;
  min-height: 20px;
  max-height: 80px;
  padding: 6px 0;
  font-family: inherit;
}

#kaizen-chat-input::placeholder {
  color: #999;
}

#kaizen-chat-send {
  background: var(--primary-color);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
}

#kaizen-chat-send:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: scale(1.05);
}

#kaizen-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Error Message */
.kaizen-error-message {
  background: var(--error-color);
  color: white;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
  :root {
    --chat-width: calc(100vw - 20px);
    --chat-height: calc(100vh - 40px);
  }
  
  #kaizen-chat-container {
    top: 10px;
    bottom: 10px;
    left: 10px;
    right: 10px;
    width: auto;
    height: calc(100vh - 20px);
    max-height: calc(100vh - 20px);
    border-radius: 18px;
  }
  
  .kaizen-message-bubble {
    max-width: calc(100% - 24px);
  }
  
  #kaizen-chat-input-area {
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 12px));
  }
}

@media (max-height: 600px) {
  :root {
    --chat-height: calc(100vh - 140px);
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Print Styles */
@media print {
  #kaizen-chat-widget,
  #kaizen-chat-container {
    display: none !important;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000000;
    --text-color: #000000;
    --bot-message-bg: #ffffff;
  }
}

/* Attention-Grabbing Chat Indicator */
#kaizen-chat-indicator {
  position: fixed;
  bottom: 25px;
  right: 95px;
  background: white;
  color: var(--text-color);
  padding: 8px 12px;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  z-index: 10001;
  opacity: 0;
  transform: translateX(10px);
  transition: all 0.4s cubic-bezier(0.4, 0.0, 0.2, 1);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  border: 2px solid var(--primary-color);
  animation: gentlePulse 3s ease-in-out infinite;
}

#kaizen-chat-indicator.visible {
  opacity: 1;
  transform: translateX(0);
}

#kaizen-chat-indicator.hidden {
  opacity: 0;
  transform: translateX(10px);
  pointer-events: none;
}

/* Pointer arrow pointing to chat bubble */
#kaizen-chat-indicator::after {
  content: '';
  position: absolute;
  top: 50%;
  right: -8px;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 8px solid white;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  filter: drop-shadow(2px 0 2px rgba(0, 0, 0, 0.1));
}

/* Close button for indicator */
.chat-indicator-close {
  background: none;
  border: none;
  color: var(--text-color);
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  margin-left: 8px;
  padding: 0;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.chat-indicator-close:hover {
  opacity: 1;
}

/* Gentle pulse animation */
@keyframes gentlePulse {
  0%, 100% {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  }
  50% {
    box-shadow: 0 4px 20px rgba(196, 30, 58, 0.25);
  }
}

/* Chat widget pulse animation */
@keyframes chatWidgetPulse {
  0%, 100% {
    box-shadow: 0 4px 20px var(--shadow-color);
  }
  50% {
    box-shadow: 0 6px 25px rgba(196, 30, 58, 0.3);
  }
}

/* Mobile responsiveness for indicator */
@media (max-width: 480px) {
  #kaizen-chat-indicator {
    right: 85px;
    bottom: 30px;
    font-size: 11px;
    padding: 6px 10px;
    max-width: 180px;
    white-space: normal;
    line-height: 1.2;
  }
  
  #kaizen-chat-indicator::after {
    right: -6px;
    border-left-width: 6px;
    border-top-width: 5px;
    border-bottom-width: 5px;
  }
}

/* Ultra-small mobile optimizations */
@media (max-width: 390px) {
  #kaizen-chat-widget {
    width: 56px;
    height: 56px;
    bottom: 18px;
    right: 14px;
    left: auto;
  }

  #kaizen-chat-container {
    width: 100vw;
    height: 78vh;
    max-height: 78vh;
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    transform: translateY(4px);
    border-radius: 16px 16px 0 0;
  }

  #kaizen-chat-header {
    height: 56px;
    padding: 12px 16px;
    border-radius: 0;
    position: sticky;
    top: 0;
    z-index: 2;
  }

  #kaizen-chat-close {
    min-width: 44px;
    min-height: 44px;
  }

  #kaizen-chat-messages {
    padding: 12px;
    font-size: 15px;
    line-height: 1.5;
    height: calc(100vh - 56px - 110px);
  }

  .kaizen-message-bubble {
    max-width: 90%;
    padding: 12px 14px;
    margin-bottom: 8px;
  }

  #kaizen-chat-input-area {
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 14px)) 12px;
    background: var(--background-color);
  }

  #kaizen-chat-input-container {
    gap: 12px;
  }

  #kaizen-chat-input {
    font-size: 16px;
    padding: 12px;
    min-height: 24px;
  }

  #kaizen-chat-send {
    min-width: 48px;
    min-height: 48px;
    font-size: 16px;
  }

  #kaizen-chat-widget.chat-open {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9);
  }
}

/* Dark Mode Support (Optional - can be enabled later) */
@media (prefers-color-scheme: dark) {
  /* Uncomment to enable dark mode
  :root {
    --background-color: #2c3e50;
    --text-color: #ffffff;
    --border-color: #4a5568;
    --bot-message-bg: #3a4a5c;
    --shadow-color: rgba(0, 0, 0, 0.3);
  }
  */
}
