/* ============================================
   CHART STYLES
   ICT Analyzer Pro V29.5
============================================ */

/* Chart Area */
.chart-area {
    flex: 1;
    display: flex;
    position: relative;
    background: var(--bg-primary);
    min-height: 0;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

.chart-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    overflow: hidden;
    background: var(--bg-primary);
    min-height: 0;
    width: 100%;
    height: 100%;
}

/* V38.2: Lightweight Charts Container Fix */
#chart-container {
    flex: 1;
    position: relative;
    width: 100% !important;
    height: 100% !important;
    min-height: 400px;
    background: var(--bg-primary);
}

/* V38.2: Target Lightweight Charts container by its table-layout structure */
/* Lightweight Charts v5 creates: div > table > tr > td structure */
#chart-container > div:not(.chart-loading):not(.chart-corner-info):not(.market-status-popup) {
    position: absolute !important;
    inset: 0 !important;
    z-index: 1 !important;
}

/* Ensure all canvases inside chart-container are properly positioned */
#chart-container canvas {
    z-index: 1 !important;
}

/* Overlay elements should be above the chart */
#chart-container .chart-loading {
    position: absolute;
    inset: 0;
    z-index: 100;
    pointer-events: none;
}

#chart-container .chart-corner-info {
    position: absolute;
    z-index: 50;
}

#chart-container .market-status-popup {
    position: absolute;
    z-index: 100;
}

#tradingview-container {
    flex: 1;
    position: relative;
    width: 100%;
    height: 100%;
}

/* Chart Loading */
.chart-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.chart-loading.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-yellow);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Bottom Status Bar */
.chart-statusbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.25rem 0.75rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    font-size: 0.65rem;
    color: var(--text-muted);
    height: 24px;
    min-height: 24px;
    flex-shrink: 0;
}

.statusbar-left, .statusbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--buy-green);
}

.status-dot.offline {
    background: var(--sell-red);
}

/* Candle Countdown Timer */
.candle-countdown {
    position: absolute;
    top: 50px;
    right: 85px;
    background: var(--bg-tertiary);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--accent-yellow);
    font-weight: 600;
    z-index: 20;
    font-family: monospace;
}

/* Quick Trade Panel on Chart */
.quick-trade-panel {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(var(--bg-primary-rgb, 11, 14, 17), 0.95);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.6rem;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    backdrop-filter: blur(4px);
    width: 150px;
}

.quick-trade-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--border-color);
}

.quick-trade-header span {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.quick-trade-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    font-size: 0.75rem;
}

.quick-trade-close:hover {
    color: var(--text-primary);
}

.quick-trade-price {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    padding: 0.2rem 0;
}

.quick-trade-buttons {
    display: flex;
    gap: 0.3rem;
}

.quick-trade-expand {
    width: 100%;
    padding: 0.35rem;
    background: var(--bg-hover);
    border: none;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.65rem;
    font-family: var(--font-family);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    transition: all 0.15s;
}

.quick-trade-expand:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ============================================
   V38: MARKET STATUS - TRADINGVIEW STYLE
============================================ */

