.viz-root {
    color-scheme: light;
    --surface-1: #fcfcfb;
    --page-plane: #f9f9f7;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #898781;
    --gridline: #e1e0d9;
    --baseline: #c3c2b7;
    --hairline: rgba(11, 11, 11, 0.10);
    --series-solar: #2a78d6;
    --series-house: #eb6834;
    --series-battery: #1baf7a;
    --series-grid: #eda100;
    --temp-cool: #2a78d6;
    --temp-mild: #eb6834;
    --temp-hot: #e34948;
    /* Grid direction reuses the palette's existing green and red rather than introducing new hues. Defined
       only here on purpose: custom properties are substituted where they are used, so these pick up the
       per-theme values of the tokens they point at without being restated in the dark blocks below. */
    --flow-export: var(--series-battery);
    --flow-import: var(--temp-hot);
}

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-bs-theme="light"])) .viz-root {
        color-scheme: dark;
        --surface-1: #1a1a19;
        --page-plane: #0d0d0d;
        --text-primary: #ffffff;
        --text-secondary: #c3c2b7;
        --text-muted: #898781;
        --gridline: #2c2c2a;
        --baseline: #383835;
        --hairline: rgba(255, 255, 255, 0.10);
        --series-solar: #3987e5;
        --series-house: #d95926;
        --series-battery: #199e70;
        --series-grid: #c98500;
        --temp-cool: #3987e5;
        --temp-mild: #d95926;
        --temp-hot: #e66767;
    }
}

:root[data-bs-theme="dark"] .viz-root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --hairline: rgba(255, 255, 255, 0.10);
    --series-solar: #3987e5;
    --series-house: #d95926;
    --series-battery: #199e70;
    --series-grid: #c98500;
    --temp-cool: #3987e5;
    --temp-mild: #d95926;
    --temp-hot: #e66767;
}

body.viz-root {
    background-color: var(--page-plane);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.viz-root .card {
    background-color: var(--surface-1);
    border-color: var(--hairline);
}

.viz-root header {
    background-color: var(--surface-1);
    border-color: var(--hairline) !important;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.stat-value {
    color: var(--text-primary);
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.1;
}

.stat-value-text {
    font-size: 1.35rem;
}

.stat-unit,
.hero-unit {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 400;
}

.hero-figure {
    color: var(--text-primary);
    font-size: clamp(3rem, 6vw, 3.75rem);
    font-weight: 600;
    line-height: 1;
}

.hero-unit {
    font-size: 1.25rem;
}

.meter {
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
}

.meter-solar {
    background-color: var(--series-solar);
}

.meter-battery {
    background-color: var(--series-battery);
}

.meter:has(.meter-solar) {
    background-color: color-mix(in oklab, var(--series-solar) 22%, var(--surface-1));
}

.meter:has(.meter-battery) {
    background-color: color-mix(in oklab, var(--series-battery) 22%, var(--surface-1));
}

.meter-fill {
    height: 100%;
    border-radius: 4px;
    width: 0;
    transition: width 0.3s ease;
}

.series-key {
    display: inline-block;
    width: 14px;
    height: 3px;
    border-radius: 2px;
    vertical-align: middle;
}

.series-solar {
    background-color: var(--series-solar);
}

.series-house {
    background-color: var(--series-house);
}

.series-battery {
    background-color: var(--series-battery);
}

.series-grid {
    background-color: var(--series-grid);
}

.flow-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.15rem;
}

.flow-dial,
.weather-dial {
    line-height: 0;
}

.weather-dial {
    display: flex;
    justify-content: center;
}

.weather-icon {
    display: inline-flex;
    align-items: center;
    color: var(--text-secondary);
}

.weather-icon svg {
    width: 16px;
    height: 16px;
}

.weather-icon-lg {
    color: var(--text-primary);
    flex: 0 0 auto;
}

.weather-icon-lg svg {
    width: 30px;
    height: 30px;
}

.flow-name {
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
}

.flow-name .series-key {
    margin-right: 0.35rem;
}

.flow-note {
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.dial-value {
    fill: var(--text-primary);
    font-size: 20px;
    font-weight: 600;
}

.dial-unit {
    fill: var(--text-secondary);
    font-size: 10px;
}

.chart-legend {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.chart-legend li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.chart-tooltip {
    position: absolute;
    z-index: 5;
    min-width: 9rem;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--hairline);
    border-radius: 0.375rem;
    background-color: var(--surface-1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    color: var(--text-primary);
    font-size: 0.8125rem;
    pointer-events: none;
}

.chart-tooltip dl {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.15rem 0.5rem;
    margin: 0;
}

.chart-tooltip dt {
    display: contents;
    font-weight: 400;
    color: var(--text-secondary);
}

.chart-tooltip dd {
    margin: 0;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.chart-tooltip-time {
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    font-variant-numeric: tabular-nums;
}

.chart-empty {
    color: var(--text-secondary);
    font-size: 0.875rem;
    padding: 3rem 0;
    text-align: center;
}

#curveChart svg {
    display: block;
    touch-action: none;
}

.axis-text {
    fill: var(--text-muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.series-label {
    fill: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
}

#curveTableView,
#historyTableView {
    max-height: 420px;
}

#historyTable th,
#historyTable td {
    font-variant-numeric: tabular-nums;
}

#historyTable thead th {
    position: sticky;
    top: 0;
    background-color: var(--surface-1);
}

#curveTable th,
#curveTable td {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#curveTable thead th {
    position: sticky;
    top: 0;
    background-color: var(--surface-1);
}
