html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: #f9f9f9;
    font-family: sans-serif;
}

.page-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    box-sizing: border-box;
}

.page-container.mobile-info-open {
    padding-bottom: min(56vh, 540px);
    padding-bottom: min(56dvh, 540px);
}

header {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 8px 10px;
    padding-left: max(10px, env(safe-area-inset-left, 0px));
    padding-right: max(10px, env(safe-area-inset-right, 0px));
}

header h1 {
    flex: 0 0 auto;
    min-width: 0;
    margin: .4em 0;
}

#current-ministry {
    min-width: 0;
    max-width: 720px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: clamp(18px, 1.8vw, 26px);
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: -.02em;
    overflow-wrap: anywhere;
    color: inherit;
    transition: opacity .3s ease;
}

#toggle-controls-button {
    flex: 0 0 auto;
    margin-left: auto;
    padding: 8px 10px;
    font-size: 14px;
    cursor: pointer;
}

@media (max-width: 900px) {
    header { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; }
    header h1 { grid-column: 1; grid-row: 1; margin: 0; }
    #toggle-controls-button { grid-column: 2; grid-row: 1; }
    #current-ministry { grid-column: 1 / -1; grid-row: 2; font-size: 20px; }
}

#data-timestamp {
    flex-basis: 100%;
    grid-column: 1 / -1;
    text-align: right;
    color: #444;
    font-size: 12px;
    line-height: 1.5;
}

#data-timestamp span {
    display: inline-block;
}

#controls button[aria-pressed="true"] {
    background: #d9e8ff;
    border: 1px solid #5273a5;
    border-radius: 3px;
}

#controls-toggle {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    padding: 0;
    text-align: left;
    cursor: pointer;
}

#controls-toggle::after {
    content: " ▾";
    font-size: 0.65em;
}

#controls-toggle[aria-expanded="false"]::after {
    content: " ▸";
}

/* Header and controls take only as much vertical space as they need */
header, #controls {
    flex: 0 0 auto;
}

/* Keep the grouped panel within the previous desktop/mobile height budgets. */
#controls {
    box-sizing: border-box;
    height: 156px;
    max-height: min(calc(100dvh - 110px), calc(100dvh - var(--history-top, 90px) - 8px));
    padding: 6px 10px;
    background: #ddd;
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.2fr) 90px;
    grid-template-rows: minmax(0, 1fr) auto;
    align-items: start;
    gap: 4px 10px;
    transition: background 0.3s;
    overflow-y: auto;
}
.controls-group {
    min-width: 0;
    box-sizing: border-box;
    padding: 3px 5px 4px;
    border: 1px solid #b9bec6;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.23);
}
.controls-group h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 3px;
    color: #475164;
    font-size: 11px;
    line-height: 12px;
    font-weight: 600;
    letter-spacing: 0.025em;
}
.controls-group h2::after { content: ""; flex: 1; border-top: 1px solid #b9bec6; }
.navigation-primary { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.ministry-choice { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; overflow: hidden; }
.ministry-choice label { font-size: 12px; white-space: nowrap; }
#ministry-select { min-width: 0; width: 100%; flex: 1; }
#ministry-select:focus-visible { outline: 2px solid #5273a5; outline-offset: -2px; }
#sunshine-toggle { flex: 0 0 auto; }
.navigation-secondary { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.search-controls {
    display: flex;
    align-items: stretch;
    flex: 1 1 230px;
    min-width: 0;
    gap: 4px;
    padding: 1px;
    border: 1px solid #aab5c4;
    border-radius: 5px;
    background: #e6ebf2;
}
#search-input { width: 90px; min-width: 0; flex: 1; }
.search-actions { display: flex; align-items: stretch; gap: 2px; padding-left: 4px; border-left: 1px solid #aab5c4; }
.jump-controls { display: flex; flex: 1 1 auto; flex-wrap: wrap; gap: 4px; align-items: center; }
.visual-settings-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.visual-settings-grid > button { min-width: 0; }
.controls-help { align-self: stretch; padding-left: 8px; border-left: 1px solid #aeb5bf; display: flex; align-items: flex-start; padding-top: 16px; }
#controls #help-button { padding: 7px 8px; border: 1px solid #7287a3; border-radius: 7px; background: #edf3fc; color: #26456c; font-weight: 600; }
@media (min-width: 1580px) { #controls { height: 118px; } }
@media (min-width: 801px) and (max-width: 1080px) { #controls { height: 194px; } }
@media (min-width: 601px) and (max-width: 800px) {
    #controls { height: 232px; grid-template-columns: minmax(0, 1fr) 90px; grid-template-rows: auto auto auto; }
    .navigation-controls { grid-column: 1; grid-row: 1; }
    .visual-controls { grid-column: 1; grid-row: 2; }
    .controls-help { grid-column: 2; grid-row: 1 / 3; }
}

#controls.input-mode {
    background: #ccc;
}

#controls.collapsed {
    display: none;
}

/* Results belong to the controls, even when their inline display is set. */
.controls-collapsed #search-results {
    display: none !important;
}

#controls select,
#controls button,
#controls input {
    font-size: 13px;
    padding: 1px 4px;
    line-height: 16px;
    font-family: inherit;
    box-sizing: border-box;
}

#controls button {
    appearance: none;
    border: 1px solid #9398a1;
    border-radius: 3px;
    color: inherit;
    background: #f1f2f4;
    cursor: pointer;
}

#controls #data-timestamp span {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}

#controls button:disabled {
    opacity: 0.42;
    cursor: default;
}

#panel-links {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9;
}
#panel-links path { fill: none; stroke: #555; stroke-width: 1.5; stroke-dasharray: 3 3; }
.night-mode #panel-links path { stroke: #b9bdc6; }

