/* --- 全域與色彩變數 --- */
:root {
    --primary-blue: #040b57;
    --accent-yellow: #ffd700;
    --light-text: #ffffff;
    --dark-text: #333333;
    --border-color: #dee2e6;
    --hover-bg: #f0f3ff;
    --body-bg: #f8f9fa;
}

body {
    background-color: var(--body-bg);
    color: var(--dark-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.screener-container {
    max-width: 1400px;
    margin: 2rem auto;
}

/* --- 頁首標題 --- */
.main-header h1 {
    color: var(--primary-blue);
    font-weight: bold;
    margin-bottom: 1.5rem;
    text-align: center;
}

#searchInput {
    /* 縮短搜尋欄寬度以符合需求 */
    max-width: 240px;
    flex: 0 0 200px;
    min-width: 120px;
}

#marketTypeSelect,
#assetTypeSelect {
    max-width: 160px;
    flex: 1 1 auto;
}

.screener-filter-container {
    display: flex;
    flex-wrap: wrap; /* 在小螢幕上自動換行 */
    gap: 1rem; /* 篩選器之間的間距 */
    padding: 1.5rem;
    background-color: var(--light-text);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 2rem;
}

.form-control, .form-select {
    border: 1px solid var(--border-color);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 0.2rem rgba(4, 11, 87, 0.25);
    outline: none;
}

/* --- 按鈕樣式 --- */
.btn {
    border: none;
    border-radius: 5px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

.btn-primary {
    background-color: var(--primary-blue);
    color: var(--light-text);
}

.btn-primary:hover {
    background-color: #06117a; /* 加深一點的藍色 */
    transform: translateY(-2px);
}

.btn-secondary {
    background-color: #6c757d;
    color: var(--light-text);
}
.btn-secondary:hover {
    background-color: #5a6268;
    transform: translateY(-2px);
}


.table-custom {
    width: 100%;
    border-collapse: collapse;
}

/* 表格頭部 (Sticky Header) */
.table-custom thead th {
    background-color: var(--primary-blue);
    color: var(--light-text);
    padding: 1rem;
    vertical-align: middle;
    position: sticky; /* 關鍵：讓表頭固定 */
    top: 0;
    z-index: 10;
    white-space: nowrap;
}

.table-custom th.sortable {
    cursor: pointer;
}

.table-custom td:nth-child(5),
.table-custom th:nth-child(5),  /* 股價 */
.table-custom td:nth-child(6),
.table-custom th:nth-child(6) { /* 漲跌 */
    min-width: 100px;
}

/* 右對齊、搜尋高亮、右上計數 */
.text-right { text-align: right; }
.search-mark { background-color: #fff176; padding: 0 .15em; border-radius: 2px; }

/* filters row: align filters left and match summary right */
.filters-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 0.75rem;
}

.match-summary {
  position: static;
  margin-left: auto;
  padding: 8px 12px;
  min-width: 140px;
  text-align: right;
  border-radius: 6px;
  font-weight: 600;
  color: var(--dark-text);
  display: inline-block;
  z-index: 5;
}

@media (max-width: 768px) {
  .filters-row { flex-direction: column; align-items: stretch; }
  .filters-row .match-summary { margin-left: 0; margin-top: 0.5rem; align-self: flex-end; min-width: auto; text-align: right; }
}

/* 排序箭頭 */
.sort-arrow {
    display: inline-block;
    width: 1em;
    text-align: center;
    color: rgba(255, 255, 255, 0.5); /* 預設半透明 */
}
.sort-arrow.sort-asc::after {
    content: '▲';
    color: var(--accent-yellow); /* 激活時變黃色 */
}
.sort-arrow.sort-desc::after {
    content: '▼';
    color: var(--accent-yellow); /* 激活時變黃色 */
}

/* 表格內容 */
.table-custom tbody td {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

/* 漲跌顯示樣式 */
.change-up {
    color: #d93025; /* 紅色代表上漲 */
    font-weight: 600;
}
.change-down {
    color: #0f9d58; /* 綠色代表下跌 */
    font-weight: 600;
}
.change-neutral {
    color: inherit;
    font-weight: 600;
}
.change-up::before,
.change-down::before {
    margin-right: 0.25rem;
}

.table-responsive {
    position: relative; /* container for match summary and allow page scroll */
    overflow: visible; /* ensure ancestor doesn't create an internal scroll (keeps sticky working) */
}

/* wrapper used in the template - also ensure it's not scrollable */
.screener-table-wrap {
    overflow: visible;
}

.table-custom thead th {
position: sticky;
top: 0; /* 固定在頂部 */
z-index: 10; /* 確保表頭在滾動內容之上 */
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1); /* 添加一點陰影，增加視覺效果 */
}

/* 調整 tooltip 的 z-index 確保在 sticky header 上方顯示 */
.tooltip-icon {
z-index: 11;
}

/* Header and filters scroll with page to let table header stick to viewport properly */
.main-header, .screener-filter-container {
  position: static;
  z-index: auto;
  padding-bottom: 15px;
  margin-bottom: 1rem;
  box-shadow: none;
}

/* 將篩選區上排 (filters) 固定在表格上方並橫向排列 */
.screener-filter-container {
  display: flex;
  flex-direction: column; /* 先垂直堆疊：上方為 controls，下方為 table */
  gap: 0.75rem;
  padding: 12px 1rem; /* 左右保留內縮空間，避免內容貼齊容器邊緣 */
}

/* 內層 controls 橫向排列 */
.screener-filter-container .filters {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap; /* 小螢幕換行 */
  width: 100%;
}

/* 讓搜尋列與表格本體也有少量內縮，並確保 box-sizing 處理邊距 */
.screener-filter-container .filters,
.screener-filter-container .screener-table-wrap {
  padding-inline: 0.5rem; /* 微調內縮，讓搜尋與表格左右不貼邊 */
  box-sizing: border-box;
}

/* 控制項尺寸與彈性 */
.screener-filter-container .filters > * {
  flex: 0 0 auto;
  min-width: 0;
}

#searchInput {
  flex: 0 0 200px;
  min-width: 120px;
  max-width: 240px;
} 

