/* Resource Scheduler — styles.
   Colour roles follow the validated reference palette (light + dark selected). */

:root {
  --wk-col: 58px;
  /* Label column flexes with BOTH the reader's text size and the screen.
     The preferred value is deliberately rem-led (not pure vw) so a larger
     browser font widens the column instead of just wrapping the text; the vw
     term then adds room on bigger screens. A user drag pins an explicit px
     width on .board and wins over this. */
  --label-col: clamp(10rem, 11rem + 8vw, 30rem);
  --total-col: 76px;
}

/* Long ranges (>52 weeks): tighter columns and smaller figures so a two-year
   view is navigable rather than an endless scroll. */
.board.dense { --wk-col: 40px; }
.board.dense .hour-cell { font-size: 10.5px; padding: 3px 0; }
.board.dense .week-cell { font-size: 9.5px; }
.board.dense .week-cell .wk-day { font-size: 10px; }
.board.dense .week-cell.today::after { content: "now"; font-size: 8px; }
.board.dense .group-total-cell { font-size: 10px; }
.board.dense .group-total-cell .act { font-size: 8.5px; }

.app-root {
  color-scheme: light;
  /* Brand type. --font-display is Diagramm, used where the design already
     calls for weight; --font-head is FreightBig Pro for headings. Body text
     waits for Diagramm Regular — see css/fonts.css for why. */
  --font-body: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Diagramm Display", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: "FreightBig Pro", Georgia, serif;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid-line: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;

  /* Categorical — one hue per service line, fixed order (validated) */
  --svc-emm: #2a78d6;      /* Energy Market Modelling */
  --svc-epr: #eb6834;      /* Economics, Policy & Regulation */
  --svc-pp: #1baf7a;       /* Price Projections */
  --svc-pdview: #eda100;   /* pdView */
  --svc-or: #e87ba4;       /* Operations Research */
  --svc-cdd: #008300;      /* Commercial & Due Diligence */
  --svc-other: #898781;    /* Other / unclassified */

  /* Status (fixed, never themed) */
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;

  --today-wash: rgba(42, 120, 214, 0.07);
  --shadow: 0 1px 3px rgba(11, 11, 11, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .app-root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid-line: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;

    --svc-emm: #3987e5;
    --svc-epr: #d95926;
    --svc-pp: #199e70;
    --svc-pdview: #c98500;
    --svc-or: #d55181;
    --svc-cdd: #008300;
    --svc-other: #898781;

    --today-wash: rgba(57, 135, 229, 0.10);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] .app-root {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid-line: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;

  --svc-emm: #3987e5;
  --svc-epr: #d95926;
  --svc-pp: #199e70;
  --svc-pdview: #c98500;
  --svc-or: #d55181;
  --svc-cdd: #008300;
  --svc-other: #898781;

  --today-wash: rgba(57, 135, 229, 0.10);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

.app-root {
  font-family: var(--font-body);
  background: var(--page);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-size: 14px;
}

button, input, select {
  font: inherit;
  color: inherit;
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 6px;
  flex-wrap: wrap;
}

.app-header h1 {
  font-family: var(--font-head);
  font-size: 21px;
  font-weight: 400;
  margin: 0;
  letter-spacing: 0.01em;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-logo {
  height: 22px;
  width: auto;
  color: var(--text-primary);
  display: block;
}
.brand-divider {
  width: 1px;
  height: 22px;
  background: var(--baseline);
}

.snapshot-chip {
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--surface-1);
}
.snapshot-chip strong { color: var(--text-primary); font-weight: 600; }

.header-spacer { flex: 1; }

/* ---------- Controls ---------- */

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 16px 10px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.control-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-1);
  border-radius: 7px;
  padding: 5px 11px;
  cursor: pointer;
  color: var(--text-primary);
  line-height: 1.2;
}
.btn:hover { border-color: var(--baseline); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.subtle { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn.subtle:hover { background: var(--surface-1); border-color: var(--border); }

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-1);
}
.segmented button {
  border: none;
  background: transparent;
  padding: 5px 12px;
  cursor: pointer;
  color: var(--text-secondary);
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.brush-chip {
  border: 1px solid var(--border);
  background: var(--surface-1);
  border-radius: 999px;
  padding: 4px 11px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.brush-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.brush-chip.erase.active { background: var(--text-secondary); border-color: var(--text-secondary); }

.brush-custom {
  width: 62px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px 8px;
  background: var(--surface-1);
}

.filter-input, .range-select {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 9px;
  background: var(--surface-1);
  min-width: 0;
}
.filter-input { width: 190px; }
.filter-input::placeholder { color: var(--text-muted); }

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 2px;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--grid-line);
  margin-bottom: 8px;
}
.tabs-spacer { flex: 1; }
.tabs .control-label { margin-right: 2px; }
.tabs #teamSelect { margin-bottom: 5px; }
.tabs button {
  border: none;
  background: none;
  padding: 7px 14px 9px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13.5px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button:hover { color: var(--text-primary); }
.tabs button.active {
  color: var(--text-primary);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

/* ---------- Stats strip ---------- */

.stats-strip {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 0 16px 10px;
  flex-wrap: wrap;
}
.stat-tile {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-1);
  padding: 7px 14px;
  min-width: 130px;
}
.stat-tile .stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.stat-tile .stat-value {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  margin-top: 1px;
  letter-spacing: -0.01em;
}
.stat-tile .stat-sub { font-size: 11px; color: var(--text-muted); }

/* A tile that opens a drill-down. Rendered as a real button so it is reachable
   by keyboard, but it has to sit flush with the plain tiles beside it. */
.stat-tile.clickable {
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: inherit;
}
.stat-tile.clickable:hover { border-color: var(--baseline); }
.stat-tile.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.month-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.month-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-1);
  padding: 3px 11px;
  font-size: 12px;
  color: var(--text-secondary);
}
.month-chip strong { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.rates-hint { align-self: center; font-size: 12px; color: var(--text-muted); }
.rates-hint button {
  border: none; background: none; padding: 0;
  color: var(--accent); cursor: pointer; text-decoration: underline;
}

.demo-chip {
  font-size: 12px;
  border: 1px dashed var(--baseline);
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--text-secondary);
  background: var(--surface-1);
}
/* A failed save must be impossible to miss — this is silent data loss otherwise. */
.demo-chip.save-failed {
  border: 1px solid var(--status-critical);
  background: color-mix(in srgb, var(--status-critical) 12%, var(--surface-1));
  color: var(--text-primary);
}
.demo-chip.save-failed strong { color: var(--status-critical); }

