/**
 * Lampira AI - Chat Component
 * Messages, content styling, sources, and follow-up suggestions
 */

/* ============ Message Container ============ */
.message-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: 100%;
    max-width: 720px;
    flex: 1;
    padding-bottom: 20px;
}

/* ============ Messages ============ */
.message {
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease;
}

.message.animate-in {
    animation: slideIn 0.3s ease;
}

/* User messages aligned to right */
.message-user {
    flex-direction: row-reverse;
    align-self: flex-end;
    max-width: 80%;
}

.message-user .message-wrapper {
    text-align: right;
}

.message-user .message-content {
    background: #f5f5f4;
    padding: 12px 16px;
    border-radius: 16px 16px 4px 16px;
    display: inline-block;
    text-align: left;
}

/* Assistant messages aligned to left */
.message-assistant {
    align-self: flex-start;
    max-width: 90%;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============ Message Avatar ============ */
.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #f5f5f4;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-avatar svg {
    width: 18px;
    height: 18px;
    color: #57534e;
}

.message-assistant .message-avatar {
    background: #111111;
}

.message-assistant .message-avatar svg {
    color: #ffffff;
}

.message-wrapper {
    flex: 1;
    min-width: 0;
}

.message-role {
    font-size: 13px;
    font-weight: 600;
    color: #111111;
    margin-bottom: 4px;
}

.message-content {
    font-size: 15px;
    line-height: 1.6;
    color: #44403c;
}

/* ============ Message Actions ============ */
.message-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message:hover .message-actions {
    opacity: 1;
}

.message-action-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border: none;
    border-radius: 6px;
    background: #f5f5f4;
    color: #57534e;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.message-action-btn:hover {
    background: #e7e5e4;
    color: #292524;
}

.message-action-btn.copied {
    background: #dcfce7;
    color: #166534;
}

.message-action-btn svg {
    flex-shrink: 0;
}

/* ============ Message Images ============ */
.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    object-fit: cover;
    border: 1px solid #e7e5e4;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.message-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ============ Message PDFs ============ */
.message-pdfs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.message-pdf {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    max-width: 200px;
}

.message-pdf .pdf-icon {
    width: 20px;
    height: 20px;
    color: #dc2626;
    flex-shrink: 0;
}

.message-pdf .pdf-filename {
    font-size: 12px;
    color: #991b1b;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============ Message Content Typography ============ */
.message-content p {
    margin-bottom: 12px;
}

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

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 16px 0 8px;
    color: #111111;
}

.message-content h1 {
    font-size: 24px;
}

.message-content h2 {
    font-size: 20px;
}

.message-content h3 {
    font-size: 18px;
}

.message-content h4 {
    font-size: 16px;
}

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

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

.message-content code.inline-code {
    background: #f5f5f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 13px;
}

.message-content pre {
    background: #0d1117;
    color: #e6edf3;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid #30363d;
    position: relative;
}

.message-content pre code {
    font-family: 'Fira Code', monospace;
    font-size: 13px;
    line-height: 1.5;
    background: transparent;
    padding: 0;
}

/* Override highlight.js background to match our theme */
.message-content pre code.hljs {
    background: transparent;
    padding: 0;
}

.message-content blockquote {
    border-left: 3px solid #e7e5e4;
    padding-left: 16px;
    margin: 12px 0;
    color: #57534e;
    font-style: italic;
}

.message-content a {
    color: #2563eb;
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content hr {
    border: none;
    border-top: 1px solid #e7e5e4;
    margin: 16px 0;
}

/* ============ Code Copy Button ============ */
.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #8b949e;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 10;
}

.message-content pre:hover .code-copy-btn {
    opacity: 1;
}

.code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #e6edf3;
}

.code-copy-btn.copied {
    background: #238636;
    border-color: #238636;
    color: #ffffff;
}

.code-copy-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* ============ Processing/Thinking Indicators ============ */
.thinking-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #78716c;
    font-size: 14px;
}

.thinking-indicator .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e7e5e4;
    border-top-color: #8b7355;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.processing-indicator {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 0;
    width: 100%;
    max-width: 300px;
}

.processing-indicator .shimmer-line {
    height: 12px;
    background: linear-gradient(90deg, #e8e7e5 25%, #f5f4f2 50%, #e8e7e5 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

.processing-indicator .shimmer-line:nth-child(1) {
    width: 100%;
}

.processing-indicator .shimmer-line:nth-child(2) {
    width: 85%;
}

.processing-indicator .shimmer-line:nth-child(3) {
    width: 70%;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Streaming message state */
.message.streaming .message-content {
    color: #44403c;
}

.message.processing .message-avatar {
    animation: pulse-avatar 2s infinite;
}

@keyframes pulse-avatar {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

/* ============ Sources / Citations ============ */
.message-sources {
    margin-top: 16px;
    border-top: 1px solid #e5e5e5;
    padding-top: 16px;
}

.sources-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #666;
    margin-bottom: 12px;
    cursor: pointer;
    user-select: none;
    padding: 8px 12px;
    margin: -8px -12px 12px -12px;
    border-radius: 8px;
    transition: background-color 0.15s ease;
}

.sources-header:hover {
    background-color: #f5f5f5;
}

.sources-header svg.sources-icon {
    color: #999;
}

.sources-chevron {
    margin-left: auto;
    color: #999;
    transition: transform 0.2s ease;
}

.message-sources.collapsed .sources-chevron {
    transform: rotate(-90deg);
}

.message-sources.collapsed .sources-header {
    margin-bottom: 0;
}

.sources-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    max-height: 500px;
    opacity: 1;
}

.message-sources.collapsed .sources-list {
    max-height: 0;
    opacity: 0;
    margin: 0;
}

.sources-count {
    background: #f0f0f0;
    color: #666;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.source-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #f8f8f8;
    border: 1px solid #e5e5e5;
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
    max-width: 280px;
    flex: 0 1 auto;
}

.source-card:hover {
    background: #f0f0f0;
    border-color: #ccc;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.source-number {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #111;
    color: #fff;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.source-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.source-title {
    font-size: 13px;
    font-weight: 500;
    color: #111;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.source-domain {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #888;
}

.source-favicon {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* ============ Follow-up Suggestions ============ */
.follow-up-suggestions {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e7e5e4;
}

.suggestions-header {
    font-size: 12px;
    font-weight: 600;
    color: #78716c;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.suggestions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.suggestion-chip {
    background: #f5f5f4;
    border: 1px solid #d6d3d1;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    color: #44403c;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    text-align: left;
}

.suggestion-chip:hover {
    background: #8b7355;
    border-color: #8b7355;
    color: #ffffff;
}

.suggestion-chip svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* ============ Chat Responsive ============ */
@media (max-width: 768px) {

    /* Messages full width */
    .message-container {
        max-width: 100%;
    }

    .message {
        padding: 12px;
    }

    /* Sources adjust */
    .sources-list {
        flex-direction: column;
    }

    .source-card {
        max-width: 100%;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .message-avatar {
        width: 28px;
        height: 28px;
    }
}