/* Chart Corner Info (Market Status + Instrument) */
.chart-corner-info {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(var(--bg-primary-rgb, 11, 14, 17), 0.85);
    border-radius: 8px;
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

.chart-corner-info:hover {
    background: rgba(var(--bg-primary-rgb, 11, 14, 17), 0.95);
    border-color: var(--border-color);
}

.chart-instrument-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

/* Market Status Dot */
.market-status-dot {
    width: 10px;
    height: 10px;
    min-width: 10px;
    min-height: 10px;
    border-radius: 50%;
    transition: all 0.3s ease;
    background: #5e6673;
    position: relative;
}

.market-status-dot.open {
    background: var(--buy-green);
    box-shadow: 0 0 0 3px rgba(14, 203, 129, 0.2);
    animation: marketPulse 2s ease-in-out infinite;
}

.market-status-dot.closed {
    background: var(--sell-red, #ef5350);
    box-shadow: 0 0 0 3px rgba(239, 83, 80, 0.2);
}

@keyframes marketPulse {
    0%, 100% {
        box-shadow: 0 0 0 3px rgba(14, 203, 129, 0.2);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(14, 203, 129, 0.1);
    }
}

/* Market Status Popup - TradingView Style */
.market-status-popup {
    position: absolute;
    top: 50px;
    left: 12px;
    width: 320px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    z-index: 100;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.market-status-popup.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Popup Header */
.market-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.market-popup-status {
    display: flex;
    align-items: center;
    gap: 10px;
}

.market-popup-status .status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transition: all 0.3s;
}

.market-popup-status .status-dot.open {
    background: var(--buy-green);
    box-shadow: 0 0 8px var(--buy-green);
}

.market-popup-status .status-dot.closed {
    background: var(--text-muted);
}

.market-popup-status .status-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.market-popup-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 6px;
    border-radius: 4px;
    transition: all 0.15s;
}

.market-popup-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Popup Body */
.market-popup-body {
    padding: 16px;
}

/* Market Message */
.market-popup-message {
    text-align: center;
    margin-bottom: 20px;
}

.market-message-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
    font-family: var(--font-mono);
}

.market-message-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.market-message-status.open {
    color: var(--buy-green);
}

.market-message-status.closed {
    color: var(--text-muted);
}

.market-message-countdown {
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-yellow);
    font-family: var(--font-mono);
    letter-spacing: 0.5px;
}

/* Session Progress - TradingView Style */
.market-session-progress {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 14px;
}

.session-day {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-weight: 500;
}

.session-progress-bar {
    position: relative;
    height: 6px;
    background: rgba(94, 102, 115, 0.3);
    border-radius: 3px;
    margin-bottom: 12px;
    overflow: visible;
}

.session-progress-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--buy-green), #45c482);
    border-radius: 3px;
    transition: width 1s linear;
    box-shadow: 0 0 8px rgba(14, 203, 129, 0.4);
}

.session-progress-marker {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    background: var(--text-primary);
    border: 2px solid var(--bg-secondary);
    border-radius: 50%;
    transition: left 1s linear;
    z-index: 2;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

.session-times {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.time-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.time-icon {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.time-icon.open {
    background: var(--buy-green);
}

.time-icon.close {
    background: var(--sell-red);
}

.time-current {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-yellow);
    font-family: var(--font-mono);
    background: rgba(240, 185, 11, 0.1);
    padding: 4px 10px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

/* Popup Footer */
.market-popup-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
}

.timezone-label {
    color: var(--text-muted);
}

.timezone-value {
    color: var(--accent-blue);
    font-weight: 500;
}

/* Price Scale Context Menu */
.price-scale-menu {
    position: fixed;
    width: 300px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    overflow: hidden;
    padding: 8px 0;
}

.price-scale-menu.active {
    display: block;
    animation: dropdownFadeIn 0.15s ease;
}

.scale-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}

.scale-menu-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.scale-menu-item.active {
    color: var(--text-primary);
}

.scale-menu-item .check {
    color: var(--text-primary);
    font-size: 1rem;
}

.scale-menu-item .shortcut {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.scale-menu-item .arrow {
    color: var(--text-muted);
}

.scale-menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 0;
}

.scale-menu-submenu {
    position: absolute;
    left: 100%;
    top: 0;
    width: 200px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    display: none;
    padding: 8px 0;
}

.scale-menu-item:hover .scale-menu-submenu {
    display: block;
}

.scale-submenu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}

.scale-submenu-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.scale-submenu-item.active .check {
    visibility: visible;
}

.scale-submenu-item .check {
    visibility: hidden;
    color: var(--text-primary);
}

