/* ---------------------------------------------------------------------------
   JobFlow - components. Reads tokens.css and holds no colour of its own.
   --------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 400 var(--text-base)/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); letter-spacing: -0.02em; }
p { margin: 0; }
a { color: var(--accent-ink); }

/* Every money and quantity column uses these, so figures line up vertically
   and a column of prices can be scanned rather than read. */
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num  { font-variant-numeric: tabular-nums; }

.label {
  font: var(--label);
  letter-spacing: var(--label-spacing);
  text-transform: uppercase;
  color: var(--ink-muted);
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------- layout */

.app { display: flex; min-height: 100vh; }

.rail {
  flex: 0 0 var(--rail-width);
  background: var(--rail);
  display: flex;
  flex-direction: column;
  padding: var(--s5) var(--s3) var(--s4);
  gap: var(--s1);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.rail__brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px var(--s5); color: var(--rail-text-on);
}
.rail__mark {
  width: 26px; height: 26px; flex-shrink: 0; border-radius: var(--radius-sm);
  background: var(--accent); display: grid; place-items: center;
  font: 700 14px var(--font-display); color: var(--accent-on);
}
.rail__name { font: 600 15px var(--font-display); letter-spacing: -0.01em; }

#nav { display: flex; flex-direction: column; min-width: 0; }
.rail__group { display: flex; flex-direction: column; gap: 2px; padding-bottom: var(--s3); }
.rail__group-label {
  font: var(--label); letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--rail-label); padding: 0 10px 6px;
}

/* A 1px accent edge slides in from the left. That is the whole hover language
   of this direction: nothing moves, nothing scales. */
.rail__item {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  min-height: 36px; padding: 9px 10px;
  border: 0; background: none; width: 100%;
  border-radius: var(--radius-sm);
  font: 500 var(--text-base) var(--font-ui); color: var(--rail-text);
  text-align: left; text-decoration: none; cursor: pointer;
  transition: background-color var(--t-fast), color var(--t-fast);
}
.rail__item::before {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 2px;
  background: var(--accent); opacity: 0; transition: opacity var(--t-fast);
}
.rail__item:hover { background: var(--rail-hover); color: var(--rail-text-on); }
.rail__item:hover::before { opacity: 1; }
.rail__item[aria-current="page"] { background: var(--rail-active); color: var(--rail-text-on); }
.rail__item[aria-current="page"]::before { opacity: 1; }
.rail__count { font: 500 var(--text-xs) var(--font-mono); color: var(--rail-label); }

.rail__foot {
  margin-top: auto; display: flex; align-items: center; gap: 10px;
  padding: var(--s3) 10px 0; border-top: 1px solid var(--rail-divider);
}
.rail__avatar {
  width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%;
  background: #343A41; display: grid; place-items: center;
  font: 600 var(--text-xs) var(--font-ui); color: #D7DCE2;
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: var(--s4) var(--s6);
  display: flex; flex-wrap: wrap; gap: var(--s4);
  align-items: center; justify-content: space-between;
}
.topbar__crumbs { display: flex; align-items: center; gap: var(--s2); font-size: var(--text-xs); color: var(--ink-muted); }
.topbar__title { font-size: var(--text-xl); font-weight: 600; }
.topbar__actions { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }

.page { padding: var(--s5) var(--s6) var(--s8); display: flex; flex-direction: column; gap: var(--s5); }
/* flex-direction must be restated: .page sets column, and without this the
   margin panel drops below the fold instead of sitting beside the quote. */
.page--split { flex-direction: row; flex-wrap: wrap; align-items: flex-start; }
.col-main { flex: 999 1 460px; min-width: 0; display: flex; flex-direction: column; gap: var(--s5); }
.col-side { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: var(--s4); }

/* -------------------------------------------------------------------- cards */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card__head {
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: var(--s3); align-items: baseline; justify-content: space-between;
}
.card__title { font-size: var(--text-md); font-weight: 600; }
.card__hint { font-size: var(--text-xs); color: var(--ink-muted); }
.card__body { padding: var(--s5); display: flex; flex-direction: column; gap: var(--s4); }
.card__accent { height: 3px; border-radius: var(--radius) var(--radius) 0 0; }

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 0 var(--s4);
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font: 500 var(--text-base) var(--font-ui); cursor: pointer;
  text-decoration: none; white-space: nowrap;
  transition: background-color var(--t-fast), border-color var(--t-fast), transform .06s ease;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-on); font-weight: 600; }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--ghost { background: var(--surface); border-color: var(--border-strong); color: var(--ink-2); }