.nav-btn { padding: 5px 9px; font-weight: 600; line-height: 1; }

/* ---------- Insights tab ---------- */

.insights {
  flex: 1;
  overflow: auto;
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chart-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-1);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.chart-card h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
}
.chart-host { overflow-x: auto; }
.chart-host svg { display: block; }
.chart-empty { color: var(--text-muted); font-size: 13px; padding: 24px 0; }

/* Client vs internal split. A row per team (or per person once a team is
   selected): name, a proportional bar, and the figures. */
.mix-list { display: flex; flex-direction: column; gap: 7px; padding: 4px 0 2px; }
.mix-row {
  display: grid;
  grid-template-columns: minmax(96px, 21%) 1fr minmax(140px, auto);
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
}
.mix-name {
  color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mix-track { background: var(--surface-1); border-radius: 4px; height: 16px; }
.mix-bar { display: flex; height: 100%; border-radius: 4px; overflow: hidden; min-width: 2px; }
.mix-bar > span { display: block; height: 100%; }
.mix-client { background: var(--accent); }
.mix-internal { background: var(--svc-violet); }
.mix-figs { color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.mix-legend {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-top: 8px; font-size: 11.5px; color: var(--text-muted);
}
.mix-legend .mix-key { width: 11px; height: 11px; border-radius: 3px; }
.mix-legend .mix-key + span { margin-right: 10px; }

@media (max-width: 720px) {
  .mix-row { grid-template-columns: 1fr; gap: 3px; }
  .mix-figs { text-align: left; }
}
.chart-legend {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.chart-legend .legend-line {
  display: inline-block;
  width: 18px;
  height: 2px;
  background: var(--text-secondary);
}

/* ---------- Team & rates tab ---------- */

.team-view {
  flex: 1;
  overflow: auto;
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.team-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.team-toolbar label { font-size: 12.5px; color: var(--text-secondary); }
.team-toolbar input {
  width: 100px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 9px;
  background: var(--surface-1);
}
.team-note { font-size: 11.5px; color: var(--text-muted); }

.team-table-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-1);
  box-shadow: var(--shadow);
  overflow: auto;
}
.team-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.team-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--baseline);
  position: sticky;
  top: 0;
  background: var(--surface-1);
}
.team-table td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--grid-line);
}
.team-table .tt-hwk { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.team-table .tt-dir { color: var(--text-secondary); }
.team-table input, .team-table select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 7px;
  background: var(--surface-1);
  font-size: 12.5px;
}
.team-table input[type="number"] { width: 70px; text-align: right; font-variant-numeric: tabular-nums; }
.team-table input[type="date"] { width: 135px; }
.starter-chip {
  font-size: 10px;
  border: 1px dashed var(--baseline);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 7px;
  color: var(--text-secondary);
}

