/* dbGaP Query - Modern Chat Interface */
/* Inspired by Nature publications - clean, elegant, professional */

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

html {
    height: 100%;
}

:root {
    --white: #FDFBF7;
    --off-white: #FAF8F4;
    --light-gray: #F5F3EF;
    --border-gray: #E5E5E5;
    --text-primary: #1A1A1A;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --accent: #0066CC;
    --accent-hover: #0052A3;
    --success: #28A745;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Times New Roman', Times, serif;
    background-color: var(--off-white);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    overscroll-behavior-y: contain;
}

/* Header */
.header {
    background-color: var(--white);
    border-bottom: 1px solid var(--border-gray);
    padding: 6px 40px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
}

.header-left {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 24px;
}

.logo {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.logo-img {
    height: 32px;
    width: auto;
}

.stats {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.stat-item {
    font-weight: 400;
    opacity: 0;
    transition: opacity 0.4s ease-in;
}

.stat-item.loaded {
    opacity: 1;
}

.stat-divider {
    color: var(--text-tertiary);
    opacity: 0;
    transition: opacity 0.4s ease-in;
}

.stat-divider.loaded {
    opacity: 1;
}

/* Main Chat Wrapper */
.chat-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 20px 20px 100px 20px; /* Bottom padding for fixed input */
}

.chat-container {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Messages Container */
.messages-container {
    padding: 32px;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 40px 20px;
}

.welcome-logo {
    height: 48px;
    width: auto;
    margin-bottom: 12px;
}

.welcome-message > p {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.examples-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    font-weight: 500;
}

.example-queries {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.example-chip {
    background-color: var(--light-gray);
    border: 1px solid var(--border-gray);
    color: var(--text-primary);
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 15px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 400;
    max-width: 100%;
    text-align: center;
}

.example-chip:hover {
    background-color: var(--border-gray);
    border-color: var(--text-tertiary);
}

/* Chat Messages */
.message {
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease;
}

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

.message-content {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    word-wrap: break-word;
}

.user-message .message-content {
    background-color: var(--light-gray);
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid var(--border-gray);
    white-space: pre-wrap;
}

.assistant-message .message-content {
    padding: 4px 0;
}

/* Markdown Styling within Assistant Messages */
.assistant-message .message-content h1,
.assistant-message .message-content h2,
.assistant-message .message-content h3,
.assistant-message .message-content h4 {
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 20px;
    margin-bottom: 12px;
    line-height: 1.3;
}

.assistant-message .message-content h1 {
    font-size: 24px;
}

.assistant-message .message-content h2 {
    font-size: 20px;
}

.assistant-message .message-content h3 {
    font-size: 18px;
}

.assistant-message .message-content h4 {
    font-size: 16px;
}

.assistant-message .message-content p {
    margin-bottom: 12px;
}

.assistant-message .message-content ul,
.assistant-message .message-content ol {
    margin-left: 20px;
    margin-bottom: 12px;
}

.assistant-message .message-content li {
    margin-bottom: 6px;
}

.assistant-message .message-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.assistant-message .message-content a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease;
}

.assistant-message .message-content a:hover {
    border-bottom-color: var(--accent);
}

.assistant-message .message-content code {
    background-color: var(--light-gray);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 13px;
    color: var(--text-primary);
}

.assistant-message .message-content pre {
    background-color: var(--light-gray);
    border: 1px solid var(--border-gray);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin-bottom: 12px;
}

.assistant-message .message-content pre code {
    background: none;
    padding: 0;
    border-radius: 0;
}

.assistant-message .message-content blockquote {
    border-left: 3px solid var(--border-gray);
    padding-left: 16px;
    margin-left: 0;
    margin-bottom: 12px;
    color: var(--text-secondary);
    font-style: italic;
}

.assistant-message .message-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    font-size: 14px;
    background-color: var(--white);
    border: 1px solid var(--border-gray);
    border-radius: 8px;
    overflow: hidden;
}

.assistant-message .message-content thead {
    background-color: var(--light-gray);
}

.assistant-message .message-content th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-gray);
}

