/* Layout Grid & Post Previews - Ported from Danbooru */

/* =========================================
   Post Gallery Grid
   ========================================= */
.post-gallery-inline .posts-container {
    overflow-x: auto;
    white-space: nowrap;
}

.post-gallery-grid .posts-container {
    display: grid;
    gap: 10px;
    /* Default gap added for WP theme */
}

.post-gallery-grid .post-preview-container {
    display: flex;
    align-items: flex-end;
    /* Ensure images sit at the bottom */
    justify-content: center;
    /* Center content in grid cell */
}

/* Fallback for posts without thumbnail */
.post-preview-image.no-preview {
    width: 100%;
    min-height: 180px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--muted-text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

/* Default to 180px style for now */
.post-gallery-grid .posts-container {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

@media screen and (min-width: 660px) {

    /* Fixed heights removed to allow soft-cropped images (variable aspect ratio) to fit naturally.
       This results in a row-based grid where height adapts to the tallest image in the row.
    */
    .post-gallery-grid.post-gallery-150 .post-preview-container {
        /* height: 150px; */
        min-height: 150px;
    }

    .post-gallery-grid.post-gallery-180 .post-preview-container {
        /* height: 180px; */
        min-height: 180px;
    }

    .post-gallery-grid.post-gallery-225 .post-preview-container {
        /* height: 225px; */
        min-height: 225px;
    }
}

@media screen and (max-width: 660px) {
    .post-gallery-grid .posts-container {
        gap: 0.25rem;
        grid-template-columns: repeat(2, auto);
        /* 2 columns on mobile default */
    }
}

/* =========================================
   Post Previews
   ========================================= */
article.post-preview {
    margin: 0;
}

article.post-preview .post-preview-link {
    display: block;
    position: relative;
    margin: 0 auto;
}

article.post-preview .desc {
    font-size: var(--text-sm);
    margin-bottom: 0;
    text-align: center;
    margin-top: 5px;
}

.post-preview-image {
    max-width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
    /* Ensure aspect ratio is kept */
}

/* Fixed Sizes logic */
.post-preview-fit-fixed {
    display: inline-flex;
    flex-direction: column;
    place-items: center;
}

/* Image borders for statuses */
.post-preview .post-preview-image {
    border: 2px solid transparent;
}

.post-preview.post-status-has-children .post-preview-image {
    border-color: var(--preview-has-children-color);
}

.post-preview.post-status-has-parent .post-preview-image {
    border-color: var(--preview-has-parent-color);
}

.post-preview.post-status-deleted .post-preview-image {
    border-color: var(--preview-deleted-color);
}

.post-preview.post-status-pending .post-preview-image,
.post-preview.post-status-flagged .post-preview-image {
    border-color: var(--preview-pending-color);
}

@media screen and (max-width: 660px) {
    .post-preview-image {
        border: none !important;
    }
}

/* =========================================
   General WP Layout Structure
   ========================================= */
body {
    padding: 10px;
}

#page {
    max-width: 100%;
    margin: 0 auto;
}

/* =========================================
   Navbar Styles
   ========================================= */
header#top {
    margin-top: 0.5rem;
    padding-bottom: 0;
    border-bottom: none;
    margin-bottom: 20px;
}

.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.mx-8 {
    margin-left: 2rem;
    margin-right: 2rem;
}

.gap-2 {
    gap: 0.5rem;
}

.inline-flex {
    display: inline-flex;
}

#app-name-header {
    font-size: var(--text-xxl);
}

#app-name {
    font-family: var(--header-font);
    font-weight: bold;
    text-decoration: none;
    color: var(--header-color);
}

#main-menu {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 0 1.25rem;
}

#main-menu a {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: var(--link-color);
    font-weight: bold;
}

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

#main-menu .current_page_item>a,
#main-menu .current-menu-item>a,
#main-menu .current {
    background: var(--subnav-menu-background-color);
    border-radius: 4px;
}

#subnav-menu {
    background: var(--subnav-menu-background-color);
    padding: 0.5rem 1.25rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

#subnav-menu a {
    margin-right: 1rem;
    color: var(--link-color);
    text-decoration: none;
}

@media screen and (max-width: 660px) {
    .hide-on-mobile {
        display: none;
    }

    #main-menu {
        background-color: var(--responsive-menu-background-color);
        flex-direction: column;
        align-items: flex-start;
    }

    #nav {
        display: none;
        /* Hidden by default on mobile, toggled via JS */
    }

    #nav.open {
        display: block;
    }
}

#bottom {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--grey-2);
    text-align: center;
    font-size: 0.8rem;
    color: var(--muted-text-color);
    width: 100%;
    /* Should span full width if in flex column, but it's outside #page content usually? Wait, index.php has footer INSIDE #page. */
}

/* Page Layout (Sidebar + Content) */
#page {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-start;
}

#sidebar {
    width: 18rem;
    /* approx 280px */
    flex-shrink: 0;
    margin-right: 20px;
}

#content {
    flex-grow: 1;
    min-width: 0;
    /* Fix flex child overflow issues */
}

/* Sidebar Sections */
aside section {
    margin-bottom: 2em;
}

aside h2 {
    font-size: var(--text-md);
    margin-bottom: 0.5em;
    border-bottom: 1px solid var(--grey-2);
}

#search-box-form {
    display: flex;
}

#search-box-form input {
    width: 100%;
    margin-right: 5px;
}

#search-box-form button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 5px;
}

#search-box-form button svg {
    width: 1em;
    height: 1em;
    fill: var(--text-color);
}

@media screen and (max-width: 660px) {
    #page {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        margin-right: 0;
        margin-bottom: 20px;
    }
}

.posts-container {
    margin-top: 20px;
}