/* Batchline order editor demo, built on nsui.js. Framework-free: index.html, this file and batchline.js.
   Each section below names the Batchline source it mirrors (netsuite-order-desk, file:line). The NSUI
   custom elements are themed only through their public --nsui-* tokens and ::part() hooks. */

/* ---- Theme. Mirrors spa/assets/batchline.css:2-21 (tokens, base type).
   --bl-*: the Batchline tokens; the page-markup parts read only these.
   --nsui-*: the public NSUI tokens set to the same values, so the real NSUI components match. */
:root {
  --bl-ground: #F5F4F2;
  --bl-surface: #FFFFFF;
  --bl-surface-sunk: #FAF9F7;
  --bl-surface-tint: #FCFBFA;
  --bl-border: #E5E2DD;
  --bl-border-soft: #EFEDE9;
  --bl-border-strong: #D4D0C9;
  --bl-text: #1A1816;
  --bl-text-muted: #5E5952;
  --bl-text-faint: #77716A;
  --bl-primary: #24586A;
  --bl-primary-hover: #1B4553;
  --bl-focus: #2B7A92;
  --bl-edited-bg: #FDF3E6;
  --bl-edited-fg: #8A4B0F;
  --bl-edited-dot: #D9822B;
  --bl-danger-bg: #FBEEEC;
  --bl-danger-fg: #A1281F;
  --bl-danger-dot: #C2473D;
  --bl-success-fg: #23663F;
  --bl-info-bg: #E8F0F3;
  --bl-info-fg: #1F4E5E;
  --bl-neutral-bg: #F1EEE9;
  --bl-neutral-fg: #4E4943;
  --bl-radius-sm: 4px;
  --bl-radius-md: 6px;
  --bl-radius-lg: 8px;
  --bl-h-tool: 34px;
  --bl-h-cell: 32px;
  --bl-shadow-pop: 0 12px 32px rgba(26,24,22,.14), 0 2px 6px rgba(26,24,22,.06);
  --bl-font: 'Oracle Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --nsui-font: var(--bl-font);
  --nsui-font-size: 13px;
  --nsui-font-size-sm: 12px;
  --nsui-bg: #FFFFFF;
  --nsui-bg-subtle: #FAF9F7;
  --nsui-bg-muted: #EFEDE9;
  --nsui-fg: #1A1816;
  --nsui-fg-muted: #5E5952;
  --nsui-fg-subtle: #77716A;
  --nsui-border: #E5E2DD;
  --nsui-border-strong: #D4D0C9;
  --nsui-ring: #2B7A92;
  --nsui-focus: 0 0 0 3px rgba(43, 122, 146, .18);
  --nsui-accent: #24586A;
  --nsui-accent-hover: #1B4553;
  --nsui-accent-soft: #F1EEE9;
  --nsui-on-accent: #FFFFFF;
  --nsui-warning: #8A4B0F;
  --nsui-warning-soft: #FDF3E6;
  --nsui-danger: #A1281F;
  --nsui-danger-soft: #FBEEEC;
  --nsui-success: #23663F;
  --nsui-success-soft: #EAF5EE;
  --nsui-info: #1F4E5E;
  --nsui-info-soft: #E8F0F3;
  --nsui-radius: 6px;
  --nsui-radius-lg: 8px;
  --nsui-control-height: 34px;
  --nsui-pad-x: 10px;
  --nsui-row-height: 40px;
  /* The open line's detail sits under its row, inside the scroll area, as in Batchline. 457px keeps the
     demo about 12% shorter than the first version; the starting heights in site/components/home/hero-grid.tsx match it. */
  --nsui-grid-max-height: 457px;
  --nsui-shadow-thumb: 0 1px 2px rgba(26, 24, 22, .1);
  --nsui-shadow-lg: var(--bl-shadow-pop);
  color-scheme: light;
}

/* ---- Base. The page is the app: always light, on Batchline's ground, no margin beyond .bl-page padding.
   The reset matches the docs site's (Tailwind preflight), so the page looks the same framed there or alone. */
html, body { margin: 0; background: var(--bl-ground); }
*, ::before, ::after { box-sizing: border-box; border: 0 solid; margin: 0; padding: 0; }
h1, h2, h3, h4, h5, h6 { font-size: inherit; font-weight: inherit; }
a { color: inherit; text-decoration: inherit; }
button, input, select { font: inherit; color: inherit; background-color: transparent; border-radius: 0; }
svg { display: block; vertical-align: middle; }

/* ---- Page frame. Mirrors spa/assets/batchline.css:31-36 (.bl-page) and :68-73 (.bl-hastip tooltips). */
.blx { display: flex; flex-direction: column; gap: 16px; padding: 18px 32px 48px; background: var(--bl-ground);
  color: var(--bl-text); font-family: var(--bl-font); font-size: 13px; line-height: 1.4; }
.blx svg.lucide { flex: none; stroke-width: 1.75; }
.blx .num { font-variant-numeric: tabular-nums; }
.blx .vsep { flex: none; width: 1px; height: 20px; background: var(--bl-border); }
.blx :focus-visible { outline: 2px solid var(--bl-focus); outline-offset: 2px; }
.blx button { font: inherit; cursor: pointer; }
/* Tooltip from data-tip, as .bl-hastip: dark chip under the control, after 400ms. */
.blx .tip { position: relative; }
.blx .tip::after { content: attr(data-tip); position: absolute; top: calc(100% + 6px); left: 50%; z-index: 30; padding: 5px 8px;
  border-radius: var(--bl-radius-sm); background: var(--bl-text); color: #fff; font-size: 12px; font-weight: 500; line-height: 1.4;
  white-space: pre; opacity: 0; transform: translate(-50%, -2px); pointer-events: none;
  transition: opacity .12s ease, transform .12s ease; }
