/* ==========================================================================
   cs-modal.css - the shared modal builder's variants
   Added 2026-10-17 (P-019 step 3, [MA3]).

   WHAT THIS STYLES
   Markup from CS_modal_block / CS_modal_ensure in core\cornerstone.utilities.js, and nothing
   else. A modal that is not built by that builder must not borrow these classes (D-080).

   .cs-modal--card    variant: 'card'. Navy blurred scrim, 16px white card, eyebrow + navy
                      title, round close, grey footer bar. Geometry taken from the New Task
                      modal (cs-tasks.js, .cs-tasks-*) so that modal can convert onto it.
                      Where cs-tasks.js uses a hex with no token, the nearest token is used:
                      see DESIGN_SYSTEM_USAGE.md section 8 D7.

   The standard modal (no variant) takes its look from cornerstone.css. This file adds one
   correction to it, the header row ([MA56], below). Geometry is px on purpose: html is
   font-size 82%, the design is 16px.
   ========================================================================== */

/* Standard variant header - title beside a fixed close [MA56]
   cornerstone.css stacks `.modal-header .btn-close { margin: -1.5rem -1.5rem -1.5rem auto }`
   and `.modal-header .close { margin-top: 1px }`, so the builder's `btn-close close` sat ~10px
   below the title and on the header's right edge (measured: header top 30, close top 56).
   Keyed on [data-cs-modal-title] as a direct child, which only the standard branch of
   CS_modal_block (JS and its PHP twin) emits: PG's own modals and the card variant (title
   inside .cs-modal-heading) are not matched. Nor is the drawer variant (data-cs-modal-variant=
   "drawer"): `.modal-sidebar button.close` fixes its close to the viewport corner, and the old
   margins are part of where it lands, so the drawers keep the header they always had. */
.modal:not([data-cs-modal-variant]) .modal-header > .modal-title[data-cs-modal-title] {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
}
.modal:not([data-cs-modal-variant]) .modal-header > .modal-title[data-cs-modal-title] + .btn-close {
    flex: 0 0 auto;
    float: none;
    margin: 0 0 0 16px;
}

/* Drawer variant title - room for the fixed close [MA94]
   `.modal-sidebar button.close` (cornerstone.css) is position:fixed at top 15px / right 55px,
   out of the header's flow, so a title long enough to wrap ran under it (measured on the admin
   change-password drawer: title right edge 1900, close 1868-1884). 40px keeps an 8px gap. The
   header's flex layout and the close's position are left as they are. */
.modal[data-cs-modal-variant="drawer"] .modal-header > .modal-title[data-cs-modal-title] {
    padding-right: 40px;
}

/* Full-screen size step - sizeClass 'modal-fullscreen' [MA75]
   cornerstone.css has BS5's `.modal-fullscreen { margin: 0 }` and then, later and at the same
   specificity, the BS3-era `.modal-dialog { margin: 30px auto }`, which wins: the dialog sat 30px
   down at full viewport height, so its bottom 30px fell off-screen and the modal's own scrollbar
   took 15px of width (measured on the template preview: dialog 0,30,1905,889 in a 1920x889
   viewport). First user: the HACCP template preview (P-019 #10). */
.modal-dialog.modal-fullscreen {
    margin: 0;
}

/* Wide size step - sizeClass 'cs-modal-wide' (860px) [MA68]
   The builder had only the 600px default and full width (`modal-lg` / `-xl` are full width
   here, [MA47]). Rob chose 860px for the HACCP hazard editor, whose six tabs do not fit 600.
   `width: auto` because the BS3-era `.modal-dialog { width: 600px }` would otherwise hold it;
   below 860px of viewport it shrinks with the dialog's own margins. Works with the card
   variant (`.cs-modal--card .modal-dialog` keeps its 52px margin). */
.modal-dialog.cs-modal-wide {
    width: auto;
    max-width: 860px;
}

/* The same step on a drawer (P-078, the PG insert/copy form modals). `.modal-sidebar` is
   position:absolute, so the `width: auto` above shrinks it to its content (471px measured);
   a drawer takes the step's width outright. */
.modal-dialog.modal-sidebar.cs-modal-wide {
    width: 860px;
    max-width: 100%;
}

/* The MRP document forms (purchase / sales order) were laid out for the old 1820px sheet and
   cramp at 860px; pgui.modal_operation_link.js swaps their drawer to this step (P-078, Rob). */
.modal-dialog.modal-sidebar.cs-modal-full {
    width: 90vw;
    max-width: 100%;
}

