/* ===== 分組篩選區 ===== */
.group-filter-area {
    display: grid;
    gap: 8px;
    width: 100%;
}

.group-filter-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: center;
    gap: 12px;
}

.group-filter-inputs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.group-filter-inputs .form-select,
.group-filter-inputs .form-control {
    width: auto;
    max-width: 100%;
}

/* ===== 表格相關樣式 ===== */
.time-tag-select {
    min-height: 30px;
    display: flex;
    width: 100%;
    max-width: none;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}

.time-tag-select .time-tag-option {
    border: 1px solid #d6dce5;
    background-color: #f4f6f8;
    color: #263238;
    min-height: 26px;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}

.time-tag-select .time-tag-option.selected {
    border-color: #3A6FAC;
    background-color: #3A6FAC;
    color: #ffffff;
}

.time-tag-select .time-tag-empty {
    color: #6c757d;
    white-space: nowrap;
}

table.table thead th {
    vertical-align: middle;
    padding: 0 .5rem;
}

/* 表格標題寬度設定 */
.group-name-header {
    min-width: 250px;
    position: sticky;
    left: 0;
    z-index: 3;
    background-clip: padding-box;
    box-shadow: 1px 0 0 rgba(0, 0, 0, 0.12);
}

.group-email-header {
    min-width: 220px;
}

.group-risk-header {
    min-width: 100px;
    width: 100px;
    text-align: center;
}

.group-default-header {
    min-width: 75px;
    width: 75px;
    text-align: center;
}

.group-promocode-header {
    min-width: 100px;
    width: 100px;
    text-align: center;
}

/* Social Goal / After-party / Travel History (header) */
.group-social-meta-header {
    min-width: 200px;
    width: 200px;
    max-width: 200px;
}

.group-sign-header {
    min-width: 85px;
    width: 85px;
    text-align: center;
}

.group-visited-restaurant-header {
    min-width: 150px;
    width: 150px;
    text-align: center;
}

.group-recent-restaurant-header {
    min-width: 240px;
    width: 240px;
    text-align: center;
}

/* 表格內容單元格樣式 */
table.table tbody td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 0;
    /* 允許 text-overflow 生效 */
}

/* Occupation 欄位樣式 - 允許折行 */
.data-cell-occupation {
    min-width: 100px;
    width: 100px;
    text-align: center;
    white-space: normal !important;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    line-height: 1.2;
    padding: 0.5rem 0.0rem;
}

/* 未分組表格特定單元格寬度 */
.data-cell-name {
    min-width: 250px;
    position: sticky;
    left: 0;
    z-index: 2;
    background-clip: padding-box;
    box-shadow: 1px 0 0 rgba(0, 0, 0, 0.12);
}

.ungrouped-table {
    --bs-table-bg: #fff;
    --bs-table-striped-bg: #fff;
    --bs-table-active-bg: #fff;
}

.data-cell-email {
    min-width: 220px;
}

.data-cell-risk-analysis {
    min-width: 100px;
    width: 100px;
    text-align: center;
}

/* 名稱列徽章可依欄寬換行 */
.data-cell-name .user-name-html {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    white-space: normal;
}

.group-risk-score-wrap {
    flex: 0 0 auto;
}

.group-risk-score-badge {
    font-size: 12px;
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
}

.group-risk-score-badge:focus {
    outline: 2px solid rgba(13, 110, 253, 0.45);
    outline-offset: 2px;
}

.group-risk-analysis-tooltip {
    min-width: 520px;
    pointer-events: none;
}

.group-risk-analysis-tooltip .table-responsive {
    max-width: 680px;
}

.data-cell-default {
    min-width: 75px;
    width: 75px;
    text-align: center;
}

.data-cell-promocode {
    min-width: 100px;
    width: 100px;
}

/* Social Goal / After-party / Travel History (body) */
.data-cell-social-meta {
    min-width: 200px;
    width: 200px;
    max-width: 200px;
}

/* 新增 Visited Restaurant data cell 樣式 */
.data-cell-visited-restaurant {
    min-width: 150px;
    width: 150px;
    text-align: center;
    /* overflow: hidden; text-overflow: ellipsis; white-space: nowrap; are already on general td */
}

.data-cell-recent-restaurant {
    min-width: 240px;
    width: 240px;
    text-align: center;
}

.data-cell-recent-restaurant a {
    color: #000;
    text-decoration: none;
}

.booking-header {
    line-height: 25px;
}

.booking-header .bi {
    margin-top: -2px;
}

/* ===== 筆記組件樣式 ===== */
.note-component {
    width: 150px;
    display: flex;
    flex-direction: column;
    background-color: #f1f1f1;
}

