/**
 * 動的検索機能用CSS
 * 静的/動的サイト対応JavaScript検索のスタイル
 */

/* アニメーション設定定数 */
:root {
    --search-animation-fast: 0.15s; /* 150ms - 高速アニメーション */
    --search-animation-medium: 0.25s; /* 250ms - 中速アニメーション */
    --search-easing: ease; /* イージング関数 */
}

/* 新しい検索バーコンテナ */
.search-bar-container {
    position: relative;
    margin-top: 8px;
    margin-bottom: 24px;
    display: flex;
    align-items: stretch;
    border: 2px solid #e3e3e3;
    border-radius: 8px;
    background: white;
    transition: border-color var(--search-animation-fast) var(--search-easing);
    overflow: visible; /* ドロップダウン表示のため変更 */
}

/* キーワード検索フィールドのコンテナ */
.search-input-container {
    position: relative;
    flex: 1;
    border-right: 1px solid #e3e3e3;
    min-width: 0; /* flexアイテムが縮小可能にする */
    display: flex;
    align-items: center;
}

.search-bar-container:focus-within,
.search-bar-container.dropdown-focused,
.search-input-container:focus-within {
    border-color: #08B15B;
    box-shadow: 0 0 0 1px rgba(8, 177, 91, 0.1);
}

#dynamic-search-input {
    flex: 1;
    padding: 4px 16px;
    border: none;
    background: transparent;
    font-size: 16px;
    outline: none;
    min-height: 44px;
    transition: background-color var(--search-animation-fast) var(--search-easing);
}

/* キーワードクリアボタン */
.search-input-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 6px;
    cursor: pointer;
    color: #666;
    font-size: 14px;
    border-radius: 50%;
    transition: all var(--search-animation-fast) var(--search-easing);
    z-index: 2;
}

.search-input-clear:hover {
    background-color: #f0f0f0;
    color: #333;
}

.search-input-clear:active {
    background-color: #e0e0e0;
}

/* セレクトコンテナ */
.select-container {
    position: relative;
    flex: 1;
    border-right: 1px solid #e3e3e3;
    min-width: 0; /* flexアイテムが縮小可能にする */
    overflow: visible; /* ドロップダウン表示のためvisibleに変更 */
}

.select-container:last-of-type {
    border-right: none;
}

.select-container select {
    display: none;
}

.select-display {
    padding: 4px 28px 4px 16px;
    border: none;
    background: transparent;
    font-size: 14px;
    cursor: pointer;
    min-height: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    position: relative;
    transition: none;
    color: #666;
    width: 100%;
    box-sizing: border-box; /* paddingを含めて幅計算 */
}

/* テキストオーバーフロー制御用の内部要素 */
.select-display-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.select-display::after {
    content: '▼';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    color: #999;
    transition: transform var(--search-animation-fast) var(--search-easing);
    pointer-events: none;
}

.select-display.active::after {
    transform: translateY(-50%) rotate(180deg);
}

/* ドロップダウンオプション */
.select-options {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    z-index: 9999;
    display: none;
    overflow: hidden; /* 角丸を維持するため */
}

/* スクロール可能な選択肢エリア */
.select-options-scroll {
    max-height: 200px;
    overflow-y: auto;
}

.select-option {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color var(--search-animation-fast) var(--search-easing);
}

.select-option:hover {
    background-color: #f8f9fa;
}

.select-option input[type="checkbox"] {
    accent-color: #08B15B;
    width: 16px;
    height: 16px;
    margin: 0;
}

.select-option:last-child {
    border-bottom: none;
}

/* クリア機能のスタイル */
.select-clear-section {
    padding: 0;
}

.select-separator {
    height: 1px;
    background-color: #e3e3e3;
    margin: 0;
}

.select-clear-button {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    text-align: center;
    transition: all var(--search-animation-fast) var(--search-easing);
    background-color: #f8f9fa;
}

.select-clear-button:hover {
    background-color: #e9ecef;
    color: #495057;
}

