/**
 * Betformatics Chart Shortcode Styles
 *
 * Styled charts (bar, horizontal, pie) for data visualization.
 *
 * Dependencies: betformatics-variables (loaded via PHP)
 *
 * @package Betformatics
 */

/* =============================================================================
   RESET - Prevent theme interference
   ============================================================================= */
.bf-chart,
.bf-chart * {
    box-sizing: border-box;
}

/* =============================================================================
   ACCESSIBLE DATA TABLE (Visually hidden for screen readers)
   ============================================================================= */
.bf-chart__data-table {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* =============================================================================
   CONTAINER
   ============================================================================= */
.bf-chart {
    position: relative;
    margin: 1.5em 0;
    background: var(--bf-white, #ffffff);
    border: 1px solid var(--bf-border, #e5e7eb);
    border-radius: var(--bf-radius-lg, 12px);
    overflow: hidden;
    font-family: var(--bf-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
}

/* =============================================================================
   HEADER
   ============================================================================= */
.bf-chart__header {
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--bf-gray-50, #f9fafb) 0%, var(--bf-gray-100, #f3f4f6) 100%);
    border-bottom: 1px solid var(--bf-border, #e5e7eb);
}

.bf-chart__title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: var(--bf-font-weight-bold, 700);
    color: var(--bf-text-primary, #1f2937);
}

/* =============================================================================
   CONTENT AREA
   ============================================================================= */
.bf-chart__content {
    padding: 20px;
}

/* =============================================================================
   VERTICAL BAR CHART
   ============================================================================= */
.bf-chart__bars--vertical {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    gap: 12px;
    height: 200px;
    padding-top: 30px;
}

.bf-chart__bar-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    max-width: 80px;
    height: 100%;
}

.bf-chart--bar .bf-chart__bar-container {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.bf-chart--bar .bf-chart__bar {
    position: relative;
    width: 100%;
    max-width: 50px;
    min-height: 4px;
    border-radius: var(--bf-radius-sm, 4px) var(--bf-radius-sm, 4px) 0 0;
    transition: opacity var(--bf-transition-fast, 0.15s ease);
}

.bf-chart--bar .bf-chart__bar-value {
    position: absolute;
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    font-weight: var(--bf-font-weight-semibold, 600);
    color: var(--bf-text-primary, #1f2937);
    white-space: nowrap;
}

.bf-chart--bar .bf-chart__bar-label {
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--bf-text-muted, #6b7280);
    text-align: center;
    word-break: break-word;
}

/* =============================================================================
   HORIZONTAL BAR CHART
   ============================================================================= */
.bf-chart__bars--horizontal {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bf-chart__bar-row {
    display: grid;
    grid-template-columns: 100px 1fr 60px;
    gap: 12px;
    align-items: center;
}

.bf-chart--horizontal .bf-chart__bar-label {
    font-size: 0.85rem;
    font-weight: var(--bf-font-weight-medium, 500);
    color: var(--bf-text-primary, #1f2937);
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bf-chart--horizontal .bf-chart__bar-container {
    height: 24px;
    background: var(--bf-gray-100, #f3f4f6);
    border-radius: var(--bf-radius-sm, 4px);
    overflow: hidden;
}

.bf-chart--horizontal .bf-chart__bar {
    height: 100%;
    min-width: 4px;
    border-radius: var(--bf-radius-sm, 4px);
    transition: opacity var(--bf-transition-fast, 0.15s ease);
}

.bf-chart--horizontal .bf-chart__bar-value {
    font-size: 0.85rem;
    font-weight: var(--bf-font-weight-semibold, 600);
    color: var(--bf-text-primary, #1f2937);
    text-align: left;
}

/* =============================================================================
   PIE CHART
   ============================================================================= */
.bf-chart__pie-wrapper {
    display: flex;
    align-items: center;
    gap: 30px;
}

.bf-chart__pie-container {
    flex-shrink: 0;
    width: 180px;
    height: 180px;
}

.bf-chart__pie-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.bf-chart__pie-slice {
    transition: opacity var(--bf-transition-fast, 0.15s ease), transform var(--bf-transition-fast, 0.15s ease);
    transform-origin: center;
}

.bf-chart__pie-slice:hover,
.bf-chart__pie-slice.bf-chart__pie-slice--active {
    opacity: 0.85;
}

/* =============================================================================
   LEGEND
   ============================================================================= */
.bf-chart__legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.bf-chart__legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-radius: var(--bf-radius-sm, 4px);
    cursor: pointer;
    transition: background var(--bf-transition-fast, 0.15s ease);
}

.bf-chart__legend-item:hover,
.bf-chart__legend-item.bf-chart__legend-item--active {
    background: var(--bf-gray-50, #f9fafb);
}

.bf-chart__legend-color {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    border-radius: var(--bf-radius-sm, 4px);
}

.bf-chart__legend-label {
    flex: 1;
    font-size: 0.85rem;
    font-weight: var(--bf-font-weight-medium, 500);
    color: var(--bf-text-primary, #1f2937);
}

.bf-chart__legend-value {
    font-size: 0.8rem;
    color: var(--bf-text-muted, #6b7280);
    white-space: nowrap;
}

/* =============================================================================
   MOBILE RESPONSIVE
   ============================================================================= */
@media (max-width: 768px) {
    .bf-chart__content {
        padding: 16px;
    }

    /* Vertical bars */
    .bf-chart__bars--vertical {
        height: 160px;
        gap: 8px;
    }

    .bf-chart__bar-group {
        max-width: 60px;
    }

    .bf-chart--bar .bf-chart__bar-value {
        font-size: 0.7rem;
        top: -20px;
    }

    .bf-chart--bar .bf-chart__bar-label {
        font-size: 0.65rem;
    }

    /* Horizontal bars */
    .bf-chart__bar-row {
        grid-template-columns: 80px 1fr 50px;
        gap: 8px;
    }

    .bf-chart--horizontal .bf-chart__bar-label,
    .bf-chart--horizontal .bf-chart__bar-value {
        font-size: 0.8rem;
    }

    .bf-chart--horizontal .bf-chart__bar-container {
        height: 20px;
    }

    /* Pie chart */
    .bf-chart__pie-wrapper {
        flex-direction: column;
        gap: 20px;
    }

    .bf-chart__pie-container {
        width: 150px;
        height: 150px;
    }

    .bf-chart__legend {
        width: 100%;
    }

    .bf-chart__legend-item {
        padding: 8px 12px;
    }
}

@media (max-width: 480px) {
    /* Vertical bars on small screens */
    .bf-chart__bars--vertical {
        height: 140px;
        overflow-x: auto;
        justify-content: flex-start;
        padding-bottom: 10px;
    }

    .bf-chart__bar-group {
        min-width: 50px;
    }

    /* Horizontal bars - stack on very small screens */
    .bf-chart__bar-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .bf-chart--horizontal .bf-chart__bar-label {
        text-align: left;
    }

    .bf-chart--horizontal .bf-chart__bar-container {
        order: 2;
    }

    .bf-chart--horizontal .bf-chart__bar-value {
        order: 3;
        text-align: right;
    }
}

/* =============================================================================
   PAGE BUILDER COMPATIBILITY
   ============================================================================= */
.elementor-widget-container .bf-chart,
.elementor-element .bf-chart,
.wp-block .bf-chart {
    margin-left: 0;
    margin-right: 0;
    max-width: 100%;
}

/* =============================================================================
   ACCESSIBILITY
   ============================================================================= */
@media (prefers-reduced-motion: reduce) {
    .bf-chart,
    .bf-chart * {
        transition: none !important;
    }
}
