/* static/css/style.css */

:root {
    --primary-color: #007bff;
    /* Bright Blue for buttons/accents (used for send/navbar) */
    --secondary-color: #6c757d;
    /* Gray for text/secondary elements */
    --background-color: #f8f9fa;
    /* Light body background */
    --background-color-light: #f1f0f7;
    /* Very light gray/lilac for chat area background */
    --card-background: #ffffff;
    /* White card background */
    --border-color: #e9ecef;
    /* Light border */
    --shadow-medium: 0 4px 10px rgba(0, 0, 0, 0.05);
    /* Soft shadow for depth */
    --success-color: #28a745;
    /* GREEN for New Chat Button/Success alerts */
    --danger-color: #dc3545;
    /* RED for Logout/Danger alerts */
    --text-color: #343a40;

    --chat-font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";

    --severity-mild: #166534;
    /* Deeper Green */
    --severity-moderate: #ccb90d;
    /* Deep Orange/Amber for better contrast */
    --severity-severe: #991b1b;
    /* Deeper Red */
    --severity-risk: #dc2626;
    /* Red-600 */
}

/* ---------------------------------------------------------------------------------- */
/* --- GLOBAL STYLES --- */
html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: var(--chat-font-stack);
    background-color: var(--background-color);
    color: var(--text-color);
}

* {
    box-sizing: border-box;
}

h1,
h2,
h3 {
    margin: 0;
    color: var(--text-color);
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--secondary-color);
}

.icon-btn:hover {
    background-color: var(--border-color);
}

/* Common button style for primary actions */
.btn-primary {
    /* MODIFIED: Make buttons full width */
    width: 100%;
    display: block;
    /* End MODIFIED */
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background-color: #0056b3;
    /* Darker blue */
}

/* ---------------------------------------------------------------------------------- */
/* --- AUTHENTICATION STYLES (login/signup) --- */
.auth-container {
    width: 100%;
    max-width: 400px;
    margin: 100px auto;
    padding: 30px;
    background-color: var(--card-background);
    border-radius: 10px;
    box-shadow: var(--shadow-medium);
    text-align: center;
}

.auth-container h2 {
    margin-bottom: 20px;
    color: var(--primary-color);
}

.form-group {
    margin-bottom: 15px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
}

.link-text {
    margin-top: 20px;
    font-size: 0.9rem;
    color: var(--secondary-color);
}

.link-text a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

/* Flash messages */
.message {
    padding: 10px;
    margin-bottom: 15px;
    border-radius: 5px;
    font-size: 0.9rem;
    text-align: left;
}

.alert-error,
.alert-danger {
    background-color: #f8d7da;
    color: var(--danger-color);
    border: 1px solid #f5c6cb;
}

.alert-success {
    background-color: #d4edda;
    color: var(--success-color);
    border: 1px solid #c3e6cb;
}

/* ---------------------------------------------------------------------------------- */
/* --- CHAT APPLICATION STYLES --- */
.main-body {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 280px;
    background-color: var(--card-background);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-medium);
    flex-shrink: 0;
    /* Prevents sidebar from shrinking */
}

.sidebar-header {
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.new-chat-float-btn {
    width: 38px;
    height: 38px;
    background-color: var(--success-color);
    color: white;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-chat-float-btn:hover {
    background-color: #1e7e34;
    /* Darker green */
}

.thread-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px 0;
}

.thread-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    margin: 5px 0;
    color: var(--text-color);
    text-decoration: none;
    transition: background-color 0.2s;
    border-radius: 0;
    /* Full width items */
}

.thread-item:hover {
    background-color: var(--background-color-light);
}

.thread-item.active {
    background-color: var(--primary-color);
    color: white;
}

.thread-item.active .thread-title,
.thread-item.active .thread-date {
    color: white;
}

.thread-title {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.95rem;
    font-weight: 500;
}

.thread-date {
    font-size: 0.8rem;
    color: var(--secondary-color);
    flex-shrink: 0;
    margin-left: 10px;
}

.sidebar-footer {
    padding: 15px;
    border-top: 1px solid var(--border-color);
}

.logout-sidebar-btn {
    width: 100%;
    padding: 10px;
    background-color: var(--danger-color);
    color: white;
    border: none;
    border-radius: 5px;
    text-align: center;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    transition: background-color 0.2s;
}

.logout-sidebar-btn:hover {
    background-color: #c82333;
    /* Darker red */
}

