:root {
  color-scheme: dark;
  --bg: #081523;
  --panel: rgba(12, 22, 38, 0.86);
  --panel-strong: rgba(7, 12, 27, 0.94);
  --line: rgba(75, 101, 138, 0.5);
  --muted: #8ba0bc;
  --text: #f8fbff;
  --soft: #b7c4d8;
  --accent: #22d3ee;
  --accent-strong: #2563eb;
  --accent-soft: rgba(34, 211, 238, 0.13);
  --chip: rgba(28, 44, 68, 0.9);
  --card: rgba(15, 27, 47, 0.86);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(14, 116, 144, 0.22), transparent 30%),
    radial-gradient(circle at 86% 18%, rgba(37, 99, 235, 0.16), transparent 28%),
    linear-gradient(135deg, #0f2a3b 0%, #08111f 46%, #050913 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

body::before {
  position: fixed;
  inset: 0;
  content: "";
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(148, 163, 184, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(148, 163, 184, 0.025) 1px, transparent 1px);
  background-size: 160px 160px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.4), transparent 55%);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
}

.workspace {
  position: relative;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
  background: rgba(6, 11, 24, 0.5);
  backdrop-filter: blur(22px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 22px;
}

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

.topbar-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(148, 163, 184, 0.72);
  padding: 0;
  cursor: pointer;
  transition: all 0.2s ease;
}

.topbar-btn:hover {
  background: rgba(30, 41, 59, 0.7);
  color: #e5f6ff;
}

/* 历史记录 Popover 容器样式 */
.history-popover {
  position: absolute;
  top: 52px;
  right: 22px;
  z-index: 1000;
  width: 300px;
  max-height: calc(100vh - 180px);
  overflow: hidden;
  background: rgba(8, 13, 29, 0.94);
  backdrop-filter: blur(28px);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  animation: popoverFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.history-popover.hidden {
  display: none;
}

@keyframes popoverFadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.popover-section {
  padding: 16px 0;
}

.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 12px;
  border-bottom: 1px solid rgba(75, 101, 138, 0.45);
  color: #e8f2ff;
  font-size: 14px;
  font-weight: 600;
}

.popover-header .chevron {
  font-size: 10px;
  color: rgba(220, 230, 220, 0.4);
}

.session-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 8px 8px 0;
  scrollbar-width: thin;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--soft);
  font-size: 14px;
  transition: all 0.2s ease;
  margin-bottom: 4px;
}

.session-item:hover {
  background: rgba(30, 41, 59, 0.72);
  color: #f8fbff;
}

.session-item.active {
  background: rgba(34, 211, 238, 0.1);
  color: #67e8f9;
  font-weight: 500;
  border-left: 2px solid var(--accent);
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.session-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 12px;
}

.session-time {
  flex: 0 0 auto;
  font-size: 12px;
  color: rgba(148, 163, 184, 0.54);
}

.session-item.active .session-time {
  color: rgba(103, 232, 249, 0.72);
}

.chat-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 72px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(34, 211, 238, 0.55);
  border-radius: 999px;
  background: linear-gradient(135deg, #06b6d4 0%, #2563eb 100%);
  color: #f8fbff;
  font-size: 14px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.22);
}

.conversation {
  height: calc(100vh - 170px);
  overflow-y: auto;
  padding: 70px clamp(18px, 7vw, 110px) 34px;
  scrollbar-color: rgba(100, 116, 139, 0.55) transparent;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.message-user {
  align-self: flex-end;
  max-width: min(520px, 82vw);
  padding: 17px 22px;
  border-radius: 18px 18px 4px 18px;
  background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
  color: #f8fbff;
  font-size: 17px;
  line-height: 1.55;
}

.message-assistant {
  width: min(1040px, 100%);
  max-width: 1040px;
  color: var(--soft);
}

.thinking {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--soft);
  font-size: 14px;
}

.process-panel {
  position: relative;
  margin-top: 8px;
  padding: 18px 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 22, 38, 0.9);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.process-head {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #eef6ff;
  font-size: 15px;
  font-weight: 650;
}

.process-icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  color: #67e8f9;
}

.collapse {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: rgba(207, 223, 236, 0.58);
  cursor: pointer;
  transition: transform 0.2s ease, color 0.2s ease;
}

.collapse:hover {
  color: rgba(255, 255, 255, 0.9);
}

.process-panel.collapsed {
  padding-bottom: 14px;
}

.process-panel.collapsed .steps {
  display: none;
}

.process-panel.collapsed .collapse {
  transform: rotate(180deg);
}

.steps {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 18px;
  padding-left: 22px;
}

.steps::before,
.nested-steps::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 1px;
  background: rgba(59, 130, 246, 0.28);
  content: "";
}

.step-card {
  position: relative;
  min-width: 0;
  padding: 15px 16px 16px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.82);
  color: var(--soft);
}

.main-step {
  border: 1px solid rgba(75, 101, 138, 0.62);
}

.nested-step {
  border: 1px solid rgba(14, 165, 233, 0.35);
  background: rgba(10, 38, 59, 0.72);
}

