/* ===================================
   PANEL COMPONENT
   ===================================
   
   Non-collapsible section panel with consistent header + content structure.
   Uses ControlsBar molecule for filter/action layout.
   
   SPACING CONTRACT:
   - Panel owns internal padding (via .dashboard-section)
   - .section-content has NO padding (parent owns it)
   - .section-header has minimal vertical padding
   - Parent container owns gap between panels (no margin-bottom)
*/

/* Panel container - OWNS the internal padding.
 *
 * THE ONE OWNER (TLP-989 item 5). dashboards-core.css used to redeclare this block and,
 * loading later with equal specificity, quietly won: the platform has been shipping
 * core's 16px padding, 6px radius and shadow, not the 12px / 12px-radius / no-shadow this
 * file described. Two files claiming one contract, and the file that documented it was
 * the one being overridden.
 *
 * Consolidated here with the values that actually ship, so nothing moves on screen. The
 * radius and padding below are therefore what the platform looks like TODAY, not a design
 * decision -- if the 12px radius this file originally intended is wanted, that is a
 * deliberate restyle of every panel and belongs on its own card.
 */
.dashboard-section {
    background: var(--bg-surface);
    border: var(--border-width-1) solid var(--border-subtle);
    border-radius: var(--border-radius-md);  /* 6px - what ships; see note above */
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    padding: var(--space-4);  /* 16px - Panel owns internal spacing */
    margin: 0;  /* CONTRACT: Parent gap handles spacing between panels */
    
    /* Flex column for height inheritance - header fixed, content fills */
    display: flex;
    flex-direction: column;
    min-height: 0;  /* Allow shrinking in flex/grid contexts */
    box-sizing: border-box;
}

/* Panel header - flexbox layout with title left, controls right */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0 var(--space-2) 0;  /* Only bottom padding before border */
    margin-bottom: var(--space-3);  /* Gap to content */
    border-bottom: var(--border-width-1) solid var(--border-subtle);
    gap: var(--space-4);
    flex-wrap: wrap;
    flex-shrink: 0;  /* Header doesn't shrink */
}

.section-header:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

/* Section title */
.section-title {
    font-size: var(--text-md);  /* 16px - professional, not oversized */
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* Section subtitle - inline with title, smaller and muted */
.section-subtitle {
    font-size: var(--text-sm);
    font-weight: var(--font-weight-normal);
    color: var(--text-muted);
}

/* Panel content - CONTRACT: NO padding, parent .dashboard-section owns it.
   SCROLL CONTRACT (ui-patterns.md, "Layout, spacing & scroll"): the body is a flex
   column that FILLS the panel and scrolls only when its content exceeds it. Never
   pinned to a vh fraction -- a viewport cap is decoupled from the panel it lives in,
   so it leaves a dead band below the body while the body still scrolls (TLP-913).
   This file is the ONE owner of the contract; never redeclare .section-content or
   .dashboard-section.scrollable-panel in an app or module stylesheet. */
.section-content {
    padding: 0;
    display: flex;
    flex-direction: column;  /* Ancestor link in the module's own fill chain */
    flex: 1;  /* Fill remaining height */
    min-height: 0;  /* Mandatory: shrink and scroll instead of overflowing */
    overflow-y: auto;  /* Scroll when content exceeds available height */
}

/* Scrollable panel variant: a sticky header over a scrolling body. */
.scrollable-panel .section-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-surface);
}

.dashboard-section.scrollable-panel {
    flex: 0 0 auto;  /* Content-sized unless the one-panel rule below promotes it */
    min-height: 0;
    overflow: visible;  /* Clipping here would kill the sticky header */
}

.dashboard-section.scrollable-panel .section-content {
    overflow-x: hidden;  /* Vertical scroller only; grids own their own x-axis */
}