.blx .tip:hover::after { opacity: 1; transform: translate(-50%, 0); transition-delay: .4s; }
.blx .tip:focus-within::after { opacity: 1; transform: translate(-50%, 0); }
/* At the right edge the chip aligns to the control's right side, so it never runs past the page. */
.blx .tip--end::after { left: auto; right: 0; transform: translate(0, -2px); }
.blx .tip--end:hover::after, .blx .tip--end:focus-within::after { transform: none; }
@media (prefers-reduced-motion: reduce) { .blx .tip::after { transition: none; } }
/* The grid look from netsuite-order-desk DESIGN.md §3i, through the grid tokens: sunk 600 muted header, cell dividers,
   alternate row, amber edited cells. Its toolbar gives way to the Batchline toolbar, and its frame sits flush. */
.blx nsui-data-grid {
  --nsui-font-size: 12px;
  --nsui-grid-header-bg: var(--bl-surface-sunk);
  --nsui-grid-header-fg: var(--bl-text-muted);
  --nsui-grid-header-weight: 600;
  --nsui-grid-divider: #F1EFEC;
  --nsui-grid-stripe: #FDFCFB;
  --nsui-grid-edited-bg: var(--bl-edited-bg);
}
.blx nsui-data-grid::part(toolbar) { display: none; }
.blx nsui-data-grid::part(frame) { border: 0; border-radius: 0; }
/* The order card (.bl-card, batchline.css:138, :1436): its corner squares off under the first tab when that tab is on. */
.blx .bl-card--first::part(root) { border-top-left-radius: 0; }
.blx .bl-empty { margin: 0; padding: 40px 16px; text-align: center; color: var(--bl-text-muted); }
@media (max-width: 760px) { .blx { padding: 14px 12px 24px; } }

/* ---- top-bar. Batchline page header: title, then "Transaction Search", the search box, Add and reload on one row.
   Mirrors netsuite-order-desk spa/app/mount.ts:539-552 and spa/assets/batchline.css:35-48 (.bl-header,
   .bl-h1, .bl-search-block, .bl-search-row, .bl-label, .bl-search, .bl-input--lg) and :53-54 (.bl-btn). */
.blx {
  /* Deviation from Batchline (align-items: flex-end): the user asked for the title and the search row to share one
     centre line. The header still starts 18px below the top, as in Batchline. */
  .bl-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
  .bl-h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -.01em; line-height: 1.4; }
  .bl-search-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .bl-label { font-size: 12px; font-weight: 500; color: var(--bl-text-muted); }
  .bl-search { position: relative; display: inline-flex; align-items: center; }
  .bl-search > svg { position: absolute; left: 10px; z-index: 1; color: var(--bl-text-faint); pointer-events: none; }
  .bl-search nsui-input::part(input) { padding-left: 34px; }
  .bl-search--lg nsui-input { width: 220px; --nsui-control-height: 36px; }
  .bl-btn-lg::part(button) { height: 38px; padding: 0 16px; }
  .bl-btn-lg::part(button):hover { background: var(--bl-ground); }
  .bl-iconbtn::part(button) { width: 36px; height: 36px; padding: 0; color: var(--bl-text-muted); }
  .bl-iconbtn::part(button):hover { background: #EAE7E2; }
}

/* ---- order-tabs. Order tabs: one trapezoid tab per open order (number, customer, edited ring and count, close), then
   "Add orders". Mirrors netsuite-order-desk spa/app/orderTabs.ts:52-56 and :125-144, and
   spa/assets/batchline.css:1433-1488 (.bl-otabs, .bl-otab, .bl-otab-b, .bl-otab-acc, .bl-otab-x, .bl-otabs-add)
   with the edited ring from :116 and :126-127 (.bl-slot, .bl-mring--edited). */
