/* Harris's List - Visualizations Page Stylesheet
 * All colours derive from CSS variables in main.css so light/dark mode works
 * automatically. Chart data palettes live in JS but read chrome colours from
 * here at render time via getComputedStyle().
 */

:root {
    --viz-bg: var(--cream);
    --viz-fg: var(--text-dark);
    --viz-muted: var(--text-light);
    --viz-axis: #888;
    --viz-grid: rgba(0, 0, 0, 0.08);
    --viz-tooltip-bg: #ffffff;
    --viz-tooltip-fg: #2d3436;
    --viz-tooltip-border: rgba(139, 35, 50, 0.35);
    --viz-caveat-bg: rgba(184, 134, 11, 0.12);
    --viz-caveat-border: rgba(184, 134, 11, 0.55);
    --viz-slider-track: rgba(45, 52, 54, 0.18);
    --viz-slider-fill: var(--burgundy);
    --viz-slider-handle: var(--burgundy);
    --viz-section-divider: rgba(45, 52, 54, 0.12);
}

[data-bs-theme="dark"] {
    --viz-axis: #aaa;
    --viz-grid: rgba(255, 255, 255, 0.10);
    --viz-tooltip-bg: #25282b;
    --viz-tooltip-fg: #e1e1e1;
    --viz-tooltip-border: rgba(168, 53, 69, 0.55);
    --viz-caveat-bg: rgba(212, 160, 23, 0.14);
    --viz-caveat-border: rgba(212, 160, 23, 0.55);
    --viz-slider-track: rgba(255, 255, 255, 0.18);
    --viz-slider-fill: var(--burgundy);
    --viz-slider-handle: var(--gold);
    --viz-section-divider: rgba(255, 255, 255, 0.10);
}

/* Page header — matches .browse-header / .map-header convention */
.viz-header {
    background-color: white;
    border-bottom: 2px solid var(--burgundy);
    padding: 2rem 0 1.5rem;
}

[data-bs-theme="dark"] .viz-header {
    background-color: #232729;
}

.viz-header h2 {
    color: var(--burgundy);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.viz-header .lead {
    color: var(--text-light);
    margin-bottom: 0;
}

/* Per-viz sections */
.viz-section {
    padding: 2.5rem 0;
    border-bottom: 1px solid var(--viz-section-divider);
}

.viz-section:last-child {
    border-bottom: none;
}

.viz-section > h3 {
    color: var(--burgundy);
    font-weight: 600;
    margin-bottom: 1rem;
}

.viz-page-intro-section {
    padding: 2rem 0 1.5rem;
    border-bottom: 1px solid var(--viz-section-divider);
}

.viz-page-intro-section p {
    color: var(--text-dark);
    line-height: 1.7;
    font-size: 1.05rem;
    margin-bottom: 0;
}

/* Table of Contents */
.viz-toc {
    padding: 1.5rem 0 2rem;
    border-bottom: 1px solid var(--viz-section-divider);
    margin-bottom: 1rem;
}
.viz-toc-inner {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.5rem 2rem;
}
.viz-toc-group .viz-toc-group-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-light);
    margin: 0 0 0.45rem;
    font-weight: 700;
    border-bottom: 1px solid var(--viz-section-divider);
    padding-bottom: 0.35rem;
}
.viz-toc-group ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
.viz-toc-group li {
    margin: 0;
}
.viz-toc-group li a {
    display: block;
    padding: 0.18rem 0;
/*    color: var(--text-dark);*/
    text-decoration: none;
    font-size: 0.95rem;
    line-height: 1.45;
    border-left: 2px solid transparent;
    padding-left: 0.6rem;
    margin-left: -0.6rem;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.viz-toc-group li a:hover {
    color: var(--burgundy);
    border-left-color: var(--burgundy);
}

/* Group dividers (Place / People / ...) */
.viz-group-heading {
    padding: 2.5rem 0 0.75rem;
    margin-bottom: -0.5rem; /* tighten against the first viz section */
}
.viz-group-heading h2 {
    color: var(--burgundy);
    font-weight: 600;
    font-size: 1.85rem;
    margin: 0 0 0.25rem;
    border-bottom: 2px solid var(--burgundy);
    padding-bottom: 0.4rem;
}
.viz-group-heading .viz-group-subtitle {
    color: var(--text-light);
    font-size: 0.95rem;
    font-style: italic;
    margin: 0;
}

.viz-intro {
    margin-bottom: 1.5rem;
}

.viz-intro .viz-story {
    color: var(--text-dark);
    font-size: 1rem;
    line-height: 1.7;
    margin-bottom: 1rem;
}

.viz-intro .viz-look-for {
    color: var(--text-dark);
    font-size: 1rem;
    line-height: 1.7;
    margin-bottom: 1rem;
}

.viz-intro .viz-look-for ul,
.viz-intro .viz-look-for li {
    font-size: 1rem;
}

.viz-intro .viz-look-for h4 {
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-light);
    margin: 0 0 0.4rem;
    font-weight: 600;
}

