/* 全局樣式 */
* { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: #f7f7f7;
  color: #333;
  line-height: 1.6;
  margin: 0;
  padding: 0;
}

/* 頁面容器 */
.page-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f7f7f7;
}

/* 上傳區塊與圖表區塊 */
.upload-block, .visualization-block, .analyze-confirm-block, .analyzing-block {
  padding: 20px 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.visualization-block .container, .analyzing-block .container {
  margin-top: 20px;
}

.analyze-confirm-block .container {
  margin-top: 20px;
  text-align: center;
  padding: 30px 20px;
}

/* 新增：分析中區塊樣式 */
.analyzing-block .container {
  text-align: center;
  padding: 50px 20px;
}

.analyzing-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.analyzing-title {
  font-size: 1.6rem;
  font-weight: 600;
  margin: 20px 0;
  color: #333;
}

/* 旋轉的加載圖標 */
.spinner {
  width: 60px;
  height: 60px;
  border: 5px solid #f3f3f3;
  border-top: 5px solid #0084ff;
  border-radius: 50%;
  animation: spin 1.5s linear infinite;
  margin-bottom: 10px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 上傳區域 */
.upload-section {
  margin-bottom: 1.5rem;
  padding: 30px;
  background-color: #ffffff;
  border: 2px dashed #ccc;
  border-radius: 12px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  text-align: center;
}

.upload-section.dragover {
  border-color: #666;
  background-color: #f0f0f0;
}

.file-label {
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
  margin-bottom: 0.5rem;
}

.help-text {
  color: #666;
  font-size: 0.875rem;
  margin-top: 0.5rem;
  margin-bottom: 1rem;
}

/* 載入指示器 */
.loading-indicator {
  text-align: center;
  padding: 1rem;
  font-size: 1rem;
  color: #333;
}

/* 受眾名稱設定區域 */
.audience-naming-section {
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 20px;
  margin-bottom: 20px;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #333;
}

.audience-naming-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 20px;
}

.audience-input-group {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px;
  border-radius: 8px;
  background-color: #f9f9f9;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);/* 這裡是陰影效果 */
}

.audience-file-name {
  font-weight: 500;
  min-width: 180px;
  flex-shrink: 0;
}

.audience-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.95rem;
  transition: border-color 0.3s;
}

.audience-input:focus {
  border-color: #0084ff;
  outline: none;
  box-shadow: 0 0 0 2px rgba(0, 132, 255, 0.2);
}

/* 淡出動畫效果 */
.fade-out {
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.button-container {
  display: flex;
  justify-content: center;
  gap: 15px; /* 按鈕之間的間距 */
  margin-top: 20px;
}

/* 確保主要按鈕更加突出 */
.primary-btn {
  background-color: #0084ff;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 120px; /* 確保按鈕有足夠寬度 */
  /* 將陰影調深、調大 */
  box-shadow: 0 4px 12px rgba(0, 132, 255, 0.25);
}

/* 滑鼠懸停效果 */
.primary-btn:hover {
  background-color: #006ad4;
  transform: translateY(-2px);
}

/* 次要按鈕樣式，讓它更輕量化 */
.secondary-btn {
  background-color: #f0f0f0;
  color: #555;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 10px 15px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.secondary-btn:hover {
  background-color: #e0e0e0;
  transform: translateY(-1px);
}

/* 分頁按鈕樣式 */
.tab-btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  background-color: #f0f0f0;
  color: #333;
  cursor: pointer;
  font-size: 1rem;
  transition: background-color 0.3s, color 0.3s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tab-btn:hover {
  background-color: #e0e0e0;
  transform: translateY(-1px);
}

.tab-btn.active {
  background-color: #cccccc;
  font-weight: bold;
}

/* 重新分析按鈕容器 */
.reanalyze-container {
  display: flex;
  justify-content: center;
  gap: 25px; /* 增加按鈕間距 */
  margin-top: 20px;
  padding-top: 10px;
}

/* 視覺化區域 */
.visualization-container {
  padding: 20px 0;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
}

/* 標籤區域 */
.tabs {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
}

/* 圖表區域 */
.chart-container {
  background-color: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); /* 這裡是陰影效果 */
}

