/* Blog Styles */

/* Dark mode badge styles */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .badge-primary {
        background-color: #956f00 !important;
        color: #e7e5e2 !important;
    }
    
    :root:not([data-theme="light"]) a.badge-primary:hover,
    :root:not([data-theme="light"]) a.badge-primary:focus {
        background-color: #7d5d00 !important;
        color: #e7e5e2 !important;
    }
    
    :root:not([data-theme="light"]) .badge-secondary {
        background-color: #595f63 !important;
        color: #e7e5e2 !important;
    }
    
    :root:not([data-theme="light"]) a.badge-secondary:hover,
    :root:not([data-theme="light"]) a.badge-secondary:focus {
        background-color: #494e52 !important;
        color: #e7e5e2 !important;
    }
}

[data-theme="dark"] .badge-primary {
    background-color: #956f00 !important;
    color: #e7e5e2 !important;
}

[data-theme="dark"] a.badge-primary:hover,
[data-theme="dark"] a.badge-primary:focus {
    background-color: #7d5d00 !important;
    color: #e7e5e2 !important;
}

[data-theme="dark"] .badge-secondary {
    background-color: #595f63 !important;
    color: #e7e5e2 !important;
}

[data-theme="dark"] a.badge-secondary:hover,
[data-theme="dark"] a.badge-secondary:focus {
    background-color: #494e52 !important;
    color: #e7e5e2 !important;
}

/* Card hover effects */
.card {
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--color-border-light);
    /* Match the card body/footer, so the sub-pixel seam between them that the
       hover lift can expose shows this colour, not Bootstrap's default white. */
    background-color: var(--color-bg-white);
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

/* Disable hover effect for sidebar cards */
.col-lg-4 .card:hover {
    transform: none;
    box-shadow: none;
}

/* Blog card link styling */
.blog-card-link {
    display: flex;
    flex-direction: column;
    color: inherit;
    cursor: pointer;
    text-decoration: none !important;
}

.blog-card-link .card-body {
    flex: 1;
    padding-bottom: 0;
}

.blog-card-link:hover {
    text-decoration: none !important;
    color: inherit;
}

.blog-card-link:hover * {
    text-decoration: none !important;
}

.blog-card-link .card-title,
.blog-card-link:hover .card-title {
    text-decoration: none !important;
}

/* Blog content styling */
.blog-content {
    line-height: 1.8;
    user-select: text;
    overflow-x: auto;
    max-width: 100%;
}

/* Allow selection for blog post title */
.blog-post h1 {
    user-select: text;
}

.blog-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 20px 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* CKEditor 5 image alignment classes */
/* CKEditor 5 wraps images in <figure class="image image-style-align-*"> */

.blog-content figure.image {
    display: table;
    clear: both;
    margin: 20px 0;
}

.blog-content figure.image img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Center alignment (default for CKEditor 5) */
.blog-content figure.image,
.blog-content figure.image-style-align-center {
    margin-left: auto;
    margin-right: auto;
}

.blog-content figure.image-style-align-center img {
    margin: 0 auto;
}

/* Left alignment */
.blog-content figure.image-style-align-left {
    float: left;
    margin: 10px 20px 10px 0;
}

.blog-content figure.image-style-align-left img {
    margin: 0;
}

/* Right alignment */
.blog-content figure.image-style-align-right {
    float: right;
    margin: 10px 0 10px 20px;
}

.blog-content figure.image-style-align-right img {
    margin: 0;
}

.blog-content figcaption {
    display: block;
    text-align: center;
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    font-style: italic;
}

/* KaTeX overflow handling for wide equations */
.blog-content .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
}

/* Clear floats after images */
.blog-content::after {
    content: "";
    display: table;
    clear: both;
}

/* Related Posts Grid */
.related-posts-section {
    margin-top: 1.5rem !important;
}

.related-posts-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.related-post-card {
    flex: 1;
    min-width: 150px;
    max-width: calc(33.333% - 0.67rem);
}

/* Tablet/narrow screens - stacked layout needs more spacing before sidebar */
@media (max-width: 991.98px) {
    .related-posts-section {
        margin-bottom: 2rem !important;
    }
    
    .related-post-card {
        max-width: calc(50% - 0.5rem);
    }
    
    /* Reduce bottom padding on blog content for narrow screens */
    .blog-content {
        padding-bottom: 0;
    }
    
    article.blog-post footer {
        margin-bottom: 1rem !important;
    }
}

