:root {
    --primary-color: #6c63ff; /* Vibrant Violet */
    --secondary-color: #F9F9F9; /* Very Light Grayish Blue - Changed to almost white */
    --text-color-dark: #2c3e50; /* Dark Slate Gray */
    --text-color-light: #7f8c8d; /* Medium Gray */
    --user-message-bg: #e0e0ff; /* Light Lavender */
    --ai-message-bg: #F7F7F7; /* Light Blue-Gray - Changed to subtle off-white */
    --border-color: #E0E0E0; /* Soft Blue-Gray - Changed to very light gray */
    --error-color: #e74c3c; /* Strong Red */
    --focus-color: #8e88ff; /* Lighter Violet for focus */
    --button-hover-color: #5a54d9; /* Darker Violet for hover */
    --header-bg-color: #F5F5F5; /* Slightly darker light blue-gray for table headers - Changed to very light gray */
    --code-bg-color: #F0F0F0; /* Lightest blue-gray for code blocks - Changed to very light gray */
}

/* General Styles */
body {
    font-family: 'Roboto', sans-serif;
    margin: 0;
    background: linear-gradient(135deg, var(--secondary-color), #e9edf2); /* Updated neutral gradient background */
    color: var(--text-color-dark);
    display: flex;
    flex-direction: row; /* Arrange items horizontally */
    justify-content: center;
    align-items: stretch; /* Stretch items to fill height */
    min-height: 100vh;
    padding: 30px; /* Increased padding */
    box-sizing: border-box;
}

/* Main Header */
#main-header {
    display: flex;
    flex-direction: column; /* Stack title vertically */
    justify-content: flex-start; /* Align title to the top within header */
    align-items: center; /* Center title horizontally within header */
    padding: 0; /* Remove padding for minimal border */
    margin-right: 0px; /* Minimal space between header and chat container */
    min-width: 50px; /* Minimal width for the vertical title */
    padding-top: 40px; /* Increased top padding to move it higher */
}

/* Title */
h1 {
    color: var(--text-color-dark);
    text-align: center;
    margin: 0; /* Remove default h1 margins */
    font-size: 2.5em; /* Slightly larger title */
    font-weight: 700; /* Bolder font */
    background: linear-gradient(45deg, var(--primary-color), #4a45b2, var(--primary-color)); /* Subtle gradient with repeat */
    background-size: 200% 200%; /* Larger background to allow movement */
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1); /* Subtle text shadow for depth */
    writing-mode: vertical-rl; /* Make text vertical, right-to-left */
    text-orientation: mixed; /* Allow characters to be rotated */
    transform: rotate(180deg); /* Rotate to read top-to-bottom */
    /* white-space: nowrap; /* Prevent wrapping - Removed to allow line breaks */
    animation: gradient-shift 8s ease infinite alternate; /* Subtle animation */
}

@keyframes gradient-shift {
    0% {
        background-position: 0% 50%;
    }
    100% {
        background-position: 100% 50%;
    }
}

/* Chatbot Container */
#chat-container {
    background-color: transparent; /* Remove background */
    border-radius: 0; /* Remove border-radius */
    box-shadow: none; /* Remove shadow */
    max-width: 850px; /* Slightly wider */
    width: 100%;
    padding: 30px; /* Revert padding to original as title is outside */
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 15px; /* Adjusted gap for new options area */
    flex-grow: 1; /* Allow chat container to take remaining space */
}

/* Options Area Styling */
#options-area {
    display: flex;
    align-items: center;
    gap: 8px; /* Space between checkbox and label */
    font-size: 0.9em;
    color: var(--text-color-light);
    padding-left: 5px; /* Align slightly with input area content */
    margin-top: -5px; /* Pull it up slightly if gap from chat-container is too much */
    margin-bottom: 5px; /* Space before info-area */
}

#no-spoilers-checkbox {
    margin: 0; /* Remove default margin */
    cursor: pointer;
    width: 16px; /* Adjust size if needed */
    height: 16px; /* Adjust size if needed */
}