.blx {
  .bl-otabs { position: relative; z-index: 1; display: flex; align-items: stretch; min-height: 40px; margin-bottom: -16px; }
  .bl-otabs-list { display: flex; align-items: flex-end; flex: 0 1 auto; min-width: 0; overflow: hidden; padding-bottom: 1px; margin-bottom: -1px; }
  .bl-otab { --fill: var(--bl-surface-sunk); position: relative; z-index: 0; flex: none; display: flex; align-items: center; height: 40px; margin-left: -10px; }
  .bl-otab:first-child { margin-left: 0; }
  .bl-otab::before, .bl-otab::after { content: ''; position: absolute; top: 0; bottom: 0; z-index: -1; background: var(--fill);
    border: 1px solid var(--bl-border); border-bottom: 0; transition: background-color .12s ease; }
  .bl-otab::before { left: 0; right: 40%; border-right: 0; border-top-left-radius: var(--bl-radius-md); transform-origin: bottom; transform: skewX(-15deg); }
  .bl-otab::after { left: 40%; right: 0; border-left: 0; border-top-right-radius: var(--bl-radius-md); transform-origin: bottom; transform: skewX(15deg); }
  .bl-otab:hover { --fill: var(--bl-surface-tint); }
  .bl-otab.is-on { --fill: var(--bl-surface); z-index: 1; }
  .bl-otab.is-on::before, .bl-otab.is-on::after { bottom: -1px; }
  .bl-otab:has(.bl-otab-b:focus-visible) { z-index: 2; }
  .bl-otab:has(.bl-otab-b:focus-visible)::before, .bl-otab:has(.bl-otab-b:focus-visible)::after { bottom: 0; border: 2px solid var(--bl-focus); }
  .bl-otab:has(.bl-otab-b:focus-visible)::before { border-right: 0; }
  .bl-otab:has(.bl-otab-b:focus-visible)::after { border-left: 0; }
  .bl-otab-acc { position: absolute; left: 12%; right: 12%; bottom: -1px; height: 2px; border-radius: 1px; background: var(--bl-primary);
    opacity: 0; transform: scaleX(.4); pointer-events: none;
    transition: transform 200ms cubic-bezier(.23,1,.32,1), opacity 200ms cubic-bezier(.23,1,.32,1); }
  .bl-otab.is-on .bl-otab-acc { opacity: .75; transform: none; }
  @media (hover: hover) and (pointer: fine) {
    .bl-otab:not(.is-on):hover .bl-otab-acc { opacity: .35; transform: scaleX(.6); }
    .bl-otab.is-on:hover .bl-otab-acc { opacity: .9; }
  }
  .bl-otab-b { height: 40px; display: inline-flex; align-items: center; gap: 8px; padding: 0 4px 0 26px; border: 0;
    border-radius: var(--bl-radius-md); background: transparent; color: var(--bl-text-muted); white-space: nowrap; }
  .bl-otab-b:focus-visible { outline: none; }
  .bl-otab-no { font-weight: 600; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
  .bl-otab.is-on .bl-otab-no, .bl-otab-b:hover .bl-otab-no { color: var(--bl-text); }
  .bl-otab-c { max-width: 160px; overflow: hidden; text-overflow: ellipsis; font-size: 12px; color: var(--bl-text-muted); }
  .bl-otab-st { display: inline-flex; align-items: center; gap: 6px; }
  .bl-otab-ed { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; color: var(--bl-edited-fg); font-variant-numeric: tabular-nums; }
  .bl-slot { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; }
  .bl-mring { display: block; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--bl-edited-dot); }
  .bl-otab-x { flex: none; width: 24px; height: 24px; margin: 0 18px 0 2px; display: inline-flex; align-items: center; justify-content: center;
    border: 0; border-radius: var(--bl-radius-sm); background: transparent; color: var(--bl-text-faint); transition: transform .14s cubic-bezier(.23,1,.32,1); }
  .bl-otab-x:hover { background: rgba(26,24,22,.06); color: var(--bl-text); }
  .bl-otab-x:active { transform: scale(.97); }
  .bl-otabs-add { flex: none; align-self: center; margin-left: 8px; }
  .bl-otabs-add::part(button):hover { background: var(--bl-ground); }
  @media (prefers-reduced-motion: reduce) { .bl-otab::before, .bl-otab::after { transition: none; } }
}

/* ---- header-strip. Order title line: fold caret, record type, divider, status mark, then Activity and the ⋯ menu.
   Mirrors netsuite-order-desk spa/app/headerBand.ts:410-427, spa/app/recordCard.ts:81-86 (actions) and
   spa/ui/marks.ts:43 (statusInfo: teal clock), with spa/assets/batchline.css:147-149 (.bl-rec-type, .bl-vsep),
   :238-243 (.bl-hd-top, .bl-fold), :94-96 (.bl-iconbtn) and :116-130 (.bl-slot, .bl-mk, .bl-t--info). */
