* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: #ffffff;
  color: #1a1a1a;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 14px 24px;
  background: #1a56db;
}

.topbar .title {
  grid-column: 2;
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.02em;
}

.topbar .auth-buttons {
  grid-column: 3;
  justify-self: end;
  display: flex;
  gap: 8px;
}

.btn-ghost {
  background: none;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 14px;
  cursor: pointer;
  color: #1a1a1a;
}
.btn-ghost:hover { background: #f5f5f5; }

.topbar .btn-ghost {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: #ffffff;
}
.topbar .btn-ghost:hover {
  background: rgba(255,255,255,0.1);
}

.btn-primary {
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
}
.btn-primary:hover { background: #333; }

.hidden { display: none !important; }

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
  overflow: hidden;
  min-height: 0;
}

/* Empty state: no messages yet — center the input vertically */
.chat-area.is-empty {
  justify-content: center;
}
.chat-area.is-empty .chat-input-row {
  margin: auto 0;
}
.chat-area.is-empty .chat-log {
  display: none;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 12px;
}

.msg {
  padding: 10px 14px;
  border-radius: 10px;
  max-width: 85%;
  line-height: 1.45;
  white-space: pre-wrap;
}
.msg.user { align-self: flex-end; background: #f0f0f0; }
.msg.assistant { align-self: flex-start; background: #ffffff; border: 1px solid #e5e5e5; }
.msg.system-error { align-self: center; color: #b00020; font-size: 13px; }

.msg.assistant :is(p, ul, ol) { margin: 0 0 0.6em 0; }
.msg.assistant :is(p, ul, ol):last-child { margin-bottom: 0; }
.msg.assistant code {
  background: #f0f0f0;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}
.msg.assistant pre {
  background: #f0f0f0;
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
}
.msg.assistant pre code { background: none; padding: 0; }

.typing-indicator {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: #ffffff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
}
.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b3b3b3;
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.chat-input-row {
  display: flex;
  gap: 8px;
  border: 1px solid #d9d9d9;
  border-radius: 10px;
  padding: 8px;
}
.chat-input-row textarea {
  flex: 1; border: none; outline: none; resize: none;
  font-size: 14px; font-family: inherit; max-height: 140px;
}
.chat-input-row button {
  background: #1a1a1a; color: #fff; border: none;
  border-radius: 6px; padding: 0 18px; cursor: pointer;
}
.chat-input-row button:disabled { background: #aaa; cursor: not-allowed; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: #fff; border-radius: 10px; padding: 24px; width: 320px;
  display: flex; flex-direction: column; gap: 10px;
}
.modal-box h2 { margin: 0 0 6px 0; font-size: 18px; }
.modal-box input { padding: 8px 10px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 14px; }
.modal-error { color: #b00020; font-size: 13px; min-height: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
