/**
 * Markdown Styling for wAIve.online
 * Beautiful, consistent formatting for AI chat responses
 * Optimized for ChatGPT/Claude-style streaming
 */

/* ========================================
   LINKS - External link styling
   ======================================== */

.message-link {
    color: #00b4d8;
    text-decoration: none;
    border-bottom: 1px solid rgba(0, 180, 216, 0.3);
    transition: all 0.2s ease;
    padding-bottom: 1px;
}

.message-link:hover {
    color: #0077b6;
    border-bottom-color: #0077b6;
    background: rgba(0, 180, 216, 0.05);
    padding: 0 2px 1px 2px;
    margin: 0 -2px;
    border-radius: 2px;
}

.message-link:visited {
    color: #5a67d8;
    border-bottom-color: rgba(90, 103, 216, 0.3);
}

/* External link indicator */
.message-link::after {
    content: '↗';
    font-size: 0.75em;
    margin-left: 2px;
    opacity: 0.6;
}

.message-link:hover::after {
    opacity: 1;
}

/* ========================================
   CODE BLOCKS - Enhanced styling
   ======================================== */

.message-code-block {
    background: rgba(15, 15, 15, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin: 12px 0;
    overflow: hidden;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: box-shadow 0.2s ease;
}

.message-code-block:hover {
    box-shadow: 0 4px 12px rgba(0, 180, 216, 0.15);
}

.message-code-header {
    background: rgba(0, 180, 216, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.message-code-language {
    color: #00b4d8;
    font-size: 0.85em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: 'SF Mono', 'Consolas', 'Monaco', 'Courier New', monospace;
}

.message-code-actions {
    display: flex;
    gap: 8px;
}

.message-copy-code {
    background: rgba(0, 180, 216, 0.2);
    border: 1px solid rgba(0, 180, 216, 0.3);
    color: #00b4d8;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8em;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.message-copy-code:hover {
    background: rgba(0, 180, 216, 0.3);
    border-color: #00b4d8;
    transform: translateY(-1px);
}

.message-copy-code:active {
    transform: translateY(0);
}

.message-code-pre {
    margin: 0;
    padding: 16px;
    overflow-x: auto;
    background: rgba(0, 0, 0, 0.3);
}

.message-code {
    font-family: 'SF Mono', 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 1.5;
    color: #e0e0e0;
    display: block;
}

/* Scrollbar styling for code blocks */
.message-code-pre::-webkit-scrollbar {
    height: 8px;
}

.message-code-pre::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

.message-code-pre::-webkit-scrollbar-thumb {
    background: rgba(0, 180, 216, 0.3);
    border-radius: 4px;
}

.message-code-pre::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 180, 216, 0.5);
}

/* ========================================
   INLINE CODE
   ======================================== */

.message-inline-code {
    background: rgba(0, 180, 216, 0.15);
    border: 1px solid rgba(0, 180, 216, 0.25);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'SF Mono', 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
    color: #00d4ff;
    font-weight: 500;
}

/* ========================================
   HEADERS
   ======================================== */

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    color: var(--text-primary);
    font-weight: 600;
    margin: 16px 0 8px 0;
    line-height: 1.3;
}

.message-content h1 {
    font-size: 1.5em;
    border-bottom: 2px solid rgba(0, 180, 216, 0.3);
    padding-bottom: 8px;
}

.message-content h2 {
    font-size: 1.3em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 6px;
}

.message-content h3 {
    font-size: 1.1em;
}

.message-content h4 {
    font-size: 1.05em;
}

.message-content h5,
.message-content h6 {
    font-size: 1em;
    opacity: 0.9;
}

/* ========================================
   LISTS
   ======================================== */

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

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

.message-content li::marker {
    color: #00b4d8;
}

/* Nested lists */
.message-content ul ul,
.message-content ol ol,
.message-content ul ol,
.message-content ol ul {
    margin: 2px 0;
}

/* Task lists (GFM) */
.message-content input[type="checkbox"] {
    margin-right: 8px;
    accent-color: #00b4d8;
}

/* ========================================
   BLOCKQUOTES
   ======================================== */

.message-content blockquote {
    border-left: 3px solid #00b4d8;
    padding-left: 16px;
    margin: 12px 0;
    color: rgba(255, 255, 255, 0.8);
    font-style: italic;
    background: rgba(0, 180, 216, 0.05);
    padding: 12px 16px;
    border-radius: 0 4px 4px 0;
}

.message-content blockquote p {
    margin: 0;
}

/* ========================================
   HORIZONTAL RULES
   ======================================== */

.message-content hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin: 16px 0;
}

/* ========================================
   TABLES
   ======================================== */

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.message-content thead {
    background: rgba(0, 180, 216, 0.2);
}

.message-content th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid rgba(0, 180, 216, 0.4);
    color: var(--text-primary);
}

.message-content td {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.message-content tbody tr:last-child td {
    border-bottom: none;
}

.message-content tr:hover {
    background: rgba(0, 180, 216, 0.05);
}

/* Alternating row colors for better readability */
.message-content tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.1);
}

.message-content tbody tr:nth-child(even):hover {
    background: rgba(0, 180, 216, 0.08);
}

/* ========================================
   TEXT FORMATTING
   ======================================== */

.message-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.message-content em {
    font-style: italic;
    color: rgba(255, 255, 255, 0.9);
}

/* Strikethrough (GFM) */
.message-content del {
    text-decoration: line-through;
    opacity: 0.6;
}

/* Bold + Italic combination */
.message-content strong em,
.message-content em strong {
    font-weight: 600;
    font-style: italic;
}

/* ========================================
   PARAGRAPHS
   ======================================== */

.message-content p {
    margin: 8px 0;
    line-height: 1.6;
}

.message-content p:first-child {
    margin-top: 0;
}

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

/* ========================================
   IMAGES
   ======================================== */

.message-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 8px 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    loading: lazy;
}

/* ========================================
   STREAMING EFFECTS
   ======================================== */

/* Blinking cursor during streaming */
@keyframes blink-cursor {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.message-content.streaming::after {
    content: '▋';
    color: #00b4d8;
    animation: blink-cursor 1s infinite;
    margin-left: 2px;
}

/* Fade-in animation for new messages */
@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.ai {
    animation: fade-in 0.3s ease;
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
   ======================================== */

/* GPU acceleration for smooth animations */
.message.ai,
.message-content,
.message-link,
.message-copy-code {
    will-change: transform;
    transform: translateZ(0);
}

/* Contain layout shifts */
.message-code-block {
    contain: layout style paint;
}

/* Optimize rendering */
.message-content {
    contain: content;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
    /* Smaller code blocks on mobile */
    .message-code-pre {
        padding: 12px;
        font-size: 0.85em;
    }

    /* Adjust table font size */
    .message-content table {
        font-size: 0.9em;
    }

    /* Smaller headers on mobile */
    .message-content h1 {
        font-size: 1.3em;
    }

    .message-content h2 {
        font-size: 1.2em;
    }

    .message-content h3 {
        font-size: 1.05em;
    }

    /* Better code block scrolling on mobile */
    .message-code-pre {
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

/* Focus styles for keyboard navigation */
.message-link:focus,
.message-copy-code:focus {
    outline: 2px solid #00b4d8;
    outline-offset: 2px;
}

/* High contrast for better readability */
@media (prefers-contrast: high) {
    .message-link {
        border-bottom-width: 2px;
    }

    .message-code-block {
        border-width: 2px;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .message.ai,
    .message-link,
    .message-copy-code {
        animation: none;
        transition: none;
    }

    .message-content.streaming::after {
        animation: none;
        opacity: 1;
    }
}
