/* #1279: norge-dev styles — minimal, dark-mode-friendly post viewer */

/* ===== Custom Properties ===== */
:root {
    /* Light mode defaults */
    --color-bg: #f8f9fa;
    --color-surface: #ffffff;
    --color-text: #1a1a2e;
    --color-text-secondary: #6c757d;
    --color-text-muted: #adb5bd;
    --color-link: #0066cc;
    --color-link-hover: #004499;
    --color-border: #e9ecef;
    --color-shadow: rgba(0, 0, 0, 0.08);
    --color-shadow-hover: rgba(0, 0, 0, 0.15);
    --color-accent: #0066cc;
    --color-header-bg: #ffffff;
    --color-load-more-bg: #0066cc;
    --color-load-more-text: #ffffff;
    --color-load-more-hover: #004499;

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

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.5rem;
    --font-size-brand: 1.25rem;
    --line-height: 1.6;

    /* Layout */
    --border-radius: 0.5rem;
    --max-width: 1500px;
}

/* #1279: Dark mode via prefers-color-scheme for comfortable reading */
@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #0d1117;
        --color-surface: #161b22;
        --color-text: #e6edf3;
        --color-text-secondary: #8b949e;
        --color-text-muted: #484f58;
        --color-link: #58a6ff;
        --color-link-hover: #79c0ff;
        --color-border: #30363d;
        --color-shadow: rgba(0, 0, 0, 0.3);
        --color-shadow-hover: rgba(0, 0, 0, 0.5);
        --color-accent: #58a6ff;
        --color-header-bg: #161b22;
        --color-load-more-bg: #21262d;
        --color-load-more-text: #e6edf3;
        --color-load-more-hover: #30363d;
    }
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: var(--line-height);
    color: var(--color-text);
    background-color: var(--color-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--color-link);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--color-link-hover);
}

a:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
    border-radius: 2px;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ===== Site Header ===== */
/* #1291: Sticky header with glassmorphism — stays visible on scroll with
   a semi-transparent blurred background so content remains readable. */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: color-mix(in srgb, var(--color-header-bg) 75%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    /*border-bottom: 1px solid var(--color-border);*/
    padding: var(--spacing-md) 0;
}

/* #1322: Inner wrapper constrains header contents to the same max-width as
   .main-content, keeping the header background full-bleed while aligning
   brand and nav with the content area below. */
/* #1295: Flex layout to position brand left and nav links right. */
.site-header-inner {
    max-width: var(--max-width);
    width: 100%;
    margin: 0 auto;
    padding: 0 var(--spacing-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-brand {
    font-size: var(--font-size-brand);
    font-weight: 700;
    color: var(--color-text);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.site-brand:hover {
    color: var(--color-accent);
}

/* #1295: Right-side navigation in the header. */
.site-nav {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

/* #1295: Feedback link styled as a subtle text button matching the site
   typography — no border or background until hover. */
.nav-link {
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text-secondary);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--border-radius);
    transition: color 0.15s ease, background-color 0.15s ease;
}

.nav-link:hover {
    color: var(--color-text);
    background-color: var(--color-border);
}

.nav-link:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    max-width: var(--max-width);
    width: 100%;
    margin: 0 auto;
    padding: var(--spacing-xl) var(--spacing-lg);
}

/* ===== Post Feed ===== */
/* #1289: CSS Grid masonry layout. Uses grid-template-rows: masonry for
   native support (Firefox), with a JS polyfill for other browsers.
   auto-fit + minmax handles responsive column counts automatically. */
.post-feed {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    grid-template-rows: masonry;
    gap: var(--spacing-lg);
    /* #1290: Items must not stretch to fill their grid area — the polyfill
       adds extra span rows for vertical spacing, and stretch would consume
       that space by expanding the card to fill all spanned rows. */
    align-items: start;
}

/* ===== Post Card ===== */
.post-card {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    box-shadow: 0 1px 3px var(--color-shadow);
    /* #1289: margin-bottom removed — grid gap handles spacing between cards */
}

.post-card:hover {
    box-shadow: 0 4px 12px var(--color-shadow-hover);
    transform: translateY(-2px);
}

.post-card-image-link {
    display: block;
}

.post-card-image {
    width: 100%;
    height: auto;
    object-fit: cover;
    aspect-ratio: 16 / 9;
}

.post-card-body {
    padding: var(--spacing-md);
}

.post-card-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: var(--spacing-sm);
}

