/* Statistics charts — layout for Plotly-based Data Summary dashboards */

/* ── Controls bar (tabs + filters) ─────────────────────────────── */
.chart-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--fotx-gray-light);
}

/* ── Tabs ──────────────────────────────────────────────────────── */
.chart-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.chart-tab {
    padding: 6px 14px;
    border: 1px solid var(--fotx-blue);
    border-radius: 3px;
    background: #fff;
    color: var(--fotx-blue);
    font-size: var(--font-sm);
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.chart-tab:hover {
    background: var(--fotx-light-blue);
}

.chart-tab:focus-visible {
    outline: 2px solid var(--fotx-blue);
    outline-offset: 2px;
}

.chart-tab.active {
    background: var(--fotx-blue);
    color: #fff;
}

/* ── Filters ──────────────────────────────────────────────────── */
.chart-filters {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-left: auto;
}

.chart-filter-label {
    font-size: var(--font-sm);
    color: var(--fotx-gray-dark);
    white-space: nowrap;
}

.chart-filter-select {
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: var(--font-sm);
    font-family: inherit;
    margin-left: 4px;
}

.chart-filter-select:focus {
    border-color: var(--fotx-blue);
    outline: 2px solid var(--fotx-light-blue);
    outline-offset: 1px;
}

/* ── Checkbox filters (e.g. data type multi-select) ──────────── */
.chart-filter-checkboxes {
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 6px 10px;
    margin: 0;
    flex-basis: 100%;
    position: relative;
}

.chart-filter-checkboxes legend {
    font-size: var(--font-sm);
    color: var(--fotx-gray-dark);
    padding: 0 4px;
}

.chart-checkbox-all {
    position: absolute;
    top: -10px;
    right: 10px;
    background: #fff;
    padding: 0 4px;
}

.chart-filter-checkbox-row {
    clear: both;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    align-items: center;
}

.chart-checkbox-label {
    font-size: var(--font-sm);
    color: var(--fotx-gray-dark);
    white-space: nowrap;
    cursor: pointer;
}

.chart-checkbox-label input {
    margin-right: 3px;
    vertical-align: middle;
}

/* ── Record count summary + download ──────────────────────────── */
.chart-summary {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    font-size: var(--font-sm);
    color: var(--fotx-gray);
    padding: 4px 0;
    min-height: 28px;
}

.chart-download-btn {
    padding: 3px 10px;
    border: 1px solid var(--fotx-gray-light);
    border-radius: 3px;
    background: #fff;
    color: var(--fotx-blue);
    font-size: var(--font-xs);
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.chart-download-btn:hover {
    background: var(--fotx-light-blue);
    border-color: var(--fotx-blue);
}

/* ── Chart container ──────────────────────────────────────────── */
.plotly-container {
    width: 100%;
    min-height: 450px;
    transition: opacity 0.15s;
}

/* ── Loading / error / empty ──────────────────────────────────── */
.chart-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px;
    color: var(--fotx-gray);
    font-size: var(--font-sm);
}

.chart-loading::before {
    content: '';
    width: 20px;
    height: 20px;
    border: 3px solid var(--fotx-gray-light);
    border-top-color: var(--fotx-blue);
    border-radius: 50%;
    animation: chart-spin 0.8s linear infinite;
}

.chart-loading .stats-error {
    color: var(--fotx-red);
}

.chart-loading:has(.stats-error)::before {
    display: none;
}

@keyframes chart-spin {
    to { transform: rotate(360deg); }
}

.chart-no-data {
    padding: 60px 40px;
    text-align: center;
    color: var(--fotx-gray);
    font-size: var(--font-base);
    font-style: italic;
}

.chart-insufficient-data {
    padding: 8px 16px;
    color: var(--fotx-gray);
    font-size: var(--font-sm);
    font-style: italic;
}

/* ── Sub-charts (Uncertainty, Source Institution) ──────────────── */
.plotly-sub-chart {
    width: 100%;
}

.sub-chart-heading {
    margin-top: 28px;
    margin-bottom: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--fotx-gray-light);
    color: var(--fotx-navy);
    font-size: var(--font-lg);
}

.sub-chart-heading:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