/* A form drawer keeps Save in view: the drawer's .modal-content is the scroller, so the form
   footer (forms/modal_form.tpl) sticks to its bottom edge. The old top sheet pinned it with
   is-fixed-bottom. Since 2026-11-03 (P-019, B-1798 [MV7-a]) every drawer built by the builder
   does the same: `.modal-content` is the scroller there too (measured), so a long drawer no
   longer pushes Save below the fold. A drawer with footer: false has nothing to pin. */
.modal-sidebar.cs-form-modal .modal-footer,
.modal[data-cs-modal-variant="drawer"] > .modal-sidebar .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--cs-white);
}

/* Scrim - the backdrop is a sibling of the modal, tagged by CS_modal_applyStacking */
.modal-backdrop.cs-modal-backdrop--card {
    background-color: color-mix(in srgb, var(--cs-navy) 50%, transparent);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.modal-backdrop.cs-modal-backdrop--card.show,
.modal-backdrop.cs-modal-backdrop--card.in {
    opacity: 1;
}

/* Dialog - centred, 52px clear top and bottom as the New Task overlay */
.cs-modal--card .modal-dialog {
    margin: 52px auto;
}
.cs-modal--card .modal-dialog-centered {
    min-height: calc(100% - 104px);
}

/* Card */
.cs-modal--card .modal-content {
    background-color: var(--surface-card);
    border: 0;
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 64px rgba(16, 43, 59, 0.28);
    max-height: calc(100vh - 104px);
    overflow: hidden;
}

/* Header */
.cs-modal--card .modal-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 18px 24px 14px;
    background-color: var(--surface-card);
    border-bottom: 1px solid var(--cs-gray-100);
    border-radius: 0;
}
.cs-modal--card .cs-modal-heading {
    flex: 1;
    min-width: 0;
}
.cs-modal--card .cs-modal-eyebrow {
    font-size: var(--fs-overline);
    font-weight: var(--fw-bold);
    letter-spacing: var(--ls-overline);
    text-transform: uppercase;
    color: var(--cs-blue);
    margin-bottom: 4px;
}
.cs-modal--card .cs-modal-eyebrow:empty {
    display: none;
}
.cs-modal--card .modal-title {
    font-family: var(--font-heading);
    font-weight: var(--fw-bold);
    font-size: 20px;
    line-height: var(--lh-snug);
    letter-spacing: -0.01em;
    color: var(--cs-navy);
    margin: 0;
}

/* Round close */
.cs-modal--card .cs-modal-close {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background-color: var(--cs-gray-100);
    color: var(--cs-navy);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}
.cs-modal--card .cs-modal-close:hover {
    background-color: var(--cs-gray-200);
}
.cs-modal--card .cs-modal-close:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

/* Body scrolls, header and footer stay put */
.cs-modal--card .modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 20px 24px;
}

/* Grey footer bar */
.cs-modal--card .modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 14px 24px;
    background-color: var(--cs-gray-50);
    border-top: 1px solid var(--cs-gray-100);
    border-radius: 0;
}
.cs-modal--card .modal-footer > * {
    margin: 0;
}

/* Phone width - 16px gutter */
@media (max-width: 575.98px) {
    .cs-modal--card .modal-dialog {
        margin: 16px;
    }
    .cs-modal--card .modal-dialog-centered {
        min-height: calc(100% - 32px);
    }
    .cs-modal--card .modal-content {
        max-height: calc(100vh - 32px);
    }
}

/* ==========================================================================
   Topbar panels - Notifications and Tasks drawer BODIES (P-501, 2026-11-17)
   Rob approved resources/audits/p501-panels-mockup.png. The drawer chrome
   (header, close, footer bar) stays the builder's; these rules style only the
   content common_offcanvas.tpl and ajax_notifications.php put inside it.
   Geometry in px from the mock-up; type at 0.07rem per design px (sibling rule,
   html is 82%). Status inks have no token yet (frontend-build.md): named once here.
   ========================================================================== */
