/**
 * 图表样式表
 */

.chart-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin: 10px;
    min-height: 450px;
    position: relative;
    overflow: hidden;
}

.chart-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    border-radius: 8px 8px 0 0;
}

.tradingview-chart {
    flex: 1;
    width: 100%;
    min-height: 400px;
    position: relative;
}

.tradingview-chart.main-pane {
    min-height: 420px;
}

.indicator-chart {
    width: 100%;
    height: 160px;
    min-height: 140px;
    position: relative;
}

.indicator-pane {
    border-top: 1px solid #202a39;
    background: rgba(10, 16, 25, 0.92);
}

.indicator-pane.hidden {
    display: none;
}

.indicator-pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid #1d2735;
    font-size: 11px;
    color: #7f8a9a;
    letter-spacing: 0.04em;
}

#indicatorTitle {
    color: #f3f4f6;
    font-weight: 700;
}

.tradingview-chart canvas {
    width: 100% !important;
    height: 100% !important;
}

/* 时间周期按钮 */
.timeframe-buttons {
    display: flex;
    gap: 4px;
}

.tf-btn {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.tf-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.tf-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
}

/* 指标按钮 */
.indicator-buttons {
    display: flex;
    gap: 4px;
}

.ind-btn {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.ind-btn:hover {
    background: var(--border-color);
}

.ind-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
}

/* 图表错误提示 */
.chart-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(246, 70, 93, 0.1);
    border: 1px solid var(--sell-color);
    border-radius: 8px;
    padding: 20px 40px;
    text-align: center;
    color: var(--sell-color);
    z-index: 100;
}

.chart-error i {
    font-size: 32px;
    margin-bottom: 10px;
    display: block;
}

/* 图表加载状态 */
.chart-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    z-index: 100;
}

.chart-loading i {
    animation: spin 1s linear infinite;
}

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

/* 订单簿样式 */
.orderbook-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    margin: 10px;
}

.orderbook-panel h4 {
    margin-bottom: 10px;
    font-size: 14px;
    color: var(--text-secondary);
}

.orderbook {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
}

.orderbook-header {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    padding: 6px 0;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.orderbook-asks,
.orderbook-bids {
    max-height: 150px;
    overflow: hidden;
}

.orderbook-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    padding: 4px 0;
    cursor: pointer;
    transition: background 0.2s;
}

.orderbook-row:hover {
    background: var(--bg-tertiary);
}

.orderbook-spread {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px 0;
    margin: 4px 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 14px;
}

/* Homepage chart refinement: denser exchange-style layout */
.symbol-selector {
    display: flex;
    align-items: stretch;
    gap: 12px;
    padding: 12px 14px 10px;
    margin: 10px 10px 0;
    background: linear-gradient(180deg, rgba(18, 24, 35, 0.98), rgba(13, 18, 28, 0.98));
    border: 1px solid #202a39;
    border-bottom: none;
    border-radius: 10px 10px 0 0;
}

.symbol-dropdown {
    min-width: 160px;
    padding: 10px 14px;
    background: #151d29;
    border: 1px solid #2a3444;
    border-radius: 8px;
    color: #f3f4f6;
    font-size: 15px;
    font-weight: 700;
}

.symbol-dropdown:focus {
    outline: none;
    border-color: #3b82f6;
}

.ticker-info {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
}

.ticker-item {
    min-height: 54px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid #202a39;
    border-radius: 8px;
}

.ticker-label {
    color: #6f7b8f;
    font-size: 11px;
    line-height: 1;
}

.ticker-value {
    color: #e5e7eb;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
}

.ticker-value.positive {
    color: #f6465d;
}

.ticker-value.negative {
    color: #0ecb81;
}

