/*
 * Schedule. Every colour is a variable from theme.css; no hex value here.
 *
 * NOTHING IS CUT OFF. No block has a fixed height: a day row is a CSS grid
 * whose lanes are `auto` rows, so a job's words wrap and the row grows. The
 * only fixed sizes are widths of time (an hour, a day column), and words
 * inside them wrap rather than spill.
 *
 * A state is a colour AND its word: the bar down a job's leading edge says
 * the state, and the word under the client says it again.
 */

.schedule {
  --name-w: 236px;
}

.sch-head {
  margin-bottom: var(--gap-2);
}

/* Toolbar ------------------------------------------------------------------ */

.sch-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px var(--gap-2);
  margin-bottom: 12px;
}

.sch-nav,
.sch-top__end,
.sch-filters,
.sch-chosen {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-1);
}

.sch-range {
  margin-left: var(--gap-1);
  font-size: var(--size-body);
  font-weight: 700;
}

.sch-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--chip);
  font-weight: 600;
}

.sch-arrow:hover {
  background: var(--line);
}

.sch-arrow svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sch-arrow__back {
  transform: rotate(180deg);
}

.sch-views {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--chip);
}

.sch-views__button {
  min-height: 34px;
  padding: 4px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-weight: 600;
}

.sch-views__button[aria-pressed="true"] {
  background: var(--card);
  box-shadow: 0 0 0 1px var(--card-ring);
}

.sch-filters {
  margin-bottom: 12px;
}

.sch-select {
  display: inline-flex;
  align-items: center;
  gap: var(--gap-1);
  min-height: 36px;
  padding: 0 4px 0 12px;
  border-radius: var(--radius);
  background: var(--chip);
  font-size: var(--size-small);
}

.sch-select__label {
  color: var(--ink-2);
  font-weight: 600;
}

/* The Team box's place while the teams are read (E1). */
.sch-select__hold {
  display: inline-block;
  min-height: 20px;
  margin: 6px 8px 6px 0;
  font-weight: 600;
}

.sch-select select {
  min-height: 32px;
  max-width: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
}

.sch-chosen {
  margin-bottom: 12px;
}

.sch-chosen__text {
  font-weight: 600;
}

/* The strip of counts above a day -------------------------------------------- */

.sch-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.schedule > .sch-strip {
  margin-bottom: 12px;
}

.sch-count {
  display: inline-flex;
  align-items: flex-start;
  gap: 6px;
  min-height: 28px;
  padding: 4px 10px;
  border: 0;
  border-radius: 14px;
  background: var(--chip);
  font-size: var(--size-small);
  font-weight: 500;
  text-align: left;
}

.sch-count::before {
  content: "";
  flex: 0 0 auto;
  margin-top: 0.45em;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-strong);
}

.sch-count--red::before {
  background: var(--red);
}

.sch-count--amber::before {
  background: var(--amber);
}

.sch-count:hover {
  background: var(--line);
}

.sch-count[aria-pressed="true"] {
  background: var(--brand);
  color: var(--on-fill);
}

.sch-count__n {
  font-weight: 700;
}

/* The card and its scroll box ------------------------------------------------ */

.sch {
  overflow: hidden;
}

.sch-scroll {
  position: relative;
  overflow: auto;
  overscroll-behavior: contain;
}

.sch-corner {
  position: sticky;
  left: 0;
  z-index: 5;
  background: var(--card);
  border-right: 1px solid var(--line);
}

.sch-name {
  position: sticky;
  left: 0;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card);
  border-right: 1px solid var(--line);
}

.sch-name .face {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  background: var(--chip);
  color: var(--ink);
  font-size: 12px;
}

.sch-name--nobody .face {
  background: var(--red);
  color: var(--on-fill);
}

.sch-name__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sch-name .name {
  font-weight: 600;
}

.sch-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
}

.sch-fact {
  color: var(--ink-2);
  font-size: var(--size-small);
}

.sch-fact.state {
  color: var(--ink);
  font-weight: 600;
}

.sch-fact--off {
  color: var(--ink);
  font-weight: 600;
}

