/* Shared styles of the D3 chart pages; see js/charts.js. */

/* Filters: one row above the chart, wrapping on small screens */
.chart-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 16px;
    align-items: flex-end;
    margin-bottom: 16px;
}

.control {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: #666;
}

.control select,
.control input[type="number"],
.control input[type="search"] {
    padding: 8px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: white;
    font: inherit;
    font-size: 14px;
    color: #212529;
    min-width: 150px;
}

.control input[type="number"] {
    min-width: 0;
    width: 100px;
}

.control input[type="range"] {
    width: 180px;
    accent-color: #35b0ab;
}

.control-inline {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #333;
    min-height: 36px;
}

/* Segmented buttons for a few exclusive choices */
.segmented {
    display: inline-flex;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    overflow: hidden;
    background: white;
}

.segmented button {
    border: 0;
    background: none;
    padding: 8px 12px;
    font: inherit;
    font-size: 14px;
    color: #444;
    cursor: pointer;
}

.segmented button + button {
    border-left: 1px solid #dee2e6;
}

.segmented button[aria-pressed="true"] {
    background: #15607A;
    color: white;
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
    flex: none;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background-color: #ccc;
    transition: 0.2s;
    border-radius: 20px;
}

.toggle-slider::before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: 0.2s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: #35b0ab;
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

.toggle-switch input:focus-visible + .toggle-slider {
    outline: 2px solid #15607A;
    outline-offset: 2px;
}

/* Stat tiles above a chart */
.stat-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat-tiles:empty {
    display: none;
}

.stat-tile {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    padding: 12px 16px;
}

.stat-label {
    font-size: 12px;
    color: #666;
}

.stat-value {
    font-size: 24px;
    font-weight: bold;
    color: #212529;
    margin-top: 2px;
}

.stat-note {
    font-size: 12px;
    color: #666;
    margin-top: 2px;
}

/* The chart card */
.chart-card {
    position: relative;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 16px;
}

.chart-card.loading svg {
    opacity: 0.4;
    transition: opacity 0.2s;
}

.chart-heading {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    margin: 0 0 4px;
}

.chart-note {
    font-size: 13px;
    color: #666;
    margin: 0 0 8px;
}

.chart-card svg {
    display: block;
    overflow: visible;
    font-family: inherit;
}

.chart-empty {
    color: #666;
    text-align: center;
    padding: 80px 16px;
}

/* Axes and grid: recessive */
.chart-card .tick text {
    fill: #666;
    font-size: 12px;
}

.chart-card .domain,
.chart-card .tick line {
    stroke: #cfd6da;
}

.chart-card .grid .tick line {
    stroke: #eceff1;
}

.chart-card .grid .domain {
    display: none;
}

.axis-title {
    fill: #666;
    font-size: 12px;
}

.mark-label {
    fill: #444;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.reference-label {
    fill: #888;
    font-size: 11px;
}

[tabindex]:focus {
    outline: none;
}

[tabindex]:focus-visible {
    outline: 2px solid #15607A;
    outline-offset: 1px;
}

/* Legend */
.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 13px;
    color: #444;
    margin: 4px 0 8px;
}

.chart-legend:empty {
    display: none;
}

.chart-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chart-key {
    display: inline-block;
    flex: none;
}

.chart-key-rect {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    background: var(--key-color);
}

.chart-key-line {
    width: 14px;
    height: 2px;
    border-radius: 1px;
    background: var(--key-color);
}

.chart-key-dash {
    width: 14px;
    border-top: 2px dashed var(--key-color);
}

.chart-key-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--key-color);
}

.chart-key-ring {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 2px solid var(--key-color);
}

/* Tooltip */
.chart-tooltip {
    position: absolute;
    z-index: 10;
    pointer-events: none;
    background: white;
    border: 1px solid #e3e7ea;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    padding: 8px 10px;
    font-size: 13px;
    color: #444;
    max-width: 280px;
}

.chart-tooltip-title {
    font-weight: bold;
    color: #212529;
}

.chart-tooltip-subtitle {
    color: #666;
    font-size: 12px;
    margin-bottom: 4px;
}

.chart-tooltip-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.chart-tooltip-row strong {
    color: #212529;
    font-variant-numeric: tabular-nums;
}

/* Table view under a chart */
.chart-table {
    margin-top: 16px;
}

.chart-table summary {
    cursor: pointer;
    color: #15607A;
    font-size: 14px;
}

.chart-table table {
    margin-top: 8px;
    font-variant-numeric: tabular-nums;
}

.chart-table th {
    cursor: default;
}

.chart-table th.sortable {
    cursor: pointer;
}

.chart-table tr.selected-row td {
    background: #eaf6f5;
    font-weight: 600;
}

/* Removable chips, e.g. the labelled players of a scatterplot */
.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.chip-list:empty {
    display: none;
}

.chip {
    border: 1px solid #35b0ab;
    border-radius: 999px;
    background: #eaf6f5;
    color: #15607A;
    padding: 4px 10px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.chip:hover {
    background: #d5efed;
}

.chip-clear {
    border-color: #dee2e6;
    background: white;
    color: #666;
}

.chart-table td:first-child,
.chart-table th:first-child {
    text-align: left;
}

@media (max-width: 600px) {
    .chart-card {
        padding: 8px;
    }

    .control select {
        min-width: 0;
    }

    .stat-value {
        font-size: 20px;
    }
}