.assistant-message .message-content td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-gray);
    color: var(--text-primary);
}

.assistant-message .message-content tr:last-child td {
    border-bottom: none;
}

.assistant-message .message-content tr:hover {
    background-color: var(--off-white);
}

.assistant-message .message-content hr {
    border: none;
    border-top: 1px solid var(--border-gray);
    margin: 20px 0;
}

/* Typing Indicator */
.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-tertiary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
    }
    30% {
        opacity: 1;
    }
}

/* Thinking Status Bar - Simple, non-expandable */
.thinking-container {
    background-color: var(--light-gray);
    border: 1px solid var(--border-gray);
    border-radius: 8px;
    padding: 12px 16px;
    margin: 16px 0;
    max-width: 400px;
}

.thinking-status {
    display: flex;
    align-items: center;
    gap: 10px;
}

.thinking-message {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    /* Animate text changes smoothly */
    transition: opacity 0.15s ease;
}

/* Streaming answer - no cursor, just smooth text appearance */

/* Smooth text appearance during streaming */
.streaming-answer .message-content {
    min-height: 1.5em;
}

/* Input Container - fixed at viewport bottom */
.input-container {
    background-color: var(--white);
    border: 1px solid var(--border-gray);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow-md);
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px);
    max-width: 800px;
    z-index: 50;
}

/* Cover element - hides text in gap between input and viewport bottom */
.input-cover {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background-color: var(--off-white);
    z-index: 49; /* Below input (50), above chat content */
}

.input-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.message-input {
    flex: 1;
    border: none;
    background-color: transparent;
    padding: 12px 0;
    font-size: 15px;
    font-family: 'Times New Roman', Times, serif;
    color: var(--text-primary);
    resize: none;
    min-height: 44px;
    max-height: 150px;
    line-height: 1.5;
}

.message-input:focus {
    outline: none;
}

.message-input::placeholder {
    color: var(--text-tertiary);
}

.send-button {
    background-color: var(--text-primary);
    color: var(--white);
    border: none;
    border-radius: 8px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-button:hover {
    background-color: #333333;
    transform: translateY(-1px);
}

.send-button:disabled {
    background-color: var(--border-gray);
    cursor: not-allowed;
}

.send-button:hover:not(:disabled) {
    background-color: #333333;
    transform: translateY(-1px);
}

.send-button:disabled {
    background-color: var(--border-gray);
    cursor: not-allowed;
}

.send-button svg {
    transform: rotate(45deg);
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.input-hint {
    font-size: 12px;
    color: var(--text-tertiary);
}

.clear-button {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.clear-button:hover {
    color: var(--text-primary);
    background-color: var(--light-gray);
}

/* Scrollbar Styling */
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-gray);
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* Auto-expanding textarea */
.message-input {
    overflow-y: hidden;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header {
        padding: 16px 20px;
    }

    .logo-img {
        height: 28px;
    }

    .stats {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .stat-divider {
        display: none;
    }

    .chat-wrapper {
        padding: 20px 16px;
    }

    .messages-container {
        padding: 20px;
        min-height: 400px;
        max-height: 500px;
    }

    .welcome-logo {
        height: 40px;
    }

    .welcome-message > p {
        font-size: 15px;
    }

    .example-chip {
        font-size: 13px;
        padding: 8px 14px;
    }
}

/* Loading State */
.send-button.loading {
    pointer-events: none;
}

.send-button.loading svg {
    animation: rotate 1s linear infinite;
}

@keyframes rotate {
    from {
        transform: rotate(45deg);
    }
    to {
        transform: rotate(405deg);
    }
}

/* Streaming content containers */
.finalized-content {
    display: contents;  /* Don't add any box/spacing, just hold the content */
}

.streaming-preview {
    white-space: pre-wrap;
    font-family: inherit;
}

/* Prevent browser scroll anchoring from causing jumps during streaming finalization */
.assistant-message .message-content {
    overflow-anchor: none;
}
