/* ====================================
   盤前總經速覽 - Widget 樣式表 (V2 Compact)
   Theme: Author Brand (Warm White, Magenta, Cyan, Red)
   ==================================== */

:root {
    /* 主色調 - 暖白系列 */
    --bg-primary: #FDF5E6;
    --bg-widget: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.8);

    /* 文字顏色 */
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;

    /* 狀態顏色 (依據圖例：紅=樂觀，黃=持平，藍=保守) */
    --color-positive: #EF4444;       /* 紅色 - 樂觀 */
    --color-positive-bg: rgba(239, 68, 68, 0.08);

    --color-negative: #3B82F6;       /* 藍色 - 保守 */
    --color-negative-bg: rgba(59, 130, 246, 0.08);

    --color-neutral: #F59E0B;        /* 黃色 - 持平 */
    --color-neutral-bg: rgba(245, 158, 11, 0.08);

    /* 圓角與陰影 */
    --radius-widget: 16px;
    --radius-card: 10px;
    --shadow-widget: 0 4px 20px rgba(166, 138, 100, 0.15);

    /* 字體 */
    --font-stack: 'Inter', 'Noto Sans TC', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-stack);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* 垂直排列 */
    align-items: center;
    /* 水平置中 */
    padding: 40px 20px;
    /* 上下左右留白 */
    gap: 20px;
    /* 兩個 Widget 間距 */
    /* 背景裝飾光暈 */
    background-image:
        radial-gradient(circle at 10% 20%, rgba(239, 68, 68, 0.03) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(59, 130, 246, 0.03) 0%, transparent 40%);
}

/* ====================================
   Widget Container
   ==================================== */
.macro-widget {
    width: 100%;
    max-width: 680px;
    /* 統一寬度 */
    background: var(--bg-widget);
    border-radius: var(--radius-widget);
    box-shadow: var(--shadow-widget);
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.02);
}

/* ====================================
   Top Section: Weather Bar
   ==================================== */
.weather-bar {
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    transition: background 0.3s ease;
}

/* 情敘顏色變化 (透過 JS 增加 class) */
.weather-bar.bullish {
    background: linear-gradient(to right, var(--color-positive-bg), transparent);
}

.weather-bar.bearish {
    background: linear-gradient(to right, var(--color-negative-bg), transparent);
}

.weather-bar.neutral {
    background: linear-gradient(to right, var(--color-neutral-bg), transparent);
}

.weather-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.weather-icon {
    font-size: 2.2rem;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.1));
}

.weather-text {
    display: flex;
    flex-direction: column;
}

.weather-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.weather-sub {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-top: 2px;
}

/* Mini Update Section */
.mini-update {
    display: flex;
    align-items: center;
    gap: 10px;
}

#update-time {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.mini-refresh {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.1rem;
    padding: 4px;
    transition: color 0.2s;
}

.mini-refresh:hover {
    color: var(--color-neutral);
}

.mini-refresh.loading {
    animation: spin 1s infinite linear;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* ====================================
   Bottom Section: Mini Cards
   ==================================== */
.mini-cards-row {
    padding: 20px 24px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    /* 3列 x 2行 = 6個 */
    gap: 16px;
    background: #fafafa;
    /* 微微灰底區分 */
}

.mini-card {
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.04);
    border-radius: var(--radius-card);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.mini-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.mini-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 6px;
}

.mini-date {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-muted);
    background: #f0f0f0;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: none;
}

.mini-value-group {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    /* 改為靠左對齊，避免數據與燈號距離太遠 */
    gap: 12px;
    /* 增加間距 */
}

.mini-value {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

/* 指示燈點點 */
.indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.indicator.up {
    background: var(--color-positive);
    box-shadow: 0 0 6px var(--color-positive);
}

.indicator.down {
    background: var(--color-negative);
    box-shadow: 0 0 6px var(--color-negative);
}

.indicator.stable {
    background: var(--color-neutral);
}

/* ====================================
   Mini Legend
   ==================================== */
.mini-legend {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    /* 項目之間的距離 */
    margin-top: 12px;
    padding: 8px 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    /* 點與文字的距離 */
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: block;
    /* 讓寬高生效 */
}

/* 圖例顏色 - 景氣燈號風格 (獨立於全域變數) */
.dot.green {
    background: #EF4444;
    /* 鮮紅色 - 樂觀 */
    box-shadow: 0 0 6px #EF4444;
}

.dot.yellow {
    background: #F59E0B;
    /* 琥珀色 - 持平 */
    box-shadow: 0 0 6px #F59E0B;
}

.dot.red {
    background: #3B82F6;
    /* 藍色 - 保守 */
    box-shadow: 0 0 6px #3B82F6;
}

/* ====================================
   Dividend Widget (除息+股期區塊)
   ==================================== */
.dividend-widget {
    width: 100%;
    max-width: 680px;
    /* 與總經 Widget 相同寬度 */
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.dividend-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--color-positive) 0%, #c4006a 100%);
    color: white;
}

