/* ==========================================================================
   layouts/app-detail-page.css — Two-column detail page with sticky sidebar nav
   --------------------------------------------------------------------------
   Generic layout for edit/detail pages: a narrow left column with clickable
   section links that scroll the main content on the right.

   Markup contract:
     .app-detail-page
       .app-detail-page__nav
         .app-detail-page__nav-list
           .app-detail-page__nav-item[href="#section-id"]  (anchor links)
       .app-detail-page__body
         .app-detail-page__section[id="section-id"]
           .app-detail-page__section-title
           (…section content…)
         .app-detail-page__actions   (sticky bottom action bar)
   ========================================================================== */

/* ========== CONTAINER ========== */

.app-detail-page {
    display: flex;
    gap: 0;
    min-height: 0;
    flex: 1 1 auto;
    width: 100%;
}

/* Contained variant — left-aligned with a max width */
.app-detail-page--contained {
    max-width: 1024px;
}

/* Card variant — centered card for simple info/settings pages */
.app-detail-page--card {
    max-width: 560px;
    margin: var(--spacing-3xl) auto;
    background: var(--bg-primary);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-xl);
    padding: var(--spacing-2xl) var(--spacing-3xl);
}

.app-detail-page__card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin: 0 auto var(--spacing-xl);
    background: var(--accent-light, rgba(104, 131, 160, 0.08));
    border-radius: var(--radius-full, 50%);
    color: var(--accent);
    font-size: 24px;
}

.app-detail-page--card .app-detail-page__body > p {
    color: var(--text-secondary);
    font-size: var(--font-body-md-size);
    line-height: var(--font-body-md-line-height);
    margin-bottom: var(--spacing-xl);
}

/* Fluid variant (default behaviour, explicit class for clarity) */
.app-detail-page--fluid {
    max-width: none;
}

/* ========== LEFT: SIDEBAR NAV ========== */

.app-detail-page__nav {
    width: 260px;
    flex-shrink: 0;
    position: sticky;
    top: 4rem;
    align-self: flex-start;
    max-height: calc(100vh - 120px);
    overflow: hidden;
}

.app-detail-page__nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.app-detail-page__nav-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 0;
    font-family: var(--font-family-primary);
    font-size: var(--font-body-md-size);
    font-weight: var(--font-weight-medium);
    line-height: var(--font-body-sm-line-height);
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
    transition: color var(--transition-fast);
    user-select: none;
}

.app-detail-page__nav-item:hover {
    color: var(--text-primary);
}

.app-detail-page__nav-item.is-active {
    color: var(--accent);
    font-weight: var(--font-weight-semibold);
}

/* Optional icon inside nav item */
.app-detail-page__nav-item .sym {
    font-size: var(--icon-size-md);
    flex-shrink: 0;
}

/* ========== PAGE CONTROLS ========== */

.app-page-controls {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    margin-top: var(--spacing-2xl);
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--border-tertiary);
}

.app-page-controls__btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    width: auto;
    padding: 0;
    background: none;
    border: none;
    text-align: left;
    font-family: var(--font-family-primary);
    font-size: var(--font-body-md-size);
    font-weight: var(--font-weight-medium);
    line-height: var(--font-body-sm-line-height);
    color: var(--text-secondary);
    cursor: pointer;
    transition: color var(--transition-fast);
    user-select: none;
}

.app-page-controls__btn:hover {
    color: var(--text-primary);
}

.app-page-controls__btn .sym {
    font-size: var(--icon-size-md);
    flex-shrink: 0;
}

/* ========== RIGHT: BODY / CONTENT ========== */

.app-detail-page__body {
    flex: 1 1 auto;
    min-width: 0;
    /* padding: 0 0 var(--spacing-3xl) var(--spacing-4xl); */
	min-height: 80vh;
}

/* ========== SECTIONS ========== */

.app-detail-page__section {
    padding-bottom: 0;
    margin: 0;
    scroll-margin-top: 0;
}

.app-detail-page__section:last-of-type {
    border-bottom: none;
}

/* A section sitting straight under the list filter bar needs separating from it. This cannot be
   done from the markup: `margin: 0` above lands in a file that loads after the app-mt--* utilities,
   so the utility class always loses. */
.main_list_filter + .app-detail-page__section {
    margin-top: var(--spacing-xl);
}

