:root {
  --ink: #0c0c0e;
  --ink-soft: #6a6a72;
  --paper: #ffffff;
  --page: #f6f5f8;
  --lilac: #f3e6f7;
  --mist: #e5dff9;
  --rule: #dcd8e2;
  --field-border: #8e8a98;
  --violet: #7860c7;
  --magenta: #ff3fb2;
  --orange: #fe6b00;
  --yellow: #f6e200;
  --turquoise: #2ad2c5;
  --line: 1px solid var(--rule);
  --stage-1: var(--violet);
  --stage-2: var(--yellow);
  --stage-3: var(--orange);
  --stage-4: var(--turquoise);
  --stage-5: var(--magenta);
  --stage-6: var(--ink);
  --stage-7: var(--ink-soft);
  --font: "Familjen Grotesk", system-ui, sans-serif;
  --width: 1440px;
  --radius-control: 4px;
  --radius-panel: 6px;
  --step-xs: 0.8125rem;
  --step-s: 0.875rem;
  --step-m: 0.9375rem;
  --step-l: 1.125rem;
  --step-xl: 1.5rem;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-m);
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: var(--step-xl); }
h2 { font-size: var(--step-l); }
p { margin: 0; }

a { color: var(--violet); text-underline-offset: 0.15em; }
a:hover { color: var(--ink); }

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.app-bar {
  background: var(--paper);
  border-bottom: var(--line);
}
.app-bar-inner {
  max-width: var(--width);
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: stretch;
  gap: 32px;
  min-height: 52px;
}
.brand {
  display: flex;
  align-items: center;
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover { color: var(--ink); }

.main-nav { display: flex; gap: 4px; flex: 1; }
.main-nav a {
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: var(--ink-soft);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 3px solid transparent;
  border-top: 3px solid transparent;
}
.main-nav a:hover { color: var(--ink); }
.main-nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--violet); }

.session { display: flex; align-items: center; gap: 14px; font-size: var(--step-s); }
.session form { margin: 0; }
.session-role { color: var(--ink-soft); }

