* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: #f8f9fa;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: #1a1a1a;
    font-size: 16px;
    line-height: 1.6;
}

.container {
    width: 100%;
    max-width: 800px;
}

.chat-container {
    background: #ffffff;
    border-radius: 0;
    border: 1px solid #e0e0e0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    height: 600px;
    overflow: hidden;
}

.chat-header {
    background: #ffffff;
    color: #1a1a1a;
    padding: 32px 32px 24px;
    border-bottom: 1px solid #e8e8e8;
}

.chat-header h1 {
    font-size: 28px;
    font-weight: 500;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.chat-header p {
    font-size: 15px;
    color: #666;
    font-weight: 400;
}

.chat-header a {
    color: #1a1a1a;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: color 0.2s;
}

.chat-header a:hover {
    color: #333;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #fafafa;
}

.message {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    animation: slideIn 0.3s ease-out;
    margin-bottom: 8px;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: -16px;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-avatar svg {
    width: 24px;
    height: 24px;
    fill: #888;
}

.message-content {
    max-width: 70%;
    padding: 14px 18px;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.user-message {
    justify-content: flex-end;
}

.user-message .message-content {
    background: #1a1a1a;
    color: #ffffff;
    border-radius: 18px 18px 4px 18px;
}

.user-message .message-content::after {
    content: '';
    position: absolute;
    bottom: 4px;
    right: -7px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-left-color: #1a1a1a;
    border-right: 0;
    border-bottom: 0;
    margin-bottom: -4px;
}

.bot-message {
    justify-content: flex-start;
}

.bot-message .message-content {
    background: #f8f8f8;
    color: #1a1a1a;
    border-radius: 18px 18px 18px 4px;
    border: 1px solid #ececec;
}

.bot-message .message-content::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: -7px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: #f8f8f8;
    border-left: 0;
    border-bottom: 0;
    margin-bottom: -4px;
}

.bot-message .message-content::before {
    content: '';
    position: absolute;
    bottom: 4px;
    left: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: #ececec;
    border-left: 0;
    border-bottom: 0;
    margin-bottom: -4px;
}

/* Sources section within bot messages */
.sources-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
}

.sources-label {
    font-size: 0.75em;
    color: #888;
    font-weight: 500;
    margin-bottom: 4px;
}

.sources-list {
    font-size: 0.75em;
    color: #888;
    line-height: 1.4;
}

/* Markdown styling for bot messages */
.bot-message .message-content p {
    margin: 0 0 16px 0;
    line-height: 1.7;
}

.bot-message .message-content p:last-child {
    margin-bottom: 0;
}

.bot-message .message-content strong {
    font-weight: 600;
    color: #1a1a1a;
}

.bot-message .message-content em {
    font-style: italic;
}

.bot-message .message-content ul,
.bot-message .message-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

.bot-message .message-content li {
    margin: 6px 0;
    line-height: 1.6;
}

.bot-message .message-content ul li {
    list-style-type: disc;
}

.bot-message .message-content ol li {
    list-style-type: decimal;
}

.bot-message .message-content h1,
.bot-message .message-content h2,
.bot-message .message-content h3 {
    margin: 16px 0 8px 0;
    font-weight: 500;
    color: #1a1a1a;
    letter-spacing: -0.02em;
}

.bot-message .message-content h1 {
    font-size: 1.4em;
}

.bot-message .message-content h2 {
    font-size: 1.2em;
}

.bot-message .message-content h3 {
    font-size: 1.1em;
}

.bot-message .message-content code {
    background: #e0e0e0;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.bot-message .message-content pre {
    background: #e0e0e0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.bot-message .message-content pre code {
    background: none;
    padding: 0;
}

.bot-message .message-content blockquote {
    border-left: 3px solid #1a1a1a;
    padding-left: 16px;
    margin: 12px 0;
    color: #666;
    font-style: italic;
}

/* Citation styling */
.bot-message .message-content sup,
.bot-message .message-content .citation {
    font-size: 0.85em;
    color: #666;
    font-weight: 500;
}

/* Link styling */
.bot-message .message-content a {
    color: #1a1a1a;
    text-decoration: none;
    border-bottom: 1px solid #1a1a1a;
}

.bot-message .message-content a:hover {
    color: #333;
    border-bottom-color: #333;
}

/* Dan Sturges' signature terminology highlighting */
.dan-term {
    color: #c7254e;
    font-weight: 600;
}

.loading {
    display: flex;
    gap: 8px;
    padding: 16px 20px !important;
    min-width: 60px;
}

.loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: bounce 1.4s infinite ease-in-out;
}

.loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

.input-container {
    padding: 24px 32px;
    background: #ffffff;
    border-top: 1px solid #e8e8e8;
}

#chat-form {
    display: flex;
    gap: 12px;
    align-items: center;
}

#user-input {
    flex: 1;
    padding: 14px 18px;
    border: 1px solid #d0d0d0;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fafafa;
}

#user-input:focus {
    border-color: #1a1a1a;
    background: #ffffff;
    box-shadow: 0 0 0 1px #1a1a1a;
}

#send-button {
    width: 44px;
    height: 44px;
    border: 1px solid #1a1a1a;
    border-radius: 8px;
    background: #1a1a1a;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

#send-button:hover {
    background: #333;
    border-color: #333;
}

#send-button:active {
    transform: scale(0.97);
}

#send-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* Scrollbar styling */
.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - 40px);
    }

    .message-content {
        max-width: 85%;
    }
}