.screener-filter-container select.form-control,
.screener-filter-container .form-select {
  flex: 0 0 160px;
  min-width: 120px;
}

.screener-filter-container .btn {
  flex: 0 0 auto;
}

/* 優化手機版佈局 */
@media (max-width: 768px) {
.screener-filter-container {
flex-direction: column; /* 在小螢幕上垂直排列 */
}
/* table uses page scrolling on mobile as well */
}

/* 滑鼠懸停效果 (Hover) */
.table-custom tbody tr:hover {
    background-color: var(--hover-bg);
}

/* 連結樣式 */
.table-custom tbody a {
    color: var(--primary-blue);
    text-decoration: none;
    font-weight: 500;
}
.table-custom tbody a:hover {
    text-decoration: underline;
    color: #06117a;
}

.no-data {
    padding: 2rem;
    font-size: 1.2rem;
    color: #6c757d;
}


/* --- 備註區域 --- */
.notes-section {
    margin-top: 2rem;
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: #6c757d;
    line-height: 1.6;
}

.notes-section p {
    margin-bottom: 0.5rem;
}

/* 提示符號樣式 */
.tooltip-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: #FFD700; /* 黃色背景 */
    color: #002060; /* 深藍色問號 */
    font-size: 12px;
    line-height: 16px;
    text-align: center;
    cursor: help; /* 鼠標變成問號提示 */
    margin-left: 5px;
    position: relative; /* 用於定位提示文字 */
    font-weight: bold;
}

.tooltip-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    right: 10%;
    top: 200%;
    transform: translate(-10px, 10px);
    background-color: #FFD700;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 1.2em;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    max-width: 250px;
    min-width: 200px;
    white-space: normal;
    word-wrap: break-word;
}

.tooltip-icon:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translate(-10px, 10px); /* 滑鼠懸停時保持在目標位置 */
}

.tooltip-icon::before {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: calc(100% + 5px); /* **改為向下顯示，箭頭位置在文字上方，指向問號** */
    border-width: 5px;
    border-style: solid;
    border-color: transparent transparent #FFD700 transparent; /* **黃色箭頭，方向向上** */
    z-index: 1001;
    opacity: 0; /* 初始隱藏 */
    visibility: hidden; /* 初始隱藏 */
    transition: opacity 0.3s ease, visibility 0.3s ease;
}


.tooltip-icon:hover::after,
.tooltip-icon:hover::before {
    opacity: 1;
    visibility: visible;
}