main { max-width: var(--width); margin: 0 auto; padding: 24px 24px 64px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px 24px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-header .lede { color: var(--ink-soft); margin-top: 4px; max-width: 70ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.page-actions form { margin: 0; }

.back-link { display: inline-block; margin-bottom: 12px; font-size: var(--step-s); font-weight: 600; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 16px;
  background: var(--violet);
  color: var(--paper);
  border: 1px solid var(--violet);
  border-radius: var(--radius-control);
  font: 600 var(--step-m) var(--font);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.button:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.button.secondary { background: var(--paper); color: var(--ink); border-color: var(--field-border); }
.button.secondary:hover { border-color: var(--ink); background: var(--paper); color: var(--ink); }

.text-action { font-weight: 600; }

.notice {
  display: flex;
  gap: 12px;
  background: var(--paper);
  border: var(--line);
  border-left: 4px solid var(--magenta);
  border-radius: var(--radius-panel);
  padding: 12px 16px;
  margin: 0 0 20px;
}
.notice ul { margin: 6px 0 0; padding-left: 20px; }
.notice.success { border-left-color: var(--turquoise); }
.notice.pending { border-left-color: var(--yellow); font-weight: 600; }

.stage-board { margin-bottom: 20px; }
.stage-strip { display: flex; gap: 12px; align-items: stretch; }
.stage-group {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  background: var(--paper);
  border: var(--line);
  border-radius: var(--radius-panel);
  overflow: hidden;
}
.stage-group.flow { flex: 6 1 0; }
.stage-group.outside { flex: 2 1 0; }

.stage {
  --color: var(--stage-7);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 76px;
  padding: 10px 14px 10px 22px;
  border-top: 4px solid var(--color);
  color: var(--ink);
  text-decoration: none;
}
.stage:first-child { padding-left: 14px; }
.stage:hover { background: var(--page); color: var(--ink); }
.stage[aria-current="true"] { background: var(--lilac); }
.stage[aria-current="true"] .stage-name { color: var(--ink); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 0.2em; }
.stage-count { font-size: 1.625rem; font-weight: 700; line-height: 1; }
.stage-name { font-size: var(--step-s); font-weight: 600; color: var(--ink-soft); line-height: 1.25; }
.stage.stage-none { border-top-style: dashed; border-top-color: var(--ink-soft); }

.flow .stage + .stage::before {
  content: "";
  position: absolute;
  left: -9px;
  top: calc(50% - 2px);
  width: 16px;
  height: 16px;
  border-top: var(--line);
  border-right: var(--line);
  transform: translateY(-50%) rotate(45deg);
}
.outside .stage + .stage { border-left: var(--line); padding-left: 14px; }

.stage-share {
  display: flex;
  gap: 2px;
  height: 6px;
  margin-top: 8px;
}
.stage-share span { flex: var(--count) 1 0; min-width: 2px; background: var(--color); border-radius: 1px; }
.stage-share .stage-none { background: repeating-linear-gradient(90deg, var(--ink-soft) 0 3px, transparent 3px 5px); }

.stage-1 { --color: var(--stage-1); }
.stage-2 { --color: var(--stage-2); }
.stage-3 { --color: var(--stage-3); }
.stage-4 { --color: var(--stage-4); }
.stage-5 { --color: var(--stage-5); }
.stage-6 { --color: var(--stage-6); }
.stage-7 { --color: var(--stage-7); }
.stage-none { --color: var(--ink-soft); }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--paper);
  border: var(--line);
  border-radius: var(--radius-panel);
}
.filters.compact { padding: 0; background: none; border: 0; margin-bottom: 16px; }
.filters .field { flex: 0 1 180px; }
.filters .search { flex: 1 1 260px; }
.filters .checkbox { flex-direction: row; align-items: center; gap: 8px; min-height: 36px; }
.filters .actions { display: flex; align-items: center; gap: 14px; min-height: 36px; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; margin: 0; }
.field-label { font-size: var(--step-s); font-weight: 600; }
.field-required { font-weight: 400; color: var(--ink-soft); }
.field-help { font-size: var(--step-xs); color: var(--ink-soft); }
.field-error { font-size: var(--step-s); font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
.field-error::before { content: ""; flex: none; width: 8px; height: 8px; background: var(--magenta); border-radius: 1px; }

input, select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  padding: 6px 10px;
  font: 400 var(--step-m) var(--font);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--field-border);
  border-radius: var(--radius-control);
}
input:hover, select:hover, textarea:hover { border-color: var(--ink); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--violet); }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border: 2px solid var(--magenta); }
input[type="checkbox"] { width: 18px; min-height: 18px; height: 18px; accent-color: var(--violet); }
textarea { resize: vertical; line-height: 1.45; }

.result-count { color: var(--ink-soft); font-size: var(--step-s); margin: 0 0 8px; }

.table-wrap {
  background: var(--paper);
  border: var(--line);
  border-radius: var(--radius-panel);
  overflow: auto;
}

@media (min-width: 721px) {
  .table-wrap.tall { max-height: calc(100vh - 96px); }
}

.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--step-s); }
.table caption { text-align: left; }
.table th, .table td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: var(--line); }
.table tbody tr:last-child > * { border-bottom: 0; }
.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--paper);
  font-size: var(--step-xs);
  font-weight: 600;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--field-border);
  white-space: nowrap;
  vertical-align: bottom;
}
.sort-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  color: inherit;
  font-weight: inherit;
  text-decoration: none;
}
.sort-link::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0;
}
.sort-link:hover, .sort-link:focus-visible { color: var(--ink); text-decoration: underline; }
.sort-link:hover::after, .sort-link:focus-visible::after { opacity: 0.4; }
th[aria-sort="ascending"] .sort-link, th[aria-sort="descending"] .sort-link { color: var(--ink); }
th[aria-sort="ascending"] .sort-link::after { opacity: 1; border-top: 0; border-bottom: 5px solid currentColor; }
th[aria-sort="descending"] .sort-link::after { opacity: 1; }