/* ── Heat map (Leaflet choropleth) ────────────────────────────── */
.heat-map-container {
    width: 100%;
    height: 600px;
    border: 1px solid var(--fotx-gray-light);
    border-radius: 3px;
}

.heat-map-legend {
    margin-top: 12px;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid var(--fotx-gray-light);
    border-radius: 3px;
    font-size: var(--font-sm);
}

.heat-map-legend strong {
    display: block;
    margin-bottom: 6px;
    color: var(--fotx-navy);
}

/* ── Gap Viewer layout (map + sidebar) ────────────────────────── */
.gap-viewer-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    margin-bottom: 10px;
    padding: 8px 12px;
    background: #fafafa;
    border: 1px solid var(--fotx-gray-light);
    border-radius: 3px;
    font-size: var(--font-xs);
}

.gap-viewer-legend strong {
    color: var(--fotx-navy);
    font-size: var(--font-sm);
    margin-right: 4px;
}

.gv-swatch {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    cursor: pointer;
    transition: opacity 0.15s;
}

.gv-swatch.disabled {
    opacity: 0.3;
}

.gv-swatch::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 14px;
    border: 1.5px solid #686868;
}

.gv-color-1::before { background: #ffaa00; }
.gv-color-2::before { background: #ea0b3b; }
.gv-color-3::before { background: #aa0000; }
.gv-color-4::before { background: #860064; }
.gv-color-5::before { background: #3c005f; }

.gv-unsampled::before {
    background: #fff;
    border-color: #ccc;
}

/* ── Uncertainty layout (charts + sidebar) ─────────────────── */
.uncertainty-layout {
    display: flex;
    gap: 0;
    position: relative;
}

.uncertainty-chart-col {
    flex: 1;
    min-width: 0;
    position: relative;
}

.uncertainty-chart-col .chart-loading {
    min-height: 200px;
}

.uncertainty-sidebar {
    width: 240px;
    flex-shrink: 0;
    padding: 12px;
    background: #fafafa;
    border-left: 1px solid var(--fotx-gray-light);
    font-size: var(--font-xs);
    transition: width 0.25s, padding 0.25s;
    overflow: hidden;
    max-height: 1200px;
}

.uncertainty-sidebar.collapsed {
    width: 0;
    padding: 0;
    border-left: none;
}

.uncertainty-sidebar.collapsed .gv-filter-body {
    display: none;
}

.uncertainty-chart-col .gv-sidebar-toggle {
    right: 248px;
}

.uncertainty-chart-col .gv-sidebar-toggle.sidebar-closed {
    right: 8px;
}

/* ── Combo dropdown (Tableau-style searchable multi-select) ── */
.combo-dropdown {
    position: relative;
}

.combo-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: #fff;
    font-size: var(--font-xs);
    font-family: inherit;
    cursor: pointer;
    text-align: left;
}

.combo-trigger:hover {
    border-color: var(--fotx-blue);
}

.combo-trigger .fa-caret-down {
    font-size: 10px;
    color: var(--fotx-gray);
    flex-shrink: 0;
}

.combo-trigger-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.combo-panel {
    display: none;
    position: fixed;
    z-index: 1001;
    min-width: 216px;
    width: max-content;
    max-width: 340px;
    background: #fff;
    border: 1px solid var(--fotx-blue);
    border-radius: 0 0 3px 3px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.combo-panel.open {
    display: block;
}

.combo-search-row {
    display: flex;
    border-bottom: 1px solid #ccc;
}

.combo-search {
    flex: 1;
    padding: 4px 6px;
    border: none;
    font-size: var(--font-xs);
    font-family: inherit;
    outline: none;
}

.combo-search-clear {
    background: none;
    border: none;
    padding: 0 6px;
    font-size: 16px;
    color: var(--fotx-gray);
    cursor: pointer;
    line-height: 1;
}

.combo-search-clear:hover {
    color: var(--fotx-red);
}

.combo-actions {
    display: flex;
    gap: 0;
    border-bottom: 1px solid #eee;
}

.combo-action {
    flex: 1;
    padding: 3px 0;
    background: none;
    border: none;
    border-right: 1px solid #eee;
    font-size: var(--font-xs);
    font-family: inherit;
    color: var(--fotx-blue);
    cursor: pointer;
}

.combo-action:last-child {
    border-right: none;
}

.combo-action:hover {
    background: var(--fotx-light-blue);
}

.combo-list {
    max-height: 200px;
    overflow-y: auto;
}

.combo-option {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    cursor: pointer;
    font-size: var(--font-xs);
    white-space: nowrap;
}

.combo-option:hover {
    background: var(--fotx-light-blue);
}

.combo-option.hidden {
    display: none;
}

.combo-option input {
    margin: 0;
    flex-shrink: 0;
}

.combo-empty {
    padding: 8px;
    color: var(--fotx-gray);
    font-size: var(--font-xs);
    font-style: italic;
    text-align: center;
}

/* ── Range slider ──────────────────────────────────────────── */
.gv-slider {
    width: 100%;
    margin: 4px 0 2px;
    cursor: pointer;
}

/* ── Dual-thumb range slider ──────────────────────────────── */
.range-dual {
    position: relative;
    height: 20px;
    margin: 6px 0 2px;
}

.range-dual input[type="range"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    margin: 0;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    height: 20px;
}

/* Track — only draw on the bottom (min) layer */
.range-dual-min::-webkit-slider-runnable-track {
    height: 4px;
    background: var(--fotx-gray-light);
    border-radius: 2px;
}

.range-dual-max::-webkit-slider-runnable-track {
    height: 4px;
    background: transparent;
}

.range-dual-min::-moz-range-track {
    height: 4px;
    background: var(--fotx-gray-light);
    border-radius: 2px;
}

.range-dual-max::-moz-range-track {
    height: 4px;
    background: transparent;
}

/* Thumbs — re-enable pointer-events */
.range-dual input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--fotx-blue);
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    cursor: pointer;
    pointer-events: auto;
    margin-top: -5px;
}

.range-dual input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--fotx-blue);
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    cursor: pointer;
    pointer-events: auto;
}

.gv-slider-value {
    display: block;
    text-align: right;
    font-size: 10px;
    color: var(--fotx-gray);
}

/* ── Cell popup (click) ──────────────────────────────────── */
.gv-cell-popup {
    font-size: var(--font-xs);
    line-height: 1.6;
}

.gv-download-row {
    margin: 6px 0 2px;
}

.gv-download-btn {
    padding: 3px 10px;
    border: 1px solid var(--fotx-gray-light);
    border-radius: 3px;
    background: #fff;
    color: var(--fotx-blue);
    font-size: var(--font-xs);
    font-family: inherit;
    cursor: pointer;
}

.gv-download-btn:hover {
    background: var(--fotx-light-blue);
    border-color: var(--fotx-blue);
}

.gv-taxa-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 8px;
    font-size: var(--font-xs);
    border: 1px solid var(--fotx-gray-light);
    border-radius: 3px;
    overflow: hidden;
}

