:root {
  color-scheme: light;
  --page: #e9edf2;
  --surface: #f7f8fa;
  --surface-strong: #ffffff;
  --line: #d8dde5;
  --text: #1f2933;
  --muted: #7a8694;
  --assistant: #ffffff;
  --assistant-border: #e3e7ee;
  --user: #86e36f;
  --user-border: #70cd5a;
  --accent: #2f7df6;
  --danger: #c2413b;
  --shadow: 0 18px 45px rgba(30, 41, 59, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--page);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.chat-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.chat-window {
  width: min(920px, 100%);
  height: min(840px, calc(100dvh - 36px));
  min-height: 560px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.chat-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface-strong);
  border-bottom: 1px solid var(--line);
}

.avatar,
.login-avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(145deg, #1f2937, #536179);
  color: #fff;
  font-weight: 700;
}

.chat-title h1,
.chat-title p {
  margin: 0;
}

.chat-title h1 {
  font-size: 18px;
  line-height: 1.25;
}

.chat-title p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.text-button,
.load-earlier {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--text);
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.icon-button:hover,
.text-button:hover,
.load-earlier:hover {
  border-color: #b7c0cc;
  background: #f2f5f8;
}

.search-bar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  padding: 10px 16px;
  background: #f0f3f7;
  border-bottom: 1px solid var(--line);
}

.search-bar input {
  width: 100%;
  height: 36px;
  border: 1px solid #d3d9e2;
  border-radius: 18px;
  padding: 0 14px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.search-bar input:focus,
.composer textarea:focus,
.login-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 125, 246, 0.12);
}

.text-button {
  height: 36px;
  border-radius: 18px;
  padding: 0 14px;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px 18px;
  background:
    linear-gradient(rgba(229, 234, 240, 0.92), rgba(229, 234, 240, 0.92)),
    repeating-linear-gradient(135deg, transparent 0 12px, rgba(255, 255, 255, 0.22) 12px 13px);
}

.time-separator {
  align-self: center;
  margin: 8px 0 4px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(126, 140, 156, 0.18);
  color: #66717f;
  font-size: 12px;
}

.message-row {
  display: grid;
  gap: 3px;
  max-width: min(76%, 680px);
  animation: bubble-in 140ms ease-out;
}

.message-row.assistant {
  align-self: flex-start;
  justify-items: start;
}

.message-row.user {
  align-self: flex-end;
  justify-items: end;
}

.bubble {
  width: fit-content;
  max-width: 100%;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  line-height: 1.52;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.bubble.assistant {
  background: var(--assistant);
  border-color: var(--assistant-border);
  color: var(--text);
}

.bubble.user {
  background: var(--user);
  border-color: var(--user-border);
  color: #10220f;
}

.message-time {
  color: #8190a1;
  font-size: 11px;
  padding: 0 4px;
}

.typing-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-width: 34px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  display: inline-block;
  border-radius: 50%;
  background: #7f8b99;
  animation: pulse 1.1s infinite ease-in-out;
}

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

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

.load-earlier {
  align-self: center;
  min-height: 32px;
  border-radius: 16px;
  padding: 0 14px;
  color: #556170;
  font-size: 13px;
}

.empty-state {
  margin: auto;
  color: #697586;
  font-size: 14px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  background: var(--surface-strong);
  border-top: 1px solid var(--line);
}

.composer textarea {
  width: 100%;
  min-height: 40px;
  max-height: 140px;
  resize: none;
  border: 1px solid #d3d9e2;
  border-radius: 8px;
  padding: 9px 11px;
  background: #fff;
  color: var(--text);
  line-height: 1.45;
  outline: none;
  overflow-y: hidden;
}

.send-button,
.login-form button {
  min-width: 68px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
}

.send-button:disabled {
  cursor: default;
  opacity: 0.55;
}

.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #eef2f7, #dde5ee);
}

.login-panel {
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-avatar {
  width: 52px;
  height: 52px;
}

.login-panel h1,
.login-panel p {
  margin: 0;
}

.login-panel h1 {
  font-size: 28px;
}

.login-panel p,
.login-status {
  color: var(--muted);
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 12px;
  margin-top: 6px;
}

.login-field {
  display: grid;
  gap: 7px;
}

.login-field span {
  color: #566273;
  font-size: 14px;
}

.login-field input {
  width: 100%;
  height: 42px;
  border: 1px solid #d3d9e2;
  border-radius: 8px;
  padding: 0 12px;
  outline: none;
}

.login-status {
  min-height: 21px;
  font-size: 13px;
}

@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

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

  .chat-window {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .message-row {
    max-width: 84%;
  }

  .chat-header {
    padding-top: max(12px, env(safe-area-inset-top));
  }
}

@media (max-width: 420px) {
  .search-bar,
  .composer,
  .messages,
  .chat-header {
    padding-left: 12px;
    padding-right: 12px;
  }

  .message-row {
    max-width: 88%;
  }

  .send-button {
    min-width: 58px;
  }

  .text-button {
    padding: 0 10px;
  }
}