/* Mobile - show up to 4 related posts */
@media (max-width: 767.98px) {
    .related-post-card {
        max-width: 100%;
        flex-basis: 100%;
    }
    
    .related-post-card.d-none {
        display: block !important;
    }
    
    .related-posts-section {
        margin-bottom: 2rem !important;
    }
    
    /* Hide non-active page numbers on mobile, keep nav buttons */
    .pagination .page-number:not(.active) {
        display: none;
    }
}

/* Mobile - add bottom padding to sidebar */
@media (max-width: 991.98px) {
    .col-lg-4 .card:last-child {
        margin-bottom: 2rem;
    }
}

.blog-content h2 {
    margin-top: 2rem;
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--color-heading);
}

.blog-content h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
    color: var(--color-heading);
}

.blog-content p {
    margin-bottom: 1.2rem;
}

.blog-content ul,
.blog-content ol {
    margin-bottom: 1.2rem;
    padding-left: 2rem;
    list-style-position: outside;
}

.blog-content ul {
    list-style-type: disc;
}

.blog-content ol {
    list-style-type: decimal;
}

.blog-content li {
    margin-bottom: 0.5rem;
    display: list-item;
}

/* Nested lists */
.blog-content ul ul {
    list-style-type: circle;
    margin-top: 0.5rem;
}

.blog-content ul ul ul {
    list-style-type: square;
}

.blog-content ol ol {
    list-style-type: lower-alpha;
    margin-top: 0.5rem;
}

.blog-content ol ol ol {
    list-style-type: lower-roman;
}

.blog-content blockquote {
    border-left: 4px solid var(--color-primary);
    padding-left: 1.5rem;
    margin: 1.5rem 0;
    font-style: italic;
    color: var(--color-text-primary);
    background-color: var(--color-bg-gray);
    padding: 1rem 1.5rem;
    border-radius: 4px;
}

/* Table wrapper - enables horizontal scroll on narrow screens */
.table-scroll-wrapper {
    overflow-x: auto;
    max-width: 100%;
    margin: 2rem auto;
}

/* Table styles */
.blog-content table {
    width: auto;
    margin: 0 auto;
    border-collapse: collapse;
    border-spacing: 0;
    text-align: left;
    font-size: 0.95em;
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
}

.blog-content table th,
.blog-content table td {
    padding: 0.65rem 1rem;
    border: 1px solid var(--color-border-light);
    vertical-align: top;
    color: var(--color-text-primary);
}

.blog-content table th {
    font-weight: 600;
    background-color: var(--color-bg-gray);
    color: var(--color-heading);
}

.blog-content table tbody tr:nth-child(even) {
    background-color: var(--color-bg-gray);
}

.blog-content table tbody tr:nth-child(odd) {
    background-color: var(--color-bg-white);
}

.blog-content p code,
.blog-content li code,
.blog-content h1 code,
.blog-content h2 code,
.blog-content h3 code,
.blog-content h4 code,
.blog-content h5 code,
.blog-content h6 code,
.blog-content td code {
    background-color: var(--color-code-bg);
    color: var(--color-code-text);
    padding: 3px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    border: 1px solid var(--color-code-border);
}

.blog-content pre {
    background-color: var(--color-code-bg);
    padding: 0;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1.5rem 0;
    border: 1px solid var(--color-code-border);
}

.blog-content pre code {
    background-color: transparent;
    padding: 1rem;
    border: none;
    color: var(--color-code-text);
    font-size: 0.875rem;
    line-height: 1.6;
    display: block;
}

/* Code block scrollbar */
.blog-content pre::-webkit-scrollbar {
    height: 10px;
}

.blog-content pre::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 4px;
}

.blog-content pre::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.blog-content pre::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Firefox scrollbar */
.blog-content pre {
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f5f5f5;
}

/* Dark mode code block scrollbar */
@media (prefers-color-scheme: dark) {
    .blog-content pre::-webkit-scrollbar-track {
        background: #1a1a1a;
    }

    .blog-content pre::-webkit-scrollbar-thumb {
        background: #4a4a4a;
    }

    .blog-content pre::-webkit-scrollbar-thumb:hover {
        background: #6a6a6a;
    }

    .blog-content pre {
        scrollbar-color: #4a4a4a #1a1a1a;
    }
}

