/* AI 策略回測系統 - 深色主題 (類似 TradingView) */

:root {
    --bg-primary: #131722;
    --bg-secondary: #1e222d;
    --bg-tertiary: #2a2e39;
    --text-primary: #d1d4dc;
    --text-secondary: #787b86;
    --text-muted: #5d606b;
    --accent-blue: #2962ff;
    --accent-purple: #7c4dff;
    --positive: #26a69a;
    --negative: #ef5350;
    --border-color: #363a45;
    --hover-bg: #2a2e39;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* 頂部導航 */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    font-size: 24px;
}

.logo-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.nav {
    display: flex;
    gap: 24px;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 4px;
    transition: all 0.2s;
}

.nav-link:hover,
.nav-link.active {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.header-stats {
    display: flex;
    gap: 24px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.stat-value {
    font-size: 16px;
    font-weight: 600;
}

.stat-value.positive {
    color: var(--positive);
}

.stat-value.negative {
    color: var(--negative);
}

/* 主內容區 */
.main-content {
    padding: 24px;
    max-width: 1600px;
    margin: 0 auto;
}

/* 篩選器 */
.filters {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 24px;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.filter-group select {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    min-width: 140px;
}

.filter-group select:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.btn-primary {
    padding: 8px 20px;
    background: var(--accent-blue);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #1e4bd8;
}

/* 策略表格 */
.strategies-container {
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.strategies-table {
    width: 100%;
    min-width: 1200px;
    border-collapse: collapse;
}

.strategies-table th,
.strategies-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.strategies-table th {
    background: var(--bg-tertiary);
    font-weight: 500;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    white-space: nowrap;
}

.strategies-table tbody tr {
    transition: background 0.15s;
}

.strategies-table tbody tr:hover {
    background: var(--hover-bg);
}

.strategies-table td {
    font-size: 14px;
}

.strategies-table td.loading {
    text-align: center;
    padding: 48px;
    color: var(--text-muted);
}

/* 數值顏色 */
.positive {
    color: var(--positive);
}

.negative {
    color: var(--negative);
}

/* 商品標籤 */
.symbol-badge {
    display: inline-block;
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.symbol-badge.crypto {
    background: rgba(247, 147, 26, 0.2);
    color: #f7931a;
}

.symbol-badge.stock {
    background: rgba(41, 98, 255, 0.2);
    color: #2962ff;
}

.symbol-badge.commodity {
    background: rgba(255, 215, 0, 0.2);
    color: #ffd700;
}

/* 時間框架標籤 */
.timeframe-badge {
    display: inline-block;
    padding: 3px 6px;
    background: rgba(156, 39, 176, 0.2);
    color: #ce93d8;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

/* 回測期間 */
.backtest-period {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* 操作按鈕 */
.btn-view {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--accent-blue);
    border-radius: 4px;
    color: var(--accent-blue);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-view:hover {
    background: var(--accent-blue);
    color: white;
}

/* Modal 彈窗 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    overflow-y: auto;
}

.modal.active {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    width: 100%;
    max-width: 1200px;
    border: 1px solid var(--border-color);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 500;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

/* 績效指標網格 */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.metric-card {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: 8px;
    text-align: center;
}

.metric-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.metric-value {
    font-size: 24px;
    font-weight: 600;
}

/* 圖表容器 */
.chart-container {
    background: var(--bg-tertiary);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 32px;
    position: relative;
}

.chart-container h3 {
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: 500;
}

.chart-container canvas {
    max-height: 300px;
    width: 100% !important;
    height: 300px !important;
}

/* 交易明細表格 */
.trades-section h3 {
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: 500;
}

.trades-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-tertiary);
    border-radius: 8px;
    overflow: hidden;
}

.trades-table th,
.trades-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

.trades-table th {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 500;
}

.trades-table-wrapper {
    max-height: 400px;
    overflow-y: auto;
}

.trades-table .time-cell {
    font-size: 12px;
    white-space: nowrap;
    color: var(--text-secondary);
}

/* 方向標籤 */
.direction-long {
    color: var(--positive);
}

.direction-short {
    color: var(--negative);
}

/* 響應式 */
@media (max-width: 1024px) {
    .filters {
        flex-wrap: wrap;
    }

    .header-stats {
        display: none;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 0 16px;
    }

    .nav {
        display: none;
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        border-radius: 6px;
        color: var(--text-primary);
        font-size: 20px;
        cursor: pointer;
        padding: 8px 12px;
        transition: all 0.2s;
    }

    .mobile-menu-btn:hover {
        background: var(--accent-blue);
        border-color: var(--accent-blue);
    }

    .mobile-menu {
        display: none;
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
        flex-direction: column;
        z-index: 99;
    }

    .mobile-menu.active {
        display: flex;
    }

    .mobile-nav-link {
        padding: 14px 24px;
        color: var(--text-secondary);
        text-decoration: none;
        border-bottom: 1px solid var(--border-color);
    }

    .mobile-nav-link.active {
        color: var(--text-primary);
        background: var(--bg-tertiary);
    }

    .main-content {
        padding: 16px;
    }

    .strategies-table th,
    .strategies-table td {
        padding: 8px 10px;
        font-size: 12px;
    }

    .strategies-container {
        overflow-x: auto;
    }
}

/* 桌面版隱藏手機選單 */
.mobile-menu-btn {
    display: none;
}

.mobile-menu {
    display: none;
}

/* 手機版選單展開狀態 (高優先級) */
.mobile-menu.active {
    display: flex !important;
}

/* 載入動畫 */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-muted);
    border-radius: 50%;
    border-top-color: var(--accent-blue);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 頁面切換 */
.page-content {
    display: none;
}

.page-content.active {
    display: block;
}

.page-title {
    font-size: 24px;
    font-weight: 500;
    margin-bottom: 24px;
    color: var(--text-primary);
}

/* 商品比較網格 */
.compare-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.compare-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.compare-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.compare-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.compare-card-title {
    font-size: 18px;
    font-weight: 600;
}

.compare-card-return {
    font-size: 20px;
    font-weight: 700;
}

.compare-card-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.compare-stat {
    display: flex;
    flex-direction: column;
}

.compare-stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.compare-stat-value {
    font-size: 16px;
    font-weight: 500;
}

/* 統計分析網格 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stats-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 24px;
    text-align: center;
}

.stats-card-icon {
    font-size: 32px;
    margin-bottom: 12px;
}

.stats-card-value {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.stats-card-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* 圖表行 */
.charts-row {
    display: flex;
    gap: 24px;
    margin-top: 24px;
}

@media (max-width: 1024px) {
    .charts-row {
        flex-direction: column;
    }
}

/* 交易詳情彈窗 */
.trade-detail-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
    overflow-y: auto;
}

.trade-detail-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    width: 100%;
    max-width: 800px;
    border: 1px solid var(--border-color);
}

.trade-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.trade-detail-header h3 {
    font-size: 18px;
    font-weight: 500;
}

.trade-detail-body {
    padding: 20px;
}

.detail-section {
    margin-bottom: 24px;
}

.detail-section h4 {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.detail-grid .label {
    color: var(--text-muted);
    margin-right: 8px;
}

.detail-text {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: var(--text-secondary);
    max-height: 300px;
    overflow-y: auto;
    font-family: inherit;
}

/* 詳情按鈕 */
.btn-detail {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--accent-purple);
    border-radius: 4px;
    color: var(--accent-purple);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-detail:hover {
    background: var(--accent-purple);
    color: white;
}

/* 策略邏輯區塊 */
.strategy-logic-section {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.strategy-logic-section h3 {
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: 500;
}

.strategy-logic-content {
    background: var(--bg-tertiary);
    padding: 20px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: var(--text-secondary);
    max-height: 500px;
    overflow-y: auto;
}