.logout-sidebar-btn svg {
    margin-right: 8px;
}

/* ---------------------------------------------------------------------------------- */
/* --- CHAT AREA STYLES --- */
.chat-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--background-color);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background-color: var(--card-background);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.chat-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.new-chat-btn {
    background-color: var(--success-color);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    font-weight: 500;
}

.new-chat-btn svg {
    margin-right: 5px;
}

.new-chat-btn:hover {
    background-color: #1e7e34;
}

.chat-history {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    background-color: var(--background-color-light);
}

.message {
    display: flex;
    margin-bottom: 15px;
    max-width: 80%;
    /* Limit message width */
}

.user-message {
    margin-left: auto;
    /* Push user message to the right */
    justify-content: flex-end;
}

.ai-message {
    margin-right: auto;
    /* Keep AI message to the left */
    justify-content: flex-start;
}

.avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    /* Prevent shrinking */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.9rem;
    text-transform: uppercase;
    flex-shrink: 0;
}

.user-avatar {
    background-color: var(--secondary-color);
    /* MODIFIED: Changed from primary to secondary color */
    color: white;
    order: 2;
    /* Move user avatar to the right side */
    margin-left: 10px;
}

.ai-avatar {
    background-color: var(--secondary-color);
    color: white;
    order: 1;
    /* Keep AI avatar on the left side */
    margin-right: 10px;
}

.message-content-wrapper {
    display: flex;
    align-items: flex-end;
    /* Align copy button to bottom of the bubble */
    order: 1;
}

.user-message .message-content-wrapper {
    order: 1;
}

.ai-message .message-content-wrapper {
    order: 2;
}

.message-bubble {
    padding: 10px 15px;
    border-radius: 18px;
    line-height: 1.4;
    max-width: 100%;
    /* Max width relative to message div (80% of chat history) */
    word-wrap: break-word;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

.user-message .message-bubble {
    background-color: var(--background-color-light);
    /* MODIFIED: Changed from primary-color (blue) to light background */
    color: var(--text-color);
    /* MODIFIED: Changed from white to dark text */
    border-bottom-right-radius: 4px;
}

.ai-message .message-bubble {
    background-color: var(--card-background);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
    text-align: left;
}

/* Markdown styling within message bubble */
.text-content p:first-child {
    margin-top: 0;
}

.text-content p:last-child {
    margin-bottom: 0;
}

.text-content pre {
    background-color: #e9e9e9;
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
    font-size: 0.85rem;
}

.text-content code {
    background-color: #e9e9e9;
    border-radius: 3px;
    padding: 2px 4px;
    font-family: monospace;
}

.text-content pre code {
    background-color: transparent;
    padding: 0;
}

/* Copy Button Styling */
.copy-message-btn {
    margin-left: 5px;
    margin-bottom: 0px;
    padding: 4px;
    background-color: transparent;
    color: var(--secondary-color);
    opacity: 0.5;
    transition: opacity 0.2s;
    border-radius: 5px;
}

.copy-message-btn:hover {
    opacity: 1;
    background-color: var(--border-color);
}

/* Image Upload Preview in Chat Bubble */
.image-bubble-wrapper {
    margin-top: 10px;
    max-width: 200px;
    /* MODIFIED: Reduced from 300px to 200px */
    overflow: hidden;
    border-radius: 10px;
}

.uploaded-img-preview-bubble {
    max-width: 100%;
    height: auto;
    display: block;
    cursor: zoom-in;
}

/* Special styling for user messages that contain ONLY an image to reduce padding/size */
.user-image-only-wrapper {
    padding: 0;
    background-color: transparent;
    border: none;
    box-shadow: none;
}


/* MODAL for Full Image View (Click-to-Enlarge) */
.image-modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.9);
    /* Black background with opacity */
    justify-content: center;
    align-items: center;
}

.modal-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90%;
    border-radius: 10px;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
}

.modal-close:hover,
.modal-close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

