/* Romeoville cost to sales. Tokens, app bar, answer card and tables follow rom-work-orders (shared_db/rom_wo_site);
   the control bar, range presets and KPI tiles follow Work Order Insight (finance_web/site).
   app.js always sets data-theme on <html>; the media query only covers the moment before it runs. */
:root {
  --surface:#ffffff; --page:#eef1f5; --zebra:#f6f8fb; --select:#dfe7f5; --ink:#0f1729; --ink2:#4a5265;
  --muted:#5f6779; --grid:#e8ecf1; --axis:#c3cad6; --line:#dde2ea; --primary:#16213a; --accent:#16213a;
  --unfav:#e34948; --fav:#2a78d6; --unfav_text:#b42828; --fav_text:#1c5cab; --warn:#c88a00;
  --wash:rgba(42,120,214,0.12);
  --fill-bad:#b42828; --fill-warn:#c88a00; --fill-good:#1c5cab;
  --tag-bad-bg:#fbe4e4; --tag-bad:#b42828; --tag-warn-bg:#fbefd2; --tag-warn:#7a5600; --tag-good-bg:#e3edfa; --tag-good:#1c5cab;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --bar:#ffffff; --bar2:#e8edf4; --bar_ink:#0f1729; --bar_muted:#4a5265;
  --pill-bg:#eef1f5; --pill-ink:#4a5265; --reload-bg:#193d66; --reload-hover:#244f80;
  --logo-a:#283343; --logo-b:#193d66; --accent_tile:#193d66;
  /* chart series: dataviz reference palette slots 1-4, fixed order (validated light + dark) */
  --s1:#2a78d6; --s2:#eb6834; --s3:#1baf7a; --s4:#eda100;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface:#182031; --page:#0f1420; --zebra:#1c2538; --select:#2a3756; --ink:#eef1f6; --ink2:#c4cad6;
    --muted:#97a0b2; --grid:#263046; --axis:#3a4560; --line:#2a3449; --bar:#0b1020; --bar2:#22304f;
    --bar_ink:#ffffff; --bar_muted:#a9b3c7; --primary:#3d5a99; --accent:#a9c1ff;
    --unfav:#e66767; --fav:#3987e5; --unfav_text:#f29a9a; --fav_text:#8dbaf2; --warn:#e0a72a;
    --wash:rgba(57,135,229,0.18);
    --fill-bad:#e66767; --fill-warn:#e0a72a; --fill-good:#3987e5;
    --tag-bad-bg:#3a1d1f; --tag-bad:#f29a9a; --tag-warn-bg:#3b3322; --tag-warn:#f6c96a; --tag-good-bg:#1d2c4a; --tag-good:#8dbaf2;
    --pill-bg:#26324f; --pill-ink:#d5dbe7; --reload-bg:#22304f; --reload-hover:#33446b; --logo-a:#e9edf4; --logo-b:#7fa7d9;
    --accent_tile:#2c3d66;
    --s1:#3987e5; --s2:#d95926; --s3:#199e70; --s4:#c98500;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --surface:#182031; --page:#0f1420; --zebra:#1c2538; --select:#2a3756; --ink:#eef1f6; --ink2:#c4cad6;
  --muted:#97a0b2; --grid:#263046; --axis:#3a4560; --line:#2a3449; --bar:#0b1020; --bar2:#22304f;
  --bar_ink:#ffffff; --bar_muted:#a9b3c7; --primary:#3d5a99; --accent:#a9c1ff;
  --unfav:#e66767; --fav:#3987e5; --unfav_text:#f29a9a; --fav_text:#8dbaf2; --warn:#e0a72a;
  --wash:rgba(57,135,229,0.18);
  --fill-bad:#e66767; --fill-warn:#e0a72a; --fill-good:#3987e5;
  --tag-bad-bg:#3a1d1f; --tag-bad:#f29a9a; --tag-warn-bg:#3b3322; --tag-warn:#f6c96a; --tag-good-bg:#1d2c4a; --tag-good:#8dbaf2;
  --pill-bg:#26324f; --pill-ink:#d5dbe7; --reload-bg:#22304f; --reload-hover:#33446b; --logo-a:#e9edf4; --logo-b:#7fa7d9;
  --accent_tile:#2c3d66;
  --s1:#3987e5; --s2:#d95926; --s3:#199e70; --s4:#c98500;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font: 14px/1.4 var(--font); min-height: 100vh;
       display: flex; flex-direction: column; }
