/* 基本樣式 */
body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 20px;
    background-color: #f4f7f6;
    color: #333;
    box-sizing: border-box; 
}

*, *::before, *::after {
    box-sizing: inherit; 
}

.container {
    max-width: 1200px; 
    margin: 0 auto;
    padding: 0 15px;
}

h1, h2, h3, h4 {
    color: #2c3e50;
}

h1 {
    text-align: center;
    margin-bottom: 30px;
    font-size: 2.5em;
}

h2 {
    font-size: 1.8em;
    border-bottom: 2px solid #3498db;
    padding-bottom: 10px;
    margin-top: 0;
}

h3 {
    font-size: 1.5em;
    margin-bottom: 15px;
}

h4 {
    font-size: 1.2em;
    margin-bottom: 10px;
    flex-shrink: 0; 
}

/* 卡片樣式 */
.card {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    padding: 25px;
    margin-bottom: 25px;
    transition: box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

/* 搜尋區域 */
.search-section h2 {
    border-bottom: none;
    margin-bottom: 15px;
}
.search-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

#itemNameInput {
    flex-grow: 1;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1em;
    transition: border-color 0.3s ease;
}

#itemNameInput:focus {
    border-color: #3498db;
    outline: none;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

#searchButton {
    padding: 12px 25px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.3s ease;
}

#searchButton:hover {
    background-color: #2980b9;
}

.recency-filter-section {
    margin-top: 20px; 
    padding-bottom: 10px; 
}
.recency-filter-section h4 {
    margin-bottom: 12px; 
    text-align: left; 
    font-size: 1.1em; 
    color: #34495e; 
}
.recency-options-horizontal {
    display: flex;
    flex-wrap: wrap; 
    gap: 20px; 
    align-items: center;
}
.recency-options-horizontal .recency-option { 
    display: flex;
    align-items: center;
}
.recency-options-horizontal input[type="radio"] {
    margin-right: 6px; 
    cursor: pointer;
}
.recency-options-horizontal label {
    cursor: pointer;
    font-size: 1em; 
    color: #555; 
}


/* 進階篩選按鈕容器 */
#advancedFilterButtonContainer {
    padding: 15px 25px; 
    text-align: center; 
}

#openAdvancedFilterButton {
    padding: 12px 28px; 
    background-color: #e67e22; 
    color: white;
    border: none;
    border-radius: 8px; 
    cursor: pointer;
    font-size: 1.1em; 
    font-weight: bold; 
    transition: background-color 0.3s ease, transform 0.1s ease; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.1); 
    display: inline-block; 
}

#openAdvancedFilterButton:hover {
    background-color: #d35400; 
    transform: translateY(-1px); 
}
#openAdvancedFilterButton:active {
    transform: translateY(0px); 
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.current-filters-display {
    margin-top: 15px; 
    font-size: 0.9em;
    color: #555;
    text-align: left; 
}
.current-filters-display span {
    background-color: #eaf2f8;
    padding: 3px 8px;
    border-radius: 12px; 
    margin-right: 8px;
    margin-bottom: 5px; 
    display: inline-flex; 
    align-items: center;
    font-size: 0.9em;
}

.remove-filter-tag {
    background-color: #e74c3c; 
    color: white;
    border: none;
    border-radius: 50%; 
    width: 18px;
    height: 18px;
    font-size: 12px;
    line-height: 16px; 
    text-align: center;
    cursor: pointer;
    margin-left: 6px;
    padding: 0;
    font-weight: bold;
}
.remove-filter-tag:hover {
    background-color: #c0392b; 
}


/* 概覽和分佈網格 */
.overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); 
    gap: 15px; 
    margin-top: 15px;
}

.distribution-grid { 
    display: grid;
    grid-template-columns: repeat(2, 1fr); 
    gap: 20px;
    margin-top: 15px;
}

.rfm-distribution-grid { 
    display: grid;
    grid-template-columns: repeat(2, 1fr); 
    gap: 20px;
    margin-top: 15px;
}


