/* ── Article Detail Page ───────────────────────────────────── */
.article-detail-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 20px;
    color: var(--text-main);
}

.article-detail-page.no-sidebar .article-detail-main {
    max-width: 840px;
    margin: 0 auto;
}

.article-detail-thumbnail {
    width: 100%;
    max-height: 400px;
    overflow: hidden;
    border-radius: 12px;
    margin-bottom: 24px;
}
.article-detail-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.article-detail-title {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 16px;
    line-height: 1.2;
    color: var(--text-main);
    border-bottom: none;
    padding-bottom: 0;
}

.article-detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.article-detail-meta i {
    margin-right: 6px;
}

.article-detail-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 32px;
}

.article-detail-content {
    font-size: 1.05rem;
    line-height: 1.8;
    color: var(--text-main);
    margin-bottom: 40px;
}

/* ── Theme-Aware Images ────────────────────────────────────── */
.theme-aware-img {
    transition: opacity 0.3s ease;
}

.article-detail-content h2,
.article-detail-content h3 {
    margin-top: 2rem;
    margin-bottom: 1rem;
}
.article-detail-content p {
    margin-bottom: 1.2rem;
}
.article-detail-content pre {
    background: var(--bg-card);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid var(--border-color);
}
.article-detail-content code {
    font-size: 0.9em;
    background-color: rgba(127, 127, 127, 0.1);
    color: #fb7185;
    padding: 2px 4px;
    border-radius: 4px;
}

/* ── Premium IDE-Style Code Window (Library) ────────────────── */
.code-window {
    background: #0f172a !important;
    border-radius: 12px !important;
    border: none !important;
    outline: none !important;
    margin: 1.5rem 0 !important;
    overflow: hidden !important;
    position: relative !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3) !important;
}

.code-header {
    background: rgba(255, 255, 255, 0.03) !important;
    padding: 0.6rem 1rem !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
}

.code-lang {
    color: #64748b !important;
    font-size: 0.75rem !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
    font-family: 'Fira Code', monospace !important;
}

.code-window pre {
    background: transparent !important;
    border: none !important;
    outline: none !important;
    margin: 0 !important;
    padding: 1.5rem !important;
    border-radius: 0 !important;
}

.code-window code {
    background: transparent !important;
    color: #f8fafc !important;
    padding: 0 !important;
    font-family: 'Fira Code', monospace !important;
    font-size: 0.9rem !important;
    line-height: 1.5 !important;
}

/* Copy Icon Button */
.copy-btn {
    background: rgba(255, 255, 255, 0.05) !important;
    border: none !important;
    border: 0 !important;
    outline: none !important;
    outline: 0 !important;
    box-shadow: none !important;
    color: #94a3b8 !important;
    padding: 6px 12px !important;
    border-radius: 6px !important;
    cursor: pointer !important;
    font-size: 0.75rem !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    transition: all 0.2s !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    line-height: 1 !important;
    letter-spacing: 0.05em !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.12) !important;
    color: #fff !important;
    border: none !important;
    outline: none !important;
}

.copy-btn:focus, .copy-btn:active {
    outline: none !important;
    border: none !important;
    box-shadow: none !important;
}

.copy-btn svg {
    width: 14px;
    height: 14px;
    fill: none !important;
    stroke: currentColor !important;
    stroke-width: 2 !important;
    stroke-linecap: round !important;
    stroke-linejoin: round !important;
}

.article-detail-footer {
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.article-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
}
.article-back-btn:hover {
    background: var(--bg-btn-hover);
    text-decoration: none;
    color: var(--text-main);
}

