/**
 * Multi-Platform GitHub Code Block Styles
 * Version: 1.2.6 (synchronized across all platforms)
 * 
 * Unified styling for GitHub code blocks across:
 * - Scroll Viewport
 * - Scroll Sites
 * - Refined.com
 * - Confluence
 */

/* === Base GitHub Code Block Styles === */

.github-code-block {
    margin: 16px 0;
    border: 1px solid #d1d9e0;
    border-radius: 8px;
    background: #ffffff;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 14px;
    line-height: 1.45;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    position: relative;
}

.github-code-block:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    border-color: #c1c8cd;
}

/* === Platform-Specific Base Styles === */

.github-code-block-scroll-viewport {
    /* Scroll Viewport specific adjustments */
}

.github-code-block-scroll-sites {
    /* Scroll Sites specific adjustments */
}

.github-code-block-refined {
    /* Refined.com specific adjustments */
}

.github-code-block-confluence {
    /* Confluence specific adjustments */
    margin: 12px 0;
    box-shadow: none;
    border-color: #dfe1e6;
}

/* === Loading State === */

.github-code-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #f8f9fa;
    color: #656d76;
    min-height: 80px;
    font-size: 13px;
}

.github-code-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e1e4e8;
    border-top: 2px solid #0969da;
    border-radius: 50%;
    animation: github-code-spin 1s linear infinite;
    margin-right: 12px;
    flex-shrink: 0;
}

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

/* === Header Styles === */

.github-code-header,
.github-code-header-refined {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #f6f8fa;
    border-bottom: 1px solid #d1d9e0;
    font-size: 13px;
    color: #656d76;
    min-height: 44px;
    box-sizing: border-box;
}

.github-code-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0; /* Allow text truncation */
}

.github-code-filename {
    font-weight: 600;
    color: #1f2328;
    font-family: inherit;
    word-break: break-all;
    flex-shrink: 1;
}

.github-code-language {
    background: #0969da;
    color: #ffffff;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    flex-shrink: 0;
}

