/* ============================================
   dibi8.com - Technical Documentation Style
   Professional, clean, readable
   ============================================ */

/* ---------- Google Fonts Import ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ---------- Root Variables ---------- */
:root {
    /* Primary colors - Documentation blue */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;

    /* Text colors */
    --text-main: #1f2937;
    --text-secondary: #4b5563;
    --text-muted: #6b7280;
    --text-light: #9ca3af;

    /* Background colors */
    --bg-body: #fafafa;
    --bg-card: #ffffff;
    --bg-code: #f3f4f6;
    --bg-hover: #f9fafb;
    --bg-sidebar: #f8fafc;

    /* Border colors */
    --border: #e5e7eb;
    --border-light: #f3f4f6;

    /* Typography */
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Shadows - minimal for doc style */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);

    /* Radius - minimal */
    --radius-sm: 4px;
    --radius-md: 6px;
}

/* Dark mode overrides */
.dark {
    --text-main: #f3f4f6;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;
    --text-light: #6b7280;
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-code: #1e293b;
    --bg-hover: #334155;
    --bg-sidebar: #1e293b;
    --border: #334155;
    --border-light: #1e293b;
    --primary-light: rgba(37, 99, 235, 0.15);
}

/* ---------- Global Typography ---------- */
body {
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.75;
    color: var(--text-main);
    background-color: var(--bg-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Headings - tighter, more authoritative */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-body);
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-main);
    margin-top: var(--space-xl);
    margin-bottom: var(--space-md);
}

h1 { font-size: 2rem; letter-spacing: -0.025em; }
h2 { font-size: 1.5rem; letter-spacing: -0.025em; border-bottom: 1px solid var(--border); padding-bottom: var(--space-sm); }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }

/* Links - subtle underline on hover */
a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* ---------- Header / Navigation ---------- */
.header {
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.header-nav {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-lg);
}

.logo a {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--text-main);
    text-decoration: none;
}

.logo a:hover {
    color: var(--primary);
    text-decoration: none;
}

/* Navigation menu items */
#menu {
    display: flex;
    gap: var(--space-lg);
}

#menu a {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    padding: var(--space-sm) 0;
    border-bottom: 2px solid transparent;
    transition: all 0.15s ease;
}

#menu a:hover,
#menu a.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    text-decoration: none;
}

/* ---------- Main Content Area ---------- */
.main {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-xl) var(--space-lg);
}

/* ---------- Homepage Grid Layout ---------- */
/* Grid layout: 4 columns per row on desktop */
body.list .main {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-lg);
    align-items: stretch;
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-xl) var(--space-lg);
}

/* All direct children of main start as auto grid items */
body.list .main > * {
    grid-column: auto;
}

/* Hide inline style/script tags from grid layout */
body.list .main > style,
body.list .main > script {
    display: none !important;
}

/* Non-post elements span full width - high specificity override */
body.list .main > section.home-search,
body.list .main > article.first-entry,
body.list .main > article.home-info,
body.list .main > .pagination,
body.list .main > footer.page-footer,
body.list .main > div.home-brand,
body.list .main > .home-brand {
    grid-column: 1 / -1 !important;
    width: 100%;
}

/* Fallback for any other non-post elements */
body.list .main > *:not(.post-entry) {
    grid-column: 1 / -1 !important;
}

/* ---------- Home Brand Section ---------- */
.home-brand {
    text-align: center;
    padding: 3rem 1rem 1.5rem;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    grid-column: 1 / -1 !important;
    width: 100%;
}

.home-brand::before,
.home-brand::after {
    display: none !important;
}

.home-brand img {
    height: 100px;
    width: auto;
    max-width: 100%;
    filter: none;
    box-shadow: none;
}

/* ---------- Post Entry Cards ---------- */
.post-entry {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    padding: 0;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    min-height: 340px;
    max-height: 340px;
    height: 340px;
    display: flex;
    flex-direction: column;
}

.post-entry:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 32px rgba(0,0,0,0.15);
    border-color: var(--primary-light);
    background: var(--bg-card);
}

