/* 使用者頭像和名稱容器樣式 */
.name-container {
    display: flex;
    align-items: start;
    gap: 10px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    object-fit: cover;
}

.name-content {
    flex: 1;
}

.user-name {
    font-weight: 500;
    margin-bottom: 4px;
}

/* 表格容器樣式 */
#tableContainer {
    overflow-y: auto;
    border: 1px solid #dee2e6;
    border-radius: 8px;
}

.users-table {
    font-size: 13px;
}

.users-table-header th {
    background-color: #DADADA;
    font-weight: 700;
    line-height: 1.25;
    padding: 10px 8px;
    position: sticky;
    text-align: center;
    top: 0;
    vertical-align: middle;
    z-index: 2;
}

.users-table-header th:first-child {
    border-top-left-radius: 8px;
}

.users-table-header th:last-child {
    border-top-right-radius: 8px;
}

.users-table th.name-column,
.users-table th.flex-col,
.users-table-header th:nth-child(4) {
    text-align: left;
}

/* 固定寬度欄位 */
.fixed-width-col {
    /* 用於核取方塊 */
    width: 2% !important;
    min-width: 2% !important;
    max-width: 2% !important;
}

.name-column {
    width: 15% !important;
    min-width: 15% !important;
    max-width: 15% !important;
}

.col-width-90 {
    width: 5% !important;
    min-width: 5% !important;
    max-width: 5% !important;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.col-width-120 {
    width: 10% !important;
    min-width: 10% !important;
    max-width: 10% !important;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.col-width-200 {
    width: 15% !important;
    min-width: 15% !important;
    max-width: 15% !important;
}

/* 彈性寬度欄位 */
.flex-col {
    flex: 1;
    min-width: 0;
    /* 允許縮小 */
}

#tableBody tr td:nth-child(3) {
    /* Email 欄位 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 標籤彈出視窗樣式 */
.tags-popup {
    position: absolute;
    width: 220px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    z-index: 1050;
    display: none;
    max-height: 250px;
}

.tags-popup.show {
    display: block;
}

.tags-popup .tags-search {
    padding: 8px;
    border-bottom: 1px solid #eee;
    position: sticky;
    /* 使搜尋欄固定 */
    top: 0;
    /* 固定在彈出視窗頂部 */
    background: white;
    /* 確保有背景色 */
    z-index: 1;
    /* 保持在列表上方 */
}

.tags-popup .tags-search input {
    width: 100%;
    padding: 6px 10px;
    font-size: 14px;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
}

.tags-popup .tags-list {
    overflow-y: auto;
    height: calc(100% - 35px);
}

.tags-popup .tags-list .tag {
    margin: 4px 0;
    width: fit-content;
    display: inline-flex;
    justify-content: flex-start;
}

.tags-popup .tags-list .tag-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.tags-popup .tags-list .tag-options-btn {
    border: 0;
    background: transparent;
    color: #6c757d;
    padding: 0 4px;
    cursor: pointer;
}

.tags-popup .tags-list .tag-options-btn:hover {
    color: #212529;
}

.tag-delete-popup {
    position: absolute;
    width: 200px;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    z-index: 1060;
    display: none;
}

.tag-delete-popup.show {
    display: block;
}

.tag-delete-popup .tags-search-container {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px;
    border-bottom: 1px solid #eee;
}

.tag-delete-popup .tags-search {
    width: 100%;
    padding: 6px 10px;
    font-size: 14px;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
}

.tag-delete-popup .btn-update-tag {
    background-color: #666;
    color: #fff;
    white-space: nowrap;
}

.tag-delete-popup .btn-update-tag:hover {
    background-color: #4f4f4f;
}

.tag-delete-popup .tag-delete-action {
    padding: 8px;
    display: flex;
    align-items: center;
}

.tag-delete-popup .tag-delete-btn {
    border: 0;
    background: transparent;
    color: #dc3545;
    cursor: pointer;
    padding: 2px 4px;
}

.tag-delete-popup .tag-delete-btn:hover {
    color: #b02a37;
}

/* 標籤列表的自訂捲軸 */
.tags-popup .tags-list::-webkit-scrollbar {
    width: 8px;
}

.tags-popup .tags-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.tags-popup .tags-list::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.tags-popup .tags-list::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 標籤篩選下拉選單樣式 */
.tags-popup .tags-list::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 所有標籤按鈕樣式 - 模仿 select 外觀 */
#allTagsBtn {
    background-color: #fff;
    background-image: none;
    border: 1px solid #ced4da;
    color: #495057;
    cursor: pointer;
    padding-right: 2rem !important;
}

#allTagsBtn:hover {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

#allTagsBtn:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
    outline: 0;
}

#allTagsBtn:active {
    background-color: #e9ecef;
    border-color: #86b7fe;
}

#allTagsBtn .bi-chevron-down,
#allTagsBtn .bi-chevron-up {
    font-size: 0.75rem;
    color: #6c757d;
}

@media (max-width: 768px) {
    .content {
        --mobile-table-min-width: 1200px;
    }

    .users-table {
        min-width: 1200px;
        table-layout: fixed;
    }

    .content > .my-2.d-flex.border {
        gap: 8px;
    }

    .content > .my-2.d-flex.border .d-inline-block {
        flex: 1 1 150px;
        min-width: 0;
        margin-right: 0 !important;
    }

    .content > .my-2.d-flex.border .d-inline-block[style*="border-left"] {
        display: none !important;
    }

    #totalUsersCount {
        display: block;
        padding: 4px 0;
        text-align: right;
        width: 100%;
    }

    .users-table-header .fixed-width-col,
    #tableContainer .fixed-width-col {
        width: 48px !important;
        min-width: 48px !important;
        max-width: none !important;
    }

    .users-table-header .name-column,
    #tableContainer .name-column {
        width: 200px !important;
        min-width: 200px !important;
        max-width: none !important;
    }

    .users-table-header .flex-col,
    #tableContainer .flex-col {
        width: 220px !important;
        min-width: 220px !important;
        max-width: none !important;
    }

    .users-table-header .col-width-90,
    #tableContainer .col-width-90 {
        width: 88px !important;
        min-width: 88px !important;
        max-width: none !important;
    }

    .users-table-header .col-width-120,
    #tableContainer .col-width-120 {
        width: 116px !important;
        min-width: 116px !important;
        max-width: none !important;
    }

    .users-table-header .col-width-200,
    #tableContainer .col-width-200 {
        width: 220px !important;
        min-width: 220px !important;
        max-width: none !important;
    }

    .tags-popup,
    .tag-delete-popup {
        max-height: min(70vh, 420px);
        max-width: calc(100vw - 24px);
        width: min(320px, calc(100vw - 24px));
    }
}