/* 選択されたタグ表示 */
.selected-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.selected-tag {
    background: #08B15B;
    color: white;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.selected-tag .remove {
    cursor: pointer;
    font-weight: bold;
    opacity: 0.8;
}

.selected-tag .remove:hover {
    opacity: 1;
}

/* 検索ボタン */
.search-button {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    margin-top: -2px;
    margin-bottom: -2px;
    background: #08B15B;
    color: white;
    border: none;
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
    cursor: pointer;
    min-height: 44px;
    transition: background-color var(--search-animation-fast) var(--search-easing);
    flex: 0 0 auto;
}

.search-button:hover {
    background: #069A4E;
}

.search-button i {
    font-size: 16px;
}


/* 検索結果コンテナ */
.search-results-container { 
    flex: 1; 
}

/* 検索フィルターフォーム */
.search-filter-form { 
    border: 1px solid #e2e2e2; 
    padding: 1.25em 1.25em 1.5em; 
    background: #fff; 
    box-shadow: 0 2px 4px rgba(0,0,0,.04); 
    border-radius: 4px; 
}

.search-filter-form h3.filter-heading { 
    font-size: 16px; 
    margin: 0 0 1em; 
    font-weight: 600; 
    color: #08B15B; 
    letter-spacing: .05em; 
}

.search-filter-form ul.filter-list { 
    list-style: none; 
    margin: 0 0 1em; 
    padding: 0; 
    max-height: 260px; 
    overflow: auto; 
}

.search-filter-form ul.filter-list li { 
    margin: 0 0 .5em; 
    font-size: 14px; 
}

.search-filter-form ul.filter-list label { 
    cursor: pointer; 
    display: flex; 
    gap: .5em; 
    align-items: center; 
    line-height: 1.3; 
}

.search-filter-form input[type=checkbox] { 
    accent-color: #08B15B; 
    width: 16px; 
    height: 16px; 
}

/* フィルターアクション */
.filter-actions,
.search-filter-form .filter-actions {
    margin-top: 16px;
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 14px;
}

.filter-actions button[type="submit"],
.search-filter-form button {
    background: #08B15B;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color var(--search-animation-fast) var(--search-easing);
    font-size: 14px;
}

.filter-actions button[type="submit"]:hover,
.search-filter-form button:hover {
    background: #069A4E;
    opacity: .85;
}

.search-filter-form #reset-filters { 
    background: #08B15B; 
    color: #fff; 
    border: none; 
    padding: .45em 1.2em; 
    font-size: 14px; 
    border-radius: 4px; 
    cursor: pointer;
}

.search-filter-form #reset-filters:hover { 
    background: #069A4E;
}

.search-filter-form #reset-filters:disabled { 
    background: #ccc; 
    cursor: not-allowed; 
    opacity: 0.6;
}

/* 検索結果メタ情報 */
.search-results-container .results-meta { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 1em; 
    align-items: center; 
    margin: 0 0 1.2em; 
}

.search-results-container .results-meta .results-count { 
    margin: 0; 
    font-size: 14px; 
}

.search-results-container .results-meta .active-filters p { 
    margin: 0; 
    font-size: 12px; 
    color: #08B15B; 
}

/* ローディング状態 */
.search-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #08B15B;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* エラー表示 */
.search-error {
    text-align: center;
    padding: 40px 20px;
    color: #dc3545;
    font-weight: 500;
}

.no-results {
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-size: 16px;
}

/* フィルターセクションの拡張 */
.filter-heading {
    position: relative;
    cursor: pointer;
    transition: color var(--search-animation-fast) var(--search-easing);
}

.filter-heading::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 8px solid #666;
    transition: transform var(--search-animation-fast) var(--search-easing);
    display: none;
}

.filter-heading.open::after {
    transform: translateY(-50%) rotate(180deg);
}

/* モバイル対応 */
@media (max-width: 768px) {
    .search-button {
        /* 検索ボタンのパディングを少し調整 */
        padding: 0 12px;
    }
    
    .filter-heading::after {
        display: block;
    }
    
    .filter-list {
        display: none;
        margin-top: 12px;
    }
    
    .search-filter-form ul.filter-list { 
        max-height: none; 
        display: grid; 
        grid-template-columns: repeat(3,minmax(0,1fr)); 
        gap: .5em 1em; 
    }
    
    .search-filter-form ul.filter-list li { 
        margin: 0; 
    }
}

/* タブレット表示（2列） - フォントサイズを少し大きく */
@media (max-width: 1024px) and (min-width: 601px) {
    .category-posts.search-results {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .category-posts.search-results .box h3 {
        font-size: 1rem; /* タイトルを通常サイズに */
    }
    
    .category-posts.search-results .box .summary {
        font-size: 0.9rem; /* 概要文を少し大きく */
    }
    
    .category-posts.search-results .box .cats .cat-item,
    .category-posts.search-results .box .tags .tag-item {
        font-size: 0.8rem; /* カテゴリ・タグを少し大きく */
    }
}

@media (max-width: 600px) {
    .search-filter-form ul.filter-list { 
        grid-template-columns: repeat(2,minmax(0,1fr)); 
    }
    
    /* モバイル表示（1列） - フォントサイズを大きく */
    .category-posts.search-results {
        grid-template-columns: 1fr;
        gap: 1.5em;
    }
    
    .category-posts.search-results .box h3 {
        font-size: 1.1rem; /* タイトルを大きく */
        line-height: 1.4;
    }
    
    .category-posts.search-results .box .summary {
        font-size: 1rem; /* 概要文を通常サイズに */
        line-height: 1.5;
    }
    
    .category-posts.search-results .box .cats .cat-item,
    .category-posts.search-results .box .tags .tag-item {
        font-size: 0.85rem; /* カテゴリ・タグを読みやすく */
    }
}

@media (max-width: 425px) {
    .search-filter-form ul.filter-list { 
        grid-template-columns: repeat(1,minmax(0,1fr)); 
    }
}

/* 検索結果のアニメーション（動的検索時のみ） */
#search-results-dynamic .box {
    animation: fadeInUp 0.3s ease forwards;
    opacity: 0;
    transform: translateY(20px);
}

