/* assets/css/custom.css */

/* --- Foundational Typography (HackMD/GitHub Style) --- */
:root {
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    --font-mono: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;

    /* Map to Main Theme Variables for Dark/Light Mode Compatibility */
    --color-fg-default: var(--fg);
    --color-fg-muted: var(--muted);
    --color-canvas-default: var(--bg);
    --color-canvas-subtle: var(--bg-secondary);
    --color-border-default: var(--border);
    --color-border-muted: var(--border-color);
    --color-accent-fg: var(--accent);
    --color-danger-fg: #cf222e;

    --font-size-body: 16px;
    --line-height-body: 1.6;
}

body {
    font-family: var(--font-sans);
    font-size: var(--font-size-body);
    line-height: var(--line-height-body);
    color: var(--color-fg-default);
    background-color: var(--color-canvas-default);
    margin: 0;
}

/* Ensure consistent font sizing across the board */
html {
    font-size: 16px;
}

/* Links */
a {
    color: var(--color-accent-fg);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    text-decoration: underline;
    color: var(--accent-hover);
}

/* --- Container & Layout Adjustments --- */
.container,
.wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
}

/* --- Post Content (HackMD/Markdown Body) --- */
/* We will wrap the post content in .markdown-body */

.markdown-body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.8;
    word-wrap: break-word;
    color: var(--fg);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--fg);
}

.markdown-body h1 {
    font-size: 2em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--color-border-muted);
}

.markdown-body h2 {
    font-size: 1.5em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--color-border-muted);
}

.markdown-body h3 {
    font-size: 1.25em;
}

.markdown-body p {
    margin-top: 0;
    margin-bottom: 16px;
}

.markdown-body blockquote {
    padding: 0 1em;
    color: var(--color-fg-muted);
    border-left: 0.25em solid var(--color-border-default);
    margin: 0 0 16px 0;
    background: var(--bg-secondary);
    border-radius: 0 4px 4px 0;
}

/* Lists */
.markdown-body ul,
.markdown-body ol {
    padding-left: 2em;
    margin-top: 0;
    margin-bottom: 16px;
}

/* Tables */
.markdown-body table {
    display: block;
    width: 100%;
    width: max-content;
    max-width: 100%;
    overflow: auto;
    border-spacing: 0;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.markdown-body table tr {
    background-color: var(--color-canvas-default);
    border-top: 1px solid var(--color-border-muted);
}

.markdown-body table tr:nth-child(2n) {
    background-color: var(--color-canvas-subtle);
}

.markdown-body table th,
.markdown-body table td {
    padding: 6px 13px;
    border: 1px solid var(--color-border-muted);
}

.markdown-body table th {
    font-weight: 600;
}

/* Code Blocks (The most important part for tech blogs) */
.markdown-body code,
.markdown-body kbd,
.markdown-body pre {
    font-family: var(--font-mono);
    font-size: 1em;
}

.markdown-body code {
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    background-color: rgba(175, 184, 193, 0.2);
    /* Semi-transparent for dark/light mode */
    border-radius: 6px;
}

.markdown-body pre {
    padding: 16px;
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    background-color: var(--bg-secondary);
    border-radius: 6px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}

.markdown-body pre code {
    display: inline;
    padding: 0;
    margin: 0;
    overflow: visible;
    line-height: inherit;
    word-wrap: normal;
    background-color: transparent;
    border: 0;
}

/* Images */
.markdown-body img {
    max-width: 100%;
    box-sizing: border-box;
    background-color: transparent;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Horizontal Rule */
.markdown-body hr {
    height: 0.25em;
    padding: 0;
    margin: 24px 0;
    background-color: var(--color-border-default);
    border: 0;
}

/* --- Layout Specific Fixes --- */

/* Fix main article width relative to TOC */
.article-layout {
    display: flex;
    gap: 2rem;
    max-width: 1200px;
    /* Force consistent width */
    margin: 0 auto;
    padding: 2rem 1rem;
}

.article-main {
    flex: 1;
    min-width: 0;
    /* Important for flex items to shrink properly */
}

/* Sidebar adjustments */
.article-sidebar {
    width: 250px;
    flex-shrink: 0;
    position: sticky;
    top: 6rem;
    /* Adjust for fixed header */
    height: calc(100vh - 8rem);
    overflow-y: auto;
    display: block;
    /* Ensure it's visible on desktop */
}

/* --- Font Consistency Fixes for Tag/Search/Category Pages --- */
/* Force all page headers to be consistent */
.page-header .page-title {
    font-size: 2.5rem !important;
    font-weight: 900;
}

.page-header .page-description {
    font-size: 1.1rem !important;
}

/* Ensure three-column layout is consistent */
.three-column-container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .article-layout {
        flex-direction: column;
    }

    .article-sidebar {
        display: none;
        /* Hide TOC on mobile by default or move to top */
        width: 100%;
        height: auto;
        position: relative;
    }

    .three-column-container {
        flex-direction: column;
    }

    .left-sidebar,
    .right-sidebar {
        display: none !important;
        /* Simplified mobile view */
    }
}



/* --- Form Elements Overrides (Robust) --- */
.search-input,
.filter-select {
    width: 100% !important;
    height: 38px !important;
    /* Fixed standard height */
    padding: 6px 12px !important;
    border: 1px solid #d0d7de !important;
    /* Neutral grey border */
    border-radius: 6px !important;
    /* Standard rounded corners (not pill) */
    background-color: #ffffff !important;
    color: #000000 !important;
    font-size: 14px !important;
    line-height: 20px !important;
    box-shadow: none !important;
    /* Remove weird glows */
    outline: none !important;
    appearance: none !important;
    /* Reset browser styles */
    margin: 0 !important;
    /* Reset margins */
    box-sizing: border-box !important;
    /* Ensure padding doesn't affect width/height */
}

/* Dropdown arrow fix */
.filter-select {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%23000000' d='M4.427 9.573l3.396-3.396a.25.25 0 01.354 0l3.396 3.396a.25.25 0 01-.177.427H4.604a.25.25 0 01-.177-.427z' transform='rotate(180 8 8)'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 8px center !important;
    padding-right: 32px !important;
}

.search-input:focus,
.filter-select:focus {
    border-color: #0969da !important;
    box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.3) !important;
    background-color: #ffffff !important;
}

.filter-select option {
    background-color: #ffffff;
    color: #000000;
}

/* Button Fix */
.btn-clear {
    width: 100%;
    margin-top: 12px;
    padding: 8px 16px;
    background-color: transparent !important;
    border: 1px solid var(--color-danger-fg, #cf222e) !important;
    color: var(--color-danger-fg, #cf222e) !important;
    border-radius: 6px !important;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s cubic-bezier(0.3, 0, 0.5, 1);
}

.btn-clear:hover {
    background-color: var(--color-danger-fg, #cf222e) !important;
    color: #ffffff !important;
}

.footer-social {
    margin-top: 12px;
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.footer-link {
    color: var(--text-muted, #6e7781);
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.2s ease, background 0.2s ease;
}

.footer-link:hover {
    color: var(--accent-color, #0969da);
    background: var(--bg-hover, #f0f2f4);
    text-decoration: none;
}