.gv-taxa-table thead th {
    text-align: left;
    font-weight: 600;
    padding: 4px 8px 4px 6px;
    border-bottom: 1px solid var(--fotx-gray-light);
    color: #fff !important;
}

.gv-taxa-table tbody td {
    padding: 2px 8px 2px 0;
    border-bottom: 1px solid #eee;
}

/* ── Hover tip — plain DOM, positioned to the right ─────── */
.gv-hover-tip {
    display: none;
    position: absolute;
    z-index: 1000;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 6px 10px;
    font-size: var(--font-xs);
    line-height: 1.5;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    pointer-events: none;
    white-space: nowrap;
}

.gv-click-hint {
    font-size: 10px;
    color: var(--fotx-gray);
    font-style: italic;
}

/* ── Cell detail panel (click) ────────────────────────────── */
.gv-detail-panel {
    display: none;
    position: absolute;
    z-index: 1000;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 3px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    max-height: 400px;
    width: 280px;
    font-size: var(--font-xs);
    line-height: 1.5;
    cursor: grab;
    flex-direction: column;
}

.gv-detail-panel:active {
    cursor: grabbing;
}

.gv-detail-header {
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
}

.gv-detail-close {
    background: none;
    border: none;
    font-size: 18px;
    line-height: 1;
    color: #999;
    cursor: pointer;
    padding: 4px 8px 0;
}

