/* =============================================================================
   The calendar
   =============================================================================

   Specification: scheduling.md SC-1, SC-3, SC-4, SC-6, SC-14.

   Not isolated CSS, and not a fork of work.css either. The calendar sits beside the
   job screens — somebody moves between a block and the job it belongs to in one
   sitting — so it inherits `.work-page` and adds only what a time grid needs.

   Every colour here comes from tokens.css. The ONE exception is `--who`, the
   assignee's own colour, which is set inline per block from `User.DefaultColorHex`
   because it is data rather than design (SC-4: a person owns their colour, and it
   is stored on the person). That is also why there is no palette in this file: a
   second source for the colour would mean the office learns that green is Dale on
   one half of the screen and somebody else on the other, which is worse than no
   colour at all.
   ========================================================================== */

/* ---- Buttons -------------------------------------------------------------
   work.css styles buttons as `.work-page .actions button`, and none of the
   calendar's buttons sit in an `.actions` row — they are in the day header, on a
   block, and in the warning panel. So the base is restated here for this page
   only, with the SAME modifier names (`.primary`, `.quiet`) so that a button is
   written the same way on every screen. Values come from work.css; nothing is
   invented. */

.schedule-page .btn {
  min-height: var(--touch-min);
  padding: 0 var(--space-3);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.schedule-page .btn.primary {
  color: var(--on-primary);
  background: var(--primary);
  border-color: var(--primary);
}

.schedule-page .btn.primary:hover {
  background: var(--primary-hover);
}

/* The day arrows and Today. Quiet because they are used constantly and must not
   compete with anything on the grid for attention. */
.schedule-page .btn.quiet {
  border-color: var(--border);
  background: transparent;
  font-weight: var(--weight-medium);
  padding: 0 var(--space-2);
}

.schedule-page .btn.quiet:hover {
  background: var(--surface-sunken);
}

.schedule-page .btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* work.css has `.state` and `.state.error`; a calendar also has things that went
   RIGHT and are worth saying ("job 1043 is back in the queue"). Healthy rather
   than primary, so it cannot be mistaken for something needing a decision. */
.schedule-page .state.ok {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--healthy-bg);
  border: 1px solid var(--healthy-border);
  border-radius: var(--radius);
  color: var(--healthy);
  margin-bottom: var(--space-4);
}

/* ---- The day, and which day --------------------------------------------- */

.schedule-page .day-head {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.schedule-page .day-head h1 {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  margin: 0;
  flex: 1 1 auto;
}

.schedule-page .day-move {
  display: flex;
  gap: var(--space-1);
}

.schedule-page .day-pick input {
  min-height: var(--touch-min);
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

/* SC-18 — narrowing the calendar to one person. Sits beside the date picker and is
   built from the same tokens: it is another way of choosing what is on screen, not a
   command, so it must not read as more important than the day it is showing. */
.schedule-page .day-showing select {
  min-height: var(--touch-min);
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;

  /* Bounded so eight fitters with long names cannot push the date off the row, and
     wide enough that a name is not truncated to initials on the common case. */
  max-width: 16rem;
}

/* Which clock these times are in. Quiet, because the office reads it as obvious —
   it is there for the day a second dealership is onboarded in another zone. */
.schedule-page .zone {
  font-size: var(--text-xs);
  color: var(--text-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 2px var(--space-2);
  white-space: nowrap;
}

/* ---- Queue beside grid --------------------------------------------------- */

.schedule-page .board {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}

@media (max-width: 900px) {
  /* The queue goes above the grid rather than beside it. Dragging between the two
     still works, and a 280px column on a phone leaves the grid unusable. */
  .schedule-page .board {
    grid-template-columns: minmax(0, 1fr);
  }
}

.schedule-page .queue {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  box-shadow: var(--shadow-sm);
}

.schedule-page .queue h2 {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.schedule-page .queue .count {
  background: var(--surface-sunken);
  border-radius: var(--radius-pill);
  padding: 0 var(--space-2);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.schedule-page .queue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2);
  max-height: 60vh;
  overflow-y: auto;
}

.schedule-page .queue-item {
  display: grid;
  gap: 2px;
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--unknown);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: grab;
}

.schedule-page .queue-item:active {
  cursor: grabbing;
}

.schedule-page .queue-item .number {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-subtle);
}

.schedule-page .queue-item .who {
  font-weight: var(--weight-medium);
}

.schedule-page .queue-item .what,
.schedule-page .queue-item .where {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.schedule-page .queue .more {
  margin: var(--space-3) 0 0;
  font-size: var(--text-xs);
  color: var(--text-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ---- The grid ------------------------------------------------------------ */

.schedule-page .grid-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  min-width: 0;
}

.schedule-page .grid-head,
.schedule-page .grid {
  display: grid;
  /* The hour gutter, then one equal column per person. Set by the same rule in both
     so a column heading cannot drift out of line with the column under it. */
  grid-template-columns: 56px repeat(auto-fit, minmax(120px, 1fr));
}

.schedule-page .grid-head {
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
  position: sticky;
  top: 0;
  z-index: 3;
}

.schedule-page .col-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  border-left: 1px solid var(--border);
  min-width: 0;
}

/* The person's own colour, as a swatch beside their name rather than as the only
   way to tell who a column belongs to (AC-15). */
.schedule-page .col-head .swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--who);
  flex: none;
}