.step-top {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.step-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: rgba(239, 247, 248, 0.94);
  font-size: 15px;
  font-weight: 700;
}

.step-dot {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 18px;
  height: 18px;
  color: #22d3ee;
}

.step-badge {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 2px 9px;
  border: 1px solid rgba(96, 116, 150, 0.58);
  border-radius: 4px;
  background: rgba(96, 112, 143, 0.28);
  color: rgba(220, 228, 238, 0.72);
  font-size: 12px;
}

.step-summary {
  margin-top: 15px;
  color: rgba(218, 231, 239, 0.66);
  font-size: 14px;
  line-height: 1.65;
}

.nested-steps {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
  padding-left: 24px;
}

.query-list {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 13px;
}

.evidence-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
}

.source-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(360px, 100%);
  min-height: 30px;
  padding: 6px 12px;
  border: 1px solid rgba(75, 101, 138, 0.45);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.7);
  color: #cbd5e1;
  font-size: 13px;
  text-decoration: none;
}

.source-pill span {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(236, 246, 240, 0.86);
  font-size: 11px;
}

.source-pill strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.evidence-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 5px 10px;
  min-width: 0;
  color: rgba(218, 231, 239, 0.72);
}

.evidence-label {
  grid-row: 1 / span 2;
  color: rgba(218, 231, 239, 0.58);
  font-size: 13px;
  line-height: 1.7;
  white-space: nowrap;
}

.evidence-title {
  min-width: 0;
  overflow: hidden;
  color: #f1f8ff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.7;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a.evidence-title:hover {
  color: #67e8f9;
  text-decoration: underline;
}

.evidence-snippet {
  min-width: 0;
  margin: 0;
  color: rgba(211, 224, 232, 0.68);
  font-size: 13px;
  line-height: 1.7;
}

.empty-evidence {
  width: 100%;
  color: rgba(238, 218, 166, 0.86);
  font-size: 14px;
  line-height: 1.6;
}

.pulse {
  position: relative;
  width: 18px;
  height: 12px;
}

.pulse::before,
.pulse::after {
  position: absolute;
  top: 4px;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: var(--accent);
  content: "";
  animation: blink 1.1s infinite ease-in-out;
}

.pulse::before {
  left: 1px;
}

.pulse::after {
  left: 10px;
  animation-delay: 0.24s;
}

@keyframes blink {
  0%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.retrieval-group {
  position: relative;
  margin: 20px 0 22px;
  padding-left: 28px;
}

.retrieval-group::before {
  position: absolute;
  top: 28px;
  bottom: 0;
  left: 8px;
  width: 3px;
  border-radius: 999px;
  background: rgba(68, 172, 83, 0.58);
  content: "";
}

.retrieval-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: rgba(183, 196, 216, 0.72);
  font-size: 14px;
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(34, 211, 238, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.query-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 9px 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  width: 100%;
  height: 31px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 999px;
  background: var(--chip);
  color: rgba(221, 228, 220, 0.66);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
}

.chip.query {
  background: rgba(58, 112, 62, 0.72);
  color: rgba(236, 248, 235, 0.92);
}

.chip::before {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.78);
  font-size: 11px;
  content: attr(data-icon);
}

.chip.query::before {
  border-radius: 999px;
  background: transparent;
  color: rgba(233, 245, 232, 0.86);
}

.chip-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.answer {
  margin-top: 24px;
  max-width: 980px;
  color: #eef6ff;
  font-size: 17px;
  line-height: 1.8;
}

.answer p {
  margin: 0 0 14px;
}

.answer strong {
  color: #ffffff;
  font-weight: 600;
}

.answer ul,
.answer ol {
  margin: 0 0 16px 0;
  padding-left: 24px;
}

.answer li {
  margin-bottom: 6px;
  line-height: 1.75;
}

.answer li::marker {
  color: var(--accent);
}

.answer ol li::marker {
  color: var(--accent);
  font-weight: 600;
}

.answer code {
  font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 85%;
  background: rgba(15, 23, 42, 0.95);
  padding: 3px 6px;
  border-radius: 4px;
  color: #93c5fd;
  word-break: break-word;
}

.answer pre {
  margin: 16px 0;
  padding: 16px;
  background: rgba(5, 10, 22, 0.82);
  border: 1px solid rgba(75, 101, 138, 0.55);
  border-radius: 8px;
  overflow-x: auto;
}

.answer pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 14px;
}

.answer h1,
.answer h2,
.answer h3,
.answer h4 {
  color: #ffffff;
  margin: 24px 0 12px;
  font-weight: 600;
}

.answer h1 { font-size: 1.5em; }
.answer h2 { font-size: 1.3em; }
.answer h3 { font-size: 1.15em; }
.answer h4 { font-size: 1.05em; }

.answer table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 15px;
  line-height: 1.55;
  background: rgba(15, 23, 42, 0.56);
  border-radius: 6px;
  overflow: visible;
}

.answer th,
.answer td {
  border: 1px solid rgba(75, 101, 138, 0.5);
  padding: 10px 14px;
  text-align: left;
}