.overview-grid div {
    background-color: #ecf0f1;
    padding: 15px;
    border-radius: 6px;
    text-align: center;
    font-size: 0.9em; 
}
.overview-grid div strong {
    font-size: 1.1em; 
    display: block;
    margin-top: 5px;
    color: #2c3e50;
}

/* 圖表容器 */
.chart-container {
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background-color: #fdfdfd;
    height: 380px; 
    display: flex;
    flex-direction: column;
    position: relative; 
    overflow: hidden; 
}
.chart-canvas-wrapper { 
    flex-grow: 1; 
    position: relative; 
    min-height: 0; 
}

.chart-container canvas {
    display: block; 
    max-width: 100%; 
    max-height: 100%; 
}
.text-fallback {
    text-align: center;
    color: #777;
    font-size: 0.9em;
    margin-top: 10px;
    flex-grow: 1; 
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 頁籤樣式 */
.tabs {
    overflow: hidden;
    border-bottom: 1px solid #ccc;
    margin-bottom: 20px;
}

.tab-link {
    background-color: #f1f1f1;
    float: left;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 14px 16px;
    transition: 0.3s;
    font-size: 1em;
    border-radius: 6px 6px 0 0; 
    margin-right: 2px;
}

.tab-link:hover {
    background-color: #ddd;
}

.tab-link.active {
    background-color: #3498db;
    color: white;
}

.tab-content {
    display: none; 
    padding: 0px 12px; 
    border-top: none;
}
.tab-content.active {
    display: block; 
}
.tabs::after { 
    content: "";
    clear: both;
    display: table;
}

/* RFM 表格 */
#rfmTable {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    font-size: 0.9em;
}

#rfmTable th, #rfmTable td {
    border: 1px solid #ddd;
    padding: 10px 12px;
    text-align: left;
    vertical-align: middle;
}

#rfmTable th {
    background-color: #3498db;
    color: white;
    font-weight: bold;
}

#rfmTable tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}

#rfmTable tbody tr:hover {
    background-color: #eaf2f8;
}

.info-icon {
    width: 14px;
    height: 14px;
    vertical-align: middle;
    margin-left: 4px;
    cursor: help;
}

/* RFM Level Colors */
.rfm-level-low-good { 
    background-color: #e6ffe6; 
    color: #006400; 
    padding: 2px 5px;
    border-radius: 3px;
    display: inline-block; 
}
.rfm-level-medium { 
    background-color: #fff0e6; 
    color: #cc8400; 
    padding: 2px 5px;
    border-radius: 3px;
    display: inline-block;
}
.rfm-level-high-bad { 
    background-color: #ffe6e6; 
    color: #990000; 
    padding: 2px 5px;
    border-radius: 3px;
    display: inline-block;
}


/* 受眾包操作 */
.audience-package-action {
    margin-top: 20px;
    padding: 15px;
    background-color: #e9ecef;
    border-radius: 6px;
    text-align: center;
}
.audience-package-action p {
    font-size: 1.1em;
    margin-bottom: 10px;
}
.audience-package-action strong {
    color: #007bff;
}
#createAudiencePackageButton {
    padding: 12px 30px;
    background-color: #e67e22;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1em;
    transition: background-color 0.3s ease;
}
#createAudiencePackageButton:hover {
    background-color: #d35400;
}

/* 載入與錯誤訊息 */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border-left-color: #09f;
    animation: spin 1s ease infinite;
    margin-bottom: 10px;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
#loadingIndicatorText {
    font-size: 1.2em;
    color: #555;
}

.error-message {
    background-color: #f8d7da;
    color: #721c24;
    padding: 15px;
    border: 1px solid #f5c6cb;
    border-radius: 6px;
    margin-bottom: 20px;
    text-align: center;
}
.success-message {
    background-color: #d4edda; 
    color: #155724; 
    padding: 10px; 
    margin-bottom: 15px; 
    border-radius: 5px; 
    text-align:center;
}

