/* CSS Variables for Theming */
:root {
  --primary-color: #6B7280;
  --primary-dark: #4B5563;
  --primary-light: #E5E7EB;
  --accent-color: #10B981;
  --success-color: #4CAF50;
  --error-color: #F44336;
  --warning-color: #FF9800;
  
  /* Light Theme */
  --bg-primary: #FAFAFA;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #F5F5F5;
  --text-primary: #212121;
  --text-secondary: #757575;
  --text-hint: #BDBDBD;
  --border-color: #E0E0E0;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-elevated: 0 4px 16px rgba(0, 0, 0, 0.15);
  
  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  
  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  
  /* Typography */
  --font-family: 'DM Sans', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
  --transition-slow: 0.3s ease;
}

/* Dark Theme */
.dark-theme {
  --bg-primary: #121212;
  --bg-secondary: #1E1E1E;
  --bg-tertiary: #2C2C2C;
  --text-primary: #FFFFFF;
  --text-secondary: #AAAAAA;
  --text-hint: #666666;
  --border-color: #333333;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-elevated: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* Reset and Base Styles */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.5;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* App Layout */
.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  margin: 0 auto;
  background: var(--bg-secondary);
  box-shadow: var(--shadow);
}

/* Header */
.app-header {
  background: var(--primary-color);
  color: white;
  padding: var(--spacing-md) var(--spacing-lg);
  box-shadow: var(--shadow);
  position: relative;
  z-index: 10;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 100%;
}

.agent-info {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.agent-info .material-icons {
  font-size: 28px;
}

.agent-info h1 {
  margin: 0;
  font-size: var(--font-size-xl);
  font-weight: 500;
  text-transform: capitalize;
}

.header-actions {
  display: flex;
  gap: var(--spacing-sm);
}

.icon-btn {
  background: transparent;
  border: none;
  color: white;
  padding: var(--spacing-sm);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-fast);
  min-width: 44px;
  min-height: 44px;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.2);
}

.icon-btn .material-icons {
  font-size: 20px;
}

/* Chat Container */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-md);
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--text-hint);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  text-align: center;
}

.empty-state .material-icons {
  font-size: 64px;
  opacity: 0.5;
  margin-bottom: var(--spacing-md);
}

.empty-state p {
  margin: 0;
  font-size: var(--font-size-lg);
}

/* Messages */
.message-wrapper {
  display: flex;
  margin-bottom: var(--spacing-md);
  opacity: 0;
  animation: fadeInUp 0.3s ease forwards;
}

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

.message-wrapper.user {
  flex-direction: row-reverse;
}

.message-avatar {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin: 0 var(--spacing-sm);
  flex-shrink: 0;
}

.message-wrapper.user .message-avatar {
  background: var(--primary-color);
  color: white;
}

.message-wrapper.ai .message-avatar {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.message-avatar .material-icons {
  font-size: 20px;
  margin-top: 10px;
}

.message-bubble {
  max-width: 70%;
  min-width: 100px;
  position: relative;
}

.message-wrapper.user .message-bubble {
  background: var(--primary-color);
  color: white;
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
  margin-left: var(--spacing-xl);
}

.message-wrapper.ai .message-bubble {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
  margin-right: var(--spacing-xl);
}

.message-content {
  padding: var(--spacing-sm) var(--spacing-md);
}

.text-content {
  word-wrap: break-word;
  line-height: 1.4;
}

.message-time {
  padding: 0 var(--spacing-md) var(--spacing-xs);
  font-size: var(--font-size-xs);
  opacity: 0.7;
}

/* Markdown Response Styling */
.markdown-response {
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.markdown-response pre {
  margin: 0;
  padding: var(--spacing-md);
  overflow-x: auto;
  font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
  font-size: var(--font-size-sm);
  line-height: 1.4;
  background: var(--bg-secondary) !important;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.markdown-response pre::-webkit-scrollbar {
  height: 6px;
}

.markdown-response pre::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
}

.markdown-response pre::-webkit-scrollbar-thumb {
  background: var(--text-hint);
  border-radius: 3px;
}

.markdown-response code {
  font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
  background: transparent;
}

/* Loading Animation */
.message-bubble.loading {
  background: var(--bg-tertiary);
  padding: var(--spacing-md);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Input Area */
.chat-input-container {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: var(--spacing-md);
}

.chat-input {
  max-width: 100%;
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  background: var(--bg-tertiary);
  border-radius: var(--radius-xl);
  padding: var(--spacing-xs);
  border: 2px solid transparent;
  transition: border-color var(--transition-fast);
}

.input-wrapper:focus-within {
  border-color: var(--primary-color);
}

.input-wrapper textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  padding: var(--spacing-sm) var(--spacing-md);
  color: var(--text-primary);
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  resize: none;
  min-height: 20px;
  max-height: 120px;
  overflow-y: auto;
}

.input-wrapper textarea::placeholder {
  color: var(--text-hint);
}


/* Responsive Design */
@media (max-width: 768px) {
  .app {
    height: 100vh;
    max-width: 100%;
  }
  
  .app-header {
    padding: var(--spacing-sm) var(--spacing-md);
  }
  
  .agent-info h1 {
    font-size: var(--font-size-lg);
  }
  
  .chat-messages {
    padding: var(--spacing-sm);
  }
  
  .message-bubble {
    max-width: 85%;
  }
  
  .message-wrapper.user .message-bubble {
    margin-left: var(--spacing-md);
  }
  
  .message-wrapper.ai .message-bubble {
    margin-right: var(--spacing-md);
  }
  
  .chat-input-container {
    padding: var(--spacing-sm);
  }
  
  .json-response pre {
    font-size: var(--font-size-xs);
  }
}

@media (max-width: 480px) {
  .header-content {
    flex-wrap: wrap;
    gap: var(--spacing-sm);
  }
  
  .agent-info {
    flex: 1;
  }
  
  .message-bubble {
    max-width: 90%;
  }
  
  .message-avatar {
    width: 32px;
    height: 32px;
  }
  
  .message-avatar .material-icons {
    font-size: 16px;
    margin-top: 8px;
  }
}

/* High contrast mode support */
@media (prefers-contrast: more) {
  :root {
    --border-color: #000000;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
  
  .dark-theme {
    --border-color: #FFFFFF;
    --text-hint: #CCCCCC;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .chat-messages {
    scroll-behavior: auto;
  }
}