.post-card-title a {
    color: var(--color-text);
}

.post-card-title a:hover {
    color: var(--color-link);
}

.post-card-description {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    line-height: 1.5;
    margin-bottom: var(--spacing-sm);
}

.post-card-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    flex-wrap: wrap;
}

.post-card-source {
    font-weight: 500;
    color: var(--color-text-secondary);
}

.post-card-date {
    color: var(--color-text-muted);
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: var(--spacing-2xl) var(--spacing-lg);
    color: var(--color-text-secondary);
    font-size: var(--font-size-lg);
}

/* ===== Pagination ===== */
/* #1292: Same width as card items in the grid — no column spanning. */
.pagination {
    text-align: center;
    padding: var(--spacing-xl) 0;
}

.load-more-btn {
    display: inline-block;
    position: relative;
    padding: var(--spacing-sm) var(--spacing-xl);
    background-color: var(--color-load-more-bg);
    color: var(--color-load-more-text);
    border-radius: var(--border-radius);
    font-size: var(--font-size-base);
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.load-more-btn:hover {
    background-color: var(--color-load-more-hover);
    color: var(--color-load-more-text);
}

.load-more-btn:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* #1281: Loading spinner shown by htmx while the next page is fetched.
   Hidden by default; htmx adds .htmx-request to the element that triggers
   the request, which reveals the spinner and hides the label text. */
.load-more-spinner {
    display: none;
}

.htmx-request .load-more-label {
    visibility: hidden;
}

.htmx-request .load-more-spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--color-load-more-text);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

@keyframes spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* ===== Feedback Dialog ===== */
/* #1295: Native <dialog> modal for the feedback form. Uses ::backdrop for
   the overlay and relies on the dialog element's built-in focus trapping
   and Escape-to-close behaviour. */
/* #1300: The global reset (* { margin: 0 }) strips the UA stylesheet's
   default margin: auto that browsers apply to showModal() dialogs for
   centering. Re-applying margin: auto restores the browser's built-in
   top-layer centering without fighting it via position: fixed/inset. */
.feedback-dialog {
    margin: auto;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background-color: var(--color-surface);
    color: var(--color-text);
    padding: 0;
    max-width: 480px;
    width: 90vw;
    box-shadow: 0 8px 32px var(--color-shadow-hover);
}

/* #1300: Increased blur radius from 4px to 8px for a more pronounced
   frosted-glass effect that clearly separates the modal from the page. */
.feedback-dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.feedback-dialog-content {
    padding: var(--spacing-lg);
}

.feedback-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-lg);
}

.feedback-dialog-title {
    font-size: var(--font-size-xl);
    font-weight: 600;
    margin: 0;
}

.feedback-dialog-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--color-text-muted);
    padding: var(--spacing-xs);
    border-radius: var(--border-radius);
    transition: color 0.15s ease, background-color 0.15s ease;
}

.feedback-dialog-close:hover {
    color: var(--color-text);
    background-color: var(--color-border);
}

.feedback-dialog-close:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* ===== Feedback Form ===== */
.feedback-form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.form-label {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text-secondary);
}

.form-input {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--color-text);
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--spacing-sm) var(--spacing-md);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.form-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 25%, transparent);
}

.form-textarea {
    resize: vertical;
    min-height: 6rem;
}

/* #1295: Submit button styled consistently with the Load More button. */
.feedback-submit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: var(--spacing-sm) var(--spacing-xl);
    background-color: var(--color-load-more-bg);
    color: var(--color-load-more-text);
    border: none;
    border-radius: var(--border-radius);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease;
    align-self: flex-end;
}

