:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1c2430; --muted: #66707f; --line: #e2e6ec;
  --brand: #004165; --brand-2: #772432; --user: #004165; --user-text: #ffffff;
  --bot: #ffffff; --link: #0b5fa5; --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a; --panel: #171e27; --text: #e6eaf0; --muted: #94a0b0; --line: #2a3441;
    --brand: #4aa3d8; --user: #1b5e8a; --user-text: #ffffff; --bot: #1b2430; --link: #7cc1ee;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.app {
  max-width: 820px; height: 100dvh; margin: 0 auto; display: flex; flex-direction: column;
  padding: 0 16px;
}
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 0 10px; }
h1 { margin: 0; font-size: 1.5rem; color: var(--brand); letter-spacing: -0.01em; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: .95rem; }
.ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font: inherit; font-size: .85rem; cursor: pointer; white-space: nowrap;
}
.ghost:hover { color: var(--text); border-color: var(--muted); }
.messages { flex: 1; overflow-y: auto; padding: 8px 0 12px; display: flex; flex-direction: column; gap: 12px; }
.empty { margin: auto 0; text-align: center; padding: 24px 0; }
.hint { color: var(--muted); margin: 0 0 12px; }
.examples { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.example {
  text-align: left; background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; font: inherit; font-size: .95rem; cursor: pointer;
}
.example:hover { border-color: var(--brand); }
.msg { max-width: 92%; padding: 10px 14px; border-radius: var(--radius); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-text); white-space: pre-wrap; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bot); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.error { align-self: center; background: transparent; border: 1px dashed var(--brand-2); color: var(--brand-2); font-size: .92rem; }
.msg.bot > :first-child { margin-top: 0; }
.msg.bot > :last-child { margin-bottom: 0; }
.msg.bot p { margin: .5em 0; }
.msg.bot ul, .msg.bot ol { margin: .5em 0; padding-left: 1.3em; }
.msg.bot a { color: var(--link); }
.msg.bot h3, .msg.bot h4 { margin: .8em 0 .3em; font-size: 1.02rem; }
.msg.bot code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.tablewrap { overflow-x: auto; margin: .6em 0; }
.msg.bot table { border-collapse: collapse; font-size: .92rem; min-width: 100%; }
.msg.bot th, .msg.bot td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; vertical-align: top; }
.msg.bot th { background: var(--bg); }
.sources { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: .82rem; color: var(--muted); }
.sources a { color: var(--link); margin-right: 10px; white-space: nowrap; }
.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .4; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 0; }
textarea {
  flex: 1; resize: none; max-height: 160px; padding: 11px 14px; font: inherit; color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
#send {
  background: var(--brand); color: #fff; border: 0; border-radius: var(--radius); padding: 11px 18px;
  font: inherit; font-weight: 600; cursor: pointer;
}
#send:disabled { opacity: .5; cursor: default; }
.foot { color: var(--muted); font-size: .76rem; text-align: center; padding: 4px 0 12px; }
.foot a { color: var(--link); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 560px) {
  .examples { grid-template-columns: 1fr; }
  .top { padding-top: 12px; }
  h1 { font-size: 1.3rem; }
  .msg { max-width: 96%; }
}
