/* 现代极简风格 - V2 */
:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --text: #0f172a;
  --text-secondary: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --border: #e2e8f0;
  --shadow: rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  padding: 16px;
}

.orb {
  display: none;
}

.layout {
  position: relative;
  z-index: 1;
  max-width: 1600px;
  margin: 0 auto;
  width: 96%;
  padding: 0;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

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

.brand-mark {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
  font-family: inherit;
  letter-spacing: normal;
  font-weight: normal;
  font-size: inherit;
  padding: 0;
  color: inherit;
}

.brand-mark::before {
  content: '';
  width: 24px;
  height: 24px;
  background: white;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

.brand-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: normal;
  color: var(--text);
}

.brand-sub {
  color: var(--text-secondary);
  font-size: 14px;
}

.status {
  display: none;
}

.thinking {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.grid {
  display: grid;
  grid-template-columns: 450px 1fr;
  gap: 20px;
  align-items: stretch;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px var(--shadow);
  backdrop-filter: none;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 16px;
  line-height: 1.3;
}

.intro {
  position: relative;
  top: auto;
  align-self: stretch;
  height: calc(100vh - 160px);
  min-height: 600px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: none;
  overflow: hidden;
}

.intro .section-title {
  margin: 0;
}

.intro p {
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0;
}

.q-index {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  max-height: none;
  overflow: auto;
  overflow-x: hidden;
  display: grid;
  align-content: start;
  gap: 6px;
  font-size: 12px;
  margin: 0;
  flex: 1 1 0;
  min-height: 0;
}

.q-index-item {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 8px;
  align-items: start;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  background: white;
  border: 1px solid #e2e8f0;
  transition: all 0.2s;
}

.q-index-item:hover {
  background: #eff6ff;
  border-color: #3b82f6;
}

.q-index-item.active {
  border-color: #3b82f6;
  background: #eff6ff;
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.1);
}

.q-index-item.pending {
  border-style: dashed;
  border-color: rgba(120, 120, 120, 0.35);
}

.q-index-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.2);
  color: #1e40af;
  font-size: 10px;
}

.q-index-num {
  font-weight: 600;
  color: #3b82f6;
}

