/* ===================================================
   CSS Variables
=================================================== */
:root {
  /* Primary Colors */
  --color-primary: #0077cc;
  --color-primary-dark: #005fa3;
  
  /* Message Colors */
  --color-user-bg: #0077cc;
  --color-bot-bg: #e5e7eb;
  --color-bot-text: #111;
  
  /* Button Colors */
  --color-button-bg: #acacac;
  --color-button-hover: #999;
  --color-button-text: white;
  
  /* UI Colors */
  --color-background: #f7f7f7;
  --color-border: #ccc;
  --color-text: #333;
  --color-text-light: #666;
}

/* ===================================================
   Base Layout & Global Styles
=================================================== */
html, body {
  margin: 0;
  padding: 0;
  font-family: 'Open Sans', sans-serif;
  background: var(--color-background);
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-size: 0.95rem;
  overflow-x: hidden;  /* Prevent horizontal scrolling */
}


/* ===================================================
   Chatbox & Message Styling
=================================================== */
#chatBox {
  flex: 1;
  padding: 0.5rem;
  padding-bottom: 6rem;  /* Increased space for typing indicator */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#chatBox.typing-active {
  padding-bottom: 6rem;  /* Keep consistent padding when typing */
}

.message {
  position: relative;
  max-width: 65%;  /* Slightly reduced max width */
  padding: 0.25rem 0.6rem;  /* Reduced vertical padding from 0.35rem to 0.25rem */
  margin: 0.2rem 0;  /* Further reduced margin */
  border-radius: 0.8rem;  /* Slightly reduced border radius */
  line-height: 1.2em;  /* Further reduced line height */
  display: block;
  word-break: break-word;
  font-size: 0.95rem;  /* Slightly reduced font size */
}

/* Message Timestamp */
.message-timestamp {
  font-size: 0.7rem;
  color: #999;
  margin-top: 0.2rem;
  text-align: right;
  position: absolute;
  right: 0;
  bottom: -1.2rem;  /* Position below the bubble */
}

/* User Message Bubble */
.user {
  align-self: flex-end;
  background-color: var(--color-user-bg);
  color: white;
  border-bottom-right-radius: 0;
  text-align: right;
  margin-left: auto;
  margin-bottom: 1.4rem;  /* Add space for timestamp */
}

.user::after {
  content: '';
  position: absolute;
  right: -6px;  /* Further reduced position */
  bottom: 4px;  /* Further reduced position */
  width: 0;
  height: 0;
  border-top: 6px solid transparent;  /* Further reduced size */
  border-left: 6px solid var(--color-user-bg);  /* Further reduced size */
}

/* Bot Message Bubble */
.bot {
  align-self: flex-start;
  background-color: var(--color-bot-bg);
  color: var(--color-bot-text);
  border-bottom-left-radius: 0;
  margin-bottom: 1.4rem;  /* Add space for timestamp */
}

.bot::after {
  content: '';
  position: absolute;
  left: -6px;  /* Further reduced position */
  bottom: 4px;  /* Further reduced position */
  width: 0;
  height: 0;
  border-top: 6px solid transparent;  /* Further reduced size */
  border-right: 6px solid var(--color-bot-bg);  /* Further reduced size */
}

/* ===================================================
   Links in Messages
=================================================== */
.user a {
  color: white;
  text-decoration: underline;
  font-weight: 500;
}

.user a:hover {
  color: #d0e7ff;
}

.bot a {
  color: var(--color-primary);
  text-decoration: underline;
  font-weight: 500;
}

.bot a:hover {
  color: var(--color-bot-text);
}

/* ===================================================
   Bot Options (Buttons)
=================================================== */
.option-instruction {
  font-size: 0.85rem;
  color: var(--color-text-light);
  margin-bottom: 0.5rem;
  font-style: italic;
}

