* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background: linear-gradient(180deg, #f7f9fc 0%, #eef3f8 100%);
  color: #1f2937;
}

.app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.chat-card {
  width: min(100%, 720px);
  background: #ffffff;
  border: 1px solid #dbe3ec;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-header h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.chat-header p {
  margin: 0;
  color: #667085;
}

.test-notice {
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  background: #eff6ff;
  color: #1e3a8a;
}

.test-notice strong {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
}

.test-notice p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

.test-notice p + p {
  margin-top: 4px;
}

.chat-controls {
  padding: 14px;
  border: 1px solid #e8eef5;
  border-radius: 14px;
  background: #fbfdff;
}

.product-picker {
  display: grid;
  gap: 6px;
}

.product-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.product-picker label {
  color: #475467;
  font-size: 13px;
  font-weight: 600;
}

.product-picker-hint {
  color: #98a2b3;
  font-size: 12px;
}

.product-picker input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 11px 14px;
  font: inherit;
  background: #ffffff;
  color: #0f172a;
}

.product-meta {
  margin: 0;
  color: #98a2b3;
  font-size: 12px;
  line-height: 1.5;
}

.product-picker input:focus,
.chat-form input:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}

.quick-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid #e8eef5;
  border-radius: 14px;
  background: #fcfdff;
  overflow: hidden;
}

.messages {
  height: 420px;
  overflow-y: auto;
  background: #f9fafb;
  padding: 16px;
}

.quick-question {
  border: 1px solid #dbe3ec;
  border-radius: 999px;
  background: #ffffff;
  color: #1f2937;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.quick-question:hover {
  background: #f8fbff;
  border-color: #bfdbfe;
}

.quick-question:disabled {
  color: #94a3b8;
  border-color: #e2e8f0;
  background: #f8fafc;
  cursor: not-allowed;
}

.message {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}

.message.user {
  align-items: flex-end;
}

.message.assistant {
  align-items: flex-start;
}

.message-bubble {
  max-width: 80%;
  padding: 12px 14px;
  border-radius: 12px;
  line-height: 1.5;
  word-break: break-word;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
}

.message-bubble p {
  margin: 0;
}

.message-bubble p + p,
.message-bubble p + .message-list,
.message-bubble .message-list + p {
  margin-top: 10px;
}

.message-list {
  margin: 0;
  padding-left: 20px;
}

.message-list li + li {
  margin-top: 6px;
}

.message.assistant .message-bubble {
  background: #e8f1ff;
  color: #0f172a;
}

.message.user .message-bubble {
  background: #1d4ed8;
  color: #ffffff;
}

.message-feedback {
  max-width: 80%;
  margin-top: 6px;
}

.feedback-helper {
  margin: 0 0 6px;
  color: #64748b;
  font-size: 12px;
  line-height: 1.4;
}

.feedback-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.feedback-button {
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: #ffffff;
  color: #1d4ed8;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.feedback-button:hover:not(:disabled) {
  background: #eff6ff;
}

.feedback-button:disabled {
  color: #94a3b8;
  border-color: #dbe3ec;
  cursor: not-allowed;
}

.feedback-status {
  color: #166534;
  font-size: 12px;
  font-weight: 600;
}

.feedback-detail {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid #dbe3ec;
  border-radius: 12px;
  background: #ffffff;
}

.feedback-detail-label {
  margin: 0 0 10px;
  color: #334155;
  font-size: 13px;
  font-weight: 600;
}

.feedback-reason-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}

.feedback-reason-option {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #334155;
  font-size: 13px;
}

.feedback-reason-option input {
  margin: 0;
}

.feedback-note {
  width: 100%;
  margin-top: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  resize: vertical;
  background: #f8fafc;
  color: #0f172a;
}

.feedback-submit {
  margin-top: 10px;
  border: none;
  border-radius: 10px;
  background: #1d4ed8;
  color: #ffffff;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.feedback-submit:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid #e8eef5;
  background: #ffffff;
}

.composer {
  display: grid;
  gap: 8px;
}

.chat-form input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  min-height: 48px;
}

.composer-hint {
  margin: 0;
  color: #98a2b3;
  font-size: 12px;
}

.chat-form button {
  border: none;
  border-radius: 10px;
  background: #2563eb;
  color: #ffffff;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  min-height: 48px;
  cursor: pointer;
}

.chat-form button:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.kb-debug {
  padding: 14px 16px;
  border: 1px solid #edf2f7;
  border-radius: 12px;
  background: #fbfcfe;
}

.kb-debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.kb-debug-header h2 {
  margin: 0;
  font-size: 14px;
  color: #667085;
  font-weight: 600;
}

.kb-debug-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.kb-debug-toggle {
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  background: #ffffff;
  color: #667085;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.kb-debug-body {
  margin-top: 12px;
  border-top: 1px solid #eef2f6;
  padding-top: 12px;
}

.kb-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.kb-summary-item {
  padding: 10px 12px;
  border: 1px solid #edf2f7;
  border-radius: 10px;
  background: #ffffff;
}

.kb-summary-label {
  display: block;
  margin-bottom: 4px;
  color: #98a2b3;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kb-summary-item strong {
  color: #334155;
  font-size: 15px;
}

.kb-load-status {
  margin: 0 0 12px;
  color: #667085;
  font-size: 12px;
}

.kb-load-status-error {
  color: #b91c1c;
  font-weight: 600;
}

.kb-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  background: #eef2f6;
  color: #667085;
  font-size: 12px;
  font-weight: 600;
}

.kb-badge-success {
  background: #dcfce7;
  color: #166534;
}

.kb-badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.kb-badge-error {
  background: #fee2e2;
  color: #b91c1c;
}

.kb-badge-thinking {
  background: #eaf2ff;
  color: #2563eb;
  animation: pulse-badge 1.4s ease-in-out infinite;
}

.kb-debug-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

.kb-debug-item {
  margin: 0;
}

.kb-debug-item dt {
  margin-bottom: 4px;
  color: #98a2b3;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kb-debug-item dd {
  margin: 0;
  color: #475467;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}

.kb-debug-item-wide {
  grid-column: 1 / -1;
}

.status {
  min-height: 24px;
  margin: 0;
  color: #475467;
  font-size: 14px;
}

.status-thinking {
  color: #2563eb;
  font-weight: 600;
}

.status-thinking::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: thinking-dots 1.2s steps(4, end) infinite;
}

@keyframes thinking-dots {
  0% {
    content: "";
  }

  25% {
    content: ".";
  }

  50% {
    content: "..";
  }

  75% {
    content: "...";
  }

  100% {
    content: "";
  }
}

@keyframes pulse-badge {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.12);
  }

  50% {
    box-shadow: 0 0 0 6px rgba(37, 99, 235, 0);
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  .chat-card {
    padding: 18px;
  }

  .messages {
    height: 360px;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }

  .product-picker-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .quick-questions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .kb-debug-grid {
    grid-template-columns: 1fr;
  }

  .kb-summary {
    grid-template-columns: 1fr;
  }

  .feedback-reason-list {
    grid-template-columns: 1fr;
  }
}
