:root {
  --red: #991827;
  --red-dark: #72111d;
  --ink: #202527;
  --muted: #68716c;
  --line: #d9dedb;
  --paper: #ffffff;
  --assistant: #f1f5f2;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: #ecefed;
  color: var(--ink);
  font-family: system-ui, "Noto Sans JP", sans-serif;
  letter-spacing: 0;
}
button, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.app {
  width: min(860px, 100%);
  height: 100dvh;
  margin: auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  background: var(--paper);
  border-inline: 1px solid var(--line);
}
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 3px solid var(--red);
  background: var(--paper);
}
header img, .assistant > img {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border: 2px solid var(--red);
  border-radius: 50%;
  object-fit: cover;
  background: var(--red);
}
h1 { flex: 1; margin: 0; font-size: 19px; }
header button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 20px;
}
.messages { overflow-y: auto; padding: 22px 18px; scroll-behavior: smooth; }
.message { display: flex; gap: 10px; margin-bottom: 18px; }
.message.user { justify-content: flex-end; }
.assistant > img { width: 42px; height: 42px; flex-basis: 42px; }
.bubble {
  max-width: min(690px, 82%);
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--assistant);
  line-height: 1.75;
  overflow-wrap: anywhere;
}
.message-text { white-space: pre-wrap; }
.bubble.pending .message-text {
  color: var(--muted);
}
.bubble.pending .message-text::after {
  content: "•••";
  display: inline-block;
  margin-left: .35em;
  color: var(--red);
  animation: thinking 1.1s ease-in-out infinite;
}
.bubble.streaming .message-text::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: -.15em;
  background: var(--red);
  animation: cursor-blink .8s step-end infinite;
}
@keyframes thinking {
  0%, 100% { opacity: .25; }
  50% { opacity: 1; }
}
@keyframes cursor-blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .bubble.pending .message-text::after,
  .bubble.streaming .message-text::after { animation: none; }
}
.user .bubble { background: var(--ink); color: #fff; border-color: var(--ink); }
.sources { margin-top: 12px; padding-top: 9px; border-top: 1px solid #cbd3ce; color: var(--muted); font-size: 12px; }
.sources summary { color: var(--red-dark); font-weight: 700; }
.sources ul { margin: 8px 0 0; padding-left: 20px; }
.suggestions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  scrollbar-width: none;
}
.suggestions button {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid #b8c0bb;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
form { display: flex; gap: 8px; padding: 10px 12px; }
textarea {
  min-width: 0;
  flex: 1;
  min-height: 48px;
  max-height: 130px;
  resize: none;
  padding: 12px;
  border: 1px solid #9da7a1;
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
}
form button {
  min-width: 70px;
  border: 0;
  border-radius: 6px;
  background: var(--red);
  color: #fff;
  font-weight: 700;
}
form button:hover { background: var(--red-dark); }
form button:disabled, header button:disabled { cursor: wait; opacity: .55; }
.status { padding: 0 14px 10px; color: var(--muted); font-size: 11px; }

@media (max-width: 560px) {
  header { padding: 10px 12px; }
  h1 { font-size: 17px; }
  .messages { padding: 16px 10px; }
  .bubble { max-width: 86%; padding: 12px 14px; }
  form { padding: 9px; }
  form button { min-width: 58px; }
}