.bot-option {
  margin-right: 0.4rem;
  margin-top: 0.2rem;
  padding: 0.5rem 1rem;
  border-radius: 0.3rem;
  border: 1px solid #666;
  cursor: pointer;
  background: #666;
  font-size: 0.85rem;
  color: var(--color-button-text);
  font-family: 'Open Sans', sans-serif;
  min-width: 120px;
  text-align: center;
  transition: all 0.2s ease;
}

.bot-option:hover {
  background-color: var(--color-user-bg);
  border-color: var(--color-user-bg);
}

/* ===================================================
   Input Area
=================================================== */
#inputArea {
  display: flex;
  border-top: 1px solid #ccc;
  padding: 0.75rem;
  background: white;
}

#userInput {
  flex: 1;
  padding: 0.625rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 0.375rem;
}

button {
  margin-left: 0.625rem;
  padding: 0.625rem 1.25rem;
  font-size: 1rem;
  background-color: var(--color-primary);
  color: white;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
}

button:hover {
  background-color: var(--color-primary-dark);
}

/* ===================================================
   Typing Indicator
=================================================== */
.typing-indicator {
  position: fixed;
  bottom: 80px;  /* Position above the input area */
  left: 50%;
  transform: translateX(-50%);
  max-width: 65%;
  margin: 0.2rem 0;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 100;  /* Ensure it stays above messages */
  pointer-events: none;  /* Allow clicking through */
}

.typing-indicator.visible {
  opacity: 1;
}

.typing-indicator.hidden {
  opacity: 0;
  pointer-events: none;
}

.typing-bubble {
  display: flex;
  align-items: flex-start;
  background-color: var(--color-bot-bg);
  padding: 0.35rem 0.6rem;
  border-radius: 0.8rem;
  border-bottom-left-radius: 0;
  animation: pulse 2s infinite;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);  /* Add subtle shadow */
}

.typing-avatar {
  width: 18px;  /* Further reduced size */
  height: 18px;  /* Further reduced size */
  background: #0077cc;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.7rem;  /* Further reduced font size */
  margin-right: 0.3rem;  /* Further reduced margin */
}

.typing-content {
  display: flex;
  flex-direction: column;
}

.typing-name {
  font-size: 0.65rem;  /* Further reduced font size */
  color: #666;
  margin-bottom: 0.1rem;  /* Further reduced margin */
}

.typing-dots {
  display: flex;
  gap: 0.15rem;  /* Further reduced gap */
}

.typing-dots span {
  width: 4px;  /* Further reduced size */
  height: 4px;  /* Further reduced size */
  background: #666;
  border-radius: 50%;
  animation: bounce 1.4s infinite;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

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

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.8; }
  100% { opacity: 1; }
}

/* ===================================================
   Test Mode Banner
=================================================== */
.test-banner {
  background-color: #fff3cd;
  color: #856404;
  padding: 0.5rem 1rem;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 500;
  border-bottom: 1px solid #ffeeba;
}

.test-banner.hidden {
  display: none;
}

/* ===================================================
   Loading Overlay
=================================================== */
.loading-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.85);
  z-index: 1000;
}

.loading-message {
  background: #0077cc;
  color: white;
  padding: 1.5rem 2rem;
  border-radius: 10px;
  font-size: 1.25rem;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.loading-circle {
  width: 24px;
  height: 24px;
  border: 2px solid white;
  border-radius: 50%;
  position: relative;
  animation: circleFill 2s infinite;
}

.loading-circle::before {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: white;
  animation: circleTop 2s infinite;
}

.loading-circle::after {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-left-color: white;
  animation: circleLeft 2s infinite;
}

.loading-text {
  font-weight: 500;
}

@keyframes circleFill {
  0%, 100% { background: transparent; }
  25% { background: white; }
  50% { background: transparent; }
  75% { background: #0077cc; }
}

@keyframes circleTop {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(180deg); }
}

@keyframes circleLeft {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(180deg); }
}