.ns-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--text-secondary);
}
.ns-form input, .ns-form select {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 9px;
  background: var(--surface-1);
}
.ns-form input#nsName { width: 180px; }
.ns-form input#nsFte { width: 60px; }

/* hours scheduled after a person's departure (or for ex-staff) */
.hour-cell.departed {
  background: repeating-linear-gradient(
    45deg,
    transparent 0 4px,
    color-mix(in srgb, var(--status-critical) 12%, transparent) 4px 8px
  );
}
/* hours scheduled before a new starter's first day */
.hour-cell.prestart {
  background: repeating-linear-gradient(
    45deg,
    transparent 0 4px,
    color-mix(in srgb, var(--text-muted) 18%, transparent) 4px 8px
  );
}
.rates-row input::placeholder { color: var(--text-muted); }

/* ---------- Legend ---------- */

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px 8px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch {
  width: 11px; height: 11px;
  border-radius: 3px;
  display: inline-block;
}
.legend-sep { color: var(--grid-line); }

/* ---------- Board ---------- */

.board {
  flex: 1;
  overflow: auto;
  margin: 0 16px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-1);
  box-shadow: var(--shadow);
  user-select: none;
  position: relative;
}

.grid {
  display: grid;
  min-width: max-content;
}

.gcell {
  border-bottom: 1px solid var(--grid-line);
  border-right: 1px solid var(--grid-line);
  min-height: 34px;
  display: flex;
  align-items: center;
  position: relative;
}

/* header rows */
.month-cell, .week-cell {
  position: sticky;
  background: var(--surface-1);
  z-index: 3;
  justify-content: center;
  font-size: 11px;
  color: var(--text-muted);
  min-height: 24px;
}
.month-cell { top: 0; font-weight: 600; color: var(--text-secondary); border-right-color: var(--baseline); }
.week-cell { top: 24px; flex-direction: column; line-height: 1.15; padding: 2px 0; }
.week-cell .wk-day { color: var(--text-secondary); font-weight: 600; font-variant-numeric: tabular-nums; }
.week-cell.today { background: var(--today-wash); }
.week-cell.today .wk-day { color: var(--accent); }
.week-cell.today::after {
  content: "this wk";
  font-size: 9px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Drag handle on the label/weeks boundary. Sits in the sticky corner so it is
   reachable however far the board is scrolled. */
.col-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  z-index: 6;
  touch-action: none;
}
.col-resizer::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--baseline);
  opacity: 0;
  transition: opacity 120ms;
}
.col-resizer:hover::after,
.col-resizer.dragging::after {
  opacity: 1;
  width: 2px;
  background: var(--accent);
}
.board.resizing { cursor: col-resize; user-select: none; }
.board.resizing * { cursor: col-resize !important; }

.corner-cell {
  position: sticky;
  left: 0;
  z-index: 5;
  background: var(--surface-1);
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-muted);
  align-items: flex-end;
}
.corner-cell.top { top: 0; }
.corner-cell.mid { top: 24px; }