.chart-container {
    background: linear-gradient(180deg, rgba(18, 24, 35, 0.98), rgba(11, 17, 26, 0.98));
    border: 1px solid #202a39;
    border-radius: 10px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.chart-toolbar {
    gap: 12px;
    padding: 10px 14px 12px;
    background: rgba(14, 20, 30, 0.96);
    border-bottom: 1px solid #202a39;
    border-radius: 10px 10px 0 0;
}

.timeframe-buttons,
.indicator-buttons {
    flex-wrap: wrap;
}

.tf-btn {
    min-width: 46px;
    padding: 6px 12px;
    position: relative;
    border: 1px solid transparent;
    border-radius: 6px;
    color: #7f8a9a;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: 0.02em;
}

.tf-btn:hover {
    background: rgba(255, 255, 255, 0.03);
    color: #d7dde8;
}

.tf-btn.active {
    background: transparent;
    border-color: transparent;
    color: #f3f4f6;
}

.tf-btn.active::after {
    content: '';
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: -6px;
    height: 2px;
    border-radius: 999px;
    background: #f3f4f6;
}

.ind-btn {
    min-width: 50px;
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid #283241;
    border-radius: 6px;
    color: #8c97a8;
    font-weight: 600;
}

.ind-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #e5e7eb;
}

.ind-btn.active {
    background: rgba(246, 70, 93, 0.12);
    border-color: rgba(246, 70, 93, 0.35);
    color: #f8b4bf;
}

.orderbook-panel {
    background: linear-gradient(180deg, rgba(18, 24, 35, 0.98), rgba(11, 17, 26, 0.98));
    border: 1px solid #202a39;
    border-radius: 10px;
}

.orderbook-row {
    border-radius: 4px;
}

.orderbook-row:hover {
    background: rgba(255, 255, 255, 0.04);
}

@media (max-width: 1200px) {
    .symbol-selector {
        flex-direction: column;
    }

    .symbol-dropdown {
        width: 100%;
    }

    .ticker-info {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {
    .ticker-info {
        grid-template-columns: 1fr;
    }

    .chart-toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .tf-btn {
        min-width: 42px;
        font-size: 12px;
    }
}

/* Homepage chart override: align with backtest chart main/sub panes */
.chart-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    margin: 10px;
    min-height: 620px;
    overflow: hidden;
}

.chart-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: transparent;
    border-bottom: none;
}

.timeframe-buttons,
.indicator-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.tf-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: auto;
    padding: 5px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.02);
    color: #8c97a8;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
}

.tf-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #f3f4f6;
}

.tf-btn.active {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.16);
    color: #f3f4f6;
}

.tf-btn.active::after {
    display: none;
}

.ind-btn {
    min-width: auto;
    padding: 5px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.02);
    color: #8c97a8;
    font-size: 12px;
    font-weight: 700;
}

.ind-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #f3f4f6;
}

.ind-btn.active {
    background: rgba(246, 70, 93, 0.12);
    border-color: rgba(246, 70, 93, 0.35);
    color: #f8b4bf;
}

.tradingview-chart.main-pane {
    width: 100%;
    height: 420px;
    min-height: 420px;
    background: linear-gradient(180deg, rgba(88,166,255,0.04), rgba(88,166,255,0.01));
    border-radius: 12px 12px 0 0;
    overflow: hidden;
}

.indicator-pane {
    border-top: 1px solid var(--border-color);
    background: rgba(10, 16, 25, 0.92);
    border-radius: 0 0 12px 12px;
    overflow: hidden;
}

.indicator-pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
}

.indicator-chart {
    width: 100%;
    height: 140px;
    min-height: 140px;
    background: rgba(88,166,255,0.01);
}

#indicatorTitle {
    color: #f3f4f6;
    font-weight: 700;
}

@media (max-width: 768px) {
    .chart-container {
        min-height: 560px;
    }

    .chart-toolbar {
        align-items: flex-start;
        gap: 10px;
    }

    .tradingview-chart.main-pane {
        height: 360px;
        min-height: 360px;
    }

    .indicator-chart {
        height: 120px;
        min-height: 120px;
    }
}

/* Homepage chart spacing override: closer to backtest panel spacing */
.symbol-selector {
    gap: 14px;
    padding: 14px 16px 10px;
    margin: 12px 12px 0;
    border-radius: 16px 16px 0 0;
}

