* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Segoe UI", sans-serif;
  background: #f4f4f6;
  color: #1a1a1a;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: #ffffff;
}

.app-header {
  padding: 14px 16px;
  font-weight: 600;
  font-size: 18px;
  border-bottom: 1px solid #e5e5e8;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-buttons {
  display: flex;
  gap: 6px;
}

.speak-toggle,
.wake-toggle {
  font-weight: 400;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid #d8d8dc;
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
}

.speak-toggle.active,
.wake-toggle.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.wake-toggle.active {
  animation: mic-pulse 2s infinite;
}

.voice-status {
  padding: 6px 16px;
  font-size: 13px;
  color: #555;
  min-height: 20px;
  text-align: center;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
}

.message.user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: #f0f0f3;
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
}

.message.assistant.pending {
  color: #888;
  font-style: italic;
}

.message .sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  font-size: 12px;
}

.message .sources ol {
  margin: 4px 0 0;
  padding-left: 18px;
}

.message .sources a {
  color: inherit;
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #e5e5e8;
  flex-shrink: 0;
  background: #fff;
}

.chat-input {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 10px 14px;
  border: 1px solid #d8d8dc;
  border-radius: 20px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
}

.chat-input:focus {
  outline: none;
  border-color: #2563eb;
}

.send-button {
  flex-shrink: 0;
  padding: 10px 18px;
  border: none;
  border-radius: 20px;
  background: #2563eb;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

.send-button:disabled {
  background: #9db8ec;
  cursor: default;
}

.mic-button {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 1px solid #d8d8dc;
  border-radius: 50%;
  background: #fff;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

.mic-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.mic-button.listening {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
  animation: mic-pulse 1.2s infinite;
}

@keyframes mic-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

@media (max-width: 600px) {
  .app {
    max-width: 100%;
  }
  .message {
    max-width: 92%;
  }
}