/* 進階篩選模態框樣式 */
.modal {
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.4); 
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto; 
    padding: 20px;
    border: 1px solid #888;
    width: 80%; 
    max-width: 750px; 
    border-radius: 8px;
    position: relative;
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.filter-note {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 15px;
    border-left: 3px solid #3498db;
    padding-left: 10px;
}

/* 模態框內頁籤樣式 */
.filter-tabs {
    overflow: hidden;
    border-bottom: 1px solid #ccc;
    margin-bottom: 15px;
}

.filter-tab-link {
    background-color: #f9f9f9;
    float: left;
    border: 1px solid #ccc;
    border-bottom: none;
    outline: none;
    cursor: pointer;
    padding: 10px 15px;
    transition: 0.3s;
    font-size: 0.95em;
    border-radius: 4px 4px 0 0;
    margin-right: 2px;
}

.filter-tab-link:hover {
    background-color: #e7e7e7;
}

.filter-tab-link.active {
    background-color: #fff;
    border-color: #ccc;
    border-bottom: 1px solid #fff; 
    color: #3498db;
    font-weight: bold;
}

.filter-tab-content {
    display: none;
    padding-top: 10px;
}
.filter-tab-content.active {
    display: block;
}
.filter-tabs::after {
    content: "";
    clear: both;
    display: table;
}


.filter-sections-container {
    max-height: 55vh; 
    overflow-y: auto; 
    margin-bottom: 20px;
    padding-right: 10px; 
}

.filter-section {
    margin-bottom: 20px;
    border: 1px solid #eee;
    padding: 15px;
    border-radius: 6px;
}

.filter-section h5 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.1em;
    color: #3498db;
}

.filter-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); 
    gap: 10px;
}

.filter-options label {
    display: flex;
    align-items: center;
    font-size: 0.95em;
    cursor: pointer;
}
.filter-options input[type="checkbox"] {
    margin-right: 8px;
}

.modal-actions {
    text-align: right;
    margin-top: 20px;
}
.modal-actions button {
    padding: 10px 20px;
    border-radius: 5px;
    border: none;
    cursor: pointer;
    font-size: 1em;
    margin-left: 10px;
}
#applyAdvancedFiltersButton {
    background-color: #2ecc71;
    color: white;
}
#applyAdvancedFiltersButton:hover {
    background-color: #27ae60;
}
#clearAdvancedFiltersButton {
    background-color: #e74c3c;
    color: white;
}
#clearAdvancedFiltersButton:hover {
    background-color: #c0392b;
}

/* 頁腳查詢時間 */
.footer {
    text-align: center;
    margin-top: 30px;
    padding: 15px;
    font-size: 0.9em;
    color: #777;
    border-top: 1px solid #eee;
}

/* *** NEW: Management Area Styling *** */
#managementArea {
    background-color: #e8f6f3; /* Light teal background */
    border-top: 3px solid #1abc9c; /* Teal top border */
}
#managementArea h2 {
    color: #16a085; /* Darker teal for heading */
    border-bottom: 1px solid #a3e4d7; /* Light teal underline */
}
.management-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}
.management-controls label {
    font-weight: bold;
    color: #2c3e50;
}
#loadAudienceIdInput {
    flex-grow: 1;
    padding: 10px 12px;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    font-size: 0.95em;
}
#loadAudienceButton, #generateAudienceFilesButton {
    padding: 10px 20px;
    background-color: #1abc9c; /* Teal button */
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.3s ease;
}
#loadAudienceButton:hover, #generateAudienceFilesButton:hover {
    background-color: #16a085;
}
#managementMessage {
    font-weight: bold;
}
#downloadLinksContainer a {
    display: block;
    margin: 5px 0;
    color: #2980b9;
    text-decoration: none;
}
#downloadLinksContainer a:hover {
    text-decoration: underline;
}
/* *** END NEW *** */


