/* RED staff UX foundation. Load last. Presentation only; no status or visibility rules.
   Desktop density is scoped away from the production phone apps. Existing column
   widths, workflow colors, modal geometry and [hidden] states remain authoritative. */
body:not(.weld-app):not(.rq-app) {
  --ux-focus: #a91627;
  --ux-control-line: #ccd1d9;
  --ux-muted: #616976;
  --ux-table-head: #f2f4f6;
  --ux-radius: 10px;
}
[data-theme="dark"] body:not(.weld-app):not(.rq-app),
body[data-theme="dark"]:not(.weld-app):not(.rq-app) {
  --ux-focus: #ff9ba3;
  --ux-control-line: #4c5361;
  --ux-muted: #b0b7c3;
  --ux-table-head: #22262d;
  color-scheme: dark;
}
[data-theme="light"] body:not(.weld-app):not(.rq-app),
body[data-theme="light"]:not(.weld-app):not(.rq-app) { color-scheme: light; }

/* Focus remains visible on keyboard navigation even in older components which
   reset outlines. Keep semantic action colors and their disabled states intact. */
body:not(.weld-app):not(.rq-app) :is(.app, .overlay, .cw-dialog, .iw-dialog, .sw-new-menu, .sw-draft-dialog, #newInvoiceDialog, #installAppDialog) :is(button, a, summary, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--ux-focus);
  outline-offset: 3px;
}
body:not(.weld-app):not(.rq-app) :is(.tbl, .iw-table, .sw-registry) tr[tabindex]:focus-visible {
  outline-offset: -3px;
}
body:not(.weld-app):not(.rq-app) .iw-search:focus-within {
  outline: 2px solid var(--ux-focus);
  outline-offset: 2px;
}
body:not(.weld-app):not(.rq-app) :is(.fld, .toolbar, .iw-field) :is(input, select, textarea):disabled {
  cursor: not-allowed;
}
body:not(.weld-app):not(.rq-app) :is(.app, .overlay, .cw-dialog, .iw-dialog) :is(input, select, textarea) {
  caret-color: var(--text);
}
body:not(.weld-app):not(.rq-app) :is(.uc-stat strong, .stat .v, .cpsum, .sw-money, .iw-number, .fs-price strong, .cw-payment-received) {
  font-variant-numeric: tabular-nums;
}

