:root {
  color-scheme: light;
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #172033;
  --muted: #64748b;
  --line: #dbe3ee;
  --primary: #176b87;
  --primary-dark: #0f4d63;
  --primary-soft: #e1f3f7;
  --danger: #b42318;
  --shadow: 0 22px 70px rgba(15, 23, 42, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(23, 107, 135, 0.18), transparent 30rem),
    linear-gradient(135deg, #eef2f7 0%, #f8fafc 100%);
  color: var(--text);
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  width: min(1320px, 100vw);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
  gap: 18px;
}

.sidebar,
.chat-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(219, 227, 238, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-radius: 28px;
  padding: 20px;
  overflow: hidden;
}

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

.brand-mark {
  display: grid;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), #64ccc5);
  color: #fff;
  font-size: 24px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.new-chat-button,
#sendButton {
  border: 0;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  transition:
    transform 0.15s ease,
    background 0.15s ease,
    box-shadow 0.15s ease;
}

.new-chat-button {
  padding: 13px 16px;
  box-shadow: 0 12px 26px rgba(23, 107, 135, 0.22);
}

.new-chat-button:hover,
#sendButton:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.key-panel {
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-soft);
  padding: 13px;
}

.key-panel label {
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.key-panel input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  outline: none;
  padding: 10px 11px;
}

.key-panel input:focus {
  border-color: rgba(23, 107, 135, 0.55);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.1);
}

.key-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.key-actions button {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

.key-actions button:first-child {
  border-color: transparent;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.key-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.key-panel p.saved {
  color: var(--danger);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.history-header button,
.composer-actions button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 7px 12px;
}

.history-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding-right: 4px;
}

.history-item {
  display: grid;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: 16px;
  background: var(--panel-soft);
  padding: 12px;
  text-align: left;
  color: var(--text);
}

.history-item:hover,
.history-item.active {
  border-color: rgba(23, 107, 135, 0.35);
  background: var(--primary-soft);
}

.history-title {
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-time {
  color: var(--muted);
  font-size: 12px;
}

.empty-history {
  margin: auto;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  border-radius: 28px;
  overflow: hidden;
  position: relative;
}

.chat-panel::before {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.72)),
    radial-gradient(circle at 15% 18%, rgba(100, 204, 197, 0.2), transparent 18rem),
    radial-gradient(circle at 92% 10%, rgba(23, 107, 135, 0.14), transparent 22rem);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  padding: 18px 22px;
  position: relative;
  z-index: 1;
}

.topbar div {
  display: grid;
  gap: 4px;
}

.topbar span {
  color: var(--muted);
  font-size: 13px;
}

.menu-button {
  display: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  padding: 8px 11px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 22px;
  overflow-y: auto;
  padding: 30px;
  position: relative;
  z-index: 1;
  scroll-behavior: smooth;
}

.welcome {
  max-width: 720px;
  margin: auto;
  border: 1px solid rgba(219, 227, 238, 0.86);
  border-radius: 32px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  padding: clamp(24px, 4vw, 44px);
  text-align: center;
}

.welcome-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  border: 1px solid rgba(23, 107, 135, 0.18);
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 7px 13px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.welcome h2 {
  margin: 0 0 12px;
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: -0.04em;
}

.welcome p {
  margin: 0 auto 20px;
  color: var(--muted);
  line-height: 1.7;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.suggestions button {
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(180deg, #ffffff, #f8fafc);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.06);
  padding: 15px;
  text-align: left;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}

.suggestions button:hover {
  border-color: rgba(23, 107, 135, 0.35);
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.1);
  transform: translateY(-2px);
}

.message {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 14px;
  width: min(920px, 100%);
  animation: messageIn 0.18s ease-out both;
}

.message.user {
  align-self: flex-end;
  grid-template-columns: minmax(0, 1fr) 42px;
  width: min(760px, 100%);
}

.avatar {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(23, 107, 135, 0.14);
  border-radius: 16px;
  background: linear-gradient(135deg, #e1f3f7, #ffffff);
  color: var(--primary-dark);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  font-weight: 800;
}

.message.user .avatar {
  grid-column: 2;
  background: linear-gradient(135deg, #172033, #334155);
  color: #fff;
}

.message-card {
  min-width: 0;
}

.message.user .message-card {
  grid-column: 1;
  grid-row: 1;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 7px 2px;
  color: var(--muted);
  font-size: 12px;
}

.message-meta span:first-child {
  color: var(--primary-dark);
  font-weight: 800;
}

.message.user .message-meta {
  justify-content: flex-end;
}

.message.user .message-meta span:first-child {
  color: #334155;
}

.bubble {
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.96));
  box-shadow: 0 18px 46px rgba(15, 23, 42, 0.08);
  padding: 17px 19px;
  line-height: 1.72;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
}

.message.user .bubble {
  border-color: rgba(23, 107, 135, 0.35);
  background: linear-gradient(135deg, var(--primary), #0f4d63);
  color: #fff;
  box-shadow: 0 18px 42px rgba(23, 107, 135, 0.2);
}

.message.loading .bubble::after {
  content: "▋";
  margin-left: 2px;
  animation: blink 0.9s steps(2, start) infinite;
}

.bubble strong {
  color: var(--primary-dark);
  font-weight: 850;
}

.message.user .bubble strong {
  color: #fff;
}

.bubble code {
  border: 1px solid rgba(23, 107, 135, 0.12);
  border-radius: 8px;
  background: rgba(23, 107, 135, 0.08);
  color: #0f4d63;
  padding: 2px 6px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.answer-heading {
  display: block;
  margin: 8px 0 -4px;
  color: var(--primary-dark);
  font-size: 1.05em;
}

.answer-list-item {
  display: block;
  margin: 4px 0;
  padding-left: 2px;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.composer {
  border-top: 1px solid var(--line);
  background: rgba(248, 250, 252, 0.86);
  padding: 16px 20px 18px;
  position: relative;
  z-index: 1;
}

.input-meta,
.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  margin: 10px 0;
}

textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 18px;
  outline: none;
  padding: 14px 16px;
  line-height: 1.55;
  color: var(--text);
}

textarea:focus {
  border-color: rgba(23, 107, 135, 0.55);
  box-shadow: 0 0 0 4px rgba(23, 107, 135, 0.1);
}

#sendButton {
  align-self: end;
  min-width: 92px;
  min-height: 52px;
  padding: 0 20px;
}

#sendButton:disabled {
  cursor: not-allowed;
  background: #94a3b8;
  transform: none;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
    min-height: 100dvh;
    padding: 0;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(84vw, 320px);
    border-radius: 0 24px 24px 0;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .chat-panel {
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .menu-button {
    display: inline-grid;
  }

  .messages {
    padding: 18px 14px;
  }

  .suggestions {
    grid-template-columns: 1fr;
  }

  .message,
  .message.user {
    grid-template-columns: 32px minmax(0, 1fr);
    width: 100%;
  }

  .message.user .avatar {
    grid-column: 1;
  }

  .message.user .message-card {
    grid-column: 2;
    grid-row: 1;
  }

  .message.user .message-meta {
    justify-content: flex-start;
  }

  .avatar {
    width: 32px;
    height: 32px;
    border-radius: 12px;
    font-size: 13px;
  }

  .composer {
    padding: 12px;
  }

  .input-meta span:first-child,
  .composer-actions span {
    display: none;
  }

  .input-row {
    grid-template-columns: 1fr;
  }

  #sendButton {
    width: 100%;
  }
}