.answer th {
  background-color: rgba(14, 165, 233, 0.18);
  color: #ffffff;
  font-weight: 600;
}

.answer tr:nth-child(even) {
  background-color: rgba(30, 41, 59, 0.35);
}

.answer tr:hover {
  background-color: rgba(30, 64, 100, 0.45);
}

.answer .citation {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 22px;
  margin: 0 3px;
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.16);
  color: #67e8f9;
  font-size: 12px;
  font-weight: 700;
  vertical-align: 1px;
}

.answer .citation.web {
  background: rgba(37, 99, 235, 0.2);
  color: #bfdbfe;
}

.citation-tooltip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  z-index: 20;
  display: none;
  width: min(360px, 82vw);
  padding: 12px 13px;
  border: 1px solid rgba(75, 101, 138, 0.7);
  border-radius: 8px;
  background: rgba(8, 13, 29, 0.98);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
  color: #eef6ff;
  text-align: left;
  transform: translateX(-50%);
}

.citation:hover .citation-tooltip,
.citation:focus .citation-tooltip {
  display: block;
}

.citation-tooltip strong {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
}

.citation-tooltip em {
  display: block;
  color: rgba(220, 230, 222, 0.68);
  font-size: 12px;
  font-style: normal;
  line-height: 1.55;
}

/* 针对表格最右侧两列的文献气泡 Tooltip 进行对齐修正，使其向左展开，防止超出视口被截断 */
.answer td:last-child .citation-tooltip,
.answer th:last-child .citation-tooltip,
.answer td:nth-last-child(2) .citation-tooltip,
.answer th:nth-last-child(2) .citation-tooltip {
  left: auto;
  right: 0;
  transform: translateX(0);
}

.composer-wrap {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 0 clamp(12px, 2.6vw, 34px) 16px;
}

.composer {
  min-height: 118px;
  border: 1px solid rgba(75, 101, 138, 0.72);
  border-radius: 26px;
  background: rgba(6, 11, 24, 0.92);
  box-shadow: 0 -18px 80px rgba(2, 8, 23, 0.42);
  overflow: hidden;
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 70px;
  padding: 20px 22px 6px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: #f8fbff;
  font-size: 16px;
  line-height: 1.55;
}

.composer textarea::placeholder {
  color: rgba(148, 163, 184, 0.72);
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 14px 12px;
}

.left-tools,
.right-tools {
  display: flex;
  align-items: center;
  gap: 11px;
}

.composer-actions button {
  display: inline-grid;
  place-items: center;
  width: 29px;
  height: 29px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(148, 163, 184, 0.82);
}

.web-search-toggle {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  width: auto !important;
  height: 29px !important;
  padding: 0 10px !important;
  border-radius: 999px !important;
  border: 1px solid rgba(75, 101, 138, 0.58) !important;
  background: rgba(15, 23, 42, 0.76) !important;
  color: rgba(148, 163, 184, 0.86) !important;
  font-size: 13px !important;
  font-weight: 500;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.web-search-toggle.active {
  background: rgba(14, 165, 233, 0.16) !important;
  border-color: rgba(34, 211, 238, 0.5) !important;
  color: #67e8f9 !important;
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.1);
}

.web-search-toggle:hover {
  background: rgba(30, 41, 59, 0.78) !important;
  color: #e8f2ff !important;
}

.web-search-toggle.active:hover {
  background: rgba(14, 165, 233, 0.24) !important;
  border-color: rgba(34, 211, 238, 0.68) !important;
  color: #ffffff !important;
}

.web-search-toggle .toggle-icon {
  font-size: 13px;
  filter: grayscale(1);
  transition: filter 0.2s ease;
}

.web-search-toggle.active .toggle-icon {
  filter: grayscale(0) drop-shadow(0 0 2px rgba(34, 211, 238, 0.55));
}

.composer-actions button:hover {
  background: rgba(30, 41, 59, 0.78);
  color: #e8f2ff;
}

#modelLabel {
  max-width: 180px;
  overflow: hidden;
  color: rgba(148, 163, 184, 0.82);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.send {
  width: 42px !important;
  height: 42px !important;
  border-radius: 50% !important;
  background: linear-gradient(135deg, #22d3ee 0%, #2563eb 100%) !important;
}

.send .send-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.send .icon-send-arrow {
  display: block;
  color: #f8fbff;
  width: 16px;
  height: 16px;
}

.send .icon-stop-square {
  display: none;
}

.send.is-busy .icon-send-arrow {
  display: none;
}

.send.is-busy .icon-stop-square {
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: #f8fbff;
}

.send:disabled {
  background: rgba(30, 41, 59, 0.82) !important;
  cursor: not-allowed !important;
  opacity: 1 !important;
}

.send:disabled .icon-send-arrow {
  color: rgba(255, 255, 255, 0.24) !important;
}

.send[disabled] {
  cursor: wait;
}

@media (max-width: 820px) {
  .conversation {
    padding: 44px 16px 34px;
  }

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

  .message-user {
    max-width: 88vw;
    font-size: 15px;
  }

  .answer {
    font-size: 15px;
  }

  .composer-wrap {
    padding-inline: 8px;
  }
}
