:root {
  font-family: "Segoe UI", "Yu Gothic UI", "Hiragino Kaku Gothic ProN", sans-serif;
  color: #17213a;
  background: #eef2ff;
}

* { box-sizing: border-box; }
body {
  min-height: 100vh;
  margin: 0;
  padding: 24px;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top left, #dbeafe, transparent 42%), linear-gradient(135deg, #f8fafc, #e0e7ff);
}

.chat-shell {
  width: min(850px, 100%);
  height: min(820px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 22px;
  box-shadow: 0 24px 70px rgba(30, 41, 59, 0.16);
}

.chat-header { display: flex; align-items: center; gap: 14px; padding: 20px 24px; border-bottom: 1px solid #e2e8f0; }
.logo { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 14px; color: white; font-weight: 800; background: linear-gradient(135deg, #4f46e5, #2563eb); }
h1 { margin: 0; font-size: 1.2rem; }
.chat-header p { margin: 5px 0 0; color: #64748b; font-size: 0.85rem; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: #22c55e; }

.messages { overflow-y: auto; padding: 26px; scroll-behavior: smooth; }
.message { display: flex; margin-bottom: 18px; }
.message.assistant { align-items: flex-start; flex-direction: column; }
.message.user { justify-content: flex-end; }
.bubble { max-width: min(75%, 620px); padding: 13px 17px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; border-radius: 18px 18px 18px 5px; background: #f1f5f9; }
.user .bubble { color: white; border-radius: 18px 18px 5px 18px; background: #4f46e5; }
.pending .bubble { color: #64748b; }
.markdown-body { white-space: normal; }
.markdown-body p { margin: 0 0 0.75em; }
.markdown-body p:last-child { margin-bottom: 0; }
.markdown-body h3, .markdown-body h4, .markdown-body h5 { margin: 1em 0 0.45em; line-height: 1.35; }
.markdown-body ul { margin: 0.4em 0 0.8em; padding-left: 1.4em; }
.markdown-body li { margin: 0.25em 0; }
.markdown-body code { padding: 0.12em 0.35em; border-radius: 4px; background: #e2e8f0; font-size: 0.9em; }
.markdown-body pre { max-width: 100%; margin: 0.7em 0; padding: 12px 14px; overflow-x: auto; border-radius: 9px; background: #17213a; }
.markdown-body pre code { padding: 0; color: #f8fafc; background: transparent; white-space: pre; }
.markdown-body a { color: #3730a3; text-decoration: underline; }
.markdown-body hr { margin: 1em 0; border: 0; border-top: 1px solid #cbd5e1; }
.table-scroll { max-width: 100%; margin: 0.7em 0; overflow-x: auto; }
.markdown-body table { width: 100%; border-collapse: collapse; font-size: 0.9em; }
.markdown-body th, .markdown-body td { min-width: 90px; padding: 8px 10px; text-align: left; vertical-align: top; border: 1px solid #cbd5e1; }
.markdown-body th { background: #e2e8f0; }
.quote-button {
  height: auto;
  margin: 5px 0 0 8px;
  padding: 4px 8px;
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 600;
  border: 0;
  border-radius: 7px;
  background: transparent;
}
.quote-button:hover { color: #3730a3; background: #eef2ff; }
.selection-quote-button {
  position: fixed;
  z-index: 1000;
  width: auto;
  height: 38px;
  padding: 0 13px;
  color: white;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  background: #17213a;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.24);
}
.selection-quote-button[hidden] { display: none; }
.selection-quote-button:hover { background: #334155; }

.error { margin: 0 24px 12px; padding: 11px 14px; color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; border-radius: 10px; font-size: 0.9rem; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 20px 0; border-top: 1px solid #e2e8f0; }
.quick-action { height: 36px; padding: 0 12px; color: #3730a3; font-size: 0.82rem; font-weight: 700; border: 1px solid #c7d2fe; border-radius: 999px; background: #eef2ff; }
.quick-action:hover { color: white; background: #4f46e5; }
.composer { position: relative; display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 16px 20px 30px; border-top: 1px solid #e2e8f0; }
.quote-preview {
  grid-column: 1 / -1;
  position: relative;
  min-width: 0;
  padding: 9px 38px 9px 12px;
  color: #475569;
  border-left: 3px solid #6366f1;
  border-radius: 7px;
  background: #f8fafc;
  font-size: 0.78rem;
}
.quote-preview[hidden] { display: none; }
.quote-preview strong { color: #3730a3; }
.quote-preview p { margin: 3px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-cancel {
  position: absolute;
  top: 5px;
  right: 6px;
  width: 28px;
  height: 28px;
  padding: 0;
  justify-content: center;
  color: #64748b;
  font-size: 1.15rem;
  border-radius: 50%;
  background: transparent;
}
.quote-cancel:hover { color: #17213a; background: #e2e8f0; }
textarea { width: 100%; min-height: 48px; max-height: 140px; resize: none; padding: 13px 15px; font: inherit; line-height: 1.4; border: 1px solid #cbd5e1; border-radius: 13px; outline: none; }
textarea:focus { border-color: #6366f1; box-shadow: 0 0 0 3px #e0e7ff; }
button { align-self: end; height: 48px; padding: 0 18px; display: flex; align-items: center; gap: 8px; color: white; font: inherit; font-weight: 700; border: 0; border-radius: 13px; background: #4f46e5; cursor: pointer; }
button:hover { background: #4338ca; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.hint { position: absolute; bottom: 7px; left: 22px; margin: 0; color: #94a3b8; font-size: 0.72rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

@media (max-width: 600px) {
  body { padding: 0; }
  .chat-shell { height: 100vh; border: 0; border-radius: 0; }
  .messages { padding: 18px 14px; }
  .bubble { max-width: 88%; }
  .chat-header { padding: 15px 16px; }
  .composer { padding-inline: 12px; }
  .quick-actions { padding-inline: 12px; }
  button span:first-child { display: none; }
}
