/**
 * Character Chat CSS - iMessage-inspired chat UI
 */

/* Tab Buttons */
.tabs {
  display: flex;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
  position: relative;
  gap: 1px;
  margin-top: 0.5rem; /* Add space above tabs */
}

.tab-btn {
  padding: 0.7rem 1.5rem;
  background-color: rgba(0, 0, 0, 0.2);
  border: none;
  color: var(--text-color);
  font-size: 0.95rem;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
  border-radius: 4px 4px 0 0;
  opacity: 0.7;
  border: 1px solid var(--border-color);
  border-bottom: none;
}

.tab-btn:hover {
  background-color: rgba(91, 129, 185, 0.1);
  opacity: 0.9;
}

.tab-btn.active {
  background-color: rgba(91, 129, 185, 0.2);
  color: var(--accent-color);
  opacity: 1;
  position: relative;
}

.tab-btn.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background-color: var(--accent-color);
}

/* Chat Container */
.chat-container {
  background-color: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  min-height: 500px;
  height: 500px; /* Fixed height */
  max-height: 72vh; /* Maximum height */
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  width: 100%;
  margin-top: 0.5rem; /* Add space between tabs and container */
  position: relative; /* For absolute positioning of children if needed */
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border-color);
  background-color: rgba(0, 0, 0, 0.2);
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50px; /* Fixed height */
  z-index: 10;
}

.chat-persona-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-avatar {
  background-color: rgba(91, 129, 185, 0.3);
  color: var(--accent-color);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  border: 1px solid var(--accent-color);
}

.chat-persona-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--accent-color);
}

/* Chat Messages Area */
.chat-messages {
  padding: 1rem;
  overflow-y: auto;
  background-color: rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: absolute;
  top: 50px; /* Below header */
  bottom: 73px; /* Above input */
  left: 0;
  right: 0;
  width: 100%;
  transition: bottom 0.3s ease; /* Smooth transition when audio player appears/disappears */
}

/* Individual Chat Message */
.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  position: relative;
  animation: message-fade-in 0.2s ease-out;
}

@keyframes message-fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* User's messages (right side) */
.user-message {
  align-self: flex-end;
  background-color: rgba(91, 129, 185, 0.3);
  border-radius: 18px 18px 4px 18px;
  padding: 0.7rem 1rem;
  color: var(--text-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Persona's messages (left side) */
.persona-message {
  align-self: flex-start;
  background-color: rgba(0, 0, 0, 0.25);
  border-radius: 18px 18px 18px 4px;
  padding: 0.7rem 1rem;
  color: var(--text-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  border-left: 2px solid var(--accent-color);
}

/* System messages (centered) */
.system-message {
  align-self: center;
  background-color: rgba(255, 0, 0, 0.1);
  border-radius: 12px;
  padding: 0.5rem 1rem;
  color: #ff9999;
  font-style: italic;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  font-size: 0.9rem;
}

/* Message components */
.message-text {
  font-size: 0.95rem;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}

.message-time {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-top: 0.3rem;
  text-align: right;
}

.user-message .message-time {
  color: rgba(255, 255, 255, 0.8);
}

.persona-message .message-time {
  text-align: left;
}

/* Play button for audio messages */
.message-play-btn {
  position: absolute;
  right: -20px;
  bottom: 0;
  background-color: rgba(91, 129, 185, 0.3);
  border: none;
  color: var(--accent-color);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s ease;
  opacity: 0.8;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.message-play-btn:hover {
  background-color: rgba(91, 129, 185, 0.5);
  opacity: 1;
  transform: scale(1.1);
}

.persona-message .message-play-btn {
  right: auto;
  left: -20px;
}

/* Typing indicator animation */
.typing-indicator {
  padding: 0.6rem 1rem;
  min-width: 60px; /* Give it some minimal width */
  width: auto; /* Allow it to grow but not too much */
  max-width: 30%; /* Limit maximum width */
}

.typing-indicator .message-text {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 4px; /* Space between dots */
}

.typing-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.8);
  animation: typing-animation 1.5s infinite ease-in-out;
  box-shadow: 0 0 2px rgba(255, 255, 255, 0.3);
}

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

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

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-animation {
  0%, 60%, 100% { transform: scale(0.8); opacity: 0.6; }
  30% { transform: scale(1.2); opacity: 1; }
}

/* Audio message playback */
.chat-audio-container {
  padding: 0.75rem;
  border-top: 1px solid var(--border-color);
  background-color: rgba(0, 0, 0, 0.2);
  display: none;
  position: absolute;
  bottom: 73px;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 5;
}

.chat-audio-container audio {
  width: 100%;
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  transition: none;
  outline: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  height: 34px;
  box-sizing: border-box;
  display: block;
}

/* Chat Input Area */
.chat-input-container {
  display: flex;
  padding: 0.75rem;
  background-color: rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--border-color);
  gap: 0.5rem;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 73px; /* Fixed height */
}

.chat-input {
  flex: 1;
  background-color: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  font-family: var(--font-primary);
  font-size: 0.95rem;
  padding: 0.7rem 1rem;
  border-radius: 20px;
  height: 40px; /* Fixed height */
  max-height: 40px; /* Same as height to prevent scrollbar */
  min-height: 40px; /* Same as height to prevent resizing */
  resize: none;
  outline: none;
  transition: all 0.2s ease;
  overflow: hidden; /* Hide scrollbar */
}

.chat-input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(91, 129, 185, 0.2);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--accent-color);
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.chat-send-btn:hover {
  background-color: #4b75b8;
  transform: scale(1.05);
}

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

.send-icon {
  font-size: 1.2rem;
  font-weight: bold;
}

/* Empty State */
.chat-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2rem;
  text-align: center;
  color: var(--text-color);
  opacity: 0.6;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

.chat-empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  .chat-message {
    max-width: 90%;
  }
  
  .chat-input {
    font-size: 0.9rem;
  }
}