.gv-detail-close:hover {
    color: #333;
}

.gv-detail-content {
    padding: 0 14px 10px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.gap-viewer-layout {
    display: flex;
    gap: 0;
    border: 1px solid var(--fotx-gray-light);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.gap-viewer-map-col {
    flex: 1;
    min-width: 0;
    position: relative;
}

.gap-viewer-map-col .heat-map-container {
    border: none;
    border-radius: 0;
    height: 650px;
}

.gap-viewer-sidebar {
    width: 240px;
    flex-shrink: 0;
    padding: 12px;
    background: #fafafa;
    border-left: 1px solid var(--fotx-gray-light);
    font-size: var(--font-xs);
    transition: width 0.25s, padding 0.25s;
    overflow: hidden;
}

.gap-viewer-sidebar.collapsed {
    width: 0;
    padding: 0;
    border-left: none;
}

.gap-viewer-sidebar.collapsed .gv-filter-body,
.gap-viewer-sidebar.collapsed .gv-filter-toggle-label {
    display: none;
}

.gv-sidebar-toggle {
    position: absolute;
    top: 8px;
    right: 248px;
    z-index: 1000;
    transition: right 0.25s;
    background: #fff;
    border: 1px solid var(--fotx-gray-light);
    border-radius: 3px;
    padding: 4px 8px;
    font-size: var(--font-xs);
    font-family: inherit;
    color: var(--fotx-navy);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.gv-sidebar-toggle:hover {
    background: var(--fotx-light-blue);
    border-color: var(--fotx-blue);
}

.gv-sidebar-toggle.sidebar-closed {
    right: 8px;
}

.gv-filter-group {
    margin-bottom: 14px;
}

.gv-filter-title {
    display: block;
    font-weight: 600;
    color: var(--fotx-navy);
    margin-bottom: 4px;
    font-size: var(--font-xs);
}

.gv-checkbox {
    display: block;
    margin: 2px 0;
    cursor: pointer;
}

.gv-select,
.gv-input {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: var(--font-xs);
    font-family: inherit;
}

.gv-select:focus,
.gv-input:focus {
    border-color: var(--fotx-blue);
    outline: 2px solid var(--fotx-light-blue);
    outline-offset: 1px;
}

.gv-help-text {
    margin-top: 16px;
    padding-top: 10px;
    border-top: 1px solid var(--fotx-gray-light);
    color: var(--fotx-gray);
    font-size: 10px;
    line-height: 1.4;
}

.gv-help-text p {
    margin: 0 0 6px;
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.legend-swatch {
    display: inline-block;
    width: 18px;
    height: 14px;
    border: 1px solid #999;
    border-radius: 2px;
    flex-shrink: 0;
}

/* Map popup styling */
.huc8-popup strong {
    display: block;
    font-size: var(--font-sm);
    color: var(--fotx-navy);
}

.huc8-popup .huc-code {
    display: block;
    font-size: var(--font-xs);
    color: var(--fotx-gray);
    margin-bottom: 6px;
}

.huc8-popup table {
    border-collapse: collapse;
    font-size: var(--font-xs);
    width: 100%;
}

.huc8-popup table td {
    padding: 2px 8px 2px 0;
}

.huc8-popup table td:last-child {
    text-align: right;
    font-weight: 600;
}

.legend-summary {
    display: block;
    font-size: var(--font-xs);
    color: var(--fotx-gray);
    margin-bottom: 6px;
}

/* Leaflet popup font size override for all map popups */
.heat-map-container .leaflet-popup-content {
    font-size: var(--font-sm);
    line-height: 1.5;
}

/* HUC8 name labels on the map */
.huc8-label {
    background: none;
    border: none;
    box-shadow: none;
}

.huc8-label span {
    display: block;
    text-align: center;
    font-size: 10px;
    font-weight: 600;
    color: #333;
    text-shadow: 1px 1px 2px #fff, -1px -1px 2px #fff,
                 1px -1px 2px #fff, -1px 1px 2px #fff;
    white-space: nowrap;
    pointer-events: none;
}