/* label column */
.label-cell {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface-1);
  padding: 3px 8px 3px 12px;
  gap: 6px;
  overflow: hidden;
}
.label-main { min-width: 0; flex: 1; }
.label-title {
  font-weight: 550;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.label-title > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Roll project number — the identifier staff actually recognise */
.proj-num {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--baseline) 22%, transparent);
  border-radius: 4px;
  padding: 1px 5px;
}
.pr-title { display: flex; gap: 6px; align-items: baseline; }
.pr-title > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.label-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.svc-dot {
  width: 9px; height: 9px;
  border-radius: 3px;
  flex: none;
}

.row-tools {
  display: none;
  gap: 2px;
  flex: none;
}
.label-cell:hover .row-tools { display: inline-flex; }
.row-tools button {
  border: 1px solid var(--border);
  background: var(--surface-1);
  border-radius: 5px;
  width: 22px; height: 22px;
  padding: 0;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1;
}
.row-tools button:hover { color: var(--text-primary); border-color: var(--baseline); }
.row-tools button.danger:hover { color: var(--status-critical); border-color: var(--status-critical); }

/* group header rows */
.group-row {
  background: color-mix(in srgb, var(--baseline) 12%, var(--surface-1));
  font-weight: 600;
}
.group-label {
  position: sticky;
  left: 0;
  z-index: 2;
  background: color-mix(in srgb, var(--baseline) 12%, var(--surface-1));
  padding: 4px 12px;
  font-size: 12.5px;
  gap: 8px;
}
.group-label .cap-note { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.group-total-cell {
  flex-direction: column;
  justify-content: center;
  line-height: 1.15;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  background: color-mix(in srgb, var(--baseline) 12%, var(--surface-1));
}
.group-total-cell .act {
  font-size: 9.5px;
  font-weight: 400;
  color: var(--text-muted);
}

/* public-holiday marker (capacity-reducing) */
.gcell.hol::before {
  content: '';
  position: absolute;
  top: 3px;
  right: 3px;
  width: 5px;
  height: 5px;
  border-radius: 1.5px;
  transform: rotate(45deg);
  background: var(--text-muted);
  opacity: 0.65;
  z-index: 1;
  pointer-events: none;
}
.group-total-cell.load-over {
  color: var(--status-critical);
  font-weight: 700;
}
.group-total-cell.load-over::after { content: "▲"; font-size: 7px; margin-left: 2px; }
.group-total-cell.load-near { color: color-mix(in srgb, var(--status-warning) 70%, var(--text-primary)); font-weight: 650; }
.group-total-cell.load-full { color: var(--status-good); font-weight: 650; }

/* hour cells */
.hour-cell {
  justify-content: center;
  cursor: cell;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  padding: 3px 1px;
}
.hour-cell.today-col { background: var(--today-wash); }
.hour-cell .bar {
  position: absolute;
  inset: 4px 0;
  background: color-mix(in srgb, var(--svc) 24%, var(--surface-1));
  border-bottom: 3px solid var(--svc);
  z-index: 0;
}

/* Won work: solid fill, solid baseline (the default above).
   Not yet won: hatched fill and a broken baseline, so speculative work is
   obvious at a glance without relying on colour alone.
   Leave: flat grey, no baseline. */
.hour-cell .bar.speculative {
  background:
    repeating-linear-gradient(
      -45deg,
      color-mix(in srgb, var(--svc) 26%, var(--surface-1)) 0 3px,
      color-mix(in srgb, var(--svc) 7%, var(--surface-1)) 3px 7px
    );
  border-bottom: 2px dashed var(--svc);
}
.hour-cell .bar.leave {
  background: color-mix(in srgb, var(--text-muted) 16%, var(--surface-1));
  border-bottom: 2px solid color-mix(in srgb, var(--text-muted) 55%, transparent);
}

/* Annual leave rows read as unavailable, not as work. */
.label-cell.leave-row .label-title,
.label-cell.leave-row .label-sub { color: var(--text-muted); }
.label-cell.leave-row .label-title { font-style: italic; font-weight: 500; }
.hour-cell.leave-row .val { color: var(--text-muted); }
.group-total-cell.on-leave::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.6;
}

