:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #171717;
  --muted: #7a8088;
  --line: #e7e9ee;
  --soft: #f0f3f7;
  --brand: #2f6fed;
  --brand-deep: #1555d8;
  --good: #0f8f68;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(21, 32, 56, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  letter-spacing: 0;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 920px;
  margin: 0 auto;
  background: #f8f9fb;
  overflow: hidden;
  position: relative;
}

.top-bar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(248, 249, 251, 0.94);
  border-bottom: 1px solid rgba(231, 233, 238, 0.85);
  backdrop-filter: blur(18px);
  z-index: 4;
}

.icon-btn,
.new-chat-btn,
.close-btn,
.text-btn,
.send-btn,
.strip-head button,
.quick-row button {
  border: 0;
  border-radius: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 0 11px;
  background: #ffffff;
  border: 1px solid var(--line);
}

.icon-btn span {
  height: 2px;
  border-radius: 2px;
  background: #30343b;
}

.app-title {
  font-size: 17px;
  font-weight: 800;
  line-height: 1.2;
}

.app-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.new-chat-btn {
  min-height: 36px;
  padding: 0 12px;
  background: #ffffff;
  color: #2f3640;
  border: 1px solid var(--line);
}

.reference-strip-wrap {
  background: #f8f9fb;
  border-bottom: 1px solid var(--line);
  padding: 9px 0 10px;
}

.strip-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 14px 8px;
  color: #3d4653;
  font-size: 13px;
  font-weight: 700;
}

.strip-head button {
  background: transparent;
  color: var(--muted);
  padding: 4px 0;
  font-size: 12px;
}

.reference-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  padding: 0 14px 2px;
  scrollbar-width: none;
}

.reference-strip::-webkit-scrollbar,
.quick-row::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.modal-content::-webkit-scrollbar {
  display: none;
}

.reference-chip {
  flex: 0 0 178px;
  min-height: 96px;
  border: 1px solid #e2e7ef;
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
  scroll-snap-align: start;
  text-align: left;
}

.reference-chip.active {
  border-color: rgba(47, 111, 237, 0.58);
  box-shadow: 0 8px 22px rgba(47, 111, 237, 0.12);
}

.chip-meta {
  color: var(--brand);
  font-size: 12px;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-title {
  color: #20242a;
  font-size: 13px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty-chip {
  flex-basis: 240px;
  background: #fdfefe;
}

.quick-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 14px 8px;
  background: #f8f9fb;
  border-bottom: 1px solid var(--line);
}

.quick-row button {
  flex: 0 0 auto;
  background: #ffffff;
  border: 1px solid #e3e6ec;
  color: #303844;
  padding: 8px 11px;
  font-size: 13px;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 14px 18px;
  overscroll-behavior: contain;
}

.welcome {
  padding: 22px 8px 16px;
}

.welcome h1 {
  margin: 0 0 10px;
  font-size: 24px;
  line-height: 1.2;
}

.welcome p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
  font-size: 14px;
}

.message {
  display: flex;
  margin: 0 0 16px;
}

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

.message.assistant {
  justify-content: flex-start;
}

.message-content {
  max-width: min(82%, 680px);
  border-radius: 8px;
  padding: 12px 13px;
  line-height: 1.78;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
}

.message.user .message-content {
  color: #ffffff;
  background: var(--brand);
}

.message.assistant .message-content {
  background: #ffffff;
  border: 1px solid var(--line);
  color: #20242a;
}

.message-content.streaming::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 18px;
  margin-left: 3px;
  background: var(--brand);
  vertical-align: -3px;
  animation: blink 1s steps(2, start) infinite;
}

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

.composer {
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(248, 249, 251, 0.96);
  border-top: 1px solid var(--line);
}

.input-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px;
  border: 1px solid #dfe3eb;
  background: #ffffff;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(24, 31, 46, 0.06);
}

.composer textarea {
  width: 100%;
  max-height: 148px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 8px 6px;
  line-height: 1.55;
  font-size: 15px;
  background: transparent;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.text-btn {
  min-height: 34px;
  padding: 0 8px;
  background: #fff1f0;
  color: var(--danger);
}

.send-btn {
  min-width: 58px;
  min-height: 36px;
  padding: 0 13px;
  background: var(--brand);
  color: #ffffff;
  font-weight: 700;
}

.send-btn:disabled,
.text-btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.drawer,
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.drawer.open,
.modal.open {
  pointer-events: auto;
}

.drawer-mask,
.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(18, 24, 36, 0);
  transition: background 0.18s ease;
}

.drawer.open .drawer-mask,
.modal.open .modal-mask {
  background: rgba(18, 24, 36, 0.42);
}

.drawer-panel {
  position: absolute;
  inset: 0 auto 0 0;
  width: min(86vw, 340px);
  background: #ffffff;
  box-shadow: var(--shadow);
  transform: translateX(-102%);
  transition: transform 0.22s ease;
  padding: calc(16px + env(safe-area-inset-top)) 14px 16px;
  display: flex;
  flex-direction: column;
}

.drawer.open .drawer-panel {
  transform: translateX(0);
}

.drawer-head,
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.drawer-head strong {
  display: block;
  font-size: 18px;
}

.drawer-head span {
  color: var(--muted);
  font-size: 12px;
}

.close-btn {
  min-height: 34px;
  padding: 0 10px;
  background: var(--soft);
  color: #3a4350;
}

.session-list {
  overflow-y: auto;
  padding-top: 14px;
}

.session-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 11px;
  margin-bottom: 10px;
  text-align: left;
}

.session-item.active {
  border-color: rgba(47, 111, 237, 0.5);
  background: #f5f8ff;
}

.session-title {
  font-weight: 700;
  color: #252b34;
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.modal-card {
  position: absolute;
  inset: auto 10px calc(10px + env(safe-area-inset-bottom));
  max-height: min(82dvh, 760px);
  background: #ffffff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  transform: translateY(110%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal.open .modal-card {
  transform: translateY(0);
}

.modal-head {
  padding: 15px 14px 12px;
  border-bottom: 1px solid var(--line);
}

.modal-meta {
  color: var(--brand);
  font-size: 12px;
  margin-bottom: 5px;
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.35;
}

.modal-content {
  overflow-y: auto;
  padding: 15px 15px 22px;
  line-height: 1.85;
  white-space: pre-wrap;
  font-size: 15px;
}

@media (min-width: 860px) {
  body {
    background: #edf0f4;
  }

  .app-shell {
    height: min(100dvh, 980px);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  .modal-card {
    width: min(760px, calc(100vw - 40px));
    left: 50%;
    right: auto;
    transform: translate(-50%, 110%);
  }

  .modal.open .modal-card {
    transform: translate(-50%, 0);
  }
}
