/* GPSINOS theme selector only. The native WOX stylesheets own page colours. */
.gpsinos-theme-control {
    position: relative;
    line-height: 1;
}

.gpsinos-theme-control--header {
    z-index: 3;
    float: right;
    margin: 6px 6px 0 8px;
}

.gpsinos-theme-control--login {
    position: absolute;
    z-index: 2;
    top: 10px;
    right: 10px;
    text-align: right;
    margin: 0;
}

.gpsinos-theme-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    min-width: 32px;
    min-height: 32px;
    padding: 5px 9px;
    border: 1px solid #b6b6b6;
    border-radius: 5px;
    background: #ffffff;
    color: #353535;
    font: inherit;
    font-size: 12px;
    line-height: 20px;
    white-space: nowrap;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.gpsinos-theme-button:hover {
    background: #eeeeee;
    border-color: #777777;
}

.gpsinos-theme-button:focus {
    outline: 2px solid #cc7e1a;
    outline-offset: 2px;
}

.gpsinos-theme-icon {
    display: inline-block;
    width: 18px;
    font-size: 20px;
    line-height: 20px;
    text-align: center;
}

.gpsinos-theme-label {
    margin-left: 6px;
}

.gpsinos-theme-status {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

html[data-gpsinos-theme="dark"] .gpsinos-theme-button {
    border-color: #777777;
    background: #333333;
    color: #f2f2f2;
}

html[data-gpsinos-theme="dark"] .gpsinos-theme-button:hover {
    border-color: #aaaaaa;
    background: #454545;
}

/* Keep explicit status text meaningful on native dark panels. */
html[data-gpsinos-theme="dark"] .text-success {
    color: #6ed49a !important;
}

html[data-gpsinos-theme="dark"] .text-danger {
    color: #ff9494 !important;
}

html[data-gpsinos-theme="dark"] .text-warning {
    color: #f5cb7a !important;
}

html[data-gpsinos-theme="dark"] .text-info {
    color: #86d1eb !important;
}

/* Native modal close actions need readable text on their dark surfaces. */
html[data-gpsinos-theme="dark"] .modal .close:not(.disabled):not(:disabled) {
    color: #f2f2f2 !important;
    opacity: .8;
    text-shadow: none;
}

html[data-gpsinos-theme="dark"] .modal .close:not(.disabled):not(:disabled):hover,
html[data-gpsinos-theme="dark"] .modal .close:not(.disabled):not(:disabled):focus {
    opacity: 1;
}

html[data-gpsinos-theme="dark"] .modal .btn-default:not(.active):not(.disabled):not(:disabled) {
    color: #f2f2f2 !important;
}

/* Keep the configured login photo/logo, with a readable dark form surface. */
html[data-gpsinos-theme="dark"] body.sign-in-layout .panel {
    background-color: #222222 !important;
    color: #f2f2f2;
}

html[data-gpsinos-theme="dark"] body.sign-in-layout .panel-background {
    background-color: #222222 !important;
}

html[data-gpsinos-theme="dark"] body.sign-in-layout .panel-body,
html[data-gpsinos-theme="dark"] body.sign-in-layout .panel-body label,
html[data-gpsinos-theme="dark"] body.sign-in-layout .panel-body .help-block {
    color: #f2f2f2;
}

html[data-gpsinos-theme="dark"] body.sign-in-layout .panel-body .btn-default:not(.active):not(.disabled):not(:disabled) {
    color: #f2f2f2 !important;
}

.gpsinos-theme-control[data-state="loading"] .gpsinos-theme-button {
    cursor: progress;
    opacity: .75;
}

.gpsinos-theme-control[data-state="error"] .gpsinos-theme-button {
    border-color: #b84537;
}

@media (max-width: 1199px) {
    .gpsinos-theme-control--header .gpsinos-theme-label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .gpsinos-theme-control--header .gpsinos-theme-button {
        padding-left: 6px;
        padding-right: 6px;
    }
}

/* Dark-mode neutral text: a little lighter, with semantic colours retained. */
html[data-gpsinos-theme="dark"] body {
    color: #e8edf2;
}

/* Read-only fleet information; status chips and engine icons keep their colours. */
html[data-gpsinos-theme="dark"] #sidebar .group-list > li:not(.active):not(.disabled):not(.has-error):not([aria-disabled="true"]) > .name > [data-device="name"] {
    color: #e8edf2;
}

html[data-gpsinos-theme="dark"] #sidebar .group-list > li > .name [data-device="time"],
html[data-gpsinos-theme="dark"] #sidebar .group-list > li > .details [data-device="time"],
html[data-gpsinos-theme="dark"] #sidebar [data-device="speed"],
html[data-gpsinos-theme="dark"] .group-heading > .group-title.collapsed:not(.disabled):not([aria-disabled="true"]) {
    color: #c2cbd4;
}

html[data-gpsinos-theme="dark"] #sidebar .nav-tabs > li:not(.active):not(.disabled) > a:not(.disabled):not(.has-error):not([aria-disabled="true"]):not(:hover):not(:focus) {
    color: #c2cbd4;
}