.app-detail-page__section-title {
    font-family: var(--font-family-primary);
    font-size: var(--font-display-sm-size);
    font-weight: var(--font-display-sm-weight);
    line-height: var(--font-display-sm-line-height);
    letter-spacing: var(--font-display-sm-letter-spacing);
    color: var(--text-primary);
    margin: 0 0 var(--spacing-2xl) 0;
}

.app-detail-page__section-subtitle {
    font-size: var(--font-body-sm-size);
    color: var(--text-tertiary);
    margin: calc(var(--spacing-sm) * -1) 0 var(--spacing-2xl) 0;
}

/* ========== FIELD GRID INSIDE SECTIONS ========== */
/* Two-column field layout within a section.
   Container queries drive breakpoints because the form shares horizontal space
   with a sidebar nav and a document-preview pane whose widths change dynamically. */

.app-detail-page__section-content {
    container-type: inline-size;
}

.app-detail-page__fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-xl) var(--spacing-3xl);
}

.app-detail-page__fields--single {
    grid-template-columns: 1fr;
}

.app-detail-page__fields--three {
    grid-template-columns: 1fr 1fr 1fr;
}

.app-detail-page__fields--four {
    grid-template-columns: 1fr 1fr 1fr 1fr;
}

.app-detail-page__fields > * {
    min-width: 0;
}

/* Compact variant — tighter gaps and smaller field margins */
.app-detail-page__fields--compact {
    gap: var(--spacing-sm) var(--spacing-xl);
}

.app-detail-page__fields--compact .app-field {
    margin-bottom: var(--spacing-xs);
}

/* Rows line up across columns: a label with an icon is as tall as one without, and a static value
   takes the height of the --sm input beside it. */
.app-detail-page__fields--compact .app-field__label {
    min-height: var(--icon-size-md);
}

/* A label row that also carries a control (a checkbox beside the label) keeps the label's height. */
.app-detail-page__fields--compact .app-field > .flex-row:first-child:has(> .app-field__label) {
    height: var(--icon-size-md);
}

.app-detail-page__fields--compact .app-field__static {
    display: flex;
    align-items: center;
    min-height: 28px;
    font-weight: var(--font-weight-medium);
}

/* Column wrapper — when a grid cell stacks multiple .app-field vertically (e.g. header sections
   with conditional elements that must stay in the same column). Normalises spacing so wrapped
   fields match the rhythm of flat grid fields. */