.github-code-lines {
    background: #6f7782;
    color: #ffffff;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}

.github-code-link {
    display: flex;
    align-items: center;
    color: #656d76;
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
}

.github-code-link:hover {
    background-color: #ffffff;
    color: #0969da;
    text-decoration: none;
}

.github-code-link:focus {
    outline: 2px solid #0969da;
    outline-offset: 2px;
}

/* === Content Styles === */

.github-code-content,
.github-code-content-refined {
    position: relative;
    overflow: auto;
    max-height: 500px;
    background: #ffffff;
}

.github-code-content pre,
.github-code-content-refined pre {
    margin: 0;
    padding: 16px;
    background: transparent;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    overflow: visible;
    white-space: pre;
    word-wrap: normal;
}

.github-code-content code,
.github-code-content-refined code {
    background: transparent !important;
    padding: 0 !important;
    border-radius: 0 !important;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    white-space: pre;
    word-wrap: normal;
}

/* === Scrollbar Styling === */

.github-code-content::-webkit-scrollbar,
.github-code-content-refined::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.github-code-content::-webkit-scrollbar-track,
.github-code-content-refined::-webkit-scrollbar-track {
    background: #f1f3f4;
}

.github-code-content::-webkit-scrollbar-thumb,
.github-code-content-refined::-webkit-scrollbar-thumb {
    background: #c1c8cd;
    border-radius: 4px;
}

.github-code-content::-webkit-scrollbar-thumb:hover,
.github-code-content-refined::-webkit-scrollbar-thumb:hover {
    background: #a8b2ba;
}

/* Firefox scrollbar */
.github-code-content,
.github-code-content-refined {
    scrollbar-width: thin;
    scrollbar-color: #c1c8cd #f1f3f4;
}

/* === Error State === */

.github-code-error,
.github-code-error-refined {
    padding: 16px;
    background: #fff8f0;
    border: 1px solid #f4c97a;
    border-radius: 8px;
    margin: 16px 0;
}

.github-code-error-header {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
}

.github-code-error-title {
    font-weight: 600;
    color: #d1242f;
    font-size: 14px;
}

.github-code-error-content {
    font-size: 13px;
    color: #656d76;
    line-height: 1.5;
}

.github-code-error-content p {
    margin: 8px 0;
}

.github-code-error-content a {
    color: #0969da;
    text-decoration: none;
}

.github-code-error-content a:hover {
    text-decoration: underline;
}

/* === Theme Variations === */

/* Light Theme (Default) */
.github-code-block.theme-light,
.github-code-block:not([class*="theme-"]) {
    background: #ffffff;
    border-color: #d1d9e0;
}

.github-code-block.theme-light .github-code-header,
.github-code-block.theme-light .github-code-header-refined,
.github-code-block:not([class*="theme-"]) .github-code-header,
.github-code-block:not([class*="theme-"]) .github-code-header-refined {
    background: #f6f8fa;
    border-bottom-color: #d1d9e0;
}

/* Dark Theme */
.github-code-block.theme-dark {
    background: #0d1117;
    border-color: #30363d;
}

.github-code-block.theme-dark .github-code-header,
.github-code-block.theme-dark .github-code-header-refined {
    background: #161b22;
    border-bottom-color: #30363d;
    color: #8b949e;
}

.github-code-block.theme-dark .github-code-content,
.github-code-block.theme-dark .github-code-content-refined {
    background: #0d1117;
}

.github-code-block.theme-dark .github-code-filename {
    color: #f0f6fc;
}

.github-code-block.theme-dark .github-code-link {
    color: #8b949e;
}

.github-code-block.theme-dark .github-code-link:hover {
    background-color: #21262d;
    color: #58a6ff;
}

.github-code-block.theme-dark .github-code-content::-webkit-scrollbar-track,
.github-code-block.theme-dark .github-code-content-refined::-webkit-scrollbar-track {
    background: #161b22;
}

.github-code-block.theme-dark .github-code-content::-webkit-scrollbar-thumb,
.github-code-block.theme-dark .github-code-content-refined::-webkit-scrollbar-thumb {
    background: #484f58;
}

.github-code-block.theme-dark .github-code-content::-webkit-scrollbar-thumb:hover,
.github-code-block.theme-dark .github-code-content-refined::-webkit-scrollbar-thumb:hover {
    background: #6e7681;
}

/* Monokai Theme */
.github-code-block.theme-monokai {
    background: #272822;
    border-color: #3e3d32;
}

.github-code-block.theme-monokai .github-code-header,
.github-code-block.theme-monokai .github-code-header-refined {
    background: #2f2f23;
    border-bottom-color: #3e3d32;
    color: #f8f8f2;
}

.github-code-block.theme-monokai .github-code-content,
.github-code-block.theme-monokai .github-code-content-refined {
    background: #272822;
}

.github-code-block.theme-monokai .github-code-filename {
    color: #f92672;
}

.github-code-block.theme-monokai .github-code-language {
    background: #a6e22e;
    color: #272822;
}

/* Darcula Theme */
.github-code-block.theme-darcula {
    background: #282a36;
    border-color: #44475a;
}

.github-code-block.theme-darcula .github-code-header,
.github-code-block.theme-darcula .github-code-header-refined {
    background: #44475a;
    border-bottom-color: #6272a4;
    color: #f8f8f2;
}

.github-code-block.theme-darcula .github-code-content,
.github-code-block.theme-darcula .github-code-content-refined {
    background: #282a36;
}

.github-code-block.theme-darcula .github-code-filename {
    color: #50fa7b;
}

.github-code-block.theme-darcula .github-code-language {
    background: #bd93f9;
    color: #282a36;
}

/* VS2015 Theme */
.github-code-block.theme-vs2015 {
    background: #1e1e1e;
    border-color: #3c3c3c;
}

.github-code-block.theme-vs2015 .github-code-header,
.github-code-block.theme-vs2015 .github-code-header-refined {
    background: #2d2d30;
    border-bottom-color: #3c3c3c;
    color: #cccccc;
}

.github-code-block.theme-vs2015 .github-code-content,
.github-code-block.theme-vs2015 .github-code-content-refined {
    background: #1e1e1e;
}

.github-code-block.theme-vs2015 .github-code-filename {
    color: #569cd6;
}

/* === Platform-Specific Adjustments === */

/* Confluence specific styles */
.github-code-block-confluence {
    font-size: 13px;
    margin: 10px 0;
}

.github-code-block-confluence .github-code-header,
.github-code-block-confluence .github-code-header-refined {
    padding: 8px 12px;
    font-size: 12px;
}

.github-code-block-confluence .github-code-content pre,
.github-code-block-confluence .github-code-content-refined pre {
    padding: 12px;
}

/* Refined.com specific styles */
.github-code-block-refined.refined-code-block {
    position: relative;
}

.github-code-block-refined.refined-code-block::selection,
.github-code-block-refined.refined-code-block *::selection {
    background: rgba(9, 105, 218, 0.2);
}

/* Scroll Viewport specific styles */
.github-code-block-scroll-viewport {
    margin: 20px 0;
}

/* === Responsive Design === */

@media (max-width: 768px) {
    .github-code-block {
        margin: 12px 0;
        border-radius: 6px;
        font-size: 13px;
    }
    
    .github-code-header,
    .github-code-header-refined {
        padding: 10px 12px;
        font-size: 12px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        min-height: auto;
    }
    
    .github-code-info {
        gap: 8px;
        flex-wrap: wrap;
        width: 100%;
    }
    
    .github-code-content,
    .github-code-content-refined {
        max-height: 300px;
    }
    
    .github-code-content pre,
    .github-code-content-refined pre {
        padding: 12px;
    }
    
    .github-code-filename {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .github-code-block {
        margin: 8px -12px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .github-code-header,
    .github-code-header-refined {
        padding: 8px 12px;
    }
    
    .github-code-info {
        font-size: 11px;
    }
    
    .github-code-content,
    .github-code-content-refined {
        max-height: 250px;
    }
    
    .github-code-content pre,
    .github-code-content-refined pre {
        padding: 12px;
        font-size: 12px;
    }
    
    /* Hide GitHub link on very small screens */
    .github-code-link {
        display: none;
    }
}

/* === Print Styles === */

@media print {
    .github-code-block {
        break-inside: avoid;
        border: 1px solid #000;
        background: #fff !important;
        box-shadow: none;
    }
    
    .github-code-header,
    .github-code-header-refined {
        background: #f5f5f5 !important;
        color: #000 !important;
        border-bottom: 1px solid #000;
    }
    
    .github-code-content,
    .github-code-content-refined {
        max-height: none;
        overflow: visible;
        background: #fff !important;
    }
    
    .github-code-link {
        display: none;
    }
    
    .github-code-spinner {
        display: none;
    }
}

/* === Accessibility === */

.github-code-block:focus-within {
    outline: 2px solid #0969da;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .github-code-block {
        border-width: 2px;
        border-color: #000;
    }
    
    .github-code-header,
    .github-code-header-refined {
        border-bottom-width: 2px;
        border-bottom-color: #000;
    }
    
    .github-code-language {
        background: #000;
        color: #fff;
    }
    
    .github-code-lines {
        background: #000;
        color: #fff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .github-code-spinner {
        animation: none;
    }
    
    .github-code-block {
        transition: none;
    }
    
    .github-code-link {
        transition: none;
    }
}

/* === RTL Support === */

[dir="rtl"] .github-code-block {
    direction: ltr; /* Code should always be LTR */
}

[dir="rtl"] .github-code-header,
[dir="rtl"] .github-code-header-refined {
    direction: rtl;
}

[dir="rtl"] .github-code-info {
    flex-direction: row-reverse;
}

/* === Dark mode system preference === */

@media (prefers-color-scheme: dark) {
    .github-code-block:not([class*="theme-"]) {
        background: #0d1117;
        border-color: #30363d;
    }
    
    .github-code-block:not([class*="theme-"]) .github-code-header,
    .github-code-block:not([class*="theme-"]) .github-code-header-refined {
        background: #161b22;
        border-bottom-color: #30363d;
        color: #8b949e;
    }
    
    .github-code-block:not([class*="theme-"]) .github-code-content,
    .github-code-block:not([class*="theme-"]) .github-code-content-refined {
        background: #0d1117;
    }
    
    .github-code-block:not([class*="theme-"]) .github-code-filename {
        color: #f0f6fc;
    }
    
    .github-code-block:not([class*="theme-"]) .github-code-loading {
        background: #161b22;
        color: #8b949e;
    }
}