/*
  Updated CSS for responsive chat interface (fixed end button alignment)
*/

body {
  font-family: 'Times New Roman', Times, serif;
  background: #f5f6fa;
  margin: 0;
  box-sizing: border-box;
}

/* Chat bubble button */
.chat-bubble-container {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  right: 20px;
  z-index: 1000;
  cursor: pointer;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #f40202;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  animation: fall-from-top 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.chat-bubble-container:hover {
  animation: pulse 3.0s infinite;
}

.bot-icon {
  width: 100%;
  height: 100%;
  background-image: url("/static/Bubble.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 50%;
}

@keyframes fall-from-top {
  0% { transform: translateY(-200px) scale(0.5); opacity: 0; }
  80% { transform: translateY(10px) scale(1.1); opacity: 1; }
  100% { transform: translateY(0) scale(1); }
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* Chat window - Mobile-first floating design */
.chat-container {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom));
  right: 10px;
  z-index: 1001;
  width: 90%; 
  min-width: 300px; 
  height: 75dvh;
  max-width: 400px;
  max-height: 550px;
  border-radius: 12px;
  background: rgb(248, 247, 247);
  color: black;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transform: scale(0);
  opacity: 0;
  transform-origin: bottom right;
  box-sizing: border-box;
  overflow: hidden;
  transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55), opacity 0.5s ease;
}

.chat-container.active {
  transform: scale(1);
  opacity: 1;
}

.chat-box {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.message-container {
  display: flex;
  align-items: flex-end;
  margin-bottom: 10px;
}

.message-container.bot {
  justify-content: flex-start;
}

/* Chat header with close button */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background: #f90202;
  color: white;
  border-radius: 12px 12px 0 0;
  overflow: hidden; /* 🔥 ensures no button spills out */
}

#close-chat {
  background: none;
  border: none;
  color: white;
  font-size: 1.4em;
  cursor: pointer;
}

/* 🔥 Fixed alignment for end button */
#end-chat-button {
  color: #ff4444;
  transition: transform 0.2s ease;
  font-size: 1.2em; /* slightly smaller */
  cursor: pointer;
  background: none;
  border: none;
  margin-left: 8px; 
  width: 28px; /* fixed size */
  height: 28px;
  display: flex;
  justify-content: center;
  align-items: center;
  line-height: 1;
  border-radius: 50%;
  flex-shrink: 0; /* prevent squishing */
}

#end-chat-button:hover {
  transform: scale(1.2);
  color: #ff0000;
}

.bot-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-image: url("/static/bot_image.png");
  background-size: cover;
  background-position: center;
  margin-right: 10px;
  flex-shrink: 0;
}

.message-content-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Pulsating glow + head tilt + eye blink */
.bot-avatar.bot-thinking {
  animation: thinking-head-tilt 2s infinite ease-in-out, thinking-glow 1.5s infinite alternate;
}

@keyframes thinking-head-tilt {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(5deg); }
}

@keyframes thinking-glow {
  0% { box-shadow: 0 0 5px 2px rgba(79, 11, 250, 0.4); }
  100% { box-shadow: 0 0 15px 5px rgba(1, 1, 253, 0.8); }
}

@keyframes thinking-blink {
  0%, 95%, 100% { opacity: 1; }
  97% { opacity: 0.2; }
}

.bot-message {
  background: #f90101;
  color: white;
  padding: 10px 15px;
  border-radius: 20px 20px 20px 5px;
  max-width: 75%;
  word-wrap: break-word;
}

.message-container.user {
  justify-content: flex-end;
}

.user-message {
  background: #090a09;
  color: rgb(246, 241, 241);
  padding: 10px 15px;
  border-radius: 20px 20px 5px 20px;
  max-width: 75%;
  word-wrap: break-word;
}

.input-container {
  display: flex;
  align-items: center;
  padding: 10px;
  border-top: 1px solid #ddd;
  background: #fc0303;
  border-radius: 0 0 12px 12px;
}

#chat-input {
  flex: 1;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
  outline: none;
  box-sizing: border-box;
}

button {
  border: none;
  background: none;
  cursor: pointer;
  margin-left: 5px;
  font-size: 1.2em;
  flex-shrink: 0; 
}

#send-button, #mic-button, #voice-toggle {
  color: #007bff;
  transition: transform 0.1s ease-out;
}

#send-button:active, #mic-button:active, #voice-toggle:active {
  transform: scale(0.9);
}

#mic-button:hover i, #voice-toggle:hover i {
    transform: scale(1.3);
    color: #ff4d4d;
    transition: transform 0.3s ease, color 0.3s ease;
}

#lead-form {
  background-color: black;
  color: red;
  padding: 20px;
  border: #090a09;
  text-align: left;
}

#lead-form h3 {
  margin-bottom: 15px;
}

#details-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#details-form label {
  font-weight: bold;
}

.form-input-group {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
}

.form-input-group.visible {
  opacity: 1;
  transform: translateY(0);
}

#details-form input,
#details-form select {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-sizing: border-box;
}

.form-group {
  display: flex;
  gap: 5px;
}

.form-group select {
  flex: 1;
}

.form-group input {
  flex: 2;
}

#lead-form-submit {
  background-color: red;
  color: white;
  padding: 10px;
  border-radius: 5px;
  font-weight: bold;
  border: none;
  width: 100%;
  box-sizing: border-box;
  margin-top: 15px;
  display: none;
}

.error-message {
  color: red;
  font-size: 0.8em;
  margin-top: -5px;
  margin-bottom: 5px;
  text-align: left;
}

.required-star {
  color: red;
  margin-left: 2px;
}

/* Media Queries for Tablet and Desktop */
@media (min-width: 768px) {
  .chat-container {
    width: 350px;
    height: 550px;
    bottom: 20px;
    right: 20px;
  }
}

@media (min-width: 1024px) {
  .chat-container {
    width: 400px;
    height: 600px;
  }
}