/**
 * @file rabies-historical.css
 * @description Styles for historical stacked vertical bars showing all years
 *   and all animal categories, keyboard focus, complete data table and exports.
 * @author Roberto Flores
 * @organization Los Angeles County Department of Public Health
 * @updated 2026-11-04
 * @note Load after global DPH dashboard, table, and export styles.
 */
#historical-data {
    --rb-blue: #005a9c;
    --rb-blue-deep: #103e65;
    --rb-line: #d5e3eb;
    min-width: 0;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

#historical-data .rb-historical-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .65rem;
    margin: 0 0 .75rem;
}

#historical-data .rb-historical-toolbar[hidden],
#historical-data .rb-historical-table-panel[hidden] {
    display: none !important;
}

#historical-data .rb-historical-chart-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .65rem;
    margin: .75rem 0 .65rem;
}

#historical-data .rb-historical-chart-heading h3 {
    margin: 0;
    color: var(--rb-blue-deep);
    font-size: .95rem;
    font-weight: 700;
    line-height: 1.4;
}

#historical-data .rb-historical-visualization {
    min-width: 0;
    max-width: 100%;
}

#historical-data .rb-historical-stack-instructions {
    margin: .3rem 0 .75rem;
    font-size: .85rem;
    line-height: 1.5;
    color: #334e5e;
}

#historical-data .rb-historical-stack-scroll {
    position: relative;
    max-width: 100%;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    padding: .35rem 0;
    border: 1px solid #d9e7eb;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    background: #fff;
}

#historical-data .rb-historical-stack-svg {
    display: block;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto;
    overflow: hidden;
}

#historical-data .rb-historical-stack-segment {
    pointer-events: none;
}

#historical-data .rb-historical-stack-year-target {
    cursor: pointer;
    pointer-events: all;
}

#historical-data .rb-historical-stack-highlight.is-active {
    stroke: #005a9c;
    stroke-width: 2;
    stroke-dasharray: 5 3;
}

#historical-data .rb-historical-stack-year-target:focus-visible {
    stroke: #b84d00;
    stroke-width: 3;
    outline: none;
}

#historical-data .rb-historical-stack-scroll:focus-visible,
#historical-data .rb-historical-table-scroll:focus-visible {
    outline: 3px solid #b84d00;
    outline-offset: 2px;
}

#historical-data .rb-historical-stack-details {
    margin: .75rem 0;
    padding: .65rem .8rem;
    color: #103e65;
    font-size: .84rem;
    line-height: 1.55;
    border-left: 3px solid #005a9c;
    background: #f3f8fb;
    overflow-wrap: anywhere;
}

/* ==========================================================
   HISTORICAL CHART HEADING + LEGEND
   Mirrors #rabid-graph .rb-chart-heading / .rb-legend.
   The title and legend are siblings in the same heading row.
   Legend remains compact; categories can wrap inside it.
   ========================================================== */
#historical-data #rb-historical-chart {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

#historical-data .rb-historical-chart-heading {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, auto);
    align-items: center;
    column-gap: .75rem;
    margin: .75rem 0 .5rem;
    min-width: 0;
}

#historical-data .rb-historical-chart-title-group {
    min-width: 0;
}

#historical-data .rb-historical-chart-heading h3 {
    margin: 0;
    color: var(--rb-blue-deep);
    font-size: .86rem;
    font-weight: 700;
    line-height: 1.3;
}

#historical-data .rb-historical-chart-heading .rb-historical-stack-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    justify-self: end;
    gap: .375rem;
    width: fit-content;
    max-width: min(100%, 720px);
    min-width: 0;
    margin: 0;
    padding: .35rem;
    background: #f3f7fa;
    border: 1px solid var(--rb-line);
    border-radius: 7px;
    box-sizing: border-box;
}

#historical-data .rb-historical-stack-legend-item {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    min-height: 28px;
    max-width: 100%;
    padding: .25rem .5rem;
    background: #e8f3fb;
    color: #103e65;
    border: 1px solid #b7d4e9;
    border-radius: 5px;
    font-size: .68rem;
    font-weight: 700;
    line-height: 1.3;
    white-space: nowrap;
    box-sizing: border-box;
}

