/**
 * rank_page.css — 榜单页面增强层样式（筛选功能、高亮等）
 * 配合 rank_page.js (RankPageSystem) 使用
 * 适用于比赛榜单页 / 外榜页
 */

/* ===== 筛选按钮激活态 ===== */
.control-btn.filter-active {
    background: var(--bs-info-bg-subtle, #cff4fc);
    border-color: var(--bs-info-border-subtle, #9eeaf9);
    color: var(--bs-info-text-emphasis, #055160);
    box-shadow: 0 0 0 2px rgba(13, 202, 240, 0.2);
}

.control-btn.filter-active i.bi {
    color: var(--bs-info, #0dcaf0);
}

.filter-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--bs-danger, #dc3545);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: var(--rank-radius-inner, 4px);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0 4px;
    pointer-events: none;
}

/* ===== 筛选 Popover ===== */
.filter-control-item {
    position: relative;
}

.filter-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    max-width: 360px;
    background: white;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: var(--rank-border-radius, 6px);
    box-shadow: var(--rank-shadow-overlay, 0 4px 18px rgba(15, 23, 42, 0.12));
    padding: 12px 14px;
    z-index: 1060;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
    pointer-events: none;
}

.filter-popover.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.filter-popover::before {
    content: '';
    position: absolute;
    top: -6px;
    right: 16px;
    width: 12px;
    height: 12px;
    background: white;
    border-left: 1px solid var(--bs-border-color, #dee2e6);
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    transform: rotate(45deg);
}

.filter-popover-section {
    margin-bottom: 8px;
}

.filter-popover-section:last-child {
    margin-bottom: 0;
}

.filter-popover-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--bs-secondary-color, #6c757d);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 6px;
}

.filter-popover-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.filter-popover-section-clear {
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 1;
    padding: 0;
}

.filter-popover-section-clear:hover {
    color: #be123c;
    border-color: #fecdd3;
    background: #fff1f2;
}

.filter-popover-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.filter-popover-mode-row {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
}

.filter-popover-mode-btn {
    border: 1px solid #d8e0ea;
    border-radius: var(--rank-radius-inner, 4px);
    background: #fff;
    color: #334155;
    font-size: 10px;
    font-weight: 600;
    padding: 3px 6px;
    line-height: 1.3;
    white-space: nowrap;
    letter-spacing: 0.1px;
    flex: 1 1 0;
}

.filter-popover-mode-btn.active {
    border-color: #9ec0e4;
    background: #edf5ff;
    color: #1d4f86;
}

.mode-sep {
    display: inline-block;
    margin: 0 4px;
    opacity: 0.7;
}

.filter-popover-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 12px;
    background: var(--bs-info-bg-subtle, #cff4fc);
    color: var(--bs-info-text-emphasis, #055160);
    border-radius: 4px;
    line-height: 1.4;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filter-popover-remove {
    margin-left: 6px;
    border: none;
    background: transparent;
    color: inherit;
    font-size: 12px;
    line-height: 1;
    opacity: 0.75;
}

.filter-popover-tag-school {
    border: 1px solid transparent;
}

.filter-popover-tag.filter-popover-tag-team {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    max-width: 240px;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    vertical-align: middle;
    position: relative;
    padding-right: 22px;
}

.filter-popover-tag-team .filter-popover-remove {
    position: absolute;
    right: 5px;
    top: 5px;
    margin-left: 0;
}

.filter-popover-tag-team .filter-popover-tag-primary {
    font-weight: 600;
    line-height: 1.3;
    max-width: 100%;
}

.filter-popover-tag-team .filter-popover-tag-meta {
    font-size: 11px;
    font-weight: 400;
    color: var(--bs-secondary-color, #6c757d);
    line-height: 1.35;
    word-break: break-word;
    max-width: 100%;
}

/* ===== 筛选 Modal ===== */
.rank-filter-modal-content {
    width: 720px;
    max-width: 92vw;
    min-height: 420px;
    margin: 18px auto;
}

.rank-filter-modal-overlay {
    overflow-y: auto;
    align-items: flex-start !important;
    padding: 12px 0;
}

.rank-filter-modal-body {
    padding: 20px 24px !important;
}

.rank-filter-top-controls {
    margin-bottom: 12px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.rank-filter-modal-content .rank-filter-top-controls .filter-card-star-mode,
.rank-filter-modal-content .rank-filter-top-controls .filter-card-display-mode {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 1px solid #dfe7f1;
    border-radius: var(--rank-border-radius, 6px);
    background: #f8fafc;
    padding: 8px 10px 8px 12px;
    min-height: 0;
}

.rank-filter-modal-content .rank-filter-top-controls .filter-card-title {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    letter-spacing: 0.2px;
    white-space: nowrap;
    line-height: 1.2;
    padding-bottom: 0;
    border-bottom: none;
    flex: 0 1 auto;
    min-width: 0;
}

.rank-filter-modal-content .rank-radio-group {
    display: inline-flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 4px;
    align-items: center;
    justify-content: flex-end;
    flex: 0 0 auto;
}

.rank-radio-btn.rank-radio-btn-icon {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    flex-shrink: 0;
}

.rank-radio-btn-icon .bi {
    font-size: 1.05rem;
    line-height: 1;
    pointer-events: none;
}

.rank-radio-btn {
    border: 1px solid #d8e0ea;
    border-radius: var(--rank-radius-inner, 4px);
    background: #fff;
    color: #334155;
    font-size: inherit;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.1px;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.rank-radio-btn.active {
    border-color: #9ec0e4;
    background: #edf5ff;
    color: #1d4f86;
}

.filter-columns {
    display: flex;
    gap: 0;
    min-height: 320px;
}

.filter-columns.filter-columns-single {
    min-height: 200px;
}

.filter-column {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.filter-column-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

.filter-column-title-main {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.filter-column-title-text {
    font-size: 14px;
    font-weight: 700;
    color: var(--bs-body-color, #1f2937);
    line-height: 1.25;
    white-space: nowrap;
}

.filter-title-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.filter-title-count {
    min-width: 22px;
    height: 18px;
    padding: 0 6px;
    border-radius: var(--rank-radius-inner, 4px);
    background: #e9f6ff;
    color: #0b5ed7;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.filter-title-clear {
    width: 20px;
    height: 20px;
    border: 1px solid #dbe3ee;
    border-radius: 50%;
    background: #ffffff;
    color: #64748b;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.filter-title-clear:hover {
    color: #be123c;
    background: #fff1f2;
    border-color: #fecdd3;
}

.filter-title-clear:active {
    transform: scale(0.94);
}

.filter-column-divider {
    width: 1px;
    background: var(--bs-border-color, #dee2e6);
    margin: 0 20px;
    flex-shrink: 0;
}

.rank-filter-group-controls {
    margin-top: 14px;
    border: 1px solid #e2e8f0;
    border-radius: var(--rank-border-radius, 6px);
    padding: 12px;
    background: #f8fafc;
    box-shadow: none;
}

.rank-filter-group-controls .filter-column-title-row {
    margin-bottom: 10px;
}

.rank-filter-group-controls .filter-title-actions .btn {
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 12px;
    line-height: 1.35;
    border-color: #cbd5e1;
    color: #334155;
    background: #fff;
}

.rank-filter-group-controls #filter-group-select {
    width: 100%;
    min-height: 124px;
    border-radius: 6px;
    border-color: #cbd5e1;
    background: #fff;
    color: #0f172a;
}

.rank-filter-group-controls #filter-group-select:focus {
    border-color: #94a3b8;
    box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.2);
}

#filter-group-multiselect {
    width: 100%;
}

/* 搜索框 */
.filter-search-wrapper {
    position: relative;
    margin-bottom: 12px;
}

.filter-search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: var(--rank-border-radius, 6px);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    background: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #212529);
    box-sizing: border-box;
}

.filter-search-input:focus {
    border-color: var(--bs-info, #0dcaf0);
    box-shadow: 0 0 0 3px rgba(13, 202, 240, 0.15);
}

.filter-search-input::placeholder {
    color: var(--bs-secondary-color, #6c757d);
    opacity: 0.65;
}

/* 候选浮动下拉层 — 默认隐藏，搜索框 focus 时出现 */
.filter-candidates-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 0 0 var(--rank-border-radius, 6px) var(--rank-border-radius, 6px);
    margin-top: -1px;
    background: var(--bs-body-bg, #fff);
    box-shadow: var(--rank-shadow-overlay, 0 4px 18px rgba(15, 23, 42, 0.1));
    z-index: 1070;
    scrollbar-width: thin;
    /* 默认隐藏 */
    display: none;
}

.filter-candidates-dropdown.show {
    display: block;
}

.filter-candidates-dropdown:empty {
    display: none !important;
}

.filter-candidate-item {
    padding: 7px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.1s ease;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    color: var(--bs-body-color, #212529);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.filter-candidate-item:last-child {
    border-bottom: none;
}

.filter-candidate-item:hover {
    background: var(--bs-info-bg-subtle, #cff4fc);
}

.filter-candidate-school {
    font-size: 11px;
    color: var(--bs-secondary-color, #6c757d);
    margin-left: 6px;
}

/* 队伍候选：主行 ID·队名 + 次行（译名·学校·教练·队员），无文字 label */
.filter-candidate-item.filter-candidate-team {
    white-space: normal;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 8px 12px;
}

.filter-candidate-team-primary {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--bs-body-color, #212529);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filter-candidate-team-meta {
    font-size: 11px;
    line-height: 1.45;
    color: var(--bs-secondary-color, #6c757d);
    word-break: break-word;
}

.filter-candidate-empty {
    padding: 12px;
    text-align: center;
    color: var(--bs-secondary-color, #6c757d);
    font-size: 12px;
    font-style: italic;
}

/* 已选 Tag */
.filter-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 28px;
    flex: 1;
    align-content: flex-start;
    overflow-y: auto;
    max-height: 132px;
    padding-right: 2px;
}

.filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px 3px 10px;
    background: var(--bs-info-bg-subtle, #cff4fc);
    color: var(--bs-info-text-emphasis, #055160);
    border: 1px solid var(--bs-info-border-subtle, #9eeaf9);
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.4;
    max-width: 200px;
    animation: filterTagIn 0.2s ease;
}

@keyframes filterTagIn {
    from { opacity: 0; transform: scale(0.85); }
    to   { opacity: 1; transform: scale(1); }
}

.filter-tag-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filter-tag.filter-tag-team {
    max-width: min(100%, 380px);
    align-items: flex-start;
}

.filter-tag-text-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.filter-tag-primary {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    color: inherit;
    word-break: break-word;
}

.filter-tag-meta {
    font-size: 11px;
    line-height: 1.4;
    color: var(--bs-secondary-color, #6c757d);
    opacity: 0.95;
    word-break: break-word;
}

.filter-tag-team .filter-tag-remove {
    flex-shrink: 0;
    margin-top: 1px;
    color: var(--filter-tag-x, var(--bs-info, #0dcaf0));
}

.filter-tag-team .filter-tag-remove:hover {
    color: var(--bs-danger, #dc3545);
}

.filter-tag-remove {
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    color: var(--bs-info, #0dcaf0);
    opacity: 0.7;
    transition: opacity 0.1s, color 0.1s;
    padding: 0 2px;
    flex-shrink: 0;
    background: none;
    border: none;
}

.filter-tag-remove:hover {
    opacity: 1;
    color: var(--bs-danger, #dc3545);
}

.filter-tag-school .filter-tag-remove {
    color: var(--filter-tag-x, var(--bs-info, #0dcaf0));
}

.filter-tag-school .filter-tag-remove:hover {
    color: var(--bs-danger, #dc3545);
}

/* Modal footer：左侧「确认后切换仅筛选」开关，右侧清空 / 确定 */
.rank-filter-modal-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 24px !important;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    background: var(--bs-light, #f8f9fa);
    border-radius: 0 0 var(--rank-border-radius, 6px) var(--rank-border-radius, 6px);
}

.rank-filter-modal-footer-left {
    flex: 1 1 220px;
    min-width: 0;
    display: flex;
    align-items: center;
}

.rank-filter-modal-footer-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    flex: 0 0 auto;
}

.filter-action-btn {
    padding: 6px 18px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.filter-clear-btn {
    background: transparent;
    color: var(--bs-secondary-color, #6c757d);
    border-color: var(--bs-border-color, #dee2e6);
}

.filter-clear-btn:hover {
    background: var(--bs-light, #f8f9fa);
    color: var(--bs-danger, #dc3545);
    border-color: var(--bs-danger, #dc3545);
}

.filter-apply-btn {
    background: var(--bs-primary, #0d6efd);
    color: #fff;
}

.filter-apply-btn:hover {
    background: #0b5ed7;
    color: #fff;
}

/* ===== 行高亮（筛选匹配） ===== */
.rank-row.rank-filter-match {
    position: relative;
    background: var(--rank-filter-bg, rgba(13, 202, 240, 0.12)) !important;
    box-shadow: inset 4px 0 0 var(--rank-filter-accent, #0dcaf0);
    outline: 1px solid var(--rank-filter-outline, rgba(13, 202, 240, 0.25));
    outline-offset: -1px;
}

.rank-row.rank-filter-match:hover {
    background: var(--rank-filter-bg-hover, rgba(13, 202, 240, 0.18)) !important;
}

/* ===== 筛选模式控件（toolbar） ===== */
.filter-switch-item {
    display: flex;
    align-items: center;
}

.filter-switch-item .filter-mode-select {
    min-width: 176px;
    height: 30px;
    font-size: 12px;
    border-radius: 6px;
    border-color: #cbd5e1;
    color: #1f2937;
    padding: 0.2rem 1.8rem 0.2rem 0.6rem;
}

.filter-switch-item .filter-mode-select:focus {
    border-color: #94a3b8;
    box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.2);
}

.rank-filter-pinned-host {
    margin: 0 0 10px 0;
    border: 1px solid #cfd8e3;
    border-radius: var(--rank-border-radius, 6px);
    background: #f8fafc;
    /* 不设水平 padding：固顶行与 #rank-grid 内 .rank-row 同宽，各列与表头对齐 */
    padding: 0;
    box-sizing: border-box;
}

.rank-filter-pinned-title {
    font-size: 12px;
    font-weight: 700;
    color: #334155;
    letter-spacing: 0.2px;
    /* 仅标题区与表头/数据行左右留白一致（与 .rank-header-row、.rank-row 的 16px 对齐） */
    padding: 10px var(--rank-padding-lg, 16px) 0;
    box-sizing: border-box;
}

.rank-filter-pinned-divider {
    height: 1px;
    background: #d7e2ee;
    margin: 8px 0 10px 0;
}

.rank-filter-pinned-grid {
    width: 100%;
    min-width: 0;
    padding: 0;
    margin: 0;
}

/* 不覆写 .rank-row 的 margin：与主榜行距一致，避免固顶块相对表头产生额外缩进 */

.rank-filter-pinned-separator {
    margin-top: 10px;
    border-top: 2px dashed #9fb3c8;
}

/* ===== 响应式 ===== */
@media (max-width: 600px) {
    .rank-filter-top-controls {
        grid-template-columns: 1fr;
    }

    .filter-columns {
        flex-direction: column;
    }

    .filter-column-divider {
        width: 100%;
        height: 1px;
        margin: 16px 0;
    }

    .rank-filter-modal-content {
        min-height: auto;
    }

    .filter-candidates-dropdown {
        max-height: 150px;
    }
}