/* ── Article TOC & Layout ──────────────────────────────────── */
.article-detail-layout {
    display: flex;
    flex-direction: row;
    gap: 40px;
    align-items: flex-start;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.article-detail-main {
    flex: 1;
    min-width: 0;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.article-detail-sidebar {
    width: 300px;
    flex-shrink: 0;
    position: sticky;
    top: 100px; /* Aligned below the fixed header with a small gap */
    bottom: 2rem;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    scrollbar-width: thin;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hide sidebar scrolling on webkit but keep it scrollable */
.article-detail-sidebar::-webkit-scrollbar {
    width: 4px;
}
.article-detail-sidebar::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
}

.article-detail-page.no-sidebar .article-detail-sidebar {
    display: none;
}

details.article-toc-container {
    padding: 16px 20px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    margin-bottom: 20px;
}

details.article-toc-container > summary.article-toc-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
    padding: 0;
    border-bottom: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    list-style: none; /* Hide default marker */
    outline: none;
}

details.article-toc-container > summary.article-toc-title::-webkit-details-marker {
    display: none;
}

details.article-toc-container > summary.article-toc-title::after {
    content: '\f107'; /* FontAwesome angle-down */
    font-family: "Font Awesome 5 Free", "Font Awesome 6 Free";
    font-weight: 900;
    color: var(--text-muted);
    font-size: 1rem;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

details.article-toc-container[open]:not(.is-closing) > summary.article-toc-title::after {
    transform: rotate(180deg);
}

.article-toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Ensure the TOC list safely holds the top spacing/border to animate seamlessly */
details.article-toc-container .details-anim-wrapper ul#article-toc {
    margin: 16px 0 0 0;
    padding: 16px 0 0 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.toc-item {
    margin-bottom: 0;
}

.toc-item.toc-h3 {
    padding-left: 12px;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
}

.toc-item.toc-h3:last-child {
    border-bottom: none;
}

.toc-item.toc-h2 > a {
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--text-main); /* or a specific green color based on theme */
    padding-left: 0;
}

.toc-item.toc-h3 > a {
    font-size: 0.9em;
    color: var(--text-muted);
}

.toc-link {
    display: block;
    color: var(--text-muted);
    text-decoration: none;
    line-height: 1.4;
    padding: 10px 14px;
    border-left: 3px solid transparent;
    transition: all 0.3s ease;
    border-radius: 0 6px 6px 0;
    margin-bottom: 2px;
}

.toc-link:hover {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.03);
    text-decoration: none;
}

.toc-link.active {
    color: var(--text-main);
    border-left-color: transparent;
    background-color: transparent;
    font-weight: 700;
}

/* ── Details Animation ───────────────────────────────────── */
details {
    margin-bottom: 0;
    border: none;
    border-radius: 0;
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
    background-color: transparent;
}

details:first-of-type {
    border-top: 1px solid var(--border-color);
}

.article-detail-content details summary {
    padding: 12px 0;
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: transparent;
    transition: color 0.2s;
    outline: none;
}

/* Hide default marker in Safari */
details summary::-webkit-details-marker {
    display: none;
}