#historical-data .rb-historical-stack-legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    flex: 0 0 10px;
    border: 1px solid rgb(0 0 0 / 18%);
    border-radius: 2px;
}

#historical-data .rb-historical-visualization {
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

/* Match the dashboard's single-column heading on narrow layouts. */
@media (max-width: 768px) {
    #historical-data .rb-historical-chart-heading {
        grid-template-columns: minmax(0, 1fr);
        gap: .65rem;
    }

    #historical-data .rb-historical-chart-heading .rb-historical-stack-legend {
        justify-self: start;
        justify-content: flex-start;
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    #historical-data .rb-historical-stack-legend-item {
        min-height: 32px;
        white-space: normal;
    }
}

/* Full data table and shared PDF export retain the original classes. */
#historical-data .rb-historical-table-panel {
    margin-top: .8rem;
}

#historical-data .rb-historical-table-scroll {
    max-width: 100%;
    overflow-x: auto;
    border: 1px solid #d9e7eb;
    border-radius: 6px;
}

#historical-data .rb-historical-data-table {
    width: max-content;
    min-width: 100%;
    margin-bottom: 0;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

#historical-data .rb-historical-data-table th,
#historical-data .rb-historical-data-table td {
    padding: .45rem .65rem;
    border-bottom: 1px solid #d9e7eb;
    white-space: nowrap;
}

#historical-data .rb-historical-data-table thead th {
    background: #e8f4fa;
    color: #103e65;
    text-align: left;
}

#historical-data .rb-historical-data-table td {
    text-align: right;
}

#historical-data .rb-historical-data-table tbody tr:hover,
#historical-data .rb-historical-data-table tbody tr:focus-within {
    background: #e8f4fa;
}

#historical-data .rb-historical-table-panel>.rb-table-export-actions {
    margin: 0 0 1rem;
}

@media (max-width: 600px) {

    #historical-data .rb-historical-stack-instructions,
    #historical-data .rb-historical-stack-details {
        font-size: .8rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    #historical-data .rb-historical-stack-scroll {
        scroll-behavior: auto;
    }
}

/* Fixed-width coordinate system scales to a maximum 1000px content area. */
#historical-data .rb-historical-stack-scroll {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
}

#historical-data .rb-historical-stack-scroll>svg.rb-historical-stack-svg {
    display: block;
    box-sizing: border-box;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto;
    overflow: hidden;
}

/* Long animal names in the legend wrap without extending the content box. */
#historical-data .rb-historical-stack-legend-item {
    max-width: 100%;
    overflow-wrap: anywhere;
}

/* ==========================================================
   HISTORICAL DETAILS PANEL — dashboard styling, interactive.
   Appended to document.body (do not scope under #historical-data).
   Three columns on wide screens, two on tablets, one on phones.
   ========================================================== */
.rb-tooltip.rb-floating-tooltip.rb-historical-floating-tooltip {
    position: fixed;
    z-index: 10000;
    box-sizing: border-box;
    width: min(var(--rb-popup-width, 760px), calc(100vw - 24px));
    min-width: 0;
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    padding: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid #b4cbda;
    border-radius: 10px;
    background: #fff;
    color: #18364a;
    box-shadow: 0 12px 36px rgb(16 62 101 / 25%), 0 3px 8px rgb(16 62 101 / 12%);
    font-family: inherit;
    font-size: .875rem;
    line-height: 1.5;
    pointer-events: auto !important;
    overflow: visible;
}

.rb-historical-floating-tooltip[hidden],
.rb-historical-tooltip-arrow[hidden] {
    display: none !important;
}

.rb-historical-floating-tooltip::before {
    content: none !important;
}

.rb-historical-floating-tooltip .rb-tooltip-heading {
    display: flex;
    flex: 0 0 auto;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
    padding: .65rem .9rem;
    border-radius: 9px 9px 0 0;
    background: #103e65;
    color: #fff;
}