/* Leave active/open navigation and its orange hover/focus treatment native. */
html[data-gpsinos-theme="dark"] #header .main-navbar .navbar-nav > li:not(.active):not(.open):not(.disabled) > a:not(.disabled):not([aria-disabled="true"]):not(:hover):not(:focus) {
    color: #e8edf2;
}

/* Values and prompts only on editable, enabled controls. */
html[data-gpsinos-theme="dark"] .form-control:not(.disabled):not(:disabled):not([readonly]):not([aria-disabled="true"]) {
    color: #e8edf2;
}

html[data-gpsinos-theme="dark"] .form-control:not(.disabled):not(:disabled):not([readonly]):not([aria-disabled="true"]):focus {
    color: #ffffff;
}

html[data-gpsinos-theme="dark"] .form-control:not(.disabled):not(:disabled):not([readonly]):not([aria-disabled="true"])::placeholder {
    color: #b3bec8;
    opacity: 1;
}

html[data-gpsinos-theme="dark"] .form-control:not(.disabled):not(:disabled):not([readonly]):not([aria-disabled="true"])::-webkit-input-placeholder {
    color: #b3bec8;
    opacity: 1;
}

html[data-gpsinos-theme="dark"] .form-control:not(.disabled):not(:disabled):not([readonly]):not([aria-disabled="true"])::-moz-placeholder {
    color: #b3bec8;
    opacity: 1;
}

html[data-gpsinos-theme="dark"] .form-control:not(.disabled):not(:disabled):not([readonly]):not([aria-disabled="true"]):-ms-input-placeholder {
    color: #b3bec8;
}

/* Neutral information immediately inside content panels, never button children. */
html[data-gpsinos-theme="dark"] .panel-body:not(.disabled):not([aria-disabled="true"]) > .text-muted:not(.disabled):not([aria-disabled="true"]),
html[data-gpsinos-theme="dark"] .modal-body:not(.disabled):not([aria-disabled="true"]) > .text-muted:not(.disabled):not([aria-disabled="true"]) {
    color: #c2cbd4;
}

html[data-gpsinos-theme="dark"] .form-group:not(.has-error):not(.has-warning):not(.has-success):not(.disabled):not([aria-disabled="true"]) > .text-muted:not(.disabled):not([aria-disabled="true"]) {
    color: #c2cbd4;
}

/* Normal enabled menu entries; selected, disabled and button variants stay native. */
html[data-gpsinos-theme="dark"] .dropdown-menu > li:not(.active):not(.disabled) > a:not(.active):not(.disabled):not(.btn):not([disabled]):not([aria-disabled="true"]):not([aria-current]) {
    color: #dce3ea;
}

html[data-gpsinos-theme="dark"] .dropdown-menu > li:not(.active):not(.disabled) > a:not(.active):not(.disabled):not(.btn):not([disabled]):not([aria-disabled="true"]):not([aria-current]):hover,
html[data-gpsinos-theme="dark"] .dropdown-menu > li:not(.active):not(.disabled) > a:not(.active):not(.disabled):not(.btn):not([disabled]):not([aria-disabled="true"]):not([aria-current]):focus {
    color: #e8edf2;
}

/* Table headings only on neutral rows/cells, including sticky headers. */
html[data-gpsinos-theme="dark"] .table.table-list > thead > tr:not(.active):not(.disabled):not(.success):not(.danger):not(.warning):not(.info):not(.text-success):not(.text-danger):not(.text-warning):not(.text-info) > th:not(.active):not(.disabled):not(.success):not(.danger):not(.warning):not(.info),
html[data-gpsinos-theme="dark"] .table.table-list > thead > tr:not(.active):not(.disabled):not(.success):not(.danger):not(.warning):not(.info):not(.text-success):not(.text-danger):not(.text-warning):not(.text-info) > td:not(.active):not(.disabled):not(.success):not(.danger):not(.warning):not(.info) {
    color: #dce3ea;
}

/* Standalone documents opt in explicitly; the marker also guards CSS failure. */
:root { --gpsinos-theme-document-ready: 1; }

.gpsinos-theme-control--floating {
    position: fixed;
    z-index: 1035;
    top: 12px;
    right: 58px;
    max-width: calc(100vw - 70px);
    margin: 0;
}

.gpsinos-theme-control--floating .gpsinos-theme-button {
    min-width: 44px;
    min-height: 44px;
}

html[data-gpsinos-surface="error"] .gpsinos-theme-control--floating {
    right: 12px;
}

.gpsinos-theme-control--document {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin: 12px 15px;
    font-family: Arial, sans-serif;
}

/* Admin has a different header from the map. Native themes own its surfaces. */
html[data-gpsinos-theme="dark"] body.admin-layout .header .navbar-main .navbar-nav > li:not(.active):not(.open):not(.disabled) > a:not(.disabled):not([aria-disabled="true"]):not(:hover):not(:focus) {
    color: #e8edf2;
}

html[data-gpsinos-theme="dark"] body.admin-layout #footer {
    color: #c2cbd4;
}

