/* Factory Display. Style: a tinted frame with the work on a white sheet, after the printed report.
   Grid at 1440: sidebar 228 + sheet 1204 + inset 8; sheet padding 32 -> content 1140;
   chart row 3 x 369.33 + 2 x 16 = 1140; KPI strip 5 equal cells in one container. */
@font-face { font-family: "Inter"; src: url("fonts/inter-latin-wght-normal.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("fonts/source-serif-4-latin-wght-normal.woff2") format("woff2"); font-weight: 200 900; font-display: swap; }

:root {
  --frame: #f5f5f3; --surface: #ffffff; --raised: #f7f6f4; --active: #e9e8e4;
  --border: #e6e5e1; --rule: #f0efec; --control: #d3d2cd;
  --text: #0b0b0b; --muted: #52514e; --faint: #6b6a66;
  --accent: #1c5cab; --primary: #1d1f20;
  --positive: #247b50; --negative: #c4242a;
  --s-blue: #2a78d6; --s-sky: #7db2f3; --s-aqua: #1baf7a; --s-orange: #eb6834; --s-grey: #8a8984;
  --grid: #e9e8e4; --weekend: rgba(11, 11, 11, .045); --hover: rgba(11, 11, 11, .05); --window: rgba(28, 92, 171, .12); --tip: #ffffff;
  color-scheme: light;
  --gap: 16px; --pad: 32px; --card-pad: 20px; --radius-card: 8px; --radius-control: 6px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
}
* { box-sizing: border-box; }
html { background: var(--frame); }
body { margin: 0; font: 14px/20px var(--font); color: var(--text); background: var(--frame); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }

/* shell */
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); grid-template-rows: 48px minmax(0, 1fr); min-height: 100vh; }
.side { grid-row: 1 / 3; padding: 14px 12px 16px; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 9px; height: 32px; padding: 0 8px; font-weight: 600; font-size: 15px; }
.brand svg { color: var(--accent); flex: none; }
.scope { margin: 2px 8px 22px 39px; font-size: 12px; line-height: 16px; color: var(--faint); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { height: 32px; display: flex; align-items: center; padding: 0 10px; border-radius: 8px; color: var(--muted); }
.nav a:hover { color: var(--text); }
.nav a[aria-current="page"] { background: var(--active); color: var(--text); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 8px; }
.side-foot .btn { align-self: flex-start; background: none; }
.stamp { margin: 0; font-size: 12px; line-height: 17px; color: var(--faint); }

.top { display: flex; align-items: center; gap: 12px; padding: 0 16px 0 4px; min-width: 0; }
.menu { display: none; height: 32px; padding: 0 12px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); }
.period { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.presets { display: flex; gap: 2px; flex: none; }
.presets button { height: 32px; padding: 0 11px; border: 0; background: none; border-radius: var(--radius-control); color: var(--muted); cursor: pointer; white-space: nowrap; position: relative; }
.presets button:hover { color: var(--text); }
.presets button[aria-pressed="true"] { color: var(--text); font-weight: 500; }
.presets button[aria-pressed="true"]::after { content: ""; position: absolute; left: 11px; right: 11px; bottom: 2px; height: 2px; background: var(--accent); border-radius: 1px; }
.range { display: flex; align-items: center; gap: 8px; color: var(--muted); margin-left: auto; }
.range label, .step { display: flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }
.range input, .step select, .range button { height: 32px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); padding: 0 8px; color: var(--text); }
.range button { padding: 0 12px; cursor: pointer; }

.sheet { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; margin: 0 8px 8px 0; padding: 28px var(--pad) 36px; min-width: 0; transition: opacity .15s; }
.sheet.loading { opacity: .55; }

/* title row */
.title { margin: 0 0 22px; display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 24px; align-items: start; }
.title > * { grid-column: 1; }
.title .actions { grid-column: 2; grid-row: 1 / span 3; display: flex; gap: 8px; }
.btn { height: 32px; padding: 0 12px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--raised); }
.btn[disabled] { color: var(--faint); cursor: progress; }
.print-only { display: none; }
h1 { font: 600 24px/30px var(--serif); letter-spacing: -.01em; margin: 0 0 6px; }
.finding { margin: 0; font-size: 16px; line-height: 24px; max-width: 78ch; }
.when { margin: 6px 0 0; font-size: 13px; color: var(--faint); }

