/**
 * BTD Macro Insights Charts - Frontend Styles
 */

/* Chart Container */
.btd-chart-container {
    position: relative;
    /* margin: 20px 0; */
    /* padding: 15px; */
    background: #ffffff;
    /* border: 1px solid #e0e0e0; */
    /* border-radius: 8px; */
    /* box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    /* margin: 20px 0; */
    background: #fff;
    /* border: 1px solid #e0e0e0; */
    /* border-radius: 9px; */
    overflow: hidden;
    /* padding: 0.8rem 1rem; */
    /* box-shadow: 1px 1px 12px rgb(0 0 0 / 14%); */
}

.btd-chart-container.dark-theme {
    background: #1e1e1e;
    border-color: #444444;
    color: #ffffff;
}

/* Chart Title */
.btd-chart-title {
    margin: 0 0 15px 0;
    padding: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1C1B1A;
    text-align: center;
    line-height: 1.4;
    margin: 0;
    /* padding: 15px 20px 10px; */
    font-size: 18px;
    font-weight: 600;
    /* border-bottom: 1px solid #f0f0f0; */
    margin-bottom: 0.2rem;
    font-family: 'Poppins', sans-serif;
}
h4.btd-chart-title {
    text-transform: uppercase;
    margin-top: 0.1rem;
    margin-bottom: 0.1rem;
    font-size: 1rem;
    font-weight: 700;
    text-align: left;
}
p.short-desc {
    position: relative;
    margin-left: 0.7rem;
    color: #555555;
    margin-top: -0.1rem;
    font-size: 0.8rem;
    font-style: italic;
    margin-bottom: 2rem;
}
.short-desc::before {
    position: absolute;
    content: '';
    display: block;
    z-index: 0;
    left: -0.5rem;
    top: 15%;
    height: 70%;
    margin-top: 0;
    width: 2px;
    border-radius: 10rem;
    background: rgb(208 0 188 / 50%);
}
.total_sector_spending {
    background: linear-gradient(90deg, #4813a8, #4329ce);
}
.btd-data-table {
    margin-block-end: 0px;
}
.btd-table-container {
    margin: 20px 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 9px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.total_sector_spending h3 {
    color: #fff;
    margin-top: 0;
    padding: 2rem;
    text-align: center;
    font-size: 1.4rem;
    margin-bottom: 0;
}
.dark-theme .btd-chart-title {
    color: #ffffff;
}

/* Chart Wrapper */
.btd-chart-wrapper {
    position: relative;
    /* width: 100%; */
    height: 100%;
    min-height: 300px;
    position: relative; 
    width: 100%; 
    height: 400px; 
    padding: 20px; 
}
.btd-error-content { 
    color: #d32f2f; 
    text-align: center; 
    font-weight: bold; 
}
 @keyframes spin { 
    0% { transform: rotate(0deg); } 
    100% { transform: rotate(360deg); } 
}
/* Chart Canvas */
.btd-chart-canvas {
    display: block;
    width: 100%; 
    height: 100%;
}
.btd-loading-content { 
    text-align: center; 
}
/* Loading State */
.btd-chart-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    /* transform: translate(-50%, -50%); */
    display: flex;
    align-items: center;
    gap: 10px;
    color: #666666;
    font-size: 14px;
    z-index: 10;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4;
}

.dark-theme .btd-chart-loading {
    color: #cccccc;
}

/* Spinner */
.btd-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #1976d2;
    border-radius: 50%;
    animation: btd-spin 1s linear infinite;

    border: 3px solid #f3f3f3; 
    border-top: 3px solid #3498db; 
    border-radius: 50%; 
    width: 30px; 
    height: 30px; 
    animation: spin 1s linear infinite; 
    margin: 0 auto 10px; 
}

.dark-theme .btd-spinner {
    border-color: #666666;
    border-top-color: #64b5f6;
}

@keyframes btd-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error State */
.btd-chart-error {
    position: absolute;
    /* top: 50%; */
    /* left: 50%; */
    /* transform: translate(-50%, -50%); */
    background: #ffebee;
    color: #c62828;
    padding: 15px 20px;
    border-radius: 4px;
    border: 1px solid #ffcdd2;
    font-size: 14px;
    text-align: center;
    z-index: 10;
    max-width: 80%;

    display: none; 
    position: absolute; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0; 
    background: rgba(255,255,255,0.95); 
    z-index: 1000; 
    align-items: center; 
    justify-content: center; 
}

.dark-theme .btd-chart-error {
    background: #2c1810;
    color: #ff8a80;
    border-color: #5d2f2f;
}

/* Chart Info */
.btd-chart-info {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e0e0e0;
    text-align: center;
}

.dark-theme .btd-chart-info {
    border-top-color: #444444;
}

.btd-chart-description {
    color: #666666;
    font-size: 12px;
    line-height: 1.4;
    font-style: italic;
}

.dark-theme .btd-chart-description {
    color: #cccccc;
}

/* Chart Type Specific Styles */
.btd-chart-total_consumer_spending,
.btd-chart-total_sector_spending {
    border-left: 4px solid #1976d2;
}

.btd-chart-demographic_spending_generation,
.btd-chart-demographic_spending_income,
.btd-chart-demographic_spending_region {
    border-left: 4px solid #388e3c;
}