@media (max-width: 1199px) {
    .gpsinos-theme-control--floating .gpsinos-theme-label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
    .gpsinos-theme-control--floating .gpsinos-theme-button {
        padding-left: 6px;
        padding-right: 6px;
    }
}

/* Screen palette for documents which do not load the application stylesheet.
   Report data with explicit colours/backgrounds keep those semantic choices. */
@media screen {
    /* Only authored neutral black text in unpainted policy content is adapted.
       The manager leaves author backgrounds and other foreground hues intact. */
    html[data-gpsinos-theme="dark"] #policy .gpsinos-policy-neutral-text,
    html[data-gpsinos-theme="dark"] .gpsinos-theme-policy .modal-body .gpsinos-policy-neutral-text {
        color: #e8edf2;
    }

    html[data-gpsinos-theme="dark"]:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) body {
        color: #e8edf2;
        background-color: #222222;
    }

    html[data-gpsinos-theme="dark"]:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) a:not(.btn) {
        color: #cc7e1a;
    }

    html[data-gpsinos-theme="dark"]:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) a:not(.btn):hover,
    html[data-gpsinos-theme="dark"]:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) a:not(.btn):focus {
        color: #edaf56;
    }

    html[data-gpsinos-theme="dark"]:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) :is(table, .table, hr) {
        border-color: #555555;
    }

    html[data-gpsinos-theme="dark"]:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) .panel:not(.panel-success):not(.panel-danger):not(.panel-warning):not(.panel-info):not(.panel-primary):not([style*="background"]) {
        background-color: #2b2b2b;
        border-color: #555555;
    }

    html[data-gpsinos-theme="dark"]:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) .panel:not(.panel-success):not(.panel-danger):not(.panel-warning):not(.panel-info):not(.panel-primary) > :is(.panel-heading, .panel-footer):not([style*="background"]):not([style*="color"]) {
        color: #e8edf2;
        background-color: #333333;
        border-color: #555555;
    }

    html[data-gpsinos-theme="dark"]:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) table:not([style*="background"]):not([style*="color"]):not([bgcolor]) > tbody > tr:not(.active):not(.success):not(.danger):not(.warning):not(.info):not([style*="background"]):not([style*="color"]):not([bgcolor]) {
        background-color: #2b2b2b;
    }

    html[data-gpsinos-theme="dark"]:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) table:not([style*="background"]):not([style*="color"]):not([bgcolor]) > :is(thead, tfoot) > tr:not(.active):not(.success):not(.danger):not(.warning):not(.info):not([style*="background"]):not([style*="color"]):not([bgcolor]) > :is(td, th):not(.active):not(.success):not(.danger):not(.warning):not(.info):not([style*="background"]):not([style*="color"]):not([bgcolor]) {
        background-color: #333333;
    }

    html[data-gpsinos-theme="dark"]:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) table:not([style*="background"]):not([style*="color"]):not([bgcolor]) > :is(tbody, thead, tfoot) > tr:not([style*="background"]):not([bgcolor]) > :is(td, th):not([style*="background"]):not([bgcolor]) {
        border-color: #555555;
    }

    /* Legends with explicit black text retain their original white backing. */
    html[data-gpsinos-theme="dark"]:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) table:is([style*="color: #000"], [style*="color:#000"], [style*="color: black"], [style*="color:black"]):not([style*="background"]) {
        background-color: #ffffff;
    }

    html[data-gpsinos-theme="dark"]:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) :is(pre, code, kbd, samp):not([style*="background"]):not([style*="color"]) {
        color: #e8edf2;
        background-color: #333333;
    }
}

@media print {
    .gpsinos-theme-control { display: none !important; }

    html:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) {
        color-scheme: light !important;
    }

    html:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) body {
        color: #000000 !important;
        background-color: #ffffff !important;
    }

    /* Match the original Bootstrap print treatment over the dark text helpers. */
    html:is([data-gpsinos-surface="document"], [data-gpsinos-surface="report"], [data-gpsinos-surface="lookup"], [data-gpsinos-surface="error"]) :is(.text-success, .text-danger, .text-warning, .text-info) {
        color: #000000 !important;
    }
}

/* Keep the Admin mobile selector beside the navigation toggle. */
@media screen and (max-width: 767px) {
    body.admin-layout .header .navbar-main .navbar-header {
        position: relative;
    }

    body.admin-layout .header .navbar-main .navbar-header > .gpsinos-theme-control--header {
        position: absolute;
        top: 5.5px;
        right: 55px;
        float: none;
        margin: 0;
    }

    body.admin-layout .header .navbar-main .navbar-header > .navbar-brand {
        max-width: calc(100% - 140px);
    }

    body.admin-layout .header .navbar-main .navbar-brand img {
        max-width: 100%;
        height: auto;
    }
}

/* Keep the theme selector clear of horizontal logos on legacy public forms. */
@media screen {
    body.sign-in-layout .panel > .panel-body:not(.gpsinos-login-body) > a:first-of-type {
        display: block;
        padding-top: 48px;
    }
}