/* Cover image area - fixed height */
.post-entry figure,
.post-entry .entry-cover {
    width: 100%;
    height: 160px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    flex-shrink: 0;
}

.post-entry figure img,
.post-entry .entry-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* If no figure/cover, show gradient placeholder and push header down */
.post-entry:not(:has(figure)):not(:has(.entry-cover)) {
    background: linear-gradient(180deg,
        rgba(102,126,234,0.12) 0%,
        rgba(118,75,162,0.06) 160px,
        var(--bg-card) 160px,
        var(--bg-card) 100%
    );
}
/* Push header down on cards without cover image to align with covered cards - SPECIFICITY BOOST */
body.list .main .post-entry:not(:has(figure)):not(:has(.entry-cover)) .entry-header {
    padding-top: 176px !important;
    position: relative;
}
/* Content area */
.post-entry .entry-header {
    padding: 1rem 1.25rem 0.5rem;
    flex-shrink: 0;
}

.post-entry .entry-header h2 {
    font-size: 1rem;
    line-height: 1.4;
    margin: 0 0 0.5rem 0;
    font-weight: 600;
    border-bottom: none;
    padding-bottom: 0;
}

.post-entry .entry-header h2 a {
    color: var(--text-main);
    text-decoration: none;
}

.post-entry .entry-header h2 a:hover {
    color: var(--primary);
}

.post-entry .entry-content {
    padding: 0 1.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0.75rem;
    flex: 1 1 auto;
}

.post-entry .entry-footer {
    padding: 0.75rem 1.25rem 1rem;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.post-entry .entry-footer .post-tags {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.post-entry .entry-footer .post-tags a {
    background: var(--bg-code);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
}

.post-entry .entry-footer .post-tags a:hover {
    background: var(--primary);
    color: white;
}

/* Post meta (date, reading time) */
.post-entry .entry-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
}

.post-entry .entry-meta a {
    color: var(--text-muted);
}

/* Post tags */
.post-entry .entry-footer .tags a {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-code);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    margin-right: var(--space-xs);
    text-decoration: none;
}

.post-entry .entry-footer .tags a:hover {
    background: var(--primary-light);
    color: var(--primary);
}

/* ---------- Single Post Page ---------- */
.post-single {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--space-2xl);
    box-shadow: var(--shadow-sm);
}

.post-single .post-header {
    margin-bottom: var(--space-xl);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--border);
}

.post-single .post-title {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
    margin-bottom: var(--space-md);
}

.post-single .post-meta {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Post content typography */
.post-content {
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text-main);
}

.post-content p {
    margin-bottom: var(--space-lg);
}

.post-content ul,
.post-content ol {
    margin-bottom: var(--space-lg);
    padding-left: var(--space-xl);
}

.post-content li {
    margin-bottom: var(--space-sm);
}

/* Blockquotes - left border style */
.post-content blockquote {
    border-left: 3px solid var(--primary);
    background: var(--bg-sidebar);
    padding: var(--space-md) var(--space-lg);
    margin: var(--space-lg) 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-style: normal;
    color: var(--text-secondary);
}

.post-content blockquote p:last-child {
    margin-bottom: 0;
}

/* ---------- Table of Contents ---------- */
.toc {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-xl);
}

.toc summary {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-main);
    cursor: pointer;
    padding: var(--space-sm) 0;
}

.toc .inner {
    padding-top: var(--space-sm);
}

.toc ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.toc ul ul {
    padding-left: var(--space-md);
    margin-top: var(--space-xs);
}

.toc li {
    margin-bottom: var(--space-xs);
}

.toc a {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-decoration: none;
    display: block;
    padding: var(--space-xs) 0;
    border-left: 2px solid transparent;
    padding-left: var(--space-sm);
    transition: all 0.15s ease;
}

.toc a:hover {
    color: var(--primary);
    border-left-color: var(--primary);
    text-decoration: none;
}

/* ---------- Code Blocks ---------- */
/* Inline code */
.post-content code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--bg-code);
    padding: 0.15em 0.4em;
    border-radius: var(--radius-sm);
    color: var(--primary);
    font-weight: 500;
}