.rb-historical-floating-tooltip .rb-historical-popup-title {
    margin: 0;
    color: #fff;
    font-size: .95rem;
    font-weight: 800;
    line-height: 1.4;
}

.rb-historical-floating-tooltip .rb-historical-tooltip-close {
    flex: 0 0 auto;
    min-width: 54px;
    min-height: 38px;
    padding: .3rem .65rem;
    border: 1px solid #daeaf5;
    border-radius: 5px;
    background: #fff;
    color: #103e65;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
}

.rb-historical-floating-tooltip .rb-historical-tooltip-close:hover {
    background: #e8f3fb;
}

.rb-historical-floating-tooltip :is(.rb-historical-tooltip-close, .rb-historical-tooltip-grid):focus-visible {
    outline: 3px solid #b84d00 !important;
    outline-offset: -3px;
}

.rb-historical-floating-tooltip .rb-historical-tooltip-help {
    flex: 0 0 auto;
    margin: 0;
    padding: .45rem .9rem;
    color: #334e5e;
    font-size: .75rem;
    background: #f5f9fc;
}

.rb-tooltip.rb-floating-tooltip.rb-historical-floating-tooltip .rb-tooltip-list.rb-historical-tooltip-grid {
    box-sizing: border-box;
    display: grid;
    grid-template-columns: repeat(var(--rb-popup-columns, 3), minmax(0, 1fr));
    align-content: start;
    gap: .45rem .65rem;
    min-height: 0;
    max-height: min(52dvh, 440px);
    overflow-y: auto !important;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: auto;
    flex: 0 1 auto;
    width: 100%;
    padding: .65rem .8rem;
    background: #fff;
}

.rb-tooltip.rb-floating-tooltip.rb-historical-floating-tooltip .rb-tooltip-row {
    box-sizing: border-box;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: .35rem;
    min-width: 0;
    width: 100%;
    min-height: 42px;
    padding: .35rem .5rem;
    border: 1px solid #e1eaf0;
    border-radius: 5px;
    background: #f8fafc;
}

.rb-tooltip.rb-floating-tooltip.rb-historical-floating-tooltip .rb-tooltip-label {
    display: inline-flex;
    gap: .4rem;
    align-items: center;
    min-width: 0;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: normal;
    font-weight: 600;
    line-height: 1.3;
}

.rb-tooltip.rb-floating-tooltip.rb-historical-floating-tooltip .rb-tooltip-dot {
    display: inline-block;
    width: 11px;
    height: 11px;
    flex: 0 0 11px;
    border: 1px solid rgb(0 0 0 / 15%);
    border-radius: 3px;
}