#performance-window {
    position: fixed;
    z-index: 8;
    pointer-events: none;
    padding: 9px 12px;
    border: 1px solid #9998;
    border-radius: 7px;
    background: rgba(240, 240, 240, 0.82);
    color: #222;
    font: 12px/1.5 sans-serif;
    font-variant-numeric: tabular-nums;
}
#performance-window[hidden] { display: none; }
#performance-window dl { display: grid; grid-template-columns: auto auto; gap: 0 12px; margin: 0; }
#performance-window dd { margin: 0; text-align: right; }
.night-mode #performance-window { background: rgba(37, 39, 44, 0.82); color: #f4f4f4; }
.role-history-note, .role-first-appearance { font-size: 13px; line-height: 1.4; margin-top: 4px; }
.role-history-heading { font-size: 15px; padding-top: 10px; border-top: 1px solid #9998; }
.compact-panels .info-window { font-size: 16px; }

.viz-control-group {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0 6px;
    min-width: 0;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.45);
    border-radius: 4px;
}
.viz-control-group label, .viz-control-group span { font-size: 11px; line-height: 13px; white-space: nowrap; }
.viz-control-group span { grid-column: 2; grid-row: 1; }
#controls .viz-control-group input[type="range"] { grid-column: 1 / -1; grid-row: 2; width: 100%; min-width: 0; height: 12px; margin: 0; padding: 0; }

@media (max-width: 600px) {
    header h1 { font-size: clamp(20px, 5.9vw, 24px); }
    #current-ministry { font-size: 18px; }
    #toggle-controls-button { max-width: 95px; min-height: 44px; }
    #controls { height: 522px; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto auto; gap: 6px; }
    #controls label, #controls select, #controls button, #controls input { box-sizing: border-box; min-width: 0; }
    #controls select, #controls button, #controls input { padding: 3px 4px; min-height: 28px; }
    .navigation-primary { flex-wrap: wrap; }
    .ministry-choice { flex-basis: 100%; }
    #sunshine-toggle { width: 100%; }
    .search-controls { flex-basis: 100%; display: grid; grid-template-columns: minmax(0, 1fr); }
    #search-input { width: 100%; }
    .search-actions { padding: 3px 0 0; border-left: 0; border-top: 1px solid #aab5c4; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
    .jump-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .visual-settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .controls-help { padding: 6px 0 0; border-left: 0; border-top: 1px solid #aeb5bf; justify-content: flex-end; }
    #controls #help-button { min-width: 88px; }
}
@media (max-width: 429px) { #controls { height: 538px; } }
@media (max-width: 389px) { #controls { height: 554px; } }
@media (max-width: 339px) { #controls { height: 604px; } }
@media (min-width: 601px) and (max-width: 700px) { #controls { height: 274px; } }

/* The tree container now fills the remaining vertical space */
#tree-container {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    overflow: auto;
    background: #fff;
}

/* Keep other CSS as before */
#tree-svg {
    display: block;
    min-width: 100%;
    min-height: 100%;
}

#help-window {
    box-sizing: border-box;
    width: min(600px, calc(100vw - 24px));
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    padding: 0;
    border: 1px solid #999;
    border-radius: 10px;
    background: #f0f0f0;
    color: #222;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
    overflow: hidden;
}

#help-window[open] {
    display: flex;
    flex-direction: column;
}

#help-window::backdrop {
    background: rgba(0, 0, 0, 0.25);
}

#help-close {
    background: #c33;
    color: #fff;
    border: 0;
    border-radius: 3px;
    min-width: 44px;
    min-height: 44px;
    font-size: 24px;
    cursor: pointer;
}