/* KPI strip: one container, hairline dividers */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--radius-card); margin-bottom: var(--gap); }
.kpi { padding: 16px var(--card-pad) 15px; border-left: 1px solid var(--border); min-width: 0; }
.kpi:first-child { border-left: 0; }
.kpi .label { font-size: 13px; line-height: 18px; color: var(--muted); }
.kpi .value { font-size: 24px; line-height: 32px; font-weight: 500; margin-top: 4px; }
.kpi.lead .value { font-size: 32px; line-height: 36px; font-weight: 600; margin-top: 0; }
.kpi .value small { font-size: 14px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.kpi .sub { font-size: 13px; line-height: 18px; color: var(--faint); margin-top: 3px; }

/* panels */
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
.card { border: 1px solid var(--border); border-radius: var(--radius-card); padding: 16px var(--card-pad) 16px; min-width: 0; display: flex; flex-direction: column; }
.span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }
.card header { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
h2 { font: 600 16px/22px var(--serif); margin: 0; }
.card header .legend { margin-left: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; line-height: 18px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.toggle { height: 26px; padding: 0 9px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); color: var(--muted); font-size: 13px; cursor: pointer; }
.toggle[aria-pressed="true"] { background: var(--active); color: var(--text); }
.note { margin: 8px 0 0; font-size: 13px; line-height: 18px; color: var(--faint); }
.plot { position: relative; flex: 1 1 auto; }
.plot svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; overflow: visible; }
.plot.flow, .plot.is-table { flex: none; min-height: 0 !important; }
.plot.flow svg { position: static; height: auto; }
.plot text { font: 12px var(--font); fill: var(--faint); font-variant-numeric: tabular-nums; }
.plot .toplabel { fill: var(--muted); font-weight: 500; }
.hit { fill: transparent; cursor: default; outline: none; }
.hit:hover, .hit:focus-visible { fill: var(--hover); }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 400; color: var(--muted); font-size: 13px; padding: 0 0 8px; }
td { padding: 8px 0; border-top: 1px solid var(--rule); }
td.num, th.num { text-align: right; padding-left: 12px; white-space: nowrap; }
.scroll { overflow-x: auto; max-height: 420px; overflow-y: auto; }
.cmp td:first-child { color: var(--text); }
.cmp .bar { display: inline-block; height: 6px; border-radius: 3px; vertical-align: middle; margin-right: 8px; }
.cmp .who { color: var(--muted); }

/* the strip: the Factory's whole history, the selected period marked */
.strip { cursor: crosshair; touch-action: pan-y; user-select: none; }
.strip .win { fill: var(--window); stroke: var(--accent); stroke-width: 1; }
.strip .sel { fill: var(--window); }

.empty { border: 1px dashed var(--control); border-radius: 8px; padding: 10px 12px; color: var(--muted); font-size: 13px; }
.error { color: var(--muted); }
.error button { border: 0; background: none; color: var(--text); text-decoration: underline; cursor: pointer; padding: 0; }