.rb-tooltip.rb-floating-tooltip.rb-historical-floating-tooltip .rb-tooltip-value {
    color: #103e65;
    font-weight: 800;
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.rb-historical-floating-tooltip .rb-historical-tooltip-note {
    flex: 0 0 auto;
    margin: 0;
    padding: .45rem .9rem;
    color: #526678;
    font-size: .75rem;
    text-align: center;
}

.rb-historical-floating-tooltip .rb-tooltip-total {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .75rem;
    align-items: center;
    padding: .7rem .9rem;
    border-top: 1px solid #b8d4e6;
    border-radius: 0 0 9px 9px;
    background: #e8f3fb;
    color: #103e65;
    font-weight: 800;
}

.rb-historical-floating-tooltip .rb-tooltip-total strong {
    font-variant-numeric: tabular-nums;
}

/* Keep the attached arrow ABOVE the popup body so the top arrow is
   visible when the popup opens below a reporting-year bar. The JS sets
   top/bottom, border edges and background to match the adjacent panel. */
.rb-tooltip.rb-floating-tooltip.rb-historical-floating-tooltip .rb-historical-tooltip-arrow {
    position: absolute !important;
    z-index: 2 !important;
    display: block;
    box-sizing: border-box;
    width: 14px;
    height: 14px;
    margin: 0;
    padding: 0;
    border-radius: 1px;
    transform: translateX(-50%) rotate(45deg);
    pointer-events: none;
}

/* JavaScript toggles hidden when there is not room for an attached arrow. */
.rb-tooltip.rb-floating-tooltip.rb-historical-floating-tooltip .rb-historical-tooltip-arrow[hidden] {
    display: none !important;
}

@media (max-width: 800px) {
    .rb-tooltip.rb-floating-tooltip.rb-historical-floating-tooltip .rb-tooltip-list.rb-historical-tooltip-grid {
        grid-template-columns: repeat(min(2, var(--rb-popup-columns, 3)), minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .rb-tooltip.rb-floating-tooltip.rb-historical-floating-tooltip {
        width: min(var(--rb-popup-width, 760px), calc(100vw - 24px));
        max-height: min(75dvh, 620px);
    }

    .rb-tooltip.rb-floating-tooltip.rb-historical-floating-tooltip .rb-tooltip-list.rb-historical-tooltip-grid {
        grid-template-columns: minmax(0, 1fr);
        max-height: min(40dvh, 340px);
        gap: .3rem;
    }

    .rb-historical-floating-tooltip .rb-tooltip-row {
        min-height: 44px;
    }

    .rb-historical-floating-tooltip .rb-tooltip-heading {
        padding-block: .4rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .rb-historical-floating-tooltip {
        animation: none !important;
        transition: none !important;
    }
}

/* ==========================================================
   Historical chart axis titles — match regular rabies dashboard
   The class is applied only to the two axis titles, not ticks.
   ========================================================== */
#historical-data .rb-historical-stack-svg .rb-historical-axis-title {
    fill: #103e65;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    text-decoration-line: underline;
    text-decoration-color: #c58b24;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

/* HTML axis titles — preserve the original SVG/container structure. */
#historical-data .rb-historical-stack-scroll {
    position: relative;
}

#historical-data .rb-historical-y-axis-title {
    position: absolute;
    top: 50%;
    left: 4px;
    z-index: 1;
    transform: translateY(-50%) rotate(180deg);
    writing-mode: vertical-rl;
    pointer-events: none;
}

#historical-data .rb-chart-bottom.rb-historical-chart-bottom {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: .25rem 0 .75rem;
    padding: .3rem 0;
    text-align: center;
}

#historical-data .rb-historical-y-axis-title,
#historical-data .rb-historical-chart-bottom .axis-title-underline {
    color: #103e65;
    font-family: inherit;
    font-size: .8rem;
    font-weight: 700;
    line-height: 1.4;
    text-decoration-line: underline;
    text-decoration-color: #c58b24;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

/* Keep the X-axis title INSIDE the graph border, directly below its SVG. */
#historical-data .rb-historical-stack-scroll>.rb-historical-chart-bottom {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-height: 28px;
    margin: 0 !important;
    padding: 0 0 .35rem !important;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

#historical-data .rb-historical-stack-scroll>.rb-historical-chart-bottom .axis-title-underline {
    display: inline-block;
    color: #103e65;
    font-weight: 700;
    text-decoration: underline;
    text-decoration-color: #c58b24;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

/* ==========================================================
   RABIES HISTORICAL CHART — TEMPORARILY HIDE PDF EXPORT
   ==========================================================
   Hides PDF download controls for historical data only.

   Does not affect:
   - Rabies Dashboard PDF
   - Rabies Map PDF
   - Historical chart visualization
   - Historical data table
   ========================================================== */

#historical-data .rb-table-export-btn,
#historical-data #rb-historical-pdf {
    display: none !important;
}

#historical-data .rb-historical-stack-legend-item {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.35rem !important;
    min-height: 28px !important;
    padding: 0.25rem 0.5rem !important;
    background: #e8f3fb !important;
    color: #103e65 !important;;
    border: 1px solid #b7d4e9 !important;
    border-radius: 5px !important;
    font-size: 0.64rem !important;
    font-weight: 700 !important;;
    line-height: 1.3 !important;
    white-space: nowrap !important;
}