/* Code Block Override - Maximum Priority Fixes */
/* This file ensures code blocks are always readable and properly formatted */

/* ============================================
   FORCE LTR FOR ALL CODE BLOCKS
   ============================================ */

/* Target all possible code block selectors with maximum specificity */
html body main .post-content pre,
html body main .post-content pre[class*="language-"],
html body main article pre,
html body pre,
html body pre[class*="language-"],
html body .token,
html body code[class*="language-"],
html body main .post-content pre code,
html body main article pre code {
    /* Force LTR direction */
    direction: ltr !important;
    text-align: left !important;
    unicode-bidi: embed !important;

    /* Ensure block display */
    display: block !important;

    /* Font settings */
    font-family:
        "Consolas", "Monaco", "Courier New", "Fira Code", "Cascadia Code",
        monospace !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
    font-weight: normal !important;
    font-style: normal !important;

    /* Text settings */
    white-space: pre !important;
    word-spacing: normal !important;
    word-break: normal !important;
    word-wrap: normal !important;
    hyphens: none !important;
    tab-size: 4 !important;
    -moz-tab-size: 4 !important;
    -webkit-hyphens: none !important;
    -moz-hyphens: none !important;
    -ms-hyphens: none !important;

    /* Remove text shadow */
    text-shadow: none !important;
}

/* Pre block specific styles */
html body pre,
html body main pre,
html body article pre,
html body .post-content pre,
html body pre[class*="language-"] {
    /* Background and borders */
    background: #1e293b !important;
    border: 1px solid #334155 !important;
    border-radius: 8px !important;

    /* Spacing */
    margin: 1.5rem 0 !important;
    padding: 0 !important;

    /* Layout */
    position: relative !important;
    overflow: visible !important;
    max-width: 100% !important;
    width: 100% !important;

    /* Ensure it's a block */
    display: block !important;
}

/* Code inside pre specific styles */
html body pre code,
html body main pre code,
html body article pre code,
html body .post-content pre code,
html body pre[class*="language-"] code,
html body code[class*="language-"] {
    /* Reset background for code inside pre */
    background: transparent !important;

    /* Text color */
    color: #e2e8f0 !important;

    /* Padding for content */
    padding: 1rem !important;
    margin: 0 !important;

    /* Overflow handling */
    overflow-x: auto !important;
    overflow-y: hidden !important;
    max-width: 100% !important;

    /* Display */
    display: block !important;

    /* Border */
    border: none !important;
    border-radius: 0 !important;
}

/* Dark theme adjustments */
[data-theme="dark"] pre,
html[data-theme="dark"] body pre {
    background: #0f172a !important;
    border-color: #1e293b !important;
}

[data-theme="dark"] pre code,
html[data-theme="dark"] body pre code {
    color: #f1f5f9 !important;
}

/* ============================================
   SYNTAX HIGHLIGHTING OVERRIDES
   ============================================ */

/* Comments */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata,
pre .comment {
    color: #64748b !important;
    font-style: italic !important;
}

/* Keywords */
.token.keyword,
.token.tag,
.token.boolean,
.token.constant,
pre .keyword {
    color: #f472b6 !important;
    font-weight: bold !important;
}

/* Strings */
.token.string,
.token.char,
.token.attr-value,
.token.regex,
.token.variable,
pre .string {
    color: #34d399 !important;
}

/* Numbers */
.token.number,
.token.operator,
.token.entity,
.token.url,
pre .number {
    color: #60a5fa !important;
}

/* Functions */
.token.function,
.token.class-name,
.token.symbol,
pre .function {
    color: #c084fc !important;
}

/* Properties */
.token.property,
.token.attr-name,
.token.builtin,
.token.deleted,
pre .property {
    color: #fbbf24 !important;
}

/* Punctuation */
.token.punctuation,
.token.inserted,
pre .punctuation {
    color: #cbd5e1 !important;
}

/* Selectors and pseudo-elements */
.token.selector,
.token.important,
.token.atrule,
pre .selector {
    color: #fb923c !important;
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */

pre::-webkit-scrollbar,
pre code::-webkit-scrollbar {
    height: 10px !important;
    width: 10px !important;
}

pre::-webkit-scrollbar-track,
pre code::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2) !important;
    border-radius: 5px !important;
}