/* Order Placement Mode Overlay */
.order-placement-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 1rem;
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--accent-yellow);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.order-placement-overlay.active {
    display: flex;
}

.order-placement-instructions {
    color: var(--text-primary);
    font-size: 0.9rem;
}

.order-placement-cancel {
    padding: 0.5rem 1rem;
    background: var(--sell-red);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    font-family: var(--font-family);
}

/* ICT Legend */
.ict-legend {
    position: absolute;
    top: 60px;
    right: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    z-index: 50;
    font-size: 0.75rem;
}

.ict-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.ict-legend-item:last-child {
    margin-bottom: 0;
}

.ict-legend-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

.ict-legend-color.ob-bull { background: rgba(14, 203, 129, 0.3); border: 1px solid #0ecb81; }
.ict-legend-color.ob-bear { background: rgba(246, 70, 93, 0.3); border: 1px solid #f6465d; }
.ict-legend-color.fvg-bull { background: rgba(14, 203, 129, 0.15); border: 1px dashed #0ecb81; }
.ict-legend-color.fvg-bear { background: rgba(246, 70, 93, 0.15); border: 1px dashed #f6465d; }
.ict-legend-color.sweep { background: rgba(240, 185, 11, 0.3); border: 1px solid #f0b90b; }
.ict-legend-color.mss { background: rgba(30, 136, 229, 0.3); border: 1px solid #1e88e5; }

/* ICT Controls Panel - HIDDEN */
.ict-controls-panel {
    display: none !important;
}

/* ICT Analysis Info Box */
.ict-analysis-info {
    position: absolute;
    bottom: 8px;
    left: 50px;
    background: rgba(var(--bg-primary-rgb, 11, 14, 17), 0.95);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    z-index: 40;
    font-size: 0.7rem;
    backdrop-filter: blur(4px);
    overflow: hidden;
    transition: all 0.2s ease;
}

.ict-analysis-info.collapsed {
    width: auto;
}

.ict-analysis-info.collapsed .ict-analysis-body {
    display: none;
}

.ict-analysis-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.ict-analysis-info.collapsed .ict-analysis-header {
    border-bottom: none;
}

.ict-analysis-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--accent-yellow);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.ict-analysis-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    font-size: 0.65rem;
    transition: transform 0.2s ease;
}

.ict-analysis-info.collapsed .ict-analysis-toggle {
    transform: rotate(180deg);
}

.ict-analysis-body {
    padding: 0.5rem 0.6rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem 0.8rem;
}

.ict-analysis-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
}

.ict-analysis-label {
    color: var(--text-muted);
}

.ict-analysis-value {
    color: var(--text-primary);
    font-weight: 500;
}

.ict-analysis-value.bullish { color: var(--buy-green); }
.ict-analysis-value.bearish { color: var(--sell-red); }

/* ============================================
   V30.1: LIVE PRICE ANIMATION
============================================ */

/* Price flash effect on change */
.price-up {
    animation: priceFlashUp 0.3s ease-out;
}

.price-down {
    animation: priceFlashDown 0.3s ease-out;
}

@keyframes priceFlashUp {
    0% {
        color: var(--text-primary);
        text-shadow: none;
    }
    50% {
        color: var(--buy-green);
        text-shadow: 0 0 10px rgba(14, 203, 129, 0.5);
    }
    100% {
        color: var(--text-primary);
        text-shadow: none;
    }
}

@keyframes priceFlashDown {
    0% {
        color: var(--text-primary);
        text-shadow: none;
    }
    50% {
        color: var(--sell-red);
        text-shadow: 0 0 10px rgba(246, 70, 93, 0.5);
    }
    100% {
        color: var(--text-primary);
        text-shadow: none;
    }
}

/* Live price indicator dot */
.live-indicator {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--buy-green);
    border-radius: 50%;
    margin-right: 4px;
    animation: livePulse 1.5s infinite;
}

@keyframes livePulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(0.8);
    }
}
