/* ==========================================================================
   Publication Tag Search Filter
   Replaces taxonomy button list with searchable dropdown
   ========================================================================== */

/* Allow sticky to work - fix ALL ancestor overflow */
#brx-content:has(.publication-tag-search-wrapper),
.brxe-section:has(.publication-tag-search-wrapper),
.brxe-container:has(.publication-tag-search-wrapper),
.brxe-block:has(.publication-tag-search-wrapper),
.brxe-div:has(.publication-tag-search-wrapper),
.brxe-post-content:has(.publication-tag-search-wrapper),
[class*="brxe-"]:has(.publication-tag-search-wrapper) {
    overflow: visible !important;
    overflow-x: visible !important;
    overflow-y: visible !important;
}

/* Wrapper - matches pipeline controls layout + sticky */
.publication-tag-search-wrapper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-m, 16px);
    padding-top: var(--space-s, 12px);
    padding-bottom: var(--space-s, 12px);

    /* Sticky behavior */
    position: -webkit-sticky !important;
    position: sticky !important;
    top: 200px;
    z-index: 90;
    background: var(--bg-body, #fff);
}

.publication-tag-search {
    position: relative;
    width: 100%;
    min-width: 250px;
    max-width: 400px;
}

.publication-tag-search__info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.publication-count {
    font-size: 0.875rem;
    color: var(--bg-body-d-3, #666);
    font-weight: 500;
}

/* Input wrapper */
.publication-tag-search__input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

/* Search input - matches pipeline search styling */
.publication-tag-search__input {
    width: 100%;
    padding: 0.75rem 1rem;
    padding-left: 2.5rem;
    padding-right: 2.5rem;
    font-size: 1rem;
    font-family: inherit;
    border: 2px solid var(--bg-body-d-2, #e0e0e0);
    border-radius: 8px;
    background: var(--bg-body, #fff);
    color: var(--text-body, #333);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.publication-tag-search__input:focus {
    outline: none;
    border-color: var(--primary, #633368);
    box-shadow: 0 0 0 3px rgba(99, 50, 104, 0.1);
}

.publication-tag-search__input::placeholder {
    color: var(--bg-body-d-2, #999);
}

/* Search icon */
.publication-tag-search__icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--bg-body-d-2, #999);
    pointer-events: none;
    opacity: 0.6;
}

/* Clear button */
.publication-tag-search__clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--text-muted, #999);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease, background 0.2s ease;
}

.publication-tag-search__clear:hover {
    color: var(--text-color, #333);
    background: rgba(0, 0, 0, 0.05);
}

/* Results dropdown */
.publication-tag-search__results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    padding: var(--space-2xs, 4px) 0;
    background: var(--bg-body, #fff);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: var(--radius-m, 8px);
    box-shadow: var(--shadow-m, 0 4px 12px rgba(0, 0, 0, 0.1));
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
}

.publication-tag-search__results li {
    padding: var(--space-xs, 8px) var(--space-s, 12px);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s ease;
}

.publication-tag-search__results li:hover,
.publication-tag-search__results li.is-highlighted {
    background: var(--primary--alt, #f5f0f6);
}

.publication-tag-search__results li .tag-name {
    font-weight: 500;
    color: var(--text-color, #333);
}

.publication-tag-search__results li .tag-count {
    font-size: var(--text-s, 0.875rem);
    color: var(--text-muted, #999);
    background: var(--bg-muted, #f5f5f5);
    padding: 2px 8px;
    border-radius: var(--radius-s, 4px);
}

.publication-tag-search__results .no-results {
    padding: var(--space-m, 16px);
    text-align: center;
    color: var(--text-muted, #999);
    cursor: default;
}

.publication-tag-search__results .no-results:hover {
    background: none;
}

/* Loading state */
.publication-tag-search__results .loading {
    padding: var(--space-m, 16px);
    text-align: center;
    color: var(--text-muted, #999);
}

/* Active tag chip */
.publication-tag-search__active-tag {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2xs, 4px);
    margin-top: var(--space-xs, 8px);
    padding: var(--space-2xs, 4px) var(--space-xs, 8px);
    background: var(--primary, #633368);
    color: #fff;
    border-radius: var(--radius-s, 4px);
    font-size: var(--text-s, 0.875rem);
    font-weight: 500;
}

.publication-tag-search__tag-name {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.publication-tag-search__remove-tag {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 0;
    font-size: 1.25em;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.publication-tag-search__remove-tag:hover {
    opacity: 1;
}

/* View all link */
.publication-tag-search__view-all {
    display: block;
    padding: var(--space-xs, 8px) var(--space-s, 12px);
    text-align: center;
    color: var(--primary, #633368);
    font-weight: 500;
    border-top: 1px solid var(--border-color, #e0e0e0);
    cursor: pointer;
    transition: background 0.15s ease;
}

.publication-tag-search__view-all:hover {
    background: var(--primary--alt, #f5f0f6);
}

/* Responsive */
@media (max-width: 600px) {
    .publication-tag-search {
        max-width: 100%;
    }
}

/* ==========================================================================
   Publication Cards (AJAX loaded)
   ========================================================================== */

.publication-item {
    list-style: none;
    margin: 0;
    padding: 0;
}

.publication-card {
    padding: var(--space-m, 16px) 0;
    border-bottom: 1px solid var(--bg-body-d-1, #eee);
}

.publication-card:last-child {
    border-bottom: none;
}

.publication-title {
    font-size: var(--text-l, 1.125rem);
    font-weight: 600;
    margin: 0 0 var(--space-2xs, 4px) 0;
    line-height: 1.4;
}

.publication-title a {
    color: var(--primary, #633368);
    text-decoration: none;
    transition: color 0.2s ease;
}

.publication-title a:hover {
    color: var(--primary-d-1, #4a2550);
    text-decoration: underline;
}

.publication-authors {
    font-size: var(--text-s, 0.875rem);
    color: var(--text-body, #333);
    margin: 0 0 var(--space-2xs, 4px) 0;
}

.publication-meta {
    font-size: var(--text-s, 0.875rem);
    color: var(--bg-body-d-3, #666);
    margin: 0 0 var(--space-xs, 8px) 0;
}

.publication-source {
    font-style: italic;
}

.publication-year {
    margin-left: 0.25em;
}

.publication-link {
    font-size: var(--text-s, 0.875rem);
    font-weight: 500;
    color: var(--secondary, #0D7377);
    text-decoration: none;
    transition: color 0.2s ease;
}

.publication-link:hover {
    color: var(--secondary-d-1, #0a5a5d);
    text-decoration: underline;
}

/* No results message */
.no-results {
    padding: var(--space-l, 32px);
    text-align: center;
    color: var(--bg-body-d-3, #666);
}

.no-results p {
    margin: 0;
}

/* ==========================================================================
   Filtered Results Container
   ========================================================================== */

.publication-filtered-results {
    display: none;
}

.publication-filtered-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: var(--space-m, 16px);
}