@media (min-width: 901px) {
  body:not(.weld-app):not(.rq-app) .app {
    --bg: #f4f5f7;
    --line: #e0e3e8;
    --hover: #f0f3f7;
    --thead-bg: var(--ux-table-head);
    --thead-tx: var(--ux-muted);
    --shadow: 0 1px 2px rgb(18 24 35 / 4%);
    --radius: 10px;
    background: var(--bg);
  }
  [data-theme="dark"] body:not(.weld-app):not(.rq-app) .app,
  body[data-theme="dark"]:not(.weld-app):not(.rq-app) .app {
    --bg: #111318;
    --line: #303641;
    --hover: #252b34;
    --shadow: 0 1px 2px rgb(0 0 0 / 12%);
  }
  body:not(.weld-app):not(.rq-app) .app > .sidebar {
    border-right: 1px solid var(--line);
    background: var(--surface);
  }
  body:not(.weld-app):not(.rq-app) .app .nav a {
    border-radius: 7px;
    padding-block: 9px;
    line-height: 1.4;
  }
  body:not(.weld-app):not(.rq-app) .app .nav a.active {
    box-shadow: none;
    background: var(--red-bg);
    color: var(--text);
  }
  body:not(.weld-app):not(.rq-app) .app .nav-sub { margin-top: 4px; }
  body:not(.weld-app):not(.rq-app) .app > .main > .topbar {
    min-height: 60px;
    border-bottom-color: var(--line);
    background: var(--surface);
    padding-inline: 20px;
    backdrop-filter: none;
  }
  body:not(.weld-app):not(.rq-app) .app > .main > .content {
    padding: 20px 24px 36px;
  }
  body:not(.weld-app):not(.rq-app) .app .page-head {
    margin-bottom: 16px;
    gap: 12px;
    align-items: center;
  }
  body:not(.weld-app):not(.rq-app) .app .page-head h1 {
    font-size: 24px;
    letter-spacing: -.02em;
    line-height: 1.25;
  }
  body:not(.weld-app):not(.rq-app) .app .page-head .sub {
    color: var(--ux-muted);
    font-size: 13px;
    line-height: 1.5;
  }
  body:not(.weld-app):not(.rq-app) .app :is(.card, .stat) {
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    border-radius: var(--ux-radius);
  }
  body:not(.weld-app):not(.rq-app) .app .stat { padding: 14px 16px; }
  body:not(.weld-app):not(.rq-app) .app .stat .v { font-size: 26px; line-height: 1.15; }
  body:not(.weld-app):not(.rq-app) .app .stats { gap: 12px; margin-bottom: 18px; }
  body:not(.weld-app):not(.rq-app) .app .card .ch { padding: 13px 16px; gap: 12px; }
  body:not(.weld-app):not(.rq-app) .app .card .ch h3 { line-height: 1.4; }
  body:not(.weld-app):not(.rq-app) .app .card .cb { padding: 14px 16px; }
  body:not(.weld-app):not(.rq-app) .app .toolbar { gap: 8px; margin-bottom: 12px; }

  /* No replacement of data grids: shrink vertical whitespace only, preserving
     plan column sizing, merged cells, expanded rows and production row colors. */
  body:not(.weld-app):not(.rq-app) .app table.tbl {
    border: 1px solid var(--line);
    box-shadow: none;
    border-radius: var(--ux-radius);
  }
  body:not(.weld-app):not(.rq-app) .app .tbl thead th {
    padding-block: 10px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--ux-muted);
    background: var(--ux-table-head);
  }
  body:not(.weld-app):not(.rq-app) .app .tbl tbody td {
    padding-block: 9px;
    font-size: 13px;
    line-height: 1.4;
    border-bottom-color: var(--line);
  }
  body:not(.weld-app):not(.rq-app) .app .tbl.plan tbody td { padding-block: 8px; }
  body:not(.weld-app):not(.rq-app) .app .tbl tbody tr.mrow td {
    padding-block: 9px;
    font-weight: 650;
  }
  body:not(.weld-app):not(.rq-app) .app .tbl td.num { color: var(--text); }
  /* Production-plan columns are counted from the end, so selection mode may
     prepend a checkbox without moving these targets. Widths override the two
     legacy 88px inline date widths; all dates and model names remain readable. */
  body:not(.weld-app):not(.rq-app) .ux-plan-scroll {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    border-radius: var(--ux-radius);
    scrollbar-gutter: stable;
  }
  body:not(.weld-app):not(.rq-app) .ux-plan-scroll > table.tbl.plan { min-width: 1360px; }
  body:not(.weld-app):not(.rq-app) .ux-plan-scroll > table.tbl.plan thead th:is(:nth-last-child(5), :nth-last-child(4)) {
    width: 108px !important;
  }
  body:not(.weld-app):not(.rq-app) .ux-plan-scroll > table.tbl.plan tbody tr:not(.mrow):not(.orow-sub) > td:is(:nth-last-child(5), :nth-last-child(4)) {
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
  body:not(.weld-app):not(.rq-app) .ux-plan-scroll > table.tbl.plan thead th:nth-last-child(8) { width: 170px !important; }
  body:not(.weld-app):not(.rq-app) .ux-plan-scroll > table.tbl.plan tbody tr:not(.mrow):not(.orow-sub) > td:nth-last-child(8) {
    white-space: normal;
    overflow-wrap: anywhere;
    max-width: none;
    text-overflow: clip;
  }
  body:not(.weld-app):not(.rq-app) .ux-plan-scroll > table.tbl.plan tbody tr:not(.mrow):not(.orow-sub) > td:nth-last-child(8) > span {
    display: block;
    line-height: 1.4;
  }

  body:not(.weld-app):not(.rq-app) .app .sw-registry td { padding-block: 10px; }
  body:not(.weld-app):not(.rq-app) .app .sw-registry small { margin-top: 3px; }
  body:not(.weld-app):not(.rq-app) .app .iw-table :is(th, td) { padding-block: 10px; }
  body:not(.weld-app):not(.rq-app) .app .iw-table th {
    background: var(--ux-table-head);
    color: var(--ux-muted);
    font-size: 12px;
    font-weight: 600;
  }
  body:not(.weld-app):not(.rq-app) .app .iw-table small { font-size: 11px; }

  /* Controls share a predictable rhythm. Do not override background/color:
     green confirmations, blue downloads and red destructive actions retain meaning. */
  body:not(.weld-app):not(.rq-app) :is(.app, .overlay, .cw-dialog) .btn {
    min-height: 38px;
    padding-block: 8px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.35;
    box-shadow: none;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
  }
  body:not(.weld-app):not(.rq-app) .app .tbl .btn { min-height: 32px; padding-block: 6px; }
  body:not(.weld-app):not(.rq-app) :is(.app, .overlay, .cw-dialog) .btn:active { transform: none; }
  body:not(.weld-app):not(.rq-app) :is(.app, .overlay, .cw-dialog) .btn.ghost { border-color: var(--ux-control-line); }
  body:not(.weld-app):not(.rq-app) :is(.app, .overlay) .chip-toggle {
    min-height: 34px;
    border-radius: 7px;
    border-style: solid;
    padding-block: 7px;
    transition: background-color .15s ease, color .15s ease, border-color .15s ease;
  }
  body:not(.weld-app):not(.rq-app) :is(.app, .overlay, .cw-dialog) .fld label {
    color: var(--ux-muted);
    font-size: 12px;
    line-height: 1.4;
  }
  body:not(.weld-app):not(.rq-app) :is(.app, .overlay, .cw-dialog) .fld :is(input, select, textarea):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]),
  body:not(.weld-app):not(.rq-app) .app .toolbar :is(input, select) {
    min-height: 38px;
    padding-block: 8px;
    border-color: var(--ux-control-line);
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.4;
  }
  body:not(.weld-app):not(.rq-app) .app :is(.sw-tabs, .uc-tabs) button {
    padding-block: 11px;
    min-height: 42px;
    font-size: 13px;
  }
  body:not(.weld-app):not(.rq-app) .app .sw-tools { margin-bottom: 14px; }
  body:not(.weld-app):not(.rq-app) .app .sw-tools select {
    min-height: 38px;
    max-width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--ux-control-line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    line-height: 1.4;
  }
  body:not(.weld-app):not(.rq-app) .customer-history-version.uc-muted {
    display: block;
    color: var(--ux-muted);
    font-size: 12px;
    line-height: 1.45;
    margin-top: 3px;
  }


  /* Customer-card layout and editing entry points are kept as implemented. */
  body:not(.weld-app):not(.rq-app) .unified-customer { font-family: var(--font); }
  body:not(.weld-app):not(.rq-app) .unified-customer .uc-body { padding: 20px; }
  body:not(.weld-app):not(.rq-app) .unified-customer .uc-tabs button { padding-block: 12px; }
  body:not(.weld-app):not(.rq-app) .unified-customer .uc-panel { border-radius: 10px; }
  body:not(.weld-app):not(.rq-app) .unified-customer .uc-row { padding-block: 12px; }
  body:not(.weld-app):not(.rq-app) .unified-customer .uc-stats { margin-bottom: 20px; }
  body:not(.weld-app):not(.rq-app) .unified-customer .uc-stat strong { line-height: 1.25; }
  body:not(.weld-app):not(.rq-app) .cw-order-card > summary { min-height: 54px; padding-block: 14px; }
  body:not(.weld-app):not(.rq-app) .cw-dialog-head { padding-block: 20px; }
  body:not(.weld-app):not(.rq-app) .cw-dialog-body { padding-block: 20px; }
  body:not(.weld-app):not(.rq-app) .cw-dialog h2 { font-size: 22px; }
  body:not(.weld-app):not(.rq-app) .cw-block { padding: 18px; }
  body:not(.weld-app):not(.rq-app) .cw-dialog-foot { padding-block: 14px; }
  body:not(.weld-app):not(.rq-app) .overlay { padding-block: 24px; }
  body:not(.weld-app):not(.rq-app) .overlay > .modal { border-radius: 14px; }
  body:not(.weld-app):not(.rq-app) .overlay .mhead .close {
    border: 1px solid var(--ux-control-line);
    box-shadow: none;
  }
  body:not(.weld-app):not(.rq-app) :is(.iw-summary, .iw-panel, .iw-tree) { border-radius: 10px; }
  body:not(.weld-app):not(.rq-app) .iw-summary { padding-block: 16px; }
  body:not(.weld-app):not(.rq-app) .iw-summary b { font-size: 24px; }
  body:not(.weld-app):not(.rq-app) .iw-list-head { padding-top: 16px; }
  body:not(.weld-app):not(.rq-app) .iw-tools { padding-block: 12px; }
  body:not(.weld-app):not(.rq-app) .iw-dialog { border-radius: 14px; }
  body:not(.weld-app):not(.rq-app) .iw-dialog :is(header, footer) { padding-block: 16px; }

  /* Operational screens refresh frequently; rows should not repeatedly fly in. */
  body:not(.weld-app):not(.rq-app) .app .content.rs-enter :is(.tbl, .tbl tbody tr, .card, .stat, .kcol) {
    animation: none;
  }
  body:not(.weld-app):not(.rq-app) .app .content.rs-enter :is(.page-head, .toolbar, .yrbar) {
    animation-duration: .16s;
    animation-delay: 0s;
  }
  body:not(.weld-app):not(.rq-app) .app :is(.stat, .kcard, .fs-card):hover {
    transform: none;
  }
  body:not(.weld-app):not(.rq-app) .overlay .doctile:hover { transform: none; }
}