.chart-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #333;
}

/* 熱力圖區域 */
.heatmap-container {
  margin-top: 5rem;
  /* 增加上方間距 */
  width: 100%;
}

.heatmap-legend {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
  gap: 5px;
}

.legend-item {
  width: 24px;
  height: 24px;
  border-radius: 4px;
}

.legend-text {
  font-size: 0.85rem;
  color: #333;
}

/* 熱力圖表格容器 */
.heatmap-table-container {
  margin-top: 2.5rem;
  /* 增加表格容器與圖例之間的間距 */
}

.heatmap-table {
  width: 100%;
  border-collapse: collapse;
  background-color: #ffffff;
  color: #333;
}

.heatmap-table th,
.heatmap-table td {
  padding: 8px;
  border: 1px solid #ddd;
  text-align: center;
}

/* 如果標題文字較長，允許在適當位置換行 */
.heatmap-table th {
  background-color: transparent;
  font-weight: 600;
  white-space: normal;
  word-wrap: break-word;
  vertical-align: middle;
}

.heatmap-table td:first-child {
  font-weight: 500;
  text-align: left;
}

/* 移除單元格的 title 懸停效果（消除 tooltip） */
.heatmap-table td {
  cursor: default !important;
}

/* 通用樣式 */
.hidden {
  display: none;
}

.reset-btn {
  background-color: #e5e5e5;
  color: #333;
  border-radius: 8px;
  padding: 10px 20px;
  border: none;
  transition: background-color 0.3s;
}

.reset-btn:hover {
  background-color: #d1d1d1;
}

/* 隱藏原生「選擇檔案」按鈕與「未選擇任何檔案」 */
.file-input {
  display: none;
}

/* 點擊時 upload 區塊的視覺反饋 */
.upload-section:active {
  background-color: #e0e0e0;   /* 按下時變成淺灰 */
  border-color:    #999;      /* 邊框變深一點 */
  box-shadow: 0 0 8px rgba(0,0,0,0.2);
  transform: scale(0.995);    /* 縮放一點點，模擬按下感 */
}

/* 永遠保留垂直捲軸，避免因出現/消失而引起頁面左右位移 */
html {
  overflow-y: scroll;
}

/* ---------- 自訂全域捲軸寬度與樣式 ---------- */
/* Chrome、Safari 等 WebKit 核心瀏覽器 */
::-webkit-scrollbar {
  width: 12px;               /* 捲軸寬度 */
  height: 12px;
}
::-webkit-scrollbar-track {
  background: transparent;   /* 軌道顏色，可改成淺灰或透明 */
}
::-webkit-scrollbar-thumb {
  background-color: rgba(0,0,0,0.2); /* 捲軸滑塊顏色 */
  border-radius: 6px;                /* 圓角 */
  border: 3px solid transparent;     /* 內邊框讓滑塊變細 */
}

/* Firefox */
html {
  scrollbar-width: thin;                /* 捲軸變細 */
  scrollbar-color: rgba(0,0,0,0.2) transparent; /* 滑塊色 + 軌道色 */
}


/* 漸層圖例樣式 */
.heatmap-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  position: relative;
  padding-bottom: 15px;
  /* 為刻度騰出空間 */
}

.legend-text {
  font-size: 0.85rem;
  color: #333;
  margin: 0 10px;
}

