/* app/static/css/styles.css */

/* --- Global Styles --- */
/* Note: All CSS variables moved to /css/base/variables.css for consistency */

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

html, body { 
    height: 100%;
    font-size: 18px; /* Increased base font size for better readability */
}

body {
    font-family: var(--font-sans);
    background-color: var(--color-white);
    display: flex;
    flex-direction: column;
    color: var(--color-black);
    line-height: 1.6; /* Increased line height for better readability */
    height: 100%;
    overflow: auto; /* Allow scrolling by default */
}

/* Only prevent scrolling on chat pages */
body.chat-page {
    overflow: hidden;
}

/* Account page - lighter background */
body.account-page {
    background-color: var(--color-white);
}

body.account-page .form-container {
    background-color: var(--color-white);
}

/* Header styles moved to components/header.css */


/* Main Content & Chat Layout */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: auto; /* Allow scrolling by default */
}

/* Only prevent overflow on chat pages */
body.chat-page .main-content {
    overflow: hidden;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden; 
}

.messages-wrapper {
    flex: 1;
    background-color: var(--color-white);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.messages-header {
    padding: 1rem 2rem;
    background-color: #fafbfc;
    color: var(--color-grey);
    font-weight: 500;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    border-bottom: 1px solid #f0f1f2;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.messages-header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: fit-content;
    margin-right: 1rem;
}

.objectives-progress {
    display: flex;
    flex: 1;
    align-items: center;
    font-size: 0.8rem;
    color: var(--color-black);
    gap: 10px;
}

.objectives-progress-bar {
    position: relative;
    flex: 1;
    height: 8px;
    background-color: var(--color-light-grey);
    border-radius: 4px;
    overflow: hidden;
    margin-right: 0.5rem;
}

.objectives-progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background-color: var(--color-turquoise);
    width: 0%;
    transition: width 0.3s ease-out;
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

#objectives-count {
    min-width: 40px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-black);
    text-align: right;
}

#messages { /* Was #chatbox */
    flex: 1;
    overflow-y: auto;
    padding: 2rem 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem; /* Increased gap for better message separation */
    scroll-behavior: smooth;
}

/* Message Styling */
.message { /* Base class for all message types */
    word-wrap: break-word;
    position: relative;
    line-height: 1.6; /* Increased line height for better readability */
    border-bottom: none;
    margin-bottom: 0.5rem; /* Space for sender label */
    animation: messageSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: bottom;
}
.message p { /* Ensure paragraphs within messages have no extra margin */
    margin: 0;
}

/* Smooth message entrance animation */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(15px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}


/* Removed old message::before styling for cleaner bubble design */

.user-msg { /* Was .user-message */
    color: var(--color-black);
    font-size: 1rem;
    font-weight: 400;
    max-width: 70%; /* Unified width for better mobile efficiency */
    margin-left: auto; /* Align to right */
    background-color: var(--color-white);
    padding: 1rem 1.5rem; /* Unified padding */
    border-radius: 20px 20px 4px 20px; /* Rounded with small corner indicating sender */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); /* Unified shadow */
    border-left: 2px solid var(--color-western-purple); /* Subtle accent for consistency */
}

.user-msg::before {
    content: "You";
    position: absolute;
    font-size: 0.7rem;
    top: -1.35rem; /* Optimized spacing */
    right: 0;
    opacity: 0.6;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-western-purple);
}

.agent-msg { /* Was .agent-message */
    color: var(--color-black);
    font-size: 1rem;
    letter-spacing: 0.01em;
    text-align: left;
    font-weight: 400;
    max-width: 70%; /* Unified width for better mobile efficiency */
    margin-right: auto; /* Align to left */
    background-color: #fafbfc; /* Subtle background differentiation */
    padding: 1rem 1.5rem; /* Unified padding */
    border-radius: 20px 20px 20px 4px; /* Rounded with small corner indicating sender */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); /* Unified shadow */
    border-left: 2px solid var(--color-ivey-green); /* Subtle accent for consistency */
}
.agent-msg::before {
    content: "Sidekick";
    position: absolute;
    font-size: 0.7rem;
    top: -1.35rem; /* Optimized spacing */
    left: 0;
    opacity: 0.6;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-ivey-green);
}
.agent-msg p { /* From new CSS */
    margin-bottom: 1.25em; /* Increased paragraph spacing */
    max-width: none; /* Allow paragraphs to use full bubble width */
}
.agent-msg p:last-child { /* From new CSS */
    margin-bottom: 0;
}


