/* =========================================
   MODERN CHAT MESSAGE STYLING (OVERHAUL)
   ========================================= */

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
}

/* User Message specific styles */
.user-message {
    align-self: flex-end;
    background: var(--primary-gradient, linear-gradient(135deg, #007aff, #0056b3));
    color: white;
    border-bottom-right-radius: 0.25rem;
    box-shadow: var(--shadow-md, 0 4px 15px rgba(0, 122, 255, 0.2));
}

.chat-message {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    font-size: 1rem;
    line-height: 1.6;
    position: relative;
    word-wrap: break-word;
    word-break: break-word;
    /* Ensure long words don't overflow */
    white-space: pre-wrap;
    /* Preserve line breaks */

    box-shadow: var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, 0.04));
    transition: transform 0.2s ease, box-shadow 0.2s ease;

    /* Animation */
    animation: fadeInSlideUp 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    opacity: 0;
    /* Start hidden */
    transform: translateY(20px);
    /* Start lower */
}

/* History Message Override - Force Visible */
.chat-message.history-message {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
}

/* Modern Link Styling (Container/Chip Style) */
.chat-message a {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 2px 10px;
    margin: 0 2px;
    border-radius: 12px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;

    /* Default (AI/System) */
    background: rgba(0, 122, 255, 0.08);
    color: #007aff;
    border: 1px solid rgba(0, 122, 255, 0.15);
}

.chat-message a:hover {
    background: rgba(0, 122, 255, 0.15);
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0, 122, 255, 0.15);
    text-decoration: none;
}

/* User Message Link Overrides */
.user-message a {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.25);
    box-shadow: none;
}

.user-message a:hover {
    background: rgba(255, 255, 255, 0.25);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Dark Theme Overrides for AI Messages */
body.dark-theme .chat-message a {
    background: rgba(64, 169, 255, 0.15);
    color: #40a9ff;
    border-color: rgba(64, 169, 255, 0.25);
}

body.dark-theme .chat-message a:hover {
    background: rgba(64, 169, 255, 0.25);
    box-shadow: 0 2px 8px rgba(64, 169, 255, 0.2);
}

/* AI/System Message specific styles */
.ai-message,
.system-message {
    align-self: flex-start;
    background: white;
    color: #1f2937;
    border-bottom-left-radius: 0.25rem;
    /* Distinctive shape */
    border: 1px solid rgba(0, 0, 0, 0.05);
}

body.dark-theme .ai-message,
body.dark-theme .system-message {
    background: #2a2a2a;
    color: #e5e5e5;
    border-color: rgba(255, 255, 255, 0.1);
}

/* Consecutive messages styling */
.chat-message.consecutive {
    margin-top: -1rem;
    /* Pull closer */
    border-radius: 1.25rem;
    /* Reset corner */
}

.user-message.consecutive {
    border-top-right-radius: 0.25rem;
}

.ai-message.consecutive {
    border-top-left-radius: 0.25rem;
}

/* MARKDOWN CONTENT STYLING */
.chat-message p {
    margin-bottom: 0.75rem;
}

.chat-message p:last-child {
    margin-bottom: 0;
}

/* Code Blocks */
.chat-message pre {
    background: #1e1e1e;
    /* Atom One Dark background */
    border-radius: 0.75rem;
    padding: 1rem;
    margin: 0.75rem 0;
    overflow-x: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

.chat-message code {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.9em;
}

/* Inline Code */
.chat-message :not(pre)>code {
    background: rgba(0, 0, 0, 0.08);
    color: #d63384;
    /* Pinkish for code */
    padding: 0.2em 0.4em;
    border-radius: 0.3em;
    font-size: 0.85em;
}

body.dark-theme .chat-message :not(pre)>code {
    background: rgba(255, 255, 255, 0.1);
    color: #ff79c6;
}

.user-message :not(pre)>code {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* Lists */
.chat-message ul,
.chat-message ol {
    margin: 0.5rem 0 0.75rem 1.5rem;
}

.chat-message li {
    margin-bottom: 0.25rem;
}

/* Blockquotes */
.chat-message blockquote {
    border-left: 4px solid #e5e7eb;
    margin: 0.75rem 0;
    padding-left: 1rem;
    font-style: italic;
    color: #6b7280;
}

body.dark-theme .chat-message blockquote {
    border-left-color: #4b5563;
    color: #9ca3af;
}

.user-message blockquote {
    border-left-color: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.8);
}

/* Tables */
.chat-message table {
    border-collapse: collapse;
    width: 100%;
    margin: 1rem 0;
    font-size: 0.9rem;
}

.chat-message th,
.chat-message td {
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 0.75rem;
    text-align: left;
}

.chat-message th {
    background: rgba(0, 0, 0, 0.03);
    font-weight: 600;
}

body.dark-theme .chat-message th,
body.dark-theme .chat-message td {
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark-theme .chat-message th {
    background: rgba(255, 255, 255, 0.05);
}

.user-message table,
.user-message th,
.user-message td {
    border-color: rgba(255, 255, 255, 0.2);
}

.user-message th {
    background: rgba(255, 255, 255, 0.1);
}

/* Headings within messages */
.chat-message h1,
.chat-message h2,
.chat-message h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
    line-height: 1.3;
}

.chat-message h1:first-child,
.chat-message h2:first-child,
.chat-message h3:first-child {
    margin-top: 0;
}

.chat-message h1 {
    font-size: 1.5rem;
}

.chat-message h2 {
    font-size: 1.3rem;
}


/* Deepfake Analysis Bar */
.deepfake-result-card {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    padding: 10px;
    /* Reduced from 15px */
    margin-top: 8px;
    /* Reduced from 10px */
    border: 1px solid rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

body.dark-theme .deepfake-result-card {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

.deepfake-bar-container {
    margin-bottom: 8px;
    /* Reduced from 12px */
}

.deepfake-label-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    /* Reduced from 0.9rem */
    font-weight: 600;
    margin-bottom: 3px;
    /* Reduced from 5px */
}

.deepfake-bar-bg {
    height: 6px;
    /* Reduced from 10px */
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

body.dark-theme .deepfake-bar-bg {
    background: rgba(255, 255, 255, 0.1);
}

.deepfake-bar-fill {
    height: 100%;
    border-radius: 3px;
    width: 0%;
    transition: width 1s ease-out;
}

.deepfake-real .deepfake-bar-fill {
    background: linear-gradient(90deg, #28a745, #20c997);
}

.deepfake-fake .deepfake-bar-fill {
    background: linear-gradient(90deg, #dc3545, #f86754);
}

.deepfake-verdict {
    margin-top: 10px;
    /* Reduced from 15px */
    font-weight: 700;
    text-align: center;
    font-size: 0.95rem;
    /* Reduced from 1.1rem */
    padding-top: 8px;
    /* Reduced from 10px */
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

body.dark-theme .deepfake-verdict {
    border-top-color: rgba(255, 255, 255, 0.1);
}