/* The Visits > Workflows board: one table for the month, a row per visit, and a track of small
   squares showing each step's status. The track is the one loud thing on the page;
   everything else follows the Patients table. */
.workflow-board--page {
  /* Big enough for two initials. */
  --workflow-step-size: var(--rem-22);
  --workflow-step-gap: var(--rem-2);
  --workflow-phase-gap: var(--rem-12);
  --workflow-phase-pre-width: calc(6 * var(--workflow-step-size) + 5 * var(--workflow-step-gap));
  --workflow-phase-short-width: calc(5 * var(--workflow-step-size) + 4 * var(--workflow-step-gap));

  /* Spaced by the margins the calendar's header, tabs and filter bar already carry, so
     switching tabs moves nothing. */
  padding-bottom: var(--rem-32);
}

/* Narrow windows scroll the table sideways, never the page. */
.workflow-board--scroll {
  overflow-x: auto;
  padding: 1px;
}

/* Builds on the global table (white card, light outline, row rules), as the Patients
   list does. */
.workflow-board--table {
  /* The set columns plus 10rem for insurance. */
  min-width: 89.5rem;

  /* Headings sit on the line just above the rows, so a step name that wraps onto two or
     three lines grows upwards and every heading still lines up at its foot. */
  th {
    vertical-align: bottom;
  }

  td {
    vertical-align: middle;
  }

  td {
    padding-block: var(--rem-10);
  }
}

/* On the header cells: in a fixed layout the first row sets the widths. The patient
   has a set width, long names ending in "…", so wide windows give their spare room
   to the insurance column, whose payer names are the ones cut short. */
.workflow-board--col-visit { width: 10.5rem; }
.workflow-board--col-patient { width: 12rem; }
.workflow-board--col-physician { width: 10rem; }
.workflow-board--col-backoffice { width: 10rem; }
.workflow-board--col-insurance { width: auto; }
.workflow-board--col-steps { width: 26rem; }
.workflow-board--col-status { width: 8rem; }
.workflow-board--col-menu { width: 3rem; }

/* Windows too narrow for every name (under about 1640px, with the sidebar): the
   physician and backoffice owner shrink to their avatars (named on hover) and the
   squares get smaller, so the table still fits without scrolling sideways. */
@media (max-width: 1640px) {
  /* Smaller squares: they still hold two initials. */
  .workflow-board--page {
    --workflow-step-size: var(--rem-18);
  }

  /* The set columns plus 10rem for insurance. */
  .workflow-board--table {
    min-width: 75.5rem;
  }

  .workflow-board--table .workflow-board--col-patient {
    width: 11rem;
  }

  .workflow-board--table .workflow-board--col-steps {
    width: 22rem;
  }

  /* Wide enough for the header, which stays: two avatar-only columns need their names. */
  .workflow-board--table .workflow-board--col-physician,
  .workflow-board--table .workflow-board--col-backoffice {
    width: 5.5rem;
  }

  .workflow-board--table td.workflow-board--col-physician,
  .workflow-board--table td.workflow-board--col-backoffice {
    font-size: 0;
  }

  .workflow-board--table .workflow-board--col-physician .details-row--value-text,
  .workflow-board--table .workflow-board--col-backoffice .details-row--value-text {
    display: none;
  }
}

/* Narrower still: insurance goes too. */
@media (max-width: 1320px) {
  .workflow-board--table {
    min-width: 50rem;
  }

  .workflow-board--table .workflow-board--col-insurance {
    display: none;
  }
}

/* ---- Cells ---- */

.workflow-board--appointment {
  display: block;
  text-decoration: none;
}

.workflow-board--time {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
  font-variation-settings: 'wght' var(--text-semibold);
  color: var(--text-heading);
}

.workflow-board--secondary {
  display: block;
  margin-top: var(--rem-2);
  font-size: var(--rem-12);
  color: var(--text-additional);
  overflow: hidden;
  text-overflow: ellipsis;
}

.workflow-board--patient {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-heading);
  font-variation-settings: 'wght' var(--text-semibold);
  text-decoration: none;
}

.workflow-board--insurance {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Step track ---- */

.workflow-board--track {
  display: flex;
  align-items: center;
  gap: var(--workflow-phase-gap);
}

.workflow-board--phase {
  display: flex;
  gap: var(--workflow-step-gap);
  width: var(--workflow-phase-short-width);

  &[data-phase="pre_visit"] {
    width: var(--workflow-phase-pre-width);
  }
}

/* The column heading names each group of squares, sitting right above it. */
.workflow-board--track-heading .workflow-board--phase {
  display: block;
  font-size: var(--rem-12);
  white-space: nowrap;
}

.workflow-board--step {
  flex: none;
  display: inline-flex;
  text-decoration: none;
  align-items: center;
  justify-content: center;
  width: var(--workflow-step-size);
  height: var(--workflow-step-size);
  border-radius: var(--radius-xs);
  /* Pending: nothing done yet, so an empty white square with an outline. */
  background: var(--surface-primary);
  box-shadow: inset 0 0 0 1px var(--neutral-400);
  /* Who last changed the step. */
  font-size: var(--rem-9);
  line-height: 1;
  letter-spacing: 0.02em;
  font-variation-settings: 'wght' var(--text-semibold);
  color: var(--neutral-700);

  &[data-status="in_progress"] { background: var(--warning-300); color: var(--warning-900); }
  &[data-status="done"] { background: var(--primary-500); color: var(--text-on-action); }
  &[data-status="blocked"] { background: var(--error-500); color: var(--text-on-action); }

  /* Nothing to do: filled grey, settled like Done but quieter. */
  &[data-status="not_needed"] {
    background: var(--neutral-200);
    color: var(--neutral-600);
  }

  &[data-status="in_progress"],
  &[data-status="done"],
  &[data-status="blocked"],
  &[data-status="not_needed"] {
    box-shadow: none;
  }
}

/* Text as in the calendar footer's legend, where this legend's classes come from. */
.workflow-board--legend {
  margin-bottom: var(--rem-12);
  font-size: var(--rem-13);
  color: var(--text-body);
}

/* The legend's swatches name a colour, not a person: keep them small. */
.workflow-board--legend .workflow-board--step {
  width: var(--rem-12);
  height: var(--rem-12);
  border-radius: var(--radius-xxs);
}

/* A cancelled or no-show visit, shown only on request: present, but stepped back. */
.workflow-board--row[data-hidden-visit="true"] td {
  opacity: 0.55;
}

/* ---- Empty month ---- */

/* As the Inbox's empty list: one quiet line. */
.workflow-board--empty {
  color: var(--text-additional);
}

/* ---- Legend row and hint ---- */

.workflow-board--legend-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--rem-8) var(--rem-24);
  margin-bottom: var(--rem-12);

  .workflow-board--legend {
    margin-bottom: 0;
  }
}