.app-detail-page__fields-col {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.app-detail-page__fields-col > .app-field {
    margin-bottom: 0;
}

/* Full-width field spanning all columns */
.app-detail-page__field--full {
    grid-column: 1 / -1;
}

/* Takes every column after the first — a summary cluster beside one column of fields */
.app-detail-page__field--rest {
    grid-column: 2 / -1;
}

/* Beside a --rest cluster the first column holds inline fields (label + input), which a quarter of a narrow
   section can't fit; it keeps its content width so the inputs don't run under the totals. */
.app-detail-page__fields--four:has(> .app-detail-page__field--rest) {
    grid-template-columns: minmax(max-content, 1fr) 1fr 1fr 1fr;
}

/* ========== SECTION HEADER ========== */

.app-detail-page__section-header {
    display: flex;
    align-items: center;
    font-family: var(--font-family-primary);
    font-size: var(--font-body-lg-size);
    font-weight: var(--font-weight-black);
    line-height: var(--font-body-lg-line-height);
    letter-spacing: 0;
    color: var(--text-secondary);
    border: none;
    padding: 0;
    margin: 0 0 var(--spacing-2xl) 0;
    cursor: pointer;
    user-select: none;
}

.app-detail-page__section-header > .sym {
    font-size: 24px;
    color: var(--text-tertiary);
    margin-right: var(--spacing-xs);
    transition: transform var(--transition-fast);
    transform: rotate(180deg);
    flex-shrink: 0;
}

.app-detail-page__section-header.is-collapsed > .sym,
.app-detail-page__section-header.toggleclosed > .sym {
    transform: rotate(0deg);
}

/* Legacy Briox.GroupToggler legends draw their own triangle; the sym chevron replaces it */
legend.togglelegend.app-detail-page__section-header::before {
    content: none;
}

.app-detail-page__section-header--sticky {
    position: sticky;
    top: 56px;
    background: var(--bg-primary);
    padding: var(--spacing-sm) 0;
    z-index: 1;
}

/* Declares its own background so a legacy skin class riding alongside cannot paint the section.
   Crm_General::CreateHeaderBlock still emits .fieldset_wrapper (#fbfbfb) on 61 CRM/cpnl blocks. */
.app-detail-page__section-content {
    padding-bottom: var(--spacing-2xl);
    background: var(--bg-primary);
}

/* When section content only contains a table, remove extra spacing */
.app-detail-page__section-content:has(> .app-table:only-child) {
    padding: 0;
    margin-bottom: 0;
    border: none;
}

.app-detail-page__section-content.is-collapsed {
    display: none;
}

/* A non-collapsible legend still reads as a section header, but is not clickable */
legend.app-detail-page__section-header:not(.togglelegend) {
    cursor: default;
}

/* Row of buttons belonging to a block inside a section */
.app-detail-page__section-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

/* Report pages: export actions sit at the right edge, above the report output */
.app-detail-page__section-actions--end {
    justify-content: flex-end;
}

/* Legacy PHP-assigned float columns (.column two) still need the container to clear */
.app-detail-page__section-content:has(> .column) {
    display: flow-root;
}

.app-detail-page__section-content > .column {
    border-right: none;
    margin-bottom: var(--spacing-3xl);
}

/* Two float columns are 50% each with no gutter, so the left one's fields ran into the right
   one's labels. Every half gets the gutter (not :not(.last)): markup marks .last by source order,
   and a third half that wraps to a new row is .last while sitting on the left. */
.app-detail-page__section-content > .column.two {
    box-sizing: border-box;
    padding-right: var(--spacing-3xl);
}

/* Sub-headings inside section content — one step below the section header (body-lg semibold),
   so body-md semibold in the primary text colour. It used to be label-sized in accent-darkest,
   which read as a dark red caption rather than as a heading. */
.app-detail-page__section-content h3 {
    font-family: var(--font-family-primary);
    font-size: var(--font-body-md-size);
    font-weight: var(--font-weight-semibold);
    line-height: var(--font-body-md-line-height);
    color: var(--text-primary);
    text-transform: none;
    letter-spacing: normal;
    text-align: left;
    margin: var(--spacing-xl) 0 var(--spacing-md) 0;
}

.app-detail-page__section-content h3:first-child {
    margin-top: 0;
}

/* An info icon beside a sub-heading keeps its own size and colour — the h3 rule above is the
   more specific of the two and would otherwise paint it accent-darkest at label size. */
.app-detail-page__section-content h3 .app-info-icon {
    margin-left: var(--spacing-xs);
    font-size: var(--icon-size-sm);
    color: var(--text-tertiary);
}

/* ========== ACTION BAR ========== */

.app-detail-page__actions {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-xl) 0;
    z-index: 10;
    background: linear-gradient(0deg, rgba(255, 255, 255, 1) 50%, rgba(255, 255, 255, 0.2) 100%);
    backdrop-filter: blur(2px);
    width: 100% !important;
}

.app-detail-page__actions-left,
.app-detail-page__actions-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

/* Use when the action bar lives outside an .app-detail-page scroll context (e.g. settings pages) */
.app-detail-page__actions--fixed {
    position: fixed;
    bottom: 0;
    left: 0;
    padding-inline: var(--spacing-xl);
    z-index: 90;
}

/* A bar the page's JS hides until a record is open (acct_class) - its display: flex beats legacy .hidden. */
.app-detail-page__actions.hidden {
    display: none;
}

/* ========== MORE ACTIONS DROPDOWN ========== */

.app-detail-page__actions-more {
    position: relative;
}

.app-detail-page__actions-dropdown {
    display: none;
    position: absolute;
    bottom: calc(100% + var(--spacing-xs));
    left: 0;
    min-width: 180px;
    background: var(--bg-primary);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--spacing-xs) 0;
    z-index: 20;
}

.app-detail-page__actions-more.is-open .app-detail-page__actions-dropdown {
    display: block;
}

/* GenerateButtonMore opens its menu through ActionBarButtons.addListeners, which toggles .hidden on
   the list — six other call sites depend on that, so that menu opens on .hidden as well. Scoped to
   --overflow: a fields menu carries no .hidden and would otherwise be stuck open, outranking the
   .is-open gating it actually uses. */
.app-detail-page__actions-dropdown--overflow:not(.hidden) {
    display: block;
}

.app-detail-page__actions-dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-lg);
    font-family: var(--font-family-primary);
    font-size: var(--font-body-sm-size);
    font-weight: var(--font-weight-medium);
    line-height: var(--font-body-sm-line-height);
    color: var(--text-primary);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
}

.app-detail-page__actions-dropdown-item:hover {
    background-color: var(--bg-tertiary);
}