#search-results-dynamic .box:nth-child(1) { animation-delay: 0.1s; }
#search-results-dynamic .box:nth-child(2) { animation-delay: 0.2s; }
#search-results-dynamic .box:nth-child(3) { animation-delay: 0.3s; }
#search-results-dynamic .box:nth-child(4) { animation-delay: 0.4s; }
#search-results-dynamic .box:nth-child(5) { animation-delay: 0.5s; }
#search-results-dynamic .box:nth-child(6) { animation-delay: 0.6s; }

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ページネーションのスタイル調整 */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    list-style: none;
    padding: 0;
    margin: 32px 0;
}

.pagination li {
    display: block;
}

.pagination a {
    display: block;
    padding: 10px 16px;
    background: white;
    color: #08B15B;
    text-decoration: none;
    border: 1px solid #d0d5dd;
    border-radius: 4px;
    transition: all var(--search-animation-fast) var(--search-easing);
}

.pagination a:hover {
    background: #f8f9fa;
    border-color: #08B15B;
}

.pagination .active a {
    background: #08B15B;
    color: white;
    border-color: #08B15B;
}

.pagination .active a:hover {
    background: #069A4E;
}

/* ==============================================
   共通レイアウト（SERVICE/WORKS共通）
   ============================================== */

/* 動的検索共通レイアウト（SERVICE/WORKS共通） */
.dynamic-search-layout { 
    display: flex; 
    gap: 3em; 
}

.dynamic-search-layout .search-filter { 
    width: 240px; 
    flex: 0 0 240px; 
}

@supports (position:sticky){
    .dynamic-search-layout .search-filter { 
        position: sticky; 
        top: calc(var(--fix-header-h, 80px) + 15px); 
        align-self: flex-start; 
    }
}

.dynamic-search-layout .search-results-container {
    flex: 1;
    min-width: 0;
}

/* レスポンシブ調整 */
@media (max-width: 1000px) {
    .dynamic-search-layout { 
        display: block; 
    }
    
    .dynamic-search-layout .search-filter { 
        width: auto; 
        margin-bottom: 2em; 
        position: static; 
    }
    
    /* 新しい検索バーのレスポンシブ対応 */
    .search-bar-container {
        flex-direction: column;
    }
    
    /* 縦型レイアウト時は縦線を横線に変更 */
    .search-input-container {
        border-right: none;
        border-bottom: 1px solid #e3e3e3;
    }
    
    .select-container {
        min-width: auto;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #e3e3e3;
    }
    
    .select-container:last-child {
        border-bottom: none;
    }
    .search-button {
        border-top-right-radius: unset;
        border-bottom-left-radius: 8px;
        border-bottom-right-radius: 8px;
        margin: 0 -2px -1px -2px;
    }
}

/* モバイル用の追加レスポンシブ */
@media (max-width: 600px) {
    .search-bar-container {
        gap: 6px;
        padding: 6px;
    }
    
    .search-button,
    .search-clear,
    .reset-button {
        min-height: 40px;
    }
    
    #dynamic-search-input {
        min-height: 40px;
        font-size: 16px; /* iOSのズーム防止 */
    }
    
    .select-display {
        min-height: 40px;
        font-size: 16px; /* iOSのズーム防止 */
    }
}

/* ==============================================
   動的検索ページ専用スタイル追加
   ============================================== */

/* 動的ページネーション調整 */
#pagination-dynamic .page-numbers {
    display: flex;
    justify-content: center;
    gap: 8px;
    list-style: none;
    padding: 0;
    margin: 32px 0;
}

#pagination-dynamic .page-numbers li {
    display: block;
}

#pagination-dynamic .page-numbers a {
    display: block;
    padding: 10px 16px;
    background: white;
    color: #08B15B;
    text-decoration: none;
    border: 1px solid #d0d5dd;
    border-radius: 4px;
    transition: all var(--search-animation-fast) var(--search-easing);
}