button, input, select { font: inherit; color: inherit; }
input, select { background: var(--surface); border: 1px solid var(--axis); border-radius: 6px; padding: 5px 8px; }
input[type="search"] { width: min(320px, 100%); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* app bar (rom-work-orders) */
.appbar { background: var(--bar); color: var(--bar_muted); display: flex; align-items: center; gap: 12px;
          padding: 8px 24px; min-height: 70px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 16px; padding-right: 8px; flex: none; white-space: nowrap; }
.logo { height: 46px; width: auto; flex: none; display: block; }
.logo .lg-a { fill: var(--logo-a); } .logo .lg-b { fill: var(--logo-b); }
.bsep { width: 1px; align-self: stretch; margin: 4px 0; background: var(--line); }
.btxt { display: flex; flex-direction: column; line-height: 1.2; }
.brand .sub { font-size: 13px; letter-spacing: .3px; }
.brand .title { color: var(--bar_ink); font-weight: 600; font-size: 18px; }
.pill { margin-left: auto; max-width: min(520px, 100%); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        color: var(--bar_muted); font-size: 12.5px; }
.pill.warn { color: var(--tag-warn); }
.pill.error { color: var(--unfav_text); font-weight: 600; }
@media (min-width: 1100px) { .appbar { flex-wrap: nowrap; } }
.reload { display: inline-flex; align-items: center; gap: 7px; background: var(--reload-bg); color: #fff; border: 0;
          border-radius: 7px; padding: 7px 15px; font-size: 14px; font-weight: 600; cursor: pointer; flex: none; }
.reload svg { width: 15px; height: 15px; }
.reload:hover { background: var(--reload-hover); }
.reload:disabled { opacity: .55; cursor: default; }
.reload:disabled svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.theme-btn { background: none; border: 0; color: var(--bar_muted); width: 36px; height: 36px; padding: 8px;
  border-radius: 7px; cursor: pointer; flex: none; }
.theme-btn:hover { background: var(--bar2); color: var(--bar_ink); }
.theme-btn svg { width: 20px; height: 20px; display: block; }
.theme-btn .sun, [data-theme="dark"] .theme-btn .moon { display: none; }
[data-theme="dark"] .theme-btn .sun { display: inline; }
.tabs { display: flex; align-self: stretch; margin: -8px 0 -1px 4px; overflow-x: auto; min-width: 0; flex: 0 1 auto; }
@media (min-width: 1100px) { .tabs { flex: none; } }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; color: var(--bar_muted); padding: 0 12px;
               cursor: pointer; white-space: nowrap; font-size: 15px; transition: color .15s ease, border-color .2s ease; }
.tabs button:hover { color: var(--bar_ink); }
.tabs button.on { color: var(--bar_ink); font-weight: 600; border-bottom-color: var(--accent); }
.tabs .count { color: var(--bar_muted); opacity: .8; font-weight: 400; }

/* control bar + range presets (Work Order Insight) */
.controlbar { background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center;
              gap: 8px 12px; padding: 8px 24px; flex-wrap: wrap; }
.cl { color: var(--ink2); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.sep { width: 1px; align-self: stretch; background: var(--line); }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.preset { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 4px 13px;
          color: var(--ink2); cursor: pointer; font-size: 13px; }
.preset:hover { border-color: var(--accent); color: var(--ink); }
.preset.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
:root[data-theme="dark"] .preset.on { background: var(--accent); border-color: var(--accent); color: var(--page); }

main { padding: 12px 24px 8px; display: flex; flex-direction: column; gap: 12px; flex: 1; min-width: 0; }
.tab { display: flex; flex-direction: column; gap: 12px; }
.bar { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; }
.h2 { font-size: 15px; margin: 6px 0 -4px; font-weight: 600; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.h2 .small { font-weight: 400; }

/* summary: a short results statement (left) and the list of problems (right), like a finance report page */
.summary { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 12px 18px 10px; }
.sum-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line);
            padding-bottom: 8px; margin-bottom: 10px; }