pre::-webkit-scrollbar-thumb,
pre code::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3) !important;
    border-radius: 5px !important;
}

pre::-webkit-scrollbar-thumb:hover,
pre code::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5) !important;
}

/* Firefox scrollbar */
pre,
pre code {
    scrollbar-width: thin !important;
    scrollbar-color: rgba(255, 255, 255, 0.3) rgba(0, 0, 0, 0.2) !important;
}

/* ============================================
   COPY BUTTON STYLING
   ============================================ */

.copy-code-btn {
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.375rem !important;
    padding: 0.25rem 0.625rem !important;
    background: rgba(139, 92, 246, 0.1) !important;
    color: #c4b5fd !important;
    border: 1px solid rgba(139, 92, 246, 0.3) !important;
    border-radius: 0.375rem !important;
    font-size: 0.75rem !important;
    font-family: "Vazirmatn", system-ui, sans-serif !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    white-space: nowrap !important;
    backdrop-filter: blur(4px) !important;
    -webkit-backdrop-filter: blur(4px) !important;
    line-height: 1 !important;
    text-transform: none !important;
    letter-spacing: normal !important;
}

pre:hover .code-copy-btn,
pre:hover button {
    opacity: 1 !important;
}

.code-copy-btn:hover,
pre button:hover {
    background: var(--primary, #7c3aed) !important;
    border-color: var(--primary, #7c3aed) !important;
    color: white !important;
    transform: translateY(-1px) !important;
}

.code-copy-btn.copied,
pre button.copied {
    background: #10b981 !important;
    border-color: #10b981 !important;
    color: white !important;
}

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

code:not(pre code),
p code,
li code,
td code,
h1 code,
h2 code,
h3 code,
h4 code,
h5 code,
h6 code {
    /* Direction for inline code */
    direction: ltr !important;
    unicode-bidi: embed !important;

    /* Styling */
    background: rgba(124, 58, 237, 0.1) !important;
    color: #7c3aed !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    font-family: "Consolas", "Monaco", "Courier New", monospace !important;
    font-size: 0.9em !important;
    font-weight: normal !important;
    white-space: nowrap !important;
    border: 1px solid rgba(124, 58, 237, 0.2) !important;
}

[data-theme="dark"] code:not(pre code) {
    background: rgba(167, 139, 250, 0.15) !important;
    color: #a78bfa !important;
    border-color: rgba(167, 139, 250, 0.3) !important;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
    html body pre code,
    html body pre[class*="language-"] code {
        font-size: 12px !important;
        padding: 0.75rem !important;
        line-height: 1.4 !important;
    }

    .code-copy-btn,
    pre button {
        opacity: 1 !important;
        padding: 4px 8px !important;
        font-size: 11px !important;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    pre {
        background: white !important;
        border: 1px solid #ccc !important;
        page-break-inside: avoid !important;
    }

    pre code {
        color: black !important;
        background: white !important;
    }

    .code-copy-btn,
    pre button {
        display: none !important;
    }
}

/* ============================================
   FINAL OVERRIDES - MAXIMUM PRIORITY
   ============================================ */

/* Use attribute selector for even higher specificity */
[class*="post"] pre,
[class*="content"] pre,
[id*="post"] pre,
[id*="content"] pre {
    direction: ltr !important;
    text-align: left !important;
}

[class*="post"] pre code,
[class*="content"] pre code,
[id*="post"] pre code,
[id*="content"] pre code {
    direction: ltr !important;
    text-align: left !important;
    display: block !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
}

/* Last resort - universal selector with important */
* pre,
* pre code {
    direction: ltr !important;
    text-align: left !important;
}

/* Ensure Prism doesn't break our styles */
.prism-code {
    direction: ltr !important;
    text-align: left !important;
}

/* Fix for RTL parent containers */
[dir="rtl"] pre,
[dir="rtl"] pre code {
    direction: ltr !important;
    text-align: left !important;
    unicode-bidi: isolate !important;
}
