:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --border: #e2e2e5;
  --accent: #10a37f;
  --accent-hover: #0d8c6d;
  --bubble-user: #10a37f;
  --bubble-user-text: #ffffff;
  --bubble-bot: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1f22;
    --surface: #2a2b2f;
    --text: #ececec;
    --text-muted: #9a9a9a;
    --border: #3a3b3f;
    --bubble-user: #10a37f;
    --bubble-user-text: #ffffff;
    --bubble-bot: #2f3033;
  }
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 18px;
  margin: 0;
}

.reset-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.reset-btn:hover {
  background: var(--surface);
  color: var(--text);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}

.msg.bot {
  align-self: flex-start;
  background: var(--bubble-bot);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg.error {
  align-self: center;
  background: transparent;
  color: #d64545;
  font-size: 13px;
  border: none;
}

.msg.typing {
  align-self: flex-start;
  background: var(--bubble-bot);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  padding: 14px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.4s infinite both;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

.attachment-preview:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}

.attachment-preview img {
  height: 56px;
  width: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.attachment-preview button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  line-height: 1;
  cursor: pointer;
  font-size: 15px;
}

.msg img.attachment {
  display: block;
  max-width: 240px;
  max-height: 240px;
  border-radius: 10px;
  margin-bottom: 6px;
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 0 16px;
  border-top: 1px solid var(--border);
}

#attach-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  width: 42px;
  height: 42px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

#attach-btn:hover {
  background: var(--bg);
}

#chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  max-height: 160px;
}

#chat-input:focus {
  outline: none;
  border-color: var(--accent);
}

#send-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  padding: 0 18px;
  font-size: 15px;
  cursor: pointer;
}

#send-btn:hover {
  background: var(--accent-hover);
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