[data-theme="dark"] .blog-content pre::-webkit-scrollbar-track {
    background: #1a1a1a;
}

[data-theme="dark"] .blog-content pre::-webkit-scrollbar-thumb {
    background: #4a4a4a;
}

[data-theme="dark"] .blog-content pre::-webkit-scrollbar-thumb:hover {
    background: #6a6a6a;
}

[data-theme="dark"] .blog-content pre {
    scrollbar-color: #4a4a4a #1a1a1a;
}

[data-theme="light"] .blog-content pre::-webkit-scrollbar-track {
    background: #f5f5f5;
}

[data-theme="light"] .blog-content pre::-webkit-scrollbar-thumb {
    background: #c1c1c1;
}

[data-theme="light"] .blog-content pre::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

[data-theme="light"] .blog-content pre {
    scrollbar-color: #c1c1c1 #f5f5f5;
}

/* Blog post header */
.blog-post header h1 {
    color: var(--color-heading);
    font-weight: 700;
}

/* Category and tag badges */
.badge {
    font-size: 0.85rem;
    padding: 0.5rem 0.8rem;
    margin-right: 0.3rem;
    margin-bottom: 0.3rem;
    user-select: none;
}

.badge-primary {
    background-color: var(--color-primary);
    color: #fff;
}

a.badge-primary {
    color: #fff;
    text-decoration: none;
}

a.badge-primary:hover,
a.badge-primary:focus {
    background-color: #e0a800;
    color: #fff;
    text-decoration: none;
}

.badge-secondary {
    background-color: #6c757d;
}

a.badge-secondary {
    color: #fff;
    text-decoration: none;
}

a.badge-secondary:hover,
a.badge-secondary:focus {
    background-color: #5a6268;
    color: #fff;
    text-decoration: none;
}

/* Pagination */
.pagination .page-link {
    color: #495057;
    border-color: #dee2e6;
    user-select: none;
}

.pagination .page-item.active .page-link {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    color: #000;
}

.pagination .page-link:hover {
    background-color: #f8f9fa;
    border-color: #dee2e6;
    color: #000;
}

/* Sidebar */
.card-header {
    background-color: var(--color-bg-white);
    border-bottom: 2px solid var(--color-border-primary);
}

.card-header h5 {
    color: var(--color-text-primary);
}

.card-body {
    background-color: var(--color-bg-white);
}

.card-footer {
    background-color: var(--color-bg-white) !important;
}

.bg-light {
    background-color: var(--color-bg-body) !important;
}

.text-dark {
    color: var(--color-text-primary) !important;
}

/* Sidebar category links */
.col-lg-4 .card-body ul.list-unstyled a {
    color: var(--color-text-primary);
    transition: color 0.2s;
}

.col-lg-4 .card-body ul.list-unstyled a:hover {
    color: var(--color-text-black);
    text-decoration: none;
}

/* Scrollable category list */
.category-list {
    max-height: 300px;
    overflow-y: auto;
}

.category-item {
    transition: background-color 0.2s;
}

.category-item:hover {
    background-color: var(--color-bg-gray);
}

.category-item.category-selected {
    background-color: var(--color-bg-gray);
    font-weight: 600;
}

.category-item.category-selected:hover {
    background-color: #dee2e6;
}

/* Dark mode category item styles */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .category-item.category-selected {
        background-color: #252b2e;
    }
    
    :root:not([data-theme="light"]) .category-item.category-selected:hover {
        background-color: #2d3336;
    }
}

[data-theme="dark"] .category-item.category-selected {
    background-color: #252b2e;
}

[data-theme="dark"] .category-item.category-selected:hover {
    background-color: #2d3336;
}

/* Filter info badges - softer color that works with pale blue background */
.badge-filter {
    background-color: #5a7a8a;
    color: #ffffff;
    margin: 0.15rem 0.25rem;
}

