:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #d71920;
  --brand-dark: #af1419;
  --soft-red: #fff1f2;
  --soft-blue: #eff6ff;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #fff7f7 0, var(--bg) 42%);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

.page {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  gap: 24px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px;
}

.page.chat-only {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
}

.page.chat-only .chat-card {
  width: min(100%, 760px);
  max-width: 760px;
  min-width: 0;
}

.chat-card,
.debug-card {
  background: var(--card);
  border: 1px solid rgba(229, 231, 235, 0.85);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-card {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 56px);
}

.chat-header,
.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 19px;
}

h3 {
  margin-bottom: 10px;
  font-size: 15px;
}

.chat-header p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.status-pill,
.backend-flag {
  white-space: nowrap;
  border-radius: 999px;
  padding: 7px 11px;
  background: var(--soft-blue);
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
}

.flag-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.backend-flag.true {
  background: var(--soft-red);
  color: var(--brand-dark);
}

.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.68)),
    repeating-linear-gradient(135deg, #fafafa 0, #fafafa 10px, #fff 10px, #fff 20px);
}

.message {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.message.user {
  flex-direction: row-reverse;
}

.avatar {
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: #111827;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.message.user .avatar {
  background: var(--brand);
}

.bubble {
  max-width: min(78%, 560px);
  border-radius: 18px;
  padding: 12px 14px;
  background: #f3f4f6;
  line-height: 1.58;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: var(--brand);
  color: #fff;
}

.composer {
  display: flex;
  gap: 12px;
  padding: 18px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.composer input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  font-size: 15px;
  outline: none;
}

.composer input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(215, 25, 32, 0.1);
}

.composer button {
  border: 0;
  border-radius: 14px;
  padding: 0 22px;
  background: var(--brand);
  color: white;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.composer button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.debug-card {
  max-height: calc(100vh - 56px);
  overflow-y: auto;
}

.debug-section {
  padding: 18px 22px;
  border-top: 1px solid var(--line);
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  border-radius: 16px;
  background: #f9fafb;
  padding: 14px;
  color: #111827;
  font-family: inherit;
  line-height: 1.6;
}

.result-list.empty {
  color: var(--muted);
}

.result-item {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px;
  background: #fff;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
}

.tag {
  border-radius: 999px;
  background: #f3f4f6;
  padding: 4px 8px;
}

.result-question,
.result-answer {
  margin-top: 8px;
  line-height: 1.55;
}

.label {
  color: var(--muted);
  font-weight: 700;
}

@media (max-width: 980px) {
  .page {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .page.chat-only {
    width: 100%;
    justify-items: stretch;
  }

  .page.chat-only .chat-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .composer {
    min-width: 0;
  }

  .composer input {
    min-width: 0;
  }

  .composer button {
    flex: 0 0 auto;
    padding: 0 16px;
  }

  .chat-card,
  .debug-card {
    min-height: auto;
    max-height: none;
  }
}

@media (max-width: 600px) {
  .page {
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
  }

  .page.chat-only .chat-card {
    height: calc(100vh - 28px);
    height: calc(100svh - 28px);
    height: calc(100dvh - 28px);
    min-height: calc(100vh - 28px);
    min-height: calc(100svh - 28px);
    min-height: calc(100dvh - 28px);
  }

  .chat-header,
  .composer {
    flex: 0 0 auto;
  }

  .chat-header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px;
  }

  .chat-header > div {
    flex: 1 1 220px;
    min-width: 0;
  }

  .chat-header h1,
  .chat-header p {
    overflow-wrap: anywhere;
  }

  .status-pill {
    flex: 0 0 auto;
    max-width: 100%;
  }

  .chat-window {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
  }

  .composer {
    width: 100%;
    padding: 14px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .composer input {
    width: 100%;
    min-width: 0;
  }

  .composer button {
    max-width: 100%;
    white-space: nowrap;
  }
}