.viz-intro .viz-look-for ul {
    margin: 0;
    padding-left: 1.25rem;
}

.viz-intro .viz-look-for li {
    margin-bottom: 0.25rem;
}

.viz-intro .viz-caveat {
    background: var(--viz-caveat-bg);
    border-left: 3px solid var(--viz-caveat-border);
    padding: 0.6rem 0.9rem;
    border-radius: 0 4px 4px 0;
    color: var(--text-dark);
    font-style: italic;
    font-size: 0.92rem;
    line-height: 1.55;
}

.viz-intro .viz-caveat::before {
    content: "Caveat: ";
    font-style: normal;
    font-weight: 600;
    color: var(--text-light);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 0.35rem;
}

/* Chart container */
.viz-chart-wrap {
    position: relative;
    background: var(--viz-bg);
    border: 1px solid var(--viz-section-divider);
    border-radius: 6px;
    padding: 0.75rem 1rem 0.5rem;
}

.viz-chart {
    width: 100%;
    overflow: visible;
}

.viz-chart svg {
    display: block;
    width: 100%;
    max-height: 420px;
    height: auto;
    margin: 0 auto;
    overflow: visible;
}

.viz-chart .leaflet-control svg {
    width: initial;
}

/* Radial charts (sunburst, chord) — square aspect, centered with a wider cap */
.viz-chart .sunburst-svg,
.viz-chart .chord-svg {
    max-width: 640px;
    max-height: 520px;
}

/* Leaflet-based charts: the host needs an explicit height; Leaflet won't size itself */
.viz-chart.viz-chart-is-map {
    max-height: none;
}
.viz-chart .viz-map {
    width: 100%;
    height: 480px;
    border-radius: 4px;
    overflow: hidden;
}

/* Slightly soften Leaflet tooltip to match the rest of the chrome */
.viz-chart .leaflet-tooltip {
    background: var(--viz-tooltip-bg);
    color: var(--viz-tooltip-fg);
    border: 1px solid var(--viz-tooltip-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    font-size: 0.85rem;
    line-height: 1.4;
    padding: 6px 10px;
    border-radius: 4px;
}
.viz-chart .leaflet-tooltip-top:before,
.viz-chart .leaflet-tooltip-bottom:before,
.viz-chart .leaflet-tooltip-left:before,
.viz-chart .leaflet-tooltip-right:before {
    border-top-color: var(--viz-tooltip-border);
}
.viz-chart .leaflet-tooltip strong {
    color: var(--burgundy);
}
.viz-chart .leaflet-control-attribution {
    font-size: 0.7rem;
}
[data-bs-theme="dark"] .viz-chart .leaflet-control-attribution {
    background: rgba(25, 28, 30, 0.85);
    color: var(--text-light);
}
[data-bs-theme="dark"] .viz-chart .leaflet-control-attribution a {
    color: var(--gold);
}

.viz-chart text {
    fill: var(--viz-fg);
    font-family: inherit;
    font-size: 11px;
}

.viz-chart .axis path,
.viz-chart .axis line,
.viz-chart .axis-baseline {
    stroke: var(--viz-axis);
    shape-rendering: crispEdges;
}

.viz-chart .axis text {
    fill: var(--viz-muted);
}

.viz-chart .grid line {
    stroke: var(--viz-grid);
    shape-rendering: crispEdges;
}

.viz-chart .ridge-label {
    fill: var(--viz-muted);
    font-size: 11px;
}

.viz-chart .chord-label {
    fill: var(--viz-fg);
}

.viz-chart .sunburst-label {
    fill: var(--viz-fg);
    pointer-events: none;
}

.viz-chart .stream-label {
    fill: var(--viz-fg);
    pointer-events: none;
    font-size: 11px;
    font-weight: 500;
    paint-order: stroke;
    stroke: var(--viz-bg);
    stroke-width: 3px;
    stroke-linejoin: round;
}

/* Tooltip */
.viz-tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--viz-tooltip-bg);
    color: var(--viz-tooltip-fg);
    border: 1px solid var(--viz-tooltip-border);
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 0.85rem;
    line-height: 1.4;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    opacity: 0;
    transition: opacity 0.12s ease;
    z-index: 10;
    max-width: 260px;
}

