* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #0f172a;
  background: linear-gradient(120deg, #b8d5ff, #c6f6d1);
  background-attachment: fixed;
}

.chat-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.chat-shell {
  width: min(960px, 100%);
  height: min(760px, calc(100vh - 48px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 28px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(18px);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 26px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, #2563eb, #14b8a6);
  border-radius: 16px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  color: #64748b;
  font-size: 13px;
}

.status {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: #475569;
  background: #f1f5f9;
  white-space: nowrap;
}

.status.connected {
  color: #047857;
  background: #d1fae5;
}

.status.error {
  color: #b91c1c;
  background: #fee2e2;
}

.status.connecting {
  color: #1d4ed8;
  background: #dbeafe;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 26px;
}

.message {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}

.message-avatar {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: white;
  background: #2563eb;
  overflow: hidden;
}

.ai-message .message-avatar {
  background: #ffffff;
  border: 1px solid rgba(59, 130, 246, 0.2);
  padding: 2px;
}

.ai-message .message-avatar img {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
}

.user-message {
  flex-direction: row-reverse;
}

.user-message .message-avatar {
  background: #0f172a;
}

.message-content {
  max-width: min(680px, 78%);
  padding: 14px 16px;
  border-radius: 18px;
  color: #1e293b;
  background: #f8fafc;
  border: 1px solid rgba(148, 163, 184, 0.18);
  line-height: 1.65;
}

.user-message .message-content {
  color: white;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border: none;
}

.chat-input-area {
  padding: 18px 22px 22px;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(248, 250, 252, 0.72);
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

#message-input {
  flex: 1;
  min-height: 48px;
  max-height: 120px;
  resize: none;
  padding: 14px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  outline: none;
  font: inherit;
  background: white;
}

#message-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

#send-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 16px;
  color: white;
  background: #2563eb;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

#send-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

#send-button:not(:disabled):hover {
  transform: translateY(-1px);
}

.input-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: #64748b;
  font-size: 12px;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.58);
  backdrop-filter: blur(4px);
}

.loading-card {
  padding: 14px 18px;
  border-radius: 16px;
  background: white;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
  color: #475569;
}

.chat-shell-wrap {
  position: relative;
}

@media (max-width: 640px) {
  .chat-page {
    padding: 0;
  }

  .chat-shell {
    height: 100vh;
    border-radius: 0;
  }

  .chat-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .message-content {
    max-width: 82%;
  }
}
