/**
 * Modern Chat UI Styles for Live Tutor
 */

:root {
  --primary-color: #11998e;
  --user-bubble-bg: #11998e;
  --agent-bubble-bg: #e8f5e9;
  --user-text-color: #ffffff;
  --agent-text-color: #1b5e20;
  --bg-color: #ffffff;
  --border-color: #c8e6c9;
  --input-bg: #f1f8f4;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-color);
  color: #202124;
  line-height: 1.6;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  color: white;
  padding: 1.5rem 2rem;
  box-shadow: var(--shadow-lg);
  position: relative;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
}

.subtitle {
  font-size: 0.875rem;
  opacity: 0.95;
  margin-top: 0.5rem;
  margin-bottom: 0.75rem;
}

.header-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  opacity: 0.9;
}

.session-timer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  background-color: rgba(255, 255, 255, 0.15);
  border-radius: 1.5rem;
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.session-timer .timer-icon {
  font-size: 1.125rem;
}

.session-timer.low {
  background-color: rgba(255, 193, 7, 0.2);
  color: #ffc107;
}

.session-timer.warning {
  background-color: rgba(244, 67, 54, 0.2);
  color: #f44336;
  animation: timerPulse 1s ease-in-out infinite;
}

@keyframes timerPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #34a853;
}

.status-indicator.disconnected {
  background-color: #ea4335;
}

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

/* Main Layout: Full width chat */
.main-layout {
  flex: 1;
  display: flex;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

/* Main Container: Chat area (full width) */
.container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Messages Area */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: linear-gradient(to bottom, #e8f5e9 0%, #f1f8f4 50%, #ffffff 100%);
}

/* Scroll styling */
#messages::-webkit-scrollbar {
  width: 8px;
}

#messages::-webkit-scrollbar-track {
  background: transparent;
}

#messages::-webkit-scrollbar-thumb {
  background: #dadce0;
  border-radius: 4px;
}

#messages::-webkit-scrollbar-thumb:hover {
  background: #bdc1c6;
}

/* Message Bubbles */
.message {
  display: flex;
  margin-bottom: 0.5rem;
  animation: slideIn 0.3s ease-out;
}

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

.message.user {
  justify-content: flex-end;
}

.message.agent {
  justify-content: flex-start;
}

.bubble {
  max-width: 70%;
  padding: 0.75rem 1rem;
  border-radius: 1.25rem;
  word-wrap: break-word;
  box-shadow: var(--shadow);
  position: relative;
}

.message.user .bubble {
  background-color: var(--user-bubble-bg);
  color: var(--user-text-color);
  border-bottom-right-radius: 0.25rem;
}

.message.agent .bubble {
  background-color: var(--agent-bubble-bg);
  color: var(--agent-text-color);
  border-bottom-left-radius: 0.25rem;
}

.bubble-text {
  margin: 0;
  line-height: 1.5;
}

/* Interrupted message styling */
.message.interrupted .bubble {
  opacity: 0.6;
  background-color: #e8eaed;
  border-left: 3px solid #f4b400;
}

.message.interrupted .bubble::after {
  content: 'interrupted';
  display: block;
  font-size: 0.75rem;
  color: #5f6368;
  font-style: italic;
  margin-top: 0.25rem;
}

/* Transcription message styling */
.message.transcription.user .bubble {
  opacity: 0.9;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.message.transcription.user .bubble::before {
  content: '🎤';
  opacity: 0.8;
  margin-right: 0.25rem;
}

/* Typing indicator */
.typing-indicator {
  display: inline-block;
  margin-left: 0.25rem;
  color: #5f6368;
}

.typing-indicator::after {
  content: '...';
  animation: ellipsis 1.5s infinite;
}

@keyframes ellipsis {
  0%, 20% {
    content: '.';
  }
  40% {
    content: '..';
  }
  60%, 100% {
    content: '...';
  }
}

/* Image bubble styling */
.bubble.image-bubble {
  padding: 0.25rem;
  max-width: 80%;
}

.bubble-image {
  max-width: 100%;
  max-height: 300px;
  width: auto;
  height: auto;
  border-radius: 0.75rem;
  display: block;
  object-fit: contain;
}

/* Input Form */
.input-container {
  border-top: 1px solid var(--border-color);
  background-color: white;
  padding: 1.5rem 2rem;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

#messageForm {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.input-wrapper {
  flex: 1;
  display: flex;
  gap: 0.75rem;
}

/* Audio-only mode - center the audio button */
.input-wrapper.audio-only {
  justify-content: center;
  max-width: 400px;
  margin: 0 auto;
}

#message {
  flex: 1;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 1.5rem;
  font-size: 1rem;
  font-family: inherit;
  background-color: var(--input-bg);
  transition: all 0.2s ease;
  outline: none;
}