/* Won / pipeline chips on the row label and in the picker */
.stage-chip {
  flex: none;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 1px 6px;
  border: 1px solid transparent;
}
.stage-chip.won {
  color: var(--status-good);
  border-color: color-mix(in srgb, var(--status-good) 40%, transparent);
  background: color-mix(in srgb, var(--status-good) 10%, transparent);
}
.stage-chip.spec {
  color: var(--text-secondary);
  border-style: dashed;
  border-color: var(--baseline);
  background: transparent;
}
.svc-dot.spec { background: transparent; }
.pr-stage.won { color: var(--status-good); border-color: color-mix(in srgb, var(--status-good) 40%, transparent); }
.pr-stage.spec { border-style: dashed; }
.pr-stage.internal { font-style: italic; }

.stat-sub .rev-won { color: var(--status-good); font-weight: 600; }
.stat-sub .rev-spec { color: var(--text-secondary); font-weight: 600; }
.hour-cell .bar.run-start { border-top-left-radius: 4px; border-bottom-left-radius: 4px; margin-left: 2px; }
.hour-cell .bar.run-end { border-top-right-radius: 4px; border-bottom-right-radius: 4px; margin-right: 2px; }
.hour-cell .val { position: relative; z-index: 1; }
.hour-cell:hover { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
.hour-cell input {
  width: 100%;
  height: 100%;
  border: 2px solid var(--accent);
  text-align: center;
  background: var(--surface-1);
  border-radius: 4px;
  padding: 0;
  position: relative;
  z-index: 2;
}

.total-cell {
  position: sticky;
  right: 0;
  z-index: 2;
  background: var(--surface-1);
  justify-content: flex-end;
  padding-right: 12px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  border-left: 1px solid var(--baseline);
}
.total-cell.strong { font-weight: 650; color: var(--text-primary); }

/* grand total footer row */
.grand-row .gcell {
  font-family: var(--font-display);
  position: sticky;
  bottom: 0;
  background: var(--surface-1);
  border-top: 1px solid var(--baseline);
  z-index: 3;
  font-weight: 650;
  font-size: 11.5px;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}
.grand-row .label-cell, .grand-row .total-cell { z-index: 4; }
.grand-row .label-cell { justify-content: flex-start; }

.grand-row.hours-offset .gcell { bottom: 34px; }
.grand-row.rev .gcell {
  border-top: none;
  color: var(--text-secondary);
  font-weight: 550;
  font-size: 11px;
}
.grand-row.rev .label-cell, .grand-row.rev .total-cell { font-size: 11.5px; }

.empty-state {
  padding: 60px 24px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state .big { font-size: 15px; color: var(--text-secondary); margin-bottom: 6px; }

/* ---------- Tooltip ---------- */

.tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 7px 10px;
  font-size: 12px;
  max-width: 280px;
  display: none;
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 2px; }
.tooltip .tt-line { color: var(--text-secondary); }
.tooltip .tt-hours { font-weight: 650; font-variant-numeric: tabular-nums; color: var(--text-primary); }

/* ---------- Dialog ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
  color: var(--text-primary);
  padding: 0;
  width: min(520px, 92vw);
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
dialog::backdrop { background: rgba(0,0,0,0.35); }

.dialog-body { padding: 18px 20px; }
.dialog-body h2 { margin: 0 0 14px; font-size: 16px; }

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.field input, .field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  background: var(--surface-1);
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.proj-search-wrap { position: relative; }
.proj-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  max-height: 240px;
  overflow: auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 10;
  display: none;
}
.proj-results.open { display: block; }
.proj-result {
  padding: 7px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--grid-line);
}
.proj-result:last-child { border-bottom: none; }
.proj-result:hover, .proj-result.hl { background: color-mix(in srgb, var(--accent) 10%, var(--surface-1)); }
.proj-result .pr-main { min-width: 0; flex: 1; }
.proj-result .pr-title { font-size: 13px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj-result .pr-sub { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj-result .pr-stage {
  flex: none;
  font-size: 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
  color: var(--text-secondary);
}
.proj-none { padding: 10px; color: var(--text-muted); font-size: 12.5px; }

.selected-proj {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  margin-top: 6px;
  background: color-mix(in srgb, var(--accent) 6%, var(--surface-1));
  font-size: 12.5px;
}
.selected-proj .clear-sel {
  margin-left: auto;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
}
.validated-note { font-size: 11px; color: var(--status-good); margin-top: 4px; display: flex; align-items: center; gap: 4px; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--grid-line);
}

/* ---------- Unresourced-work drill-down ---------- */

#gapsDialog { width: min(720px, 94vw); }
.gaps-body { max-height: 62vh; overflow: auto; }
.gap-intro { font-size: 12px; color: var(--text-secondary); margin-bottom: 14px; }
.gap-section + .gap-section { margin-top: 18px; }
.gap-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  border-bottom: 1px solid var(--baseline);
  padding-bottom: 4px;
}
.gap-head-title { font-size: 12.5px; font-weight: 650; }
.gap-note { font-size: 11.5px; color: var(--text-muted); margin: 5px 0 2px; }
.gap-empty { font-size: 12.5px; color: var(--text-muted); padding: 8px 0; }
.gap-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 2px;
  border-bottom: 1px solid var(--grid-line);
}
.gap-item:last-child { border-bottom: none; }
.gap-main { min-width: 0; flex: 1; }
.gap-main .pr-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gap-money {
  flex: none;
  min-width: 86px;
  text-align: right;
  font-size: 11.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}