/* How to use the board, as quiet as the legend beside it. */
.workflow-board--hint {
  font-size: var(--rem-13);
  color: var(--text-additional);
}

/* A square whose step has comments carries a small dot in its corner. */
.workflow-board--step[data-comments="true"] {
  position: relative;

  &::after {
    content: "";
    position: absolute;
    top: -2px;
    right: -2px;
    width: var(--rem-6);
    height: var(--rem-6);
    border: 1px solid var(--surface-primary);
    border-radius: var(--radius-full);
    background: var(--neutral-800);
  }
}

/* ---- Focused phase: one labelled column per step ---- */

/* The patient gets a fixed width and the steps share whatever is left evenly, rather
   than the patient soaking up the spare room and pushing the steps to the right. */
.workflow-board--table[data-phase]:not([data-phase="all"]) {
  min-width: 66rem;

  .workflow-board--col-patient {
    width: 11rem;
  }

  /* The step columns need the room, so the backoffice owner is an avatar (named on
     hover), as the owners in the step cells are. */
  .workflow-board--col-backoffice {
    width: 5.5rem;
  }

  td.workflow-board--col-backoffice {
    font-size: 0;

    .details-row--value-text {
      display: none;
    }
  }

  /* A step cell grows a second line when it has an owner or comments. Every cell hangs
     from the top, so each Tag stays on the line of the visit's date and name, whatever
     the cells beside it hold. */
  td {
    vertical-align: top;
  }
}

/* Step names wrap onto two or three lines rather than widening the table, with room on
   their right so one name never runs into the next. */
.workflow-board--table .workflow-board--col-step,
.workflow-board--table .workflow-board--step-cell {
  padding-right: var(--rem-16);
}

.workflow-board--col-step {
  white-space: normal;
  line-height: 1.25;
}

/* The whole cell opens the step: its status Tag, and under it the owner and comment
   count when there are any. */
.workflow-board--step-cell-link {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--rem-4);
  text-decoration: none;
}

.workflow-board--step-cell-meta {
  display: flex;
  align-items: center;
  gap: var(--rem-6);
}

.workflow-board--comment-count {
  display: inline-flex;
  align-items: center;
  gap: var(--rem-2);
  font-size: var(--rem-12);
  color: var(--text-additional);
}

/* Narrower windows in a focused phase: the step cells already say each step's status,
   so the visit's overall Status column goes, and the step columns tighten. */
@media (max-width: 1320px) {
  .workflow-board--table[data-phase]:not([data-phase="all"]) {
    min-width: 50rem;

    .workflow-board--col-status {
      display: none;
    }

    .workflow-board--col-patient {
      width: 10rem;
    }
  }
}

/* ---- Backoffice owner and coverage ---- */

/* Payer on top, then the eligibility Tag and, in the Pre-visit view, the auth Tag. */
.workflow-board--coverage {
  display: flex;
  flex-direction: column;
  gap: var(--rem-4);
  min-width: 0;
}

.workflow-board--coverage-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--rem-4);
}

.workflow-board--col-coverage {
  width: 9rem;
}

/* The empty owner avatar sits where an owner's initials would. */
.workflow-board--unassigned {
  display: inline-flex;
}

/* The eligibility Tag opens the patient's insurance. */
.workflow-board--eligibility-link {
  display: inline-flex;
  border-radius: var(--rem-4);
  text-decoration: none;
}

/* ---- Follow-up ---- */

.workflow-board--col-follow-up {
  width: 8rem;
}

/* The date on top, how far off it is under it, as the appointment cell reads. */
.workflow-board--follow-up {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.workflow-board--follow-up-date {
  font-variant-numeric: tabular-nums;
  font-variation-settings: 'wght' var(--text-semibold);
}

/* Under the status Tag on the All steps view. */
.workflow-board--col-status .workflow-board--follow-up {
  margin-top: var(--rem-4);
}

/* The prior-auths step also carries the visit's auth Tag, so its column is wider than
   the other steps'. */
.workflow-board--col-step[data-step-key="eligibility_and_prior_auths"] {
  width: 8rem;
}

/* A Tag never runs into the next step's column: a long status ends in "…" inside its
   cell, named in full on hover. */
.workflow-board--step-cell-link {
  min-width: 0;
  max-width: 100%;

  .chips--chip {
    max-width: 100%;
    min-width: 0;
  }

  .chips--chip > :not(.chips--text) {
    flex-shrink: 0;
  }

  .chips--text {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
