:root {
  --bg: #fafaf8;
  --green: #8dbfa0;
  --green-hover: #79ad91;
  --green-soft: #eaf5ee;
  --text: #263238;
  --muted: #6f7f7a;
  --border: #ddebe3;
  --card: #ffffff;
  --note: #fff4c7;
  --emotion: #fff7d8;
  --orange: #f4b860;
  --brown: #5a4035;
  --shadow: 0 16px 40px rgba(38, 50, 56, 0.08);
  --soft-shadow: 0 8px 22px rgba(38, 50, 56, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(140deg, #fbfbf7, #eef7f1);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

.app {
  position: relative;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  background: var(--bg);
}

.sidebar {
  background: rgba(255, 255, 255, 0.58);
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.icon-button,
.top-icon {
  width: 42px;
  height: 42px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(38, 50, 56, 0.04);
  transition: transform 0.18s ease, background 0.18s ease;
}

.icon-button:hover,
.top-icon:hover {
  transform: translateY(-1px);
  background: var(--green-soft);
}

.icon-button img,
.top-icon img {
  width: 24px;
  height: 24px;
}

.drawer,
.drawer-mask {
  display: none;
}

.sidebar {
  position: relative;
  z-index: 22;
}

.drawer {
  display: block;
  position: absolute;
  left: 64px;
  top: 0;
  bottom: 0;
  width: 292px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px);
  z-index: 20;
  transform: translateX(calc(-100% - 64px));
  transition: transform 0.22s ease;
  border-right: 1px solid var(--border);
  padding: 18px;
  border-radius: 0 24px 24px 0;
  box-shadow: 18px 0 48px rgba(38, 50, 56, 0.12);
}

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

.app.drawer-open .drawer-mask {
  display: block;
  position: absolute;
  inset: 0;
  background: rgba(38, 50, 56, 0.12);
  z-index: 19;
}

.drawer-head {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.drawer-head img {
  width: 46px;
  height: 46px;
}

.drawer-head strong,
.drawer-head span {
  display: block;
}

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

.new-chat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: var(--green-soft);
  border: 1px solid #cae3d4;
  border-radius: 16px;
  padding: 11px 12px;
  margin-bottom: 16px;
  color: var(--text);
}

.new-chat-row:hover,
.history-list button:hover {
  background: #f4faf6;
}

.new-chat-row img {
  width: 22px;
}

.history-list p {
  margin: 16px 0 8px;
}

.history-list button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 13px;
  color: var(--text);
  background: transparent;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-shell {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  min-height: 76px;
  padding: 16px 26px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid rgba(221, 235, 227, 0.7);
  background: rgba(250, 250, 248, 0.76);
  backdrop-filter: blur(18px);
  z-index: 5;
}

.top-icon {
  display: none;
}

.title-area {
  flex: 1;
  min-width: 0;
}

.title-area h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0;
}

.title-area p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.chat-content {
  position: relative;
  overflow: auto;
  padding: 26px 36px 116px;
}

.empty-state {
  height: 100%;
  min-height: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.mascot-hero {
  width: 230px;
  margin-bottom: 10px;
}

.empty-state h2 {
  margin: 8px 0;
  font-size: 30px;
  letter-spacing: 0;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.conversation {
  max-width: 850px;
  margin: 0 auto;
}

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

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

.assistant-message {
  justify-content: flex-start;
  align-items: flex-start;
  gap: 12px;
}

.bubble {
  max-width: 72%;
  padding: 13px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.user-bubble {
  background: var(--green-soft);
  border: 1px solid #cae3d4;
  border-bottom-right-radius: 6px;
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--border);
  padding: 3px;
  box-shadow: 0 4px 12px rgba(38, 50, 56, 0.05);
}

.answer-card {
  width: min(720px, calc(100vw - 160px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px 20px;
  box-shadow: var(--soft-shadow);
  line-height: 1.72;
}

.answer-card h3 {
  margin: 14px 0 6px;
  font-size: 15px;
}

.answer-body {
  white-space: pre-wrap;
  color: #344448;
}

.status-line {
  font-weight: 650;
  margin-bottom: 10px;
}

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

.source-list {
  display: grid;
  gap: 10px;
}

.source-note {
  background: var(--note);
  border: 1px solid #ecd896;
  border-radius: 14px;
  padding: 12px;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.source-note:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(90, 64, 53, 0.1);
}

.source-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.source-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-title img {
  width: 18px;
  flex: 0 0 auto;
}

.source-page {
  color: #7a6b45;
  font-size: 13px;
}

.source-toggle,
.copy-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #6f613b;
  background: rgba(255, 255, 255, 0.52);
  border-radius: 10px;
  padding: 6px 8px;
}

.source-toggle img,
.copy-button img {
  width: 16px;
}

.source-excerpt {
  margin-top: 10px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.42);
  color: #4c4030;
  font-size: 14px;
  line-height: 1.75;
}

.excerpt-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.excerpt-meta span {
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: #6f613b;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.excerpt-section,
.excerpt-paragraph {
  margin: 0;
  padding: 8px 0;
  border-top: 1px solid rgba(236, 216, 150, 0.58);
  overflow-wrap: anywhere;
}

.excerpt-section {
  font-weight: 700;
  color: #3f3526;
}

.excerpt-paragraph + .excerpt-paragraph {
  padding-top: 10px;
}

.copy-button {
  margin-top: 8px;
  background: #fff;
  border: 1px solid #eadba5;
}

.emotion-card {
  max-width: 520px;
  background: var(--emotion);
  border: 1px solid #f0dda0;
  border-radius: 20px;
  padding: 18px 20px;
  box-shadow: var(--soft-shadow);
  line-height: 1.8;
}

.empty-result,
.reference-answer {
  padding: 12px 14px;
  border-radius: 14px;
  background: #fff;
  border: 1px dashed #e7d28e;
}

.reference-answer {
  background: #fff9e4;
}

.error-card {
  border-color: #f2d4a6;
}

.retry-button {
  margin-top: 10px;
  background: var(--orange);
  color: #fff;
  border-radius: 13px;
  padding: 10px 14px;
}

.typing-dots {
  display: flex;
  gap: 5px;
  margin: 8px 0;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: dotPulse 1s infinite;
}

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

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

.input-bar {
  position: absolute;
  left: 64px;
  right: 0;
  bottom: 0;
  padding: 18px 36px 24px;
  background: linear-gradient(180deg, rgba(250, 250, 248, 0), rgba(250, 250, 248, 0.96) 28%, #fafaf8);
  z-index: 6;
}

.composer {
  max-width: 850px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px 10px 10px 16px;
  display: flex;
  align-items: end;
  gap: 10px;
  box-shadow: 0 12px 32px rgba(38, 50, 56, 0.09);
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  min-height: 44px;
  max-height: 160px;
  line-height: 1.55;
  padding: 10px 0;
  color: var(--text);
  background: transparent;
}

.composer textarea::placeholder {
  color: #9aa8a2;
}

.send-button {
  width: 42px;
  height: 42px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  background: var(--green-soft);
  border: 1px solid #cae3d4;
  transition: background 0.18s ease, transform 0.18s ease, opacity 0.18s ease;
}

.send-button:not(:disabled) {
  background: var(--green);
}

.send-button:not(:disabled):hover {
  transform: translateY(-1px);
  background: var(--green-hover);
}

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

.send-button img {
  width: 24px;
}

@keyframes mascotFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-7px);
  }
}

.mascot-float {
  animation: mascotFloat 3.8s ease-in-out infinite;
}

@keyframes thinking {
  0%,
  100% {
    transform: rotate(0) translateY(0);
  }
  35% {
    transform: rotate(-1.5deg) translateY(-2px);
  }
  70% {
    transform: rotate(1.5deg) translateY(-1px);
  }
}

.thinking-motion {
  animation: thinking 2.2s ease-in-out infinite;
}

@keyframes dotPulse {
  0%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 820px) {
  .app {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .top-icon {
    display: grid;
  }

  .chat-shell {
    height: 100vh;
  }

  .topbar {
    min-height: 58px;
    padding: 10px 12px;
  }

  .title-area h1 {
    font-size: 16px;
  }

  .title-area p {
    max-width: 210px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-content {
    padding: 16px 14px 96px;
  }

  .empty-state {
    min-height: 620px;
  }

  .mascot-hero {
    width: 150px;
  }

  .empty-state h2 {
    font-size: 24px;
  }

  .bubble {
    max-width: 78%;
    font-size: 14px;
  }

  .assistant-message {
    gap: 8px;
  }

  .avatar {
    width: 38px;
    height: 38px;
    border-radius: 14px;
  }

  .answer-card {
    width: calc(100vw - 74px);
    padding: 14px;
    border-radius: 18px;
    font-size: 14px;
  }

  .source-head {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .source-toggle {
    grid-column: 2;
  }

  .input-bar {
    left: 0;
    padding: 14px 12px 18px;
  }

  .composer {
    border-radius: 20px;
    padding: 8px 8px 8px 13px;
  }

  .send-button {
    width: 40px;
    height: 40px;
  }

  .drawer {
    left: 0;
    width: 82%;
    transform: translateX(-105%);
  }
}