.gap-money.gap-unknown { font-weight: 400; color: var(--text-muted); }
.gap-act { flex: none; padding: 3px 9px; font-size: 12px; }

/* ---------- Signed-in state and permissions ---------- */

.snapshot-chip.signed-in { border-color: color-mix(in srgb, var(--status-good) 45%, var(--border)); }
.chip-link {
  border: none;
  background: none;
  padding: 0 0 0 8px;
  margin-left: 6px;
  border-left: 1px solid var(--border);
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  text-decoration: underline;
}

/* A row outside your remit. Greyed and locked rather than removed — knowing
   the work exists is the point of a shared plan; changing it is not yours. */
.label-cell.locked-row .label-title,
.label-cell.locked-row .label-sub { color: var(--text-muted); }
.lock-mark { flex: none; font-size: 10px; opacity: 0.55; cursor: help; }
.hour-cell.locked-cell { cursor: default; }
.hour-cell.locked-cell:hover { outline: none; }
.hour-cell.locked-cell .val { color: var(--text-muted); }
.hour-cell.locked-cell .bar { opacity: 0.5; }
/* One beat of feedback so a click that legitimately does nothing does not
   read as a broken app. */
.hour-cell.locked-flash { outline: 2px solid var(--status-warning); outline-offset: -2px; }

.lock-toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(560px, 90vw);
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--status-warning);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 8px 14px;
  font-size: 12.5px;
}

.demo-chip.merge-note {
  border-style: solid;
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 8%, var(--surface-1));
}

/* ---------- Who changed what ---------- */

/* The header wraps when it runs out of room, and the controls must not be what
   wraps — a "Changes" button on its own line reads as a layout bug. Keep them
   together and let the long snapshot chip give up the space instead. */