#options-area label {
    cursor: pointer;
}

/* Messages Area */
#messages {
    /* Removed border */
    background-color: var(--secondary-color);
    height: 500px; /* Slightly taller */
    overflow-y: auto;
    padding: 20px; /* Increased padding */
    margin-bottom: 20px;
    border-radius: 10px; /* Softer corners */
    display: flex;
    flex-direction: column;
    gap: 15px; /* Increased gap between messages */
    box-shadow: none; /* Removed inner shadow */
}

/* Message Row */
.message-row {
    padding: 12px 18px; /* Increased padding */
    border-radius: 18px; /* More rounded bubble shape */
    max-width: 75%; /* Slightly narrower for better flow */
    word-wrap: break-word;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); /* More subtle shadow on bubbles */
}

/* User Message */
.user-message {
    background-color: var(--user-message-bg);
    align-self: flex-end;
    text-align: right;
    color: var(--primary-color);
    border-bottom-right-radius: 4px; /* Pointed corner for user */
}

/* AI Message */
.ai-message {
    background-color: var(--ai-message-bg);
    align-self: flex-start;
    text-align: left;
    color: var(--text-color-dark);
    border-bottom-left-radius: 4px; /* Pointed corner for AI **/
}

/* Status Message */
.status-message {
    font-style: italic;
    color: var(--text-color-light);
    font-size: 0.95em; /* Slightly larger */
    text-align: center;
    padding: 8px; /* Increased padding */
}

/* Error Message */
.error-message {
    color: var(--error-color);
    font-weight: bold;
    text-align: center;
    padding: 8px;
}

/* Input Area */
#input-area {
    display: flex;
    gap: 15px; /* Increased gap */
    margin-bottom: 20px;
}

/* Question Input */
#question-input {
    flex-grow: 1;
    padding: 14px; /* Increased padding */
    /* Removed border */
    border-radius: 8px; /* Softer corners */
    font-size: 1.05em; /* Slightly larger font */
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05); /* Subtle inner shadow */
}

#question-input:focus {
    border-color: var(--focus-color);
    box-shadow: 0 0 0 0.3rem rgba(56, 178, 172, 0.3); /* Using new focus color */
}

/* Send Button */
#send-button {
    padding: 14px 30px; /* Increased padding */
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px; /* Softer corners */
    cursor: pointer;
    font-size: 1.05em; /* Slightly larger font */
    font-weight: 700; /* Bolder text */
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
}

#send-button:hover:not(:disabled) {
    background-color: var(--button-hover-color); /* Darker teal on hover */
    transform: translateY(-2px); /* More pronounced lift */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); /* More subtle shadow on hover */
}

#send-button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: none;
}

#send-button:disabled {
    background-color: var(--border-color); /* Lighter disabled color */
    cursor: not-allowed;
}

/* Info Area */
#info-area {
    font-size: 0.9em; /* Slightly larger */
    color: var(--text-color-light);
    /* Removed border-top */
    padding-top: 10px; /* Adjusted padding if options-area adds space */
    margin-top: 0; /* Adjusted margin if options-area adds space */
}

/* Sources List */
#sources-list {
    margin-top: 8px; /* Increased margin */
    max-height: 120px; /* Slightly taller */
    overflow-y: auto;
    /* Removed border */
    padding: 10px; /* Increased padding */
    border-radius: 6px; /* Softer corners */
    background-color: #fcfcfc; /* Lighter background */
    display: none; /* Hidden by default, show with JS */
    box-shadow: none; /* Removed inner shadow */
}

#sources-list a {
    color: var(--primary-color); /* Brighter blue for links */
    text-decoration: none;
}

#sources-list a:hover {
    text-decoration: underline;
}