/* Dark mode filter styles */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .alert-info {
        background-color: #1b3d45 !important;
        border-color: #1b3d45 !important;
    }
    
    :root:not([data-theme="light"]) .filter-label {
        color: #8de2f1 !important;
    }
    
    :root:not([data-theme="light"]) .badge-filter {
        background-color: #4a626e !important;
        color: #e7e5e2 !important;
    }
    
    :root:not([data-theme="light"]) .badge-removable:hover {
        background-color: #3a525e !important;
        color: #e7e5e2 !important;
    }
    
    :root:not([data-theme="light"]) .btn-close-filter {
        color: #8de2f1 !important;
    }
    
    :root:not([data-theme="light"]) .btn-close-filter:hover {
        background-color: #8de2f1 !important;
        color: #1b3d45 !important;
    }
}

[data-theme="dark"] .alert-info {
    background-color: #1b3d45 !important;
    border-color: #1b3d45 !important;
}

[data-theme="dark"] .filter-label {
    color: #8de2f1 !important;
}

[data-theme="dark"] .badge-filter {
    background-color: #4a626e !important;
    color: #e7e5e2 !important;
}

[data-theme="dark"] .badge-removable:hover {
    background-color: #3a525e !important;
    color: #e7e5e2 !important;
}

[data-theme="dark"] .btn-close-filter {
    color: #8de2f1 !important;
}

[data-theme="dark"] .btn-close-filter:hover {
    background-color: #8de2f1 !important;
    color: #1b3d45 !important;
}

/* Removable filter badges */
.badge-removable {
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none !important;
}

.badge-removable:hover {
    background-color: #495867;
    color: #ffffff;
    text-decoration: none !important;
}

.badge-removable i {
    font-size: 0.7em;
    opacity: 0.7;
}

/* Filter content wrapping */
.filter-content {
    flex: 1;
    min-width: 0;
}

.filter-group {
    display: flex;
    align-items: baseline;
}

.filter-label {
    min-width: 85px;
    flex-shrink: 0;
    line-height: 1.5rem;
    padding-top: 0.15rem;
}

.filter-badges {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.filter-group .badge {
    white-space: nowrap;
}

/* Close filter button - positioned in top-right corner */
.btn-close-filter {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    color: #0c5460;
    border-radius: 50%;
    font-size: 0.9rem;
    transition: all 0.2s;
    text-decoration: none;
    user-select: none;
}

.btn-close-filter:hover {
    background-color: #0c5460;
    color: #ffffff;
    text-decoration: none;
}

.category-count {
    background-color: #6c757d;
    color: #ffffff;
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
    border-radius: 0.25rem;
    user-select: none;
}

.category-list::-webkit-scrollbar {
    width: 6px;
}

.category-list::-webkit-scrollbar-track {
    background: var(--color-scrollbar-track);
    border-radius: 3px;
}

.category-list::-webkit-scrollbar-thumb {
    background: var(--color-scrollbar-thumb);
    border-radius: 3px;
}

.category-list::-webkit-scrollbar-thumb:hover {
    background: var(--color-scrollbar-thumb-hover);
}

/* Scrollable tag cloud */
.tag-cloud {
    max-height: 200px;
    overflow-y: auto;
    padding: 1.25rem;
}

.tag-cloud::-webkit-scrollbar {
    width: 6px;
}

.tag-cloud::-webkit-scrollbar-track {
    background: var(--color-scrollbar-track);
    border-radius: 3px;
}

.tag-cloud::-webkit-scrollbar-thumb {
    background: var(--color-scrollbar-thumb);
    border-radius: 3px;
}

.tag-cloud::-webkit-scrollbar-thumb:hover {
    background: var(--color-scrollbar-thumb-hover);
}

/* Category count badge */
.category-list .badge-light {
    background-color: #e9ecef;
    color: #495057;
    font-size: 0.75rem;
}

/* Featured image */
.card-img-top {
    height: 200px;
    object-fit: cover;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .blog-content {
        font-size: 1rem;
    }
    
    .card-img-top {
        height: 180px;
    }
}

/* Button styling */
.btn-xs {
    padding: 0.2rem 0.5rem !important;
    font-size: 0.75rem !important;
}

.btn-blog-outline {
    color: var(--color-primary-text) !important;
    background-color: transparent !important;
    border: 2px solid var(--color-primary-text) !important;
    border-radius: 6px !important;
    user-select: none;
    outline: none !important;
    box-shadow: none !important;
}

.btn-blog-outline:hover,
.btn-blog-outline:focus,
.btn-blog-outline:active {
    color: #d39e00 !important;
    background-color: rgba(255, 193, 7, 0.1) !important;
    border-color: #d39e00 !important;
    outline: none !important;
    box-shadow: none !important;
}

.btn-blog-outline-dark {
    color: #343a40 !important;
    background-color: transparent !important;
    border: 2px solid #343a40 !important;
    border-radius: 6px !important;
    user-select: none;
    outline: none !important;
    box-shadow: none !important;
}

.btn-blog-outline-dark:hover,
.btn-blog-outline-dark:focus,
.btn-blog-outline-dark:active {
    color: #1d2124 !important;
    background-color: rgba(52, 58, 64, 0.1) !important;
    border-color: #1d2124 !important;
    outline: none !important;
    box-shadow: none !important;
}

/* Dark mode styles for back to blog button */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .btn-blog-outline-dark {
        color: var(--color-primary-text) !important;
        border-color: var(--color-border-primary) !important;
    }
    
    :root:not([data-theme="light"]) .btn-blog-outline-dark:hover,
    :root:not([data-theme="light"]) .btn-blog-outline-dark:focus {
        color: var(--color-bg-white) !important;
        background-color: var(--color-border-primary) !important;
        border-color: var(--color-border-primary) !important;
    }
}