.header-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.app-header .snapshot-chip {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#activityBtn { position: relative; }
.unseen-badge {
  display: inline-block;
  margin-left: 6px;
  min-width: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Attribution on the row itself, because "who moved my Tuesday" gets asked
   while looking at Tuesday. A dot when it moved since you last read the feed,
   a hairline mark otherwise — present but not shouting. */
.row-by {
  flex: none;
  font-size: 11px;
  color: var(--text-muted);
  cursor: help;
  padding: 0 2px;
}
.row-by-new { color: var(--accent); font-size: 9px; }

#activityDialog { width: min(640px, 94vw); }
.act-body { max-height: 62vh; overflow: auto; }
.act-empty { color: var(--text-muted); font-size: 13px; padding: 14px 0; }
.act-entry { padding: 9px 0; border-bottom: 1px solid var(--grid-line); }
.act-entry:last-child { border-bottom: none; }
.act-new { border-left: 2px solid var(--accent); padding-left: 9px; margin-left: -11px; }
.act-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.act-who { font-size: 12.5px; font-weight: 650; }
.act-when { font-size: 11px; color: var(--text-muted); }
.act-new-dot {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 999px;
  padding: 0 6px;
}
.act-line { font-size: 12.5px; color: var(--text-secondary); line-height: 1.45; }
.act-weeks { color: var(--text-muted); font-size: 11.5px; }
.act-denied { color: var(--status-critical); }

/* ---------- Per-job rate ---------- */

/* A repriced allocation must be obvious without hovering: a job on a client
   rate card should not look identical to one on the standard rates. */
.rate-chip {
  flex: none;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  border-radius: 999px;
  padding: 1px 6px;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  font-variant-numeric: tabular-nums;
}
.row-tools button.rate-set { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }

.rate-toggle { margin-top: 4px; }
.rate-toggle button { min-width: 108px; }
#rowRate:disabled {
  /* Still readable — it is showing the rate card figure, not nothing. */
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
  opacity: 1;
}

.field-note { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; line-height: 1.45; }
.field-note.rate-warn { color: var(--status-critical); font-weight: 600; }
#rateDialog { width: min(480px, 92vw); }
#rateInfo { font-size: 12.5px; color: var(--text-secondary); }
#rateEffect {
  font-size: 12.5px;
  color: var(--text-secondary);
  border-top: 1px solid var(--grid-line);
  padding-top: 10px;
  margin-bottom: 0;
}
#rateEffect strong { color: var(--text-primary); font-variant-numeric: tabular-nums; }

.rate-controls { display: inline-flex; align-items: center; gap: 8px; }
.team-note.warn { color: color-mix(in srgb, var(--status-warning) 65%, var(--text-primary)); }
.team-table .tt-rate .tt-hidden { color: var(--text-muted); }
.team-table input:disabled, .team-table select:disabled {
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
  opacity: 1;                 /* readable, not washed out — it is still data */
}

.identity-admin {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-1);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}
.identity-admin .ia-head { font-size: 12.5px; font-weight: 650; margin-bottom: 8px; }
.identity-admin .ia-head .team-note { font-weight: 400; margin-left: 8px; }

.hint-bar {
  padding: 4px 16px 10px;
  font-size: 11.5px;
  color: var(--text-muted);
}
kbd {
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  font-family: inherit;
  font-size: 10.5px;
  background: var(--surface-1);
}

/* ---------- Performance (estimate vs actual) tab ---------- */

.perf-view {
  flex: 1;
  overflow: auto;
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.perf-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.perf-note { font-size: 11.5px; color: var(--text-muted); }
/* Auditing against a moving plan is the trap this warns about. */
.perf-note.warn { color: color-mix(in srgb, var(--status-warning) 60%, var(--text-primary)); }
.perf-sub { font-weight: 400; font-size: 11.5px; color: var(--text-muted); margin-left: 6px; }
.perf-table-wrap { overflow: auto; max-height: 46vh; }
.perf-table td.num, .perf-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.perf-table td { padding: 5px 10px; }
.perf-empty { color: var(--text-muted); padding: 14px 10px; }

/* Variance bands: within 10% reads fine, 10-25% worth a look, past 25% is a
   real estimating miss. */
.var-ok { color: var(--status-good); }
.var-warn { color: color-mix(in srgb, var(--status-warning) 70%, var(--text-primary)); }
.var-bad { color: var(--status-critical); font-weight: 650; }
.stat-value.var-ok, .stat-value.var-warn, .stat-value.var-bad { font-weight: 700; }
.tag-unplanned {
  font-size: 10px;
  border: 1px dashed var(--baseline);
  border-radius: 999px;
  padding: 1px 7px;
  color: var(--text-muted);
}
.perf-table tr.row-unplanned td { background: color-mix(in srgb, var(--baseline) 8%, transparent); }

/* ---------- Team heat map ---------- */

.heat-grid { display: grid; gap: 1px; min-width: 640px; font-size: 11px; }
.heat-name { min-width: 0; }
.heat-corner, .heat-head {
  font-size: 10px;
  color: var(--text-secondary);
  text-align: center;
  padding-bottom: 2px;
  white-space: nowrap;
}
.heat-corner { text-align: left; }
.heat-name {
  padding-right: 8px;
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
  line-height: 20px;
}
.heat-cell { height: 20px; border-radius: 2px; }
.heat-avg {
  height: 20px;
  line-height: 20px;
  font-size: 11px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding-right: 4px;
}

/* Load ramp. Cool end is deliberately light so spare capacity reads as "room"
   rather than as another shade of busy; over-capacity breaks to warm/critical
   so too-hot differs in kind, not just intensity. Every band carries dark ink
   at >= 4.5:1 (measured) except >120%, which takes white at 4.8:1. */
.heat-none  {
  background: transparent;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--baseline) 30%, transparent);
}
.heat-off   { background: repeating-linear-gradient(45deg, transparent 0 3px,
              color-mix(in srgb, var(--baseline) 30%, transparent) 3px 6px); }
