/* LSA Chat Interface Styles */

.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 200px);
    min-height: 500px;
    max-height: 800px;
}

.chat-header {
    text-align: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

.chat-header h2 {
    font-size: 1.4rem;
    color: var(--accent);
    margin: 0 0 0.25rem 0;
    font-weight: normal;
}

.chat-header p {
    color: var(--source-color);
    margin: 0;
    font-size: 0.9rem;
}

.chat-actions {
    margin-top: 0.75rem;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
}

.btn-secondary {
    background: transparent;
    color: var(--source-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: all 0.15s;
}

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Main chat area */
.chat-main {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: white;
}

@media (prefers-color-scheme: dark) {
    .chat-messages {
        background: black;
    }
}

.message {
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease;
}

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

.message-content {
    padding: 0.75rem 1rem;
    line-height: 1.6;
}

.message.user .message-content {
    background: var(--accent);
    color: white;
    margin-left: 20%;
    border-radius: 8px;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    margin-right: 10%;
}

.message-content p {
    margin: 0 0 0.5rem 0;
}

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

.message-content ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message-content li {
    margin: 0.25rem 0;
}

.message-content .hint {
    font-size: 0.85rem;
    color: var(--source-color);
    margin-top: 1rem;
    font-style: italic;
}

/* Citations in messages */
.message-content .citation {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
}

.message-content .citation:hover {
    text-decoration: underline;
}

/* Headers in responses */
.message-content h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 1rem 0 0.5rem 0;
    color: var(--text-color);
}

.message-content h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0.75rem 0 0.4rem 0;
    color: var(--text-color);
}

.message-content h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0.5rem 0 0.3rem 0;
    color: var(--text-color);
}

/* Lists in responses */
.message-content ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message-content ol li {
    margin-bottom: 0.3rem;
}

/* Thinking section (extended thinking) */
.thinking-section {
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
}

.thinking-section summary {
    cursor: pointer;
    color: var(--source-color);
    font-style: italic;
    padding: 0.25rem 0;
}

.thinking-section summary:hover {
    color: var(--link-color);
}

.thinking-section summary::marker {
    color: var(--accent);
}

.thinking-content {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-color);
    border: 1px dashed var(--border-color);
    border-radius: 4px;
    color: var(--source-color);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
}

.response-text {
    margin-top: 0.5rem;
}

/* Loading indicator */
.message.assistant .message-content.loading::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 0.5rem;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Source modal popup */
.source-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.source-modal.visible {
    display: flex;
}

.source-modal-content {
    background: var(--quote-bg);
    border-radius: 12px;
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.source-modal-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.source-modal-number {
    font-weight: bold;
    color: white;
    background: var(--accent);
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.9rem;
}

.type-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.type-badge.authoritative {
    background: #2e7d32;
    color: white;
}

.type-badge.editorial {
    background: #5d4037;
    color: white;
}

.source-modal-header h3 {
    flex: 1;
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-color);
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--source-color);
    padding: 0;
    line-height: 1;
}

.btn-close:hover {
    color: var(--text-color);
}

.source-modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
    line-height: 1.7;
    color: var(--text-color);
}

.source-modal-citation {
    padding: 0.75rem 1.25rem;
    background: rgba(0, 0, 0, 0.15);
    font-size: 0.85rem;
    font-style: italic;
    color: var(--source-color);
    border-top: 1px solid var(--border-color);
}

.source-modal-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    text-align: right;
}

.source-modal-footer .btn-primary {
    padding: 0.5rem 1.25rem;
}

/* Input area */
.chat-input-container {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

#user-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--quote-bg);
    color: var(--text-color);
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    resize: none;
    max-height: 150px;
    overflow-y: auto;
}

#user-input:focus {
    outline: none;
    border-color: var(--accent);
}

#user-input::placeholder {
    color: var(--source-color);
}

#send-btn {
    padding: 0.75rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#send-btn:hover {
    opacity: 0.9;
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-hint {
    font-size: 0.75rem;
    color: var(--source-color);
    margin-top: 0.5rem;
    text-align: right;
}

/* Error message */
.error-message {
    background: #fee;
    border: 1px solid #fcc;
    color: #c33;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

@media (prefers-color-scheme: dark) {
    .error-message {
        background: #3a2020;
        border-color: #5a3030;
        color: #f99;
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - 180px);
    }

    .message.user .message-content {
        margin-left: 10%;
    }

    .message.assistant .message-content {
        margin-right: 5%;
    }

    .source-modal-content {
        max-height: 90vh;
        margin: 0.5rem;
    }
}
