/**
 * Diverging Chart Component Styles
 * 
 * Creates a center-aligned bar chart with CSS Grid
 * Positive values extend right, negative values extend left
 */

/* === Component Container === */
.vna2-diverging-chart-container {
    position: relative;
    margin: 20px 0;
    padding: 15px;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* === Info Icon === */
.chart-info-icon {
    position: absolute;
    top: 15px;
    right: 15px;
    cursor: pointer;
    z-index: 10;
}

.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: #000;
    color: white;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
    font-family: system-ui, -apple-system, sans-serif;
    text-align: center;
    line-height: 1;
    transition: all 0.2s ease;
    border: 2px solid #fff;
    position: relative;
}

.info-icon:before {
    content: "i";
    font-style: normal;
    font-weight: 700;
    font-size: 13px;
}

.info-icon:hover {
    background: #333;
    transform: scale(1.1);
}

.info-icon:active {
    transform: scale(0.95);
}

/* === Main Chart Grid === */
.diverging-chart {
    display: grid;
    grid-template-columns: 50px 1fr 3px 1fr;
    gap: 0;
    align-items: center;
    margin-top: 20px;
}

/* === Party Row === */
.party-row {
    display: contents; /* Each row spans all grid columns */
    height: 40px;
}

.party-row + .party-row {
    margin-top: 8px;
}

/* === Grid Cells === */
.party-logo-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    justify-content: flex-start;
}

.negative-bar-cell {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 4px 0;
    height: 32px;
}

.center-line-cell {
    display: flex;
    justify-content: center;
    align-items: stretch;
    height: 32px;
}

.positive-bar-cell {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 4px 0;
    height: 32px;
}

/* === Party Logo === */
.party-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    cursor: pointer;
    transition: transform 0.2s ease;
    background: transparent;
}

.party-logo:hover {
    transform: scale(1.2);
}

/* Party label hidden for logo-only display */
.party-label {
    display: none;
}

/* === Center Line === */
.center-line {
    width: 3px;
    height: 100%;
    background: linear-gradient(to bottom, #dee2e6 0%, #adb5bd 50%, #dee2e6 100%);
    border-radius: 1px;
}

/* === Bars === */
.bar {
    height: 24px;
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
    min-width: 30px; /* Ensure score label is always visible */
    position: relative;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.bar:hover {
    transform: scaleY(1.1);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

/* === Positive Bars (extend right) === */
.positive-bar {
    background: linear-gradient(90deg, #28a745 0%, #20c997 50%, #17a2b8 100%);
    justify-content: flex-end;
    padding-right: 8px;
    /* Rounded on the right side, straight on the left (center) side */
    border-radius: 0 3px 3px 0;
}

.positive-bar .score-label {
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* === Negative Bars (extend left) === */
.negative-bar {
    background: linear-gradient(270deg, #dc3545 0%, #e83e8c 50%, #fd7e14 100%);
    justify-content: flex-start;
    padding-left: 8px;
    /* Rounded on the left side, straight on the right (center) side */
    border-radius: 3px 0 0 3px;
}

.negative-bar .score-label {
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* === Neutral Bars (scores between -10 and 10) === */
.neutral-bar {
    background: linear-gradient(90deg, #6c757d 0%, #adb5bd 50%, #6c757d 100%);
    justify-content: center;
    /* Rounded on appropriate side based on direction */
}

.neutral-bar.positive-direction {
    justify-content: flex-end;
    padding-right: 8px;
    border-radius: 0 3px 3px 0;
}

.neutral-bar.negative-direction {
    justify-content: flex-start;
    padding-left: 8px;
    border-radius: 3px 0 0 3px;
}

.neutral-bar .score-label {
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* === Score Labels === */
.score-label {
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
}

/* === Tooltips === */
.vna2-tooltip {
    position: absolute;
    background: #333;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.4;
    max-width: 250px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    opacity: 0;
    transform: translateY(5px);
    transition: all 0.2s ease;
    pointer-events: none;
}

.vna2-tooltip.show {
    opacity: 1;
    transform: translateY(0);
}

.vna2-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #333;
}

.vna2-tooltip.bottom::after {
    top: -10px;
    border-top-color: transparent;
    border-bottom-color: #333;
}

/* === Responsive Design === */
@media (max-width: 768px) {
    .diverging-chart {
        grid-template-columns: 40px 1fr 2px 1fr;
        gap: 0;
    }
    
    .party-logo-cell {
        padding: 6px 5px;
        gap: 5px;
    }
    
    .party-logo {
        width: 28px;
        height: 28px;
    }
    
    .bar {
        height: 20px;
        min-width: 25px;
    }
    
    .score-label {
        font-size: 11px;
    }
    
    .vna2-tooltip {
        max-width: 200px;
        font-size: 12px;
    }
    
    .negative-bar-cell,
    .positive-bar-cell,
    .center-line-cell {
        height: 28px;
    }
}

@media (max-width: 480px) {
    .vna2-diverging-chart-container {
        padding: 10px;
        margin: 15px 0;
    }
    
    .diverging-chart {
        grid-template-columns: 35px 1fr 2px 1fr;
    }
    
    .party-logo {
        width: 24px;
        height: 24px;
    }
    
    .bar {
        height: 18px;
        min-width: 20px;
    }
    
    .score-label {
        font-size: 10px;
    }
    
    .vna2-tooltip {
        max-width: 180px;
        font-size: 11px;
        padding: 6px 10px;
    }
}

/* === Dark Mode Support === */
body.dark-mode .vna2-diverging-chart-container {
    background: #1a1a1a;
    border-color: #333;
    color: #fff;
}

body.dark-mode .party-label {
    color: #ddd;
}

body.dark-mode .center-line {
    background: linear-gradient(to bottom, #555 0%, #777 50%, #555 100%);
}

body.dark-mode .info-icon {
    background: #000;
    border-color: #fff;
}

body.dark-mode .info-icon:hover {
    background: #333;
}

body.dark-mode .vna2-tooltip {
    background: #444;
    color: #fff;
}

body.dark-mode .vna2-tooltip::after {
    border-top-color: #444;
}

body.dark-mode .vna2-tooltip.bottom::after {
    border-bottom-color: #444;
    border-top-color: transparent;
}

/* === Animation for Initial Load === */
@keyframes slideInFromCenter {
    from {
        width: 0;
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.party-row .bar {
    animation: slideInFromCenter 0.6s ease-out;
    animation-fill-mode: both;
}

.party-row:nth-child(1) .bar { animation-delay: 0.1s; }
.party-row:nth-child(2) .bar { animation-delay: 0.2s; }
.party-row:nth-child(3) .bar { animation-delay: 0.3s; }
.party-row:nth-child(4) .bar { animation-delay: 0.4s; }
.party-row:nth-child(5) .bar { animation-delay: 0.5s; }
.party-row:nth-child(6) .bar { animation-delay: 0.6s; }
.party-row:nth-child(7) .bar { animation-delay: 0.7s; }
.party-row:nth-child(8) .bar { animation-delay: 0.8s; }