/* Code blocks */
.highlight {
    background: var(--bg-code);
    border-radius: var(--radius-md);
    margin: var(--space-lg) 0;
    overflow: hidden;
}

.highlight pre {
    background: transparent;
    padding: var(--space-lg);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.7;
}

.highlight code {
    background: transparent;
    padding: 0;
    color: inherit;
    font-weight: 400;
}

/* Code copy button */
.copy-code {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: var(--space-xs) var(--space-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.copy-code:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ---------- Tables ---------- */
.post-content table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--space-lg) 0;
    font-size: 0.9375rem;
}

.post-content th {
    background: var(--bg-sidebar);
    font-weight: 600;
    text-align: left;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 2px solid var(--border);
    color: var(--text-main);
}

.post-content td {
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-light);
    color: var(--text-secondary);
}

.post-content tr:hover td {
    background: var(--bg-hover);
}

/* ---------- Images ---------- */
.post-content img {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    max-width: 100%;
    height: auto;
}

.post-content figure {
    margin: var(--space-xl) 0;
}

.post-content figcaption {
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: var(--space-sm);
}

/* ---------- Breadcrumbs ---------- */
.breadcrumbs {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: var(--space-lg);
}

.breadcrumbs a {
    color: var(--text-muted);
}

.breadcrumbs a:hover {
    color: var(--primary);
}

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    justify-content: center;
    gap: var(--space-sm);
    margin-top: var(--space-2xl);
    padding-top: var(--space-xl);
    border-top: 1px solid var(--border);
}

.pagination a {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    text-decoration: none;
    transition: all 0.15s ease;
}

.pagination a:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    text-decoration: none;
}

/* ---------- Footer ---------- */
.footer {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: var(--space-xl) 0;
    margin-top: var(--space-2xl);
    font-size: 0.875rem;
    color: var(--text-muted);
}

.footer a {
    color: var(--text-secondary);
}

.footer a:hover {
    color: var(--primary);
}

/* ---------- Search Page ---------- */
.search-form {
    max-width: 600px;
    margin: 0 auto var(--space-2xl);
}

.search-form input {
    width: 100%;
    padding: var(--space-md) var(--space-lg);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: var(--font-body);
    background: var(--bg-card);
    color: var(--text-main);
    transition: border-color 0.15s ease;
}

.search-form input:focus {
    outline: none;
    border-color: var(--primary);
}

.search-form input::placeholder {
    color: var(--text-light);
}

/* ---------- Language Switcher (flags) ---------- */
.lang-switch {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

.lang-switch a {
    opacity: 0.6;
    transition: opacity 0.15s ease;
}

.lang-switch a:hover,
.lang-switch a.active {
    opacity: 1;
}

/* ---------- Share Buttons ---------- */
.share-buttons {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.share-buttons a {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    border-radius: 9999px;
    font-size: 0.8125rem;
    font-weight: 500;
    background: var(--bg-code);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    text-decoration: none;
    transition: all 0.15s ease;
}

.share-buttons a:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-1px);
    text-decoration: none;
}

/* ---------- Comments Section ---------- */
.comments-section {
    margin-top: var(--space-2xl);
    padding-top: var(--space-xl);
    border-top: 1px solid var(--border);
}

.comments-section h3 {
    font-size: 1.125rem;
    margin-bottom: var(--space-md);
}

/* ---------- Home Info / Profile ---------- */
.home-info {
    text-align: center;
    padding: 0.75rem 0;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.home-info .entry-header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 0.35rem;
    color: var(--text-main);
    line-height: 1.25;
}

.home-info .entry-content {
    font-size: 0.85rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0.35rem auto;
    line-height: 1.45;
}

/* ---------- Scroll to Top Button ---------- */
.top-link {
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-md);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all 0.15s ease;
}

.top-link:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.top-link svg {
    width: 20px;
    height: 20px;
}

/* ---------- Post Navigation (Prev/Next) ---------- */
.post-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
    margin-top: var(--space-2xl);
    padding-top: var(--space-xl);
    border-top: 1px solid var(--border);
}

.post-nav a {
    padding: var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    text-decoration: none;
    transition: all 0.15s ease;
}

