:root {
    /* Plant DPS color palette */
    --plant-dps-blue: #4267b2;
    --plant-dps-dark-blue: #2d4a7c;
    --plant-dps-light-blue: #5a7bc2;
    --background-gray: #f5f5f5;
    --white: #ffffff;
    --text-dark: #333333;
    --text-light: #666666;
    --border-color: #e0e0e0;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--background-gray) 0%, #e8f5e9 100%);
    color: var(--text-dark);
    min-height: 100vh;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    background: var(--white);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-left: 4px solid var(--plant-dps-blue);
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
}

.logo {
    max-height: 80px;
    width: auto;
    object-fit: contain;
}

main {
    flex: 1;
    display: flex;
    flex-direction: row;
    gap: 20px;
}

.chat-container {
    background: var(--white);
    border-radius: 16px;
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 280px);
    min-height: 500px;
    border: 2px solid var(--plant-dps-blue);
    flex: 1;
    transition: flex 0.3s ease;
}

.chat-container.with-pdf {
    flex: 0 0 40%;
}

/* PDF Viewer Panel */
.pdf-viewer {
    background: var(--white);
    border-radius: 16px;
    box-shadow: var(--shadow-xl);
    border: 2px solid var(--plant-dps-blue);
    display: none;
    flex-direction: column;
    height: calc(100vh - 280px);
    min-height: 500px;
    flex: 1;
}

.pdf-viewer.active {
    display: flex;
}

.pdf-viewer-header {
    padding: 14px 20px;
    background: linear-gradient(135deg, var(--plant-dps-blue) 0%, var(--plant-dps-light-blue) 100%);
    color: var(--white);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 14px 14px 0 0;
}

#pdf-title {
    font-weight: 600;
    font-size: 13px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.close-pdf-btn {
    background: transparent;
    border: none;
    color: var(--white);
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.close-pdf-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

#pdf-iframe {
    flex: 1;
    width: 100%;
    border-radius: 0 0 10px 10px;
}

/* Clickable Reference Links */
.reference-link {
    color: var(--plant-dps-blue);
    text-decoration: none;
    cursor: pointer;
    border-bottom: 1px dashed var(--plant-dps-blue);
    transition: all 0.2s;
    font-weight: 500;
}

.reference-link:hover {
    color: var(--plant-dps-blue);
    border-bottom-color: var(--plant-dps-blue);
    background: rgba(139, 92, 246, 0.1);
    border-radius: 2px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

.welcome-message h2 {
    color: var(--plant-dps-blue);
    margin-bottom: 12px;
    font-size: 28px;
    font-weight: 700;
}

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

.message {
    display: flex;
    gap: 12px;
    max-width: 80%;
    animation: slideIn 0.3s ease-out;
}

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

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

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

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: var(--white);
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--plant-dps-blue), var(--plant-dps-light-blue));
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--plant-dps-blue), var(--plant-dps-light-blue));
}

.message-content {
    background: var(--background-gray);
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
}

.message.user .message-content {
    background: linear-gradient(135deg, var(--plant-dps-blue), var(--plant-dps-light-blue));
    color: var(--white);
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--background-gray);
    border-bottom-left-radius: 4px;
    border-left: 3px solid var(--plant-dps-blue);
}

/* Markdown formatting inside messages */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    color: var(--plant-dps-dark-blue);
    margin: 12px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
}

.message-content h1 { font-size: 1.5em; }
.message-content h2 { font-size: 1.3em; }
.message-content h3 { font-size: 1.15em; }
.message-content h4 { font-size: 1.05em; }
.message-content h5 { font-size: 1em; }
.message-content h6 { font-size: 0.95em; }

.message-content p {
    margin: 8px 0;
    line-height: 1.6;
}

.message-content strong {
    font-weight: 600;
    color: var(--plant-dps-dark-blue);
}

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

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

.message-content li {
    margin: 4px 0;
    line-height: 1.5;
}

.message-content code {
    background: rgba(37, 99, 235, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    color: var(--plant-dps-dark-blue);
    border: 1px solid rgba(37, 99, 235, 0.2);
}

.message-content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

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

.message-content blockquote {
    border-left: 3px solid var(--plant-dps-blue);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-light);
    font-style: italic;
}

.message-content a {
    color: var(--plant-dps-blue);
    text-decoration: none;
    border-bottom: 1px solid var(--plant-dps-blue);
}

.message-content a:hover {
    color: var(--plant-dps-blue);
    border-bottom-color: var(--plant-dps-blue);
}

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

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border-color);
    padding: 8px;
    text-align: left;
}

.message-content th {
    background: rgba(37, 99, 235, 0.1);
    font-weight: 600;
    color: var(--plant-dps-dark-blue);
}

/* Remove top margin from first element and bottom margin from last element */
.message-content > *:first-child {
    margin-top: 0;
}

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

/* Math/Formula styling with MathJax */
.message-content .MathJax {
    font-size: 1em !important;
}

.message-content mjx-container[display="true"] {
    margin: 12px 0;
    overflow-x: auto;
}

/* References section styling */
.message-content hr + h2,
.message-content hr + h3 {
    margin-top: 8px;
}

.input-container {
    display: flex;
    gap: 12px;
    padding: 20px;
    border-top: 1px solid var(--border-color);
    background: var(--white);
    border-radius: 0 0 12px 12px;
}

#user-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: border-color 0.3s;
}

#user-input:focus {
    outline: none;
    border-color: var(--plant-dps-blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#send-button {
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--plant-dps-blue), var(--plant-dps-light-blue));
    color: var(--white);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

#send-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

#send-button:active {
    transform: translateY(0);
}

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

.loading-indicator {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--white);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    text-align: center;
}

.loading-indicator.active {
    display: block;
}

.spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto 16px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--plant-dps-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

footer {
    text-align: center;
    padding: 20px;
    color: var(--text-light);
    font-size: 14px;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--plant-dps-blue);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--plant-dps-dark-blue);
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .logo {
        max-height: 60px;
    }

    .logo-secondary {
        max-height: 50px;
    }

    .chat-container {
        height: calc(100vh - 240px);
    }

    .message {
        max-width: 90%;
    }

    .welcome-message h2 {
        font-size: 22px;
    }
}