.dividend-icon {
    font-size: 1.25rem;
}

.dividend-title {
    flex: 1;
    font-size: 1rem;
    font-weight: 700;
}

.refresh-btn-small {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.refresh-btn-small:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(180deg);
}

/* Help Tooltip */
.help-tooltip {
    position: relative;
    display: inline-flex;
    margin-left: 8px;
}

.help-icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: help;
}

.help-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 8px;
    background: #333;
    color: white;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.help-content::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #333;
}

.help-tooltip:hover .help-content {
    display: block;
}

.help-line {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
}

.dot-mini {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot-mini.magenta {
    background: #E20074;
}

.dot-mini.cyan {
    background: #00AEEF;
}

.dot-mini.red {
    background: #FF0000;
}

.dividend-list {
    padding: 12px 16px;
    max-height: 300px;
    overflow-y: auto;
}

.dividend-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
}

.dividend-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
    font-size: 0.9rem;
}

.dividend-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: #fafafa;
    border-radius: 10px;
    transition: all 0.2s;
}

.dividend-item:hover {
    background: #f0f0f0;
    transform: translateX(4px);
}

.dividend-item:last-child {
    margin-bottom: 0;
}

.dividend-stock-code {
    min-width: 50px;
    font-weight: 700;
    color: var(--color-positive);
    font-size: 0.85rem;
}

.dividend-stock-name {
    flex: 1;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.dividend-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: #eee;
    padding: 3px 8px;
    border-radius: 4px;
    margin-right: 10px;
}