.sum-head h1 { font-size: 16px; font-weight: 600; margin: 0; }
.summary.error .sum-head h1 { color: var(--unfav_text); }
.sum-body { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 8px 36px; align-items: start; }
@media (max-width: 900px) { .sum-body { grid-template-columns: 1fr; } }
.stmt { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
.stmt th { text-align: right; font-weight: 400; color: var(--muted); font-size: 12px; padding: 0 0 4px 16px; }
.stmt th:first-child { text-align: left; padding-left: 0; }
.stmt td { padding: 2px 0; }
.stmt td.n { text-align: right; padding-left: 16px; white-space: nowrap; }
.stmt tr.sub td:first-child { padding-left: 16px; color: var(--ink2); }
.stmt tr.sub td.n { color: var(--ink2); }
.stmt tr.tot td { border-top: 1px solid var(--ink2); font-weight: 600; padding-top: 4px; }
.stmt tr.gap td { padding-top: 8px; }
.stmt tr.dim td { color: var(--muted); font-size: 12px; }
.issues h2 { font-size: 12px; font-weight: 400; color: var(--muted); margin: 0 0 4px; }
.issues ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink); }
.issues li { padding-left: 2px; }
.issues li::marker { color: var(--muted); }
.issues .go { background: none; border: 0; padding: 0; color: var(--fav_text); cursor: pointer; text-decoration: underline;
              text-underline-offset: 2px; font-size: 12.5px; white-space: nowrap; }
.issues .go:hover { color: var(--ink); }
.foot { margin: 10px 0 0; padding-top: 6px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.foot:empty { display: none; }

/* tags */
.tagx { border-radius: 3px; padding: 1px 8px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.tagx.bad { background: var(--tag-bad-bg); color: var(--tag-bad); }
.tagx.warn { background: var(--tag-warn-bg); color: var(--tag-warn); }
.tagx.good { background: var(--tag-good-bg); color: var(--tag-good); }
.tagx.plain { background: var(--zebra); color: var(--ink2); border: 1px solid var(--line); }

/* tables */
.table { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; overflow: auto; max-height: 460px; }
.table.tall { max-height: min(66vh, 720px); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--ink2); text-align: left; font-weight: 600;
     padding: 6px 8px; border-bottom: 1px solid var(--axis); white-space: nowrap; }
th.sort { cursor: pointer; user-select: none; } th.sort:hover { color: var(--ink); }
th.sorted::after { content: " ▾"; } th.sorted.asc::after { content: " ▴"; }
td { padding: 5px 8px; white-space: nowrap; max-width: 300px; overflow: hidden; text-overflow: ellipsis;
     border-bottom: 1px solid var(--grid); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.desc { max-width: 230px; color: var(--ink2); }
@media (min-width: 1500px) { td.desc { max-width: 360px; } }
tr.go { cursor: pointer; } tr.go:hover > td { background: var(--select); }
tr.go.on > td { background: var(--select); }
tr.go:focus-visible { outline: 2px solid var(--fav); outline-offset: -2px; }
tr.total > td { font-weight: 600; border-top: 1px solid var(--line); }
.mo { font-weight: 700; font-variant-numeric: tabular-nums; }
.neg { color: var(--unfav_text); font-weight: 600; }
.pos { color: var(--fav_text); }
.empty-msg { color: var(--muted); padding: 20px; text-align: center; white-space: normal; }
.status { color: var(--muted); padding: 4px 24px 8px; font-size: 12px; min-height: 24px; }
.maphow { font-size: 12px; color: var(--muted); max-width: 1100px; }
.maphow p { margin: 4px 0; }
.note { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px 14px; font-size: 13px; color: var(--ink2); }
.note:empty { display: none; }

/* ratio bar in a table cell: cost as a share of sales, 100% marked */
.rbar { position: relative; display: inline-block; width: 90px; height: 8px; background: var(--grid); border-radius: 1px;
        vertical-align: middle; margin-left: 8px; overflow: hidden; }
.rbar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 1px; background: var(--fill-good); }
.rbar i.warn { background: var(--fill-warn); } .rbar i.bad { background: var(--fill-bad); }
.rbar b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); left: calc(100% / 1.5); }
/* mix bar: material | labor | overhead (series colours) */
.mix { display: inline-flex; gap: 2px; width: 110px; height: 8px; vertical-align: middle; }
.mix span { display: block; height: 100%; border-radius: 2px; }
.mix .m { background: var(--s1); } .mix .l { background: var(--s2); } .mix .o { background: var(--s3); }

/* vpick pills (rom-work-orders) */
.vpick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.vpick button { all: unset; box-sizing: border-box; cursor: pointer; padding: 4px 11px; border: 1px solid var(--line); border-radius: 4px;
                background: var(--surface); font-size: 13px; color: var(--ink2); display: inline-flex; gap: 6px; align-items: baseline; }
.vpick button:hover { border-color: var(--axis); color: var(--ink); }
.vpick button:focus-visible { outline: 2px solid var(--fav); outline-offset: 1px; }
.vpick button.on { border-color: var(--accent); background: var(--select); color: var(--ink); font-weight: 600; }
.vpick button b { font-variant-numeric: tabular-nums; }