/* ---------------------------------------------------------------------------------- */
/* --- INPUT AREA STYLES --- */
.input-area-container {
    padding: 10px 20px;
    background-color: var(--card-background);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.file-preview-bar {
    display: flex;
    align-items: center;
    padding: 8px;
    margin-bottom: 10px;
    background-color: var(--background-color-light);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.file-preview-thumbnail {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 5px;
    margin-right: 10px;
}

.file-preview-name {
    flex-grow: 1;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 10px;
}

.remove-file-btn {
    padding: 4px;
    border-radius: 50%;
    color: var(--danger-color);
}

.remove-file-btn:hover {
    background-color: #f8d7da;
}

.input-group {
    display: flex;
    align-items: flex-end;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background-color: var(--card-background);
    padding: 5px 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.attach-btn,
.send-btn {
    flex-shrink: 0;
    color: var(--secondary-color);
    margin: 0 5px;
    padding: 8px;
}

.send-btn {
    background-color: var(--primary-color);
    color: white;
    border-radius: 50%;
}

.send-btn svg {
    width: 20px;
    height: 20px;
}

.send-btn:hover {
    background-color: #0056b3;
}

#queryInput {
    flex-grow: 1;
    border: none;
    resize: none;
    padding: 10px 5px;
    font-size: 1rem;
    outline: none;
    max-height: 200px;
    /* Limit max height of textarea */
    overflow-y: auto;
    background-color: transparent;
    line-height: 1.4;
}

/* Typing Indicator */
.typing-indicator-wrapper {
    max-width: fit-content;
}

.typing-indicator-wrapper .message-bubble {
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 38px;
    /* Maintain height to prevent jumping */
}

.dot-flashing {
    position: relative;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--secondary-color);
    color: var(--secondary-color);
    animation: dotFlashing 1s infinite alternate;
    animation-delay: 0s;
    margin: 0 3px;
}

.dot-flashing::before,
.dot-flashing::after {
    content: '';
    display: inline-block;
    position: absolute;
    top: 0;
}

.dot-flashing::before {
    left: -12px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--secondary-color);
    color: var(--secondary-color);
    animation: dotFlashing 1s infinite alternate;
    animation-delay: 0.5s;
    /* Adjusted delay for better flow */
}

.dot-flashing::after {
    left: 12px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--secondary-color);
    color: var(--secondary-color);
    animation: dotFlashing 1s infinite alternate;
    animation-delay: 1s;
}

@keyframes dotFlashing {
    0% {
        background-color: var(--secondary-color);
        opacity: 0.5;
    }

    50%,
    100% {
        background-color: var(--secondary-color);
        opacity: 1;
    }
}

/* --- Thread list row with delete --- */
.thread-item-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    margin-bottom: 6px;
    border-radius: 6px;
}

.thread-item-row.active {
    background: rgba(255, 255, 255, 0.08);
}

.thread-item-link {
    flex: 1;
    display: flex;
    justify-content: space-between;
    text-decoration: none;
    color: inherit;
}

.thread-title {
    font-weight: 600;
}

.thread-delete-btn {
    background: transparent;
    border: none;
    color: #ccc;
    cursor: pointer;
    padding: 4px;
}

.thread-delete-btn:hover {
    color: #f66;
}

/* --- Severity and Diagnostic Styling --- */
.severity-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 800;
    /* Extra bold for prominence */
    margin-top: 8px;
    color: #ffffff !important;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border: none;
    cursor: default;
    transition: transform 0.2s;
}

.severity-badge:hover {
    transform: translateY(-1px);
}

.severity-mild {
    background-color: var(--severity-mild);
}

.severity-moderate {
    background-color: var(--severity-moderate);
}

.severity-severe,
.severity-risk {
    background-color: var(--severity-risk);
}

.diagnosis-probability {
    font-size: 0.9rem;
    color: var(--secondary-color);
    font-style: italic;
    margin-left: 8px;
}

.diagnosis-card {
    background-color: #ffffff;
    border: 1px solid #dee2e6;
    border-left: 6px solid var(--primary-color);
    padding: 24px;
    margin: 20px 0;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    position: relative;
}

.diagnosis-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 6px;
    height: 100%;
    background: var(--primary-color);
    border-top-left-radius: 16px;
    border-bottom-left-radius: 16px;
}

.diagnosis-section-title {
    display: block;
    font-weight: 800;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--primary-color);
    margin-top: 12px;
    margin-bottom: 8px;
    line-height: 1.2;
}

.diagnosis-section-title:first-child {
    margin-top: 0;
}

.severe-warning {
    background-color: #fff3f3;
    border: 1px solid #ffcdd2;
    color: #c62828;
    padding: 12px;
    border-radius: 8px;
    margin-top: 10px;
    font-weight: 600;
}