.table tbody tr:hover > * { background: var(--page); }
.table .num { text-align: right; }
.table .number, .table .date { white-space: nowrap; color: var(--ink-soft); }
.table .name { min-width: 240px; }
.table .name a { color: var(--ink); font-weight: 600; text-decoration: none; }
.table .name a:hover, .table .name a:focus-visible { color: var(--violet); text-decoration: underline; }

.badge {
  --color: var(--stage-7);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--color);
  box-shadow: inset 0 0 0 1px rgb(12 12 14 / 0.25);
}
.badge.stage-none::before { background: none; box-shadow: inset 0 0 0 1px var(--ink-soft); }
.badge.archived { --color: var(--magenta); }

.scope {
  --color: var(--rule);
  display: inline-block;
  padding: 1px 8px;
  border-radius: var(--radius-control);
  background: color-mix(in srgb, var(--color) 28%, var(--paper));
  font-weight: 600;
  white-space: nowrap;
}
.scope.yes { --color: var(--turquoise); }
.scope.no { --color: var(--magenta); }
.scope.unsure { --color: var(--yellow); }
.scope.not-applicable { background: var(--page); color: var(--ink-soft); }

.missing { color: var(--ink-soft); font-style: italic; }
.muted { color: var(--ink-soft); }

.empty-state {
  background: var(--paper);
  border: 1px dashed var(--field-border);
  border-radius: var(--radius-panel);
  padding: 32px;
}
.empty-state p { margin-bottom: 8px; }

.record-number { color: var(--ink-soft); font-weight: 600; margin-bottom: 4px; display: flex; gap: 12px; align-items: center; }
.record-header h1 { max-width: 40ch; }
.record-meta { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 8px 0 0; }
.record-meta div { display: flex; gap: 6px; }
.record-meta dt { color: var(--ink-soft); }
.record-meta dd { margin: 0; font-weight: 600; }

.block {
  --tone: var(--ink);
  min-width: 0;
  background: var(--paper);
  border: var(--line);
  border-left: 4px solid var(--tone);
  border-radius: var(--radius-panel);
  padding: 16px 20px 20px;
  margin: 0 0 16px;
}
.block.orange { --tone: var(--orange); }
.block.turquoise { --tone: var(--turquoise); }
.block.violet { --tone: var(--violet); }
.block > h2, .block > legend { margin-bottom: 14px; }
.block > legend { float: left; width: 100%; padding: 0; font-size: var(--step-l); font-weight: 700; }
.block > legend + * { clear: both; }

.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px 24px; margin: 0; }
.fields .wide { grid-column: 1 / -1; }
.fields dt { font-size: var(--step-s); color: var(--ink-soft); }
.fields dd { margin: 0; overflow-wrap: anywhere; }
.fields .note { align-self: end; color: var(--ink-soft); min-height: 36px; display: flex; align-items: center; }

.form-footer {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 0;
  background: var(--page);
  border-top: var(--line);
}

.month-nav { display: flex; gap: 8px; flex-wrap: wrap; }