/* Keep loading indicators running; remove decorative entrance motion only. */
@media (prefers-reduced-motion: reduce) {
  body:not(.weld-app):not(.rq-app) :is(.app, .overlay, .cw-dialog, .iw-dialog, .sw-new-menu, .sw-draft-dialog) *,
  body:not(.weld-app):not(.rq-app) :is(.overlay, .cw-dialog, .iw-dialog, .sw-new-menu, .sw-draft-dialog) {
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  body:not(.weld-app):not(.rq-app) .content.rs-enter :is(.page-head, .stats > *, .yrbar, .toolbar, .card, .tbl, .tbl tr, .kcol),
  body:not(.weld-app):not(.rq-app) :is(.overlay.open, .overlay.open > .modal, .unified-customer .uc-body, .cw-related-content, .cw-order-details, .cw-dialog[open], .iw, .iw-dialog, .sw-new-menu, .sw-draft-dialog, .cbx-list, .agreement-editor) {
    animation: none !important;
  }
}

/* Text links need a lighter foreground in night mode, not a lighter red fill.
   #ff929a on #17191e = 8.23:1. Green received text already meets contrast. */
[data-theme="dark"] body:not(.weld-app):not(.rq-app) :is(.unified-customer, .cw-dialog) :is(.uc-link, .cw-related-toggle),
body[data-theme="dark"]:not(.weld-app):not(.rq-app) :is(.unified-customer, .cw-dialog) :is(.uc-link, .cw-related-toggle) {
  color: #ff929a;
}
body:not(.weld-app):not(.rq-app) :is(.unified-customer, .cw-dialog) :is(.uc-link, .cw-related-toggle):is(:hover, :focus-visible) {
  text-decoration: underline;
  text-underline-offset: 3px;
}
[data-theme="dark"] body:not(.weld-app):not(.rq-app) .unified-customer .btn.cw-confirm-payment,
body[data-theme="dark"]:not(.weld-app):not(.rq-app) .unified-customer .btn.cw-confirm-payment {
  background: #15734c;
  border-color: #15734c;
  color: #fff;
}
body:not(.weld-app):not(.rq-app) .ux-load-error {
  display: grid;
  gap: 10px;
  padding: 20px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}
body:not(.weld-app):not(.rq-app) .ux-load-error strong { font-size: 15px; line-height: 1.4; }
body:not(.weld-app):not(.rq-app) .ux-load-error p {
  margin: 0;
  color: var(--ux-muted);
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
body:not(.weld-app):not(.rq-app) .ux-load-error .btn { justify-self: start; margin-top: 2px; }

@media (min-width: 901px) {
  body:not(.weld-app):not(.rq-app) .ux-plan-scroll .tbl.plan td.ocaret {
    padding-inline: 4px;
    text-overflow: clip;
  }
  body:not(.weld-app):not(.rq-app) .ux-plan-scroll .tbl.plan tr:has(td.ocaret) td:nth-last-child(10) {
    white-space: normal;
    overflow-wrap: anywhere;
    text-overflow: clip;
  }
}

/* Monthly commission uses the server's existing events; details retain every action. */
#bnWrap .bn-month-list { padding: 0 18px 12px; }
#bnWrap :is(.bn-month-columns, .bn-month-deal > summary) {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(135px, .38fr) minmax(170px, .45fr) 18px;
  align-items: center;
  gap: 20px;
}
#bnWrap .bn-month-columns { padding: 10px 12px; font-size: 12px; color: var(--ux-muted); }
#bnWrap .bn-month-columns > :nth-child(2), #bnWrap .bn-month-columns > :nth-child(3) { text-align: right; }
#bnWrap .bn-month-deal { border-top: 1px solid var(--line); }
#bnWrap .bn-month-deal > summary { padding: 14px 12px; cursor: pointer; list-style: none; border-radius: 6px; }
#bnWrap .bn-month-deal > summary::-webkit-details-marker { display: none; }
#bnWrap .bn-month-deal > summary:hover { background: var(--surface-2); }
#bnWrap .bn-month-identity { min-width: 0; overflow-wrap: anywhere; }
#bnWrap .bn-month-identity > b { font-size: 14px; }
#bnWrap .bn-month-identity .bnsub { margin-top: 4px; }
#bnWrap .bn-month-sources { display: block; font-size: 12px; color: var(--ux-muted); margin-top: 4px; }
#bnWrap .bn-month-value { text-align: right; font-size: 14px; font-variant-numeric: tabular-nums; }
#bnWrap .bn-month-value > small { display: none; }
#bnWrap .bn-month-value > .bnsub { white-space: normal; font-weight: 400; margin-top: 4px; }
#bnWrap .bn-month-chevron { color: var(--ux-muted); transition: transform .15s ease; text-align: center; }
#bnWrap .bn-month-deal[open] > summary { background: var(--surface-2); }
#bnWrap .bn-month-deal[open] .bn-month-chevron { transform: rotate(180deg); }
#bnWrap .bn-month-breakdown { padding: 14px 0 20px; }
#bnWrap .bn-month-breakdown-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0 12px 12px; }
#bnWrap .bn-month-breakdown-head > b { font-size: 13px; }
#bnWrap .bn-month-total { display: flex; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line); padding: 16px 50px 4px 12px; }
@media (max-width: 760px) {
  #bnWrap .bn-month-list { padding-inline: 8px; }
  #bnWrap .bn-month-columns { display: none; }
  #bnWrap .bn-month-deal > summary { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 18px; gap: 10px 12px; padding: 14px 8px; }
  #bnWrap .bn-month-identity { grid-column: 1 / 3; }
  #bnWrap .bn-month-value { grid-row: 2; text-align: left; font-size: 13px; }
  #bnWrap .bn-month-value > small { display: block; color: var(--ux-muted); font-size: 11px; font-weight: 400; margin-bottom: 4px; }
  #bnWrap .bn-month-chevron { grid-column: 3; grid-row: 1; }
  #bnWrap .bn-month-breakdown-head { flex-wrap: wrap; }
  #bnWrap .bn-month-total { padding-right: 8px; }
}
@media (prefers-reduced-motion: reduce) { #bnWrap .bn-month-chevron { transition: none; } }