.cs-panel {
    --cs-panel-ink-success: #02894e;
    --cs-panel-ink-warning: #9a6206;
    --cs-panel-ink-danger:  #a51f1f;
    font-family: var(--font-body);
    color: var(--text-body);
}
.cs-panel-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 8px 20px;
    border-bottom: 1px solid var(--border-subtle);
}
.cs-panel-count {
    font-family: var(--font-heading);
    font-size: 0.84rem;
    font-weight: 600;
    line-height: 1;
    padding: 5px 9px;
    border-radius: var(--radius-pill);
    background: var(--color-primary);
    color: var(--text-on-brand);
}
.cs-panel-count[hidden] { display: none; }
/* Tasks has no "Mark all read": with no open tasks its bar would be an empty strip */
.cs-panel-bar:has(> [data-cs-panel-count][hidden]:only-child) { display: none; }
.cs-panel-link {
    border: 0;
    background: none;
    padding: 0;
    font-family: var(--font-heading);
    font-size: 0.91rem;
    font-weight: 500;
    color: var(--text-link);
    cursor: pointer;
}
.cs-panel-link:hover { text-decoration: underline; }
.cs-panel-link:disabled { color: var(--cs-gray-400); cursor: default; text-decoration: none; }
.cs-panel-markall { margin-left: auto; }
.cs-panel-group {
    padding: 16px 20px 8px;
    font-family: var(--font-heading);
    font-size: 0.77rem;
    font-weight: 600;
    letter-spacing: var(--ls-overline);
    text-transform: uppercase;
    color: var(--text-muted);
}
.cs-panel-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 20px;
    border: 0;
    background: transparent;
    text-align: left;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-standard);
}
a.cs-panel-row:hover, a.cs-panel-row:focus { color: inherit; text-decoration: none; }
.cs-panel-row:hover { background: var(--surface-page); }
.cs-panel-row:focus-visible { outline: none; box-shadow: inset var(--shadow-focus); }
.cs-panel-item.is-unread > .cs-panel-row { background: var(--surface-tint); }
.cs-panel-icon {
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 16px;
}
.cs-panel-icon--b { background: var(--cs-blue-100);  color: var(--cs-blue-700); }
.cs-panel-icon--g { background: var(--cs-green-100); color: var(--cs-panel-ink-success); }
.cs-panel-icon--r { background: var(--cs-red-100);   color: var(--cs-panel-ink-danger); }
.cs-panel-icon--a { background: var(--cs-amber-100); color: var(--cs-panel-ink-warning); }
.cs-panel-icon--n { background: var(--cs-gray-100);  color: var(--cs-gray-600); }
.cs-panel-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cs-panel-title,
.cs-panel-sub {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cs-panel-title {
    font-family: var(--font-heading);
    font-size: 0.98rem;
    font-weight: 500;
    line-height: var(--lh-snug);
    color: var(--text-body);
}
.cs-panel-item.is-unread .cs-panel-title { font-weight: 600; color: var(--text-strong); }
.cs-panel-sub { font-size: 0.875rem; line-height: 1.4; color: var(--text-muted); }
.cs-panel-when { flex: 0 0 auto; font-size: 0.84rem; color: var(--text-muted); white-space: nowrap; }
.cs-panel-dot { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--color-primary); }
.cs-panel-detail {
    margin: 0 20px 8px 66px;
    padding: 10px 12px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: var(--surface-card);
    font-size: 0.91rem;
    line-height: var(--lh-normal);
    overflow-x: auto;
}
.cs-panel-detail[hidden] { display: none; }
.cs-panel-detail-body ul { margin: 0; padding-left: 18px; }
.cs-panel-detail-body a { color: var(--text-link); }
.cs-panel-detail-actions { margin-top: 8px; }
.cs-panel-pill {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px 3px 8px;
    border-radius: var(--radius-pill);
    font-family: var(--font-heading);
    font-size: 0.805rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
}
.cs-panel-pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; }
.cs-panel-pill--overdue { background: var(--cs-red-100);   color: var(--cs-panel-ink-danger); }
.cs-panel-pill--overdue::before { background: var(--cs-red); }
.cs-panel-pill--due     { background: var(--cs-amber-100); color: var(--cs-panel-ink-warning); }
.cs-panel-pill--due::before { background: var(--cs-amber); }
.cs-panel-pill--draft   { background: var(--cs-gray-100);  color: var(--cs-gray-600); }
.cs-panel-pill--draft::before { background: var(--cs-gray-400); }
.cs-panel-loading { padding: 32px 20px; font-size: 0.91rem; color: var(--text-muted); text-align: center; }
.cs-panel-empty { padding: 56px 32px 60px; text-align: center; }
.cs-panel-empty-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 14px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--surface-tint);
    color: var(--color-primary);
    font-size: 24px;
}
.cs-panel-empty-title {
    margin: 0 0 6px;
    font-family: var(--font-heading);
    font-size: 1.12rem;
    font-weight: 600;
    color: var(--text-strong);
}
.cs-panel-empty-text { margin: 0; font-size: 0.98rem; color: var(--text-muted); }
.cs-panel-viewall {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0 auto;
    font-family: var(--font-heading);
    font-size: 0.98rem;
    font-weight: 500;
    color: var(--text-link);
    text-decoration: none;
}
.cs-panel-viewall:hover { color: var(--color-primary-hover); text-decoration: underline; }

