/*
 * 盒子主题 - 文章列表自适应网格（v2 · 2026-08-17）
 *
 * 核心修正：旧版用「视口媒体查询」(@media min-width:1920/2560/3440…) 增减列数，
 * 但容器被限宽 1940px 后，视口 3440 仍按 9 列算 → 9 列塞进 1940 容器 → 卡片挤成小条。
 *
 * 新方案：卡片列数由「卡片父容器的实际宽度」决定，而非浏览器视口。
 *   · 容器(.container)统一限宽 1940px 并居中（见 hezi-content-padding.css）；
 *   · 卡片父容器(.ajaxpager / .widget-ajaxpager)设为 CSS Grid，
 *     grid-template-columns: repeat(auto-fill, minmax(280px, 1fr))
 *     → 列数随容器宽度自动计算（容器上限 1940，故宽屏下列数/卡片尺寸稳定）；
 *   · 不依赖任何视口媒体查询增减列数。
 *
 * 作用范围：所有列表类页面（body:not(.single)）；排除固定宽侧边栏 .sidebar。
 */

/* 1. 列表页主容器左右留白（限宽 1940 + 居中由 hezi-content-padding.css 统一管，
      此处只补 padding，避免与父主题默认打架） */
body.home .container,
body.archive .container,
body.search .container,
body.category .container,
body.tag .container,
body.author .container,
body.date .container {
    padding-left: 20px !important;
    padding-right: 20px !important;
}

/* 2. 卡片父容器变网格：列数由容器宽度自动算（非视口） */
body:not(.single) .ajaxpager:has(.posts-item.card),
body:not(.single) .widget-ajaxpager:has(.posts-item.card) {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    align-items: start;
    /* 2026-08-17：清掉父主题 .posts-row 的 margin:-8px。
       旧 inline-block 百分比布局靠它把两侧卡片外边距抵消成齐边；
       网格改用 gap 后这 -8px 会让网格比 .content-layout 宽 16px，
       导致卡片右缘比顶部大图更贴右侧边栏、左缘更贴左侧抽屉（间距不一致）。
       特异性 (0,4,1) 压过 hezi-fullwidth.css 的 body:not(.single) .posts-row (0,2,1)。 */
    margin-left: 0 !important;
    margin-right: 0 !important;
}
/* 卡片交给 grid 分配，清掉旧的 inline-block 百分比宽度与间距 */
body:not(.single) .ajaxpager:has(.posts-item.card) > .posts-item.card,
body:not(.single) .widget-ajaxpager:has(.posts-item.card) > .posts-item.card {
    width: auto !important;
    margin: 0 !important;
}
/* 排序头 / 加载器等非卡片直接子元素占满整行 */
body:not(.single) .ajaxpager:has(.posts-item.card) > *:not(.posts-item),
body:not(.single) .widget-ajaxpager:has(.posts-item.card) > *:not(.posts-item) {
    grid-column: 1 / -1;
}

/* 3. 小屏：强制单列，保证卡片可读 */
@media (max-width: 560px) {
    body:not(.single) .ajaxpager:has(.posts-item.card),
    body:not(.single) .widget-ajaxpager:has(.posts-item.card) {
        grid-template-columns: 1fr;
    }
}

/* 4. 侧边栏排除：固定 311px，保持单列，不被上面的规则挤成多列 */
body:not(.single) .sidebar .posts-item.card,
body:not(.single) .sidebar .posts-item.list {
    width: 100% !important;
}
body:not(.single) .sidebar .posts-item.list {
    display: block !important;
    flex-direction: column !important;
}

/* 5. 入场淡入（呼应子主题动效；尊重系统"减少动态效果"设置） */
@keyframes heziGridIn {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: none; }
}
body:not(.single) .posts-item.card {
    animation: heziGridIn 0.45s ease both;
}
@media (prefers-reduced-motion: reduce) {
    body:not(.single) .posts-item.card { animation: none !important; }
}
