@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Color Palette - Dark Theme */
  --color-accent-primary: #10B981;
  --color-accent-bright: #34D399;
  --color-accent-muted: #6EE7B7;
  --color-steel-blue: #71717A;

  /* Semantic Colors */
  --bg-primary: #000000;
  --bg-secondary: #0A0A0A;
  --bg-tertiary: #141414;
  --surface-elevated: #1A1A1A;
  --surface-overlay: rgba(26, 26, 26, 0.95);

  /* UI Colors */
  --color-primary: var(--color-accent-primary);
  --color-accent: var(--color-accent-bright);
  --color-border: rgba(255, 255, 255, 0.08);
  --color-border-hover: rgba(255, 255, 255, 0.15);

  /* Text Colors */
  --text-primary: #FAFAFA;
  --text-secondary: #A1A1AA;
  --text-tertiary: #71717A;
  --text-inverse: #FFFFFF;

  /* Message Colors */
  --msg-bot-bg: var(--bg-tertiary);
  --msg-bot-border: var(--color-border);
  --msg-user-bg: linear-gradient(135deg, var(--color-accent-primary), var(--color-accent-bright));

  /* Status Colors */
  --status-online: #10B981;
  --status-success: #10B981;
  --status-error: #EF4444;
  --status-warning: #F59E0B;

  /* Spacing Scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(16, 185, 129, 0.05) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(16, 185, 129, 0.03) 0%, transparent 50%);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Typography */
.text-heading {
  font-weight: 600;
  line-height: 1.2;
}

.text-body {
  font-weight: 400;
  line-height: 1.6;
}

.text-mono {
  font-family: 'JetBrains Mono', monospace;
}

/* Chat Container */
.chat-container {
  width: 90%;
  max-width: 920px;
  height: 90vh;
  max-height: 800px;
  background: var(--surface-overlay);
  backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  overflow: hidden;
  position: relative;
}

/* Header */
header {
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, transparent 100%);
  flex-shrink: 0;
}

header h1 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  letter-spacing: -0.01em;
}

.header-icon {
  width: 24px;
  height: 24px;
  filter: brightness(0) saturate(100%) invert(82%) sepia(12%) saturate(497%) hue-rotate(176deg) brightness(93%) contrast(86%);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#language-select {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--color-border);
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  outline: none;
  cursor: pointer;
  margin-right: 8px;
  font-family: inherit;
}

#language-select:hover {
  border-color: var(--color-border-hover);
  background: rgba(255, 255, 255, 0.1);
}

#language-select option {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--status-online);
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.6), 0 0 0 3px rgba(16, 185, 129, 0.15);
  animation: pulse-status 2s ease-in-out infinite;
}

@keyframes pulse-status {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.7;
    transform: scale(1.1);
  }
}

/* Chat Box */
#chat-box {
  flex: 1;
  padding: var(--space-xl);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  scroll-behavior: smooth;
}

#chat-box::-webkit-scrollbar {
  width: 6px;
}

#chat-box::-webkit-scrollbar-track {
  background: transparent;
}

#chat-box::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

#chat-box::-webkit-scrollbar-thumb:hover {
  background: var(--color-border-hover);
}

/* Message Wrapper */
.message-wrapper {
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
  max-width: 85%;
  animation: slideIn 0.3s var(--transition-base);
}

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

.message-wrapper.bot {
  align-self: flex-start;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Avatar */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.avatar img {
  width: 20px;
  height: 20px;
  filter: brightness(0) saturate(100%) invert(72%) sepia(12%) saturate(497%) hue-rotate(176deg) brightness(93%) contrast(86%);
}

.avatar.user {
  background: linear-gradient(135deg, var(--color-blue-primary), var(--color-blue-bright));
  border: none;
}

.avatar.user::after {
  content: '👤';
  font-size: 18px;
}

/* Message Bubble */
.message {
  padding: var(--space-md) var(--space-lg);
  font-size: 0.9375rem;
  line-height: 1.6;
  border-radius: var(--radius-lg);
  position: relative;
  word-wrap: break-word;
}

.message.bot {
  background: var(--msg-bot-bg);
  border: 1px solid var(--msg-bot-border);
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.message.user {
  background: var(--msg-user-bg);
  color: var(--text-inverse);
  border-bottom-right-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}

.message b,
.message strong {
  font-weight: 600;
  color: var(--color-accent-bright);
}

.message.bot b,
.message.bot strong {
  color: var(--color-accent-muted);
}

/* Timestamp */
.message-time {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  margin-top: var(--space-xs);
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Loading Message */
.message.loading {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--msg-bot-bg);
  border: 1px solid var(--msg-bot-border);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
}

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

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--text-tertiary);
  border-radius: 50%;
  animation: typing 1.4s ease-in-out 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% {
    opacity: 0.3;
    transform: translateY(0);
  }

  30% {
    opacity: 1;
    transform: translateY(-8px);
  }
}