.feedback-submit-btn:hover {
    background-color: var(--color-load-more-hover);
}

.feedback-submit-btn:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* #1295: Loading spinner for feedback submit, follows same pattern as
   the Load More spinner (#1281). Hidden by default; htmx adds
   .htmx-request to the indicator element during the request. */
.feedback-submit-spinner {
    display: none;
}

.htmx-request.feedback-submit-spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--color-load-more-text);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: var(--spacing-sm);
}

/* #1295: While spinner is active, make button non-interactive. */
.feedback-submit-btn:has(.htmx-request) {
    pointer-events: none;
    opacity: 0.7;
}

/* ===== Feedback Response ===== */
/* #1295: Success and error messages returned by the /api/feedback endpoint
   as HTML fragments swapped into the response container by htmx. */
.feedback-response:empty {
    display: none;
}

.feedback-success {
    background-color: color-mix(in srgb, #22c55e 15%, var(--color-surface));
    border: 1px solid color-mix(in srgb, #22c55e 40%, var(--color-border));
    color: var(--color-text);
    padding: var(--spacing-md);
    border-radius: var(--border-radius);
    font-size: var(--font-size-sm);
    text-align: center;
}

.feedback-error {
    background-color: color-mix(in srgb, #ef4444 15%, var(--color-surface));
    border: 1px solid color-mix(in srgb, #ef4444 40%, var(--color-border));
    color: var(--color-text);
    padding: var(--spacing-md);
    border-radius: var(--border-radius);
    font-size: var(--font-size-sm);
    margin-bottom: var(--spacing-md);
}

/* ===== About Dialog ===== */
/* #1328: Read-only modal for about.md content. Reuses the same native
   <dialog> pattern and close-button styles from the feedback dialog. */
.about-dialog {
    margin: auto;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background-color: var(--color-surface);
    color: var(--color-text);
    padding: 0;
    max-width: 640px;
    width: 90vw;
    box-shadow: 0 8px 32px var(--color-shadow-hover);
}

.about-dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.about-dialog-content {
    padding: var(--spacing-lg);
}

.about-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-lg);
}

.about-dialog-title {
    font-size: var(--font-size-xl);
    font-weight: 600;
    margin: 0;
}

/* #1328: Prose styles for rendered markdown inside the about dialog.
   Provides readable typography for headings, paragraphs, lists, links,
   code blocks, and horizontal rules. */
.about-dialog-body h1,
.about-dialog-body h2,
.about-dialog-body h3 {
    margin-top: var(--spacing-lg);
    margin-bottom: var(--spacing-sm);
    font-weight: 600;
    line-height: 1.3;
}

.about-dialog-body h1 { font-size: var(--font-size-xl); }
.about-dialog-body h2 { font-size: var(--font-size-lg); }
.about-dialog-body h3 { font-size: var(--font-size-base); }

.about-dialog-body h1:first-child,
.about-dialog-body h2:first-child,
.about-dialog-body h3:first-child {
    margin-top: 0;
}

.about-dialog-body p {
    margin-bottom: var(--spacing-md);
    line-height: var(--line-height);
}

.about-dialog-body ul,
.about-dialog-body ol {
    margin-bottom: var(--spacing-md);
    padding-left: var(--spacing-xl);
}

.about-dialog-body li {
    margin-bottom: var(--spacing-xs);
    line-height: var(--line-height);
}

.about-dialog-body a {
    color: var(--color-link);
}

.about-dialog-body a:hover {
    color: var(--color-link-hover);
}

.about-dialog-body code {
    font-family: "SFMono-Regular", "Cascadia Code", "Fira Code", "Consolas",
        monospace;
    font-size: 0.875em;
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    padding: 0.1em 0.3em;
}

.about-dialog-body pre {
    margin-bottom: var(--spacing-md);
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    overflow-x: auto;
}

.about-dialog-body pre code {
    background: none;
    border: none;
    padding: 0;
}

.about-dialog-body hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: var(--spacing-lg) 0;
}

.about-dialog-body blockquote {
    border-left: 3px solid var(--color-border);
    padding-left: var(--spacing-md);
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-md);
}

