:root {
  color-scheme: light;
  --bg: #eef2f8;
  --bg-soft: #f8fafc;
  --panel: #ffffff;
  --text: #0f172a;
  --text-secondary: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --highlight: #fef08a;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow: 0 12px 40px rgba(15, 23, 42, 0.1);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --user-bubble: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  --assistant-bubble: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(37, 99, 235, 0.12), transparent),
    linear-gradient(180deg, #f0f5ff 0%, var(--bg) 50%);
  color: var(--text);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.app {
  max-width: 860px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px 0 12px;
  flex-shrink: 0;
}

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

.logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--user-bubble);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
  flex-shrink: 0;
}

.header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.stats {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

/* Chat shell */
.chat-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 0;
  margin-bottom: 20px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

/* Welcome card */
.welcome-card {
  text-align: center;
  padding: 32px 24px;
  background: linear-gradient(180deg, var(--primary-soft) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-md);
  margin: auto 0;
}

.welcome-icon {
  font-size: 36px;
  margin-bottom: 12px;
}

.welcome-card h2 {
  margin: 0 0 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.welcome-card > p {
  margin: 0 auto 20px;
  max-width: 480px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.hint-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

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

.hint-chip {
  border: 1px solid var(--primary-border);
  background: white;
  color: var(--primary);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.hint-chip:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
}

/* Message bubbles */
.message {
  display: flex;
  gap: 10px;
  max-width: 100%;
  animation: fadeIn 0.25s ease;
}

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

.message-user {
  flex-direction: row-reverse;
  align-self: flex-end;
  max-width: 85%;
}

.message-assistant {
  align-self: flex-start;
  max-width: 100%;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.message-user .message-avatar {
  background: var(--primary-soft);
  color: var(--primary);
}

.message-assistant .message-avatar {
  background: var(--user-bubble);
  color: white;
  font-size: 13px;
}

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

.message-user .message-bubble {
  background: var(--user-bubble);
  color: white;
  border-radius: 18px 18px 4px 18px;
  padding: 12px 16px;
  font-size: 15px;
  line-height: 1.6;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.message-assistant .message-bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--line);
  border-radius: 4px 18px 18px 18px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
}

.message-assistant .message-bubble > p {
  margin: 0;
}

/* Hit cards */
.hit-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.hit-card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  transition: border-color 0.15s ease;
}

.hit-card:hover {
  border-color: var(--primary-border);
}

.hit-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.hit-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.5;
}

.hit-meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.hit-snippet {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text-secondary);
}

.hit-snippet mark {
  background: var(--highlight);
  color: inherit;
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 600;
}

.hit-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

.btn-expand {
  border: 1px solid var(--primary-border);
  background: white;
  color: var(--primary);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-expand:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.btn-expand:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s infinite ease-in-out;
}

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

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

@keyframes bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* Input area */
.chat-input-area {
  border-top: 1px solid var(--line);
  padding: 14px 16px 10px;
  background: var(--bg-soft);
  flex-shrink: 0;
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px 8px 8px 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-form:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.chat-form textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 15px;
  line-height: 1.5;
  font-family: inherit;
  color: var(--text);
  max-height: 120px;
  padding: 6px 0;
}

.chat-form textarea:focus {
  outline: none;
}

.chat-form textarea::placeholder {
  color: #94a3b8;
}

.chat-form button[type="submit"] {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--user-bubble);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.chat-form button[type="submit"]:hover:not(:disabled) {
  transform: scale(1.04);
}

.chat-form button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-hint {
  margin: 6px 0 0;
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
}

/* Article modal */
.article-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.25s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0 0 6px;
  font-size: 20px;
  line-height: 1.4;
}

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

.modal-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  color: var(--muted);
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.modal-close:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.modal-body {
  overflow-y: auto;
  padding: 24px;
  line-height: 1.8;
  font-size: 16px;
}

/* Rich text */
.rich-text #js_content,
.rich-text .rich_media_content {
  visibility: visible !important;
  opacity: 1 !important;
}

.rich-text img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 16px auto;
  border-radius: 8px;
}

.rich-text p,
.rich-text section {
  margin: 0 0 14px;
}

.rich-text h1,
.rich-text h2,
.rich-text h3 {
  margin: 18px 0 10px;
}

.rich-text mark {
  background: var(--highlight);
  padding: 1px 3px;
  border-radius: 3px;
}

.video-placeholder {
  text-align: center;
  padding: 20px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

.video-placeholder img {
  max-width: 100%;
  margin-bottom: 12px;
}

.empty-content {
  padding: 32px 24px;
  text-align: center;
  color: var(--muted);
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
}

.loading {
  color: var(--muted);
}

/* Mobile */
@media (max-width: 640px) {
  .app {
    padding: 0 10px;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    padding-top: 16px;
  }

  .stats {
    align-self: flex-start;
  }

  .chat-shell {
    border-radius: var(--radius-md);
    margin-bottom: 12px;
  }

  .chat-messages {
    padding: 16px 14px;
  }

  .welcome-card {
    padding: 24px 16px;
  }

  .message-user {
    max-width: 92%;
  }

  .hit-header {
    flex-direction: column;
    gap: 4px;
  }

  .hit-meta {
    white-space: normal;
  }

  .article-modal {
    padding: 0;
    align-items: stretch;
  }

  .modal-panel {
    max-height: 100vh;
    border-radius: 0;
  }
}
