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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 800px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    height: 90vh;
    max-height: 700px;
}

header {
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 24px;
    color: #1f2937;
    font-weight: 600;
}

.logout-btn {
    padding: 8px 16px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: #dc2626;
}

.model-selector-container {
    padding: 16px 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f9fafb;
}

.model-selector-label {
    font-size: 14px;
    font-weight: 500;
    color: #4b5563;
}

.model-selector {
    padding: 8px 12px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    color: #1f2937;
    background: white;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
    min-width: 200px;
}

.model-selector:focus {
    border-color: #667eea;
}

.model-selector:hover {
    border-color: #d1d5db;
}

.current-model-display {
    font-size: 13px;
    color: #6b7280;
    font-style: italic;
}

.error-container {
    margin: 16px 24px;
    padding: 12px 16px;
    background: #fee2e2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.error-container.hidden {
    display: none;
}

#error-message {
    color: #991b1b;
    font-size: 14px;
    flex: 1;
}

.retry-btn {
    padding: 6px 12px;
    background: #dc2626;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.2s;
}

.retry-btn:hover {
    background: #b91c1c;
}

.retry-btn.hidden {
    display: none;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease-in;
}

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

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

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
    line-height: 1.5;
}

.message.user .message-bubble {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: #f3f4f6;
    color: #1f2937;
    border-bottom-left-radius: 4px;
}

.loading-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    color: #6b7280;
    font-size: 14px;
}

.loading-indicator.hidden {
    display: none;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #e5e7eb;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.chat-form {
    padding: 20px 24px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 12px;
}

.prompt-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.prompt-input:focus {
    border-color: #667eea;
}

.submit-btn {
    padding: 12px 24px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: background 0.2s;
}

.submit-btn:hover:not(:disabled) {
    background: #5568d3;
}

.submit-btn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

/* Mobile responsive */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .container {
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    header h1 {
        font-size: 20px;
    }

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

    .chat-form {
        padding: 16px;
    }

    .prompt-input {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .submit-btn {
        padding: 12px 16px;
    }
}


/* PDF Upload Container */
.pdf-upload-container {
    padding: 12px 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    background: #f9fafb;
}

.pdf-file-input {
    display: none;
}

.pdf-upload-btn {
    padding: 8px 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
    display: inline-block;
}

.pdf-upload-btn:hover {
    background: #5568d3;
}

.pdf-upload-btn.disabled {
    background: #9ca3af;
    cursor: not-allowed;
    pointer-events: none;
}

.pdf-upload-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #6b7280;
}

.pdf-upload-loading.hidden {
    display: none;
}

.pdf-upload-error {
    padding: 8px 12px;
    background: #fee2e2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #991b1b;
    font-size: 13px;
    flex-basis: 100%;
}

.pdf-upload-error.hidden {
    display: none;
}

.document-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 8px;
}

.document-indicator.hidden {
    display: none;
}

.doc-badge {
    font-size: 12px;
    font-weight: 600;
    color: #4338ca;
    background: #c7d2fe;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.doc-name {
    font-size: 13px;
    color: #4b5563;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.clear-document-btn {
    padding: 4px 8px;
    background: transparent;
    color: #6b7280;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s, color 0.2s;
}

.clear-document-btn:hover {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fecaca;
}

/* Mobile responsive for PDF upload */
@media (max-width: 768px) {
    .pdf-upload-container {
        padding: 12px 16px;
    }

    .doc-name {
        max-width: 120px;
    }
}

/* Login Container */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: white;
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    margin: 0 0 0.5rem 0;
    color: #2d3748;
    font-size: 2rem;
    text-align: center;
}

.login-subtitle {
    text-align: center;
    color: #718096;
    margin: 0 0 2rem 0;
    font-size: 0.95rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
    color: #4a5568;
    font-size: 0.9rem;
}

.form-group input {
    padding: 0.75rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.login-btn {
    padding: 0.875rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.login-btn:active {
    transform: translateY(0);
}

.login-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.error-message {
    padding: 0.75rem;
    background: #fed7d7;
    color: #c53030;
    border-radius: 8px;
    font-size: 0.9rem;
    text-align: center;
}

.loading-message {
    text-align: center;
    color: #718096;
    font-size: 0.9rem;
}

.hidden {
    display: none !important;
}

/* Metrics Display */
.metrics-container {
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 8px;
    font-size: 12px;
    color: #6b7280;
    border-left: 3px solid #e5e7eb;
}

.message.user .metrics-container {
    background: rgba(255, 255, 255, 0.15);
    border-left-color: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.9);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
}

.metric-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.metric-label {
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.metric-value {
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    font-weight: 600;
}

.message.user .metric-value {
    color: rgba(255, 255, 255, 1);
}

.message.assistant .metric-value {
    color: #1f2937;
}

/* Mobile responsive for metrics */
@media (max-width: 480px) {
    .metrics-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    
    .metrics-container {
        font-size: 11px;
    }
    
    .metric-value {
        font-size: 12px;
    }
}

/* ===== PDF Upload Styles ===== */

/* PDF Upload Container */
.pdf-upload-container {
    padding: 12px 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f9fafb;
    flex-wrap: wrap;
}

/* Hidden file input */
.pdf-file-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

/* Upload button */
.pdf-upload-btn {
    padding: 8px 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s, opacity 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.pdf-upload-btn:hover:not(:disabled) {
    background: #5568d3;
}

.pdf-upload-btn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Upload loading state */
.pdf-upload-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #6b7280;
}

.pdf-upload-loading .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.pdf-upload-loading.hidden {
    display: none;
}

/* Document Indicator */
.document-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 24px;
    background: #eef2ff;
    border-bottom: 1px solid #c7d2fe;
    animation: fadeIn 0.3s ease-in;
}

.document-indicator.hidden {
    display: none;
}

.document-indicator .doc-name {
    font-size: 14px;
    font-weight: 500;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.document-indicator .doc-badge {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 3px 8px;
    background: #667eea;
    color: white;
    border-radius: 10px;
    white-space: nowrap;
}

/* Clear document button */
.clear-document-btn {
    padding: 4px 10px;
    background: transparent;
    color: #6b7280;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
    margin-left: auto;
}

.clear-document-btn:hover {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fecaca;
}

/* PDF upload error message */
.pdf-upload-error {
    padding: 8px 24px;
    background: #fee2e2;
    border-bottom: 1px solid #fecaca;
    color: #991b1b;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: fadeIn 0.3s ease-in;
}

.pdf-upload-error.hidden {
    display: none;
}

.pdf-upload-error .error-dismiss-btn {
    margin-left: auto;
    padding: 2px 8px;
    background: transparent;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

.pdf-upload-error .error-dismiss-btn:hover {
    background: #fecaca;
}

/* Mobile responsive for PDF upload */
@media (max-width: 768px) {
    .pdf-upload-container {
        padding: 10px 16px;
        gap: 8px;
    }

    .pdf-upload-btn {
        font-size: 13px;
        padding: 7px 12px;
    }

    .document-indicator {
        padding: 8px 16px;
        gap: 8px;
        flex-wrap: wrap;
    }

    .document-indicator .doc-name {
        max-width: 140px;
        font-size: 13px;
    }

    .document-indicator .doc-badge {
        font-size: 10px;
        padding: 2px 6px;
    }

    .clear-document-btn {
        font-size: 11px;
        padding: 3px 8px;
    }

    .pdf-upload-error {
        padding: 8px 16px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .pdf-upload-container {
        padding: 8px 12px;
    }

    .document-indicator {
        padding: 8px 12px;
    }

    .document-indicator .doc-name {
        max-width: 100px;
    }
}