.system-msg { /* Was .event-log or .error-message */
    color: var(--color-grey);
    font-style: italic;
    text-align: center;
    padding: 0.25rem 0;
    width: 100%;
    margin: 0;
    align-self: center;
    opacity: 0.8;
    font-size: 0.9rem;
    border-bottom: none;
}
.system-msg.error { /* Specific styling for errors if needed */
    color: #dc3545; /* Red */
    font-weight: bold;
}
.system-msg::before { /* System messages don't get the top border */
    display: none;
}
.system-msg::after { /* System messages don't get sender labels */
    display: none;
}


/* Message Form Styles */
#messageForm { /* Was #inputArea */
    display: flex;
    gap: 0.75rem;
    align-items: center;
    background-color: var(--color-white);
    padding: 1.25rem 2.5rem;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.04);
    z-index: 5;
    border-top: 1px solid #f0f1f2;
}

#messageInput { /* Was #userInput */
    flex: 1;
    padding: 0.875rem 1.25rem;
    border: 2px solid var(--theme-border-primary);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: var(--font-sans);
    transition: border-color 0.3s ease;
    /* Multiline behavior for textarea */
    line-height: 1.5;
    min-height: var(--input-height); /* start at the standard input height */
    max-height: 6.75rem; /* fallback cap ~3 lines; JS will fine-tune */
    overflow-y: auto;
    resize: none; /* resizing is handled automatically */
}

#messageInput:focus {
    outline: none;
    border-color: var(--color-turquoise);
    box-shadow: 0 0 0 3px rgba(0, 151, 160, 0.2);
}

#messageInput::placeholder {
    color: var(--color-light-grey);
}

#sendButton, #continueButton, .begin-button {
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-white);
    font-size: 1rem;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
#sendButton {
    background-color: var(--color-western-purple);
}
#continueButton, .begin-button {
     background-color: var(--color-turquoise);
}

/* Hide the Continue button while preserving functionality */
#continueButton {
    display: none;
}

/* Begin button container */
.begin-button-container {
    display: none; /* Hidden by default until we know if there are messages */
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 40%;
    left: 0;
    right: 0;
    z-index: 10;
    background: rgba(255, 255, 255, 0.7);
    padding: 2rem;
}

.begin-button {
    padding: 1rem 2.5rem;
    font-size: 1.2rem;
    font-weight: 500;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
    min-width: 150px;
    transition: all 0.2s ease-in-out;
}

.begin-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}


#sendButton:hover:not(:disabled) {
    background-color: #6b3c99; /* Darker purple */
}
#continueButton:hover:not(:disabled),
.begin-button:hover {
    background-color: #007a8a; /* Darker turquoise */
}

#sendButton:active:not(:disabled),
#continueButton:active:not(:disabled),
.begin-button:active {
    transform: translateY(1px);
}

#sendButton:disabled,
#continueButton:disabled {
    background-color: var(--color-light-grey);
    cursor: not-allowed;
}

/* Loading dots for system messages like "Connecting..." */
@keyframes loadingDots {
    0%, 20% { content: "."; }
    40% { content: ".."; }
    60%, 100% { content: "..."; }
}
.system-msg.waiting::after {
    content: "";
    animation: loadingDots 1.5s infinite;
    display: inline-block;
    width: 1em; /* Adjust width to fit dots */
    text-align: left;
}

/* Toast notification styles */
/* `components/forms.css` also defines .toast/.toast-container and is co-loaded
   on chat.html and courses.html. Every property either sheet sets is therefore
   declared here in full, including the ones that would otherwise be inherited
   from it by omission: `top` (S2-20 — forms.css anchors the container to the
   top, and top+bottom on a fixed element stretch it to the viewport height) and
   `display` (forms.css uses flex for an icon+text toast; these are text-only). */