/* ===== 404 Not Found ===== */
/* #1336: Simplified 404 page — renders static/404.md content when available,
   otherwise shows a generic fallback. Centered layout with prose styles for
   the markdown content (reuses the same typography rules as .about-dialog-body). */
.not-found {
    text-align: center;
    padding: var(--spacing-2xl) var(--spacing-lg);
    max-width: 640px;
    margin: 0 auto;
}

.not-found-title {
    font-size: 5rem;
    font-weight: 800;
    color: var(--color-text-muted);
    line-height: 1;
    margin-bottom: var(--spacing-lg);
    letter-spacing: -0.04em;
}

/* #1336: Prose container for rendered 404.md markdown content. */
.not-found-content {
    text-align: left;
    margin-bottom: var(--spacing-xl);
}

.not-found-content h1,
.not-found-content h2,
.not-found-content h3 {
    margin-top: var(--spacing-lg);
    margin-bottom: var(--spacing-sm);
    font-weight: 600;
    line-height: 1.3;
}

.not-found-content h1 { font-size: var(--font-size-xl); }
.not-found-content h2 { font-size: var(--font-size-lg); }
.not-found-content h3 { font-size: var(--font-size-base); }

.not-found-content h1:first-child,
.not-found-content h2:first-child,
.not-found-content h3:first-child {
    margin-top: 0;
}

.not-found-content p {
    margin-bottom: var(--spacing-md);
    line-height: var(--line-height);
}

.not-found-content ul,
.not-found-content ol {
    margin-bottom: var(--spacing-md);
    padding-left: var(--spacing-xl);
}

.not-found-content li {
    margin-bottom: var(--spacing-xs);
    line-height: var(--line-height);
}

.not-found-content a {
    color: var(--color-link);
}

.not-found-content a:hover {
    color: var(--color-link-hover);
}

.not-found-content code {
    font-family: "SFMono-Regular", "Cascadia Code", "Fira Code", "Consolas",
        monospace;
    font-size: 0.875em;
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    padding: 0.1em 0.3em;
}

.not-found-content pre {
    margin-bottom: var(--spacing-md);
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    overflow-x: auto;
}

.not-found-content pre code {
    background: none;
    border: none;
    padding: 0;
}

.not-found-content hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: var(--spacing-lg) 0;
}

.not-found-content blockquote {
    border-left: 3px solid var(--color-border);
    padding-left: var(--spacing-md);
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-md);
}

/* #1336: Generic fallback when no 404.md is provided. */
.not-found-fallback {
    font-size: var(--font-size-lg);
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-xl);
    line-height: var(--line-height);
}

.not-found-home {
    display: inline-block;
    font-size: var(--font-size-base);
    font-weight: 500;
    padding: var(--spacing-sm) var(--spacing-xl);
    background-color: var(--color-load-more-bg);
    color: var(--color-load-more-text);
    border-radius: var(--border-radius);
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.not-found-home:hover {
    background-color: var(--color-load-more-hover);
    color: var(--color-load-more-text);
}

.not-found-home:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* ===== Responsive ===== */
/* #1289: Grid auto-fit handles column counts automatically, so no
   post-feed overrides are needed per breakpoint. Only spacing and
   card-level tweaks remain for small viewports. */
@media (max-width: 600px) {
    .main-content {
        padding: var(--spacing-md);
    }

    .site-header {
        padding: var(--spacing-sm) 0;
    }

    .site-header-inner {
        padding: 0 var(--spacing-md);
    }

    .post-card-image {
        aspect-ratio: 2 / 1;
    }

    /* #1295: Full-width dialog on small screens with reduced padding. */
    .feedback-dialog,
    .about-dialog {
        width: 95vw;
    }

    .feedback-dialog-content,
    .about-dialog-content {
        padding: var(--spacing-md);
    }

    /* #1295: Full-width submit button on mobile for easier tap target. */
    .feedback-submit-btn {
        align-self: stretch;
    }
}
