/* ============================== */
/* [[[ BLOCK: DATA VISUALS ]]]   */
/* ============================== */

/* Main Container Card */
.data-visual {
    background: white;
    padding: var(--internal-space-md) var(--internal-space-xl);
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(20, 20, 20, 0.1);
    border: var(--color-grey-lighter) 1px solid;
    max-width: 900px;
    width: 100%;

    display: flex;
    flex-direction: column;
    gap: var(--internal-space-md);
    /* Consistent spacing for all sections */
    /* The single source of truth for vertical spacing */

    /* Document Flow */
    margin-top: var(--internal-space-md);
    margin-bottom: var(--internal-space-md);
}

.data-visual__footer {
    display: flex;
    flex-direction: column;
    gap: var(--internal-space-xs);
    /* Keeps hint and legend tightly grouped */
}

/* --- 1. Layout Patterns --- */

/* Side-by-side positioning (e.g. Donut Pairs or Stack Chart blocks) */
.data-visual__group {
    display: flex;
    flex-direction: row;
    column-gap: var(--internal-space-xl);
    row-gap: var(--internal-space-md);
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}

/* Internal Chart Components (Title -> Target SVG) */
.data-visual__item {
    display: flex;
    flex-direction: column;
    gap: var(--internal-space-sm);
    /* Title-to-visual space */
    flex: 1 1 300px;
    min-width: 0;
    /* Prevents large SVGs from forcing the container wider than its shared space */
}

/* Parent Modifiers */
.data-visual--full .data-visual__item {
    width: 100%;
}

.data-visual--half .data-visual__item {
    /* Layout handled by flex-basis in base .data-visual__item */
    width: auto;
}

/* --- 2. Typography Hierarchy --- */

.data-visual__item h3,
.data-visual__item h4 {
    font-size: 1.25rem;
    color: var(--color-grey-dark);
    text-align: center;
}

.data-visual__hint {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--color-primary-variant);
    text-align: left;
    margin: 0;
    /* Handled by parent gap */
}

/* --- 3. Legend & Metadata --- */

.data-visual__legend {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    column-gap: var(--internal-space-lg);
    row-gap: var(--internal-space-sm);
    border-top: 1px solid var(--color-grey-light);
    padding-top: var(--internal-space-sm);
    /* Tightened to match the hint text proximity */
}

.data-visual__legend-item {
    display: flex;
    align-items: center;
    gap: var(--internal-space-sm);
    font-size: 0.9rem;
    color: var(--color-grey-dark);
}

.data-visual__legend-swatch {
    width: var(--internal-space-lg);
    height: var(--internal-space-lg);
    border: 1px solid var(--color-grey-light);
    border-radius: 4px;
}

/* --- 4. Interactive Components (SVGs & D3) --- */

.data-visual path {
    transition: opacity 0.2s;
}

.data-visual path:focus {
    outline: 3px solid var(--color-highlight);
    outline-offset: 4px;
    position: relative;
    z-index: 10;
}

.data-visual path:hover {
    opacity: 0.9;
    cursor: pointer;
    stroke: var(--color-highlight);
    stroke-width: 2px;
}

/* Standardized SVG Typography overrides using internal system */
.data-visual svg text {
    font-family: var(--font-main);
    font-size: 0.8rem;
    fill: var(--color-grey-dark);
}

.data-visual .domain,
.data-visual .tick line {
    stroke: rgba(0, 0, 0, 0.08);
}

/* Ensure SVG content is responsive but doesn't force container growth */
.data-visual svg {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    /* Centers the chart if it is smaller than its container */
}

/* --- 6. Mobile Responsiveness: Breakout Pattern --- */
/* The card bleeds out to the edges but text stays aligned with the page gutter */

@media (max-width: 600px) {
    .data-visual {
        margin-inline: calc(var(--page-gutter) * -1);
        padding-inline: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
        width: 100vw;
    }

    /* All text blocks stay aligned with the page gutter */
    .data-visual__item h3,
    .data-visual__item h4,
    .data-visual__footer,
    .data-visual figcaption {
        padding-left: var(--page-gutter);
        padding-right: var(--page-gutter);
    }


    .data-visual figcaption {
        font-size: 0.95rem;
        line-height: 1.4;
    }
}

/* --- 5. Global Utility: Tooltip --- */

.tooltip {
    position: absolute;
    text-align: center;
    padding: var(--internal-space-sm);
    font-family: var(--font-main);
    font-size: 0.85rem;
    background: var(--color-grey-dark);
    color: white;
    border-radius: 4px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    max-width: 250px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    z-index: var(--z-overlay);
}