.btd-chart-sector_demographic_spending_by_income,
.btd-chart-sector_demographic_spending_by_generation {
    border-left: 4px solid #f57c00;
}

.btd-chart-durable_nondurable_goods {
    border-left: 4px solid #7b1fa2;
}

.chart-grid {
    display: flex;
    gap: 1rem;
    flex-flow: column;
    justify-content: center;
    align-items: center;
}
.chart-card {
    flex: 1 0 auto;
    width: 100%;
}
.chart-card.minimized button.toggle-stretch svg.shrink {
    display: none;
}
.chart-card button.toggle-stretch svg.expand {
    display: none;
}
.chart-card.minimized button.toggle-stretch svg.expand {
    display: block;
}

.chart-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 1px 1px 12px rgb(0 0 0 / 11%);
    padding: 0.8rem 1rem;
    transition: box-shadow 0.3s ease;
    flex: 0 1 auto;
    width: 100%;
    position: relative;
    /* margin-top: 1rem; */
    transition: all 0.4s ease-in-out;
}
.btd-chart-container {
    position: relative;
}
.btd-chart-wrapper {
    position: relative;
    /* z-index: 0; */
}
/* .chart-card > p {
    max-width: 100%;
} */
.chart-card .unlock-data-wrapper,
.btd-chart-wrapper .unlock-data-wrapper {
    position: absolute;
    right: 2rem;
    width: 32%;
    height: auto;
    z-index: 0;
    bottom: 8.3rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-width: 8rem;
    transition: all 0.2s ease-in-out;
}
.chart-card .unlock-data-wrapper {
    top: 10rem;
}
.btd-chart-wrapper .unlock-data-wrapper {
    top: 3rem;
}
.chart-card .unlock-data-wrapper::before,
.btd-chart-wrapper .unlock-data-wrapper::before {
    content: '';
    display: block;
    position: absolute;
    right:0;
    left: -1rem;
    bottom: 0rem;
    top: -1rem;
    background: linear-gradient(90deg, rgb(255 255 255 / 20%) 0%, rgb(255 255 255 / 93%) 30%);
    z-index: -1;
    border-radius: 0.3rem;
    opacity: 1;
}
.chart-card .unlock-data-wrapper::after,
.btd-chart-wrapper .unlock-data-wrapper::after {
    content: '';
    display: block;
    position: absolute;
    right:0;
    left: 0;
    bottom: 0;
    top: 0;
    /* background: #fff; */
    z-index: -1;
    border-radius: 0.6rem;
    /* opacity: 0.6; */
    /* box-shadow: 0px 1px 13px -6px rgb(0 0 0 / 70%); */
    border-radius: 0.6rem;
    filter: blur(13px);
}



@media (min-width: 73.5em) {
    .chart-grid {
        flex-flow: row wrap;
    }
    .chart-card.limit-50 {
        flex: 1 0 calc(50% - 0.5rem);
        max-width: calc(50% - 0.5rem);
    }
    /* .chart-card.limit-50 {
        max-width: 49%;
    } */
}

/* TODO: this is copied in Brand Insights public.css */
.brand-insight-intro {
    padding: 1.2rem 1.4rem;
    background-color: #F9F6FC;
    margin-top: 0;
    margin-bottom: 0;
    border-radius: 6px;
    border: 1px solid #EDDEFC;
    margin-bottom: 1.2rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .btd-chart-container {
        /* margin: 15px 0; */
        /* padding: 10px; */
    }
    
    .btd-chart-title {
        font-size: 16px;
        margin-bottom: 10px;
    }
    
    .btd-chart-wrapper {
        min-height: 250px;
    }
    
    .btd-chart-description {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .btd-chart-container {
        /* margin: 10px 0; */
        padding: 8px;
    }
    
    .btd-chart-title {
        font-size: 14px;
    }
    
    .btd-chart-wrapper {
        min-height: 200px;
    }
}

/* Print Styles */
@media print {
    .btd-chart-container {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000000;
    }
    
    .btd-chart-loading,
    .btd-chart-error {
        display: none !important;
    }
}

/* High DPI/Retina Display Support */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .btd-chart-canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: 'crisp-edges';
    }
}

/* Focus States for Accessibility */
.btd-chart-canvas:focus {
    outline: 2px solid #1976d2;
    outline-offset: 2px;
}

.dark-theme .btd-chart-canvas:focus {
    outline-color: #64b5f6;
}

/* Chart Controls (for future use) */
.btd-chart-controls {
    margin-top: 10px;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btd-chart-control {
    padding: 5px 10px;
    font-size: 12px;
    border: 1px solid #e0e0e0;
    background: #ffffff;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btd-chart-control:hover {
    background: #f5f5f5;
    border-color: #1976d2;
}

.btd-chart-control.active {
    background: #1976d2;
    color: #ffffff;
    border-color: #1976d2;
}

.dark-theme .btd-chart-control {
    background: #2c2c2c;
    border-color: #444444;
    color: #ffffff;
}

.dark-theme .btd-chart-control:hover {
    background: #404040;
    border-color: #64b5f6;
}

.dark-theme .btd-chart-control.active {
    background: #64b5f6;
    border-color: #64b5f6;
    color: #000000;
}