/* `Briox.ActionBarButtons` moves the bar's own <button> elements into this menu and strips their
   `app-btn` / `novus_action_button` classes, so an action that is disabled for the current
   selection arrives here as a bare `<button disabled>`. The legacy bar relied on the browser's
   default grey for exactly that; the rule above sets an explicit `color`, which overrides it — so
   every item in a migrated More menu read as enabled, and still lit up on hover. Restate it. */
.app-detail-page__actions-dropdown-item:disabled {
    color: var(--color-disabled-text);
    cursor: default;
}

.app-detail-page__actions-dropdown-item:disabled:hover {
    background-color: transparent;
}

.app-detail-page__actions-dropdown-item .sym {
    font-size: var(--icon-size-sm);
}

.app-detail-page__actions-dropdown-item--danger {
    color: var(--error);
}

.app-detail-page__actions-dropdown-item--danger:hover {
    background-color: #fef2f2;
}

/* A menu of labelled fields rather than menu items — the controls inside keep their own widgets */
.app-detail-page__actions-dropdown--fields {
    left: auto;
    right: 0;
    min-width: 280px;
    padding: var(--spacing-lg);
    display: none;
    flex-direction: column;
    gap: var(--spacing-md);
}

.app-detail-page__actions-more.is-open .app-detail-page__actions-dropdown--fields {
    display: flex;
}

/* The bar sizes its dropdowns to their content (width: auto below); inside the menu the field
   governs instead, so both selects line up. Needs the bar in the selector to outrank that rule. */
.app-detail-page__actions .app-detail-page__actions-dropdown--fields .novus_filter_input_block,
.app-detail-page__actions .app-detail-page__actions-dropdown--fields .novus_filter_input_block > * {
    width: 100%;
    margin: 0;
}

/* The metrics used to be restated here to mirror an --lg bar, and to outrank
   .app-field .novus_filter_select in overrides.css. That rule is gone — the widget carries the
   <select>'s own app-input size class now — so the size governs and the menu follows the bar at
   whatever size the bar is. */

.app-detail-page__actions .app-detail-page__actions-dropdown--fields .novus_filter_select .selected_filter_text {
    font-size: inherit;
    font-weight: inherit;
}


/* ========== OPTIONAL FIELDS (View less / View all toggle) ========== */

.app-field--optional.is-hidden {
    display: none;
}

/* ========== RESPONSIVE — CONTAINER QUERIES ========== */
/* The form's available width depends on the nav bar and document preview column,
   not the viewport. Container queries on .app-detail-page__section-content (set above)
   collapse the grid based on actual container width. */

@container (max-width: 600px) {
    .app-detail-page__fields--four {
        grid-template-columns: 1fr 1fr;
    }

    /* Too narrow to sit beside the fields, so the summary cluster goes below them. */
    .app-detail-page__fields--four:has(> .app-detail-page__field--rest) {
        grid-template-columns: 1fr;
    }

    .app-detail-page__fields--four > .app-detail-page__field--rest {
        grid-column: auto;
    }

    /* Stacked, the fields go first so a caption over the summary cluster stays with it. */
    .app-detail-page__fields--four:has(> .app-detail-page__field--rest) > .app-detail-page__fields-col:not(.app-detail-page__field--rest) {
        order: -1;
    }

    /* Stacked below the fields there is no row height to fill, so the notes box keeps its own minimum. */
    .app-detail-page__fields--four > .app-detail-page__field--rest > .app-field--grow > textarea.app-input {
        min-height: 80px;
    }

    .app-detail-page__fields--three {
        grid-template-columns: 1fr 1fr;
    }

    .app-detail-page__section-header {
        font-size: var(--font-body-md-size);
    }

    .app-detail-page__section-title {
        font-size: var(--font-body-lg-size);
    }
}

@container (max-width: 380px) {
    .app-detail-page__fields,
    .app-detail-page__fields--three,
    .app-detail-page__fields--four {
        grid-template-columns: 1fr;
    }

    .app-detail-page__field--rest {
        grid-column: auto;
    }
}

/* ========== RESPONSIVE — VIEWPORT FALLBACKS ========== */
/* Viewport-based rules kept as fallbacks for sections not inside a container context. */

@media (max-width: 960px) {
    .app-detail-page__nav {
        display: none;
    }

    .app-detail-page__body {
        border-left: none;
        padding-left: 0;
    }
}