/* tooltip */
.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--tip); border: 1px solid var(--control); border-radius: 8px; padding: 8px 10px; font-size: 13px; line-height: 19px; box-shadow: 0 4px 14px rgba(0, 0, 0, .1); max-width: 260px; }
.tip b { display: block; font-weight: 600; margin-bottom: 2px; }
.tip .row { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.tip .row i { width: 10px; height: 2px; border-radius: 1px; flex: none; }
.tip .row strong { font-weight: 600; min-width: 2ch; text-align: right; font-variant-numeric: tabular-nums; }
.tip .row span { color: var(--muted); }

/* wide and ultrawide: more columns, never longer lines */
@media (min-width: 1900px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  :root { --pad: 40px; }
}
@media (min-width: 2800px) {
  .grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .span2 { grid-column: span 2; }
}

/* tablet: the sidebar folds, two columns */
@media (max-width: 1100px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .side { display: none; grid-row: auto; position: fixed; inset: 0; z-index: 30; background: var(--frame); padding: 16px; }
  .side.open { display: flex; }
  .side .nav a { height: 44px; font-size: 16px; }
  .menu { display: inline-block; flex: none; }
  .top { padding: 8px 12px; align-items: flex-start; }
  .period { flex-wrap: wrap; row-gap: 8px; }
  .sheet { margin: 0 8px 8px; padding: 22px 20px 28px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span3, .span2 { grid-column: 1 / -1; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi:nth-child(4) { border-left: 0; }
  .kpi:nth-child(n+4) { border-top: 1px solid var(--border); }
  .kpi:nth-child(5) { grid-column: span 2; }
  .range { margin-left: 0; }
}

/* phone: the sheet becomes the screen */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .top { padding: 8px 12px; }
  .period { flex-wrap: wrap; row-gap: 8px; }
  .presets { overflow-x: auto; max-width: 100%; flex: 1 1 100%; order: 2; scrollbar-width: none; }
  .presets button { height: 40px; }
  .range, .step { display: none; }
  .period.more .range, .period.more .step { display: flex; flex: 1 1 100%; order: 3; flex-wrap: wrap; }
  .period.more .range input, .period.more .step select, .period.more .range button { height: 40px; }
  .sheet { margin: 0; border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; padding: 20px 16px 28px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { border-left: 0; border-top: 1px solid var(--border); padding: 12px 14px; }
  .kpi.lead { grid-column: 1 / -1; border-top: 0; }
  .kpi:nth-child(odd):not(.lead) { border-left: 1px solid var(--border); }
  .kpi:nth-child(5) { grid-column: auto; }
  .finding { font-size: 15px; line-height: 22px; }
  .card { padding: 14px 14px 14px; }
}
@media (prefers-reduced-motion: reduce) { .sheet { transition: none; } }


/* overview: named areas, so every row closes on the sheet's edges at every width */
.grid.areas { grid-template-areas: "jira jira cmp" "items test test" "strip strip strip"; align-items: stretch; }
.areas > .a-jira { grid-area: jira; } .areas > .a-cmp { grid-area: cmp; } .areas > .a-items { grid-area: items; } .areas > .a-test { grid-area: test; } .areas > .a-strip { grid-area: strip; }
.grid.stack { grid-template-columns: minmax(0, 1fr); }
.presets .custom { display: none; }
@media (min-width: 1900px) {
  .grid.areas { grid-template-areas: "jira jira test test" "items items cmp cmp" "strip strip strip strip"; }
  .grid.stack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 2800px) {
  .grid.areas { grid-template-areas: "jira jira test test items cmp" "strip strip strip strip strip strip"; }
}
@media (max-width: 1100px) {
  .grid.areas { grid-template-areas: "jira jira" "items test" "cmp cmp" "strip strip"; }
  .grid.stack { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .grid.areas { grid-template-areas: "jira" "cmp" "items" "test" "strip"; }
  .presets .custom { display: inline-block; }
}

/* night: true neutral darks, lightness steps, colour on the data only; chart steps validated for this surface */
:root[data-theme="dark"] {
  --frame: #111111; --surface: #1a1a19; --raised: #222221; --active: #2a2a28;
  --border: #2e2e2c; --rule: #262624; --control: #46463f;
  --text: #f0efec; --muted: #c3c2b7; --faint: #9a9992;
  --accent: #6ea3e8; --primary: #f0efec;
  --s-blue: #4e96ee; --s-sky: #2a5ca8; --s-aqua: #199e70; --s-orange: #d95926; --s-grey: #7d7c76;
  --grid: #2b2b29; --weekend: rgba(255, 255, 255, .05); --hover: rgba(255, 255, 255, .07); --window: rgba(110, 163, 232, .16); --tip: #262624;
  color-scheme: dark;
}
:root[data-theme="dark"] .tip { box-shadow: 0 4px 14px rgba(0, 0, 0, .5); }

@media (max-width: 640px) {
  .title { grid-template-columns: minmax(0, 1fr); }
  .title .actions { grid-column: 1; grid-row: auto; margin-top: 12px; }
  .btn { height: 40px; }
}

/* paper: the same page, always in day colours, with its own head and foot */
@page {
  size: A4; margin: 12mm 12mm 16mm;
  @bottom-center { content: "CONFIDENTIAL · NOT FOR DISTRIBUTION"; font: 600 7pt "Inter", sans-serif; letter-spacing: .12em; color: #52514e; }
  @bottom-right { content: counter(page) " / " counter(pages); font: 8pt "Inter", sans-serif; color: #6b6a66; }
}
@media print {
  :root, :root[data-theme="dark"] {
    --frame: #ffffff; --surface: #ffffff; --raised: #f7f6f4; --active: #e9e8e4; --border: #e6e5e1; --rule: #f0efec; --control: #d3d2cd;
    --text: #0b0b0b; --muted: #52514e; --faint: #6b6a66; --accent: #1c5cab;
    --s-blue: #2a78d6; --s-sky: #7db2f3; --s-aqua: #1baf7a; --s-orange: #eb6834; --s-grey: #8a8984;
    --grid: #e9e8e4; --weekend: rgba(11, 11, 11, .045); --window: rgba(28, 92, 171, .12);
    color-scheme: light;
  }
  html, body { background: #fff; }
  .side, .top, .toggle, .actions, .tip { display: none !important; }
  .shell { display: block; min-height: 0; }
  .sheet { border: 0; margin: 0; padding: 0; opacity: 1 !important; }
  .card, .kpis, .title { break-inside: avoid; }
  .grid, .grid.areas, .grid.stack { display: block; }
  .card { margin-bottom: 14px; }
  .sheet { padding: 0 2px; }
  .print-only { display: flex; }
  .print-head { justify-content: space-between; font-size: 11px; color: var(--faint); border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-bottom: 18px; }
}

/* the page as the server lays it out before printing: one column, so every chart is drawn at its paper width */
:root[data-print] .side, :root[data-print] .top, :root[data-print] .actions { display: none; }
:root[data-print] .shell { display: block; min-height: 0; }
:root[data-print] .sheet { border: 0; margin: 0; padding: 0 2px; }
:root[data-print] .grid, :root[data-print] .grid.areas, :root[data-print] .grid.stack { display: block; }
:root[data-print] .card { margin-bottom: 14px; }

/* who is signed in, and the sign-in page */
.who { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; font-size: 12px; color: var(--faint); overflow-wrap: anywhere; }
.who[hidden] { display: none; }
.door { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.door .sheet { margin: 0; width: min(420px, 100%); padding: 28px 32px 32px; }
.door .brand { padding: 0; margin-bottom: 28px; }
.door .actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.door .btn { display: flex; align-items: center; justify-content: center; height: 40px; }