.help-content {
    padding: 0 18px 18px;
    overflow-y: auto;
    overscroll-behavior: contain;
    line-height: 1.5;
}

.help-content li + li {
    margin-top: 8px;
}

.node-legend {
    border-top: 1px solid #ccc;
}

.node-legend h2 {
    font-size: 18px;
}

.node-legend p {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.legend-node {
    flex: 0 0 70px;
    padding: 7px 0;
    color: #fff;
    text-align: center;
    border-radius: 4px;
}

.legend-standard { background: #4285f4; }
.legend-agency { background: #34a853; }
.legend-vacant { background: #c33; }

.link {
    fill: none;
    stroke: #888;
    stroke-width: 2px;
}

.window-link {
    fill: none;
    stroke: #555;
    stroke-width: 1.5px;
    stroke-dasharray: 3,3;
}

.node rect {
    cursor: pointer;
    stroke: #fff;
    stroke-width: 1px;
    rx: 8px;
    ry: 8px;
}

.node text {
    font: 16px sans-serif;
    fill: #fff;
    text-anchor: middle;
    dominant-baseline: central;
}

.info-window {
    font-size: 18px;
    font-family: sans-serif;
    background: #f0f0f0;
    border: 1px solid #999;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

.info-window-header, .help-header {
    background: #003399;
    color: #fff;
    padding: 12px 14px;
    font-weight: bold;
    cursor: move;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.help-header { cursor: default; }

.info-window-title {
    min-width: 0;
    overflow-wrap: anywhere;
}

.info-window-content {
    padding: 14px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    cursor: auto;
    white-space: normal;
    word-wrap: break-word;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
}

.info-window-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.info-window-toolbar label {
    font-size: 14px;
    font-weight: 600;
}

.info-window-toolbar select {
    font-size: 14px;
    padding: 4px 6px;
}

.info-window-section-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 6px;
}

.info-window-role-entry {
    margin-bottom: 10px;
}

.info-window-role-line {
    line-height: 1.35;
}

.info-window-role-line-detail {
    padding-left: 14px;
}

/* For Webkit browsers (Chrome, Edge, Safari) */
.info-window-content::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.info-window-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.08);
}

.info-window-content::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
}

.info-window-footer {
    padding: 10px 14px;
    background: #ddd;
    text-align: right;
    flex-shrink: 0;
}

.info-window-link a {
    color: #003399;
    text-decoration: underline;
}

.info-window-close-btn {
    flex: 0 0 auto;
    background: #c33;
    color: #fff;
    border: none;
    border-radius: 3px;
    padding: 2px 5px;
    cursor: pointer;
}

/* This panel is outside the SVG so panning and zooming cannot move it. */
.info-window-mobile {
    position: fixed;
    z-index: 10;
    left: 0;
    right: 0;
    bottom: 0;
    box-sizing: border-box;
    width: 100%;
    height: min(56vh, 540px);
    height: min(56dvh, 540px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border-radius: 14px 14px 0 0;
    font-size: 16px;
}

.info-window-mobile .info-window-header {
    cursor: default;
    padding: 8px max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px));
    max-height: 35%;
    box-sizing: border-box;
}

.info-window-reporting-caution {
    margin-bottom: 10px;
    padding: 10px 12px;
    border-left: 4px solid #995500;
    background: #fff4d4;
    color: #5c3c00;
    font-size: 13px;
    line-height: 1.4;
    white-space: pre-line;
}

.info-window-mobile .info-window-title {
    max-height: 100%;
    overflow-y: auto;
}

.info-window-mobile .info-window-close-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 20px;
}