.q-index-text {
  color: var(--text);
  line-height: 1.4;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.refs {
  min-height: 0;
  max-height: none;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow: auto;
  overflow-x: hidden;
  margin: 0;
  flex: 2 1 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.refs-empty {
  color: var(--text-secondary);
  font-size: 13px;
}

.refs-header {
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

.refs-meta {
  margin-bottom: 12px;
  color: #3a4a55;
}

.refs-meta table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
  word-break: break-word;
}

.refs-meta th {
  text-align: left;
  width: 80px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 11px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
  font-weight: 500;
}

.refs-meta td {
  padding: 6px 8px;
  border: 1px solid var(--border);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.refs-actions {
  margin-bottom: 12px;
}

.refs-link {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 6px;
  background: #eff6ff;
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  border: 1px solid #bfdbfe;
  transition: all 0.2s;
}

.refs-link:hover {
  background: var(--accent);
  color: white;
}

.refs pre {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.6;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
  word-break: break-word;
  color: var(--text);
}

.tips {
  display: none;
}

.tip {
  background: var(--panel-soft);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13px;
  color: #2e3f4b;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.tags span {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.12);
  color: #1e40af;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.actions {
  margin-top: auto;
}

button {
  border: none;
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  border-radius: 8px;
  transition: all 0.2s;
}

button.primary {
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  font-weight: 500;
}

button.primary:hover {
  background: var(--accent-hover);
}

button.ghost {
  padding: 8px 16px;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

button.ghost:hover {
  background: #f1f5f9;
}

.chat {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  height: calc(100vh - 160px);
  min-height: 600px;
}

/* 空状态样式 */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #dbeafe, #bfdbfe);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
}

.empty-state-icon::before {
  content: '💬';
  font-size: 32px;
}

.empty-state-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.empty-state-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.suggestion-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 600px;
}

.suggestion-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.suggestion-card:hover {
  border-color: var(--accent);
  background: #eff6ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.suggestion-card-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

/* 有对话时隐藏空状态 */
.chat.has-messages .empty-state {
  display: none;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
  padding-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: grid;
  gap: 8px;
  animation: rise 0.35s ease-out;
}

.message.user {
  justify-items: end;
}

.message.user .bubble {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  align-self: flex-end;
  max-width: 85%;
}

.message.assistant .bubble {
  background: #eff6ff;
  border: 1px solid #dbeafe;
  align-self: flex-start;
  width: 95%;
}

.bubble {
  padding: 12px 16px;
  border-radius: 8px;
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 14px;
}

.bubble .cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 2px;
  font-size: 10px;
  color: #ffffff;
  background: var(--accent);
  border-radius: 999px;
  cursor: pointer;
  vertical-align: super;
  transition: all 0.2s;
}

.bubble .cite:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.bubble .cite-missing {
  background: #9aa7b2;
}

.thinking-bubble {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
}

.thinking-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  animation: pulse 1.2s infinite ease-in-out;
}

.thinking-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dot:nth-child(3) {
  animation-delay: 0.4s;
}

.thinking-text {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 4px;
}

.bubble p {
  margin: 0 0 10px;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 16px;
  font-size: 14px;
  table-layout: fixed;
  word-break: break-word;
}

.bubble thead th {
  text-align: left;
  background: #f1f5f9;
  padding: 8px 10px;
  border: 1px solid var(--border);
  font-weight: 600;
}

.bubble tbody td {
  padding: 8px 10px;
  border: 1px solid var(--border);
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4,
.bubble h5,
.bubble h6 {
  margin: 12px 0 8px;
  font-size: 16px;
  letter-spacing: 0.02em;
  font-weight: 600;
}

.bubble h1 { font-size: 18px; }
.bubble h2 { font-size: 16px; }
.bubble h3 { font-size: 15px; }
.bubble h4 { font-size: 14px; }

.bubble ul,
.bubble ol {
  margin: 6px 0 10px 20px;
  padding: 0;
}

.bubble li {
  margin-bottom: 4px;
}

.bubble blockquote {
  margin: 8px 0 12px;
  padding: 8px 12px;
  border-left: 3px solid var(--accent);
  background: rgba(59, 130, 246, 0.05);
  border-radius: 4px;
}

.bubble blockquote p:last-child {
  margin-bottom: 0;
}

.bubble code {
  background: rgba(59, 130, 246, 0.1);
  color: #1e40af;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.9em;
}

.code-block {
  margin-top: 10px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #f8fafc;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #f1f5f9;
  font-size: 12px;
  color: #64748b;
}

.code-header .code-lang {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.copy-btn {
  border: 1px solid var(--border);
  background: #ffffff;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.copy-btn:hover {
  background: var(--bg);
  border-color: var(--accent);
  color: var(--accent);
}

.code-block pre {
  margin: 0;
  padding: 12px;
  overflow-x: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #27313a;
}

.code-block pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bubble pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow-x: hidden;
}

.bubble a {
  color: var(--accent);
  text-decoration: none;
}

.bubble a:hover {
  text-decoration: underline;
}

.meta {
  color: var(--text-secondary);
  font-size: 12px;
  margin-top: 6px;
}

.details {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.details summary {
  cursor: pointer;
  color: var(--accent);
  user-select: none;
}

.details summary:hover {
  color: var(--accent-hover);
}

.details pre {
  white-space: pre-wrap;
  background: #f8fafc;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  margin-top: 8px;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  position: sticky;
  bottom: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 6px var(--shadow);
  backdrop-filter: blur(6px);
  z-index: 2;
}

#input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  padding: 12px;
  color: var(--text);
  font-size: 14px;
  resize: vertical;
  font-family: inherit;
}

#input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hint {
  color: var(--text-secondary);
  font-size: 12px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0px);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  50% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 960px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .intro {
    order: 2;
    height: auto;
    min-height: auto;
    overflow: visible;
  }
  .chat {
    min-height: auto;
  }
  .q-index {
    flex: none;
    max-height: 280px;
  }
  .refs {
    flex: none;
    max-height: 420px;
  }
  .actions {
    margin-top: 18px;
  }
}