.legend-gradient {
  height: 20px;
  width: 70%;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.legend-scale {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  height: 15px;
  display: flex;
}

.scale-marker {
  position: absolute;
  font-size: 0.7rem;
  color: #666;
  transform: translateX(-50%);
}

/* 標籤單元格樣式 - 修改為固定寬度 */
.heatmap-table td.label-cell {
  font-weight: 500;
  text-align: right;
  padding-right: 15px;
  border: none;  /* 先移除所有邊框 */
  border-right: 1px solid #ddd;
  position: relative;
  background-color: transparent;
  white-space: normal; 
  width: 200px !important;  /* 固定寬度 */
  min-width: 200px !important;
  max-width: 200px !important;
  height: auto;
  min-height: 40px;
  vertical-align: middle;
}

/* 確保標籤文字過長時能正常換行 */
.heatmap-table td.label-cell,
.heatmap-table th:first-child {
  overflow-wrap: break-word;
  word-wrap: break-word;
  hyphens: auto;
}

/* 添加刻度線樣式 */
.heatmap-table td.label-cell::after {
  content: '';
  position: absolute;
  right: -4px;
  /* 刻度線向右延伸 */
  width: 4px;
  /* 刻度線長度 */
  height: 1px;
  background-color: transparent;
  top: 50%;
  transform: translateY(-50%);
}

/* 標題樣式 - 修改為固定寬度 */
.heatmap-table th:first-child {
  text-align: right;
  padding: 15px 15px 15px 8px; /* 上、右、下、左 */
  border: none;  /* 先移除所有邊框 */
  border-right: 1px solid #ddd;
  background-color: transparent;
  white-space: normal; /* 修改為normal允許換行 */
  width: 200px !important;  /* 固定寬度 */
  min-width: 200px !important;
  max-width: 200px !important;
}

/* 調整標題行的高度，確保有足夠空間 */
.heatmap-table thead tr {
  height: auto;
  min-height: 60px;
}

/* 為標題添加更好的視覺區分 */
.heatmap-table thead {
  border-bottom: 2px solid transparent;
}

/* 修改表格容器 */
.heatmap-table-container {
  flex: 1;
  overflow-x: auto;
}

/* 標籤標題樣式 */
.label-header {
  position: absolute;
  top: 0;
  left: 0;
  padding: 8px;
  padding-right: 15px;
  font-weight: 600;
  background-color: #f0f0f0;
  height: 39px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  /* 標題靠右對齊 */
  width: 200px;
  /* 與左側標籤容器寬度一致 */
  box-sizing: border-box;
  border-bottom: 1px solid #ddd;
  text-align: right;
}

/* 受眾欄位寬度設定 - 修改為固定寬度並允許換行 */
.heatmap-table th:not(:first-child),
.heatmap-table td:not(:first-child) {
  width: 120px !important;
  min-width: 120px !important;
  max-width: 120px !important;
  word-wrap: break-word;
  white-space: normal;
  height: auto;
  line-height: 1.4;
  vertical-align: middle;
  padding: 10px 8px;
}

/* 調整標題文字樣式，使其有更好的可讀性 */
.heatmap-table th:not(:first-child) {
  font-size: 0.95rem;
  padding: 15px 12px;
  background-color: transparent;
  border-left: 1px solid transparent;
  border-right: 1px solid transparent;
  border-top: 1px solid transparent;
}

/* 增加表格列的最小高度，確保有足夠空間顯示換行的文字 */
.heatmap-table tr {
  min-height: 50px;
}

/* 調整表格容器，確保可以水平滾動 */
.heatmap-table-container {
  flex: 1;
  overflow-x: auto;
  margin-bottom: 20px; /* 為捲軸留出底部空間 */
}

/* 設定表格佈局為固定，確保欄位寬度計算穩定 */
.heatmap-table {
  width: auto; /* 讓表格寬度根據內容自動調整 */
  table-layout: fixed;
}

/* 長條圖容器樣式，與熱力圖保持一致 */
.chart-container-wrapper {
  width: 100%;
  margin-top: 2.5rem; /* 與熱力圖容器相同的上方間距 */
}

.canvas-container {
  margin-top: 2.5rem; /* 與熱力圖表格容器相同的間距 */
  background-color: #ffffff;
  border-radius: 8px;
  padding: 15px;
  /* 重要：確保容器能夠正確容納內容 */
  overflow: hidden; /* 防止意外溢出 */
  width: 100%;
}

/* 確保長條圖在容器中正確顯示 */
.canvas-container canvas {
  display: block;
  width: 100%;
  min-height: 400px; /* 設置最小高度 */
  height: auto; /* 允許根據內容自動調整高度 */
}

/* 確保圖表區域有足夠空間 */
.chart-area {
  width: 100%;
  min-height: 400px; /* 最小高度 */
}

.heatmap-table th.empty-header-cell {
  border: none;
  background-color: transparent;
}

/* X 按鈕樣式 */
.remove-audience-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-color: #f1f1f1;
  color: #666;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  transition: all 0.2s ease;
}