/* [P-887] Phone width: top bar and page gutter. The header is inline-styled in layout_header.tpl, so these
   need !important. The logo, divider and mark go (the company name stays); the icon group tightens so the
   bar fits a 390 screen instead of spilling 46px past it. */
@media (max-width: 575.98px) {
    #dc-root .sc-host > div > header { padding: 0 12px !important; gap: 8px !important; }
    #dc-root .sc-host > div > header > span { display: none !important; }
    #dc-root .sc-host > div > header > div[style*="margin-left: auto"] { gap: 8px !important; }
    #dc-root .sc-host > div > main { padding-left: 12px !important; padding-right: 12px !important; }
}

/* [P-887] Drawer width (<= 768px, see page_list_sidebar.tpl): the nav is a slide-in drawer, so the 56px
   logo/rail column of the shell grid is a blank white strip down the left of the page. Collapse it and
   drop its logo cell. The hamburger is Bootstrap d-md-none (hidden from 768px) but the drawer starts at
   768px inclusive, so at exactly 768 (iPad portrait) there was no way to open the nav: show it there. */
@media (max-width: 768px) {
    #dc-root .sc-host > div { grid-template-columns: 0 minmax(0, 1fr) !important; }
    #dc-root .sc-host > div > div:first-child { display: none !important; }
    #dc-root .sc-host > div > header > button.d-md-none { display: inline-flex !important; }
}

/* [P-887] Rob 2026-11-24: no full-screen button on phones and tablets (the maximize icon is the first
   svg in the top bar). At drawer width the divider goes too and the Cornerstone mark stays in its place;
   on a phone the company name gives way to the mark (above, <= 575px). */
@media (max-width: 1024px) {
    #dc-root .sc-host > div > header > svg { display: none !important; }
}
@media (max-width: 768px) {
    #dc-root .sc-host > div > header > div:not([style*="margin-left: auto"]) { display: none !important; }
}
@media (max-width: 768px) {
    /* the header img is 0 wide on desktop (layout_header.tpl, P-985); at drawer width it shows the logo.
       Desktop untouched. */
    #dc-root .sc-host > div > header > img { content: url("../img/cs_logo.svg"); height: 28px !important; width: auto !important; }
}

/* [P-887] Reveal drawers on a phone. cornerstone.css gives `.modal-sidebar.modal-md` width:50%, so the
   Notifications and Tasks panels (and any other md drawer) were 195px of a 390px screen with their text
   cut to "WT2...". Under 576px a drawer takes the screen width; from 576px up the 50% step stands. */
@media (max-width: 575.98px) {
    .modal .modal-dialog.modal-sidebar { width: 100%; max-width: 100%; }
}

/* [P-887] Phones only (<= 575px): buttons and navigation get a 40px minimum hit area (the measured
   targets were 20-36px). Padding-free: min-height/min-width only, so icon-only buttons keep their glyph
   size. Text sizes are deliberately left alone (listed in the findings file). */
@media (max-width: 575.98px) {
    .btn, button.close, .cs-nav a, .cs-navitem > a, .cs-flyout a,
    #dc-root .sc-host > div > header .nav-link,
    #dc-root .sc-host > div > header .nav-item > a { min-height: 40px; min-width: 40px; display: inline-flex; align-items: center; justify-content: center; }
    .cs-nav a, .cs-navitem > a, .cs-flyout a { justify-content: flex-start; display: flex; }
}
@media (max-width: 575.98px) {
    /* the menu button carries inline width/height:36px */
    #dc-root .sc-host > div > header > button { width: 40px !important; height: 40px !important; }
}

/* [PF-1] close button on a blue modal or drawer bar: white at every width (its place is phone only, AD-8) */
.modal-header.bg-primary .btn-close { filter: brightness(0) invert(1); opacity: 1; }

/* [P-973] Phone width: single views (AD-1). Every single page (order, invoice, works order, stock item,
   supplier, customer) is .cs-container with inline grid tracks, so its cards kept their desktop columns
   at 390px and ran under the metadata rail. Inline styles, so !important. Same 767.98px step as the form
   rows (cs-forms.css, P-887): pairs become one column, 3 and 4 tracks become two. */
