/* ============================================
   CHART POPUP - Reusable Component
   ============================================ */

/* ===== 1. OVERLAY (Dark Background) ===== */
.chart-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: 99999;
    display: none;
    justify-content: flex-end;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.chart-popup-overlay.active {
    display: flex;
    opacity: 1;
    pointer-events: none;
}

/* ===== 2. POPUP CONTAINER ===== */
.chart-popup-container {
    background: #ffffff;
    width: 60%;
    max-width: none;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    pointer-events: auto;
}

.chart-popup-overlay.active .chart-popup-container {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* ===== 3. POPUP HEADER ===== */
.chart-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.chart-popup-symbol {
    font-size: 18px;
    font-weight: 700;
    color: #2c3e50;
}

.chart-popup-symbol .badge {
    background: #40b0b2;
    color: white;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 8px;
}

.chart-popup-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chart-popup-btn {
    padding: 6px 14px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.chart-popup-btn-maximize {
    background: #40b0b2;
    color: white;
}

.chart-popup-btn-maximize:hover {
    background: #359a9c;
}

.chart-popup-btn-close {
    background: #ef5350;
    color: white;
}

.chart-popup-btn-close:hover {
    background: #d32f2f;
}

/* ===== 4. CHART BODY ===== */
.chart-popup-body {
    display: block;
    padding: 10px 30px 30px 20px;
    overflow: hidden;
    position: relative;
    height: 480px;
    min-height: 480px;
    background: #ffffff;
}
.chart-popup-body > #chartLegend {
    display: none;
}

/* Chart container inside popup */
.chart-popup-body #stockChart {
    width: 100%;
    min-height: 0;
    position: relative;
}

/* Time buttons inside popup */
.chart-popup-body #timeButtons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
    justify-content: center;
}

.chart-popup-body #timeButtons button {
    padding: 5px 14px;
    border: 2px solid #e0e0e0;
    border-radius: 16px;
    background: white;
    color: #333;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.chart-popup-body #timeButtons button:hover {
    background: #f0f0f0;
    border-color: #40b0b2;
}

.chart-popup-body #timeButtons button.active {
    background: #40b0b2;
    border-color: #40b0b2;
    color: white;
}

.chart-popup-body #timeButtons button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Legend should be at bottom */
.chart-popup-body #chartLegend {
    flex-shrink: 0;
    font-family: monospace;
    font-size: 12px;
    background: #f7f7f7;
    padding: 6px 10px;
    border-radius: 4px;
    margin-top: 8px;
    min-height: 30px;
    overflow-x: auto;
    white-space: nowrap;
}

/* Loading spinner - centered */
.chart-popup-body #loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: white;
    z-index: 10;
    text-align: center;
    padding: 20px;
}

.chart-popup-body #loading .spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #40b0b2;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    animation: chartPopupSpin 1s linear infinite;
    margin: 0 auto 12px;
}

@keyframes chartPopupSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.chart-popup-body #errorMsg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: white;
    z-index: 10;
    text-align: center;
    padding: 20px;
    color: #e76d67;
    font-size: 14px;
}

/* Company header inside popup (simplified) */
.chart-popup-body .company-header {
    display: none; /* Hidden in popup - symbol shown in header */
}

/* Date range display in popup header */
.chart-popup-date-range {
    font-size: 12px;
    color: #888;
    font-weight: 400;
    margin-left: 12px;
}

/* ===== 5. IFRAME LOADING ===== */
.chart-popup-iframe {
    display: block;
    width: 100%;
    height: 450px;
    min-height: 450px;
    border: none;
}

/* ===== 6. RESPONSIVE ===== */
@media (max-width: 600px) {
    .chart-popup-container {
        width: 95%;
        max-width: 95%;
        max-height: 95vh;
        border-radius: 8px;
    }
    
    .chart-popup-header {
        padding: 10px 14px;
    }
    
    .chart-popup-symbol {
        font-size: 16px;
    }
    
    .chart-popup-body {
        padding: 10px 12px 14px 12px;
        min-height: 300px;
    }
    
    .chart-popup-body #stockChart {
    display: none;
}
    
    .chart-popup-body #timeButtons button {
        padding: 4px 10px;
        font-size: 11px;
    }
    
    .chart-popup-body #chartLegend {
        font-size: 11px;
        padding: 4px 8px;
        min-height: 26px;
    }
    
    .chart-popup-btn {
        padding: 4px 10px;
        font-size: 12px;
    }
}

@media (max-width: 400px) {
    .chart-popup-body #stockChart {
        height: 220px !important;
    }
    
    .chart-popup-body {
        padding: 8px 8px 10px 8px;
        min-height: 250px;
    }
    
    .chart-popup-symbol {
        font-size: 14px;
    }
    
    .chart-popup-date-range {
        font-size: 10px;
        margin-left: 6px;
    }
}

/* ===== 7. SCROLL LOCK ===== */
body.chart-popup-open {
    overflow: hidden !important;
}