:root {
  --carbon: #272b2c;
  --graphite: #4c5253;
  --mist: #f2f4f3;
  --panel: #ffffff;
  --line: #d9dfdc;
  --yellow: #ffe600;
  --yellow-deep: #e5c600;
  --blue: #0b75df;
  --danger: #c74b43;
  --success: #168e6f;
  --mono: "DM Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --display: "Space Grotesk", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { min-width: 320px; margin: 0; color: var(--carbon); background: var(--mist); font-family: var(--display); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; z-index: 20; left: 12px; top: -50px; padding: 10px 14px; background: var(--yellow); color: var(--carbon); font-weight: 700; }
.skip-link:focus { top: 12px; }

.app-shell { display: grid; grid-template-columns: 166px minmax(0, 1fr); min-height: 100dvh; }
.side-rail { position: sticky; top: 0; display: flex; flex-direction: column; height: 100dvh; padding: 23px 15px 19px; background: var(--carbon); color: white; }
.brand-lockup { display: flex; gap: 10px; align-items: center; line-height: .93; letter-spacing: -.05em; font-size: 21px; }
.brand-lockup strong { font-weight: 700; }
.brand-kicker { display: block; margin-bottom: 5px; color: var(--yellow); font-family: var(--mono); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
.brand-mark { display: grid; width: 35px; height: 35px; place-items: center; border: 2px solid var(--yellow); color: var(--yellow); font-size: 26px; font-weight: 700; }
.rail-nav { display: grid; gap: 7px; margin-top: 70px; }
.rail-link { display: grid; grid-template-columns: 23px 1fr; gap: 8px; padding: 10px 8px; color: #c4c8c5; border-left: 2px solid transparent; text-decoration: none; font-size: 12px; }
.rail-link span { color: #898f8d; font-family: var(--mono); font-size: 9px; }
.rail-link:hover, .rail-link.is-active { border-left-color: var(--yellow); color: white; background: #343a3a; }
.rail-link.is-active span { color: var(--yellow); }
.rail-footer { display: flex; gap: 8px; align-items: center; margin-top: auto; color: #aeb5b1; font-family: var(--mono); font-size: 9px; line-height: 1.4; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 0 4px rgba(255, 230, 0, .13); }

.workspace { min-width: 0; padding: 18px 24px 24px; }
.topbar { display: flex; justify-content: space-between; gap: 18px; align-items: center; padding: 7px 0 8px; border-bottom: 1px solid var(--line); }
.topbar-context { display: flex; gap: 8px; align-items: center; margin: 0; color: #78817f; font-family: var(--mono); font-size: 9px; letter-spacing: .07em; text-transform: uppercase; }
.topbar-context span + span::before, .topbar-context strong::before { margin-right: 8px; color: #afb7b4; content: "/"; }
.topbar-context strong { color: var(--carbon); font-weight: 500; }
.eyebrow { margin: 0 0 4px; color: #78817f; font-family: var(--mono); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(25px, 2.4vw, 34px); letter-spacing: -.055em; line-height: .95; }
h2 { margin-bottom: 0; font-size: 17px; letter-spacing: -.04em; }
.universal-search { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 0 11px; border: 1px solid #b6bfbc; background: white; }
.universal-search span { color: var(--graphite); font-family: var(--mono); font-size: 18px; }
.universal-search input { width: 100%; height: 36px; border: 0; outline: 0; color: var(--carbon); font-size: 12px; }
.universal-search:focus-within { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(11,117,223,.12); }
.topbar-signal { align-self: center; padding: 7px 9px; color: var(--graphite); background: #e5eae7; font-family: var(--mono); font-size: 9px; white-space: nowrap; }

.overview { padding: 16px 0 13px; }
.section-heading, .table-heading { display: flex; justify-content: space-between; gap: 20px; align-items: end; }
.section-note { margin: 0; color: #737b79; font-family: var(--mono); font-size: 9px; }
.kpi-grid { display: grid; grid-template-columns: repeat(7, minmax(118px, 1fr)); gap: 7px; margin-top: 10px; }
.kpi-card { min-height: 82px; padding: 10px 12px; border: 1px solid var(--line); background: var(--panel); }
.kpi-card.is-primary { border-color: var(--carbon); background: var(--yellow); }
.kpi-label { display: block; min-height: 20px; color: #66706d; font-family: var(--mono); font-size: 8px; line-height: 1.3; letter-spacing: .03em; text-transform: uppercase; }
.kpi-card.is-primary .kpi-label { color: #494600; }
.kpi-value { display: block; margin-top: 6px; font-size: clamp(19px, 1.8vw, 26px); font-weight: 600; letter-spacing: -.06em; line-height: .95; }
.kpi-foot { display: block; margin-top: 6px; color: #707a77; font-family: var(--mono); font-size: 8px; }

.ledger-ribbon { display: grid; grid-template-columns: 165px minmax(0, 1fr) 150px; gap: 12px; align-items: stretch; padding: 11px 14px; border-top: 3px solid var(--carbon); background: var(--carbon); color: white; }
.ribbon-title h2 { color: var(--yellow); }
.ribbon-title .eyebrow { color: #aeb6b3; }
.ribbon-title p:last-child { margin: 6px 0 0; color: #c6cdca; font-size: 10px; line-height: 1.35; }
.status-lane { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(88px, 1fr); gap: 2px; overflow-x: auto; }
.status-segment { min-height: 66px; padding: 9px 10px; border: 0; color: white; background: #3a4140; text-align: left; }
.status-segment:hover, .status-segment.is-selected { background: #535b59; }
.status-segment.is-selected { box-shadow: inset 0 -3px 0 var(--yellow); }
.status-segment small { display: block; min-height: 19px; color: #bdc5c1; font-family: var(--mono); font-size: 8px; line-height: 1.25; }
.status-segment strong { display: block; margin-top: 4px; font-size: 20px; letter-spacing: -.06em; }
.integrity-readout { display: grid; align-content: center; gap: 4px; padding-left: 12px; border-left: 1px solid #59615f; color: #dce3df; font-family: var(--mono); font-size: 9px; line-height: 1.2; }
.integrity-readout strong { color: var(--yellow); font-size: 18px; letter-spacing: -.05em; }

.data-workspace { min-width: 0; margin-top: 14px; padding: 14px; border: 1px solid var(--line); background: var(--panel); }
.app-footer { display: flex; gap: 7px; align-items: center; padding: 9px 2px 0; margin: 0; color: #77807d; font-family: var(--mono); font-size: 8px; letter-spacing: .025em; }
.table-control-bar { display: grid; grid-template-columns: minmax(280px, 1fr) auto; gap: 12px; align-items: end; margin-top: 10px; }
.table-tools { display: flex; flex-wrap: wrap; gap: 9px; align-items: end; }
.compact-select { display: grid; gap: 3px; color: #68716f; font-family: var(--mono); font-size: 8px; letter-spacing: .05em; text-transform: uppercase; }
.compact-select select { min-width: 112px; height: 31px; padding: 0 7px; border: 1px solid #c9d1ce; color: var(--carbon); background: white; font-family: var(--display); font-size: 11px; text-transform: none; }
.quiet-button { height: 31px; padding: 0 10px; border: 1px solid #c9d1ce; color: var(--graphite); background: white; font-size: 11px; }
.quiet-button:hover { border-color: var(--carbon); color: var(--carbon); }
.export-button { border-color: #c3aa00; color: var(--carbon); background: var(--yellow); font-weight: 600; }
.export-button:hover { border-color: var(--carbon); background: #ffef44; }
.export-button:disabled { cursor: wait; opacity: .66; }
.table-state { min-height: 18px; margin: 8px 0 6px; color: #6e7775; font-family: var(--mono); font-size: 9px; }

.tabulator { width: 100%; border: 1px solid var(--line); background: white; color: var(--carbon); font-family: var(--display); font-size: 12px; }
.tabulator .tabulator-header { border-bottom: 1px solid #bec8c4; background: #ecf0ee; color: #59615f; font-family: var(--mono); font-size: 9px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; }
.tabulator .tabulator-header .tabulator-col { border-right: 1px solid #d5dcda; background: transparent; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 8px 8px; }
.tabulator .tabulator-header .tabulator-col .tabulator-header-filter { margin-top: 6px; }
.tabulator .tabulator-header .tabulator-col .tabulator-header-filter input { width: 100%; height: 22px; padding: 2px 5px; border: 1px solid #c7d0cd; border-radius: 0; outline: 0; color: var(--carbon); background: #fbfcfb; font-family: var(--display); font-size: 10px; letter-spacing: 0; text-transform: none; }
.tabulator .tabulator-header .tabulator-col .tabulator-header-filter input::placeholder { color: #929b98; }
.tabulator .tabulator-header .tabulator-col .tabulator-header-filter input:focus { border-color: var(--blue); background: white; box-shadow: 0 0 0 2px rgba(11,117,223,.12); }
.tabulator .tabulator-row { min-height: 48px; border-bottom: 1px solid #e1e6e4; background: white; }
.tabulator .tabulator-row:nth-child(even) { background: #fafbfa; }
.tabulator .tabulator-row:hover { background: #fff9cc; }
.tabulator .tabulator-row .tabulator-cell { padding: 7px 8px; border-right: 1px solid #edf0ef; white-space: normal; line-height: 1.35; }
.tabulator .tabulator-row.order-parent-row { min-height: 52px; background: #fff9cc; border-top: 2px solid var(--carbon); cursor: pointer; }
.tabulator .tabulator-row.order-parent-row:nth-child(even) { background: #fff9cc; }
.tabulator .tabulator-row.order-parent-row:hover { background: #fff15a; }
.tabulator .tabulator-row.order-parent-row .tabulator-cell { border-right-color: #e4d36f; font-weight: 500; }
.tabulator .tabulator-row.product-line-row { min-height: 46px; background: #fff; cursor: pointer; }
.tabulator .tabulator-row.product-line-row:nth-child(even) { background: #fbfcfb; }
.tabulator .tabulator-row.product-line-row:hover { background: #f5f8f6; }
.tabulator .tabulator-row.product-line-row .tabulator-cell { border-right-color: #edf0ef; }
.tabulator .tabulator-data-tree-control { display: inline-grid; width: 18px; height: 18px; place-items: center; margin-right: 6px; border: 1px solid #a78e00; color: var(--carbon); background: var(--yellow); vertical-align: middle; }
.tree-toggle { display: block; font-size: 12px; line-height: 1; }
.tabulator .tabulator-footer { border-top: 1px solid var(--line); background: #f5f7f6; }
.tabulator .tabulator-paginator { color: var(--graphite); font-size: 10px; }
.tabulator .tabulator-paginator .tabulator-page { min-width: 28px; margin: 2px; border: 1px solid #c4ceca; border-radius: 0; color: var(--carbon); background: white; }
.tabulator .tabulator-paginator .tabulator-page.active { border-color: var(--carbon); color: var(--carbon); background: var(--yellow); }
.tabulator .tabulator-col-resize-handle { width: 3px; background: transparent; }
.tabulator .tabulator-col-resize-handle:hover { background: var(--yellow-deep); }
.mono-cell { font-family: var(--mono); font-size: 11px; }
.ro-cell { color: #0968c5; font-family: var(--mono); font-size: 11px; font-weight: 500; }
.product-cell { color: var(--carbon); font-family: var(--mono); font-size: 11px; font-weight: 500; }
.child-empty { color: #9ca5a1; font-family: var(--mono); font-size: 10px; }
.sub-cell { margin-top: 3px; color: #78817f; font-family: var(--mono); font-size: 8px; line-height: 1.25; }
.status-chip { display: inline-block; padding: 3px 5px; border: 1px solid currentColor; font-family: var(--mono); font-size: 8px; letter-spacing: .03em; text-transform: uppercase; }
.status-pending_approval, .status-pending_acknowledgement { color: #896d00; background: #fff5bc; }
.status-new { color: #0d65ad; background: #e1f0ff; }
.status-approved, .status-open_to_fulfill, .status-completed { color: #176e59; background: #ddf6ed; }
.status-rejected, .status-closed, .status-cancelled { color: #9b3b34; background: #ffe8e5; }
.status-unknown { color: #66706d; background: #eef1ef; }
.integrity-chip { display: inline-block; padding: 3px 5px; font-family: var(--mono); font-size: 8px; }
.integrity-good { color: #126b56; background: #dcf5ec; }.integrity-warning { color: #815700; background: #fff1bd; }.integrity-issue { color: #9b3b34; background: #ffe8e5; }

.modal-open { overflow: hidden; }
.dossier { width: min(1120px, calc(100vw - 42px)); max-width: none; max-height: calc(100dvh - 42px); padding: 0; border: 1px solid #8c9692; background: #f8faf9; box-shadow: 0 24px 68px rgba(0,0,0,.28); }
.dossier[open] { display: flex; flex-direction: column; }
.dossier::backdrop { background: rgba(31,36,35,.48); backdrop-filter: blur(2px); }
.dossier-head { display: flex; justify-content: space-between; gap: 15px; padding: 17px 20px; border-bottom: 1px solid var(--line); background: var(--yellow); }
.dossier-head h2 { max-width: 480px; font-family: var(--mono); font-size: 15px; letter-spacing: -.03em; }.dossier-head .eyebrow { color: #635d00; }
.icon-button { display: grid; width: 32px; height: 32px; place-items: center; border: 1px solid var(--carbon); color: var(--carbon); background: transparent; font-size: 22px; }.icon-button:hover { color: white; background: var(--carbon); }
.dossier-body { overflow: auto; padding: 18px 20px 22px; }.empty-dossier { max-width: 360px; color: #6f7976; font-size: 13px; line-height: 1.6; }
.dossier-section { margin-bottom: 18px; }.dossier-section h3 { margin: 0 0 9px; font-family: var(--mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.dossier-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }.dossier-fact { min-height: 62px; padding: 9px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: white; }.dossier-fact span { display: block; color: #717b78; font-family: var(--mono); font-size: 8px; text-transform: uppercase; }.dossier-fact strong { display: block; margin-top: 6px; font-size: 11px; overflow-wrap: anywhere; }
.party-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }.party-card { min-height: 116px; padding: 11px; border: 1px solid var(--line); background: white; }.party-card h4 { margin: 0 0 7px; color: #6b7472; font-family: var(--mono); font-size: 9px; text-transform: uppercase; }.party-card p { margin: 0; font-size: 10px; line-height: 1.45; overflow-wrap: anywhere; }
.detail-table { width: 100%; border-collapse: collapse; background: white; font-size: 10px; }.detail-table th, .detail-table td { padding: 8px; border: 1px solid var(--line); text-align: left; vertical-align: top; }.detail-table th { color: #606a67; background: #edf1ef; font-family: var(--mono); font-size: 8px; text-transform: uppercase; }.detail-table td { overflow-wrap: anywhere; }
.download-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin: 14px 0 18px; }.source-action, .customer-export { min-width: 0; border: 1px solid #bec8c4; background: white; color: var(--carbon); font-family: var(--display); text-decoration: none; }.source-action summary, .customer-export { display: flex; justify-content: space-between; gap: 9px; align-items: center; min-height: 48px; padding: 10px 12px; cursor: pointer; font-size: 12px; font-weight: 600; }.source-action summary span, .customer-export span, .source-action small { color: #6e7775; font-family: var(--mono); font-size: 8px; font-weight: 400; text-transform: uppercase; }.source-action summary::marker { color: var(--yellow-deep); }.source-action[open] { border-color: var(--carbon); }.source-picker { display: grid; gap: 1px; padding: 0 8px 8px; }.source-picker a { display: flex; justify-content: space-between; gap: 8px; padding: 8px; color: #0968c5; background: #f5f7f6; font-family: var(--mono); font-size: 9px; text-decoration: none; overflow-wrap: anywhere; }.source-picker a:hover { background: #fff9cc; }.source-picker a span { flex: 0 0 auto; color: #69726f; }.source-action.is-unavailable { display: grid; gap: 4px; padding: 10px 12px; color: #737b79; background: #f5f7f6; font-size: 12px; }.customer-export { border-color: var(--carbon); background: var(--yellow); }.customer-export:hover { background: #fff15a; }.issue-list, .event-list { display: grid; gap: 7px; padding: 0; margin: 0; list-style: none; }.issue-list li, .event-list li { padding: 9px; border-left: 3px solid #b7c1bd; background: white; font-size: 10px; line-height: 1.45; }.issue-list li.is-error { border-left-color: var(--danger); }.issue-list li.is-warning { border-left-color: var(--yellow-deep); }.event-list li strong { display: block; font-family: var(--mono); font-size: 9px; }

@media (max-width: 1480px) { .kpi-grid { grid-template-columns: repeat(4, minmax(130px, 1fr)); } .ledger-ribbon { grid-template-columns: 170px minmax(0, 1fr); } .integrity-readout { grid-column: 2; border-left: 0; border-top: 1px solid #59615f; padding: 10px 0 0; grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 980px) { .app-shell { grid-template-columns: 1fr; }.side-rail { position: static; z-index: 3; flex-direction: row; align-items: center; height: auto; min-height: 67px; padding: 12px 18px; }.rail-nav { display: flex; margin: 0 0 0 35px; overflow: auto; }.rail-link { display: block; white-space: nowrap; }.rail-link span { display: none; }.rail-footer { display: none; }.topbar { gap: 14px; }.topbar-signal { align-self: center; }.ledger-ribbon { grid-template-columns: 1fr; }.integrity-readout { grid-column: auto; grid-template-columns: repeat(3, 1fr); }.workspace { padding: 20px; }.kpi-grid { grid-template-columns: repeat(3, minmax(120px, 1fr)); }.table-control-bar { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .workspace { padding: 15px; }.side-rail { align-items: flex-start; }.brand-lockup { font-size: 17px; }.rail-nav { margin-left: 18px; }.rail-link { font-size: 10px; }.section-heading, .table-heading { align-items: flex-start; flex-direction: column; }.kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }.table-tools { width: 100%; }.compact-select, .compact-select select { flex: 1; width: 100%; }.quiet-button { flex: 1; }.dossier { width: 100vw; max-height: 100dvh; border: 0; }.dossier-head { padding: 14px; }.dossier-body { padding: 14px; }.dossier-facts, .party-grid, .download-actions { grid-template-columns: 1fr; }.status-lane { grid-auto-columns: minmax(112px, 1fr); }.integrity-readout { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; } }

/* Root AI tab shares the existing rail; its panel never replaces the shell. */
button.rail-link{width:100%;border:0;border-left:2px solid transparent;border-radius:0;background:transparent;text-align:left;font:inherit;font-size:12px;cursor:pointer}button.rail-link:hover,button.rail-link.is-active{border-left-color:var(--yellow);background:#343a3a;color:white}
#ledger-panel[hidden],#ai-panel[hidden]{display:none!important}
@media(max-width:980px){button.rail-link{width:auto;min-height:44px;padding:10px 8px;white-space:nowrap}}

@media(max-width:980px){.app-shell{grid-template-columns:minmax(0,1fr)}.workspace{min-width:0}.rail-nav{min-width:0;flex:1}.brand-lockup{flex-shrink:0}}
@media(max-width:640px){.side-rail{flex-direction:column;gap:12px}.rail-nav{margin:0;width:100%;display:grid;grid-template-columns:repeat(4,minmax(0,1fr));flex:none}.rail-link,button.rail-link{padding:10px 5px;min-height:44px;font-size:10px}}
