:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-hover: #f5f5f5;
  --text-primary: #1a1a2e;
  --text-secondary: #555;
  --accent: #4361ee;
  --accent-hover: #3a56d4;
  --accent-light: #eef0ff;
  --border: #e0e0e0;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  --user-bg: #4361ee;
  --user-text: #ffffff;
  --assistant-bg: #ffffff;
  --assistant-text: #1a1a2e;
  --header-bg: rgba(255, 255, 255, 0.85);
  --footer-bg: #ffffff;
  --welcome-bg: #f8f9ff;
  --chip-bg: #eef0ff;
  --chip-border: #d0d5ff;
  --chip-hover: #4361ee;
  --chip-text: #4361ee;
  --chip-hover-text: #ffffff;
  --scrollbar-thumb: #c0c0c0;
  --scrollbar-track: transparent;
  --danger: #ef476f;
}

[data-theme="dark"] {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface-hover: #222240;
  --text-primary: #e8e8f0;
  --text-secondary: #9999b0;
  --accent: #6c8cff;
  --accent-hover: #5270e0;
  --accent-light: #1e2040;
  --border: #2a2a45;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --user-bg: #4361ee;
  --user-text: #ffffff;
  --assistant-bg: #1e1e38;
  --assistant-text: #e0e0ec;
  --header-bg: rgba(15, 15, 26, 0.9);
  --footer-bg: #0f0f1a;
  --welcome-bg: #1a1a2e;
  --chip-bg: #1e2040;
  --chip-border: #3a3a60;
  --chip-hover: #4361ee;
  --chip-text: #8c9cff;
  --chip-hover-text: #ffffff;
  --scrollbar-thumb: #3a3a5c;
  --scrollbar-track: transparent;
}

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

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  transition: background 0.3s ease, color 0.3s ease;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}

.site-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  transition: color 0.3s ease;
}

.app-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  flex: 1;
  transition: color 0.3s ease;
}

.theme-toggle {
  background: var(--accent-light);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: background 0.3s ease, border-color 0.3s ease, transform 0.2s ease;
  flex-shrink: 0;
}

.theme-toggle:hover {
  transform: scale(1.08);
}

.theme-toggle .icon-dark { display: none; }
[data-theme="dark"] .theme-toggle .icon-light { display: none; }
[data-theme="dark"] .theme-toggle .icon-dark { display: inline; }

/* Main Layout */
.chat-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

/* Mic Status */
.mic-status {
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
  margin-bottom: 8px;
  display: none;
  animation: pulse 1s ease-in-out infinite;
}

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

/* Chat Container */
.chat-container {
  width: 100%;
  max-width: 720px;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: background 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

/* Message Area */
.message-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
}

.message-area::-webkit-scrollbar {
  width: 6px;
}

.message-area::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

.message-area::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

/* Welcome Message */
.welcome-message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--welcome-bg);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.welcome-avatar {
  font-size: 28px;
  flex-shrink: 0;
  line-height: 1;
}

.welcome-message p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
  transition: color 0.3s ease;
}

/* Messages */
.message {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  animation: messageIn 0.3s ease-out;
}

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

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 4px;
}

.message-avatar.user {
  background: var(--user-bg);
  order: 1;
}

.message-avatar.assistant {
  background: var(--accent-light);
  border: 1px solid var(--border);
}

.message-content {
  max-width: 80%;
  display: flex;
  flex-direction: column;
}

.message.user .message-content {
  align-items: flex-end;
}

.message-bubble {
  padding: 10px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

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

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

.message.assistant .message-bubble {
  background: var(--assistant-bg);
  color: var(--assistant-text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  padding: 0 4px;
}

.message-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--text-secondary);
  transition: background 0.2s, color 0.2s;
}

.message-actions button:hover {
  background: var(--accent-light);
  color: var(--accent);
}

/* Message content formatting */
.message-bubble b, .message-bubble strong { font-weight: 700; }
.message-bubble i, .message-bubble em { font-style: italic; }
.message-bubble u { text-decoration: underline; }
.message-bubble a { color: var(--accent); text-decoration: underline; }
.message-bubble ul, .message-bubble ol { padding-left: 20px; margin: 6px 0; }
.message-bubble li { margin-bottom: 4px; }

/* Typing Indicator */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 12px 24px;
}

.typing-indicator.active {
  display: flex;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: typingBounce 1.4s ease-in-out infinite;
}

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

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

/* Suggestions */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 20px 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  color: var(--chip-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.chip:hover {
  background: var(--chip-hover);
  border-color: var(--chip-hover);
  color: var(--chip-hover-text);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(67, 97, 238, 0.2);
}

/* Input Area */
.input-area {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  transition: border-color 0.3s ease;
}

.input-area input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface-hover);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease, background 0.3s ease, color 0.3s ease;
}

.input-area input::placeholder {
  color: var(--text-secondary);
}

.input-area input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}

.btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

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

.btn-mic {
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--border);
}

.btn-mic:hover {
  background: var(--accent);
  color: white;
  transform: scale(1.05);
}

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

/* Footer */
.app-footer {
  text-align: center;
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--footer-bg);
  border-top: 1px solid var(--border);
  transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Responsive */
@media (max-width: 600px) {
  .app-header {
    padding: 10px 16px;
    gap: 10px;
  }

  .app-title {
    font-size: 17px;
  }

  .app-subtitle {
    display: none;
  }

  .chat-layout {
    padding: 8px;
  }

  .chat-container {
    border-radius: 12px;
  }

  .message-area {
    padding: 12px;
  }

  .message-content {
    max-width: 90%;
  }

  .message-bubble {
    font-size: 14px;
    padding: 8px 14px;
  }

  .suggestions {
    padding: 0 12px 8px;
    gap: 6px;
  }

  .chip {
    font-size: 12px;
    padding: 5px 12px;
  }

  .input-area {
    padding: 8px 12px 12px;
  }

  .input-area input {
    font-size: 14px;
    padding: 8px 14px;
  }

  .welcome-message {
    padding: 12px;
  }

  .welcome-avatar {
    font-size: 22px;
  }
}
