/* ==========================================================================
   AI Chat Assistant Widget Stylesheet
   Design System: Premium Glassmorphic, Modern Transitions & Responsive Layout
   ========================================================================== */

:root {
  /* Colors */
  --chat-primary: #114193;         /* Matches MKS site steel blue */
  --chat-primary-light: #1e5fc2;
  --chat-secondary: #EDDB27;       /* Matches MKS site yellow accent */
  --chat-accent: #0f172a;          /* Deep slate */
  
  --chat-bg-container: rgba(255, 255, 255, 0.92);
  --chat-bg-header: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-light) 100%);
  --chat-bg-user-bubble: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-light) 100%);
  --chat-bg-bot-bubble: #f1f5f9;
  --chat-bg-input: #ffffff;
  
  --chat-text-light: #ffffff;
  --chat-text-dark: #0f172a;
  --chat-text-muted: #64748b;
  
  /* Fonts */
  --chat-font-family: 'Inter', system-ui, -apple-system, sans-serif;
  
  /* Shadows & Borders */
  --chat-shadow-widget: 0 12px 40px rgba(0, 0, 0, 0.12);
  --chat-shadow-fab: 0 6px 20px rgba(17, 65, 147, 0.3);
  --chat-border-color: rgba(226, 232, 240, 0.8);
  --chat-border-radius-lg: 16px;
  --chat-border-radius-sm: 8px;
  
  /* Transitions */
  --chat-transition-speed: 0.35s;
  --chat-transition-curve: cubic-bezier(0.16, 1, 0.3, 1);
}

/* --------------------------------------------------------------------------
   Floating Action Button (Trigger)
   -------------------------------------------------------------------------- */
.chat-widget-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--chat-bg-header);
  border: none;
  cursor: pointer;
  box-shadow: var(--chat-shadow-fab);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: all 0.3s var(--chat-transition-curve);
  outline: none;
}

.chat-widget-trigger:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 10px 25px rgba(17, 65, 147, 0.4);
}

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

.chat-widget-trigger svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: var(--chat-text-light);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform var(--chat-transition-speed) var(--chat-transition-curve);
}

/* Toggle rotation state when active */
.chat-widget-trigger.active svg.chat-icon-open {
  transform: rotate(90deg) scale(0);
  opacity: 0;
  position: absolute;
}

.chat-widget-trigger svg.chat-icon-close {
  transform: rotate(-90deg) scale(0);
  opacity: 0;
  position: absolute;
}

.chat-widget-trigger.active svg.chat-icon-close {
  transform: rotate(0) scale(1);
  opacity: 1;
  position: static;
}

/* Ripple effect on FAB */
.chat-widget-trigger::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  border: 2px solid var(--chat-primary-light);
  opacity: 0;
  animation: pulse-ring 2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

@keyframes pulse-ring {
  0% {
    transform: scale(0.95);
    opacity: 0.8;
  }
  100% {
    transform: scale(1.3);
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   Chat Container Panel
   -------------------------------------------------------------------------- */
.chat-widget-container {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: 580px;
  max-height: calc(100vh - 120px);
  background: var(--chat-bg-container);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--chat-border-color);
  border-radius: var(--chat-border-radius-lg);
  box-shadow: var(--chat-shadow-widget);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9998;
  
  /* Animations & Initial Hidden State */
  opacity: 0;
  transform: translateY(30px) scale(0.95);
  pointer-events: none;
  visibility: hidden;
  transition: opacity var(--chat-transition-speed) var(--chat-transition-curve),
              transform var(--chat-transition-speed) var(--chat-transition-curve),
              visibility var(--chat-transition-speed) var(--chat-transition-curve);
}

.chat-widget-container.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
}

/* --------------------------------------------------------------------------
   Header Bar
   -------------------------------------------------------------------------- */
.chat-widget-header {
  background: var(--chat-bg-header);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--chat-text-light);
}

.chat-bot-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-bot-avatar {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid var(--chat-secondary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.5px;
  color: var(--chat-text-light);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: relative;
}

/* Online indicator dot */
.chat-bot-avatar::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background-color: #22c55e;
  border: 2px solid var(--chat-primary);
  border-radius: 50%;
}

.chat-bot-info {
  display: flex;
  flex-direction: column;
}