.note-body {
    background-color: #f1f1f1;
    padding: 10px 10px;
}

/* Highlighted note area background */
.note-component.highlighted-note-area,
.note-body.highlighted-note-area {
    background-color: #DFE6DF;
}

.note-body textarea {
    width: 100%;
    min-height: 30px;
    /* 初始高度 */
    max-height: 120px;
    /* 最大高度，防止過長 */
    padding: 5px 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    resize: none;
    overflow-y: hidden;
    /* 防止出現捲動條 */
    font-size: 12px;
}

.group-reasons-btn.btn-outline-primary:not(:hover):not(:focus):not(:active) {
    background-color: #fff;
}

.group-reason-status-badge {
    color: #3A6FAC;
    border: 1px solid #3A6FAC;
}

.group-reason-model-badge {
    font-size: 0.4rem;
}

.note-body input {
    padding: 5px 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
}

/* ===== 響應式表格樣式 ===== */
.table-responsive {
    overflow-x: auto;
    overflow-y: hidden;
}

#groupSection-* {
    display: flex !important;
    align-items: stretch !important;
}

.border.p-3 .rounded.overflow-hidden.border {
    display: flex;
    align-items: stretch;
}

/* ===== 拖曳排序相關樣式 ===== */
.sortable-chosen {
    background: #ffeeba !important;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.sortable-ghost {
    background-color: #f8f9fa !important;
    opacity: 0.4;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.sortable-fallback {
    opacity: 0.8;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    background-color: white;
    max-width: 800px;
    z-index: 1000;
    border-radius: 4px;
    overflow: hidden;
}

.sortable-fallback td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== AI Generator 表格 ===== */
.ai-table-scroll {
    max-height: 360px;
    overflow-y: auto;
}

.ai-table-scroll.table-responsive {
    overflow-y: auto;
}

.ai-data-table {
    table-layout: fixed;
    width: 100%;
}

.ai-data-table th,
.ai-data-table td {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-data-table .ai-checkbox-header,
.ai-data-table .ai-checkbox-cell {
    min-width: 44px !important;
    width: 44px !important;
    max-width: 44px !important;
    text-align: center;
}

.ai-data-table th:not(.ai-checkbox-header),
.ai-data-table td:not(.ai-checkbox-cell) {
    width: calc((100% - 44px) / 5);
    max-width: calc((100% - 44px) / 5);
}

.ai-data-table .data-cell-tags {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
}

.ai-data-table .data-cell-name {
    overflow: visible;
    text-overflow: clip;
}

.ai-data-table .data-cell-email {
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-data-table .group-name-header,
.ai-data-table .group-email-header,
.ai-data-table .group-tags-header {
    text-align: left;
}

.ai-data-table .group-default-header,
.ai-data-table .data-cell-default {
    text-align: center;
}

.ai-data-table .email-cell,
.ai-data-table .email-text {
    cursor: default;
}

.ai-data-table .data-cell-name .tags-container {
    flex-wrap: wrap;
    white-space: normal;
}

.ai-data-table .data-cell-tags .tags-container {
    flex-wrap: wrap;
    white-space: normal;
    align-items: center;
}

.ai-tags-popup .tags-search-container {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 5px;
}

.ai-tags-popup .tags-search {
    flex-grow: 1;
}

.ai-tags-popup .tags-list {
    overflow-y: auto;
    max-height: 180px;
}

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

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

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

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

.ai-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: 2100;
    display: none;
}

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

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

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

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

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

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

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

.ai-feature-card {
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    background-color: #fff;
    min-width: 240px;
}

.ai-model-method-select {
    width: min(100%, 360px);
}

.ai-modal-scroll {
    max-height: 60vh;
    overflow-y: auto;
}

.ai-action-toolbar {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
}

.ai-action-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-action-check {
    font-size: 0.95rem;
}

.ai-action-btn:disabled {
    background-color: #cfd4da;
    border-color: #cfd4da;
    color: #6c757d;
    opacity: 1;
}

.ai-modal-scroll .list-group-item {
    font-family: "Courier New", Courier, monospace;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;
}

/* AI 生成中文字顏色漸變動畫（紅 -> 青 -> 綠 -> 黃 循環） */
@keyframes ai-generating-color-cycle {
    0% {
        color: #ff4d4f;
    }

    33% {
        color: #00bcd4;
    }

    66% {
        color: #4caf50;
    }

    100% {
        color: #ffeb3b;
    }
}

.ai-generating-anim {
    animation: ai-generating-color-cycle 1.6s linear infinite !important;
}

.ai-inline-spinner.ai-generating-anim {
    animation: spinner-border 0.75s linear infinite, ai-generating-color-cycle 1.6s linear infinite !important;
}

#aiPromptContent {
    max-height: 220px;
    overflow-y: auto;
    margin-bottom: 0;
}

#aiTagResultText {
    max-height: 45vh;
    overflow-y: auto;
    font-family: "Courier New", Courier, monospace;
    font-size: 0.9rem;
    white-space: pre;
}