.info-window-mobile .info-window-content {
    padding: 12px max(14px, env(safe-area-inset-right, 0px)) 12px max(14px, env(safe-area-inset-left, 0px));
    touch-action: pan-y;
}

.info-window-mobile .info-window-toolbar select {
    font-size: 16px;
    min-height: 44px;
    max-width: 100%;
}

.info-window-mobile .info-window-footer,
.info-window-mobile .resize-handle {
    display: none;
}

.resize-handle {
    position: absolute;
    width: 16px;
    height: 16px;
    background: #333;
    bottom: 0;
    right: 0;
    cursor: nwse-resize;
}

/* Added styles for search results */
#search-results {
    background: #eee;
    padding: 10px;
    display: none;
    min-height: 100px;
    max-height: 300px;
    overflow: auto;
    box-sizing: border-box;
}

#search-results table {
    width: 100%;
    border-collapse: collapse;
}

#search-results th, #search-results td {
    border: 1px solid #999;
    padding: 4px;
    font-size: 12px;
    cursor: pointer;
}

#search-results .highlight {
    background: #ff0;
}

#loading-container {
    flex: 0 0 auto;
    box-sizing: border-box;
    width: 100%;
    padding: 12px 16px 16px;
    background: #eaf1ff;
    border-bottom: 1px solid #bdcfee;
}

.loading-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    color: #173d80;
    font-size: 15px;
    font-weight: 600;
}

.loading-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #bdcfee;
    border-top-color: #245bc1;
    border-radius: 50%;
    animation: loading-spin 1.2s linear infinite;
}

#loading-track {
    height: 36px;
    background: #cbd9ef;
    border-radius: 6px;
    overflow: hidden;
}

#loading-bar {
    width: 0%;
    height: 100%;
    background: #245bc1;
    border-radius: inherit;
    transition: width 0.2s ease;
}

.is-indeterminate #loading-bar {
    width: 35%;
    animation: loading-travel 2s ease-in-out infinite alternate;
}

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

@keyframes loading-travel {
    to { transform: translateX(185%); }
}

@media (prefers-reduced-motion: reduce) {
    .loading-spinner,
    #loading-bar,
    .is-indeterminate #loading-bar {
        animation: none;
        transition: none;
    }
}

.show-chart-button {
    padding: 7px 12px;
    margin-bottom: 12px;
    font-size: 14px;
    cursor: pointer;
}

#history-window {
    position: fixed;
    z-index: 11;
    top: var(--history-top, 90px);
    right: 12px;
    bottom: 12px;
    width: calc(50% - 18px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    background: #f0f0f0;
    color: #222;
    border: 1px solid #999;
    border-radius: 10px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
    overflow: hidden;
}

#history-window[hidden] { display: none; }

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex: 0 0 auto;
    padding: 8px 14px;
    background: #003399;
    color: #fff;
    font-weight: bold;
}

#history-close {
    min-width: 44px;
    min-height: 44px;
    font-size: 24px;
    color: #fff;
    background: #c33;
    border: 0;
    border-radius: 3px;
    cursor: pointer;
}

.history-content {
    overflow: auto;
    min-height: 0;
    padding: 0 14px 14px;
    overscroll-behavior: contain;
    font-size: 14px;
    line-height: 1.4;
}

