* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  font-size: 15px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.panel { width: 100%; max-width: 760px; }

/* ---- Login ---- */
#login { max-width: 380px; text-align: center; padding: 24px; }
#login h1 { font-size: 2rem; letter-spacing: -0.02em; font-weight: 600; margin-bottom: 4px; }
#login .sub { color: #94a3b8; margin-bottom: 28px; font-size: 0.95rem; }
#loginForm { display: flex; flex-direction: column; gap: 10px; }
#loginForm input {
  padding: 12px 16px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  color: #e2e8f0;
  font-size: 1rem;
  font-family: inherit;
}
#loginForm input:focus { outline: none; border-color: #60a5fa; background: #223047; }
#loginForm button {
  padding: 12px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  margin-top: 6px;
  transition: background 0.15s;
}
#loginForm button:hover { background: #1d4ed8; }
#loginForm button:disabled { background: #475569; cursor: wait; }
.error { color: #f87171; font-size: 0.85rem; min-height: 1.2rem; margin-top: 4px; }

/* ---- Chat ---- */
#chat { display: flex; flex-direction: column; height: calc(100vh - 40px); max-height: 920px; }
#chat header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  border-bottom: 1px solid #1e293b;
}
#chat header h1 { font-size: 1.2rem; letter-spacing: -0.01em; font-weight: 600; }
#chat header div { display: flex; gap: 8px; }
#chat header button {
  background: transparent;
  color: #94a3b8;
  border: 1px solid #1e293b;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
}
#chat header button:hover { color: #e2e8f0; border-color: #334155; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }

.msg { display: flex; max-width: 85%; }
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }
.msg .bubble {
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  font-size: 0.95rem;
}
.msg.user .bubble { background: #2563eb; color: white; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: #1e293b; color: #e2e8f0; border-bottom-left-radius: 4px; }
.msg.assistant.error .bubble { background: #3b1f1f; color: #fca5a5; border: 1px solid #7f1d1d; }

.typing {
  align-self: flex-start;
  padding: 10px 14px;
  background: #1e293b;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  color: #64748b;
  font-style: italic;
}
.dot { display: inline-block; animation: bounce 1.4s infinite; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

#chatForm {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid #1e293b;
  align-items: flex-end;
}
#input {
  flex: 1;
  padding: 10px 14px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  color: #e2e8f0;
  font-size: 0.95rem;
  resize: none;
  min-height: 44px;
  max-height: 200px;
  font-family: inherit;
  line-height: 1.5;
}
#input:focus { outline: none; border-color: #60a5fa; }
#sendBtn {
  padding: 10px 22px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 500;
  font-family: inherit;
  height: 44px;
}
#sendBtn:hover { background: #1d4ed8; }
#sendBtn:disabled { background: #334155; cursor: not-allowed; }

@media (max-width: 640px) {
  body { padding: 0; }
  #chat { height: 100vh; max-height: none; padding: 0 12px; border-radius: 0; }
  #login { padding: 20px; }
  .msg { max-width: 92%; }
}
