* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f5f5;
  color: #1a1a1a;
}

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

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #e0e0e0;
  background: #fff;
}

header h1 {
  font-size: 16px;
  margin: 0;
}

.thread {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #888;
}

.thread input {
  width: 120px;
  padding: 4px 6px;
  font-size: 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
}

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.4;
  font-size: 14px;
}

.msg.user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  white-space: pre-wrap;
}

.msg.assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e5e5e5;
}

.msg-content p {
  margin: 0 0 10px;
}

.msg-content p:last-child {
  margin-bottom: 0;
}

.msg-content h1,
.msg-content h2,
.msg-content h3 {
  margin: 12px 0 6px;
  font-size: 15px;
}

.msg-content h1:first-child,
.msg-content h2:first-child,
.msg-content h3:first-child {
  margin-top: 0;
}

.msg-content ul {
  margin: 0 0 10px;
  padding-left: 20px;
}

.msg-content li {
  margin: 2px 0;
}

.table-wrap {
  overflow-x: auto;
  margin: 0 0 10px;
}

.msg-content table {
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.msg-content th,
.msg-content td {
  border: 1px solid #e5e5e5;
  padding: 6px 10px;
  text-align: left;
}

.msg-content th {
  background: #f8f8f8;
  font-weight: 600;
}

.copy-btn {
  margin-top: 8px;
  padding: 3px 10px;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  background: #f8f8f8;
  color: #666;
  font-size: 11px;
  cursor: pointer;
}

.copy-btn:hover {
  background: #eee;
}

.citation a {
  display: inline-block;
  min-width: 14px;
  padding: 0 4px;
  margin-left: 2px;
  border-radius: 6px;
  background: #eef2ff;
  color: #2563eb;
  font-size: 10px;
  text-align: center;
  text-decoration: none;
  line-height: 15px;
}

.citation a:hover {
  background: #dbe4ff;
}

.sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #eee;
}

.sources-label {
  font-size: 11px;
  color: #999;
  margin-bottom: 5px;
}

.sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: #555;
  background: #f5f5f5;
  border: 1px solid #e5e5e5;
  border-radius: 12px;
  padding: 3px 9px 3px 3px;
  text-decoration: none;
}

.source-chip:hover {
  background: #ececec;
}

.source-n {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  font-size: 9px;
}

.msg.thinking {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 14px;
}

.msg.thinking span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #bbb;
  animation: thinking-bounce 1.2s infinite ease-in-out;
}

.msg.thinking span:nth-child(2) { animation-delay: 0.2s; }
.msg.thinking span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.tool-call {
  align-self: flex-start;
  font-size: 12px;
  color: #aaa;
  font-style: italic;
  padding: 0 4px;
}

#chat-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #e0e0e0;
  background: #fff;
}

#message {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 14px;
}

button {
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: #2563eb;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}