/* ===================================================
   Modal Styling (Reset Confirmation)
=================================================== */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-content {
  background: #fff;
  padding: 20px 30px;
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.modal-content button {
  margin: 10px;
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#confirmYes { background-color: #d9534f; color: #fff; }
#confirmNo  { background-color: #ccc; }

/* ===================================================
   Responsive Design
=================================================== */
@media screen and (max-width: 600px) {
  #chatBox { padding: 0.75rem; }

  .message {
    max-width: 90%;
    font-size: 0.95rem;
  }

  .message a {
    color: #d5eda8;
  }

  .message a:hover {
    color: #76d9ef;
  }

  .bot-option {
    font-size: 0.85rem;
    padding: 0.4rem 0.6rem;
  }

  #userInput {
    font-size: 1rem;
    padding: 0.5rem;
  }

  button {
    font-size: 1rem;
    padding: 0.5rem 1rem;
  }

  .typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.75rem 1rem;
    padding: 0.75rem 1rem;
    background: #e5e7eb;
    color: #333;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 500;
    width: fit-content;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  }
}


/* ===================================================
   Utility Classes
=================================================== */
.hidden {
  display: none !important;
}

/* ===================================================
   Chat Ended Message
=================================================== */
.chat-ended {
  background: #f8f9fa;
  border-top: 1px solid #e9ecef;
  padding: 1rem;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.chat-ended-message {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: #6c757d;
  font-size: 1rem;
}

.chat-ended-icon {
  background: #28a745;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.chat-ended-text {
  font-weight: 500;
}

/* Dark theme for chat ended state */
.dark-theme .chat-ended {
  background: #2d2d2d;
  border-top-color: #3d3d3d;
}

.dark-theme .chat-ended-message {
  color: #e0e0e0;
}

/* Tools Button and Menu */
.tools-container {
  position: relative;
  display: inline-block;
}

.tools-button {
  margin-left: 0.625rem;
  padding: 0.625rem 1.25rem;
  font-size: 1rem;
  background-color: #e5e7eb;  /* Light grey color */
  color: #666;  /* Darker grey for the icon */
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
  height: 100%;  /* Match parent height */
  min-height: 2.5rem;  /* Match send button height */
}

.tools-button:hover {
  background-color: #d1d5db;  /* Slightly darker grey on hover */
}

.tools-button svg {
  color: #666;  /* Darker grey for the icon */
  width: 1rem;
  height: 1rem;
}

.tools-menu {
  position: absolute;
  right: 0;
  bottom: 100%;  /* Changed from top: 100% to bottom: 100% */
  margin-bottom: 4px;  /* Changed from margin-top to margin-bottom */
  background: white;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  min-width: 160px;
  z-index: 1000;
  overflow: hidden;  /* Ensure hover states don't overflow rounded corners */
}

.tools-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  color: #333;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.2s ease;
  margin: 0;  /* Remove any default margins */
  box-sizing: border-box;  /* Include padding in width calculation */
}

.tools-menu-item:hover {
  background: #f3f4f6;
  width: 100%;  /* Ensure hover state covers full width */
}

.tools-menu-item span {
  font-size: 14px;
}

/* Dark Theme for Tools */
.dark-theme .tools-button {
  background: #3d3d3d;
}

.dark-theme .tools-button:hover {
  background: #4d4d4d;
}

.dark-theme .tools-button svg {
  color: #ffffff;
}

.dark-theme .tools-menu {
  background: #2d2d2d;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.dark-theme .tools-menu-item {
  color: #ffffff;
}

.dark-theme .tools-menu-item:hover {
  background: #3d3d3d;
}

/* Dark Theme */
.dark-theme {
  background-color: #1a1a1a;
  color: #ffffff;
}

.dark-theme #chatBox {
  background-color: #2d2d2d;
}

.dark-theme .message {
  background-color: #3d3d3d;
}

.dark-theme .message.user {
  background-color: #0078d4;
}

.dark-theme #userInput {
  background-color: #2d2d2d;
  color: #ffffff;
  border-color: #3d3d3d;
}

.dark-theme .modal-content {
  background-color: #2d2d2d;
  color: #ffffff;
}

.dark-theme .modal-content h3 {
  color: #ffffff;
}

.menu-icon {
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