/* A day, or a part of one, she does not work: grey stripes, and a word. */
.sch-shade,
.sch-tl.is-off,
.sch-cell.is-off {
  background-image: repeating-linear-gradient(135deg, var(--chip) 0 6px, transparent 6px 12px);
}

/* Day ---------------------------------------------------------------------- */

.sch-day {
  width: max-content;
  min-width: 100%;
}

.sch-row {
  display: grid;
  grid-template-columns: var(--name-w) var(--tl-width);
  border-bottom: 1px solid var(--line);
}

.sch-row--head {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--card);
}

.sch-row--nobody {
  border-bottom: 2px solid var(--line-strong);
}

.sch-hours {
  display: flex;
}

.sch-hour {
  flex: 0 0 var(--hour);
  padding: 8px 6px;
  border-left: 1px solid var(--line);
  color: var(--ink-2);
  font-size: var(--size-small);
  font-weight: 600;
}

.sch-tl {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), calc(var(--hour) / 12));
  row-gap: 4px;
  align-content: start;
  min-height: 60px;
  padding: 6px 0;
  background-color: var(--card);
}

/* Hour lines, under everything. */
.sch-tl::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: repeating-linear-gradient(to right, var(--line) 0 1px, transparent 1px var(--hour));
  pointer-events: none;
}

.sch-shade {
  position: relative;
  z-index: 0;
  margin: -6px 0;
}

/* Now: a line under the jobs, so it never crosses their words. */
.sch-now {
  position: relative;
  z-index: 0;
  width: 2px;
  margin: -6px 0;
  background: var(--red);
  pointer-events: none;
}

/* A job ---------------------------------------------------------------------- */

.sch-job {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 6px 10px 6px 10px;
  border-left: 4px solid var(--line-strong);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 0 0 1px var(--line);
  font-size: var(--size-small);
  line-height: 1.35;
  overflow-wrap: anywhere;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.sch-job--day {
  margin: 0 2px;
}

/* A job's words: one box, as the block's children were (the gap is the block's). */
.sch-job__words {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

/* On the Day grid the words stay in sight beside the names while the block runs off
   the left edge (E5): sticky inside their own block, so they never leave it. */
.sch-job--day .sch-job__words {
  position: sticky;
  left: calc(var(--name-w) + 12px);
  align-self: flex-start;
  max-width: 100%;
}

.sch-job:hover {
  box-shadow: 0 0 0 1px var(--line-strong), 0 2px 6px rgba(16, 24, 40, 0.08);
}

.sch-job--red {
  border-left-color: var(--red);
}

.sch-job--amber {
  border-left-color: var(--amber);
}

.sch-job--green {
  border-left-color: var(--green);
}

.sch-job--brand {
  border-left-color: var(--brand);
}

.sch-job--done {
  background: var(--hover);
  color: var(--ink-2);
}

.sch-job.is-selected {
  box-shadow: 0 0 0 2px var(--brand);
}

.sch-job.is-dragging {
  z-index: 20;
  cursor: grabbing;
  box-shadow: 0 0 0 2px var(--brand), 0 12px 28px rgba(16, 24, 40, 0.2);
}

.sch-job.is-saving {
  opacity: 0.7;
}

.sch-job__time {
  font-weight: 700;
}

.sch-job__client {
  font-weight: 600;
  color: var(--ink);
}

.sch-job--done .sch-job__client {
  color: var(--ink-2);
}

.sch-job__address {
  color: var(--ink-2);
}

.sch-job__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 2px 10px;
}

.sch-job__foot .state {
  font-size: var(--size-small);
}

.sch-job__repeat,
.sch-job__saving {
  color: var(--ink-2);
  font-weight: 600;
}

.sch-job__saving {
  color: var(--brand);
}

/* The right edge: drag it to change the length. */
.sch-job__edge {
  position: absolute;
  top: 0;
  right: -2px;
  bottom: 0;
  width: 10px;
  cursor: ew-resize;
}

.sch-job__edge::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 4px;
  width: 2px;
  height: 14px;
  margin-top: -7px;
  border-radius: 1px;
  background: var(--line-strong);
  opacity: 0;
}

