/* --- Original Slider Styles --- */
.kainoto-swiper-container { overflow: hidden; position: relative; }
.kainoto-swiper-container.nd-template .swiper-slide { position: relative; display: flex; justify-content: center; align-items: center; color: white; }
.kainoto-swiper-container.nd-template .kainoto-background { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-size: cover; background-position: center; z-index: 1; }
.kainoto-swiper-container.nd-template .kainoto-background-overlay { position: absolute; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.4); z-index: 2; }
.kainoto-swiper-container.nd-template .kainoto-foreground-image { position: relative; z-index: 4; max-width: 50%; height: auto; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); }
.kainoto-swiper-container.nd-template .kainoto-overlay { position: absolute; z-index: 5; text-align: center; }
.kainoto-swiper-container.nd-template .kainoto-title { font-size: 2.5rem; margin-bottom: 1rem; }
.kainoto-swiper-container.nd-template .kainoto-button { display: inline-block; padding: 0.5rem 1.5rem; border: 1px solid #fff; color: white; text-decoration: none; transition: background 0.3s; }
.kainoto-swiper-container.nd-template .kainoto-button:hover { background: rgba(255, 255, 255, 0.2); }
.kainoto-swiper-container .pageItem { height: 400px; display: flex; flex-direction: column; justify-content: flex-end; background-size: cover; background-position: center; text-decoration: none; }
.kainoto-swiper-container .itemDetails { background: rgba(0,0,0,0.7); color: #fff; padding: 1rem; }
.kainoto-swiper-container .pageTitle { font-size: 1.5rem; }

/* --- NEW & UPDATED Grid & Masonry Layout Styles --- */
.kainoto-pba-grid-container {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(var(--pba-cols-mobile, 1), 1fr);
}

.kainoto-pba-masonry-container {
    width: 100%;
}

/* NEW default item style */
.pba-item {
    display: flex;
    flex-direction: column;
    justify-content: flex-end; /* Pushes content to the bottom */
    min-height: 350px;
    background-size: cover;
    background-position: center;
    text-decoration: none;
    position: relative;
    overflow: hidden;
    color: #333;
    border-radius: 4px;
    transition: transform 0.3s ease;
    background-color: #f0f0f0; /* Fallback color if no image */
}

.pba-item:hover {
    transform: translateY(-5px);
}

.pba-item-content-wrapper {
    background: rgba(255, 255, 255, 0.95);
    padding: 15px;
    width: 100%;
    backdrop-filter: blur(3px);
}

.pba-item-title {
    font-size: 1.25rem;
    margin: 0 0 10px 0;
    color: #111;
}

.pba-item-excerpt {
    font-size: 0.9rem;
    color: #555;
    line-height: 1.5;
    margin-bottom: 15px;
}

.pba-item-button {
    display: inline-block;
    padding: 8px 15px;
    background-color: #0073aa;
    color: #fff;
    border-radius: 3px;
    font-size: 0.9rem;
    font-weight: bold;
    text-align: center;
    transition: background-color 0.2s;
}

.pba-item:hover .pba-item-button {
    background-color: #005a87;
}

/* For Masonry, define column widths */
.kainoto-pba-masonry-container .pba-item {
    width: calc((100% / var(--pba-cols-mobile, 1)) - 20px);
    margin-bottom: 20px;
}

/* Responsive columns */
@media (min-width: 768px) {
    .kainoto-pba-grid-container { grid-template-columns: repeat(var(--pba-cols-tablet, 2), 1fr); }
    .kainoto-pba-masonry-container .pba-item { width: calc((100% / var(--pba-cols-tablet, 2)) - 20px); }
}

@media (min-width: 1024px) {
    .kainoto-pba-grid-container { grid-template-columns: repeat(var(--pba-cols-desktop, 3), 1fr); }
    .kainoto-pba-masonry-container .pba-item { width: calc((100% / var(--pba-cols-desktop, 3)) - 20px); }
}

/* --- Load More Button Styles --- */
.kainoto-pba-load-more-wrapper { text-align: center; margin-top: 30px; }
.kainoto-pba-load-more { padding: 10px 25px; font-size: 1rem; cursor: pointer; background-color: #0073aa; color: #fff; border: none; border-radius: 4px; transition: background-color 0.3s; }
.kainoto-pba-load-more:hover { background-color: #005a87; }
.kainoto-pba-load-more:disabled { background-color: #999; cursor: not-allowed; }

/* --- Search Field Styles --- */
.kainoto-pba-search-wrapper { position: relative; flex: 1; min-width: 250px; max-width: 400px; }
.kainoto-pba-search-input { width: 100%; padding: 9px 35px 9px 12px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; transition: border-color 0.2s, box-shadow 0.2s; padding: 0.65em !important; }
.kainoto-pba-search-input:focus { outline: none; border-color: #0073aa; box-shadow: 0 0 0 1px rgba(0, 115, 170, 0.2); }
.kainoto-pba-search-input::placeholder { color: #999; }
.kainoto-pba-search-clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: #e74c3c; color: #fff; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 18px; line-height: 20px; cursor: pointer; display: none; padding: 0; text-align: center; transition: background-color 0.2s; }
.kainoto-pba-search-clear:hover { background: #c0392b; }

/* --- Toolbar Styles --- */
.kainoto-pba-toolbar { display: flex; gap: 15px; margin: 0 0 15px 0; flex-wrap: wrap; align-items: center; }
.kainoto-pba-post-count { margin-left: auto; font-size: 14px; color: #444; white-space: nowrap; }
.kainoto-pba-post-count-filtered,
.kainoto-pba-post-count-total { font-weight: 600; color: #1d2327; }

/* --- Hash Filter Tags --- */
.pba-hash-tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 15px 0; }
.pba-hash-tag { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; background: #0073aa; color: #fff; border-radius: 4px; font-size: 13px; line-height: 1.4; }
.pba-hash-tag-label { white-space: nowrap; }
.pba-hash-tag-remove { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; padding: 0; border: none; background: rgba(255,255,255,0.25); color: #fff; border-radius: 50%; cursor: pointer; font-size: 14px; line-height: 1; transition: background 0.2s; }
.pba-hash-tag-remove:hover { background: rgba(255,255,255,0.5); }
.kainoto-pba-filter-option.pba-hash-locked { background: #0073aa; color: #fff; font-weight: 500; pointer-events: none; opacity: 0.85; }
.kainoto-pba-filter-option.pba-hash-locked::before { content: '\1F512'; }

/* --- Comparison View Styles --- */
.kainoto-pba-view-toggle { display: inline-flex; gap: 8px; }
.kainoto-pba-toggle-btn { padding: 8px 14px; border: 1px solid #0073aa; background: #fff; color: #0073aa; cursor: pointer; border-radius: 4px; transition: background-color 0.2s, color 0.2s; }
.kainoto-pba-toggle-btn.active { background: #0073aa; color: #fff; }

/* --- Sort Dropdown Styles --- */
.kainoto-pba-sort-dropdown { position: relative; display: inline-block; }
.kainoto-pba-sort-btn { padding: 8px 14px; border: 1px solid #0073aa; background: #fff; color: #0073aa; cursor: pointer; border-radius: 4px; transition: background-color 0.2s, color 0.2s; font-size: 14px; }
.kainoto-pba-sort-btn:hover { background: #f0f8ff; }
.kainoto-pba-sort-menu { display: none; position: absolute; top: 100%; left: 0; background: #fff; border: 1px solid #ddd; border-radius: 4px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); z-index: 9999; min-width: 200px; margin-top: 5px; }
.kainoto-pba-sort-menu.active { display: block; }
.kainoto-pba-sort-item { padding: 10px 15px; cursor: pointer; border-bottom: 1px solid #f0f0f0; display: flex; justify-content: space-between; align-items: center; transition: background-color 0.2s; }
.kainoto-pba-sort-item:last-child { border-bottom: none; }
.kainoto-pba-sort-item:hover { background: #f5f5f5; }
.kainoto-pba-sort-item.active { background: #e6f3ff; font-weight: 600; }
.kainoto-pba-sort-item[data-field="reset"] { font-style: italic; color: #666; }
.kainoto-pba-sort-indicator { margin-left: 10px; font-size: 12px; color: #0073aa; }
.kainoto-pba-sort-indicator::before { content: '↕'; opacity: 0.3; }
.kainoto-pba-sort-item.active .kainoto-pba-sort-indicator[data-direction="ascending"]::before { content: '↑'; opacity: 1; }
.kainoto-pba-sort-item.active .kainoto-pba-sort-indicator[data-direction="descending"]::before { content: '↓'; opacity: 1; }

/* --- Filter Dropdown Styles --- */
.kainoto-pba-filter-dropdown { position: relative; display: inline-block; }
.kainoto-pba-filter-btn { padding: 8px 14px; border: 1px solid #0073aa; background: #fff; color: #0073aa; cursor: pointer; border-radius: 4px; transition: background-color 0.2s, color 0.2s; font-size: 14px; }
.kainoto-pba-filter-btn:hover { background: #f0f8ff; }
.kainoto-pba-filter-btn.has-filters { background: #0073aa; color: #fff; font-weight: 600; }
.kainoto-pba-filter-count { display: inline-block; margin-left: 5px; background: rgba(255,255,255,0.3); padding: 2px 6px; border-radius: 10px; font-size: 11px; font-weight: bold; }
.kainoto-pba-filter-count:empty { display: none; }
.kainoto-pba-filter-menu { display: none; position: absolute; top: 100%; left: 0; background: #fff; border: 1px solid #ddd; border-radius: 4px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); z-index: 9999; min-width: 250px; max-width: 350px; margin-top: 5px; max-height: 400px; overflow-y: auto; }
.kainoto-pba-filter-menu.active { display: block; }
.kainoto-pba-filter-header { padding: 12px 15px; border-bottom: 2px solid #f0f0f0; display: flex; justify-content: space-between; align-items: center; background: #fafafa; font-weight: 600; }
.kainoto-pba-filter-reset { padding: 4px 10px; background: #e74c3c; color: #fff; border: none; border-radius: 3px; cursor: pointer; font-size: 12px; transition: background 0.2s; }
.kainoto-pba-filter-reset:hover { background: #c0392b; }
.kainoto-pba-filter-content { padding: 10px 0; }
.kainoto-pba-filter-group { margin-bottom: 10px; }
.kainoto-pba-filter-group-title { padding: 8px 15px; background: #f5f5f5; font-weight: 600; font-size: 13px; color: #333; border-top: 1px solid #e5e5e5; border-bottom: 1px solid #e5e5e5; }
.kainoto-pba-filter-option { padding: 8px 15px 8px 30px; cursor: pointer; transition: background-color 0.2s; position: relative; font-size: 14px; }
.kainoto-pba-filter-option:hover { background: #f5f5f5; }
.kainoto-pba-filter-option.active { background: #e6f3ff; color: #0073aa; font-weight: 500; }
.kainoto-pba-filter-option.active::before { content: '✓'; position: absolute; left: 10px; font-weight: bold; }
.kainoto-pba-filter-option-count { float: right; font-size: 11px; color: #999; background: #f0f0f0; padding: 2px 6px; border-radius: 10px; margin-left: 8px; }

/* --- Date Range Filter Styles --- */
.kainoto-pba-filter-date-group .kainoto-pba-date-range-wrapper { padding: 12px 15px; display: flex; flex-direction: column; gap: 10px; }
.kainoto-pba-date-label { font-size: 12px; color: #555; font-weight: 500; margin-bottom: 4px; }
.kainoto-pba-date-input { padding: 8px 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; width: 100%; box-sizing: border-box; transition: border-color 0.2s; }
.kainoto-pba-date-input:focus { outline: none; border-color: #0073aa; box-shadow: 0 0 0 1px rgba(0, 115, 170, 0.2); }
.kainoto-pba-date-input:hover { border-color: #aaa; }

/* --- Numeric Range Filter Styles --- */
.kainoto-pba-filter-range-group {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    row-gap: 8px;
    align-items: center;
    padding: 10px 15px;
    border-top: 1px solid #e5e5e5;
    border-bottom: 1px solid #e5e5e5;
    background: #fafafa;
}

.kainoto-pba-filter-range-group .kainoto-pba-filter-group-title {
    grid-column: 1;
    grid-row: 1;
    padding: 0;
    margin: 0;
    border: 0;
    background: transparent;
    font-size: 13px;
    white-space: normal;
}

.kainoto-pba-range-values {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.kainoto-pba-range-min-value,
.kainoto-pba-range-max-value {
    font-size: 12px;
    color: #444;
    white-space: nowrap;
    width: 70px;
    padding: 2px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    text-align: center;
    -moz-appearance: textfield;
}

.kainoto-pba-range-min-value::-webkit-outer-spin-button,
.kainoto-pba-range-min-value::-webkit-inner-spin-button,
.kainoto-pba-range-max-value::-webkit-outer-spin-button,
.kainoto-pba-range-max-value::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.kainoto-pba-range-min-value {
    grid-column: auto;
}

.kainoto-pba-range-max-value {
    grid-column: auto;
}

.kainoto-pba-range-input {
    grid-column: 1;
    grid-row: 3;
    width: 100%;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    pointer-events: none;
    height: 24px;
}

.kainoto-pba-range-input::-webkit-slider-runnable-track {
    height: 6px;
    background: #e1e4e8;
    border-radius: 999px;
}

.kainoto-pba-range-input::-moz-range-track {
    height: 6px;
    background: #e1e4e8;
    border-radius: 999px;
}

.kainoto-pba-range-max::-webkit-slider-runnable-track {
    background: transparent;
}

.kainoto-pba-range-max::-moz-range-track {
    background: transparent;
}

.kainoto-pba-range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #0073aa;
    border: 2px solid #ffffff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    margin-top: -5px;
    pointer-events: auto;
    cursor: pointer;
}

.kainoto-pba-range-input::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #0073aa;
    border: 2px solid #ffffff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    pointer-events: auto;
    cursor: pointer;
}

.kainoto-pba-compare-container { margin-top: 20px; }
.kainoto-pba-compare-scroll { overflow-x: auto; }
.kainoto-pba-compare-table { border-collapse: collapse; width: 100%; min-width: 480px; }
.kainoto-pba-compare-table th,
.kainoto-pba-compare-table td { border: 1px solid #e5e5e5; padding: 10px; background: #fff; text-align: left; }
.kainoto-pba-compare-table thead th { background: #f6f7f7; position: sticky; top: 0; z-index: 2; }
.kainoto-pba-compare-table th.sticky { position: sticky; left: 0; background: #f6f7f7; z-index: 3; }
.kainoto-pba-compare-table tbody tr:nth-child(odd) td { background: #fafafa; }
.kainoto-pba-compare-table tbody tr:nth-child(odd) th.sticky { background: #f0f0f0; }

@media (max-width: 767px) {
    .kainoto-pba-compare-scroll { -webkit-overflow-scrolling: touch; }
    .kainoto-pba-compare-table th,
    .kainoto-pba-compare-table td { padding: 8px; font-size: 0.9rem; }
}

/* --- TAXONOMY MASONRY GRID STYLES --- */
.lcd-masonry-wrapper {
    /* True masonry grid layout with variable item sizes */
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    grid-auto-rows: auto;
    grid-auto-flow: dense; /* Allows items to fill gaps */
    gap: 1rem;
    width: 100%;
}

/* Individual taxonomy term item */
.lcd-tag-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 120px;
    padding: 1.5rem;
    border-radius: 8px;
    text-decoration: none !important;
    font-weight: 700;
    font-family: 'Segoe UI', sans-serif;
    font-size: 1.1rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;
    word-wrap: break-word;
    word-break: break-word;
}

.lcd-tag-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
    z-index: 2;
}

/* Optional description text within tag items */
.lcd-tag-desc {
    display: block;
    font-size: 0.85rem;
    font-weight: 400;
    margin-top: 5px;
    opacity: 0.8;
}

/* --- COLOR ROTATION (4-color scheme) --- */

/* Color 1: Dark Blue (Brand) */
.lcd-tag-item:nth-child(4n+1) {
    background-color: #003d80;
    color: #ffffff;
}

/* Color 2: Light Gray (Neutral) */
.lcd-tag-item:nth-child(4n+2) {
    background-color: #f4f7f6;
    color: #333333;
    border: 1px solid #e0e0e0;
}

/* Color 3: Medium Blue (Primary) */
.lcd-tag-item:nth-child(4n+3) {
    background-color: #0056b3;
    color: #ffffff;
}

/* Color 4: Dark Gray/Black (Contrast) */
.lcd-tag-item:nth-child(4n+4) {
    background-color: #222222;
    color: #ffffff;
}

/* --- SIZE VARIATIONS (Based on post count) --- */

/* Extra Small: 0-25% of count range - 1x1 grid cell */
.lcd-tag-item.size-xs {
    font-size: 0.85rem;
    min-height: 100px;
    grid-column: span 1;
    grid-row: span 1;
}

/* Small: 25-50% of count range - 1x1.5 grid cell */
.lcd-tag-item.size-sm {
    font-size: 0.95rem;
    min-height: 130px;
    grid-column: span 1;
    grid-row: span 1;
}

/* Medium: 50-75% of count range - 2x1.5 grid cells */
.lcd-tag-item.size-md {
    font-size: 1.15rem;
    min-height: 140px;
    grid-column: span 2;
    grid-row: span 1;
    padding: 1.5rem;
}

/* Large: 75-100% of count range - 2x2 grid cells */
.lcd-tag-item.size-lg {
    font-size: 1.4rem;
    min-height: 180px;
    grid-column: span 2;
    grid-row: span 2;
    padding: 1.8rem;
}

/* --- RESPONSIVE MASONRY --- */

@media (max-width: 1200px) {
    .lcd-masonry-wrapper {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
    
    .lcd-tag-item.size-md {
        grid-column: span 2;
    }
    
    .lcd-tag-item.size-lg {
        grid-column: span 2;
    }
}

@media (max-width: 768px) {
    .lcd-masonry-wrapper {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    
    .lcd-tag-item.size-md {
        grid-column: span 2;
    }
    
    .lcd-tag-item.size-lg {
        grid-column: span 2;
        grid-row: span 1;
        min-height: 120px;
    }
}

@media (max-width: 480px) {
    .lcd-masonry-wrapper {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.5rem;
    }
    
    .lcd-tag-item {
        min-height: 80px;
        font-size: 0.9rem;
        padding: 0.8rem;
    }
    
    .lcd-tag-item.size-md {
        grid-column: span 1;
        min-height: 100px;
    }
    
    .lcd-tag-item.size-lg {
        grid-column: span 1;
        grid-row: span 1;
        min-height: 100px;
    }
}

/* Loading state styles */
.pba-loading {
    position: relative;
    opacity: 0.6;
    pointer-events: none;
}

.pba-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: pba-spin 1s linear infinite;
    z-index: 1000;
}

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

/* Clickable tag badge styles */
.pba-tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.pba-tag {
    display: inline-block;
    padding: 3px 10px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 0.8rem;
    color: #333;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    line-height: 1.4;
}
.pba-tag:hover {
    background: #0073aa;
    color: #fff;
    border-color: #0073aa;
}

/* Collapsible field styles */
.pba-collapsible {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    /* -webkit-line-clamp is set inline via style attribute */
}
.pba-collapsible.pba-expanded {
    display: block;
    -webkit-line-clamp: unset !important;
}
.pba-collapsible-toggle {
    background: none;
    border: none;
    color: #0073aa;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px 0;
    margin-top: 2px;
    display: none; /* shown by JS only when content is actually clamped */
}
.pba-collapsible-toggle.pba-visible {
    display: inline-block;
}
.pba-collapsible-toggle:hover {
    text-decoration: underline;
}

/* No results message */
.kainoto-pba-no-results {
    padding: 40px 20px;
    text-align: center;
    color: #666;
    font-size: 16px;
    width: 100%;
}

/* Current post ACF image mode */
.kainoto-pba-current-images .pba-current-acf-image-item {
    width: 100%;
}

.kainoto-pba-current-images .pba-current-acf-image {
    display: block;
    width: 100%;
    height: auto;
}

.kainoto-pba-current-images .pba-current-acf-image-link {
    display: block;
    text-decoration: none;
}