.dividend-amount {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.dividend-type-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

.dividend-type-badge.cash {
    color: #d63384;
    background: rgba(214, 51, 132, 0.1);
}

.dividend-type-badge.stock {
    color: #198754;
    background: rgba(25, 135, 84, 0.1);
}

.dividend-futures-badge {
    font-size: 0.65rem;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, #00AEEF 0%, #0088cc 100%);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 6px;
    white-space: nowrap;
}

.dividend-yield-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

/* 高殖利率 >= 5% (高標 - 此處借用正面色/紅色) */
.dividend-yield-badge.yield-high {
    color: #fff;
    background: linear-gradient(135deg, #EF4444 0%, #c40000 100%);
}

/* 中殖利率 3% ~ 5% (持平 - 青色) */
.dividend-yield-badge.yield-mid {
    color: #fff;
    background: linear-gradient(135deg, #00AEEF 0%, #0088cc 100%);
}

/* 低殖利率 < 3% (保守 - 紅色) */
.dividend-yield-badge.yield-low {
    color: #fff;
    background: linear-gradient(135deg, #FF0000 0%, #cc0000 100%);
}

.dividend-footer {
    padding: 10px 16px;
    background: #fafafa;
    border-top: 1px solid #eee;
}

.dividend-note {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ====================================
   Responsive
   ==================================== */
@media (max-width: 600px) {
    body {
        padding: 20px 10px;
        /* 手機版左右 padding 一致 */
    }

    .macro-widget {
        margin: 0 auto;
        /* 水平置中 */
        width: calc(100% - 20px);
        /* 扣除左右各 10px */
        max-width: none;
    }

    .weather-bar {
        padding: 16px;
    }

    .mini-cards-row {
        grid-template-columns: repeat(2, 1fr);
        /* 手機版變2列 */
        padding: 16px;
    }

    .weather-title {
        font-size: 1rem;
    }

    .dividend-widget {
        margin: 0 auto;
        /* 水平置中 */
        width: calc(100% - 20px);
        /* 扣除左右各 10px */
        max-width: none;
    }

    .dividend-item {
        flex-wrap: wrap;
        gap: 6px;
    }

    .dividend-stock-name {
        flex: unset;
        width: 100%;
        order: -1;
    }
}

/* ====================================
   分頁切換 Tabs
   ==================================== */
.dividend-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #eee;
    padding: 0 16px;
    background: #fafafa;
}

.dividend-tab {
    padding: 12px 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s ease;
}

.dividend-tab:hover {
    color: var(--text-primary);
}

.dividend-tab.active {
    color: var(--color-positive);
    border-bottom-color: var(--color-positive);
    font-weight: 600;
}

.dividend-tab-content {
    display: none;
}

.dividend-tab-content.active {
    display: block;
}

/* ====================================
   股期比較表格
   ==================================== */
.comparison-table-container {
    max-height: 400px;
    overflow: auto;
    padding: 8px 16px;
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.comparison-table thead {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 1;
}

.comparison-table th {
    padding: 10px 8px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid #eee;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.comparison-table th:hover {
    background: #f5f5f5;
}

.comparison-table th::after {
    content: ' ↕';
    color: #ccc;
    font-size: 0.7rem;
}

.comparison-table th.sort-asc::after {
    content: ' ↑';
    color: var(--color-positive);
}

.comparison-table th.sort-desc::after {
    content: ' ↓';
    color: var(--color-negative);
}

.comparison-table td {
    padding: 10px 8px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}

.comparison-table tbody tr:hover {
    background: #fafafa;
}

.comparison-table .stock-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.comparison-table .stock-code {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.comparison-table .positive {
    color: var(--color-positive);
    font-weight: 600;
}

.comparison-table .highlight {
    background: linear-gradient(90deg, var(--color-positive-bg), transparent);
}

.comparison-note {
    padding: 10px 16px;
    font-size: 0.7rem;
    color: var(--text-muted);
    border-top: 1px solid #eee;
}

.loading-cell {
    text-align: center;
    color: var(--text-muted);
    padding: 30px !important;
}

/* 手機版表格樣式 */
@media (max-width: 600px) {
    .dividend-tabs {
        padding: 0 8px;
    }

    .dividend-tab {
        padding: 10px 14px;
        font-size: 0.8rem;
    }

    .comparison-table-container {
        padding: 8px;
    }

    .comparison-table {
        font-size: 0.75rem;
    }

    .comparison-table th,
    .comparison-table td {
        padding: 8px 4px;
    }

    /* 隱藏部分欄位 */
    .comparison-table th:nth-child(3),
    .comparison-table td:nth-child(3),
    .comparison-table th:nth-child(4),
    .comparison-table td:nth-child(4) {
        display: none;
    }
}

/* ====================================
   總經區塊分頁樣式
   ==================================== */
.macro-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    padding: 0 8px;
}

.macro-tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 20px;
    transition: all 0.2s ease;
}

.macro-tab:hover {
    background: rgba(226, 0, 116, 0.08);
    color: var(--color-positive);
}

.macro-tab.active {
    background: var(--color-positive);
    color: white;
}

.macro-tab-content {
    display: none;
}

.macro-tab-content.active {
    display: block;
}

/* ====================================
   市場熱度指標樣式
   ==================================== */
.heat-container {
    padding: 16px;
}

.heat-main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    margin-bottom: 20px;
}

.heat-gauge {
    text-align: center;
}

.heat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.heat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.heat-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.04);
}

.heat-icon {
    font-size: 1.8rem;
}

.heat-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* 熱度等級顏色 */
.heat-status.safe {
    background: rgba(34, 197, 94, 0.1);
}

.heat-status.safe .heat-text {
    color: #16a34a;
}

.heat-status.normal {
    background: rgba(34, 197, 94, 0.08);
}

.heat-status.normal .heat-text {
    color: #22c55e;
}

.heat-status.warning {
    background: rgba(234, 179, 8, 0.12);
}

.heat-status.warning .heat-text {
    color: #ca8a04;
}

.heat-status.danger {
    background: rgba(239, 68, 68, 0.12);
}

.heat-status.danger .heat-text {
    color: #dc2626;
}

.heat-status.cold {
    background: rgba(59, 130, 246, 0.1);
}

.heat-status.cold .heat-text {
    color: #2563eb;
}

/* 詳細數據區 */
.heat-details {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 12px;
    margin-bottom: 16px;
}

.heat-item {
    text-align: center;
}

.heat-item-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.heat-item-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* 判斷標準圖例 */
.heat-legend {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.heat-legend-item {
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.03);
}

/* 響應式調整 */
@media (max-width: 768px) {
    .heat-main {
        flex-direction: column;
        gap: 16px;
    }

    .heat-details {
        grid-template-columns: repeat(2, 1fr);
    }

    .heat-legend {
        gap: 8px;
    }

    .heat-legend-item {
        font-size: 0.7rem;
    }
}

/* ====================================
   Indicator Popup (詳細資料彈窗)
   ==================================== */
.indicator-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.indicator-popup-overlay.active {
    display: flex;
    opacity: 1;
}

.indicator-popup {
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    min-width: 280px;
    max-width: 350px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    position: relative;
    transform: scale(0.9);
    opacity: 0;
    transition: all 0.25s ease;
}

.indicator-popup-overlay.active .indicator-popup {
    transform: scale(1);
    opacity: 1;
}

.popup-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: #f0f0f0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup-close:hover {
    background: var(--color-positive);
    color: white;
}

.popup-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 2px solid #f0f0f0;
}

.popup-icon {
    font-size: 1.8rem;
}

.popup-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.popup-content {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: #fafafa;
    border-radius: 10px;
}

.popup-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.popup-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.popup-value.up {
    color: var(--color-positive);
}

.popup-value.down {
    color: var(--color-negative);
}

.popup-value.stable {
    color: var(--color-neutral);
}

/* Mobile popup adjustments */
@media (max-width: 600px) {
    .indicator-popup {
        min-width: 260px;
        max-width: calc(100% - 40px);
        padding: 20px;
    }

    .popup-title {
        font-size: 1.1rem;
    }
}