#history-node-name { font-weight: 600; overflow-wrap: anywhere; }
.history-compact #history-node-name { display: none; }
.history-compact .history-toolbar { margin: 8px 0; }
.history-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.history-toolbar select { min-width: 0; max-width: 100%; padding: 6px; font-size: 14px; }
#history-plot svg { display: block; width: 100%; overflow: visible; }
.history-line { fill: none; stroke: #245bc1; stroke-width: 2.5px; }
.history-point { fill: #245bc1; stroke: #fff; stroke-width: 1.5px; cursor: pointer; }
.history-point:focus { stroke: #111; stroke-width: 3px; outline: none; }
.history-axis { color: #444; }
.history-axis text, .history-axis-label { fill: currentColor; font: 11px sans-serif; }
.history-grid { color: #d0d0d0; }
#history-readout { min-height: 20px; }
.history-note { font-size: 12px; color: #555; }
#history-values summary { cursor: pointer; padding: 8px 0; }
#history-values table { width: 100%; border-collapse: collapse; }
#history-values th, #history-values td { padding: 6px; border-bottom: 1px solid #aaa; text-align: left; }

.info-window-docked,
.history-open .info-window-mobile {
    position: fixed;
    z-index: 10;
    top: var(--history-top, 90px);
    left: 12px;
    right: auto;
    bottom: 12px;
    width: calc(50% - 18px);
    height: auto;
    box-sizing: border-box;
    border-radius: 10px;
    font-size: 16px;
}

.info-window-docked .info-window-header { cursor: default; }
.info-window-docked .info-window-footer, .info-window-docked .resize-handle { display: none; }
.info-window-docked .info-window-close-btn { min-width: 44px; min-height: 44px; font-size: 20px; }
.history-open .page-container.mobile-info-open { padding-bottom: 0; }

@media (max-width: 600px) {
    #history-window {
        top: var(--history-top, 90px);
        left: 8px;
        right: 8px;
        bottom: calc((100dvh - var(--history-top, 90px)) * 0.48 + 12px);
        width: auto;
    }
    .history-open .info-window-mobile {
        top: calc(var(--history-top, 90px) + (100dvh - var(--history-top, 90px)) * 0.52);
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
    }
    .history-open .info-window-mobile .info-window-header { max-height: 40%; }
    .history-toolbar select { font-size: 16px; min-height: 44px; }
}

/* Night Mode starts off and follows the toggle for this page session. */
body.night-mode {
    color-scheme: dark;
    background: #202124;
    color: #f4f4f4;
}
.night-mode #tree-container { background: #000; }
.night-mode #controls, .night-mode .info-window-footer { background: #292b30; }
.night-mode #controls.input-mode { background: #34363c; }
.night-mode .viz-control-group { background: #35373d; }
.night-mode #data-timestamp, .night-mode .history-note { color: #c5c7ce; }
.night-mode button, .night-mode input, .night-mode select { color: #f4f4f4; background-color: #35373d; border: 1px solid #747780; border-radius: 4px; }
.night-mode input[type="range"], .night-mode #controls-toggle { border: 0; }
.night-mode #controls-toggle { background: none; }
.night-mode #controls button[aria-pressed="true"] { background: #304364; border-color: #7c9ac6; }
.night-mode #search-results, .night-mode .info-window, .night-mode #help-window, .night-mode #history-window { background: #25272c; color: #f4f4f4; border-color: #747780; }
.night-mode #search-results .highlight { background: #66521b; }
.night-mode .info-window-header, .night-mode .help-header, .night-mode .history-header { background: #263954; }
.night-mode .info-window-close-btn, .night-mode #help-close, .night-mode #history-close { background: #962e35; }
.night-mode .info-window-link a { color: #a2c2ff; }
.night-mode .info-window-reporting-caution { background: #3b3322; color: #f1dca6; border-color: #b8954d; }
.night-mode .resize-handle { background: #aaa; }
.night-mode .info-window-content::-webkit-scrollbar-thumb { background: #888; }
.night-mode #loading-container { background: #252c38; border-color: #475875; }
.night-mode .loading-status { color: #c3d5f6; }
.night-mode #loading-track { background: #3a4354; }
.night-mode .ministry-link, .night-mode .agency-link, .night-mode .window-link { stroke: #a4a8b0; }
.night-mode .ministry-node rect[fill="#4285f4"] { fill: #2c5ea9; filter: drop-shadow(0 0 2px #639cf5); }
.night-mode .ministry-node rect[fill="#c33"] { fill: #9e3036; filter: drop-shadow(0 0 2px #ed747b); }
.night-mode .agency-node rect { fill: #24753d; filter: drop-shadow(0 0 2px #62c47e); }
.night-mode .legend-standard { background: #2c5ea9; box-shadow: 0 0 4px #639cf5; }
.night-mode .legend-agency { background: #24753d; box-shadow: 0 0 4px #62c47e; }
.night-mode .legend-vacant { background: #9e3036; box-shadow: 0 0 4px #ed747b; }
.night-mode .history-line { stroke: #8ab4ff; }
.night-mode .history-point { fill: #8ab4ff; stroke: #25272c; }
.night-mode .history-point:focus { stroke: #fff; }
.night-mode .history-axis { color: #ddd; }
.night-mode .history-grid { color: #484b53; }
.night-mode :focus-visible { outline: 2px solid #a2c2ff; outline-offset: 2px; }

.night-mode .controls-group { background: #303238; border-color: #565c67; }
.night-mode #controls button { background: #35373d; color: #f4f4f4; border-color: #747780; }
.night-mode .controls-group h2 { color: #c0cad9; }
.night-mode .controls-group h2::after, .night-mode .controls-help { border-color: #565c67; }
.night-mode .search-controls { background: #293545; border-color: #637185; }
.night-mode .search-actions { border-color: #637185; }
.night-mode #controls #help-button { background: #30415b; color: #e0ebff; border-color: #8096b6; }

/* Chart interaction and screensaver controls retain the Controls height budget. */
header { cursor: pointer; }
.controls-help { flex-direction: column; gap: 6px; padding-top: 0; align-items: center; }
#controls #screensaver-toggle { width: 100%; padding: 5px 3px; border: 1px solid #7988a4; border-radius: 8px; background: #e4e9f5; color: #263954; font-size: 12px; line-height: 16px; }
#controls #screensaver-toggle[aria-pressed="true"] { background: #cbd9f5; border-color: #245bc1; }
.night-mode #controls #screensaver-toggle { color: #f4f4f4; background: #283951; border-color: #8194b2; }
@media (max-width: 600px) {
    .controls-help { flex-direction: row; }
    #controls #screensaver-toggle { width: auto; min-width: 125px; }
}
.info-window { box-sizing: border-box; }
.info-window-header, .history-header { touch-action: none; user-select: none; cursor: move; }
.info-window-docked .info-window-header, .info-window-mobile .info-window-header { cursor: move; }
.info-window-docked .resize-handle, .info-window-mobile .resize-handle { display: block; }
.resize-handle { touch-action: none; z-index: 2; opacity: .65; }
.resize-handle-left { left: 0; right: auto; cursor: nesw-resize; }
#history-title { font-size: 14px; line-height: 1.25; overflow-wrap: anywhere; }
.history-header { min-height: 44px; }
#history-node-name { display: none; }
.history-toolbar { margin: 10px 0; }
#history-bounds { padding: 6px; font-size: 13px; }
.performance-clock { margin-top: 4px !important; padding-top: 4px; border-top: 1px solid #8886; }
.screensaver-mode .info-window, .screensaver-mode #history-window, .screensaver-mode #panel-links {
    opacity: .65; transition: opacity .4s ease;
}
.screensaver-mode #current-ministry { opacity: .65; }
.screensaver-mode.screensaver-fading .info-window, .screensaver-mode.screensaver-fading #history-window,
.screensaver-mode.screensaver-fading #panel-links { opacity: 0; }
@media (prefers-reduced-motion: reduce) {
    .screensaver-mode .info-window, .screensaver-mode #history-window, .screensaver-mode #panel-links,
    #current-ministry { transition-duration: .01s; }
}

/* Nine visual settings fit within the existing two-row wide-screen footprint. */
@media (min-width: 601px) {
    .visual-settings-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (min-width: 1580px) {
    #controls .visual-settings-grid > button { font-size: 12px; line-height: 14px; padding: 1px 3px; }
}
@media (min-width: 1580px) {
    .visual-controls { padding: 2px 5px; }
    .visual-controls h2 { margin-bottom: 2px; }
    .visual-settings-grid { gap: 2px 4px; }
}
@media (min-width: 801px) and (max-width: 1200px) {
    .visual-settings-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.default-role-control {
    grid-column: span 2;
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    padding: 1px 4px;
    border: 1px solid #aaa;
    border-radius: 4px;
    background: rgba(255, 255, 255, .35);
}
#controls .default-role-control label { font-size: 12px; line-height: 14px; white-space: nowrap; }
#controls #default-role-sort { flex: 1; width: 0; min-width: 0; max-width: 100%; appearance: auto; }
.night-mode .default-role-control { background: #35373d; border-color: #747780; }
@media (max-width: 1200px) {
    .default-role-control { grid-column: auto; flex-direction: column; align-items: stretch; gap: 1px; padding: 1px 3px; }
    #controls #default-role-sort { width: 100%; flex: none; }
}
@media (min-width: 601px) and (max-width: 800px) {
    .default-role-control { grid-column: span 2; }
}
