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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #fff;
  color: #1a1a1a;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Header */
#header {
  flex-shrink: 0;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 12px 16px;
}

.header-content {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 800px;
  margin: 0 auto;
}

#new-chat-btn {
  margin-left: auto;
  background: none;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  color: #6b7280;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

#new-chat-btn:hover {
  background: #f3f4f6;
  color: #2dccd3;
  border-color: #2dccd3;
}

#new-chat-btn svg {
  width: 16px;
  height: 16px;
}

.avatar {
  height: 36px;
  flex-shrink: 0;
  border-radius: 6px;
}

#header h1 {
  font-size: 17px;
  font-weight: 600;
  color: #111;
}

/* Messages */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.message {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
}

.message.ai p {
  margin: 0;
}

.message.ai p + p {
  margin-top: 8px;
}

.message.ai strong {
  font-weight: 600;
}

.message.ai h2, .message.ai h3, .message.ai h4 {
  margin: 8px 0 4px;
  font-weight: 600;
}

.message.ai h2 { font-size: 17px; }
.message.ai h3 { font-size: 16px; }
.message.ai h4 { font-size: 15px; }

.message.ai ul, .message.ai ol {
  margin: 6px 0;
  padding-left: 20px;
}

.message.ai li {
  margin: 2px 0;
}

.message.ai code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}

.message.ai pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
}

.message.ai pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  color: inherit;
}

.message.user {
  align-self: flex-end;
  background: #2dccd3;
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.message.ai {
  align-self: flex-start;
  background: #F3F4F6;
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Welcome screen */
#welcome {
  margin: auto;
  text-align: center;
  color: #6b7280;
}

.welcome-logo {
  height: 64px;
  border-radius: 10px;
  margin-bottom: 16px;
}

#welcome h2 {
  font-size: 20px;
  font-weight: 600;
  color: #111;
  margin-bottom: 8px;
}

#welcome p {
  font-size: 15px;
}

/* Loading dots */
.loading-dots {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9ca3af;
  animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
.loading-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Input area */
#input-area {
  flex-shrink: 0;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  padding: 12px 16px;
}

#chat-form {
  display: flex;
  gap: 8px;
  max-width: 800px;
  margin: 0 auto;
}

#user-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 24px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

#user-input:focus {
  border-color: #2dccd3;
}

#user-input:disabled {
  background: #f9fafb;
  color: #9ca3af;
}

#send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #2dccd3;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

#send-btn:hover {
  background: #25b0b6;
}

#send-btn:disabled {
  background: #9fe6e9;
  cursor: not-allowed;
}

#send-btn svg {
  width: 18px;
  height: 18px;
}

/* Scrollbar */
#messages::-webkit-scrollbar {
  width: 6px;
}

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

#messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

/* Mobile */
@media (max-width: 600px) {
  .message {
    max-width: 85%;
    font-size: 14px;
  }

  #header {
    padding: 10px 12px;
  }

  #input-area {
    padding: 10px 12px;
  }
}
