* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Noto Sans TC", sans-serif;
  background: #f5f5f7;
  color: #1a1a1a;
}

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

#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #ddd;
  background: #fff;
}

#app-header h1 {
  font-size: 1.1rem;
  margin: 0;
}

#clear-btn {
  background: none;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
}

#clear-btn:hover {
  background: #eee;
}

#message-list {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.bubble {
  max-width: 80%;
  padding: 0.6rem 0.9rem;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
}

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

.bubble.model {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #ddd;
  border-bottom-left-radius: 4px;
}

.bubble.error {
  align-self: flex-start;
  background: #fdecea;
  border: 1px solid #f5b5ae;
  color: #8a1f11;
}

.bubble.model h1,
.bubble.model h2,
.bubble.model h3 {
  margin: 0.8em 0 0.4em;
  line-height: 1.3;
}

.bubble.model h1 {
  font-size: 1.3em;
}

.bubble.model h2 {
  font-size: 1.15em;
}

.bubble.model h3 {
  font-size: 1.05em;
}

.bubble.model p {
  margin: 0.5em 0;
}

.bubble.model :first-child {
  margin-top: 0;
}

.bubble.model :last-child {
  margin-bottom: 0;
}

.bubble.model strong {
  font-weight: 700;
}

.bubble.model ul,
.bubble.model ol {
  margin: 0.4em 0;
  padding-left: 1.4em;
}

.bubble.model li {
  margin: 0.2em 0;
}

.bubble.model hr {
  border: none;
  border-top: 1px solid #ddd;
  margin: 1em 0;
}

.bubble.model code {
  background: #f0f0f0;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}

.bubble.model pre {
  background: #f0f0f0;
  padding: 0.6em 0.8em;
  border-radius: 8px;
  overflow-x: auto;
}

.bubble.model a {
  color: #2563eb;
}

.bubble.loading {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.75rem 1rem;
}

.bubble.loading span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #999;
  animation: bubble-bounce 1.2s infinite ease-in-out;
}

.bubble.loading span:nth-child(2) {
  animation-delay: 0.15s;
}

.bubble.loading span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bubble-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

#attachment-error {
  padding: 0 1rem;
  font-size: 0.8rem;
  color: #8a1f11;
}

#attachment-error:empty {
  display: none;
}

#attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0 1rem;
}

#attachment-preview:empty {
  display: none;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
  max-width: 160px;
}

.attachment-chip img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.attachment-chip .chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip .chip-remove {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0 0.2rem;
  color: #666;
}

.bubble-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

#attach-btn {
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #fff;
  font-size: 1.1rem;
  padding: 0 0.75rem;
  cursor: pointer;
}

#attach-btn:hover {
  background: #eee;
}

#attach-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

#login-screen[hidden],
#app[hidden] {
  display: none;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 280px;
  padding: 1.5rem;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 12px;
}

#login-form h1 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
  text-align: center;
}

#login-password {
  padding: 0.6rem 0.75rem;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 1rem;
}

#login-form button {
  padding: 0.6rem;
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

#login-error {
  margin: 0;
  font-size: 0.8rem;
  color: #8a1f11;
  min-height: 1em;
}

#version-badge {
  position: fixed;
  right: 0.5rem;
  bottom: 0.5rem;
  font-size: 0.7rem;
  color: #999;
  pointer-events: none;
}

#input-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid #ddd;
  background: #fff;
}

#input-box {
  flex: 1;
  resize: none;
  padding: 0.6rem 0.75rem;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}

#send-btn {
  padding: 0 1.25rem;
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

#send-btn:disabled,
#input-box:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#send-btn:not(:disabled):hover {
  background: #1d4ed8;
}