/* ===== 綁定好友相關樣式 ===== */
/* 不在群組中的背景色 */
.table>tbody>tr[data-partner-not-in-group="true"] {
    --bs-table-bg: #F8E8E8;
}

.table>tbody>tr[data-partner-not-in-group="true"]:hover {
    --bs-table-bg: #F8E8E8;
}

/* 已綁定好友的背景色 */
.table>tbody>tr[data-has-bound="true"] {
    --bs-table-bg: #E8F7F8;
}

.table>tbody>tr[data-has-bound="true"]:hover {
    --bs-table-bg: #E8F7F8;
}

.table>tbody>tr[data-has-bound="true"] td {
    padding: 0;
}

/* 綁定好友合併行樣式 */
.table>tbody>tr[data-has-bound="true"] td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
}

.table>tbody>tr[data-has-bound="true"] td:nth-child(n+3) {
    text-align: center;
}

.table>tbody>tr[data-has-bound="true"] td:nth-child(n+3) .d-flex.flex-column>div {
    justify-content: center;
}

.table>tbody>tr[data-has-bound="true"] td>div.d-flex.flex-column {
    min-height: 80px;
    /* 設定最小高度確保有足夠空間 */
}

.table>tbody>tr[data-has-bound="true"] td>div.d-flex.flex-column>div {
    flex: 1;
    /* 讓兩個 div 平均分配高度 */
    display: flex;
    /* 使內容可以垂直置中 */
    align-items: center;
    /* 垂直置中內容 */
    padding: 0.5rem;
}

.table>tbody>tr[data-has-bound="true"] td>div.d-flex.flex-column>div:first-child {
    border-bottom: 1px solid #ccc !important;
}

.table>tbody>tr[data-has-bound="true"] td:nth-child(n+3) {
    text-align: center;
}

/* Loosely bound friend background color */
.table>tbody>tr[data-is-loose-bound="true"] {
    --bs-table-bg: #F3EEBD;
}

.table>tbody>tr[data-is-loose-bound="true"]:hover {
    --bs-table-bg: #F3EEBD;
    /* Keep same color on hover, or choose a slightly darker shade if preferred */
}

/* Ensure padding and other styles are consistent with strongly bound rows */
.table>tbody>tr[data-is-loose-bound="true"] td {
    padding: 0;
    /* Match data-has-bound */
}

.table>tbody>tr[data-is-loose-bound="true"] td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    /* Match data-has-bound */
}

.table>tbody>tr[data-is-loose-bound="true"] td:nth-child(n+3) {
    text-align: center;
    /* Match data-has-bound */
}

.table>tbody>tr[data-is-loose-bound="true"] td:nth-child(n+3) .d-flex.flex-column>div {
    justify-content: center;
    /* Match data-has-bound */
}

.table>tbody>tr[data-is-loose-bound="true"] td>div.d-flex.flex-column {
    min-height: 80px;
    /* Match data-has-bound */
}

.table>tbody>tr[data-is-loose-bound="true"] td>div.d-flex.flex-column>div {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 0.5rem;
    /* Match data-has-bound */
}

.table>tbody>tr[data-is-loose-bound="true"] td>div.d-flex.flex-column>div:first-child {
    border-bottom: 1px solid #ccc !important;
    /* Match data-has-bound */
}