@media (max-width: 767.98px) {
    .cs-container > * [style*="grid-template-columns:"] > * { min-width: 0; }
    .cs-container > * [style*="grid-template-columns:1.1fr 1fr"],
    .cs-container > * [style*="grid-template-columns:1fr 320px"],
    .cs-container > * [style*="grid-template-columns:1fr 1fr; gap:40px"],
    .cs-container > * [style*="grid-template-columns:1fr 1fr; gap:22px"] { grid-template-columns: minmax(0, 1fr) !important; }
    .cs-container > * [style*="grid-template-columns:repeat("] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .cs-container > * [style*="width:360px"] { width: 100% !important; }
    .cs-container .cs-kv-value { overflow-wrap: anywhere; }
}
@media (max-width: 575.98px) {
    .cs-container.d-grid { column-gap: 10px !important; }
    .cs-container > * [style*="padding:26px"] { padding: 16px !important; }
    .cs-container .d-flex:has(> .cs-layout-seg) { flex-wrap: wrap; max-width: 100%; }
    .cs-layout-seg { max-width: 100%; }
    .cs-doc-variant > .d-flex { flex-wrap: wrap; }
    .cs-layout-seg button { padding-left: 8px !important; padding-right: 8px !important; }
    /* AD-3: the record name chip beside "Entry Details" */
    .cs-container h2 > .badge { white-space: normal; overflow-wrap: anywhere; text-align: left; line-height: 1.35; border-radius: var(--radius-sm); }
    /* AD-2: a tab row takes a second line, so the last tab is never cut */
    .nav-pills.flex-nowrap { flex-wrap: wrap !important; }
    /* AD-4: Filter builder condition row, stacked */
    .filter-builder-condition > div { flex: 0 0 100%; max-width: 100%; }
    .filter-builder-condition > div:not(.filter-builder-condition-actions) { margin-bottom: 8px; }
    /* AD-6: the quick search icons are 40px on a phone (above) */
    .js-quick-filter input.has-icon-left { padding-left: 56px; }
    .js-quick-filter input.form-control.has-icon-right { padding-right: 56px; text-overflow: ellipsis; }
    /* AD-8: close button on a blue modal or drawer bar */
    .modal-header.bg-primary .btn-close { margin: 0 -8px 0 auto; padding: 0; align-self: center; justify-content: center; background-position: center; filter: brightness(0) invert(1); opacity: 1; }
    .modal-sidebar .modal-header button.close:not(.alert-close) { top: 4px; right: 8px; }
}

/* [P-1000] Phone width: supplier contact card, status cards, Risk Matrix rows (DR2-1 to DR2-3). Inline
   styles again, so !important. A span of 3 in the two-track grid of P-973 made a third, auto track that
   took the width of the other two. Nothing here applies from 768px up. */
@media (max-width: 767.98px) {
    .cs-container > * [style*="grid-column:span 3"] { grid-column: 1 / -1 !important; }
    /* parts/status_card.tpl: three a row, two under 576px */
    .row[style*="flex-wrap: nowrap"]:has(> .col .stat-widget) { flex-wrap: wrap !important; justify-content: flex-start !important; }
    .row[style*="flex-wrap: nowrap"] > .col:has(.stat-widget) { flex: 0 0 33.3333%; max-width: 33.3333%; }
    /* System Options, Risk Matrix editor: short boxes on the first line, the description on its own line */
    .cs-rm-scale, .cs-rm-scale tbody, .cs-rm-bands, .cs-rm-bands tbody { display: block; }
    .cs-rm-scale tr, .cs-rm-bands tr { display: flex; flex-wrap: wrap; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border-subtle); }
    .cs-rm-scale td, .cs-rm-bands td { flex: 0 0 auto; }
    .cs-rm-scale td:last-child, .cs-rm-bands td:last-child { width: auto !important; margin-left: auto; }
    .cs-rm-scale td:nth-child(2), .cs-rm-bands td:nth-child(3) { flex: 1 1 0; min-width: 0; width: auto !important; }
    .cs-rm-scale td:nth-child(3) { order: 1; flex: 0 0 100%; }
    .cs-rm-bands td:nth-child(-n+2) { width: 76px !important; }
    .cs-rm-bands td:nth-child(4) { flex: 0 0 100%; }
}
@media (max-width: 575.98px) {
    .row[style*="flex-wrap: nowrap"] > .col:has(.stat-widget) { flex: 0 0 50%; max-width: 50%; }
}