.schedule-page .col-head .col-count {
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

/* TC-8 AC-36, AC-38: approved leave on the calendar, with pending visibly different.
   Colour alone is not the distinction — the words differ too ("On leave" / "Leave
   requested"), so the two read apart without relying on sight of the hue. */
.schedule-page .col-head .leave-badge {
  flex: none;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  padding: 1px var(--space-2);
  border-radius: var(--radius-full, 999px);
  background: var(--warning-subtle, #fdf0d5);
  color: var(--warning-strong, #8a5a00);
  border: 1px solid var(--warning, #e0a82e);
  white-space: nowrap;
}

.schedule-page .col-head .leave-badge.pending {
  background: transparent;
  border-style: dashed;
  color: var(--text-subtle);
}

.schedule-page .grid-scroll {
  /* Twenty-four hours exist; nine of them are on screen. AC-8 is the scroll
     position, and this is what makes it a position rather than a boundary. */
  max-height: 70vh;
  overflow-y: auto;
}

.schedule-page .grid {
  position: relative;
  height: calc(24 * var(--hour-height));
}

.schedule-page .hours {
  position: relative;
  border-right: 1px solid var(--border);
}

.schedule-page .hour {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--hour-height);
  padding: 2px var(--space-1) 0 0;
  text-align: right;
  font-size: var(--text-xs);
  color: var(--text-subtle);
  border-top: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.schedule-page .col {
  position: relative;
  border-left: 1px solid var(--border);
  min-width: 0;
}

/* ---- Half-hour drop targets --------------------------------------------- */

.schedule-page .slot {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed transparent;
}

/* Every other slot gets the hour line. Dashed for the half hour so the eye reads
   the hour as the stronger division. */
.schedule-page .slot:nth-child(odd) {
  border-top-color: var(--border);
  border-top-style: solid;
}

.schedule-page .slot:nth-child(even) {
  border-top-color: var(--surface-sunken);
}

/* AC-10. Outside 8–5 is SHADED, which is a hint. It is never a refusal: an
   emergency wire-break call at half past six in the evening is real work, and a
   calendar that cannot represent it gets worked around with a note somewhere else,
   at which point the schedule has stopped being the truth. */
.schedule-page .slot.out,
.schedule-page .hour.out {
  background: var(--surface-sunken);
}

.schedule-page .slot .ghost {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  color: var(--primary);
  background: var(--primary-subtle);
  outline: 2px dashed var(--primary-border);
  outline-offset: -2px;
  pointer-events: none;
}

/* ---- A block ------------------------------------------------------------- */

.schedule-page .block {
  position: absolute;
  left: 2px;
  right: 2px;
  z-index: 2;
  overflow: hidden;
  border-radius: var(--radius-sm);
  /* The assignee's colour carries identity, so it is the whole left edge rather
     than a tint — readable at a glance down a column, and it survives the block
     being too short to show much else. */
  border-left: 5px solid var(--who);
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: grab;
}

.schedule-page .block:active {
  cursor: grabbing;
}

.schedule-page .block.lifting,
.schedule-page .queue-item.lifting {
  opacity: 0.4;
}

.schedule-page .block-open {
  display: grid;
  gap: 1px;
  padding: var(--space-1) var(--space-2);
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.schedule-page .block-open:hover {
  background: var(--primary-subtle);
}

.schedule-page .block .times {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.schedule-page .block .who {
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.schedule-page .block .what,
.schedule-page .block .where,
.schedule-page .block .fitter {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Out of hours, said in words as well as by the shading under it — the shading is
   behind the block and a block covers it. */
.schedule-page .block.out-of-hours {
  border-top-color: var(--due-soon-border);
  border-right-color: var(--due-soon-border);
  border-bottom-color: var(--due-soon-border);
}

.schedule-page .block .flag {
  position: absolute;
  right: var(--space-1);
  bottom: var(--space-1);
  font-size: 0.6875rem;
  color: var(--due-soon);
  background: var(--due-soon-bg);
  border: 1px solid var(--due-soon-border);
  border-radius: var(--radius-pill);
  padding: 0 var(--space-1);
  pointer-events: none;
}

.schedule-page .block .unplace {
  position: absolute;
  top: 0;
  right: 0;
  width: 22px;
  height: 22px;
  line-height: 1;
  border: 0;
  border-radius: 0 var(--radius-sm) 0 var(--radius-sm);
  background: transparent;
  color: var(--text-subtle);
  cursor: pointer;
}

.schedule-page .block .unplace:hover {
  background: var(--overdue-bg);
  color: var(--overdue);
}

/* ---- The double-booking warning ----------------------------------------- */

/* The due-soon palette, not overdue. A double-booking is a decision to make, not a
   dog behind a fence that has stopped working — and tokens.css reserves the loudest
   colour for the latter. Same reasoning as the cancel warning in work.css. */
.schedule-page .confirm {
  background: var(--due-soon-bg);
  border: 1px solid var(--due-soon-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  display: grid;
  gap: var(--space-3);
}

.schedule-page .confirm .clash-list {
  margin: 0;
  padding-left: var(--space-5);
  display: grid;
  gap: var(--space-1);
}

.schedule-page .confirm .muted {
  color: var(--text-muted);
}

.schedule-page .confirm .note {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.schedule-page .confirm-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ---- One person's own day ------------------------------------------------ */

/* My day is the same grid with one column and no queue, so it needs almost nothing
   of its own (SC-9: a technician cannot see who else is working, and cannot see
   unassigned work at all). */
.schedule-page.my-day .board {
  grid-template-columns: minmax(0, 1fr);
}

.schedule-page.my-day .grid-head,
.schedule-page.my-day .grid {
  grid-template-columns: 56px minmax(0, 1fr);
}

/* ---- SC-17: creating work where it was clicked --------------------------- */

/* The slot is a drop target and now a click target too, so it says so on hover.
   Deliberately faint: this is a 48-cell grid and a strong hover on every cell
   makes the board flicker as the mouse crosses it. */
.schedule-page .slot.clickable {
  cursor: copy;
}

.schedule-page .slot.clickable:hover {
  background: var(--surface-sunken);
  box-shadow: inset 0 0 0 1px var(--primary);
}

/* The out-of-hours shade must survive the hover, or AC-10's one hint disappears
   exactly when somebody is about to book into it. */
.schedule-page .slot.out.clickable:hover {
  background: var(--surface-sunken);
}

/* AC-76. The keyboard equivalent, in the column head. Small, and never the only
   way in — the slot click is for the mouse. */
.schedule-page .col-add {
  margin-left: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  line-height: 1;
  padding: 0 var(--space-2);
  cursor: pointer;
}

.schedule-page .col-add:hover,
.schedule-page .col-add:focus-visible {
  color: var(--primary);
  border-color: var(--primary);
}

/* The create form reuses .confirm's box so it sits where the clash warning sits,
   but it is a form rather than a warning, so it drops the amber. */
.schedule-page .confirm.create {
  background: var(--surface);
  border-color: var(--border);
}

.schedule-page .confirm.create .field {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: calc(var(--space-1) * -1);
}

.schedule-page .confirm.create .input {
  width: 100%;
  max-width: 28rem;
}

.schedule-page .confirm.create .chosen {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0;
}

.schedule-page .confirm.create .match-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-1);
  max-width: 28rem;
}

/* A whole-row target. The office is picking a customer off a list at speed, and a
   hit area the width of the name is the kind of thing that gets clicked twice. */
.schedule-page .confirm.create .match {
  width: 100%;
  text-align: left;
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.schedule-page .confirm.create .match:hover,
.schedule-page .confirm.create .match:focus-visible {
  border-color: var(--primary);
}

/* ---- SC-19: day / week / month ------------------------------------------------------- */

/* AC-97: the team calendar spans the page, to the layout's own maximum. MyDay shares
   .schedule-page and keeps the 1100px cap — its single column would become a prairie. */
.work-page.schedule-page:not(.my-day) {
  max-width: none;
}

.view-switch {
  display: inline-flex;
  gap: 2px;
  border: 1px solid var(--border, #d5d2cb);
  border-radius: var(--radius);
  padding: 2px;
}

.view-switch .btn.current {
  background: var(--primary, #154b78);
  color: #fff;
}

/* The week: seven columns, each a DAY (AC-90). Cards stack in start order — this is an
   agenda per day, deliberately not an hour grid; the day view is the precision instrument. */
.week-board {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, minmax(130px, 1fr));
  gap: var(--space-2);
  align-items: start;
  overflow-x: auto;
}

.week-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 12rem;
  padding: var(--space-2);
  border: 1px solid var(--border, #e3e0d9);
  border-radius: var(--radius);
  background: var(--surface, #fff);
}

.week-col.today {
  border-color: var(--primary, #154b78);
  box-shadow: inset 0 3px 0 0 var(--primary, #154b78);
}

.week-day-head {
  display: flex;
  flex-direction: column;
  align-items: start;
  padding: var(--space-1);
  border: 0;
  border-radius: var(--radius);
  background: none;
  font: inherit;
  cursor: pointer;
  text-align: left;
}

.week-day-head:hover {
  background: var(--surface-2, #f3f1ec);
}

.week-day-head .dow {
  font-weight: var(--weight-semibold);
}

.week-day-head .dom {
  font-size: var(--text-sm);
  color: var(--text-muted, #5f676d);
}

.week-block {
  position: relative;
  border-left: 4px solid var(--who, #8a8f94);
  border-radius: var(--radius);
  background: var(--surface-2, #f7f6f1);
}

.week-block .block-open {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: var(--space-2);
  text-decoration: none;
  color: inherit;
}

.week-block .times {
  font-size: var(--text-xs, 0.8rem);
  color: var(--text-muted, #5f676d);
}

.week-block .who {
  font-weight: var(--weight-semibold);
}

.week-block .fitter {
  font-size: var(--text-xs, 0.8rem);
  color: var(--text-muted, #5f676d);
}

.week-block.lifting {
  opacity: 0.5;
}

/* The month: a reading view (AC-93). No drop targets on purpose. */
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  gap: var(--space-1);
  overflow-x: auto;
}

.month-dow {
  padding: var(--space-1);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-muted, #5f676d);
}

.month-cell {
  min-height: 7rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-1);
  border: 1px solid var(--border, #e3e0d9);
  border-radius: var(--radius);
  background: var(--surface, #fff);
}

.month-cell.outside {
  background: var(--surface-2, #f7f6f1);
  opacity: 0.7;
}

.month-cell.today {
  border-color: var(--primary, #154b78);
  box-shadow: inset 0 2px 0 0 var(--primary, #154b78);
}

.month-day {
  align-self: start;
  min-width: 1.8rem;
  padding: 2px 6px;
  border: 0;
  border-radius: 999px;
  background: none;
  font: inherit;
  font-weight: var(--weight-semibold);
  cursor: pointer;
}

.month-day:hover {
  background: var(--primary, #154b78);
  color: #fff;
}

.month-chip {
  display: flex;
  gap: 4px;
  align-items: baseline;
  padding: 1px 4px 1px 6px;
  border-left: 3px solid var(--who, #8a8f94);
  border-radius: 3px;
  background: var(--surface-2, #f7f6f1);
  font-size: var(--text-xs, 0.78rem);
  text-decoration: none;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.month-chip .times {
  color: var(--text-muted, #5f676d);
  flex: none;
}

.month-chip .who {
  overflow: hidden;
  text-overflow: ellipsis;
}

.month-more {
  align-self: start;
  padding: 1px 4px;
  border: 0;
  background: none;
  font-size: var(--text-xs, 0.78rem);
  color: var(--primary, #154b78);
  cursor: pointer;
}

@media (max-width: 900px) {
  .week-board,
  .month-grid {
    /* Gloved hands and bright sun: columns keep a readable minimum and the board scrolls
       sideways, instead of squeezing seven columns into a phone. */
    grid-auto-flow: unset;
  }
}
