/* static/css/components/chart-panel.css */

/* Chart CSS Variables (shared by AI chart + Price Trends chart) */
:root {
    --chart-candle-up: var(--color-market-up);
    --chart-candle-down: var(--color-market-down);
    --chart-grid: var(--quote-table-border, #E8E5E0);
    --chart-crosshair: var(--color-border-strong);
    --chart-tooltip-bg: var(--color-bg-tertiary);
    --chart-tooltip-border: var(--quote-table-border, #E8E5E0);
    --chart-tooltip-text: var(--quote-table-text, #1C1917);
    --chart-bg: var(--quote-panel-surface, #FEFDFB);
    --chart-header-bg: var(--quote-panel-surface, #FEFDFB);
    --chart-header-border: var(--quote-table-border, #E8E5E0);
    --chart-text: var(--quote-table-text, #1C1917);
    --chart-text-secondary: var(--color-text-secondary);
    --chart-label-font-size: 11px;
}

.chart-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--chart-bg);
    container-type: inline-size;
    container-name: chart-panel;
}

/* Header */
.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    border-bottom: 1px solid var(--chart-header-border);
    background: var(--chart-header-bg);
    min-height: 32px;
}

.chart-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.stock-code {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-secondary);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

.stock-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--chart-text);
}

/* Quote Info Bar */
.chart-quote {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 0;
    margin-right: 4px;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    white-space: nowrap;
    overflow: visible;
    min-width: 0;
    flex: 1;
}

.quote-date {
    color: var(--chart-text);
    opacity: 0.55;
    font-size: 11px;
    order: 99;
    margin-left: auto;
    transition: color 0.15s ease, background 0.15s ease, padding 0.15s ease;
}

.quote-date.is-hovering {
    color: var(--color-accent);
    opacity: 1;
    font-weight: 600;
    background: var(--color-accent-subtle);
    padding: 1px 5px;
    border-radius: 3px;
}

.quote-sep[data-sep="1"] {
    display: none;
}

.quote-sep {
    width: 1px;
    height: 16px;
    background: var(--chart-header-border);
    opacity: 0.7;
    flex-shrink: 0;
    margin: 0 4px;
}

.quote-item {
    display: inline-flex;
    align-items: baseline;
    gap: 1px;
}

.quote-label {
    color: var(--chart-text);
    opacity: 0.45;
    font-size: 10px;
    font-family: system-ui, -apple-system, sans-serif;
    margin-right: 1px;
}

.quote-value {
    color: var(--chart-text);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: -0.2px;
    font-variant-numeric: tabular-nums;
}

/* 漲跌色 — 台股慣例：紅漲綠跌 */
.quote-value.quote-up {
    color: var(--chart-candle-up, #DC2626);
    font-weight: 600;
    font-size: 12.5px;
}

.quote-value.quote-down {
    color: var(--chart-candle-down, #16A34A);
    font-weight: 600;
    font-size: 12.5px;
}

.quote-value.quote-flat {
    color: var(--chart-text);
    opacity: 0.45;
}

/* 漲跌區塊間距 */
.quote-change {
    margin-right: 2px;
}

/* 漲跌幅加底色標籤效果 */
.quote-change-pct .quote-value {
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11.5px;
    letter-spacing: -0.3px;
}

.quote-change-pct .quote-value.quote-up {
    background: rgba(220, 38, 38, 0.12);
}

.quote-change-pct .quote-value.quote-down {
    background: rgba(22, 163, 74, 0.12);
}

.quote-change-pct .quote-value.quote-flat {
    background: rgba(0, 0, 0, 0.05);
}

.chart-toolbar {
    display: flex;
    gap: 8px;
}

.chart-btn {
    padding: 6px 12px;
    border: 1px solid var(--chart-header-border);
    background: var(--chart-bg);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--chart-text);
    transition: all 0.2s ease;
}

.chart-btn:hover {
    background: var(--quote-table-header-bg, #FAF9F6);
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.chart-btn:active {
    transform: scale(0.95);
}

/* Content */
.chart-content {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.chart-container {
    width: 100%;
    height: 100%;
    padding: 4px 8px;
}

/* Loading State */
.chart-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--chart-bg);
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--chart-header-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.chart-loading p {
    color: var(--chart-text-secondary);
    font-size: 14px;
}

/* Error State */
.chart-error {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--chart-bg);
    gap: 16px;
}

.error-message {
    color: var(--color-danger);
    font-size: 14px;
}

.retry-btn {
    padding: 8px 16px;
    border: 1px solid var(--color-accent);
    background: var(--chart-bg);
    color: var(--color-accent);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.retry-btn:hover {
    background: var(--color-accent);
    color: var(--color-text-on-accent);
}

/* Empty State */
.chart-empty {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--chart-bg);
}

.chart-empty p {
    color: var(--chart-text-secondary);
    font-size: 14px;
}

/* ==================== Indicator Label Overlay ==================== */

#priceTrendsChart,
.price-chart-area {
    position: relative;
}

.chart-indicator-labels {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 20;
    visibility: hidden;  /* 初始隱藏，等 setChart() 完成後才顯示 */
}

/* --- Indicator Label: TradingView-style overlay (5 rounds) --- */
.indicator-label {
    position: absolute;
    left: 6px;
    font-size: var(--chart-label-font-size, 13px);
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    line-height: 1.4;
    white-space: nowrap;
    letter-spacing: 0.01em;
    text-shadow:
        0 0 4px rgba(0, 0, 0, 0.9),
        0 1px 2px rgba(0, 0, 0, 0.7);
}

.label-name {
    color: rgba(255, 255, 255, 0.38);
    margin-right: 0;
    font-size: 0.88em;
}

.label-value {
    margin-right: 8px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    filter: saturate(1.15) brightness(1.1);
}

/* 副圖標籤（RSI 等）完全繼承 .indicator-label，不另設規則 */

/* ===== Light Mode ===== */
[data-theme="light"] .indicator-label {
    text-shadow:
        0 0 3px rgba(255, 255, 255, 0.95),
        0 1px 2px rgba(255, 255, 255, 0.8);
}

[data-theme="light"] .label-name {
    color: rgba(0, 0, 0, 0.35);
}

[data-theme="light"] .label-value {
    filter: saturate(1.1) brightness(0.85);
}

/* ===== Disable Highcharts Hover Highlight ===== */
.highcharts-point-hover {
    fill-opacity: 1 !important;
    opacity: 1 !important;
}

.highcharts-column-series .highcharts-point-hover {
    fill-opacity: 1 !important;
    opacity: 1 !important;
}

.highcharts-series-hover path {
    stroke-width: inherit !important;
}

.highcharts-series-hover {
    opacity: 1 !important;
}

.highcharts-series:not(.highcharts-series-hover) {
    opacity: 1 !important;
}

/* ========== Axis Resizer (drag-panes) ==========
 * 設計語言：「靜時無形，互動時有感」
 * States: Idle → Hover → Drag
 * ================================================ */

/* --- Idle: 細線分隔 + ns-resize hit zone --- */
.highcharts-axis-resizer {
    stroke: var(--color-border-default, #D6D3CE) !important;
    stroke-width: 1.5 !important;
    stroke-opacity: 0.55;
    stroke-dasharray: none;
    cursor: ns-resize;
    transition:
        stroke 0.25s cubic-bezier(0.4, 0, 0.2, 1),
        stroke-opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
        filter 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Hover: 線條浮現 --- */
.highcharts-axis-resizer:hover {
    stroke: var(--color-secondary, #78716C) !important;
    stroke-opacity: 0.45;
}

/* --- Drag: 品牌橘 + glow --- */
.highcharts-axis-resizer.resizer-dragging {
    stroke: var(--color-accent, #F97316) !important;
    stroke-opacity: 1;
    filter: drop-shadow(0 0 4px rgba(249, 115, 22, 0.35));
    transition:
        stroke 0.1s ease-out,
        stroke-opacity 0.1s ease-out,
        filter 0.1s ease-out;
}

/* --- Dark Mode --- */
[data-theme="dark"] .highcharts-axis-resizer {
    stroke: rgba(255, 255, 255, 0.18) !important;
    stroke-opacity: 0.6;
}
[data-theme="dark"] .highcharts-axis-resizer:hover {
    stroke: rgba(255, 255, 255, 0.3) !important;
    stroke-opacity: 0.55;
}
[data-theme="dark"] .highcharts-axis-resizer.resizer-dragging {
    stroke: var(--color-accent, #FB923C) !important;
    stroke-opacity: 1;
    filter: drop-shadow(0 0 6px rgba(251, 146, 60, 0.45));
}

/* --- 膠囊手柄 --- */
.axis-resizer-handle {
    fill: var(--color-text-muted, #A8A29E);
    opacity: 0.3;
    pointer-events: none;
    transition:
        opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
        fill 0.25s cubic-bezier(0.4, 0, 0.2, 1),
        filter 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.axis-resizer-handle.handle-hover {
    fill: var(--color-secondary, #78716C);
    opacity: 0.65;
}
.axis-resizer-handle.handle-dragging {
    fill: var(--color-accent, #F97316);
    opacity: 1;
    filter: drop-shadow(0 0 4px rgba(249, 115, 22, 0.3));
    transition: opacity 0.1s ease-out, fill 0.1s ease-out, filter 0.1s ease-out;
}

/* Dark capsule */
[data-theme="dark"] .axis-resizer-handle {
    fill: var(--color-text-muted, #57534E);
    opacity: 0.25;
}
[data-theme="dark"] .axis-resizer-handle.handle-hover {
    fill: var(--color-secondary, #A8A29E);
    opacity: 0.55;
}
[data-theme="dark"] .axis-resizer-handle.handle-dragging {
    fill: var(--color-accent, #FB923C);
    opacity: 1;
    filter: drop-shadow(0 0 6px rgba(251, 146, 60, 0.4));
}

@media (prefers-reduced-motion: reduce) {
    .highcharts-axis-resizer,
    .axis-resizer-handle { transition: none !important; }
}

/* ==================== Chart Loading Skeleton ====================

.chart-skeleton,
.chart-container:empty::before {
    content: '';
    display: block;
    width: 100%;
    height: 300px;
    background: linear-gradient(90deg, var(--color-bg-secondary) 25%, var(--color-bg-tertiary) 50%, var(--color-bg-secondary) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s ease-in-out infinite;
    border-radius: var(--brand-radius-md, 12px);
}
@keyframes skeletonShimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
    .chart-skeleton,
    .chart-container:empty::before { animation: none; }
}

/* ==================== Responsive Quote Bar (Container Queries) ==================== */

/* Tier 2: Compact (550-699px) — 隱藏開高低、標籤文字、sep-3 */
@container chart-panel (max-width: 699px) {
    .quote-open, .quote-high, .quote-low { display: none; }
    .quote-close .quote-label, .quote-volume .quote-label { display: none; }
    .quote-sep[data-sep="3"] { display: none; }
}

/* Tier 3: Narrow (450-549px) — 再隱藏成交量、sep-2 */
@container chart-panel (max-width: 549px) {
    .quote-volume { display: none; }
    .quote-sep[data-sep="2"] { display: none; }
}

/* Tier 4: Minimal (< 450px) — 再隱藏漲跌 */
@container chart-panel (max-width: 449px) {
    .quote-change { display: none; }
}