.toast-container {
    position: fixed;
    top: auto;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

.toast {
    display: block;
    background-color: #333;
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateY(20px);
    /* --theme-shadow-* are complete box-shadow values, not colours. Using one in
       the colour slot makes the declaration invalid at computed-value time,
       which resolves to `none` AFTER the cascade and so suppresses forms.css's
       shadow too (S2-19). */
    box-shadow: var(--theme-shadow-medium);
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* The palette prefix is `--color-` (base/variables.css). The unprefixed names
   these rules used are defined nowhere, so the background was dropped and the
   variants rendered transparent — .toast.info as white-on-white (S2-18). */
.toast.success { background-color: var(--color-bright-green); color: var(--color-black); }
.toast.error { background-color: var(--color-error); color: var(--color-white); }
.toast.warning { background-color: var(--color-sand); color: var(--color-black); }
.toast.info { background-color: var(--color-grey); color: var(--color-white); }


/* Responsive adjustments */
@media (max-width: 768px) {
    .header-title { font-size: 1.25rem; }
    .app-header { padding: 0.75rem 1rem; }
    #messages { padding: 1rem; }
    #messageForm { padding: 0.75rem 1rem; }
    #messageInput, #sendButton, #continueButton { padding: 0.75rem 1rem; }

    .user-msg,
    .agent-msg {
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
    }
}

@media (max-width: 480px) {
    #sendButton, #continueButton { padding: 0.75rem; }
    .message::after { font-size: 0.7rem; }
}

/* --- Markdown Content Styling (Add this to the end of the file) --- */

/* Style elements inside the agent's message bubble */
.agent-msg h1,
.agent-msg h2,
.agent-msg h3 {
    margin-top: 1em;
    margin-bottom: 0.6em;
    font-family: var(--font-serif);
    font-weight: 600;
    line-height: 1.25;
    border-bottom: 1px solid var(--theme-border-primary);
    padding-bottom: 0.3em;
}

.agent-msg h1 { font-size: 1.5em; }
.agent-msg h2 { font-size: 1.25em; }
.agent-msg h3 { font-size: 1.1em; }

/* Remove top margin for the very first element in a message */
.agent-msg > *:first-child {
    margin-top: 0;
}

.agent-msg p {
    margin-bottom: 1em; /* Add space between paragraphs */
}

/* Make sure the last paragraph in a message has no bottom margin */
.agent-msg > *:last-child {
    margin-bottom: 0;
}

.agent-msg ul,
.agent-msg ol {
    padding-left: 2em;
    margin-bottom: 1.25em; /* Consistent with paragraph spacing */
    margin-top: 0.75em; /* Add top margin for better separation */
}

.agent-msg li {
    margin-bottom: 0.5em; /* Increased for better readability */
    line-height: 1.7; /* Slightly increased line height for lists */
}

.agent-msg a {
    color: var(--color-turquoise);
    text-decoration: none;
    font-weight: 500;
}
.agent-msg a:hover {
    text-decoration: underline;
}

/* Inline code styles */
.agent-msg code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
    font-size: 0.9em;
    padding: 0.2em 0.4em;
    margin: 0;
    background-color: #f0f0f0; /* A very light grey */
    border-radius: 4px;
    color: var(--color-black);
}

/* Code block styles */
.agent-msg pre {
    padding: 1em;
    overflow: auto;
    font-size: 0.9em;
    line-height: 1.45;
    background-color: #f6f8fa; /* GitHub's code block color */
    border: 1px solid var(--theme-border-primary);
    border-radius: var(--radius-md);
    margin-bottom: 1em;
}

/* Reset inner code element styles within a pre block */
.agent-msg pre code {
    padding: 0;
    margin: 0;
    font-size: 1em; /* Inherit font-size from pre */
    background-color: transparent;
    border: 0;
}

/* Blockquote styles */
.agent-msg blockquote {
    margin: 0 0 1em 0;
    padding: 0 1em;
    color: var(--color-grey);
    border-left: 0.25em solid var(--color-ivey-green);
}
.agent-msg blockquote p {
    margin-bottom: 0;
}

/* Thinking indicator styles - unified with agent message bubbles */
.thinking-indicator {
    color: var(--color-black);
    font-size: 1rem;
    font-weight: 400;
    max-width: 70%; /* Unified width matching agent messages */
    margin-right: auto; /* Align to left */
    background-color: #fafbfc; /* Same as agent messages */
    padding: 1rem 1.5rem; /* Unified padding */
    border-radius: 20px 20px 20px 4px; /* Same as agent messages */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); /* Unified shadow */
    border-left: 2px solid var(--color-ivey-green); /* Same accent */
    position: relative;
    margin-bottom: 0.5rem; /* Space for label */
}

/* "Sidekick" label for thinking indicator */
.thinking-indicator::before {
    content: "Sidekick";
    position: absolute;
    font-size: 0.7rem;
    top: -1.35rem;
    left: 0;
    opacity: 0.6;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-ivey-green);
}

/* Modern bouncing dots animation container */
.thinking-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    margin-left: 4px;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    background-color: var(--color-ivey-green);
    border-radius: 50%;
    display: inline-block;
    animation: typingDot 1.4s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

/* Bouncing dot animation (like iMessage/Slack) */
@keyframes typingDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Scroll to bottom button */
#scrollToBottomBtn {
    position: fixed;
    bottom: 100px;
    right: 2.5rem;
    background-color: var(--color-white);
    border: 1px solid #e8eaed;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 100;
    transition: all 0.2s ease;
    color: var(--color-ivey-green);
    font-size: 1.2rem;
}

#scrollToBottomBtn:hover {
    background-color: var(--color-ivey-green);
    color: var(--color-white);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#scrollToBottomBtn.show {
    display: flex;
    animation: fadeInScale 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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