.viz-tooltip.is-visible {
    opacity: 1;
}

.viz-tooltip strong {
    color: var(--burgundy);
}

/* Caveat badge (inside chart) */
.viz-badge {
    display: inline-block;
    background: var(--viz-caveat-bg);
    border: 1px solid var(--viz-caveat-border);
    color: var(--text-dark);
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 999px;
    margin-right: 0.4rem;
    margin-bottom: 0.4rem;
    line-height: 1.4;
}

.viz-badge-row {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

/* Double-handle edition slider */
.viz-slider {
    margin: 1.5rem 0 0.5rem;
    padding: 0 8px;
}

.viz-slider-track-wrap {
    position: relative;
    height: 36px;
}

.viz-slider-track {
    position: absolute;
    top: 16px;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--viz-slider-track);
    border-radius: 2px;
}

.viz-slider-fill {
    position: absolute;
    top: 16px;
    height: 4px;
    background: var(--viz-slider-fill);
    border-radius: 2px;
    pointer-events: none;
}

.viz-slider-tick {
    position: absolute;
    top: 22px;
    width: 1px;
    height: 6px;
    background: var(--viz-muted);
    opacity: 0.55;
    pointer-events: none;
}

.viz-slider-tick-label {
    position: absolute;
    top: 30px;
    transform: translateX(-50%);
    font-size: 10px;
    color: var(--viz-muted);
    pointer-events: none;
    white-space: nowrap;
}

.viz-slider-handle {
    position: absolute;
    top: 8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--viz-slider-handle);
    border: 2px solid var(--cream);
    transform: translateX(-50%);
    cursor: grab;
    z-index: 2;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: background 0.15s ease;
}

