/* --- 背面の固定 --- */
body.p-modal-open { overflow: hidden !important; }

/* --- 検索窓（サイドバー等） --- */
.p-sidebar-search { padding: 25px 0px 15px 0px; position: relative; }
.p-search-form {
    display: flex; background: #fff; border: 1px solid #ccc;
    border-radius: 5px; overflow: hidden; height: 38px;
}
.p-search-form input { border: none; outline: none; padding: 0 12px; width: 100%; font-size: 14px; }
.p-search-form button { background: none; border: none; cursor: pointer; padding: 0 10px; }

/* --- モーダル外枠 --- */
.p-search-overlay {
    display: none; position: fixed; top: 0; left: 220px;
    width: calc(100% - 220px); height: 100vh;
    background: rgba(0, 0, 0, 0.8); z-index: 10000;
}

/* --- モーダル本体 --- */
.p-search-modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 95%;
    max-width: 1200px;
    height: 95vh;
    background: #f1f1f1;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box; /* 余白を含めてサイズを計算する */
}

/* ヘッダー */
.p-search-modal-header {
    flex: 0 0 60px; padding: 0 20px; background: #fff;
    display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #ddd;
}
.p-close-btn { background: none; border: none; font-size: 45px; cursor: pointer; color: #999; line-height: 1; }

/* 関連タグエリア */
#p-related-tag-area { background: #fff; border-bottom: 1px solid #ddd; padding: 10px 0; }
.p-related-tag-wrapper { 
    display: flex; 
    align-items: center; 
    padding: 8px 20px; 
    gap: 15px; 
}
.p-related-tag-label { 
    font-size: 12px; 
    font-weight: bold; 
    color: #666; 
    white-space: nowrap; 
}
.p-related-tag-scroll { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 8px; 
    align-items: center;
}

/* 全タグ一覧（#入力時） */
.p-all-tags-container { padding: 20px; width: 100%; box-sizing: border-box; }
.p-all-tags-label { font-weight: bold; color: #191970; margin-bottom: 15px; border-bottom: 1px solid #ddd; padding-bottom: 10px; }
.p-all-tags-list { display: flex !important; flex-wrap: wrap !important; gap: 10px; }

/* 共通タグボタン */
.p-selectable-tag {
    display: inline-flex; align-items: center; background: #fdfdfd;
    border: 1px solid #191970; color: #191970; padding: 6px 14px;
    border-radius: 20px; font-size: 13px; font-weight: 500;
    cursor: pointer; transition: 0.2s; white-space: nowrap;
}
.p-selectable-tag:hover { background: #191970; color: #fff; }

/* ページ全体の余白対策（既存のまま維持） */
@media (min-width: 768px) {
    .l-container { max-width: 1200px !important; margin: 0 auto !important; }
}

/* ページネーション */
.p-pagination-area, .p-cat-page-adjust { 
    flex: 0 0 60px; background: transparent; display: flex; justify-content: center; align-items: center; padding: 20px 0;
}
.p-page-btn { padding: 8px 16px; margin: 0 5px; border: 1px solid #bbb; background: #f8f8f8; cursor: pointer; border-radius: 4px; }
.p-page-btn.is-active { background: #191970; color: #fff; border-color: #191970; }

/* スマホでの検索特有の微調整 */
@media (max-width: 768px) {
    .p-search-overlay { left: 0; width: 100%; }
    .p-related-tag-wrapper { flex-direction: column; align-items: flex-start; padding: 10px 15px; gap: 5px; }
}


/* PC用：検索結果の「枠ゾーン」そのものに隙間を作る */
@media screen and (min-width: 769px) {
    #p-search-results-list {
        /* すでに 4列(grid) の設定がある場合はそのまま */
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 25px;

        /* ★ここ！枠ゾーンの壁とカードの間に「隙間」を作る */
        padding: 40px 60px; 
        
        /* 100%から余白分を差し引いて計算させる */
        box-sizing: border-box; 
        
        /* 中身が多くなっても余白を保ったままスクロールさせる */
        overflow-y: auto;
    }
}

/* --- 検索モーダル内だけの特殊レイアウト（記事枠.cssへ） --- */
@media screen and (min-width: 769px) {
    /* 並び方のルール：4列にする */
    #p-search-results-list {
        display: grid;
        grid-template-columns: repeat(4, 1fr); 
        gap: 25px;
        /* ここに「枠ゾーンの周りの余白」も書いちゃう */
        padding: 40px 60px;
        box-sizing: border-box;
    }

    /* カードの形：縦長にする */
    #p-search-results-list .p-item-card {
        flex-direction: column;
        height: auto;
    }

    #p-search-results-list .p-item-image {
        width: 100%;
        aspect-ratio: 3 / 2;
    }

    #p-search-results-list .p-item-title {
        font-size: 17px;
        line-height: 1.5;
    }
}

/* --- 検索結果の配置（検索.css） --- */
@media screen and (min-width: 769px) {
    #p-search-results-list {
        display: grid;
        grid-template-columns: repeat(4, 1fr); /* 4列に並べる指令 */
        gap: 25px;
        
        /* モーダルの壁から枠を離すための「内側の余白」 */
        padding: 40px 60px; 
        box-sizing: border-box;
        
        overflow-y: auto;
        flex-grow: 1; /* 余ったスペースを埋める */
    }
}

/* スマホ時：他と揃えて2列にする */
@media screen and (max-width: 768px) {
    #p-search-results-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
        padding: 15px 10px; /* スマホ用の程よい余白 */
    }
}