* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", sans-serif;
    color: #222;
    background: #fafafa;
    line-height: 1.6;
}

.public-header {
    padding: 1rem 2rem;
    border-bottom: 1px solid #e5e5e5;
    background: #fff;
}

.public-site-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    text-decoration: none;
}

.public-main {
    max-width: 780px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}

.public-article h1 {
    font-size: 2rem;
    margin: 0 0 1.5rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.5rem;
}

.public-content h2 { font-size: 1.5rem; margin-top: 2rem; }
.public-content h3 { font-size: 1.2rem; margin-top: 1.5rem; }

.public-content a { color: #2563eb; text-decoration: none; }
.public-content a:hover { text-decoration: underline; }
.public-content a.wikilink { color: #7c3aed; }

.public-content code {
    background: #f0f0f0;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    font-size: 0.92em;
}

.public-content pre {
    background: #1e1e1e;
    color: #f0f0f0;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
}

.public-content pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

.public-content blockquote {
    border-left: 3px solid #ddd;
    margin: 1rem 0;
    padding: 0.2rem 1rem;
    color: #666;
}

.public-backlinks {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e5e5e5;
}

.public-backlinks h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #666;
    margin: 0 0 0.5rem;
}

.public-backlinks ul { list-style: none; padding: 0; margin: 0; }
.public-backlinks li { padding: 0.25rem 0; }
.public-backlinks a { color: #555; text-decoration: none; }
.public-backlinks a:hover { color: #2563eb; text-decoration: underline; }

/* Chat UI */
.chat-body { display: flex; flex-direction: column; min-height: 100vh; }

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
    padding: 1rem;
    box-sizing: border-box;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0 1rem;
    min-height: 300px;
}

.chat-message {
    margin: 0.75rem 0;
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.chat-user { align-self: flex-end; align-items: flex-end; }
.chat-assistant, .chat-error { align-self: flex-start; align-items: flex-start; }

.chat-bubble {
    padding: 0.6rem 0.9rem;
    border-radius: 12px;
    line-height: 1.5;
    word-break: break-word;
}

.chat-user .chat-bubble {
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-assistant .chat-bubble {
    background: #fff;
    color: #222;
    border: 1px solid #e5e5e5;
    border-bottom-left-radius: 4px;
}

.chat-citations {
    margin-top: 0.35rem;
    font-size: 0.8rem;
    color: #666;
    padding: 0 0.5rem;
}

.chat-citations a { color: #2563eb; text-decoration: none; }
.chat-citations a:hover { text-decoration: underline; }

.chat-error {
    align-self: center;
    color: #b91c1c;
    font-size: 0.9rem;
    padding: 0.5rem 0.75rem;
    background: #fef2f2;
    border-radius: 6px;
}

.chat-typing .chat-bubble {
    display: inline-flex;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
}

.chat-typing .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #999;
    animation: chat-bounce 1.2s infinite ease-in-out;
}

.chat-typing .dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

#chat-form {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
    padding-top: 0.5rem;
    border-top: 1px solid #e5e5e5;
}

#chat-input {
    flex: 1;
    padding: 0.6rem 0.8rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font: inherit;
    resize: vertical;
    min-height: 2.5rem;
    max-height: 200px;
}

#chat-input:focus {
    outline: none;
    border-color: #2563eb;
}

#chat-submit {
    padding: 0 1.2rem;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

#chat-submit:disabled { opacity: 0.5; cursor: not-allowed; }
#chat-submit:hover:not(:disabled) { background: #1d4ed8; }