.viz-slider-handle:focus {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

.viz-slider-handle:active,
.viz-slider-handle.is-dragging {
    cursor: grabbing;
    background: var(--dark-burgundy);
}

.viz-slider-readout {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 0.5rem;
}

.viz-slider-readout strong {
    color: var(--text-dark);
    font-weight: 600;
}

.viz-slider-reset {
    background: none;
    border: 1px solid var(--viz-section-divider);
    color: var(--text-light);
    padding: 2px 10px;
    font-size: 0.78rem;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.viz-slider-reset:hover {
    color: var(--burgundy);
    border-color: var(--burgundy);
}

/* Legend */
.viz-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1.1rem;
    margin-top: 0.85rem;
    padding: 0 0.25rem;
    width: 100%;
    font-size: 0.88rem;
    color: var(--text-dark);
    line-height: 1.5;
}

.viz-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.viz-legend-item.is-dimmed {
    opacity: 0.35;
}

.viz-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* Coverage strip beneath some charts */
.viz-coverage-strip {
    margin-top: 0.5rem;
    font-size: 0.78rem;
    color: var(--text-light);
}

/* Price scatter — bubble overlap blending */
.viz-chart .scatter-svg .scatter-pt {
    mix-blend-mode: multiply;
    transition: opacity 0.12s ease;
}
[data-bs-theme="dark"] .viz-chart .scatter-svg .scatter-pt {
    /* multiply darkens to black on a dark canvas; use lighten instead */
    mix-blend-mode: screen;
}
.viz-chart .scatter-svg .scatter-pt:hover {
    stroke-width: 1.6;
    opacity: 1;
}
.viz-chart .scatter-svg .grid-y {
    pointer-events: none;
}
.viz-chart .scatter-svg .scatter-empty {
    font-style: italic;
}

/* Paths Sankey — paired panels (origin→reason | reason→occupation) */
.viz-chart.viz-chart-is-paired {
    /* The two panels live in a CSS grid; container needs no fixed aspect. */
}
.viz-chart .sankey-panels,
.viz-chart .viz-paired-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.4rem;
    align-items: start;
}
.viz-chart .viz-paired-panels.viz-paired-uneven {
    /* For cultural-refs / verse: left panel is wider (streamgraph or stack)
     * than the right (leaderboard). */
    grid-template-columns: 1.55fr 1fr;
}
.viz-chart .sankey-panel,
.viz-chart .viz-paired-panel {
    min-width: 0;
}
.viz-chart .viz-paired-panel svg {
    width: 100%;
    height: auto;
    display: block;
}
.viz-chart .leader-axis text {
    /* Author names on the leaderboard need the full theme foreground */
    font-weight: 500;
}
.viz-chart .sankey-svg {
    width: 100%;
    height: auto;
    display: block;
}
.viz-chart .sankey-link {
    transition: stroke-opacity 0.12s ease;
    cursor: pointer;
}
.viz-chart .sankey-node {
    stroke: var(--viz-bg);
    stroke-width: 1;
    cursor: pointer;
}
.viz-chart .sankey-label {
    pointer-events: none;
    font-family: inherit;
}
.viz-chart .sankey-coverage {
    margin-top: 0.4rem;
    font-size: 0.78rem;
    color: var(--text-light);
    text-align: center;
}
.viz-chart .sankey-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-light);
    font-style: italic;
}
[data-bs-theme="dark"] .viz-chart .sankey-link {
    mix-blend-mode: screen;
}
@media (max-width: 880px) {
    .viz-chart .sankey-panels {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

/* Price heatmap — cells, whiskers, IQR box, median bar */
.viz-chart .heatmap-svg .heatmap-cell {
    transition: opacity 0.12s ease;
}
.viz-chart .heatmap-svg .heatmap-box {
    cursor: pointer;
}
.viz-chart .heatmap-svg .heatmap-box:hover .box-iqr {
    fill-opacity: 0.85;
}
.viz-chart .heatmap-svg .box-iqr {
    transition: fill-opacity 0.12s ease;
}

/* Tooltip extras used by price-scatter / price-heatmap */
.viz-tooltip .tt-muted {
    color: var(--text-light);
    font-size: 0.78rem;
}
.viz-tooltip .tt-quote {
    margin-top: 4px;
    font-style: italic;
    color: var(--text-light);
    border-top: 1px dashed var(--viz-section-divider, rgba(0,0,0,0.12));
    padding-top: 4px;
    font-size: 0.78rem;
}

/* Verse-mottoes: second-row separator between the (length / attribution) pair
 * and the (origin-period / theme leaderboard) pair from the enrichment pass. */
.viz-chart .verse-row-sep {
    height: 0;
    border-top: 1px dashed var(--viz-section-divider);
    margin: 1rem 0 0.75rem;
}

/* Verse-mottoes panel headings — shared between "Top sources" and "Top themes
 * (multi-label)" so the styling can't drift between panels. */
.viz-chart .verse-panel-title {
    fill: var(--viz-muted);
    font-size: 13px;
    font-style: italic;
    font-weight: 400;
}

/* Origin-period legend rendered as HTML below the chart so flex-wrap handles
 * variable label widths without truncation. */
.viz-chart .origin-legend-html {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.9rem;
    margin-top: 0.4rem;
    font-size: 0.78rem;
    color: var(--text-light);
    line-height: 1.3;
}
.viz-chart .origin-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}
.viz-chart .origin-legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex: 0 0 auto;
}

/* ============================================================
 * Paratext mosaic (viz 13)
 * ============================================================ */

/* Panel-heading variant used by paratext HTML titles (cf. .verse-panel-title
 * which is SVG-only). Uses `color` so it renders inside an HTML <div>. */
.viz-chart .paratext-panel-title {
    color: var(--viz-muted);
    font-size: 13px;
    font-style: italic;
    font-weight: 400;
    margin: 0 0 0.35rem 0;
    text-align: center;
}