/* 響應式調整 */
@media (max-width: 1024px) { 
    .distribution-grid, .rfm-distribution-grid { 
        grid-template-columns: 1fr; 
    }
    .recency-options-horizontal {
        flex-direction: column; 
        align-items: flex-start; 
    }
    .recency-options-horizontal .recency-option { 
        margin-bottom: 5px; 
    }
    .management-controls {
        flex-direction: column;
        align-items: stretch;
    }
    #loadAudienceIdInput, #loadAudienceButton {
        width: 100%;
    }
     #loadAudienceButton {
        margin-top: 10px;
    }
}

@media (max-width: 768px) {
    .search-controls {
        flex-direction: column;
        align-items: stretch;
    }
    #itemNameInput, #searchButton {
        width: 100%;
    }
    .overview-grid, .distribution-grid, .rfm-distribution-grid { 
        grid-template-columns: 1fr; 
    }
    .tabs .tab-link, .filter-tabs .filter-tab-link { 
        float: none;
        display: block;
        width: 100%;
        text-align: left;
        margin-bottom: 1px;
        border-radius: 6px; 
    }
    .tabs, .filter-tabs { 
        border-bottom: none; 
    }
    .modal-content {
        width: 95%;
        margin: 10% auto;
    }
    .filter-options {
        grid-template-columns: 1fr; 
    }

    #rfmTable th, #rfmTable td {
        padding: 8px;
        font-size: 0.85em;
    }
    h1 { font-size: 2em; }
    h2 { font-size: 1.5em; }
    h3 { font-size: 1.3em; }

    .recency-options-horizontal {
        flex-direction: column;
        align-items: flex-start;
    }
     .recency-options-horizontal .recency-option { 
        margin-bottom: 8px; 
    }
	
}
#line-customer {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  background-color: #00c300;
  color: white;
  padding: 12px 18px;
  border-radius: 50px;
  font-size: 16px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  text-decoration: none;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

#line-customer:hover {
  background-color: #009f28;
  transform: translateY(-2px);
}
/* --- 優惠活動區塊樣式 --- */
#promo-banner-card {
    background: linear-gradient(135deg, #fff8e1, #ffecb3); /* 淺黃色漸變背景 */
    border: 2px solid #ffc107; /* 醒目的黃色邊框 */
    text-align: center;
    padding: 30px;
}

.promo-banner-content h3 {
    color: #c56200; /* 深橘色標題 */
    font-size: 1.8em;
    margin-bottom: 15px;
}

.promo-description {
    font-size: 1.1em;
    color: #5d4037;
    margin-bottom: 20px;
}

.promo-details {
    margin: 20px 0;
    font-size: 1.2em;
    color: #bf360c; /* 火焰紅色 */
    font-weight: bold;
}

.promo-details .promo-deadline {
    background-color: #ffc107;
    color: #000;
    padding: 2px 8px;
    border-radius: 4px;
}

.promo-cta-button {
    background: #ff5722; /* 鮮豔的橘紅色 */
    color: white;
    border: none;
    border-radius: 8px;
    padding: 15px 30px;
    font-size: 1.3em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 87, 34, 0.4);
    width: 100%;
    margin-top: 15px;
}

.promo-cta-button:hover {
    background: #e64a19; /* 更深的橘紅色 */
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(255, 87, 34, 0.5);
}
.promo-details .promo-code {
    background-color: #2c3e50; /* 深藍灰背景 */
    color: #ffffff; /* 白色文字 */
    padding: 3px 10px;
    border-radius: 5px;
    font-family: monospace;
    font-size: 1.1em;
    border: 1px dashed #ffc107;
}
.promo-gift-item {
    margin: 15px 0;
}

.promo-main-gift {
    margin-bottom: 5px; /* 縮小主說明和次說明的間距 */
}

.promo-sub-detail {
    font-size: 0.9em; /* 讓字體稍微小一點 */
    color: #5d4037; /* 使用較柔和的顏色 */
    font-weight: normal; /* 取消粗體 */
    margin: 0 auto;
    padding: 5px 15px;
    max-width: 80%; /* 讓寬度稍微內縮，看起來更像註解 */
    border-left: 3px solid #ffca28; /* 左側加上一條強調線 */
    text-align: left; /* 文字靠左對齊，更易閱讀 */
}