/**
 * Copyright (c) 2026 DNA Genics, S.L. All rights reserved.
 *
 * Shared reference-fixed ADMIXTURE PCA panel styling (chart container, controls, legend note,
 * closest-references table and fullscreen mode). Colors are driven by --pca-* CSS variables so
 * each report theme can override them; the defaults below fall back to the regional report's
 * --rr-* tokens where present, and to the gold theme otherwise (matching Iberian/Celtic).
 * Per-report overrides (e.g. Viking's blue theme) set --pca-accent/--pca-accent-light on a
 * report-scoped selector in that report's own view CSS.
 */

.pca-panel {
    --pca-accent: var(--rr-gold, #c9a030);
    --pca-accent-light: var(--rr-gold-light, #dbb840);
    --pca-text: var(--rr-mist, rgba(255, 255, 255, 0.9));
    --pca-text-dim: var(--rr-mist-dim, rgba(255, 255, 255, 0.7));
    --pca-font-display: var(--rr-font-display, 'Playfair Display', Georgia, serif);
}

.rr-chart-container {
    background: rgba(42, 33, 26, 0.5);
    border-radius: 16px;
    padding: 24px;
    border: 1px solid rgba(201, 160, 48, 0.1);
    margin-bottom: 24px;
    position: relative;
}

.rr-chart {
    min-height: 400px;
    width: 100%;
}

.rr-chart .plotly .modebar {
    display: flex !important;
    opacity: 1 !important;
    top: 0.85rem !important;
    right: 0.85rem !important;
    padding: 0.2rem 0.25rem;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(201, 160, 48, 0.18);
    border-radius: 999px;
    backdrop-filter: blur(8px);
}

.rr-chart .plotly .modebar-btn {
    color: var(--pca-text-dim) !important;
    fill: currentColor !important;
    opacity: 1 !important;
}

.rr-chart .plotly .modebar-btn:hover,
.rr-chart .plotly .modebar-btn.active {
    color: var(--pca-accent-light) !important;
    background: rgba(201, 160, 48, 0.12);
}

.rr-chart-legend {
    text-align: center;
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
}

.rr-chart-legend p {
    font-size: 0.9rem;
    color: var(--pca-text-dim);
    margin: 0;
}

.rr-chart-legend i {
    color: var(--pca-accent);
    margin-right: 8px;
}

.rr-pca-controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 16px;
    margin: 0 0 20px;
    padding: 18px;
    border: 1px solid rgba(201, 160, 48, 0.18);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
}

.rr-pca-controls label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--pca-text-dim);
    font-size: 0.82rem;
    font-weight: 600;
}

.rr-pca-select {
    min-height: 42px;
    padding: 8px 10px;
    color: #f3f0eb;
    background: #211b17;
    border: 1px solid rgba(201, 160, 48, 0.35);
    border-radius: 8px;
}

.rr-pca-select:focus-visible {
    outline: 3px solid rgba(255, 213, 79, 0.45);
    outline-offset: 2px;
}

.rr-pca-table-wrapper {
    margin-top: 24px;
    padding: 22px;
    border: 1px solid rgba(201, 160, 48, 0.15);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.025);
}

.rr-pca-table-title {
    margin: 0 0 6px;
    color: #fff;
    font-family: var(--pca-font-display);
    font-size: 1.15rem;
}

.rr-pca-table-intro {
    margin-bottom: 14px;
    color: var(--pca-text-dim);
    font-size: 0.88rem;
}

.rr-pca-table {
    --bs-table-color: #e8e2da;
    --bs-table-bg: transparent;
    --bs-table-border-color: rgba(255, 255, 255, 0.08);
    --bs-table-striped-color: #e8e2da;
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
    --bs-table-hover-color: #fff;
    --bs-table-hover-bg: rgba(201, 160, 48, 0.08);
    margin-bottom: 0;
    width: 100%;
    min-width: 36rem;
    border-collapse: collapse;
    color: #e8e2da;
}

.rr-pca-table thead {
    background: rgba(0, 0, 0, 0.35);
}

.rr-pca-table thead th {
    padding: 12px 14px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--pca-accent-light) !important;
    background-color: rgba(0, 0, 0, 0.35) !important;
    border-top: 0;
    border-bottom: 1px solid rgba(201, 160, 48, 0.25);
    white-space: nowrap;
}

.rr-pca-table tbody td {
    padding: 12px 14px;
    color: #e8e2da !important;
    background-color: transparent !important;
    border-top-color: rgba(255, 255, 255, 0.08);
    vertical-align: top;
    font-size: 0.9rem;
    line-height: 1.45;
}

.rr-pca-table tbody tr:nth-child(even) td {
    background-color: rgba(255, 255, 255, 0.025) !important;
}

.rr-pca-table tbody tr:hover td {
    background-color: rgba(201, 160, 48, 0.08) !important;
    color: #fff !important;
}

.rr-pca-table tbody tr.rr-pca-table-row {
    cursor: pointer;
}

.rr-pca-table tbody tr.rr-pca-table-row:focus-visible {
    outline: 2px solid var(--pca-accent-light, #c9a030);
    outline-offset: -2px;
}

.rr-pca-table tbody td:first-child {
    font-weight: 600;
    color: var(--pca-text) !important;
}

.rr-pca-table tbody td:last-child {
    font-variant-numeric: tabular-nums;
    text-align: right;
    color: var(--pca-accent-light) !important;
    white-space: nowrap;
}

.rr-pca-table tbody td:nth-child(3) {
    min-width: 11rem;
    white-space: nowrap;
}

.rr-pca-table-responsive {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    touch-action: pan-x;
    border-radius: 8px;
}

.rr-pca-table-wrapper .rr-pca-table-responsive {
    margin-bottom: 0;
}

@media (max-width: 900px) {
    .rr-pca-controls {
        grid-template-columns: repeat(2, minmax(140px, 1fr));
    }
}

@media (max-width: 520px) {
    .rr-pca-controls {
        grid-template-columns: 1fr;
    }

    .rr-chart-container {
        padding: 8px;
    }

    .rr-pca-table-wrapper {
        padding: 16px;
    }

    .rr-pca-table {
        min-width: 32rem;
    }
}

/* ========================================
   FULLSCREEN MODE (native Fullscreen API + CSS fallback)
   ======================================== */
.rr-chart-container:fullscreen,
.rr-chart-container.rr-chart-fullscreen-fallback {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    margin: 0;
    padding: 32px;
    background: #1a140f;
    border-radius: 0;
    z-index: 2147483000;
}

.rr-chart-container.rr-chart-fullscreen-fallback {
    position: fixed;
    top: 0;
    left: 0;
}

.rr-chart-container:fullscreen .rr-chart,
.rr-chart-container.rr-chart-fullscreen-fallback .rr-chart {
    flex: 1 1 auto;
    min-height: 0;
}
