/* =============================================
   Matrix AI Chatbot - Frontend Styles
   ============================================= */

:root {
  --primary-color: #4a90e2; /* Will be overridden by PHP */
  --secondary-color: #031326; /* Will be overridden by PHP */
  --message-bubble-color: #e1f0fe; /* Will be overridden by PHP */
  --user-message-color: var(--primary-color); /* Add this */
  --primary-text-color: #ffffff;
  --chat-bg-color: #f9f9f9;
  --input-bg-color: #ffffff;
  --border-color: #e0e0e0;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --typing-indicator-color: #666666;
  --mobile-vh: 1vh; /* Will be set by JS */
}

/* Base Container */
#matrixai-chatbot-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 99999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  font-size: 14px; /* Base font size */
  line-height: 1.4;
}

/* Chat Button */
#matrixai-chatbot-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: var(--primary-color);
  color: var(--primary-text-color);
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 10px var(--shadow-color);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  z-index: 9999;
}

#matrixai-chatbot-button:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#matrixai-chatbot-button .chat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

#matrixai-chatbot-button svg {
  width: 24px;
  height: 24px;
}

/* Chat Window */
#matrixai-chatbot-window {
  position: fixed;
  bottom: 90px;
  right: 20px;
  /*width: 350px;
  max-width: 90vw;*/
  /* Remove specific height/max-height for full screen on mobile */
  /* This ensures it tries to fill the available space, and relies on flexbox for internal scrolling
  height: 500px;
  max-height: 70vh;  */
  display: flex;          /* Make it a flex container */
  flex-direction: column; /* Stack children vertically: header, messages, input */
  overflow: hidden;       /* Important to contain child overflow, especially messages */
  box-sizing: border-box; /* Ensures padding/border are included in the element's total width and height */
  
  background: var(--chat-bg-color);
  /*border-radius: 12px;*/
  box-shadow: 0 5px 15px var(--shadow-color);
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 9998;
  
  /* Non-mobile specific dimensions */
  width: 380px;
  max-width: calc(100vw - 40px); /* Example, adjust as needed for desktop */
  height: 500px;
  max-height: calc(100vh - 100px); /* Example, adjust as needed for desktop */
  border-radius: 10px;

}

#matrixai-chatbot-window.active {
  transform: translateY(0);
  opacity: 1;
}

/* Chat Header */
.matrixai-chatbot-header {
  background-color: var(--primary-color);
  color: var(--primary-text-color);
  padding: 12px 15px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.matrixai-chatbot-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ffffff;
  overflow: hidden;
  flex-shrink: 0;
}

.matrixai-chatbot-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.matrixai-chatbot-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#matrixai-chatbot-close {
  background: none;
  border: none;
  color: var(--primary-text-color);
  font-size: 24px;
  cursor: pointer;
  padding: 0 5px;
  line-height: 1;
}

/* Messages Container */
.matrixai-chatbot-messages {
  flex: 1;                /* Allows this element to grow and shrink, taking available space */
  padding: 15px;
  overflow-y: auto;       /* Enable vertical scrolling */
  scroll-behavior: smooth;/* Smooth scrolling for new messages */
  -webkit-overflow-scrolling: touch; /* Improved touch scrolling on iOS */
}

/* Message Bubbles */
.matrixai-chatbot-message {
  margin-bottom: 15px;
  display: flex;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.matrixai-chatbot-message.user-message {
  margin-left: auto;
  justify-content: flex-end;
}

.matrixai-chatbot-message.bot-message {
  margin-right: auto;
}

.bot-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  margin-right: 10px;
  flex-shrink: 0;
  align-self: flex-end;
}

.bot-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-content {
  padding: 10px 15px;
  border-radius: 18px;
  line-height: 1.5;
  word-wrap: break-word;
}

.bot-message .message-content {
  background-color: var(--message-bubble-color);
  color: #333333;
  border-bottom-left-radius: 5px;
}

.user-message .message-content {
  background-color: var(--user-message-color);;
  color: var(--primary-text-color);
  border-bottom-right-radius: 5px;
}

/* Typing Indicator */
.typing-indicator {
  display: none;
}

.typing-indicator .message-content {
  display: flex;
  align-items: center;
  height: 30px;
  background-color: var(--message-bubble-color);
}

.typing-indicator .dot {
  width: 8px;
  height: 8px;
  background-color: var(--typing-indicator-color);
  border-radius: 50%;
  margin: 0 2px;
  animation: typingAnimation 1.4s infinite ease-in-out;
}

.typing-indicator .dot:nth-child(1) {
  animation-delay: 0s;
}

.typing-indicator .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingAnimation {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Input Area */
.matrixai-chatbot-input-area {
/*  padding: 12px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--input-bg-color);
  padding-bottom: calc(12px + env(safe-area-inset-bottom)); /* Add safe area to input padding */
  display: flex;                /* Make it a flex container to arrange children horizontally */
  align-items: flex-end;        /* Aligns items (input and button) to the bottom */
  padding: 10px 15px;           /* Consistent padding around the input and button */
  border-top: 1px solid var(--border-color); /* Visual separator from messages above */
  background-color: var(--input-bg-color); /* Background color for the input area */
  gap: 10px; /* Adds space between the input field and the send button */
  box-sizing: border-box; /* Crucial for consistent sizing */

  /* For modern iOS devices with notches and the home indicator bar */
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); /* Adds padding for the iOS safe area at the bottom */
}

#matrixai-chatbot-input {
  min-height: 20px; /* Ensures a reasonable minimum height for the input field */
  padding: 10px 15px; /* Adjust padding as needed for appearance */
  flex: 1;
  flex-grow: 1; /* Allows the input field to take up available horizontal space */
  width: 100%; /* Ensures it doesn't overflow its parent when growing */
  box-sizing: border-box; /* Important: ensures padding and border are included in the element's total width/height */
  border: 1px solid var(--border-color);
  border-radius: 20px;
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  font-family: inherit;
  font-size: inherit;
  transition: border-color 0.3s ease;
}

