/*
 * Syntax Highlighting CSS for Code Blocks
 * Enhanced GitHub-style theme with RTL support
 */

/* Base Code Block Styling */
.hljs {
    display: block;
    overflow-x: auto;
    padding: 1.5rem !important;
    margin: 1.5rem 0 !important;
    background: #2d3748 !important;
    color: #e2e8f0 !important;
    border-radius: 8px !important;
    border: 1px solid #4a5568 !important;
    font-family: 'Consolas', 'Monaco', 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
    direction: ltr !important;
    text-align: left !important;
    position: relative;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

/* Pre tag wrapper */
pre {
    margin: 1.5rem 0 !important;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    overflow: visible !important;
}

pre code {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    font-size: inherit !important;
    color: inherit !important;
    white-space: pre !important;
    word-wrap: normal !important;
}

/* Code container with copy button */
.code-container {
    position: relative;
    margin: 1.5rem 0;
}

.code-container .hljs {
    margin: 0 !important;
}

/* Copy button styling - Small transparent icon button */
.copy-code-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(45, 55, 72, 0.7);
    color: rgba(226, 232, 240, 0.8);
    border: 1px solid rgba(113, 128, 150, 0.3);
    border-radius: 6px;
    padding: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    z-index: 15;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    opacity: 0.6;
}

.copy-code-btn:hover {
    background: rgba(113, 128, 150, 0.8);
    border-color: rgba(160, 174, 192, 0.6);
    color: rgba(255, 255, 255, 0.95);
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
}

.copy-code-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.copy-code-btn.copied {
    background: rgba(56, 161, 105, 0.8);
    border-color: rgba(104, 211, 145, 0.6);
    color: rgba(240, 255, 244, 0.95);
    opacity: 1;
}

.copy-code-btn.loading {
    pointer-events: none;
    opacity: 0.5;
}

/* Show button more clearly when parent is hovered */
.hljs:hover .copy-code-btn {
    opacity: 1;
}

/* Animations for copy button states */
.copy-code-btn svg {
    transition: all 0.2s ease;
}

.copy-code-btn:hover svg {
    transform: scale(1.1);
}

.copy-code-btn.copied svg {
    animation: checkmark 0.3s ease-in-out;
}

.copy-code-btn .loading-icon {
    animation: spin 1s linear infinite;
}

@keyframes checkmark {
    0% { transform: scale(0.8); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Language label */
.code-language {
    position: absolute;
    top: 10px;
    left: 10px;
    background: #1a202c;
    color: #a0aec0;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Syntax highlighting colors */
.hljs-comment,
.hljs-quote {
    color: #a0aec0 !important;
    font-style: italic !important;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-subst {
    color: #ff6b6b !important;
    font-weight: bold !important;
}

.hljs-number,
.hljs-literal,
.hljs-variable,
.hljs-template-variable,
.hljs-tag .hljs-attr {
    color: #4ecdc4 !important;
}

.hljs-string,
.hljs-doctag {
    color: #95e1d3 !important;
}

.hljs-title,
.hljs-section,
.hljs-selector-id {
    color: #ffd93d !important;
    font-weight: bold !important;
}

.hljs-type,
.hljs-class .hljs-title {
    color: #ffd93d !important;
}

.hljs-tag,
.hljs-name,
.hljs-attribute {
    color: #ff9f43 !important;
    font-weight: normal !important;
}

.hljs-regexp,
.hljs-link {
    color: #ff6b9d !important;
}

.hljs-symbol,
.hljs-bullet {
    color: #c44569 !important;
}

.hljs-built_in,
.hljs-builtin-name {
    color: #6c5ce7 !important;
}

.hljs-meta {
    color: #a29bfe !important;
}

.hljs-deletion {
    background: #ffeaa7 !important;
}

.hljs-addition {
    background: #55efc4 !important;
}

.hljs-emphasis {
    font-style: italic !important;
}

.hljs-strong {
    font-weight: bold !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .hljs {
        padding: 1rem !important;
        font-size: 13px !important;
        border-radius: 6px !important;
    }
    
    .copy-code-btn {
        top: 6px;
        right: 6px;
        width: 24px;
        height: 24px;
        padding: 4px;
    }
    
    .copy-code-btn svg {
        width: 14px;
        height: 14px;
    }
    
    .code-language {
        top: 6px;
        left: 6px;
        padding: 3px 6px;
        font-size: 10px;
    }
}

/* RTL Layout adjustments */
.rtl .copy-code-btn {
    right: auto;
    left: 8px;
}

.rtl .code-language {
    left: auto;
    right: 8px;
}

@media (max-width: 768px) {
    .rtl .copy-code-btn {
        left: 6px;
        right: auto;
    }
    
    .rtl .code-language {
        right: 6px;
        left: auto;
    }
}

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

.hljs::-webkit-scrollbar-track {
    background: #1a202c;
    border-radius: 4px;
}

.hljs::-webkit-scrollbar-thumb {
    background: #4a5568;
    border-radius: 4px;
}

.hljs::-webkit-scrollbar-thumb:hover {
    background: #718096;
}



/* Focus styles for accessibility */
.copy-code-btn:focus {
    outline: 2px solid #63b3ed;
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .hljs {
        background: #f7fafc !important;
        color: #2d3748 !important;
        border: 1px solid #e2e8f0 !important;
        box-shadow: none !important;
    }
    
    .copy-code-btn,
    .code-language {
        display: none !important;
    }
}
