@media (prefers-color-scheme: dark) {
    /* Override buildbot CSS variables for sidebar - keeping blue tones */
    :root {
      --bb-sidebar-background-color: #1e2a3a !important;
      --bb-sidebar-header-background-color: #15202b !important;
      --bb-sidebar-header-text-color: #e7f0ff !important;
      --bb-sidebar-title-text-color: #6b8cbe !important;
      --bb-sidebar-footer-background-color: #15202b !important;
      --bb-sidebar-button-text-color: #a3b9d9 !important;
      --bb-sidebar-button-hover-background-color: #2a3e54 !important;
      --bb-sidebar-button-hover-text-color: #ffffff !important;
      --bb-sidebar-button-current-background-color: #15202b !important;
      --bb-sidebar-button-current-text-color: #c5d7f0 !important;
      --bb-sidebar-stripe-hover-color: #ffa726 !important;
      --bb-sidebar-stripe-current-color: #ff8f00 !important;
    }

    /* Body and main content */
    body {
      background-color: #0d1117 !important;
      color: #d0d7de !important;
    }

    #root {
      background-color: #0d1117 !important;
      color: #d0d7de !important;
    }

    /* Main content area */
    .gl-page-with-sidebar > .content {
      background-color: #0d1117 !important;
    }

    /* Fix garbled/overlapping text in sidebar navigation */
    .gl-page-with-sidebar .sidebar ul li {
      position: relative !important;
      clear: both !important;
    }

    .gl-page-with-sidebar .sidebar ul li ul {
      display: none !important;
    }
    .gl-page-with-sidebar .sidebar ul li.current ul,
    .gl-page-with-sidebar .sidebar ul li.expanded ul {
      display: block !important;
    }

    .gl-page-with-sidebar .sidebar .bb-sidebar-item {
      display: block !important;
      overflow: hidden !important;
      text-overflow: ellipsis !important;
      white-space: nowrap !important;
    }


    /* Panels and Cards */
    .panel,
    .panel-default,
    .panel-heading,
    .panel-body,
    .panel-footer {
      background-color: #161b22 !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    .panel-title {
      color: #d0d7de !important;
    }

    /* Section headers (like "Janitor", "macOS-Sonoma-Release-Build-EWS") */
    .panel-heading,
    .card-header {
      background-color: #1f4662 !important;
      color: #e7f0ff !important;
      border-color: #30363d !important;
    }

    /* Cards (React components) */
    .card {
      background-color: #161b22 !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    .card-body,
    .card-footer {
      background-color: #161b22 !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    /* Tables */
    .table {
      background-color: #161b22 !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    .table th,
    .table td {
      background-color: #161b22 !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    .table-striped tbody tr:nth-of-type(odd) {
      background-color: #1c2128 !important;
    }

    .table-striped tbody tr:nth-of-type(even) {
      background-color: #161b22 !important;
    }

    .table-hover tbody tr:hover {
      background-color: #1f4662 !important;
      color: #ffffff !important;
    }

    /* Navigation and Breadcrumbs */
    .navbar {
      background-color: #161b22 !important;
      border-color: #30363d !important;
      color: #d0d7de !important;
    }

    .navbar-default {
      background-color: #161b22 !important;
      border-color: #30363d !important;
    }

    .navbar-default .navbar-nav > li > a {
      color: #58a6ff !important;
    }

    .navbar-default .navbar-nav > li > a:hover,
    .navbar-default .navbar-nav > li > a:focus {
      color: #79c0ff !important;
      background-color: #1f4662 !important;
    }

    .navbar-brand {
      color: #ffffff !important;
    }

    .breadcrumb {
      background-color: #161b22 !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    .breadcrumb > li + li:before {
      color: #6e7681 !important;
    }

    /* Forms and Inputs */
    .form-control,
    input,
    textarea,
    select,
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="number"],
    input[type="search"] {
      background-color: #0d1117 !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    .form-control:focus,
    input:focus,
    textarea:focus,
    select:focus {
      background-color: #161b22 !important;
      color: #ffffff !important;
      border-color: #58a6ff !important;
      outline: 0 !important;
      box-shadow: 0 0 0 0.2rem rgba(88, 166, 255, 0.3) !important;
    }

    .form-control::placeholder {
      color: #6e7681 !important;
    }

    .form-group label {
      color: #d0d7de !important;
    }

    /* Custom select styling */
    .custom-select {
      background-color: #0d1117 !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    /* Buttons */
    .btn {
      border-color: #30363d !important;
    }

    .btn-default,
    .btn-light {
      background-color: #21262d !important;
      color: #c9d1d9 !important;
      border-color: #6e7681 !important;
      border-width: 1px !important;
      border-style: solid !important;
    }

    .btn-default:hover,
    .btn-light:hover,
    .btn-default:focus,
    .btn-light:focus {
      background-color: #30363d !important;
      color: #ffffff !important;
      border-color: #484f58 !important;
    }

    .btn-primary {
      background-color: #1f6feb !important;
      border-color: #1f6feb !important;
    }

    .btn-primary:hover,
    .btn-primary:focus {
      background-color: #388bfd !important;
      border-color: #388bfd !important;
    }

    .btn-secondary {
      background-color: #373e47 !important;
      border-color: #373e47 !important;
    }

    .btn-secondary:hover,
    .btn-secondary:focus {
      background-color: #484f58 !important;
      border-color: #484f58 !important;
    }

    /* Links */
    a {
      color: #58a6ff !important;
    }

    a:hover,
    a:focus {
      color: #79c0ff !important;
      text-decoration: underline !important;
    }

    /* Modals */
    .modal-content {
      background-color: #161b22 !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    .modal-header {
      background-color: #0d1117 !important;
      color: #d0d7de !important;
      border-bottom-color: #30363d !important;
    }

    .modal-body {
      background-color: #161b22 !important;
      color: #d0d7de !important;
    }

    .modal-footer {
      background-color: #0d1117 !important;
      border-top-color: #30363d !important;
    }

    .modal-title {
      color: #d0d7de !important;
    }

    .close {
      color: #d0d7de !important;
      opacity: 0.8 !important;
    }

    .close:hover {
      color: #ffffff !important;
      opacity: 1 !important;
    }

    /* Alerts */
    .alert {
      border-color: #30363d !important;
    }

    .alert-info {
      background-color: #0c2d6b !important;
      color: #79c0ff !important;
      border-color: #1f6feb !important;
    }

    .alert-warning {
      background-color: #4d2d00 !important;
      color: #f0b72f !important;
      border-color: #bb8009 !important;
    }

    .alert-danger,
    .alert-error {
      background-color: #490202 !important;
      color: #ff7b72 !important;
      border-color: #da3633 !important;
    }

    .alert-success {
      background-color: #033a16 !important;
      color: #7ee787 !important;
      border-color: #2ea043 !important;
    }

    /* List groups */
    .list-group-item {
      background-color: #161b22 !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    .list-group-item:hover,
    .list-group-item:focus {
      background-color: #1c2128 !important;
      color: #ffffff !important;
    }

    /* Dropdowns */
    .dropdown-menu {
      background-color: #161b22 !important;
      border-color: #30363d !important;
    }

    .dropdown-item {
      color: #d0d7de !important;
    }

    .dropdown-item:hover,
    .dropdown-item:focus {
      background-color: #1c2128 !important;
      color: #ffffff !important;
    }

    .dropdown-divider {
      border-top-color: #30363d !important;
    }

    /* Tabs */
    .nav-tabs {
      border-bottom-color: #30363d !important;
    }

    .nav-tabs .nav-link {
      color: #8b949e !important;
      background-color: #0d1117 !important;
      border-color: #30363d !important;
    }

    .nav-tabs .nav-link:hover,
    .nav-tabs .nav-link:focus {
      color: #d0d7de !important;
      background-color: #161b22 !important;
      border-color: #30363d !important;
    }

    .nav-tabs .nav-link.active {
      color: #ffffff !important;
      background-color: #0d1117 !important;
      border-color: #30363d #30363d transparent !important;
    }

    /* Pager */
    .pager li > a,
    .pager li > span {
      background-color: #21262d !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    .pager li > a:hover,
    .pager li > a:focus {
      background-color: #30363d !important;
      color: #ffffff !important;
    }

    .pager .disabled > a,
    .pager .disabled > span {
      color: #6e7681 !important;
      background-color: #161b22 !important;
    }

    /* Build navigation buttons (Previous/Next) - fix contrast */
    li.previous a.bb-build-view-nav-button,
    li.next a.bb-build-view-nav-button {
      background-color: #21262d !important;
      color: #d0d7de !important;
      border-color: #6e7681 !important;
    }

    li.previous a.bb-build-view-nav-button:hover,
    li.next a.bb-build-view-nav-button:hover {
      background-color: #30363d !important;
      color: #ffffff !important;
      text-decoration: none !important;
    }

    li.next.disabled span.bb-build-view-nav-button {
      background-color: #161b22 !important;
      color: #6e7681 !important;
      opacity: 0.6 !important;
    }

    /* Tooltips */
    .tooltip-inner {
      background-color: #21262d !important;
      color: #d0d7de !important;
    }

    .tooltip.bs-tooltip-top .arrow::before {
      border-top-color: #21262d !important;
    }

    .tooltip.bs-tooltip-bottom .arrow::before {
      border-bottom-color: #21262d !important;
    }

    .tooltip.bs-tooltip-start .arrow::before {
      border-left-color: #21262d !important;
    }

    .tooltip.bs-tooltip-end .arrow::before {
      border-right-color: #21262d !important;
    }

    /* Popovers */
    .popover {
      background-color: #161b22 !important;
      border-color: #30363d !important;
    }

    .popover-header {
      background-color: #0d1117 !important;
      color: #d0d7de !important;
      border-bottom-color: #30363d !important;
    }

    .popover-body {
      color: #d0d7de !important;
    }

    /* Build status badges - keep original colors, they work well */
    .bb-badge-round.results_SUCCESS,
    .bb-badge-status.results_SUCCESS {
      background-color: #238636 !important;
      color: #ffffff !important;
    }

    .bb-badge-round.results_WARNINGS,
    .bb-badge-status.results_WARNINGS {
      background-color: #bb8009 !important;
      color: #000000 !important;
    }

    .bb-badge-round.results_FAILURE,
    .bb-badge-status.results_FAILURE {
      background-color: #da3633 !important;
      color: #ffffff !important;
    }

    .bb-badge-round.results_SKIPPED,
    .bb-badge-status.results_SKIPPED {
      background-color: #6e7681 !important;
      color: #ffffff !important;
    }

    /* Text colors */
    .text-muted {
      color: #8b949e !important;
    }

    .text-primary {
      color: #58a6ff !important;
    }

    .text-success {
      color: #3fb950 !important;
    }

    .text-info {
      color: #79c0ff !important;
    }

    .text-warning {
      color: #d29922 !important;
    }

    .text-danger {
      color: #f85149 !important;
    }

    /* Code blocks and pre-formatted text */
    code {
      background-color: rgba(110, 118, 129, 0.4) !important;
      color: #ff7b72 !important;
      border: 1px solid #30363d !important;
    }

    pre {
      background-color: #161b22 !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    pre code {
      background-color: transparent !important;
      border: none !important;
    }

    /* Log lines */
    .logline {
      background-color: #161b22 !important;
      color: #d0d7de !important;
      border-color: #30363d !important;
    }

    /* Pagination */
    .pagination .page-link {
      background-color: #21262d !important;
      color: #58a6ff !important;
      border-color: #30363d !important;
    }

    .pagination .page-link:hover {
      background-color: #30363d !important;
      color: #79c0ff !important;
      border-color: #484f58 !important;
    }

    .pagination .page-item.active .page-link {
      background-color: #1f6feb !important;
      border-color: #1f6feb !important;
      color: #ffffff !important;
    }

    .pagination .page-item.disabled .page-link {
      background-color: #161b22 !important;
      color: #6e7681 !important;
      border-color: #30363d !important;
    }

    /* Progress bars */
    .progress {
      background-color: #21262d !important;
    }

    /* Wells */
    .well {
      background-color: #161b22 !important;
      border-color: #30363d !important;
      color: #d0d7de !important;
    }

    /* Horizontal rules */
    hr {
      border-top-color: #30363d !important;
    }

    /* Change details */
    .changedetails {
      background-color: #161b22 !important;
      color: #d0d7de !important;
    }

    .changedetails-heading {
      color: #d0d7de !important;
    }

    /* Build summary */
    .buildsummary {
      background-color: #161b22 !important;
      color: #d0d7de !important;
    }

    /* Waterfall and console views */
    .waterfall-view,
    .console-view {
      background-color: #0d1117 !important;
      color: #d0d7de !important;
    }

    /* Property table */
    .property-table {
      background-color: #161b22 !important;
      color: #d0d7de !important;
    }

    /* Force scheduler forms */
    .force-scheduler-form {
      background-color: #161b22 !important;
    }

    /* Scrollbars (webkit browsers) */
    ::-webkit-scrollbar {
      width: 12px;
      height: 12px;
    }

    ::-webkit-scrollbar-track {
      background: #161b22;
    }

    ::-webkit-scrollbar-thumb {
      background: #30363d;
      border-radius: 6px;
    }

    ::-webkit-scrollbar-thumb:hover {
      background: #484f58;
    }

    /* Selection */
    ::selection {
      background-color: #1f6feb !important;
      color: #ffffff !important;
    }

    ::-moz-selection {
      background-color: #1f6feb !important;
      color: #ffffff !important;
    }
}