.chart-container {
    margin: 0 12px 12px;
    border-radius: 0 0 16px 16px;
    border-top: none;
    box-shadow: none;
}

.chart-toolbar {
    padding: 12px 16px 10px;
}

.tradingview-chart.main-pane {
    margin: 0 16px;
}

.indicator-pane {
    margin: 0 16px 16px;
}

.orderbook-panel {
    margin: 12px;
    border-radius: 16px;
}

@media (max-width: 768px) {
    .symbol-selector {
        margin: 10px 10px 0;
        padding: 12px 12px 8px;
    }

    .chart-container {
        margin: 0 10px 10px;
    }

    .tradingview-chart.main-pane {
        margin: 0 12px;
    }

    .indicator-pane {
        margin: 0 12px 12px;
    }

    .orderbook-panel {
        margin: 10px;
    }
}

/* Homepage unified market+chart panel */
.chart-panel {
    gap: 0;
}

.symbol-selector {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-bottom: none;
    box-shadow: none;
}

.chart-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-top: none;
    margin-top: 0;
}

.chart-toolbar {
    padding-top: 8px;
}

.ticker-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.symbol-dropdown {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.08);
}

/* Ensure dropdown text stays readable when browser renders a light option panel */
.symbol-dropdown option {
    color: #111827;
    background: #ffffff;
}

@media (max-width: 768px) {
    .chart-panel {
        gap: 0;
    }
}

/* Homepage main/sub chart layout override: match backtest stacked panes */
.chart-container {
    padding: 0 0 16px;
}

.chart-toolbar {
    margin-bottom: 0;
    padding: 12px 16px;
}

.tradingview-chart.main-pane {
    margin: 0;
    border-radius: 12px 12px 0 0;
}

.indicator-pane {
    margin: 0;
    border-radius: 0 0 12px 12px;
}

@media (max-width: 768px) {
    .chart-container {
        padding: 0 0 12px;
    }

    .tradingview-chart.main-pane {
        margin: 0;
    }

    .indicator-pane {
        margin: 0;
    }
}

/* Unified homepage chart panel after DOM merge */
.unified-chart-panel {
    padding-top: 0;
}

.unified-chart-panel .symbol-selector {
    margin: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    border-radius: 16px 16px 0 0;
}

.unified-chart-panel .chart-toolbar {
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

/* Homepage explicit main/sub indicator grouping */
.chart-toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.toolbar-label {
    color: var(--text-secondary);
    font-size: 11px;
    letter-spacing: 0.04em;
    font-weight: 700;
    white-space: nowrap;
}

.main-indicator-buttons,
.indicator-buttons,
.timeframe-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.main-pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
}

.main-pane-note {
    color: #f3f4f6;
    font-weight: 700;
}

.unified-chart-panel .indicator-pane-header span:first-child,
.main-pane-header span:first-child {
    font-weight: 700;
}

@media (max-width: 768px) {
    .toolbar-group {
        width: 100%;
        align-items: flex-start;
    }

    .main-pane-header {
        padding: 8px 10px;
    }
}

/* Hard fix: force homepage sub-chart visible */
.unified-chart-panel #mainChart {
    flex: 0 0 auto;
    height: 420px !important;
    min-height: 420px !important;
}

.unified-chart-panel #indicatorPane {
    display: block !important;
    flex: 0 0 auto;
    min-height: 241px !important;
    height: auto !important;
    overflow: hidden;
}

.unified-chart-panel #indicatorChart {
    display: block !important;
    width: 100% !important;
    height: 200px !important;
    min-height: 200px !important;
}

@media (max-width: 768px) {
    .unified-chart-panel #mainChart {
        height: 360px !important;
        min-height: 360px !important;
    }

    .unified-chart-panel #indicatorPane {
        min-height: 211px !important;
    }

    .unified-chart-panel #indicatorChart {
        height: 170px !important;
        min-height: 170px !important;
    }
}