#pagination-dynamic .page-numbers a:hover {
    background: #f8f9fa;
    border-color: #08B15B;
}

#pagination-dynamic .page-numbers .current {
    background: #08B15B;
    color: white;
    border-color: #08B15B;
    padding: 10px 16px;
    border-radius: 4px;
    border: 1px solid #08B15B;
}

/* 検索結果のグリッドレイアウト（共通） */
.category-posts.search-results, 
#search-results-static.category-posts.search-results,
#search-results-dynamic.category-posts.search-results { 
    display: grid !important; 
    grid-template-columns: repeat(3, 1fr); 
    gap: 2em 1.5em; 
}

/* 3列表示時のフォントサイズ調整 */
.category-posts.search-results .box h3 {
    font-size: 0.9rem; /* タイトルを少し小さく */
    line-height: 1.3;
    margin-bottom: 0.5rem;
}

.category-posts.search-results .box .summary {
    font-size: 0.85rem; /* 概要文を小さく */
    line-height: 1.4;
    margin-bottom: 0.75rem;
}

.category-posts.search-results .box .cats .cat-item,
.category-posts.search-results .box .tags .tag-item {
    font-size: 0.75rem; /* カテゴリ・タグを小さく */
    padding: 0.25rem 0.5rem;
}

.category-posts.search-results .box {
    /* Material-like elevation 2 */
    box-shadow:
        0px 2px 1px -1px rgba(0,0,0,0.2),
        0px 1px 1px 0px rgba(0,0,0,0.14),
        0px 1px 3px 0px rgba(0,0,0,0.12);
    border-radius: 8px;
    overflow: hidden;
    transition: box-shadow var(--search-animation-fast) var(--search-easing);
}

.category-posts.search-results .box:hover {
    box-shadow:
        0px 3px 3px -2px rgba(0,0,0,0.2),
        0px 3px 4px 0px rgba(0,0,0,0.14),
        0px 1px 8px 0px rgba(0,0,0,0.12);
}

/* レスポンシブ：2カラム */
@media (max-width: 1000px) {
    .category-posts.search-results, 
    #search-results-static.category-posts.search-results,
    #search-results-dynamic.category-posts.search-results { 
        grid-template-columns: repeat(2, 1fr) !important; 
        gap: 1.5em; 
    }
}

/* レスポンシブ：1カラム */
@media (max-width: 600px) {
    .category-posts.search-results, 
    #search-results-static.category-posts.search-results,
    #search-results-dynamic.category-posts.search-results { 
        grid-template-columns: 1fr !important; 
        gap: 1.2em; 
    }
}

/* 動的検索ページ共通スタイル調整 */
.service .search-section,
.works .search-section {
    margin-bottom: 24px;
}

.service .search-input-container input::placeholder,
.works .search-input-container input::placeholder {
    color: #999;
}

.search-results-container {
    min-height: 400px;
}

.search-results .no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: #666;
    font-size: 18px;
}

/* 
WORKS検索でも service.css のバッジスタイルを使用するため、
WORKSページでもクラス名を .category-posts.search-results に統一済み
既存の service.css の以下のスタイルが適用される:
- .category-posts.search-results .box .meta-bottom
- .category-posts.search-results .box .meta-bottom .cats
- .category-posts.search-results .box .meta-bottom .tags  
- .category-posts.search-results .box .meta-bottom .tag_list
- .category-posts.search-results .box .meta-bottom .tag_list.cat-item
*/

/* ドロップダウンオプションのスタイル */
.select-options {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: none;
    max-height: 300px; /* クリアボタンも見えるように高さを増加 */
    overflow-y: auto;
}

.select-options.show {
    display: block;
}

.select-options-scroll {
    padding: 0;
}

.select-option {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.select-option:hover {
    background-color: #f5f5f5;
}

.select-option input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

.select-option label {
    flex: 1;
    cursor: pointer;
    margin: 0;
    font-size: 14px;
}

.select-clear-section {
    border-top: 1px solid #eee;
}

.select-separator {
    height: 1px;
    background-color: #eee;
    margin: 0;
}

.select-clear-button {
    padding: 8px 12px;
    text-align: center;
    cursor: pointer;
    color: #666;
    font-size: 12px;
    background-color: #f9f9f9;
    transition: background-color 0.2s ease;
}

.select-clear-button:hover {
    background-color: #f0f0f0;
}

.select-container {
    position: relative;
    overflow: visible;
}

/* 親要素のオーバーフローを無効にする */
.search-section,
.search-bar-container {
    overflow: visible;
}

