:root {
  --bg: #f4f5f9; --panel: #ffffff; --text: #1d2130; --muted: #7a8094;
  --user: #4f6bff; --user-text: #ffffff; --bot: #eceef6; --border: #dfe2ee;
  --code: #14172a; --code-text: #e6e9ff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f111a; --panel: #171a27; --text: #e8eaf4; --muted: #8a90a8;
    --bot: #222638; --border: #2a2f45;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }

.app { max-width: 820px; height: 100%; margin: 0 auto; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.title { display: flex; align-items: center; gap: 10px; }
.title h1 { font-size: 17px; margin: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #2ecc71; }
#clearBtn { background: transparent; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
#clearBtn:hover { color: var(--text); }

main { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; line-height: 1.55; font-size: 15px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-text); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bot); border-bottom-left-radius: 4px; }
.msg.error { background: #ffe5e5; color: #a31515; }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin-bottom: 0; }
.msg pre { background: var(--code); color: var(--code-text); padding: 12px; border-radius: 10px; overflow-x: auto; font-size: 13px; margin: 8px 0; }
.msg code { font-family: ui-monospace, Menlo, Consolas, monospace; }
.msg :not(pre) > code { background: rgba(128,128,160,.22); padding: 1px 5px; border-radius: 5px; font-size: 13px; }

.typing span { display: inline-block; width: 7px; height: 7px; margin: 0 2px; background: var(--muted); border-radius: 50%; animation: b 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes b { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

form { display: flex; gap: 10px; padding: 12px 18px 4px; border-top: 1px solid var(--border); }
textarea { flex: 1; resize: none; max-height: 160px; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; outline: none; }
textarea:focus { border-color: var(--user); }
#sendBtn { background: var(--user); color: #fff; border: 0; border-radius: 12px; padding: 0 20px; font-weight: 600; cursor: pointer; }
#sendBtn:disabled { opacity: .5; cursor: not-allowed; }
.hint { margin: 0; padding: 4px 18px 12px; font-size: 12px; color: var(--muted); }
