/* Shared chrome and widgets. Load this after legacy CSS and before page-specific theme overrides. */

/* Theme picker styles also apply in Standard through the fallback values. */
.ui-theme-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    margin-inline-end: .5rem;
    border: 1px solid var(--ui-border, #79a7c9);
    border-radius: 50%;
    background: var(--ui-surface, #eaf5ff);
    color: var(--ui-accent, #225f8d);
    font-size: 1.1rem;
    cursor: pointer;
}

.ui-theme-trigger[hidden],
.ui-theme-options[hidden] {
    display: none;
}

.ui-theme-trigger:hover,
.ui-theme-trigger[aria-expanded="true"] {
    background: var(--ui-surface-hover, #d9ecfc);
}

.ui-theme-trigger:focus-visible,
.ui-theme-option:has(input:focus-visible) {
    outline: 2px solid var(--ui-focus, #175f97);
    outline-offset: 1px;
}

.tippy-box[data-theme~="ui-theme"] {
    background: var(--ui-surface, #fff);
    color: var(--ui-text, #193950);
    box-shadow: var(--ui-shadow, 0 4px 16px rgb(21 48 72 / 22%));
    border: 1px solid var(--ui-border, #79a7c9);
    border-radius: .65rem;
}

.tippy-box[data-theme~="ui-theme"] .tippy-content {
    padding: .35rem;
}

.ui-theme-option {
    position: relative;
    display: flex;
    align-items: center;
    gap: .6rem;
    box-sizing: border-box;
    min-width: 10rem;
    min-height: 38px;
    padding: .35rem .65rem;
    border-radius: .4rem;
    cursor: pointer;
}

.ui-theme-option:hover,
.ui-theme-option:has(input:checked) {
    background: var(--ui-surface-hover, #eaf5ff);
}

.ui-theme-option input {
    /* Make the whole row the native radio hit area and keep keyboard navigation. */
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: inherit;
}

.ui-theme-option-icon,
.ui-theme-option-check {
    color: var(--ui-accent, #225f8d);
}

.ui-theme-option-check {
    margin-inline-start: auto;
    visibility: hidden;
}

.ui-theme-option input:checked ~ .ui-theme-option-check {
    visibility: visible;
}

@media (max-width: 575.98px) {
    .ui-theme-trigger {
        /* Align with the legacy account button on the mobile header row. */
        margin-top: 10px;
    }
}

/* Workspace canvas, header, and footer */
html:is([data-ui-theme="dark"], [data-ui-theme="light"]),
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) body {
    background: var(--ui-page-bg);
    color: var(--ui-text);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(.atpai-header, .footer) {
    background: var(--ui-surface);
    color: var(--ui-text);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .atpai-header {
    border-bottom: 1px solid var(--ui-border);
}

/* Apply tint after the base header and footer surfaces. */
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(.section-heading-titles, [data-role="footer"]) {
    background-color: var(--ui-surface-tinted);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .section-heading-titles {
    border-block-end: 1px solid var(--ui-divider-subtle);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .section-heading-titles > div {
    color: var(--ui-text-muted);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) [data-role="footer"] {
    border-block-start: 1px solid var(--ui-divider-subtle);
}

/* Keep transparent brand images legible using a small backdrop behind each logo. */
html[data-ui-theme="dark"] .atpai-header .logotype-container img {
    background: var(--ui-brand-backdrop);
    border-radius: .35rem;
}

html[data-ui-theme="dark"] .atpai-header .app-version {
    color: #2e5371;
}

html[data-ui-theme="dark"] .footer .made-by-surveyors-for-surveyors {
    color: var(--ui-text-muted);
}

/* Header links and live bridge indicators */
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) #header-atpaicrm-link {
    /* The shared header sets this link's color with !important. */
    color: var(--ui-nav-text) !important;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(.header-admin-bridges-stats, #left-menu-admin-label) {
    background: var(--ui-surface-raised);
    color: var(--ui-text);
    border-color: var(--ui-border);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .central-stat-cell {
    border-color: var(--ui-border);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(.bridges-app-info-icon-cell, .faq-quick-link-block a) {
    color: var(--ui-link);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .bridge-app-activity-cell [data-role="online"] {
    background: var(--ui-success);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .bridge-app-activity-cell [data-role="offline"] {
    background: var(--ui-danger);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .bridge-app-activity-cell [data-role="pending"] {
    background: var(--ui-text-muted);
}

/* The authentication flow can prepend this notice above the header. */
html[data-ui-theme="dark"] .template-organization-banner {
    background: var(--ui-surface-raised);
    color: var(--ui-text);
    border-color: var(--ui-border);
}

html[data-ui-theme="dark"] .template-organization-banner-copy p {
    color: var(--ui-text-muted);
}

html[data-ui-theme="dark"] .template-organization-banner-icon {
    background: var(--ui-surface);
    color: var(--ui-accent);
    border-color: var(--ui-border);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .administrator-session-banner {
    background: var(--ui-warning-surface);
    color: var(--ui-warning);
    border-color: var(--ui-divider-subtle);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .administrator-session-banner button {
    background: var(--ui-surface);
    color: var(--ui-warning);
    border-color: var(--ui-border);
    box-shadow: none;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .administrator-session-banner button:hover {
    background: var(--ui-surface-hover);
}

/* Left navigation geometry and status cues */
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .atpai-left-bar {
    background: var(--ui-nav-bg);
    /* Theme selection can change row heights between viewport resize events. */
    overflow-y: auto;
    scrollbar-width: thin;
}

/* The inset separator keeps the rail 55px wide. The marker overlaps it within the scroll area. */
html[data-ui-theme="dark"] #atpai-left-menu-bar {
    box-shadow: inset -1px 0 var(--ui-border);
    --ui-nav-marker: var(--ui-nav-bg);
    /* A non-overlay scrollbar belongs on the left, clear of the marker's edge. */
    direction: rtl;
}

html[data-ui-theme="dark"] #atpai-left-menu-bar > .left-bar-menu-item {
    /* Only the scroll container uses RTL to place the scrollbar. Menu content stays LTR. */
    direction: ltr;
    margin-inline-end: 1px;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .atpai-left-bar.left-menu-scroll-enabled::after {
    background: linear-gradient(to bottom, transparent, var(--ui-nav-bg));
}

html[data-ui-theme="dark"] #atpai-left-menu-bar.left-menu-scroll-enabled::after {
    /* Keep the scroll fade off the separator at the bottom of the rail. */
    background-size: calc(100% - 1px) 100%;
    background-repeat: no-repeat;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .atpai-left-bar .left-bar-menu-item {
    /* Match the desktop header's 55px content box and its lower border. */
    height: 56px;
    color: var(--ui-nav-text);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .atpai-left-bar #left-menu-support {
    min-height: 56px;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .atpai-left-bar #left-menu-admin-label {
    color: var(--ui-text);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .atpai-left-bar :is(#left-menu-users, #left-menu-api, #left-menu-beta-testers, #left-menu-saas-admin) {
    color: var(--ui-success);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .atpai-left-bar #left-menu-organization-admin {
    background: var(--ui-surface);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .atpai-left-bar .left-bar-menu-item:not(#left-menu-admin-label):hover,
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .atpai-left-bar .left-bar-menu-item.active {
    background: var(--ui-surface-hover);
    color: var(--ui-accent);
}

/* The Dashboard and Storage set important legacy triangle borders by menu item ID. */
html:is([data-ui-theme="dark"], [data-ui-theme="light"])
#atpai-left-menu-bar .left-bar-menu-item.active .left-menu-current-section-triangle > span {
    border-right-color: var(--ui-nav-marker, var(--ui-accent)) !important;
}

html[data-ui-theme="dark"] #atpai-left-menu-bar .left-menu-current-section-triangle {
    /* Center within the actual row height, including auto-height rows with badges. */
    inset-block: 0;
    right: -1px;
    height: auto;
    margin: 0;
}

html[data-ui-theme="dark"] #atpai-left-menu-bar .left-bar-menu-item.active .left-menu-current-section-triangle > span {
    border-block-width: 8px;
    border-right-width: 8px !important;
}

/* Keep support badges legible when the sidebar changes its link color on hover. */
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) #left-menu-support :is(
    [data-role="organization-opened-tickets-count"], [data-role="saas-opened-tickets-count"]
) {
    color: #fff;
}

html[data-ui-theme="light"] #left-menu-support [data-role="organization-opened-tickets-count"] {
    background-color: #792581;
}

html[data-ui-theme="light"] #left-menu-support [data-role="saas-opened-tickets-count"] {
    background-color: #535e16;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) #left-menu-support :is(
    [data-role="unresponded-messages-from-tech-support-icon"],
    [data-role="unresponded-messages-from-users-support-icon"]
) {
    background-color: var(--ui-danger-surface);
    color: var(--ui-danger);
}

/* Loading and legacy modal overlays already carry their opacity in the palette token. */
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .wait-loader .overlay,
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(.modal-overlay, .atpai-modal .overlay) {
    background: var(--ui-overlay);
    opacity: 1;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .wait-loader .loader-icon {
    color: var(--ui-accent);
}

/* The admin bridge details dialog is built dynamically after authentication. */
html[data-ui-theme="dark"] #bridges-apps-stats-modal a {
    color: var(--ui-link);
}

html[data-ui-theme="dark"] #bridges-apps-stats-modal .online-label {
    color: var(--ui-success);
}

html[data-ui-theme="dark"] #bridges-apps-stats-modal .offline-label {
    color: var(--ui-danger);
}

/* Native controls keep the workspace palette outside authored and export content. */
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .ui-theme-workspace
:is(
    input:not([type]), input[type="text"], input[type="number"], input[type="email"], input[type="date"],
    input[type="password"], input[type="search"], input[type="tel"], input[type="url"], select, textarea
):not(:where(
    .page-block *, .proposal-rates-page *,
    .qbo-preview-table-scroll *, #export-pt-pdf-output-area-wrapper *
)) {
    background: var(--ui-surface);
    color: var(--ui-text);
    border-color: var(--ui-border);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .ui-theme-workspace
:is(input, textarea):not(:where(
    .page-block *, .proposal-rates-page *,
    .qbo-preview-table-scroll *, #export-pt-pdf-output-area-wrapper *
))::placeholder {
    color: var(--ui-text-muted);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .ui-theme-workspace
:is(a, button, input, select, textarea):focus-visible:not(:where(
    .page-block *, .proposal-rates-page *,
    .qbo-preview-table-scroll *, #export-pt-pdf-output-area-wrapper *
)) {
    outline: 2px solid var(--ui-focus);
    outline-offset: 2px;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .ui-theme-workspace
.button:not(:where(
    .page-block *, .proposal-rates-page *,
    .qbo-preview-table-scroll *, #export-pt-pdf-output-area-wrapper *
)) {
    background: var(--ui-surface-raised);
    color: var(--ui-text);
    border-color: var(--ui-border);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .ui-theme-workspace
.button:hover:not(:where(
    .page-block *, .proposal-rates-page *,
    .qbo-preview-table-scroll *, #export-pt-pdf-output-area-wrapper *
)) {
    background: var(--ui-surface-hover);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .ui-theme-workspace
:is(.button.green-button, #usernamerole):not(:where(
    .page-block *, .proposal-rates-page *,
    .qbo-preview-table-scroll *, #export-pt-pdf-output-area-wrapper *
)) {
    background: var(--ui-primary-bg);
    color: var(--ui-primary-text);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .ui-theme-workspace
:is(.button.green-button, #usernamerole):hover:not(:where(
    .page-block *, .proposal-rates-page *,
    .qbo-preview-table-scroll *, #export-pt-pdf-output-area-wrapper *
)) {
    background: var(--ui-primary-hover);
}

/* The legacy notification badge uses important declarations for its warning colors. */
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) #usernamerole.user-have-critical-notifications {
    background: var(--ui-danger-surface) !important;
    color: var(--ui-danger);
    border-color: var(--ui-danger) !important;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .user-have-critical-notifications .user-notifications-bell-block {
    color: var(--ui-danger) !important;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .ui-theme-workspace
:where(main, .modal, .ateam-modal-v2, .atpai-modal) a[href]:not(:where(
    .button, .page-block *, .next-page-area-cell *, #export-pt-pdf-output-area-wrapper *,
    [data-role="textarea-extracted-content"] *, .proposal-rates-page *,
    .qbo-preview-table-scroll *, .product-subscription-actions *
)) {
    color: var(--ui-link);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(
    .modal-form-many-fields .field-label-description, .ateam-modal-top-short-description
) {
    color: var(--ui-text-muted);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .requred-field > div {
    background: var(--ui-surface-hover);
    color: var(--ui-link);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .field-with-wrong-data:not(:where(.page-block *, .proposal-rates-page *, #export-pt-pdf-output-area-wrapper *)) {
    background-color: var(--ui-danger-surface) !important;
    border-color: var(--ui-danger);
}

/* Tabs, result tables and pagers share the same treatment across staff pages. */
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .action-tabs:not(:where(.page-block *)) {
    border-color: var(--ui-divider-subtle);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .action-tab:not(:where(.page-block *)) {
    color: var(--ui-text-muted);
    opacity: 1;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .action-tab:hover:not(:where(.page-block *)) {
    background: var(--ui-surface-hover);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .action-tab.active:not(:where(.page-block *)) {
    background: var(--ui-surface-tinted);
    border-color: var(--ui-border);
    color: var(--ui-text);
    box-shadow: none;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(
    .ateam-standard-table-v2-header, .ateam-standard-table-v2-footer, .ateam-standard-table-row-v2
):not(:where(
    .page-block *, .proposal-rates-page *,
    .qbo-preview-table-scroll *, #export-pt-pdf-output-area-wrapper *
)) td {
    color: var(--ui-text);
    border-color: var(--ui-divider-subtle);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(
    .ateam-standard-table-v2-header, .ateam-standard-table-v2-footer
):not(:where(
    .page-block *, .proposal-rates-page *,
    .qbo-preview-table-scroll *, #export-pt-pdf-output-area-wrapper *
)) td {
    background: var(--ui-surface-tinted);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .ateam-standard-table-row-v2:hover:not(:where(
    .page-block *, .proposal-rates-page *,
    .qbo-preview-table-scroll *, #export-pt-pdf-output-area-wrapper *
)) {
    background: var(--ui-surface-hover);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) div:is([data-role="pagination"], [data-role="pagination-2"]):not(:where(.page-block *)) {
    background: var(--ui-surface-tinted);
    border-color: var(--ui-divider-subtle);
    box-shadow: none;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) div:is([data-role="pagination"], [data-role="pagination-2"]):not(:where(.page-block *)) .pager-left-label {
    color: var(--ui-text-muted);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) div:is([data-role="pagination"], [data-role="pagination-2"]):not(:where(.page-block *)) div[data-role="pager"] {
    background: var(--ui-surface);
    border-color: var(--ui-border);
    color: var(--ui-link);
    box-shadow: none;
    text-shadow: none;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) div:is([data-role="pagination"], [data-role="pagination-2"]):not(:where(.page-block *)) div[data-role="pager"]:hover {
    background: var(--ui-surface-hover);
    box-shadow: none;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) div:is([data-role="pagination"], [data-role="pagination-2"]):not(:where(.page-block *)) div[data-role="pager"][data-activepage="yes"] {
    background: var(--ui-surface-hover);
    border-color: var(--ui-accent);
    color: var(--ui-text) !important;
    box-shadow: none;
    text-shadow: none;
}

/* Cover both project dialog families and the vendor dialogs mounted on body. */
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .ateam-modal-v2,
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .alertify .ajs-dimmer {
    background: var(--ui-overlay);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(
    .ateam-modal-central-part-v2-content, .ui-dialog, .alertify .ajs-dialog, dialog.product-subscription-overlay
) {
    background: var(--ui-surface);
    color: var(--ui-text);
    border-color: var(--ui-border);
    box-shadow: var(--ui-shadow);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(
    .ateam-modal-header-v2, .ateam-modal-title-content-v2, .ateam-modal-buttons-content-v2,
    .ateam-modal-header-title-v2--close-modal, .ui-dialog .ui-dialog-titlebar,
    .alertify .ajs-header, .alertify .ajs-footer
) {
    background: var(--ui-surface-raised);
    color: var(--ui-text);
    border-color: var(--ui-divider-subtle);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(
    .ateam-modal-header-title-v2, .ui-dialog .ui-dialog-content, .alertify .ajs-content, .product-subscription-overlay h2
) {
    color: var(--ui-text);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .product-subscription-overlay p {
    color: var(--ui-text-muted);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .product-subscription-actions button {
    background: var(--ui-surface-raised);
    color: var(--ui-text);
    border-color: var(--ui-border);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(
    .ateam-modal-header-title-v2--close-modal, .alertify .ajs-button
):hover {
    background: var(--ui-surface-hover);
    color: var(--ui-text);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(.modal-header i, .modal-header-icon-before, .modal-icon) {
    color: var(--ui-accent);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .alertify-notifier .ajs-message {
    background: var(--ui-surface-raised);
    color: var(--ui-text);
    border-color: var(--ui-divider-subtle);
    text-shadow: none;
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .alertify-notifier .ajs-message.ajs-success {
    border-color: var(--ui-success);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) .alertify-notifier .ajs-message.ajs-error {
    border-color: var(--ui-danger);
}

/* Date pickers, autocomplete results and Select2 popovers use the current surface. */
html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(
    .ui-datepicker, .ui-autocomplete, .select2-dropdown,
    .select2-container .select2-selection--single, .select2-container .select2-selection--multiple
) {
    background: var(--ui-surface);
    color: var(--ui-text);
    border-color: var(--ui-border);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(
    .ui-datepicker .ui-datepicker-header, .ui-datepicker .ui-state-default,
    .select2-container .select2-selection__choice
) {
    background: var(--ui-surface-raised);
    color: var(--ui-text);
    border-color: var(--ui-divider-subtle);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(
    .ui-datepicker .ui-state-active, .ui-autocomplete .ui-state-active,
    .select2-container .select2-results__option--highlighted[aria-selected],
    .select2-container .select2-results__option[aria-selected="true"]
) {
    background: var(--ui-surface-hover);
    color: var(--ui-text);
    border-color: var(--ui-accent);
}

html:is([data-ui-theme="dark"], [data-ui-theme="light"]) :is(
    .select2-container .select2-selection__rendered, .select2-container .select2-selection__choice__remove,
    .select2-container .select2-selection__clear, .select2-container .select2-search__field
) {
    color: var(--ui-text);
}