.post-nav a:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
    text-decoration: none;
}

.post-nav .prev-post {
    text-align: left;
}

.post-nav .next-post {
    text-align: right;
}

.post-nav .post-nav-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-xs);
}

.post-nav .post-nav-title {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.9375rem;
}

/* ---------- Ads Integration ---------- */
.ad-container {
    margin: var(--space-xl) 0;
    padding: var(--space-md);
    background: var(--bg-sidebar);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    text-align: center;
}

/* ---------- Reading Progress Bar ---------- */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: var(--primary);
    z-index: 1000;
    transition: width 0.1s ease;
}

/* ---------- Homepage Spacing Fixes ---------- */
.home-search {
    margin-bottom: 0.5rem !important;
}

.home-info + article.post-entry,
.home-info + article.first-entry {
    margin-top: 0.5rem !important;
}

/* ---------- Main Background Cleanup ---------- */
body .main,
body.home .main,
body:has(.home-brand) .main,
.main:has(.home-brand) {
    background: transparent !important;
    background-color: transparent !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
}

body:has(.home-brand),
body.home,
html:has(.home-brand) {
    background: var(--bg) !important;
}

.home-brand,
.home-brand * {
    background: transparent !important;
    background-color: transparent !important;
    box-shadow: none !important;
    border: none !important;
}

/* ---------- Dark Mode Adjustments ---------- */
.dark .post-entry {
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.dark .post-entry:hover {
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

/* ---------- Responsive Breakpoints ---------- */
/* Tablet: 2 columns */
@media (max-width: 1024px) {
    body.list .main {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.25rem;
        padding: var(--space-lg) var(--space-md);
    }

    .home-brand {
        padding: 2rem 1rem 1rem;
    }

    .home-brand img {
        height: 80px;
    }

    .post-entry {
        min-height: 320px;
        max-height: 320px;
        height: 320px;
    }

    .post-entry figure,
    .post-entry .entry-cover {
        height: 140px;
    }

    .post-entry:not(:has(figure)):not(:has(.entry-cover)) {
        background: linear-gradient(180deg,
            rgba(102,126,234,0.12) 0%,
            rgba(118,75,162,0.06) 140px,
            var(--bg-card) 140px,
            var(--bg-card) 100%
        );
    }
}

/* Mobile: 1 column */
@media (max-width: 640px) {
    body.list .main {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: var(--space-md);
    }

    .home-brand {
        padding: 1.5rem 1rem 0.75rem;
    }

    .home-brand img {
        height: 60px;
    }

    .post-entry {
        min-height: auto;
        max-height: none;
        height: auto;
    }

    .post-entry figure,
    .post-entry .entry-cover {
        height: 180px;
    }

    .post-entry:not(:has(figure)):not(:has(.entry-cover)) {
        background: linear-gradient(180deg,
            rgba(102,126,234,0.12) 0%,
            rgba(118,75,162,0.06) 180px,
            var(--bg-card) 180px,
            var(--bg-card) 100%
        );
    }

    .post-single {
        padding: var(--space-lg);
    }

    .post-single .post-title {
        font-size: 1.5rem;
    }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.125rem; }
}

/* Extra small mobile adjustments */
@media (max-width: 480px) {
    body.list .main {
        padding: var(--space-sm);
        gap: 0.75rem;
    }

    .post-entry .entry-header {
        padding: 0.875rem 1rem 0.4rem;
    }

    .post-entry .entry-content {
        padding: 0 1rem;
        -webkit-line-clamp: 3;
    }

    .post-entry .entry-footer {
        padding: 0.6rem 1rem 0.875rem;
    }
}

/* ---------- Cover Image Fallbacks ---------- */
.post-entry figure img[src=''],
.post-entry figure img:not([src]),
.post-entry figure img[src='data:'],
.post-entry .entry-cover img[src=''],
.post-entry .entry-cover img:not([src]) {
    display: none !important;
}

.post-entry figure:has(img[src='']),
.post-entry figure:has(img:not([src])),
.post-entry figure:has(img[src='data:']) {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
}