/* Markdown Styles */
.message-row h1,
.message-row h2,
.message-row h3 {
    font-weight: 700; /* Bolder headings */
    margin: 12px 0 6px 0; /* Adjusted margins */
    color: var(--text-color-dark);
}

.message-row h1 {
    font-size: 1.5em; /* Larger heading */
}

.message-row h2 {
    font-size: 1.3em;
}

.message-row h3 {
    font-size: 1.2em;
}

.message-row p {
    margin: 4px 0; /* Adjusted margins */
    line-height: 1.4; /* Reduced line height for condensation */
}

.message-row ul,
.message-row ol {
    padding-left: 25px; /* Increased padding */
    margin: 6px 0;
}

.message-row li {
    margin-bottom: 2px; /* Reduced margin for condensation */
}

.message-row table {
    border-collapse: collapse;
    width: 100%;
    margin: 15px 0; /* Increased margin */
    font-size: 0.95em; /* Slightly larger font */
    box-shadow: none; /* Removed shadow on tables */
}

.message-row th,
.message-row td {
    border: none; /* Removed border */
    padding: 10px; /* Increased padding */
    text-align: left;
}

.message-row th {
    background-color: var(--header-bg-color); /* Lighter background for headers */
    font-weight: 700; /* Bolder headers */
    color: var(--text-color-dark); /* Darker text for headers */
}

/* User vs AI specific styles */
.user-message table th {
    background-color: rgba(108, 99, 255, 0.1); /* Primary color with transparency */
}

.ai-message table th {
    background-color: rgba(127, 140, 141, 0.1); /* Text color light with transparency */
}

/* Styles for the AI message bubble when it's showing a status update */
.ai-message.ai-message-status {
    font-style: italic;
    color: var(--text-color-light);
    align-items: center;
    justify-content: flex-start;
}

/* Code blocks */
.message-row pre {
    background-color: var(--code-bg-color); /* Slightly darker background */
    border-radius: 6px; /* Softer corners */
    padding: 15px; /* Increased padding */
    overflow-x: auto;
    margin: 15px 0; /* Increased margin */
    box-shadow: none; /* Removed inner shadow */
}

.message-row code {
    font-family: 'Fira Code', 'Consolas', Monaco, 'Andale Mono', monospace; /* More modern monospace font */
    font-size: 0.95em; /* Slightly larger font for code */
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    body {
        padding: 15px;
        align-items: stretch; /* Allow chat container to take full width */
    }

    #chat-container {
        max-width: 100%;
        padding: 20px;
        border-radius: 0;
        box-shadow: none;
        gap: 12px; /* Adjust gap for mobile */
    }

    #options-area {
        padding-left: 0; /* Full width on mobile */
        margin-top: 0;
        margin-bottom: 10px;
    }

    h1 {
        font-size: 2em; /* Smaller title on mobile */
        margin-bottom: 20px;
    }

    #messages {
        height: 400px; /* Shorter message area */
        padding: 15px;
        gap: 10px;
    }

    .message-row {
        max-width: 90%; /* Wider message bubbles */
        padding: 10px 15px;
    }

    #input-area {
        flex-direction: column; /* Stack input and button vertically */
        gap: 10px;
    }

    #question-input {
        width: 100%; /* Full width for input */
        font-size: 1em;
        padding: 12px;
        box-sizing: border-box; /* Ensure padding is included in width */
    }

    #send-button {
        width: 100%; /* Full width for button */
        font-size: 1em;
        padding: 12px;
    }

    #send-button {
        padding: 12px 20px;
    }

    #info-area {
        padding-top: 15px;
        margin-top: 15px;
    }

    #sources-list {
        max-height: 100px;
        padding: 8px;
    }

    .message-row h1 {
        font-size: 1.3em;
    }

    .message-row h2 {
        font-size: 1.1em;
    }

    .message-row h3 {
        font-size: 1em;
    }

    .message-row pre {
        padding: 10px;
        margin: 10px 0;
    }

    .message-row code {
        font-size: 0.9em;
    }
}