.btn--ghost:hover { background: var(--surface-inset); border-color: #C9C0B2; }
.btn--quiet { background: none; border-color: transparent; color: var(--ink-muted); }
.btn--quiet:hover { background: var(--surface-inset); color: var(--ink); }
.btn--lg { min-height: 48px; padding: 0 var(--s5); font-size: var(--text-md); }
.btn--block { width: 100%; }

/* ------------------------------------------------------------- steppers etc */

.stepper { display: flex; align-items: center; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.stepper__btn {
  width: 42px; min-height: var(--tap); border: 0; background: var(--surface-inset);
  color: var(--ink-2); font: 400 16px var(--font-ui); cursor: pointer;
  transition: background-color var(--t-fast);
}
.stepper__btn:hover { background: var(--surface-hover); }
.stepper__btn:first-child { border-right: 1px solid var(--border-strong); }
.stepper__btn:last-child { border-left: 1px solid var(--border-strong); }
.stepper__value { min-width: 84px; text-align: center; padding: 0 6px; font: 500 var(--text-lg) var(--font-mono); font-variant-numeric: tabular-nums; }

.chip {
  display: inline-flex; align-items: center; gap: var(--s2);
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
  background: var(--surface); color: var(--ink-muted);
  font: 500 var(--text-sm) var(--font-ui); cursor: pointer;
  transition: background-color var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.chip:hover { border-color: var(--accent); }
.chip__dot { width: 7px; height: 7px; border-radius: 50%; background: #CFC7B8; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent-ink); }
.chip[aria-pressed="true"] .chip__dot { background: var(--accent); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font: var(--label); letter-spacing: 0.08em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 3px; border: 1px solid;
}
.pill--good { color: var(--good); background: var(--good-soft); border-color: var(--good-border); }
.pill--warn { color: var(--warn); background: var(--warn-soft); border-color: var(--warn-border); }
.pill--bad  { color: var(--bad);  background: var(--bad-soft);  border-color: var(--bad-border); }
.pill--info { color: var(--info); background: var(--info-soft); border-color: var(--info-border); }
.pill--mute { color: var(--ink-muted); background: var(--surface-inset); border-color: var(--border); }

/* ------------------------------------------------------------------- tables */

.table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.table th {
  text-align: left; font: var(--label); letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--ink-muted); padding: 9px var(--s5); background: var(--surface-inset);
  white-space: nowrap;
}
.table th.r, .table td.r { text-align: right; }
.table td { padding: var(--s3) var(--s5); border-top: 1px solid var(--border-soft); vertical-align: middle; }
.table tbody tr { position: relative; transition: background-color var(--t-fast); }
.table tbody tr::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
  background: var(--accent); opacity: 0; transition: opacity var(--t-fast);
}
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:hover::before { opacity: 1; }
.table tbody tr:hover .row-action { opacity: 1; }
.row-action { opacity: 0; transition: opacity var(--t-fast); font-size: var(--text-xs); font-weight: 500; color: var(--accent-ink); }
.table__total td { background: var(--surface-inset); border-top: 2px solid var(--border); font-weight: 600; }
.table-wrap { overflow-x: auto; }

.code { font: 400 10px var(--font-mono); color: var(--ink-faint); }

/* ------------------------------------------------------------ margin figure */

.margin__value { font: 700 var(--text-3xl)/0.9 var(--font-display); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.margin__bar { position: relative; height: 10px; border-radius: 5px; background: var(--border-soft); overflow: hidden; }
.margin__fill { position: absolute; inset: 0 auto 0 0; border-radius: 5px; transition: width var(--t-base); }
.margin__target { position: relative; height: 15px; }
.margin__target-mark { position: absolute; top: 0; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.margin__target-tick { width: 1px; height: 5px; background: var(--ink-2); }
.margin__target-text { font: 500 9px var(--font-mono); color: var(--ink-2); white-space: nowrap; }

.note {
  font-size: var(--text-sm); line-height: 1.5; padding: 10px var(--s3);
  border-radius: var(--radius-sm); border: 1px solid;
}
.note--good { color: var(--good); background: var(--good-soft); border-color: var(--good-border); }
.note--warn { color: var(--warn); background: var(--warn-soft); border-color: var(--warn-border); }
.note--bad  { color: var(--bad);  background: var(--bad-soft);  border-color: var(--bad-border); }
.note--info { color: var(--info); background: var(--info-soft); border-color: var(--info-border); }

/* -------------------------------------------------------------------- tiles */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); gap: var(--s3); }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--s4); display: flex; flex-direction: column; gap: 6px;
  text-decoration: none; color: inherit; cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.tile:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.tile__value { font: 700 var(--text-2xl)/1 var(--font-display); letter-spacing: -0.025em; font-variant-numeric: tabular-nums; }
.tile__label { font-size: var(--text-sm); color: var(--ink-muted); }
.tile--alert { border-color: var(--bad-border); background: var(--bad-soft); }
.tile--alert .tile__value { color: var(--bad); }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat__k { font: var(--label); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
.stat__v { font: 500 var(--text-md) var(--font-mono); font-variant-numeric: tabular-nums; }

.kv { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: 11px var(--s4); border-bottom: 1px solid var(--border-soft); }
.kv:last-child { border-bottom: 0; }
.kv__k { font-size: var(--text-sm); color: var(--ink-2); }
.kv__v { font: 400 var(--text-base) var(--font-mono); font-variant-numeric: tabular-nums; }

.empty { padding: var(--s10) var(--s6); text-align: center; color: var(--ink-muted); display: flex; flex-direction: column; gap: var(--s2); align-items: center; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: var(--s3); }

/* ------------------------------------------------------------------- banner */

.banner {
  display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center;
  padding: var(--s3) var(--s5); font-size: var(--text-sm);
  border-bottom: 1px solid var(--warn-border); background: var(--warn-soft); color: var(--warn);
}

/* ------------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .app { flex-direction: column; }
  /* One scrollable row, not a wrapping block. nowrap on both the rail and the
     groups inside it is what stops the nav turning into four stacked lines on
     a phone. */
  .rail {
    flex: 0 0 auto; width: 100%; height: auto; position: sticky; top: 0; z-index: 10;
    flex-direction: row; flex-wrap: nowrap; align-items: center; gap: var(--s1);
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding: var(--s2) var(--s4);
  }
  .rail__brand { padding: 0 var(--s3) 0 0; flex-shrink: 0; }
  /* The groups live inside #nav, so that is what has to stop stacking them. */
  #nav { flex-direction: row; flex-wrap: nowrap; gap: var(--s1); }
  .rail__group { flex-direction: row; flex-wrap: nowrap; padding: 0; gap: var(--s1); }
  .rail__group-label, .rail__foot, .rail__count { display: none; }
  .rail__item { width: auto; white-space: nowrap; flex-shrink: 0; padding: 8px 12px; }
  /* The sliding accent edge reads as a dropped border in a horizontal row, so
     it becomes an underline instead. */
  .rail__item::before { left: 6px; right: 6px; top: auto; bottom: 2px; width: auto; height: 2px; }
  .topbar, .page { padding-left: var(--s4); padding-right: var(--s4); }
  .topbar { position: static; }
}

/* ----------------------------------------------------------- segmented */

.seg {
  min-height: 30px; padding: 0 11px;
  border: 1px solid var(--border-strong); background: var(--surface);
  font: 500 var(--text-xs) var(--font-ui); color: var(--ink-muted);
  cursor: pointer; transition: background-color var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.seg:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.seg:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.seg + .seg { margin-left: -1px; }
.seg:hover { color: var(--ink); border-color: #C9C0B2; }
.seg--on { background: var(--ink); border-color: var(--ink); color: var(--surface); position: relative; z-index: 1; }
.seg--on:hover { color: var(--surface); border-color: var(--ink); }

/* A chart row lifts very slightly under the cursor. The tooltip is the SVG's
   own <title>, which costs nothing and reads to a screen reader as well. */
.ch-row { transition: opacity var(--t-fast); cursor: default; }
.ch-row:hover { opacity: .82; }

/* --------------------------------------------------------------- flash */

.flash {
  position: fixed; right: var(--s5); bottom: var(--s5); z-index: 60;
  padding: 11px var(--s4); border-radius: var(--radius);
  font: 500 var(--text-sm) var(--font-ui);
  box-shadow: var(--shadow-md); border: 1px solid;
  animation: flash-in .16s ease;
}
.flash[hidden] { display: none; }
.flash--good { background: var(--good-soft); border-color: var(--good-border); color: var(--good); }
.flash--bad { background: var(--bad-soft); border-color: var(--bad-border); color: var(--bad); }

@keyframes flash-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .flash { animation: none; }
  * { transition-duration: .01ms !important; }
}
