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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #333;
}

main {
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.card {
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: #6c63ff;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 14px;
}

/* ── Chat card ── */
#chat-card { display: flex; flex-direction: column; gap: 12px; }

#chat-card .card-title {
  font-family: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', sans-serif;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: none;
  background: linear-gradient(135deg, #7c6fff, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.chat-header .card-title { margin-bottom: 0; }

.btn-reset-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  border-radius: 6px;
  color: #9ca3af;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, transform 0.2s;
}

.btn-reset-icon:hover  { color: #6c63ff; background: #f0eeff; }
.btn-reset-icon:active { transform: rotate(-180deg); }

/* ── Messages ── */
#chat-messages {
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0;
}

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.chat-bubble.user {
  align-self: flex-end;
  background: #6c63ff;
  color: #fff;
  border-bottom-right-radius: 3px;
  white-space: pre-wrap;
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: #f0f2f5;
  color: #333;
  border-bottom-left-radius: 3px;
}

.chat-bubble.assistant p  { margin: 0 0 8px; }
.chat-bubble.assistant p:last-child { margin-bottom: 0; }
.chat-bubble.assistant ul,
.chat-bubble.assistant ol { padding-left: 1.4em; margin: 4px 0 8px; }
.chat-bubble.assistant li { margin-bottom: 2px; }
.chat-bubble.assistant h1,
.chat-bubble.assistant h2,
.chat-bubble.assistant h3 { margin: 8px 0 4px; font-size: 1em; }
.chat-bubble.assistant a  { color: #6c63ff; }
.chat-bubble.assistant code {
  background: #e8eaf6;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
  font-family: monospace;
}
.chat-bubble.assistant pre {
  background: #f6f8fa;
  border: 1px solid #e1e4e8;
  border-radius: 6px;
  padding: 10px 14px;
  overflow-x: auto;
  margin: 6px 0;
}
.chat-bubble.assistant pre code {
  background: none;
  padding: 0;
  font-size: 12px;
}

/* ── Thinking indicator ── */
.chat-thinking {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 10px 14px;
}
.chat-thinking span {
  width: 7px; height: 7px;
  background: #9ca3af;
  border-radius: 50%;
  animation: bounce 1s infinite ease-in-out;
}
.chat-thinking span:nth-child(1) { animation-delay: 0s; }
.chat-thinking span:nth-child(2) { animation-delay: 0.15s; }
.chat-thinking span:nth-child(3) { animation-delay: 0.30s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

/* ── Input ── */
.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input-row textarea {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  overflow-y: hidden;
  min-height: 38px;
  max-height: 120px;
  transition: border-color 0.15s;
}
.chat-input-row textarea:focus { border-color: #6c63ff; }

.btn-apply {
  padding: 8px 20px;
  background: #6c63ff;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-apply:hover  { background: #5a52d5; }
.btn-apply:active { transform: scale(0.97); }

.chat-footer {
  display: flex;
  align-items: center;
  gap: 12px;
}
.login-state {
  font-size: 10px;
  transition: color 0.3s;
}
.login-state.logged-out { color: #d1d5db; }
.login-state.logged-in  { color: #059669; }

.chat-conv-id {
  font-size: 11px;
  font-family: monospace;
  color: #9ca3af;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Suggestions ── */
.chat-suggestions {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0;
}

.suggestion-chip {
  padding: 7px 14px;
  background: #f0eeff;
  color: #6c63ff;
  border: 1px solid #d4d0ff;
  border-radius: 20px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  line-height: 1.4;
}

.suggestion-chip:hover  { background: #e0dbff; }
.suggestion-chip:active { transform: scale(0.97); }

/* ── iframe mode ── */
html, body { height: 100%; }
body { background: transparent; }
#chat-messages { max-height: calc(100vh - 160px); }