.sch-job:hover .sch-job__edge::after {
  opacity: 1;
}

/* Where a dragged job would land. */
.sch-drop {
  outline: 2px dashed var(--brand);
  outline-offset: -2px;
}

/* Week --------------------------------------------------------------------- */

/* Seven days fit beside the names on a 1440 screen with the menu open. */
.sch--week {
  --name-w: 196px;
}

/* A day is at least 96 px, so all seven fit beside the names at 1280 too (D2: at
   124 Sunday was past the card's edge with no sign). At 1440 each day is about 127
   px either way, so nothing there changes. */
.sch--week {
  --day-min: 96px;
}

/* Under 1366 wide (a 1280 laptop), the names column and the padding give a little
   room back so a word like "Maplewood," still fits a job card whole in a day of
   about 108 px. Nothing changes at 1366 and wider. */
@media (max-width: 1365px) {
  .sch--week {
    --name-w: 172px;
  }

  .sch--week .sch-cell {
    padding: 4px;
  }

  .sch--week .sch-job {
    padding: 6px 8px;
  }

  /* A card's state is its coloured left bar and its word; beside the word, the dot
     of the same colour took the room a word like "Programado" needs, and broke it. */
  .sch--week .sch-job .state::before {
    display: none;
  }
}

.sch-week {
  min-width: calc(var(--name-w) + 7 * var(--day-min));
}

.sch-wrow {
  display: grid;
  grid-template-columns: var(--name-w) repeat(7, minmax(var(--day-min), 1fr));
  border-bottom: 1px solid var(--line);
}

.sch-wrow--head {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--card);
}

.sch-wrow--nobody {
  border-bottom: 2px solid var(--line-strong);
}

.sch-wday {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-left: 1px solid var(--line);
}

.sch-wday.is-today {
  box-shadow: inset 0 3px 0 var(--brand);
}

.sch-wday__label {
  align-self: flex-start;
  padding: 0;
  border: 0;
  background: transparent;
  font-weight: 700;
  text-align: left;
}

.sch-wday__label:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sch-wday .sch-count {
  min-height: 24px;
  padding: 2px 8px;
}

.sch-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 64px;
  min-width: 0;
  padding: 6px;
  border-left: 1px solid var(--line);
}

.sch-cell.is-today {
  background-color: var(--hover);
}

/* Teams -------------------------------------------------------------------- */

.sch-group {
  display: block;
  background: var(--chip);
  border-bottom: 1px solid var(--line);
}

.sch-group__button {
  position: sticky;
  left: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--gap-1);
  min-height: 38px;
  padding: 6px 12px;
  border: 0;
  background: transparent;
  font-weight: 700;
  text-align: left;
}

.sch-group__chev {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 120ms ease-out;
}

.sch-group__chev.is-open {
  transform: rotate(90deg);
}

.sch-group__count {
  color: var(--ink-2);
  font-size: var(--size-small);
  font-weight: 600;
}

.sch-more {
  height: 1px;
}

/* Compact: more rows on screen, the same facts minus the address. ------------ */

.sch--compact .sch-name {
  padding: 5px 12px;
  align-items: center;
}

.sch--compact .sch-name .face {
  width: 24px;
  height: 24px;
  font-size: 11px;
}

.sch--compact .sch-tl {
  min-height: 40px;
  padding: 3px 0;
  row-gap: 3px;
}

.sch--compact .sch-job {
  flex-direction: row;
  flex-wrap: wrap;
  column-gap: 8px;
  padding: 3px 8px;
}

.sch--compact .sch-cell {
  min-height: 40px;
  gap: 4px;
  padding: 4px;
}

/* Month -------------------------------------------------------------------- */