/* ONE-PANEL FILL -- the house rule for where a tab scrolls.

   A tab whose content is a SINGLE panel gives that panel the whole tab: the panel
   header (title, count, filters, actions) pins and only the rows scroll, inside the
   panel. No dead band below a short list, and the action bar at the foot of a row is
   always on screen.

   Two or more panels and NOBODY fills: they stay content-sized and .tab-content-container
   scrolls past them. Scrolling the page is what happens when there is more than fits --
   never the fallback for one list.

   Things that do not render are siblings but not content, and must neither count as a
   second panel nor stop the panel above them from filling: Modal.build always emits a
   display:none .modal-overlay, and modules park hidden file inputs after the panel with
   the .hidden utility (Employees, Location Information -- a hidden input was the only
   thing keeping a 1,425-row list from ever scrolling internally). Anything that DOES
   render after the panel (a sub-tab bar, an .expandable-panel-list) stops it -- that tab
   is not a one-panel tab.

   This file is the ONE owner of whether a panel fills. VerticalStackTemplate.css owns
   only the gap BETWEEN panels; it used to promote whichever panel happened to be
   :last-child, which made two identical-looking tabs behave differently purely on
   whether the module rendered a trailing modal (TLP-913 follow-up). Modules must not
   re-declare this in their own stylesheets.

   ANCHORED TO .tab-content-container ON PURPOSE -- read this before widening it.

   `flex: 1` only delivers a height if EVERY ancestor between here and the tab container
   passes one down. The stack does; a module wrapper does not (`.menu-body` is a plain
   display:block div). So the stack branch requires the stack to be a DIRECT child of the
   tab container. If it did not, a panel inside a wrapper would still match this rule,
   take `flex: 1` that resolves against nothing, AND take the size containment below --
   and size containment does not need a height to bite. The panel then asks its body how
   tall it is, containment answers zero, and the tab renders as a header strip with its
   content laid out invisibly behind it. Measured on stage 2026-09-03: Menu, 95px panel,
   0px body, 645px of courses nobody could see.

   The invariant: THIS RULE MAY ONLY PROMOTE A PANEL WHOSE HEIGHT PROVABLY ARRIVES.
   With it anchored, a module wrapper costs a page scroll -- recoverable, and what the
   platform did before TLP-981 -- instead of invisible content. */
.tab-content-container:not(:has(> .dashboard-section ~ .dashboard-section)) > .dashboard-section:not(:has(~ :not(.modal-overlay):not(.hidden))),
.tab-content-container > .vertical-stack-layout:not(:has(> .dashboard-section ~ .dashboard-section)) > .dashboard-section:not(:has(~ :not(.modal-overlay):not(.hidden))) {
    flex: 1;
    min-height: 0;
}

/* The query container the open-row cap measures against (ExpandablePanel.css).

   DANGER, and the reason this selector is not simply `.section-content`:
   `container-type: size` applies SIZE CONTAINMENT, which tells the browser to lay the
   element out as if it had NO CONTENTS. On a PROMOTED body that is harmless -- its
   height comes from the flex rule above, not from what is inside it. On a CONTENT-SIZED
   body it is fatal: the panel asks the body how tall it is, containment answers "zero",
   and the panel collapses to header + padding while its content is still laid out and
   overflowing. Measured on stage 2026-09-03: ten tabs rendered as ~97px strips with
   `clientHeight: 0` against a `scrollHeight` of 368. It hides from a search for height
   rules, and computed `contain` still reports `none`, so it is hard to find twice.

   Keep this selector pair identical to the fill rule above: only a panel that fills may
   be a size container. `e2e/one-panel-fill-stage.spec.js` fails if they drift. */
.tab-content-container:not(:has(> .dashboard-section ~ .dashboard-section)) > .dashboard-section:not(:has(~ :not(.modal-overlay):not(.hidden))) > .section-content,
.tab-content-container > .vertical-stack-layout:not(:has(> .dashboard-section ~ .dashboard-section)) > .dashboard-section:not(:has(~ :not(.modal-overlay):not(.hidden))) > .section-content {
    container-type: size;
}

/* ControlsBar integration - allow it to grow and take remaining space */
.section-header .controls-bar {
    flex: 1;
    justify-content: flex-end;
}

/* Grouped controls bars own their own layout -- don't override */
.section-header .controls-bar.controls-bar--groups {
    justify-content: space-between;
}

.section-header .controls-bar.controls-bar--groups-1 {
    justify-content: flex-start;
}

.section-header .controls-bar.controls-bar--groups-2 {
    justify-content: flex-start;
}

/* Responsive */
@media (max-width: 768px) {
    .dashboard-section {
        padding: var(--space-3);
    }
    
    .section-header {
        flex-direction: column;
        align-items: stretch;
        padding: 0 0 var(--space-1_5) 0;
    }
    
    .section-title {
        margin-bottom: var(--space-2);
    }
    
    /* ControlsBar handles its own responsive behavior */
    .section-header .controls-bar {
        justify-content: space-between;
    }
}