.heat-cold  { background: #dcebfd; color: #0b0b0b; }
.heat-light { background: #9ec5f4; color: #0b0b0b; }
.heat-good  { background: #3987e5; color: #0b0b0b; }
.heat-hot   { background: #ec835a; color: #0b0b0b; }
.heat-over  { background: #d03b3b; color: #ffffff; }

.heat-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.heat-cell.heat-none, .heat-cell.heat-off { color: var(--text-muted); font-weight: 400; }

/* violet for internal investment work */
.app-root { --svc-violet: #4a3aa7; }
:root[data-theme="dark"] .app-root { --svc-violet: #9085e9; }
.stage-chip.invest {
  border-color: color-mix(in srgb, var(--svc-violet) 45%, transparent);
  color: var(--svc-violet);
}
.hour-cell .bar.invest { border-bottom-style: dotted; border-bottom-width: 3px; }
.heat-key {
  width: 16px;
  height: 11px;
  border-radius: 2px;
  display: inline-block;
  vertical-align: -1px;
}

/* ---------- Recoverability indicators ---------- */

.rec-chip {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-radius: 999px;
  padding: 1px 6px;
  flex: none;
  white-space: nowrap;
}
/* Over the cap is money already lost, so it takes the critical hue; "tight"
   warns before the money is gone. */
.rec-chip.rec-over  { background: var(--status-critical); color: #fff; }
.rec-chip.rec-tight { background: #fab219; color: #0b0b0b; }
.rec-chip.rec-ok    { background: color-mix(in srgb, var(--status-good) 16%, transparent);
                      color: var(--status-good);
                      box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--status-good) 40%, transparent); }
.rec-chip.rec-idle  { background: transparent; color: var(--text-muted);
                      box-shadow: inset 0 0 0 1px var(--border); }

td.rec-over  { color: var(--status-critical); font-weight: 700; }
td.rec-tight { color: #b4531f; font-weight: 650; }
td.rec-ok    { color: var(--status-good); }
:root[data-theme="dark"] .app-root td.rec-tight,
:root:where(:not([data-theme="light"])) .app-root td.rec-tight { color: #fab219; }

.empty-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 18px 0 10px;
  flex-wrap: wrap;
}
.empty-hint { font-size: 12px; color: var(--text-muted); }
.build-stamp { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------- Sign-in gate ----------
   Covers the whole viewport so no part of the board is briefly visible behind
   it. The app has not loaded a plan at this point, but the header and empty
   grid would still flash, and a flash of an application you are not signed in
   to looks like a leak even when it is empty. */
.signin-gate {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.signin-gate[hidden] { display: none; }
.signin-card {
  max-width: 26rem; width: 100%;
  text-align: center;
  padding: 40px 32px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
}
.signin-logo { width: 56px; height: 56px; color: var(--accent); margin-bottom: 18px; }
.signin-card h1 {
  font-family: var(--font-display);
  font-size: 22px; margin: 0 0 10px;
}
.signin-sub { color: var(--text-secondary); font-size: 13.5px; margin: 0 0 24px; line-height: 1.5; }
.signin-btn { width: 100%; justify-content: center; padding: 10px 16px; font-size: 14px; }
.signin-note {
  margin: 16px 0 0; font-size: 12.5px; color: var(--status-critical);
  line-height: 1.45;
}
.signin-note[hidden] { display: none; }