@media (max-width: 600px) {
    .app-detail-page__fields,
    .app-detail-page__fields--three,
    .app-detail-page__fields--four {
        grid-template-columns: 1fr;
    }
}

/* ========== REDUCED MOTION ========== */

@media (prefers-reduced-motion: reduce) {
    .app-detail-page__nav-item {
        transition: none;
    }

    html {
        scroll-behavior: auto;
    }
}

/* ========== ACTION BAR — TAMING LEGACY SPACING ==========
   A migrated bar still contains .novus_action_bar_group wrappers. They add padding: 0 10px
   plus a 10px margin on every non-last button, which stacks with the flex gap into an uneven
   rhythm (measured 15/16/46/30/60px between controls). Neutralise both and let one gap govern. */

.app-detail-page__actions-left,
.app-detail-page__actions-right {
    gap: var(--spacing-lg);
}

/* When the bar runs out of room it should break between groups, not inside one */
.app-detail-page__actions-right {
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: var(--spacing-md);
    /* Stays right even when an empty left group is hidden (legacy :empty rules) and space-between has one item. */
    margin-left: auto;
}

/* Once the right side wraps, centring leaves the left button floating between rows */
.app-detail-page__actions-left {
    align-self: flex-start;
}

.app-detail-page__actions .novus_action_bar_group {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
    padding: 0;
    /* Legacy flex-flow: row wrap plus flex: 0 1 auto let a group shrink below its content and
       stack its own controls into three rows while every neighbour stayed on one. */
    flex-wrap: nowrap;
    flex-shrink: 0;
}

.app-detail-page__actions .novus_action_bar_group button:not(:last-child),
.app-detail-page__actions .novus_action_bar_group .app-btn:not(:last-child) {
    margin-right: 0;
}

/* Groups whose buttons are all conditioned away still take a flex slot, doubling the gap
   next to them (measured 28px where the rhythm is 14px). */
.app-detail-page__actions .novus_action_bar_group:not(:has(*)) {
    display: none;
}

/* the filter wrappers carry margin: 4px 6px 4px 0 of their own */
.app-detail-page__actions .novus_filter_input_block,
.app-detail-page__actions .novus_filter_select {
    margin: 0;
}

/* The bar's dropdowns render as bare text — give them the same shape as the buttons
   so it reads as a control. Their <select> no longer carries no_border. */
.app-detail-page__actions .novus_filter_select {
    height: 40px;
    width: auto;
    box-sizing: border-box;
    /* match .app-btn--secondary.app-btn--outline.app-btn--lg, which is what stands next to it */
    padding: 0 var(--spacing-2xl);
    border: 1px solid currentcolor;
    border-radius: var(--radius-lg);
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--font-body-lg-size);
    line-height: var(--font-body-lg-line-height);
    font-weight: var(--font-weight-semibold);
}

.app-detail-page__actions .novus_filter_select .selected_filter_text {
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
}

/* .app-btn--outline's hover: tint the surface, keep the outline on currentcolor */
.app-detail-page__actions .novus_filter_select:hover {
    background: var(--bg-tertiary);
}

/* The legacy arrow is a 10px \25bc glyph that sits badly. Use the same symbol as the
   split button so every dropdown in the bar reads the same. */
.app-detail-page__actions .novus_filter_select::after {
    content: 'expand_more';
    font-family: 'Material Symbols Outlined';
    font-size: var(--icon-size-md);
    font-weight: normal;
    line-height: 1;
    margin-left: var(--spacing-sm);
    color: var(--text-secondary);
}

/* ========== SECTION CARD ==========
   A plain bordered card around a section's fields. Deliberately NOT
   .app-detail-page__section-content: that variant also sets `border: none` on every
   .app-input inside it, which suits the label-left inline form but hides the fields on a
   page whose labels sit above bordered inputs. This only draws the box. */

.app-section-card {
    padding: var(--spacing-xl);
    border: 1.5px solid var(--border-secondary);
    border-radius: var(--radius-xl);
    margin-bottom: var(--spacing-2xl);
    box-sizing: border-box;
}

/* Read-only fields inside a section card: the legacy .readonly class sets border: none and a
   transparent background, so a locked field reads as loose text among bordered ones. Give it
   the design system's locked look instead — scoped, so legacy pages keep their behaviour. */

.app-section-card .app-input.readonly,
.app-section-card .app-input[readonly] {
    border: 1px solid var(--border-secondary);
    background: var(--color-disabled-bg);
    color: var(--color-disabled-text);
}