details summary::after {
    content: '\f107'; /* FontAwesome angle-down */
    font-family: "Font Awesome 5 Free", "Font Awesome 6 Free";
    font-weight: 900;
    color: var(--text-muted);
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

details[open]:not(.is-closing) summary::after {
    transform: rotate(180deg);
}

details summary:hover {
    color: var(--text-main);
}

.details-anim-wrapper {
    overflow: hidden;
    transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.details-anim-wrapper ul {
    margin: 0;
    padding-bottom: 1.5rem;
    padding-left: 1.5rem;
}

/* ── Tree View Details (Nested) ──────────────────────────── */
details.tree-details {
    border: none;
    border-top: none !important;
    border-bottom: none !important;
    margin-bottom: 0px;
}

.article-detail-content details.tree-details summary {
    font-size: 1.05rem;
    font-weight: 600;
    padding: 6px 0;
    justify-content: flex-start;
    gap: 12px;
}

.article-detail-content details.tree-details summary::after {
    font-size: 0.9rem;
    transform: rotate(-90deg); /* points right by default */
}

.article-detail-content details.tree-details[open]:not(.is-closing) summary::after {
    transform: rotate(0deg); /* points down when open */
}

details.tree-details .details-anim-wrapper ul,
details.tree-details .details-anim-wrapper div.mt-2 {
    padding-bottom: 0.5rem;
    padding-left: 2rem;
}
details.tree-details .details-anim-wrapper ul {
    list-style-type: disc;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 992px) {
    .article-detail-layout {
        flex-direction: column;
        gap: 20px;
    }
    
    .article-detail-sidebar {
        width: 100%;
        position: static;
        max-height: none;
        transform: translateY(0); /* Reset transform on mobile */
        margin-top: 40px; /* Add spacing below article content */
    }

    .article-detail-title {
        font-size: 1.8rem;
    }
}

@media (max-width: 768px) {
    .article-detail-title {
        font-size: 1.6rem;
    }
}
/* ── Comment System ───────────────────────────────────────── */
.article-comments-section {
    margin-top: 60px;
    padding-top: 40px;
    border-top: 2px solid var(--border-color);
}

.comments-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 30px;
    color: var(--text-main);
}

.comment-form-container {
    margin-bottom: 40px;
    background: var(--bg-card);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid var(--border-alt, rgba(0,0,0,0.05));
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.comment-textarea, .reply-textarea {
    width: 100%;
    min-height: 100px;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-input, rgba(0,0,0,0.02));
    color: var(--text-main);
    resize: vertical;
    margin-bottom: 16px;
    font-family: inherit;
    transition: all 0.2s ease;
}

.comment-textarea:focus, .reply-textarea:focus {
    outline: none;
    border-color: var(--accent-color, #007bff);
    background: var(--bg-body);
    box-shadow: 0 0 0 4px rgba(0, 123, 255, 0.1);
}

.btn-submit {
    padding: 8px 32px;
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: #fff !important;
    border: none;
    border-radius: 50px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
    text-transform: none;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.comment-form-actions, .reply-form-actions {
    display: flex;
    justify-content: flex-start;
    gap: 12px;
    align-items: center;
    flex-wrap: nowrap;
    margin-top: 8px;
}

.btn-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4);
    opacity: 1;
}

.btn-cancel {
    padding: 8px 24px;
    background: transparent !important;
    color: var(--text-muted) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 50px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.3s ease;
    box-shadow: none !important;
    text-transform: none;
}

.btn-cancel:hover {
    background: var(--bg-input, rgba(0,0,0,0.05)) !important;
    color: var(--text-main) !important;
    border-color: var(--text-muted) !important;
}

/* Comment Item */
.comment-item {
    display: flex;
    gap: 16px;
    margin-bottom: 30px;
    transition: all 0.3s ease;
}

.comment-reply {
    margin-left: 50px;
    margin-top: 20px;
}

.comment-avatar {
    width: 48px;
    height: 48px;
    font-size: 40px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.comment-main {
    flex: 1;
}

.comment-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.comment-author {
    font-weight: 700;
    color: var(--text-main);
}

.comment-date {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.comment-content {
    line-height: 1.6;
    color: var(--text-main);
    margin-bottom: 12px;
}

.comment-actions {
    display: flex;
    gap: 20px;
    font-size: 0.9rem;
}

.comment-action-btn {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    transition: all 0.2s;
    border-radius: 50px;
    line-height: 1;
}

.comment-action-btn:hover {
    color: var(--text-main);
    background: var(--bg-input, rgba(0,0,0,0.05)) !important;
}

.comment-action-btn.active {
    color: var(--accent-color, #007bff) !important;
}

.reply-form-container {
    margin-top: 16px;
    background: var(--bg-card);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.login-to-comment {
    text-align: center;
    padding: 20px;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px dashed var(--border-color);
    color: var(--text-muted);
}

.login-to-comment a {
    color: var(--accent-color, #007bff);
    font-weight: 600;
}

/* ── Responsive Overrides & Fixes ─────────────────────────── */


/* 2. Responsive Images in Content */
.article-detail-content img {
    max-width: 100% !important;
    height: auto !important;
    display: block;
    margin: 1.5rem auto;
}

/* 3. Responsive Code & Terminal Windows */
.code-window, 
.terminal-block,
pre, 
code {
    max-width: 100% !important;
    box-sizing: border-box !important;
}

.code-window pre,
.article-detail-content pre {
    overflow-x: auto !important;
    white-space: pre !important; /* Keep code lines on one line with scroll */
}

/* 4. Support for inline code that should wrap if too long */
.article-detail-content p code,
.article-detail-content li code {
    white-space: normal !important;
    word-break: break-all !important;
}

/* 5. Fix for rigid grid layouts (like Prerequisites/Requirements) */
.article-detail-content [style*="grid-template-columns"] {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)) !important;
}

/* 6. Specific fix for any fixed-width elements (common in pasted content) */
.article-detail-content [style*="width"] {
    max-width: 100% !important;
    height: auto !important;
}

@media (max-width: 768px) {
    .article-detail-page {
        padding: 20px 15px;
    }
    
    .article-detail-title {
        font-size: 1.5rem !important;
        word-break: break-word;
    }

    .article-detail-content {
        font-size: 1rem;
    }

    /* Force main containers to be responsive even if content adds fixed widths */
    .article-detail-page, 
    .article-detail-layout, 
    .article-detail-main, 
    .article-detail-header, 
    .article-detail-content,
    .section {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
}

/* ── Image Lightbox ─────────────────────────────────────────── */
#img-lightbox {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease, background 0.3s ease, backdrop-filter 0.3s ease;
}

#img-lightbox.active {
    opacity: 1;
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: all;
    cursor: zoom-out;
}

.lightbox-img {
    max-width: 90vw;
    max-height: 82vh;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
    transform: scale(0.85);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    cursor: default;
}

#img-lightbox.active .lightbox-img {
    transform: scale(1);
    opacity: 1;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 24px;
    background: rgba(255, 255, 255, 0.1) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    box-shadow: none !important;
    color: #fff !important;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s;
}

.lightbox-close svg {
    width: 14px;
    height: 14px;
    display: block;
    flex-shrink: 0;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2) !important;
}

.lightbox-hint {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.45);
    letter-spacing: 0.03em;
    cursor: default;
}