.chat-bot-name {
  margin: 0;
  font-family: var(--chat-font-family);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}

.chat-bot-status {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.8);
  font-family: var(--chat-font-family);
  margin-top: 2px;
}

.chat-close-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

.chat-close-btn:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

.chat-close-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--chat-text-light);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --------------------------------------------------------------------------
   Messages Panel
   -------------------------------------------------------------------------- */
.chat-messages-panel {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background-color: #f8fafc;
  scroll-behavior: smooth;
}

/* Scrollbar customization */
.chat-messages-panel::-webkit-scrollbar {
  width: 6px;
}

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

.chat-messages-panel::-webkit-scrollbar-thumb {
  background-color: #cbd5e1;
  border-radius: 10px;
}

.chat-messages-panel::-webkit-scrollbar-thumb:hover {
  background-color: #94a3b8;
}

/* Message Bubble Layout */
.chat-message {
  max-width: 80%;
  display: flex;
  flex-direction: column;
  animation: bubble-fade-in 0.3s var(--chat-transition-curve) forwards;
}

@keyframes bubble-fade-in {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Message bubble text */
.chat-bubble {
  padding: 12px 16px;
  font-family: var(--chat-font-family);
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Bot Message Styling */
.chat-message.bot {
  align-self: flex-start;
}

.chat-message.bot .chat-bubble {
  background-color: var(--chat-bg-bot-bubble);
  color: var(--chat-text-dark);
  border-radius: 4px 16px 16px 16px;
  border: 1px solid rgba(226, 232, 240, 0.6);
}

/* User Message Styling */
.chat-message.user {
  align-self: flex-end;
}

.chat-message.user .chat-bubble {
  background: var(--chat-bg-user-bubble);
  color: var(--chat-text-light);
  border-radius: 16px 4px 16px 16px;
}

/* Message Timestamp */
.chat-timestamp {
  font-size: 10px;
  color: var(--chat-text-muted);
  margin-top: 4px;
  align-self: flex-start;
}

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

/* --------------------------------------------------------------------------
   Typing Indicator
   -------------------------------------------------------------------------- */
.chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
}

.chat-typing-dot {
  width: 6px;
  height: 6px;
  background-color: #94a3b8;
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

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

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

@keyframes typing-bounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

/* --------------------------------------------------------------------------
   Footer / Form Input Row
   -------------------------------------------------------------------------- */
.chat-input-footer {
  display: flex;
  padding: 16px;
  background: var(--chat-bg-input);
  border-top: 1px solid var(--chat-border-color);
  gap: 10px;
  align-items: center;
}

.chat-input-footer input {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 24px;
  padding: 12px 18px;
  font-family: var(--chat-font-family);
  font-size: 14px;
  outline: none;
  background-color: #f8fafc;
  transition: all 0.25s var(--chat-transition-curve);
  color: var(--chat-text-dark);
}

.chat-input-footer input:focus {
  border-color: var(--chat-primary-light);
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(17, 65, 147, 0.1);
}

.chat-send-btn {
  background: var(--chat-bg-header);
  border: none;
  cursor: pointer;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s var(--chat-transition-curve);
  box-shadow: 0 2px 8px rgba(17, 65, 147, 0.15);
}

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

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

.chat-send-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--chat-text-light);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  margin-left: 2px; /* Visual centering adjustment for send triangle */
}

/* Accessibility Focus States */
.chat-widget-trigger:focus-visible,
.chat-close-btn:focus-visible,
.chat-send-btn:focus-visible,
.chat-input-footer input:focus-visible {
  outline: 3px solid var(--chat-secondary);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Responsive Screen Adjustments (Mobile Mode)
   -------------------------------------------------------------------------- */
@media screen and (max-width: 480px) {
  .chat-widget-trigger {
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
  }
  
  .chat-widget-container {
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }
  
  .chat-widget-container.open {
    transform: translateY(0); /* Avoid scale shifts on full-screen mobile triggers */
  }
  
  .chat-widget-header {
    border-radius: 0;
    padding: 16px;
    safe-area-inset-top: env(safe-area-inset-top); /* Suppor for iOS notches */
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }
  
  .chat-input-footer {
    safe-area-inset-bottom: env(safe-area-inset-bottom);
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}