/* Ensure grip icon style consistency */
.table>tbody>tr[data-is-loose-bound="true"] .bi-grip-vertical {
    cursor: grab;
    color: #aaa;
    margin-right: 4px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Highlighted group table header */
.table-highlighted-header thead th {
    background-color: #C5D5BF;
}

/* ===== 電子郵件相關樣式 ===== */
.email-cell {
    position: relative;
    padding: 4px 0;
    min-width: 150px;
    display: inline-block;
}

.email-text {
    display: block;
    position: relative;
    cursor: pointer;
}

/* Popover 內的 email-actions 樣式 */
.popover .email-actions a {
    text-decoration: none;
    color: #3A6FAC;
    font-size: 12px;
}

.popover .email-actions a:hover {
    text-decoration: underline;
}

/* ===== 解除綁定按鈕樣式 ===== */
.unbind-button {
    position: absolute;
    left: 43px;
    top: 49%;
    transform: translateY(-50%);
    z-index: 1;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background-color: transparent;
    background-image: url('../img/bound_icon.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 1;
}

.bi {
    display: inline-block;
    width: 1rem;
    height: 1rem;
}

.table>tbody>tr .bi-grip-vertical,
.table>tbody>tr[data-has-bound="true"] .bi-grip-vertical {
    cursor: grab;
    color: #aaa;
    margin-right: 4px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.unavailable-row {
    color: #777;
    opacity: 0.6;
    --bs-table-bg: #e9e9e9;
    --bs-table-striped-bg: #e9e9e9;
    --bs-table-active-bg: #e9e9e9;
}

/* ===== Email List Modal - 標籤篩選樣式（參考 users.css） ===== */
#emailListAllTagsBtn {
    background-color: #fff;
    border: 1px solid #ced4da;
    color: #495057;
    cursor: pointer;
    padding-right: 2rem !important;
}

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

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

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

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

/* Modal 內標籤彈出視窗，需浮在最上層（覆蓋 .modal-backdrop 和 .modal） */
.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: 2000; /* 高於 Bootstrap modal (1050~1100) */
    display: none;
    max-height: 250px;
}

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

.tags-popup .selected-tags-container {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 4px;
}

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

/* 已排除的 Email 清單樣式（灰階背景） */
#excludedEmailBlock .list-group-item {
    background-color: #f1f3f5;
}

#excludedEmailBlock h6 {
    color: #6c757d;
}

/* ===== AI 分組模型套用 Modal - 參加者小卡片樣式 ===== */
.attendee-mini-card {
    background-color: #f8f9fa;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.attendee-mini-card:hover {
    background-color: #e9ecef;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.attendee-tooltip {
    animation: fadeIn 0.2s ease-in-out;
}

.attendee-tooltip-floating {
    position: fixed;
    z-index: 2000;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    padding: 0.75rem;
    box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.15);
    width: max-content;
    max-width: min(720px, calc(100vw - 16px));
    max-height: calc(100vh - 16px);
    overflow-y: auto;
    overflow-x: hidden;
    pointer-events: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.attendee-tooltip strong {
    color: #495057;
}

.attendee-tooltip .mb-1:last-child {
    margin-bottom: 0 !important;
}

.attendee-tooltip .small {
    white-space: normal;
    word-break: break-word;
}

/* 自動分組 Modal 動作區塊 */
.algo-group-action-footer {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding: 0 1rem 1rem;
}

.algo-group-action-block {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 0.875rem;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background-color: #fff;
}

.algo-group-action-block-ai {
    border-color: #b6d4fe;
    background-color: #f8fbff;
}

.algo-group-action-title {
    font-weight: 600;
    color: #212529;
    margin-bottom: 0.25rem;
}

.algo-group-action-desc {
    color: #6c757d;
    font-size: 0.8125rem;
    line-height: 1.45;
}

.algo-group-action-btn {
    min-width: 112px;
    white-space: nowrap;
}

.algo-group-action-cancel-row {
    display: flex;
    justify-content: center;
    width: 100%;
}

@media (max-width: 575.98px) {
    .algo-group-action-block {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .algo-group-action-btn {
        width: 100%;
    }

    .algo-group-action-cancel-row {
        justify-content: stretch;
    }
}

@media (max-width: 768px) {
    #filterArea .group-filter-inputs input,
    #filterArea .group-filter-inputs select {
        flex: 0 1 auto;
        min-width: 0;
    }

    #groupHeader,
    #ungroupedHeader {
        align-items: stretch !important;
        gap: 8px;
    }

    #groupHeader > .d-flex,
    #ungroupedHeader > .d-flex {
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }

    #groupHeader .btn,
    #ungroupedHeader .btn {
        flex: 1 1 120px;
        margin-right: 0 !important;
    }

    #groupsContainer,
    #ungroupedSection .border.p-3 {
        padding: 0.75rem !important;
    }

    .border.p-3 .rounded.overflow-hidden.border {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .border.p-3 .rounded.overflow-hidden.border > .table-responsive {
        min-width: 780px;
    }

    .note-component {
        min-width: 150px;
    }

    .group-risk-analysis-tooltip,
    .high-risk-detail-tooltip {
        min-width: 0;
        max-width: calc(100vw - 24px);
    }

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

.group-loading-toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 2147483647;
    display: flex;
    align-items: center;
    gap: 10px;
    width: max-content;
    max-width: calc(100vw - 32px);
    padding: 12px 18px;
    border-radius: 8px;
    background: #263238;
    color: #fff;
    box-shadow: 0 4px 18px #0003;
    pointer-events: none;
}
.group-loading-toast[hidden] { display: none; }
.group-loading-toast .spinner-border { flex-shrink: 0; }
@media (prefers-reduced-motion: reduce) {
    .group-loading-toast .spinner-border { animation: none; }
}