.calendar { background: var(--paper); border: var(--line); border-radius: var(--radius-panel); overflow-x: auto; }
.calendar-grid { min-width: 760px; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.week + .week { border-top: var(--line); }
.week.weekdays div { padding: 8px 10px; font-size: var(--step-xs); font-weight: 600; color: var(--ink-soft); border-bottom: 1px solid var(--field-border); }
.day { min-height: 112px; padding: 6px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.day + .day { border-left: var(--line); }
.day.outside { background: var(--page); }
.day.outside .day-number { color: var(--ink-soft); font-weight: 400; }
.day-number { align-self: flex-start; padding: 1px 5px; font-size: var(--step-s); font-weight: 700; }
.day.today .day-number { background: var(--ink); color: var(--paper); border-radius: var(--radius-control); }
.event {
  --color: var(--stage-7);
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 2px 6px;
  border-left: 3px solid var(--color);
  background: var(--page);
  border-radius: 0 3px 3px 0;
  font-size: var(--step-xs);
  line-height: 1.25;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.event:hover { background: var(--lilac); color: var(--ink); }
.event-time { font-weight: 700; }
.event-name { overflow: hidden; text-overflow: ellipsis; }

.panel {
  background: var(--paper);
  border: var(--line);
  border-radius: var(--radius-panel);
  padding: 16px 20px;
  margin-bottom: 24px;
}
.panel > h2 { margin-bottom: 12px; }
.panel .table-wrap { border: 0; border-radius: 0; }
.panel .table th:first-child, .panel .table td:first-child { padding-left: 0; }
.panel-intro { color: var(--ink-soft); margin: -4px 0 14px; max-width: 70ch; }
.panel > h2 .muted { font-weight: 400; margin-left: 6px; }

.inline-form { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px 16px; }
.inline-form .field { flex: 0 1 200px; }
.inline-form .field.wide { flex: 1 1 280px; }
.inline-form-actions { display: flex; align-items: center; padding-top: calc(var(--step-s) * 1.45 + 4px); }

.table.with-controls td { vertical-align: middle; }
.table.with-controls select { min-width: 150px; }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); gap: 24px; }
.panels .panel { margin: 0; }

.undated { margin-top: 24px; }
.undated ul { margin: 0; padding-left: 20px; columns: 2 320px; }
.undated li { margin-bottom: 4px; break-inside: avoid; }

.figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  margin: 0 0 24px;
  background: var(--paper);
  border: var(--line);
  border-radius: var(--radius-panel);
  overflow: hidden;
}
.figure { padding: 14px 16px; border-right: var(--line); border-bottom: var(--line); margin: 0 -1px -1px 0; }
.figure dt { font-size: var(--step-s); color: var(--ink-soft); line-height: 1.25; min-height: 2.5em; }
.figure dd { margin: 6px 0 0; font-size: 1.75rem; font-weight: 700; line-height: 1; }

.table.matrix th, .table.matrix td { white-space: nowrap; }
.table.matrix thead th:not(:first-child) { white-space: normal; min-width: 76px; }
.table.matrix tbody th { font-weight: 600; }
.table.matrix td a { font-weight: 600; }
.table.matrix .zero { color: var(--ink-soft); }
.table.matrix .total, .table.matrix tfoot > tr > * { font-weight: 700; }
.table.matrix tfoot > tr > * { border-top: 1px solid var(--field-border); border-bottom: 0; }

.table.bars tbody th { font-weight: 600; white-space: nowrap; }
.table.bars tbody th a { color: var(--ink); text-decoration: none; }
.table.bars tbody th a:hover, .table.bars tbody th a:focus-visible { color: var(--violet); text-decoration: underline; }
.table.bars .dept { color: var(--ink-soft); }
.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.bar { display: block; height: 10px; width: calc(var(--share) * 110px); min-width: 2px; background: var(--violet); border-radius: 1px; }
.bar-value { font-weight: 700; }

.sign-in { max-width: 480px; margin-top: 48px; }
.sign-in h1 { margin-bottom: 8px; }
.sign-in p { margin-bottom: 20px; }

@media (max-width: 1100px) {
  .stage-strip { flex-direction: column; }
  .stage-group.flow { grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stage-group.flow .stage { padding-left: 14px; border-bottom: var(--line); }
  .stage-group.flow .stage + .stage::before { display: none; }
  .stage-group.flow .stage:not(:nth-child(3n + 1)) { border-left: var(--line); }
  .session-name { display: none; }
}

@media (max-width: 720px) {
  .app-bar-inner { flex-wrap: wrap; gap: 0 16px; padding: 0 16px; }
  .brand { min-height: 48px; }
  .session { margin-left: auto; }
  .main-nav { order: 3; flex-basis: 100%; overflow-x: auto; margin: 0 -8px; }
  .main-nav a { min-height: 44px; padding: 0 8px; }
  main { padding: 16px 16px 48px; }
  .stage-group.flow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage-group.flow .stage:not(:nth-child(3n + 1)) { border-left: 0; }
  .stage-group.flow .stage:nth-child(2n) { border-left: var(--line); }
  .stage-group.outside { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters .field, .filters .search, .inline-form .field, .inline-form .field.wide { flex: 1 1 100%; }
  .inline-form-actions { padding-top: 0; }
  .block { padding: 14px 16px 16px; }
  .panel { padding: 14px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
