:root {
  --imessage-blue: #1976d2;
  --sent-message-bg: #1976d2;
  --sent-message-text: white;
  --received-message-bg: #f0f0f0;
  --received-message-text: #333;
  --input-bg: #f8f9fa;
  --border-color: #e0e0e0;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --titlebar-bg: rgba(255, 255, 255, 0.95);
  --titlebar-text: #333;
  --footer-bg: rgba(248, 249, 250, 0.95);
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  margin: 0;
  padding: 0;
  height: 100vh;
  width: 100vw;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%);
  overflow: hidden;
}

#root {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: transparent;
  overflow: hidden;
  position: relative;
}

/* Background pattern for visual interest */
#root::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(#d3e0f0 1.2px, transparent 1.2px);
  background-size: 24px 24px;
  opacity: 0.3;
  z-index: -1;
}

.chat-container {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: transparent;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.chat-container::-webkit-scrollbar {
  display: none;
}

.message {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 18px;
  word-wrap: break-word;
  word-break: break-word;
  position: relative;
  animation: messageAppear 0.2s ease-out;
  box-shadow: 0 2px 5px var(--shadow-color);
  line-height: 1.5;
  font-size: 16px;
}

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

.message.sent {
  background-color: var(--sent-message-bg);
  color: var(--sent-message-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.message.received {
  background-color: var(--received-message-bg);
  color: var(--received-message-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.input-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px;
  background-color: var(--footer-bg);
  border-top: 1px solid var(--border-color);
  gap: 10px;
  width: 100%;
}

.model-toggle {
  display: flex;
  background: white;
  border-radius: 12px;
  padding: 4px;
  box-shadow: 0 2px 8px var(--shadow-color);
  border: 1px solid var(--border-color);
  width: fit-content; /* Only take the width needed */
  max-width: 500px;
  justify-content: center;
  align-self: center; /* Center the toggle container */
  gap: 4px; /* Small gap between the two buttons */
}

.model-option {
  padding: 12px 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  min-height: 44px; /* Match the textbox height */
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 80px; /* Ensure minimum width for consistency */
  flex: 0 0 auto; /* Don't grow or shrink, take natural width */
}

.model-option.active {
  background: var(--imessage-blue);
  color: white;
}

#message-input {
  width: 100%;
  max-width: 500px;
  border: 1px solid var(--border-color);
  padding: 12px 16px;
  border-radius: 20px;
  background-color: white;
  resize: none;
  font-size: 16px;
  font-family: inherit;
  box-shadow: inset 0 1px 2px var(--shadow-color);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  min-height: 44px;
  max-height: 150px;
  overflow-y: auto;
  line-height: 1.4;
  box-sizing: border-box;
}

#message-input:focus {
  outline: none;
  border-color: var(--imessage-blue);
  box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.2);
}

#send-button {
  border: none;
  background-color: var(--imessage-blue);
  color: white;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  padding: 12px 20px;
  border-radius: 20px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(25, 118, 210, 0.3);
  min-height: 44px; /* Match the textbox height */
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center; /* Center the button */
}

#send-button:hover {
  background-color: #1565c0;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(25, 118, 210, 0.4);
}

#send-button:active {
  transform: translateY(0);
}

#send-button:disabled {
  background-color: #bbdefb;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.footer-text {
  text-align: center;
  padding: 12px;
  font-size: 12px;
  color: #757575;
  background-color: var(--footer-bg);
  border-top: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
}

.titlebar {
  padding: 16px 20px;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--titlebar-text);
  background-color: var(--titlebar-bg);
  box-shadow: 0 2px 10px var(--shadow-color);
  z-index: 10;
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
}

.content-below-titlebar {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
}

/* Responsive design */
@media (max-width: 768px) {
  .message {
    max-width: 85%;
  }

  .input-container {
    padding: 12px;
  }

  .titlebar {
    padding: 14px;
    font-size: 17px;
  }

  #message-input {
    padding: 10px 14px;
    font-size: 16px;
  }

  #send-button {
    padding: 10px 16px;
    font-size: 16px;
  }
}

/* Loading animation for received messages */
.message.received:empty::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background-color: #333;
  margin-right: 5px;
  animation: loadingDots 1.4s infinite;
  box-shadow: 7px 0 0 0 #333, 14px 0 0 0 #333;
}

@keyframes loadingDots {
  0%, 60%, 100% {
    box-shadow: 7px 0 0 0 #333, 14px 0 0 0 #333;
  }
  30% {
    box-shadow: 7px 0 0 0 #333, 14px 0 0 0 rgba(255, 255, 255, 0);
  }
}

/* Additional animations and enhancements */
@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.message.sent {
  animation: messageAppear 0.3s ease-out, pulse 2s infinite 3s;
}

.model-option {
  position: relative;
  overflow: hidden;
}

.model-option::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5px;
  height: 5px;
  background: rgba(255, 255, 255, 0.5);
  opacity: 0;
  border-radius: 100%;
  transform: scale(1, 1) translate(-50%);
  transform-origin: 50% 50%;
}

.model-option:focus:not(:active)::after {
  animation: ripple 1s ease-out;
}

@keyframes ripple {
  0% {
    transform: scale(0, 0);
    opacity: 0.5;
  }
  100% {
    transform: scale(50, 50);
    opacity: 0;
  }
}