/* Cards grid (left panel of row 1) — fits 3 cards on a typical viewport. */
.viz-chart .paratext-cards-host {
    /* The grid lives directly inside the panel; allow it to overflow scroll
     * if a tall edition pushes the panel beyond the heatmap row height. */
    max-height: 760px;
    overflow-y: auto;
    padding-right: 4px;
}
.viz-chart .paratext-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.6rem;
}
.viz-chart .paratext-empty {
    padding: 1.5rem 0.5rem;
    color: var(--text-light);
    font-style: italic;
    text-align: center;
}
.viz-chart .paratext-card {
    background: var(--viz-bg);
    border: 1px solid var(--viz-section-divider, rgba(0,0,0,0.12));
    border-radius: 6px;
    padding: 0.55rem 0.6rem 0.5rem;
    font-size: 0.78rem;
    line-height: 1.32;
    cursor: default;
    transition: border-color 0.12s ease, transform 0.12s ease;
}
.viz-chart .paratext-card:hover {
    border-color: rgba(139, 35, 50, 0.55);
    transform: translateY(-1px);
}
.viz-chart .paratext-card-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.4rem;
}
.viz-chart .paratext-card-year {
    color: #8b2332;
    font-weight: 600;
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}
.viz-chart .paratext-card-subtitle-group {
    color: var(--viz-muted);
    font-style: italic;
    font-size: 0.7rem;
    text-align: right;
}
.viz-chart .paratext-card-imprint {
    color: var(--text-light);
    margin-top: 0.25rem;
}
.viz-chart .paratext-card-price {
    color: var(--text-light);
    font-size: 0.72rem;
    margin-top: 0.1rem;
}
.viz-chart .paratext-card-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.4rem;
}
.viz-chart .paratext-chip {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-style: italic;
    border: 1px solid currentColor;
    line-height: 1.4;
}
.viz-chart .paratext-chip-preface {
    color: #8b2332;
}
.viz-chart .paratext-chip-afterword {
    color: #3a6f78;
}
.viz-chart .paratext-card-quote {
    margin-top: 0.4rem;
    font-style: italic;
    color: var(--text-light);
    border-left: 2px solid rgba(139, 35, 50, 0.35);
    padding-left: 0.45rem;
    font-size: 0.74rem;
}
.viz-chart .paratext-card-quote-afterword {
    border-left-color: rgba(58, 111, 120, 0.45);
}
.viz-chart .paratext-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.45rem;
}
.viz-chart .paratext-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.66rem;
    font-weight: 500;
    background: rgba(139, 35, 50, 0.10);
    color: #8b2332;
    border: 1px solid rgba(139, 35, 50, 0.20);
}
.viz-chart .paratext-badge-publisher-moved,
.viz-chart .paratext-badge-subtitle-changed,
.viz-chart .paratext-badge-afterword-introduced {
    background: rgba(58, 111, 120, 0.12);
    color: #3a6f78;
    border-color: rgba(58, 111, 120, 0.25);
}

/* Stance-arc legend (HTML below the SVG) */
.viz-chart .paratext-arc-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 0.9rem;
    margin-top: 0.4rem;
    font-size: 0.78rem;
    color: var(--text-light);
    line-height: 1.3;
    justify-content: center;
}
.viz-chart .paratext-arc-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}
.viz-chart .paratext-arc-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex: 0 0 auto;
}
.viz-chart .paratext-arc-dot-preface {
    background: #8b2332;
}
.viz-chart .paratext-arc-dot-afterword {
    background: transparent;
    border: 2px solid #3a6f78;
}

[data-bs-theme="dark"] .viz-chart .paratext-card {
    background: rgba(255,255,255,0.04);
}
[data-bs-theme="dark"] .viz-chart .paratext-card-year {
    color: #d77a85;
}
[data-bs-theme="dark"] .viz-chart .paratext-chip-preface,
[data-bs-theme="dark"] .viz-chart .paratext-badge {
    color: #d77a85;
    border-color: rgba(215, 122, 133, 0.4);
    background: rgba(215, 122, 133, 0.10);
}
[data-bs-theme="dark"] .viz-chart .paratext-chip-afterword {
    color: #7fb6c0;
}
[data-bs-theme="dark"] .viz-chart .paratext-badge-publisher-moved,
[data-bs-theme="dark"] .viz-chart .paratext-badge-subtitle-changed,
[data-bs-theme="dark"] .viz-chart .paratext-badge-afterword-introduced {
    color: #7fb6c0;
    border-color: rgba(127, 182, 192, 0.4);
    background: rgba(127, 182, 192, 0.10);
}

/* Responsive */
@media (max-width: 768px) {
    .viz-section {
        padding: 2rem 0;
    }
    .viz-chart {
        min-height: 260px;
    }
    .viz-chart text {
        font-size: 10px;
    }
    .viz-chart .paratext-cards-host {
        max-height: none;
    }
}