[data-theme="dark"] .btn-blog-outline-dark {
    color: var(--color-primary-text) !important;
    border-color: var(--color-border-primary) !important;
}

[data-theme="dark"] .btn-blog-outline-dark:hover,
[data-theme="dark"] .btn-blog-outline-dark:focus {
    color: var(--color-bg-white) !important;
    background-color: var(--color-border-primary) !important;
    border-color: var(--color-border-primary) !important;
}

.btn-outline-primary {
    color: var(--color-primary-text);
    border-color: var(--color-primary-text);
}

.btn-outline-primary:hover {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    color: #000;
}

.btn-outline-secondary:hover {
    background-color: #6c757d;
    border-color: #6c757d;
}

/* Social share buttons */
.social-share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    color: #fff;
    font-size: 20px;
    transition: all 0.3s ease;
    text-decoration: none;
    user-select: none;
}

.social-share-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    text-decoration: none;
}

.social-share-btn:focus,
.social-share-btn:active,
.social-share-btn:visited {
    color: #fff !important;
    text-decoration: none;
    outline: none;
}

.social-share-btn::selection,
.social-share-btn *::selection {
    background-color: transparent;
    color: #fff;
}

.twitter-share {
    background-color: #000000;
}

.twitter-share:hover {
    background-color: #1a1a1a;
    color: #fff;
}

.facebook-share {
    background-color: #1877f2;
}

.facebook-share:hover {
    background-color: #0d65d9;
    color: #fff;
}

.reddit-share {
    background-color: #ff4500;
}

.reddit-share:hover {
    background-color: #e03d00;
    color: #fff;
}

.email-share {
    background-color: #6c757d;
}

.email-share:hover {
    background-color: #5a6268;
    color: #fff;
}

/* Mobile share section spacing */
.mobile-share-section {
    margin-bottom: 2rem;
}

/* About the Author section */
.about-author-content {
    font-size: 0.95rem;
}

.about-author-content p {
    line-height: 1.6;
}

.about-author-content .author-name {
    font-size: 1.1rem;
}

.about-author-content .text-muted {
    color: var(--color-text-secondary) !important;
}

/* About the Author - centered on mobile/narrow screens */
@media (max-width: 991.98px) {
    .about-author-content {
        text-align: center;
    }
    
    .about-author-content .social-icon {
        justify-content: center;
    }
}

/* Blog Footer */
.blog-footer {
    border-top: 1px solid var(--color-border-light);
}

.blog-footer p,
.blog-footer .text-muted {
    font-size: 13px;
    color: var(--color-text-secondary) !important;
}

/* Responsive blog list spacing */
@media (max-width: 991.98px) {
    .blog-list-container {
        padding-top: 10px !important;
    }
    
    .blog-list-container .row {
        margin-top: 0.5rem !important;
    }
}