.sch-month {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.sch-mhead {
  padding: 8px 10px;
  background: var(--card);
  color: var(--ink-2);
  font-size: var(--size-small);
  font-weight: 600;
}

.sch-mday {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-height: 116px;
  padding: 8px 10px;
  border: 0;
  background: var(--card);
  font-size: var(--size-small);
  text-align: left;
}

.sch-mday:hover {
  background: var(--hover);
}

.sch-mday.is-other {
  background: var(--page);
  color: var(--ink-2);
}

.sch-mday__date {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  margin: -4px 0 2px -6px;
  border-radius: 14px;
  font-size: var(--size-body);
  font-weight: 700;
}

.sch-mday.is-today .sch-mday__date {
  background: var(--brand);
  color: var(--on-fill);
}

.sch-mday__jobs {
  font-weight: 700;
}

.sch-mline {
  display: inline-flex;
  align-items: flex-start;
  gap: 6px;
}

.sch-mline::before {
  content: "";
  flex: 0 0 auto;
  margin-top: 0.45em;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-strong);
}

.sch-mline--red::before {
  background: var(--red);
}

.sch-mline--amber::before {
  background: var(--amber);
}

.sch-mline--green::before {
  background: var(--green);
}

.sch-mline--brand::before {
  background: var(--brand);
}

/* List --------------------------------------------------------------------- */

.sch-list {
  padding: 4px 0 var(--gap-2);
}

.sch-list__day + .sch-list__day {
  margin-top: var(--gap-2);
}

/* Its pages (E1): which jobs this page holds, the page before and after, and the
   days of the view with their counts. */
.sch-list__pages {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 12px 20px 4px;
}

.sch-list__pages--end {
  padding: var(--gap-2) 20px 4px;
}

.sch-list__range {
  color: var(--ink-2);
  font-size: var(--size-small);
  font-weight: 600;
}

.sch-list__step {
  display: inline-flex;
  gap: var(--gap-1);
}

.sch-list__days {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-basis: 100%;
}

.sch-list__days .chip {
  gap: 6px;
}

.sch-list__count {
  color: var(--ink-2);
  font-weight: 600;
}

.sch-list__date {
  padding: 12px 20px 4px;
  font-size: var(--size-body);
  font-weight: 700;
}

/* One set of column widths for every day, so the days line up. */
.sch-list__table {
  table-layout: fixed;
}

.sch-list__table th:nth-child(1) {
  width: 17%;
}

.sch-list__table th:nth-child(2) {
  width: 21%;
}

.sch-list__table th:nth-child(3) {
  width: 28%;
}

.sch-list__table th:nth-child(4) {
  width: 18%;
}

/* The job in the side panel ------------------------------------------------ */

.drawer__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-1);
  padding: 0 20px 20px;
}

.sch-who {
  display: grid;
  gap: 6px;
}

.sch-who__row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
}

.sch-edit {
  padding: 4px 20px 0;
}

.sch-edit .drawer__actions {
  padding: 4px 0 20px;
}

.sch-edit__times {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.sch-edit .find {
  margin-bottom: var(--gap-1);
}

.sch-pick {
  display: grid;
}

.sch-pick__row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}

.sch-pick__row input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

/* Print: the list, and nothing of the frame around it. ----------------------- */

/* The whole list, every page, put beside the page shown only while printing
   (views/schedule.js listPrint). Never seen on screen. */
.sch-list__print {
  display: none;
}

@media print {
  .band,
  .menu,
  .drawer,
  .sch-top,
  .sch-filters,
  .sch-chosen,
  .schedule > .notice,
  .schedule > .sch-strip {
    display: none !important;
  }

  body {
    background: var(--card);
  }

  .page {
    padding: 0;
  }

  .card {
    box-shadow: none;
  }

  .tbl th {
    position: static;
  }

  .tbl-scroll.is-wide {
    max-height: none;
    overflow: visible;
  }

  .sch-list__day {
    break-inside: avoid-page;
  }

  .sch-list__step,
  .sch-list__days {
    display: none !important;
  }

  .sch-list.is-printing-all > :not(.sch-list__print) {
    display: none !important;
  }

  .sch-list.is-printing-all > .sch-list__print {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sch-group__chev {
    transition: none;
  }
}

/* The grid while the days of a view are still being read: room held, nothing
   that reads as "nothing booked". */
.sch-loading {
  min-height: 420px;
}

/* A week's cell while its days are read (views/schedule.js waitingGrid, D4): a grey
   bar where its jobs will go. */
.sch-hold {
  display: block;
  min-height: 48px;
}