/* charts */
.charts2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(520px, 100%), 1fr)); gap: 12px; }
.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px 14px 6px; min-width: 0; }
.chart-card h3 { margin: 0 0 4px; font-size: 14px; font-weight: 600; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.chart-card h3 span { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 12px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart text.dl { fill: var(--ink2); font-weight: 600; }
.chart .gl { stroke: var(--grid); stroke-width: 1; }
.chart .ax { stroke: var(--axis); stroke-width: 1; }
.chart .ref { stroke: var(--ink2); stroke-width: 1.5; }
.chart text.reft { fill: var(--ink2); font-weight: 600; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .hair { stroke: var(--ink2); stroke-width: 1; opacity: .5; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; font-size: 12px; color: var(--ink2); margin: 2px 0 4px; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }
.sw.ln { height: 3px; width: 16px; border-radius: 2px; }
.sw.dt { width: 9px; height: 9px; border-radius: 50%; }
.sw.refsw { width: 16px; height: 0; border-radius: 0; border-top: 2px dashed var(--ink2); }
.chart .ref.dash { stroke-dasharray: 5 4; }
.chart .stepdot { fill: var(--ink2); stroke: var(--surface); stroke-width: 1.5; }
.c1 { background: var(--s1); } .c2 { background: var(--s2); } .c3 { background: var(--s3); } .c4 { background: var(--s4); }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--axis);
       border-radius: 4px; padding: 7px 10px; font-size: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.12); max-width: 340px; }

/* segment chart: lost (left) / made (right) per product family, class, customer or item (after WO Insight) */
.seg-head { display: flex; justify-content: space-between; align-items: center; gap: 8px 16px; flex-wrap: wrap; }
.seg-head h3 { margin: 0; }
.seg-ctl { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; }
.seg-ctl input[type="number"] { width: 64px; }
.seg-how { margin: 4px 0 2px; }
.chart .bar.fav { fill: var(--fav); } .chart .bar.unfav { fill: var(--unfav); }
.chart text.bl { fill: var(--ink2); font-size: 11.5px; }
.chart text.seglab { fill: var(--ink2); font-size: 12.5px; }
.chart text.seglab.on { fill: var(--ink); font-weight: 600; }
.chart text.net.neg { fill: var(--unfav_text); } .chart text.net.pos { fill: var(--fav_text); }
.chart text.offs { fill: var(--tag-warn); font-weight: 600; font-size: 11.5px; }
.chart .segon { fill: var(--select); }
.chart .seghit { cursor: pointer; } .chart .seghit:hover { fill: var(--wash); }
.favsw { background: var(--fav); } .unfavsw { background: var(--unfav); }
.segbar { background: var(--select); color: var(--ink); padding: 6px 24px; font-size: 13px; border-bottom: 1px solid var(--line); }
.plainlink { background: none; border: 0; padding: 0; margin-left: 8px; color: var(--fav_text); text-decoration: underline;
             text-underline-offset: 2px; cursor: pointer; font-size: 13px; }
.plainbtn { background: var(--surface); border: 1px solid var(--axis); border-radius: 4px; padding: 5px 12px; cursor: pointer;
            color: var(--ink); font-size: 13px; }
.plainbtn:hover { border-color: var(--ink2); }
.tip b { font-weight: 600; } .tip .r { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.tip .r span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }

/* item detail */
tr.odrow > td { padding: 0; background: var(--surface) !important; white-space: normal; max-width: none; }
.odetail { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 14px 20px 18px 28px;
           display: flex; flex-direction: column; gap: 12px;
           position: sticky; left: 0; max-width: calc(100vw - 52px); }
.facts4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 10px 24px; }
.facts4 > div { display: flex; flex-direction: column; gap: 2px; }
.facts4 .big { font-size: 16px; font-weight: 600; }
.facts4 .k { font-size: 12px; color: var(--muted); }
.say { font-size: 13.5px; color: var(--ink); max-width: 1000px; }
.say b { font-weight: 600; }
.split2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(460px, 100%), 1fr)); gap: 12px; }
.split2 .table { max-height: 300px; }

@media (max-width: 1100px) {
  th { white-space: normal; vertical-align: bottom; }
  td { white-space: normal; overflow-wrap: anywhere; }
  td.num, td .tagx, td.mo { white-space: nowrap; overflow-wrap: normal; }
}
@media (min-width: 700px) and (max-height: 820px) {
  main { padding-top: 8px; gap: 8px; }
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes growX { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