.blx {
  .bl-hd-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px 12px 14px; }
  .bl-fold { width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; border: 0;
    border-radius: var(--bl-radius-sm); background: transparent; color: var(--bl-text-muted); }
  .bl-fold:hover { background: var(--bl-neutral-bg); color: var(--bl-text); }
  .bl-fold svg { transition: transform .22s cubic-bezier(.23,1,.32,1); }
  .bl-fold.is-open svg { transform: rotate(90deg); }
  .bl-rec-type { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--bl-primary); }
  .bl-mk { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
  .bl-mk .bl-slot { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; color: var(--bl-focus); }
  /* Level with the capitals of the status text: the line box's middle is about .06em above them. */
  .bl-mk .bl-slot svg { transform: translateY(.06em); }
  .bl-t--info { color: var(--bl-info-fg); font-weight: 500; }
  .bl-spacer { flex: 1 1 auto; }
  .bl-rec-actions { display: flex; align-items: center; gap: 4px; }
  .bl-rec-actions nsui-button::part(button) { width: 36px; height: 36px; padding: 0; color: var(--bl-text-muted); }
  .bl-rec-actions nsui-button::part(button):hover { background: #EAE7E2; }
}

/* ---- header-field. One header field in the summary band: label above value. Editable values are an inline button that shows a
   border and a pencil on hover; fixed values are static, with a lock when NetSuite will not let them change.
   Mirrors netsuite-order-desk spa/app/headerBand.ts:196-228 (headerField, staticField) and
   spa/assets/batchline.css:211-230 (.bl-hf, .bl-hf-l, .bl-hv, .bl-hv-pen, .bl-hv-t, .bl-hv-static) and :304 (.bl-hv-lock). */
.blx {
  .bl-hf { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .bl-hf-l { font-size: 12px; color: var(--bl-text-muted); padding-left: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* Labels with an info tip must not clip: the tip's chip draws above the label. */
  .bl-hf-l.bl-trow-tip { display: inline-flex; align-items: center; gap: 5px; overflow: visible; }
  .bl-hv { display: flex; align-items: center; gap: 6px; width: 100%; min-width: 0; height: 30px; margin: 0; padding: 0 6px;
    border: 1px solid transparent; border-radius: var(--bl-radius-md); background: transparent; font: inherit; font-weight: 500;
    color: var(--bl-text); text-align: left; cursor: text; transition: background-color .12s ease, border-color .12s ease; }
  .bl-hv-pen { flex: none; margin-left: auto; color: var(--bl-text-faint); opacity: 0; transition: opacity .12s ease; }
  @media (hover: hover) and (pointer: fine) {
    .bl-hv:hover { background: var(--bl-surface); border-color: var(--bl-border-strong); }
    .bl-hv:hover .bl-hv-pen { opacity: 1; }
  }
  .bl-hv:focus-visible { background: var(--bl-surface); border-color: var(--bl-focus); outline: none; box-shadow: 0 0 0 3px rgba(43,122,146,.18); }
  .bl-hv:focus-visible .bl-hv-pen { opacity: 1; }
  .bl-hv-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bl-hv-t.is-empty { color: var(--bl-text-faint); font-weight: 400; }
  .bl-hv-static { display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 7px; font-weight: 500; min-width: 0; }
  .bl-hv-static a { color: var(--bl-primary); text-decoration: none; }
  .bl-hv-static a:hover { color: var(--bl-primary-hover); text-decoration: underline; }
  .bl-hv-lock { flex: none; color: var(--bl-text-faint); }
}

/* ---- tip. Info icon with a dark tooltip above it; focusable, so keyboard users can read it too.
   Mirrors netsuite-order-desk spa/app/headerBand.ts:231-233 (tipIcon) and spa/assets/batchline.css:320-325 (.bl-tip). */
.blx {
  .bl-tip { position: relative; display: inline-flex; color: var(--bl-text-faint); cursor: help; border-radius: 50%; }
  .bl-tip::after { content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px); z-index: 30; width: max-content; max-width: 240px;
    padding: 7px 10px; border-radius: var(--bl-radius-md); background: var(--bl-text); color: #fff; font-size: 12px; font-weight: 400; line-height: 1.4;
    text-align: left; white-space: normal; box-shadow: var(--bl-shadow-pop); opacity: 0; transform: translate(-50%, 2px); pointer-events: none;
    transition: opacity .12s ease, transform .12s ease; }
  .bl-tip:hover::after, .bl-tip:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }
  .bl-tip:hover, .bl-tip:focus-visible { color: var(--bl-text-muted); }
  @media (prefers-reduced-motion: reduce) { .bl-tip::after { transition: none; } }
}

/* ---- credit-meter. Credit used and Outstanding: an 18px ring, the value, an info button; hover or focus on the button shows
   the breakdown card. Mirrors netsuite-order-desk spa/app/headerBand.ts:254-351 (ring, meterCell,
   creditFields), shared/header.ts:86-91 (outstandingText) and spa/assets/batchline.css:287-311
   (.bl-cred, .bl-cred-v, .bl-cred-i, .bl-ring-*, .bl-cred-card, .bl-cred-row, .bl-cred-sep, .bl-cred-note). */
.blx {
  .bl-cred { position: relative; }
  .bl-cred-v { display: grid; grid-template-columns: 18px 1fr; column-gap: 8px; align-items: center; justify-content: start;
    height: 30px; padding: 0 7px; font-weight: 500; color: var(--bl-text); }
  .bl-cred-v.is-muted { color: var(--bl-text-muted); }
  .bl-cred-t { white-space: nowrap; font-variant-numeric: tabular-nums; }
  .bl-cred-i { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; padding: 0;
    border: 0; border-radius: 50%; background: transparent; color: var(--bl-text-faint); }
  .bl-cred-i::before { content: ''; position: absolute; inset: -5px; }
  @media (hover: hover) and (pointer: fine) { .bl-cred-i:hover { color: var(--bl-text); } }
  .bl-ring { flex: none; display: block; }
  .bl-ring-track { stroke: #DCD7CF; }
  .bl-ring-ok { stroke: var(--bl-focus); }
  .bl-ring-near { stroke: var(--bl-edited-dot); }
  .bl-ring-over { stroke: var(--bl-danger-dot); }
  .bl-ring circle.is-added { opacity: .45; }
  .bl-cred-card { position: absolute; left: 0; top: calc(100% + 4px); z-index: 25; width: max-content; min-width: 280px; max-width: 360px;
    padding: 12px 14px; border: 1px solid var(--bl-border); border-radius: var(--bl-radius-lg); background: var(--bl-surface);
    box-shadow: var(--bl-shadow-pop); font-size: 13px; line-height: 1.45; color: var(--bl-text); opacity: 0; transform: scale(.97);
    transform-origin: top left; pointer-events: none;
    transition: opacity .16s cubic-bezier(.23,1,.32,1), transform .16s cubic-bezier(.23,1,.32,1); }
  .bl-cred:has(.bl-cred-i:hover) .bl-cred-card { transition-delay: .15s; }
  .bl-cred:has(.bl-cred-i:hover) .bl-cred-card, .bl-cred:has(.bl-cred-i:focus) .bl-cred-card, .bl-cred-card:hover {
    opacity: 1; transform: none; pointer-events: auto; }
  .bl-cred-row { display: flex; justify-content: space-between; align-items: baseline; gap: 24px; padding: 4px 0; color: var(--bl-text-muted); white-space: nowrap; }
  .bl-cred-row .num { color: var(--bl-text); font-weight: 600; text-align: right; }
  .bl-cred-row.is-bad, .bl-cred-row.is-bad .num { color: var(--bl-danger-fg); }
  .bl-cred-sep { height: 1px; margin: 6px 0; background: var(--bl-border-soft); }
  .bl-cred-note { white-space: nowrap; color: var(--bl-text-muted); }
  @media (prefers-reduced-motion: reduce) { .bl-cred-card { transform: none; transition: opacity .16s; } }
}

/* ---- totals-card. Totals card at the right of the summary band: Memo, Subtotal, Shipping and Tax (with info tips), then the
   working total. Mirrors netsuite-order-desk spa/app/headerBand.ts:353-383 (totalsPanel, memoRow) and
   spa/assets/batchline.css:246-256 (.bl-hd-memorow, memo in the totals), :316-327 (.bl-hd-totals, .bl-trow)
   and the shared Tip and EditableValue parts. */
.blx {
  .bl-hd-totals { flex: 1 1 360px; min-width: 320px; max-width: 440px; margin-left: auto; padding: 16px 24px; border-left: 1px solid var(--bl-border);
    background: var(--bl-surface); display: flex; flex-direction: column; justify-content: flex-start; gap: 5px; }
  .bl-hd-memorow { flex: none; display: flex; align-items: center; gap: 8px; min-width: 0; padding: 0 0 8px; margin-bottom: 4px; border-bottom: 1px solid var(--bl-border-soft); }
  .bl-memo-i { flex: none; color: var(--bl-text-muted); }
  .bl-memo-l { flex: none; font-weight: 600; color: var(--bl-text); }
  .bl-memo-f { flex: 1 1 auto; min-width: 0; }
  .bl-memo-f .bl-hv { font-weight: 400; }  /* .bl-hv comes from header-field.tsx */
  .bl-trow { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
  .bl-trow-l { color: var(--bl-text-muted); }
  .bl-trow-tip { display: inline-flex; align-items: center; gap: 5px; }
  .bl-trow .num { font-variant-numeric: tabular-nums; }
  .bl-trow--total { margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--bl-border); font-weight: 600; }
  .bl-trow--total .num { font-size: 20px; display: inline-flex; align-items: baseline; gap: 8px; white-space: nowrap; }
}

/* ---- summary-band. Summary band under the title line: Customer, Order and Segments groups, then the totals card.
   Mirrors netsuite-order-desk spa/app/headerBand.ts:436-458 (the band and its groups) and :236-245 (profitFields),
   and spa/assets/batchline.css:244-245 (.bl-hd-band, .bl-hd-groups) and :257-266 (.bl-hd-grp, .bl-hd-h, .bl-hd-grid). */
.blx {
  .bl-hd-band { --bl-hcol: 96px; container: bl-band / inline-size; display: flex; flex-wrap: wrap; align-items: stretch;
    background: var(--bl-surface-sunk); border-top: 1px solid var(--bl-border); border-bottom: 1px solid var(--bl-border); }
  /* Deviation from Batchline: each group sizes to its content (no truncated dates or names) and the
     groups wrap only when that content does not fit. Batchline's fixed bases wrapped Segments at 1440px. */
  .bl-hd-groups { flex: 999 1 680px; min-width: 0; display: flex; flex-wrap: wrap; align-items: stretch; }
  .bl-hd-grp { flex: 1 1 max-content; min-width: 0; display: flex; flex-direction: column; justify-content: flex-start;
    gap: 12px; padding: 16px 24px 20px; border-left: 1px solid var(--bl-border); }
  .bl-hd-grp:first-child { border-left: 0; }
  .bl-hd-h { align-self: flex-start; margin: 0 0 0 7px; padding: 7px 0 4px; line-height: 16px; border-bottom: 1px solid var(--bl-border-strong);
    font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--bl-text-muted); }
  .bl-hd-grid { flex: 1 1 auto; display: grid; grid-template-columns: repeat(2, auto); gap: 10px 12px; align-content: space-evenly; }
  .bl-hd-grid--3 { grid-template-columns: repeat(3, auto); }
  /* Segments: wider columns, so Department and Class do not crowd each other. */
  .bl-hd-grp:nth-child(3) .bl-hd-grid { grid-template-columns: repeat(2, minmax(96px, auto)); column-gap: 24px; }
  /* Order and ship dates use the NSUI calendar input, sized to the 30px header values. */
  .bl-hd-date { --nsui-control-height: 30px; --nsui-pad-x: 6px; --nsui-font-size: 12px; width: 114px; margin-left: 7px; }  /* 7px: in line with the label */
  /* The credit column takes only its content's width, so each info icon sits 8px after the widest value
     (Batchline :266, minmax(max-content, 1fr)). Stretched, the 1fr in .bl-cred-v pushed the icons far right. */
  @media (min-width: 761px) { .bl-hd-grp--3:first-child .bl-hd-grid--3 { grid-template-columns: auto auto max-content; } }
  /* A band of 1,400px or less (about a 1440px window) gets tighter spacing, so all three groups fit on one row. */
  @container bl-band (max-width: 1400px) {
    .bl-hd-grp { padding: 16px 14px 20px; }
    .bl-hd-grid { column-gap: 8px; }
    .bl-hd-grp:nth-child(3) .bl-hd-grid { grid-template-columns: repeat(2, auto); column-gap: 16px; }
    .bl-hd-totals { flex-basis: 320px; }
  }
  @media (max-width: 760px) {
    .bl-hd-grp { border-left: 0; border-top: 1px solid var(--bl-border); }
    .bl-hd-grp:first-child { border-top: 0; }
    .bl-hd-grid, .bl-hd-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .bl-hd-totals { min-width: 0; max-width: none; border-left: 0; border-top: 1px solid var(--bl-border); }
  }
}

/* ---- line-toolbar. Line toolbar: Undo and Redo, the line filter, Filter and View tools, the Add line split, Actions, Stock, then
   the All / Edited segments at the right. Mirrors netsuite-order-desk spa/app/toolbar.ts:162-184 (segments),
   :404-445 (the bar), :447-470 (addLineButton) and :508-520 (stockButton), with spa/assets/batchline.css:461-471
   (.bl-toolbar, .bl-seg), :53-65 (.bl-btn, .bl-btn--tool, .bl-btn--icon), :1018-1051 (.bl-tb-end, .bl-stock-btn,
   .bl-split, widths) and :1551-1553 (.bl-split). */
.blx {
  .bl-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; padding: 12px 16px; border-top: 1px solid var(--bl-border);
    background: var(--bl-surface-tint); }
  .bl-toolbar > * { flex-shrink: 0; }
  .bl-tb-group { display: flex; align-items: center; gap: 2px; }
  .bl-tb-sep { height: 24px; margin-left: 6px; }
  .bl-search--filter { position: relative; display: inline-flex; align-items: center; flex: 1 1 240px; max-width: 340px; min-width: 140px; }
  .bl-toolbar > .bl-search--filter { flex-shrink: 1; }
  .bl-search--filter > svg { position: absolute; left: 10px; z-index: 1; color: var(--bl-text-faint); pointer-events: none; }
  .bl-search--filter nsui-input { width: 100%; }
  .bl-search--filter nsui-input::part(input) { padding-left: 34px; }
  .bl-tool::part(button):hover { background: var(--bl-ground); }
  .bl-tool--icon::part(button) { width: 34px; padding: 0; }
  .bl-tool--ghost::part(button) { color: var(--bl-text); }
  .bl-tool--ghost::part(button):hover { background: #EAE7E2; }
  .bl-split { display: inline-flex; }
  .bl-split nsui-button::part(button) { font-weight: 600; }
  .bl-split nsui-button:first-child::part(button) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
  .bl-split nsui-button + nsui-button { margin-left: -1px; }
  .bl-split nsui-button + nsui-button::part(button) { border-top-left-radius: 0; border-bottom-left-radius: 0; padding: 0 7px;
    border-left-color: rgba(255,255,255,.35); color: rgba(255,255,255,.85); }
  .bl-view-caret { color: var(--bl-text-faint); margin-left: -2px; }
  .bl-stock-btn::part(button) { padding: 0 10px; gap: 6px; }
  .bl-mk { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
  .bl-mk-slot { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; color: var(--bl-danger-fg); }
  .bl-mk-slot svg { transform: translateY(-1px); }
  .bl-tb-short { color: var(--bl-danger-fg); font-weight: 600; font-variant-numeric: tabular-nums; }
  .bl-tb-end { margin-left: auto; display: flex; align-items: center; gap: 12px; min-width: 0; }
  .bl-seg::part(panels) { display: none; }
  .bl-seg::part(tablist) { padding: 3px; gap: 2px; border-radius: var(--bl-radius-md); }
  .bl-seg::part(tab) { height: 28px; padding: 0 10px; border-radius: var(--bl-radius-sm); }
  @media (max-width: 1600px) {
    .bl-search--filter { flex-basis: 200px; }
    .bl-tb-end { gap: 10px; }
    .bl-seg::part(tab) { padding: 0 8px; }
  }
  @media (max-width: 1440px) { .bl-seg::part(tab) { padding: 0 7px; } }
  @media (max-width: 1099px) { .bl-toolbar { flex-wrap: wrap; } }
}

/* ---- line-history. Batchline history for one line: a git-style rail with day headings, then entries (save-job chip, "Current",
   who and when, and a −/+ diff). Mirrors netsuite-order-desk spa/grid/detail.ts:319-350 (historyColumn),
   spa/grid/lineFacts.ts:114 (HIST sizes) and :136-189 (dayLabel, clock, historyRows), and
   spa/assets/batchline.css:1137-1172 (.bl-hv-scroll, .bl-hx-*). */
.blx {
  .bl-hv-scroll { overflow-y: auto; overscroll-behavior: contain; border-radius: var(--bl-radius-md); }
  .bl-hv-inner { position: relative; }
  .bl-hv-inner::before { content: ''; position: absolute; z-index: 0; left: 8.25px; top: 14px; bottom: 10px; width: 1.5px; background: var(--bl-border-strong); }
  .bl-hx-day, .bl-hx-e { position: relative; box-sizing: border-box; }
  .bl-hx-node { position: absolute; z-index: 1; left: 5.5px; top: 10.5px; width: 7px; height: 7px; border-radius: 50%; background: #B8B2A9; }
  .bl-hx-day-l { position: absolute; left: 22px; top: 6px; right: 0; font-size: 12px; font-weight: 600; line-height: 16px; color: #4A4540;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bl-hx-e { padding: 4px 6px 10px 36px; overflow: hidden; }
  .bl-hx-conn { position: absolute; z-index: 1; left: 0; top: -6px; overflow: visible; }
  .bl-hx-dot { position: absolute; z-index: 2; left: 25.5px; top: 13.5px; width: 5px; height: 5px; border-radius: 50%; background: #9A948C; }
  .bl-hx-dot--cur { background: var(--bl-focus); }
  .bl-hx-head { position: relative; z-index: 1; display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; height: 24px; min-width: 0; overflow: hidden; }
  .bl-hx-chip { flex: none; display: inline-flex; align-items: center; padding: 1px 6px; border-radius: var(--bl-radius-sm); background: var(--bl-neutral-bg);
    color: var(--bl-text); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; font-weight: 600; line-height: 16px; text-decoration: none; }
  .bl-hx-chip:hover { text-decoration: none; }
  .bl-hx-cur { flex: none; display: inline-flex; align-items: center; height: 18px; padding: 0 7px; border-radius: 999px; border: 1px solid var(--bl-focus);
    color: var(--bl-info-fg); font-size: 11px; font-weight: 600; }
  .bl-hx-who { min-width: 0; padding: 0 4px; font-size: 12px; line-height: 22px; color: var(--bl-text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bl-hx-diff { position: relative; z-index: 1; display: flex; flex-direction: column; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; }
  .bl-hx-df { display: flex; gap: 6px; height: 18px; line-height: 18px; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bl-hx-df:first-child { border-radius: 4px 4px 0 0; }
  .bl-hx-df:last-child { border-radius: 0 0 4px 4px; }
  .bl-hx-df:only-child { border-radius: 4px; }
  .bl-hx-df--del { background: #FBEFED; color: var(--bl-danger-fg); }
  .bl-hx-df--add { background: #EEF6F0; color: var(--bl-success-fg); }
  .bl-hx-s { flex: none; width: 8px; }
  .bl-h-empty { margin: 4px 0 0; font-size: 12px; line-height: 16px; color: #6E6861; }
}

/* ---- line-detail. Line detail, "Detailed" layout: four read-only figure columns and the history, a rule, then the line fields
   and Line status. Mirrors netsuite-order-desk spa/grid/detail.ts:40-98 (fields, Line status switch),
   :218-290 (figures, kvColumn) and :356-376 (panel), spa/grid/lineFacts.ts:16-19 and :88-97 (PANEL, DET), and
   spa/assets/batchline.css:712 (.bl-detail), :713-729 (.bl-field, .bl-switch) and :1057-1137 (.bl-dc, .bl-ro--det, .bl-kv).
   The panel is slotted into the grid's detail row, under its own line; the 96px left inset is Batchline's. */
.blx {
  .bl-detail { background: var(--bl-surface-sunk); border-top: 1px solid #BDB6AC; }
  .bl-dc { padding: 12px 24px 14px 96px; }
  .bl-ro--det { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1.6fr); align-items: start; }
  .bl-ro-col { min-width: 0; padding-right: 18px; }
  .bl-ro--det > .bl-ro-col:not(.bl-ro-col--hist) { align-self: stretch; display: flex; flex-direction: column; height: 140px; }
  .bl-ro-col--rule { border-left: 1px solid var(--bl-border); padding-left: 18px; }
  .bl-ro-col--hist { padding-right: 0; }
  .bl-ro-t { height: 22px; flex: none; display: flex; align-items: center; font-size: 12px; font-weight: 600; color: var(--bl-neutral-fg); }
  .bl-kvl { margin: 0; flex: 1 1 0; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-auto-rows: minmax(0, 1fr); }
  .bl-kv { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 0; border-bottom: 1px dashed var(--bl-border-soft); }
  .bl-kv:last-child { border-bottom: 0; }
  .bl-kv dt { display: inline-flex; align-items: center; gap: 5px; flex: none; font-size: 12px; color: var(--bl-text-muted); white-space: nowrap; }
  .bl-kv dd { flex: 1 1 0; margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; font-weight: 600;
    color: var(--bl-text); text-align: right; white-space: nowrap; }
  .bl-kv.is-zero dd { color: #6E6861; font-weight: 500; }
  .bl-kv.is-bad dt, .bl-kv.is-bad dd { color: var(--bl-danger-fg); }
  .bl-kv-note { margin-left: 1px;  /* 6px after the label with the dt's 5px gap */ font-size: 11px; color: #6E6861; }
  .bl-dc-rule { height: 1px; margin: 12px 0; background: var(--bl-border); }
  .bl-lf-fields { margin: 0; padding: 0; border: 0; min-width: 0; display: flex; flex-wrap: wrap; gap: 10px 16px; align-content: flex-start; --nsui-control-height: 32px; }
  .bl-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: none; }
  .bl-field .bl-label { display: block; height: 16px; line-height: 16px; font-size: 12px; font-weight: 500; color: var(--bl-text-muted); white-space: nowrap; }
  .bl-lf-fields nsui-input::part(label), .bl-lf-fields nsui-select::part(label) { height: 16px; line-height: 16px; font-size: 12px; font-weight: 500; color: var(--bl-text-muted); }
  .bl-lf-fields nsui-input::part(input), .bl-lf-fields nsui-select::part(select) { padding: 0 8px; }
  .bl-switch::part(root) { height: 32px; min-height: 32px; gap: 8px; padding: 0 10px 0 6px; border: 1px solid var(--bl-border-strong);
    border-radius: var(--bl-radius-md); background: var(--bl-surface); color: var(--bl-text); font-weight: 500; }
  @media (max-width: 760px) {
    /* The stacked detail is taller than the grid's scroll area, so on a phone the page scrolls instead. */
    nsui-data-grid { --nsui-grid-max-height: none; }
    .bl-dc { padding: 12px 16px 14px; }
    .bl-ro--det { grid-template-columns: minmax(0, 1fr); }
    .bl-ro--det > .bl-ro-col:not(.bl-ro-col--hist) { height: auto; padding: 0 0 12px; }
    .bl-ro-col--rule { border-left: 0; padding-left: 0; border-top: 1px solid var(--bl-border); padding-top: 8px; }
    .bl-kvl { flex: none; grid-auto-rows: 32px; }
    .bl-lf-fields > * { width: 100% !important; }
  }
}

/* ---- toolbar panels (nsui-popover). Lighter versions of Batchline's filter, view, add, actions and stock panels
   (spa/app/toolbar.ts:65-344). The popover draws the border, radius and shadow; these style the content. */
.bl-pop { --nsui-font-size: 13px; font-size: 13px; color: var(--bl-text); }
.bl-pop::part(panel) { min-width: 260px; max-width: 380px; padding: 12px 14px; }
.bl-pop-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.bl-pop-sub { display: block; font-size: 11px; color: var(--bl-text-muted); font-weight: 400; }
.bl-pop-head .bl-pop-sub { display: inline; }
.bl-pop-grp { padding: 6px 0; border-top: 1px solid var(--bl-border-soft); }
.bl-pop-h { margin: 2px 0 4px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--bl-text-muted); }
.bl-pop-row { display: flex; align-items: center; gap: 10px; min-height: 28px; }
.bl-pop-row nsui-checkbox { flex: none; }
.bl-pop-row > :nth-child(2) { margin-left: auto; }
.bl-pop-d { flex: 0 1 150px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--bl-text-muted); font-size: 12px; }
.bl-pop-n { flex: none; color: var(--bl-text-muted); font-variant-numeric: tabular-nums; }
.bl-pop-list { max-height: 280px; overflow: auto; border-top: 1px solid var(--bl-border-soft); padding-top: 4px; }
.bl-pop-note { margin: 4px 0 6px; font-size: 12px; color: var(--bl-text-muted); }
.bl-pop-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; padding-top: 10px;
  border-top: 1px solid var(--bl-border-soft); color: var(--bl-text-muted); }
.bl-link { border: 0; padding: 0; background: none; font: inherit; font-size: 12px; color: var(--bl-focus); cursor: pointer; }
.bl-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 16px; height: 16px; margin-left: 4px; padding: 0 4px;
  border-radius: 8px; background: var(--bl-focus); color: #fff; font-size: 10px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bl-menu { display: flex; flex-direction: column; margin: -6px -8px; }
.bl-menu button { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px; border: 0; border-radius: 6px; background: none;
  font: inherit; color: var(--bl-text); text-align: left; cursor: pointer; }
.bl-menu button:hover:not([disabled]) { background: var(--bl-surface-sunk); }
.bl-menu button[disabled] { color: var(--bl-text-faint); cursor: default; }
.bl-menu button.is-danger:not([disabled]) { color: var(--bl-danger-fg); }
.bl-menu kbd { margin-left: auto; font: inherit; font-size: 11px; color: var(--bl-text-muted); }
.bl-menu-sep { height: 1px; margin: 4px 0; background: var(--bl-border-soft); }
.bl-stock-row { display: grid; grid-template-columns: minmax(150px, 1fr) 64px 48px 80px; align-items: center; gap: 8px; min-height: 32px;
  padding: 2px 6px; border-radius: 6px; }
.bl-stock-row .num { text-align: right; font-variant-numeric: tabular-nums; }
.bl-stock-row .is-bad { color: var(--bl-danger-fg); font-weight: 600; }
.bl-stock-row.is-on { background: var(--bl-surface-sunk); }
.bl-stock-row--h { min-height: 24px; font-size: 11px; color: var(--bl-text-muted); }
.bl-stock-row--h span:not(:first-child) { text-align: right; }
#pop-stock::part(panel), #pop-add::part(panel) { max-width: none; }
#pop-add .bl-pop-d { flex: 1 1 200px; margin-left: 8px; }
.bl-pop nsui-checkbox { white-space: nowrap; }
.bl-pop-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; padding: 2px 0; }
.bl-pop-cols nsui-checkbox { min-height: 28px; justify-self: start; }