/* Input Area */
.input-area {
  padding: var(--space-lg);
  background: linear-gradient(0deg, var(--bg-secondary) 0%, transparent 100%);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--space-md);
  align-items: center;
  flex-shrink: 0;
}

/* Input Field */
input[type="text"] {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--color-border);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9375rem;
  outline: none;
  transition: all var(--transition-base);
}

input[type="text"]:hover {
  border-color: var(--color-border-hover);
  background: var(--surface-elevated);
}

input[type="text"]:focus {
  background: var(--surface-elevated);
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(21, 96, 189, 0.15);
}

input[type="text"]::placeholder {
  color: var(--text-tertiary);
}

/* Buttons */
button {
  background: var(--bg-tertiary);
  border: 1px solid var(--color-border);
  color: var(--text-primary);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  white-space: nowrap;
  user-select: none;
}

button:hover {
  background: var(--surface-elevated);
  border-color: var(--color-border-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

button:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

button img {
  width: 16px;
  height: 16px;
  filter: brightness(0) saturate(100%) invert(82%) sepia(12%) saturate(497%) hue-rotate(176deg) brightness(93%) contrast(86%);
}

/* Primary Button */
button.primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--text-inverse);
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

button.primary:hover {
  background: var(--color-accent);
  border-color: var(--color-accent);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.15) inset;
}

button.primary img {
  filter: brightness(0) invert(1);
}

/* Recording Button State */
#mic-btn.recording {
  background: var(--status-error);
  border-color: var(--status-error);
  color: var(--text-inverse);
  animation: pulse-recording 1.5s ease-in-out infinite;
}

#mic-btn.recording img {
  filter: brightness(0) invert(1);
}

@keyframes pulse-recording {

  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4), var(--shadow-md);
  }

  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0), var(--shadow-md);
  }
}

/* Code Blocks */
pre {
  background: var(--bg-secondary);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8125rem;
  margin-top: var(--space-sm);
  color: var(--text-secondary);
  border: 1px solid var(--color-border);
  line-height: 1.6;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-2xl);
  color: var(--text-secondary);
  text-align: center;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  opacity: 0.3;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  body {
    height: 100dvh; /* Use dynamic viewport height for mobile */
  }

  .chat-container {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }

  header {
    padding: var(--space-md) var(--space-lg);
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  header h1 {
    font-size: 1rem;
    flex: 1;
    min-width: 150px;
  }

  .header-icon {
    width: 20px;
    height: 20px;
  }

  .status-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    justify-content: flex-end;
    margin-top: var(--space-xs);
  }

  #language-select {
    font-size: 0.75rem;
    padding: 4px 6px;
    max-width: 120px;
  }

  #chat-box {
    padding: var(--space-lg);
    gap: var(--space-md);
    /* Ensure proper scrolling on mobile */
    -webkit-overflow-scrolling: touch;
  }

  .message-wrapper {
    max-width: 95%;
  }

  .avatar {
    width: 32px;
    height: 32px;
  }

  .avatar img {
    width: 16px;
    height: 16px;
  }

  .message {
    padding: var(--space-md) var(--space-md);
    font-size: 0.875rem;
    max-width: 100%;
  }

  .input-area {
    padding: var(--space-md);
    padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
    gap: var(--space-sm);
    flex-wrap: nowrap;
  }

  input[type="text"] {
    flex: 1;
    min-width: 0; /* Allow input to shrink */
    font-size: 16px; /* Prevent zoom on iOS */
    padding: var(--space-md);
  }

  button {
    padding: var(--space-md);
    font-size: 0.875rem;
    white-space: nowrap;
  }

  button.primary {
    min-width: 60px;
  }

  #mic-btn {
    min-width: 70px;
  }

  .btn-text {
    display: inline; /* Show text on mobile */
  }

  .status-indicator {
    font-size: 0.6875rem;
  }

  .status-dot {
    width: 6px;
    height: 6px;
  }

  /* Improve touch targets */
  button, input, select {
    min-height: 44px; /* iOS recommended touch target */
  }

  /* Better message spacing on small screens */
  .message-time {
    font-size: 0.625rem;
  }
}

/* Smooth scrolling for all elements */
* {
  scroll-behavior: smooth;
}

/* Focus visible styles for accessibility */
*:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}