#matrixai-chatbot-input:focus {
  border-color: var(--primary-color);
}

#matrixai-chatbot-send {
  background-color: var(--primary-color);
  color: var(--primary-text-color);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.3s ease;
  position: sticky;
}
/* Ensure the send button doesn't shrink or get pushed off */
#matrixai-chatbot-send-button {
  flex-shrink: 0; /* Prevents the button from shrinking when space is limited */
}

#matrixai-chatbot-send:hover {
  transform: scale(1.05);
}

#matrixai-chatbot-send svg {
  width: 18px;
  height: 18px;
}

/* Scrollbar Styling */
.matrixai-chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

.matrixai-chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.matrixai-chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.matrixai-chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}



/* Animation for new messages */
@keyframes messageAppear {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.matrixai-chatbot-message:last-child {
  animation: messageAppear 0.3s ease;
}

/* Error Message Styling */
.chatbot-error-message {
  color: #dc3545;
  padding: 8px 12px;
  border-radius: 18px;
  background-color: #f8d7da;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chatbot-error-message .icon {
  font-size: 16px;
}

/* Subtle hover effect for message bubbles */
.message-content:hover {
    transform: translateY(-1px);
    transition: transform 0.2s ease;
}

/* Ensure proper styling for dynamically added typing indicator */
.matrixai-typing-indicator {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    max-width: 85%;
}

.matrixai-typing-indicator .matrixai-typing-dots {
    padding: 10px 15px;
    background-color: var(--message-bubble-color);
    border-radius: 18px;
    border-bottom-left-radius: 5px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.matrixai-typing-indicator .matrixai-typing-dots span {
    width: 8px;
    height: 8px;
    background-color: var(--typing-indicator-color);
    border-radius: 50%;
    animation: matrixaiTypingBounce 1.3s infinite ease-in-out;
}

.matrixai-typing-indicator .matrixai-typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

.matrixai-typing-indicator .matrixai-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.matrixai-typing-indicator .matrixai-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes matrixaiTypingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}
/* Add this to your CSS for mobile when the chat is active */
body.matrixai-chatbot-open {
    overflow: hidden !important;
    height: 100% !important; /* Prevents scrolling of the background content */
    position: fixed !important; /* Prevents layout shifting */
    width: 100% !important;
}
/* ========================
   Mobile Responsiveness 
   ======================== */

@media (max-width: 767px) {
    #matrixai-chatbot-button {
        position: fixed !important;
        bottom: 20px !important;
        right: 20px !important;
        width: 60px !important;
        height: 60px !important;
        z-index: 100001;
        -webkit-tap-highlight-color: transparent;
    }
    
    #matrixai-chatbot-window {
        top: 0 !important;              /* Stretch to top */
        left: 0 !important;             /* Stretch to left */
        right: 0 !important;            /* Stretch to right */
        bottom: 0 !important;           /* Stretch to bottom */
        width: 100vw !important;        /* Full viewport width */
        /* Use --mobile-vh set by JS to account for keyboard */
        height: calc(100 * var(--mobile-vh, 1vh)) !important;
        max-height: calc(100 * var(--mobile-vh, 1vh)) !important;
        border-radius: 0 !important;    /* No rounded corners for full screen */
        z-index: 99999 !important;      /* Ensure it's on top */
    }
	
	#matrixai-chatbot-container {
        bottom: 20px; /* Adjust as needed, but the button will likely be beneath the full-screen chat */
        right: 20px;
    }
	
    #matrixai-chatbot-input {
        font-size: 16px !important; /* Ensure input field is at least 16px */
    }
	
    /* iOS Viewport Fix */
    @supports (-webkit-touch-callout: none) {
        #matrixai-chatbot-window {
            height: -webkit-fill-available !important;
            bottom: 70px !important;
            max-height: 80% !important;
        }
    }
	.matrixai-chatbot-window.active {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        z-index: 99999 !important;
    }
	.matrixai-chatbot-button {
		touch-action: manipulation;
		-webkit-tap-highlight-color: transparent;
	}
	.message-content {
        font-size: 16px !important; /* Ensure message content is at least 16px */
    }
}

/* Extra small devices (phones, 480px and down) */
@media (max-width: 480px) {
    #matrixai-chatbot-window {
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: calc(100 * var(--mobile-vh, 1vh)) !important; /* Use --mobile-vh */
        max-height: calc(100 * var(--mobile-vh, 1vh)) !important; /* Use --mobile-vh */
        border-radius: 0 !important;
    }
    
    #matrixai-chatbot-container {
        /* Keep these, but the window will override them when open */
        bottom: 10px;
        right: 10px;
    }
    
    #matrixai-chatbot-button {
        background-color: var(--primary-color);
        width: 50px;
        height: 50px;
        bottom: 10px;
        right: 10px;
    }
    
    .matrixai-chatbot-header h2 {
        font-size: 15px;
    }
    
    #matrixai-chatbot-input {
        font-size: 16px !important;
        padding: 10px 15px; /* Adjust padding if needed after font size change */
    }
    
    #matrixai-chatbot-send {
        width: 36px;
        height: 36px;
    }
    
    .message-content {
        font-size: 16px !important;
        padding: 10px 15px; /* Adjust padding if needed after font size change */
    }
    
    .matrixai-chatbot-header h2 {
        font-size: 16px !important; /* Ensure header title is at least 16px */
    }
    
    .matrixai-chatbot-message {
        max-width: 90%;
    }
}