#message:focus {
  border-color: var(--primary-color);
  background-color: white;
  box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1);
}

/* Buttons */
button {
  padding: 0.875rem 1.5rem;
  border: none;
  border-radius: 1.5rem;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  white-space: nowrap;
}

#sendButton {
  background-color: var(--primary-color);
  color: white;
}

#sendButton:hover:not(:disabled) {
  background-color: #3367d6;
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

#sendButton:disabled {
  background-color: #dadce0;
  color: #80868b;
  cursor: not-allowed;
  opacity: 0.6;
}

#startAudioButton {
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  color: white;
  transition: all 0.3s ease;
  min-width: 200px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(17, 153, 142, 0.3);
}

#startAudioButton:hover:not(:disabled):not(.recording) {
  background: linear-gradient(135deg, #0d8078 0%, #2dd368 100%);
  box-shadow: 0 4px 12px rgba(17, 153, 142, 0.4);
  transform: translateY(-2px);
}

#startAudioButton:disabled {
  background-color: #dadce0;
  color: #80868b;
  cursor: not-allowed;
  opacity: 0.6;
}

/* Recording state (Stop Audio) */
#startAudioButton.recording {
  background-color: #ea4335;
  animation: recordingPulse 2s ease-in-out infinite;
  position: relative;
}

#startAudioButton.recording:hover {
  background-color: #d33426;
  box-shadow: 0 0 20px rgba(234, 67, 53, 0.4);
}

#startAudioButton.recording::before {
  content: '🔴';
  margin-right: 0.5rem;
  animation: recordingBlink 1.5s ease-in-out infinite;
}

@keyframes recordingPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(234, 67, 53, 0.7);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(234, 67, 53, 0);
  }
}

@keyframes recordingBlink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* System Messages */
.system-message {
  text-align: center;
  color: #5f6368;
  font-size: 0.875rem;
  padding: 0.5rem;
  margin: 1rem 0;
  font-style: italic;
}

/* Responsive Design */

/* Tablet and below (iPad and smaller) */
@media (max-width: 1024px) {
  header {
    padding: 1.25rem 1.5rem;
  }

  .main-layout {
    max-width: 100%;
  }

  #messages {
    padding: 1.5rem;
  }

  .bubble {
    max-width: 75%;
  }
}

/* Mobile devices */
@media (max-width: 768px) {
  header {
    padding: 1rem 1rem;
  }

  h1 {
    font-size: 1.25rem;
  }

  .subtitle {
    font-size: 0.8125rem;
  }

  .header-info {
    justify-content: center;
  }

  .session-timer {
    font-size: 0.9375rem;
    padding: 0.375rem 0.875rem;
  }


  #messages {
    padding: 1rem;
  }

  .bubble {
    max-width: 85%;
    padding: 0.625rem 0.875rem;
  }

  .input-container {
    padding: 1rem;
  }

  .input-wrapper {
    flex-direction: column;
    gap: 0.625rem;
  }

  .input-wrapper.audio-only {
    max-width: 100%;
  }

  #message {
    width: 100%;
  }

  button {
    width: 100%;
    padding: 0.75rem 1.25rem;
  }

  #startAudioButton {
    max-width: 100%;
    min-width: unset;
  }
}

/* Small mobile devices */
@media (max-width: 480px) {
  header {
    padding: 0.875rem 0.875rem;
  }

  h1 {
    font-size: 1.125rem;
  }

  .subtitle {
    font-size: 0.75rem;
  }

  .header-info {
    flex-direction: column;
    gap: 0.5rem;
  }

  .session-timer {
    font-size: 0.875rem;
    padding: 0.25rem 0.75rem;
  }

  #messages {
    padding: 0.75rem;
  }

  .bubble {
    max-width: 90%;
    font-size: 0.9375rem;
  }

  .input-container {
    padding: 0.875rem;
  }

  .input-wrapper.audio-only {
    padding: 0 1rem;
  }

  button {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
  }
}

/* Loading state */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
