/* Reusable Sort Filter Control Styles - Mobile First Design */
.sort-filter-control-modern {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    margin-bottom: 16px;
}

.sort-filter-header-modern {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.sort-filter-header-modern i {
    font-size: 14px;
    color: var(--text-secondary);
}

.sort-filter-options-modern {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

@media (min-width: 480px) {
    .sort-filter-options-modern {
        grid-template-columns: repeat(4, 1fr);
    }
}

.sort-option-modern {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    box-sizing: border-box;
    height: 44px;
    min-height: 44px;
    padding: 0 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    text-align: left;
}

.sort-option-modern:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary);
}

.sort-option-modern.active {
    background: var(--gradient-primary);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(96, 165, 250, 0.3);
}

.sort-option-modern.active .sort-icon-modern {
    color: white;
}

.sort-icon-modern {
    font-size: 12px;
    color: var(--text-secondary);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.sort-option-modern.active .sort-icon-modern {
    color: white;
}

.sort-option-modern[data-order="asc"] .sort-icon-modern {
    transform: rotate(180deg);
}

.sort-option-modern[data-order="desc"] .sort-icon-modern {
    transform: rotate(0deg);
}

/* Mobile Optimizations */
@media (max-width: 767px) {
    .sort-filter-options-modern {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .sort-option-modern {
        padding: 0 10px;
        font-size: 12px;
    }
}

/* Header row sort trigger — 44×44, matches portfolio tab refresh pill */
.sort-filter-popover-wrap {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

/* Portfolio detail Allocations/Analysis: keep view toggle above sibling chrome for hit-testing */
#allocations-view-mode-wrap,
#order-history-view-mode-wrap,
#analysis-view-mode-wrap {
    z-index: 2;
}

.sort-filter-popover-wrap .tab-refresh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    max-width: 44px;
    min-height: 44px;
    max-height: 44px;
    padding: 0;
    box-sizing: border-box;
    line-height: 1;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    /* iOS Safari: reliable taps on icon buttons; avoid double-tap zoom delay */
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.12);
    user-select: none;
    -webkit-user-select: none;
}

.sort-filter-popover-wrap .tab-refresh-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.sort-filter-popover-wrap .tab-refresh-btn i {
    font-size: 16px;
    line-height: 1;
    width: 1em;
    height: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    vertical-align: middle;
    /* iOS Safari: icon must not steal hit-testing from <button> */
    pointer-events: none;
}

[data-theme="dark"] .sort-filter-popover-wrap .tab-refresh-btn,
[data-theme="dark"] .sort-filter-popover-wrap .tab-refresh-btn i {
    color: #fff;
}

[data-theme="dark"] .sort-filter-popover-wrap .tab-refresh-btn:hover,
[data-theme="dark"] .sort-filter-popover-wrap .tab-refresh-btn:hover i {
    color: #fff;
}

/* Popover panel (Allocations, Alerts, Analysis headers) */
.sort-filter-popover-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 100;
    min-width: 220px;
    padding: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] .sort-filter-popover-panel {
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.sort-filter-options-modern.sort-filter-options-in-popover {
    display: flex !important;
    flex-direction: column;
    gap: 6px;
    grid-template-columns: unset;
    margin: 0;
}

.sort-filter-options-in-popover .sort-option-modern {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* +2px vs default 13px on .sort-option-modern */
    font-size: 15px;
}

.sort-filter-options-in-popover .sort-option-modern .sort-icon-modern {
    font-size: 10px;
    line-height: 1;
    width: 1em;
    height: 1em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    vertical-align: middle;
    margin: 0;
}

