html {
    background: var(--nx-color-background);
    font-size: 110%;
    touch-action: manipulation;
}

@media (max-width: 1024px) {
    html {
        font-size: 115%;
    }
}

body {
    background: var(--nx-color-background);
    color: var(--nx-color-text);
    font-family: var(--nx-font-family);
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
}

/* Constructly lists are flush by default, including new shared tree consumers.
   Keep cell, row, toolbar and hierarchy spacing inside their own elements. */
body .nx-tree-list,
body .nx-crud-tree-list__tree {
    padding: 0 !important;
}

body .nx-tab-page:is(.project-list-page, .contact-list-page,
    .activity-team-page, .activity-dependencies-page, .list-page) {
    padding: 0;
}

/* Attachment explorers grow with their items; their tab owns scrolling.
   Tree-list tabs instead clip around a control with its own scroll viewport.
   Only override active tabs so hidden pages retain their visibility rules. */
body .nx-tab-page:not([hidden]):has(> .nx-attachments) {
    display: block !important;
    min-height: 0;
    overflow: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0;
}

/* Keep links aligned with surrounding text, including shared component links. */
a,
a:link,
a:visited,
a:hover,
a:focus,
a:active {
    color: inherit !important;
}

/* Size from the largest tab, cap the dialog, and keep chrome outside scrolling. */
.nx-popup__backdrop .nx-popup__dialog.nx-card {
    height: auto !important;
    min-height: 0 !important;
    max-height: min(90dvh, var(--nx-popup-available-height, calc(100dvh - 2rem))) !important;
    overflow: hidden !important;
}

/* These are the sizing chain between the dialog and its tab viewport.
   Auto bases measure natural content; shrinking keeps it inside the dialog. */
.nx-popup__dialog :is(
    .nx-editor, .nx-editor__form, .nx-editor__layout, .nx-editor__body,
    .project-editor-panels, .contact-editor-panels, .activity-panels,
    .member-panels, .bulk-panels, .record-pages, .user-editor-panels,
    .equipment-editor, .equipment-body, .equipment-plan, .contact-reference
) {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    overflow: hidden !important;
}

.nx-popup__dialog :is(.nx-editor__navigation, .nx-editor__footer,
    .equipment-header, .equipment-navigation, .contact-reference-header) {
    flex: 0 0 auto;
}

/* Non-tabbed forms still need their own scroll area. */
.nx-popup__dialog .nx-editor__body:not(:has(.nx-tab-page)),
.nx-popup__dialog .nx-popup-content,
.nx-popup__dialog .contact-reference-body {
    flex: 1 1 auto !important;
    min-height: 0;
    overflow: auto !important;
}

/* An indefinite grid measures the tallest page; once the dialog reaches its
   cap this track shrinks, and each page scrolls only its own content. */
.nx-popup__dialog :has(> .nx-tab-page) {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

.nx-popup__dialog .nx-tab-page {
    display: block !important;
    grid-area: 1 / 1;
    align-self: stretch;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow: auto !important;
    overscroll-behavior: contain;
}

.nx-popup__dialog .nx-tab-page[hidden] {
    visibility: hidden !important;
    pointer-events: none;
}

/* Lists and fields supply natural content to their page, not a second
   viewport or a minimum height that stretches otherwise short tabs. */
.nx-popup__dialog .nx-tab-page :is(
    .contact-selection-list, .activity-dependency-list, .bulk-person-list,
    .user-permissions-form, .user-permission-list-space,
    .stage-panel, .stage-history, .stage-team, .project-team-list,
    .nx-crud-tree-list, .nx-tree-list, .nx-field, .nx-text-area
) {
    flex: 0 0 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

.nx-popup__dialog .nx-text-area::after {
    display: block !important;
}

/* Overview/Notes share a form in the deliverable stage grid. */
.nx-popup__dialog .equipment-overview-editor {
    grid-area: 1 / 1;
    align-self: stretch;
}

.nx-popup__dialog .equipment-overview-editor--inactive {
    visibility: hidden !important;
    pointer-events: none;
}

/* Deliverable stages share one bounded viewport rather than sizing from row count. */
.nx-popup__backdrop .nx-popup__dialog.nx-card.equipment-popup {
    height: min(35.5rem, 90dvh, var(--nx-popup-available-height, calc(100dvh - 2rem))) !important;
}
.nx-popup__dialog.equipment-popup .equipment-body > .equipment-page {
    display: flex !important;
    flex-direction: column;
    overflow: hidden !important;
}
.nx-popup__dialog.equipment-popup .equipment-page > .stage-panel,
.nx-popup__dialog.equipment-popup .equipment-page .stage-history,
.nx-popup__dialog.equipment-popup .stage-history > .nx-crud-tree-list {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
}
.nx-popup__dialog.equipment-popup .stage-history .nx-tree-list {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow: auto !important;
}
.nx-popup__dialog.equipment-popup .equipment-page .stage-team {
    flex: 0 0 auto !important;
}

/* Dedicated Notes tabs fill their viewport; only the input scrolls. Hidden
   popup tabs still contribute a normal editor height to largest-tab sizing. */
.nx-tab-page.project-notes-fill:not([hidden]),
.nx-popup__dialog .nx-tab-page.project-notes-fill {
    display: flex !important;
    flex-direction: column;
    min-height: 0;
    overflow: hidden !important;
}

.nx-tab-page.project-notes-fill :is(fieldset, .nx-field, .nx-text-area) {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

.nx-tab-page.project-notes-fill .nx-field > label {
    flex: 0 0 auto;
}

.nx-tab-page.project-notes-fill .nx-text-area::after {
    display: block !important;
    content: " " !important;
    flex: 0 1 auto;
}