.remove-audience-btn:hover {
  background-color: #ff4d4d;
  color: white;
}

/* 頁面標題容器樣式 - 新增 */
.page-title-container {
  text-align: center;
  padding: 20px 0;
  background-color: #ffffff;
  border-bottom: 1px solid #e0e0e0;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.main-title {
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #333;
}

.stage-subtitle {
  font-size: 1.2rem;
  font-weight: 500;
  color: #666;
  margin: 0;
}

/* 新增綜合分析區塊樣式 */
.analysis-section {
  margin-top: 30px;
  padding-top: 25px;
}

.analysis-title {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 15px;
  color: #333;
}

.analysis-content {
  font-size: 1rem;
  line-height: 1.6;
  color: #444;
  background-color: #f9f9f9;
  padding: 15px;
  border-radius: 8px;
  border-left: 4px solid #0084ff;
}

/* 圖表操作按鈕 */
.chart-action-buttons {
  position: static;
  top: 15px;
  right: 15px;
  display: flex;
  gap: 10px;
}

.icon-btn {
  background-color: #f0f0f0;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.icon-btn:hover {
  background-color: #e0e0e0;
  transform: translateY(-2px);
}

/* 分析操作按鈕區塊 */
.analysis-action-block {
  display: flex;
  justify-content: flex-end; /* 按鈕靠右 */
  padding: 5px 0;
  margin-bottom: 10px; /* 與下方內容保持間距 */
  position: relative;
}

.copy-btn {
  position: static;
}

/* 確保複製按鈕樣式與其他圖表操作按鈕一致 */
.icon-btn.copied::after {
  content: '已複製';
  position: absolute;
  top: -30px;
  right: 50%;
  transform: translateX(50%);
  background-color: #333;
  color: white;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  z-index: 100; /* 確保在其他元素上方 */
}

.icon-btn.copied::before {
  content: '';
  position: absolute;
  top: -8px;
  right: 50%;
  transform: translateX(50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #333;
  z-index: 100; /* 確保在其他元素上方 */
}

/* Token 使用情況區塊 */
.token-usage {
  text-align: center;
  margin-bottom: 15px;
  color: #666;
  font-size: 0.9rem;
}

/* 確保圖表容器有相對定位 */
.chart-container-wrapper {
  position: relative;
}

.heatmap-container {
  position: relative;
}

/* 新增操作按鈕區塊樣式 */
.action-buttons-block {
  display: flex;
  justify-content: flex-end; /* 按鈕靠右 */
  padding: 10px 0;
  margin-bottom: 15px; /* 與下方圖表保持間距 */
}

/* Token 使用情況容器 */
.token-usage-container {
  text-align: center;
  margin: 15px 0;
}

/* Token 使用情況詳細樣式 */
.token-usage {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 15px;
  padding: 6px 12px;
  border-radius: 4px;
  background-color: transparent;
  font-size: 0.9rem;
  font-weight: 500;
}

.token-detail {
  display: inline-block;
  padding: 0 5px;
}

.token-total {
  display: inline-block;
  padding: 0 5px;
  font-weight: 600;
}

/* 品牌信息區塊樣式 */
.brand-info-block {
  padding: 20px 0;
}

.brand-info-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin: 15px 0;
}

.brand-info-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.brand-info-label {
  font-weight: 500;
  color: #444;
  font-size: 0.95rem;
}

.brand-info-input {
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 1rem;
  transition: border-color 0.3s ease;
}

.brand-info-input:focus {
  border-color: #0084ff;
  outline: none;
  box-shadow: 0 0 0 2px rgba(0, 132, 255, 0.2);
}