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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    height: 100vh;
    background: #f8fafc;
    color: #1e293b;
    display: flex;
    flex-direction: column;
}

.header {
    background: white;
    border-bottom: 1px solid #e2e8f0;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #0f172a;
}

.status-section {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-text {
    font-size: 0.875rem;
    color: #10b981;
    font-weight: 500;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
}

.status-indicator.connected {
    background: #10b981;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: min(600px, 80vw);
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    position: relative;
}

.message-container {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    max-width: min(600px, 80vw);
}

.message-container.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-container.assistant {
    align-self: flex-start;
}

.message.user {
    align-self: flex-end;
    background: #3b82f6;
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message.assistant {
    background: white;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 0.25rem;
}

/* Markdown styles for assistant messages */
.message.assistant h1,
.message.assistant h2,
.message.assistant h3 {
    margin: 0.5rem 0;
    font-weight: 600;
}

.message.assistant h1 {
    font-size: 1.25rem;
    color: #1e293b;
}

.message.assistant h2 {
    font-size: 1.125rem;
    color: #334155;
}

.message.assistant h3 {
    font-size: 1rem;
    color: #475569;
}

.message.assistant p {
    margin: 0.5rem 0;
}

.message.assistant p:first-child {
    margin-top: 0;
}

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

.message.assistant strong {
    font-weight: 600;
    color: #1e293b;
}

.message.assistant em {
    font-style: italic;
    color: #374151;
}

.message.assistant code {
    background: #f1f5f9;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 0.825rem;
    color: #e11d48;
}

.message.assistant pre {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin: 0.5rem 0;
    overflow-x: auto;
}

.message.assistant pre code {
    background: none;
    padding: 0;
    color: #374151;
    font-size: 0.8rem;
}

.message.assistant ul,
.message.assistant ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message.assistant li {
    margin: 0.25rem 0;
}

.message.assistant a {
    color: #3b82f6;
    text-decoration: underline;
}

.message.assistant a:hover {
    color: #2563eb;
}

.message.error {
    align-self: center;
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.input-section {
    background: white;
    border-top: 1px solid #e2e8f0;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Instructions Section */
.instructions-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.instructions-toggle {
    background: none;
    border: none;
    padding: 0.5rem 0;
    font-size: 0.875rem;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-align: left;
    transition: color 0.2s ease;
}

.instructions-toggle:hover {
    color: #374151;
}

.toggle-icon {
    transition: transform 0.2s ease;
    font-size: 0.75rem;
}

.instructions-toggle.expanded .toggle-icon {
    transform: rotate(90deg);
}

.instructions-content {
    display: none;
    flex-direction: column;
    gap: 0.25rem;
}

.instructions-content.expanded {
    display: flex;
}

.instructions-input {
    min-height: 2.5rem;
    max-height: 80px;
    padding: 0.625rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    resize: none;
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.25rem;
    background: #f8fafc;
}

.instructions-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 1px #3b82f6;
    background: white;
}

.instructions-char-count {
    font-size: 0.75rem;
    color: #6b7280;
    text-align: right;
}

/* Reasoning Section */
.reasoning-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
}

.reasoning-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: #374151;
    cursor: pointer;
}

.reasoning-checkbox {
    width: 1rem;
    height: 1rem;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    cursor: pointer;
}

.reasoning-options {
    display: none;
    flex-direction: row;
    gap: 1rem;
    margin-top: 0.25rem;
    padding-left: 1.5rem;
}

.reasoning-options.show {
    display: flex;
}

.reasoning-option {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
    color: #64748b;
    cursor: pointer;
}

.reasoning-radio {
    width: 0.875rem;
    height: 0.875rem;
    cursor: pointer;
}

/* Input Area Wrapper */
.input-area-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.input-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.message-input {
    min-height: 2.5rem;
    max-height: 120px;
    padding: 0.625rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    resize: none;
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.25rem;
}

.message-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 1px #3b82f6;
}

.char-count {
    font-size: 0.75rem;
    color: #6b7280;
    text-align: right;
}

.send-button {
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    height: fit-content;
    min-width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-button:hover:not(:disabled) {
    background: #2563eb;
}

.send-button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.loading {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #f1f5f9;
    border-radius: 1rem;
    align-self: flex-start;
    color: #64748b;
    font-style: italic;
}

.loading.show {
    display: flex;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e2e8f0;
    border-top: 2px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #64748b;
    text-align: center;
    padding: 2rem;
}

.empty-state h2 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
    color: #374151;
}

/* Reasoning Button */
.reasoning-button {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.75rem;
    color: #64748b;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.reasoning-button:hover {
    background: #e2e8f0;
    color: #475569;
}

.reasoning-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Reasoning Modal */
.reasoning-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.reasoning-modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.reasoning-modal-content {
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    max-width: 600px;
    max-height: 80vh;
    width: 90%;
    margin: 2rem;
    display: flex;
    flex-direction: column;
}

.reasoning-modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.reasoning-modal-header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: #1e293b;
}

.reasoning-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #64748b;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.25rem;
}

.reasoning-modal-close:hover {
    background: #f1f5f9;
    color: #374151;
}

.reasoning-modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    font-size: 0.875rem;
    line-height: 1.6;
    color: #374151;
    white-space: pre-wrap;
}

@media (max-width: 640px) {
    .header {
        flex-direction: column;
        align-items: stretch;
    }

    .status-section {
        justify-content: center;
    }

    .message {
        max-width: min(95vw, 500px);
    }

    .message-container {
        max-width: min(95vw, 500px);
    }

    .reasoning-modal-content {
        margin: 1rem;
        width: calc(100% - 2rem);
        max-height: 90vh;
    }

    .reasoning-modal-header,
    .reasoning-modal-body {
        padding: 1rem;
    }
}