/*
 * Labour and the Field Work Log: two screens of records written in the field. They share the
 * module hero, the tinted stats and the list card (today.css); this file holds what is theirs:
 * the layout, the line above each day, the row tints by approval state, the record sheet's
 * state tile, and the pieces of the two forms (chips, the line per worker, the photo tiles).
 *
 * Layout: Labour is two columns from 1000px up (records | by worker); the Work Log is one. Both
 * fit the viewport from 1000px on landscape screens; between 900px and 999px they scroll inside
 * main.
 */

.records {
  display: flex;
  flex-direction: column;
}

.records-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(260px, 22vw, 380px);
  gap: 20px;
  align-items: start;
  margin-top: 16px;
}

.records-grid--list {
  grid-template-columns: minmax(0, 1fr);
}

.records-grid .jobs {
  margin-top: 0;
}

/* ---- The list ------------------------------------------------------------------------- */

/* The line above each day's records */
.jobs-day {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 22px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--fs-13);
}

.jobs-day strong {
  color: var(--ink);
  font-size: var(--fs-14);
  font-weight: 800;
}

/* The icon says where a record stands: waiting, approved, sent back; grey for an absence. */
.job--record[data-status="pending"] .job-icon {
  background: var(--amber-soft);
  color: var(--amber-ink);
}

.job--record[data-status="approved"] .job-icon {
  background: var(--green-soft);
  color: var(--green-ink);
}

.job--record[data-status="returned"] .job-icon {
  background: var(--red-soft);
  color: var(--red-ink);
}

.job--record[data-status="absent"] .job-icon {
  background: var(--surface-2);
  color: var(--ink-3);
}

.job--record[data-status="absent"] .job-title h3 {
  color: var(--ink-2);
}

/* ---- By worker (the card beside the labour records) ------------------------------------ */

.by-worker .block-row {
  gap: 2px;
}

.by-worker .block-name {
  display: grid;
  gap: 1px;
}

.by-worker .block-pct {
  min-width: 0;
  white-space: nowrap;
}

.by-worker .block-delayed {
  white-space: nowrap;
}

.by-worker-output {
  color: var(--ink-2);
  font-size: var(--fs-13);
}

/* ---- The record sheet ------------------------------------------------------------------ */

.sheet-tile--pending {
  background: var(--amber-soft);
  color: var(--amber-ink);
}

.sheet-tile--approved {
  background: var(--green-soft);
  color: var(--green-ink);
}

.sheet-tile--returned {
  background: var(--red-soft);
  color: var(--red-ink);
}

.record-sheet .sheet-note {
  align-items: flex-start;
}

.record-sheet .sheet-note .icon {
  flex: none;
  margin-top: 1px;
}

.record-sheet .sheet-note span {
  font-weight: 500;
  overflow-wrap: anywhere;
}

.record-sheet .sheet-facts dd {
  max-width: 68%;
}

/* ---- Chips that switch on and off (workers, tools) -------------------------------------- */

.pick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pick-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-15);
  font-weight: 600;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.pick-chip:hover {
  background: var(--surface-2);
}

.pick-chip .icon {
  flex: none;
  width: 18px;
  height: 18px;
}

.pick-chip small {
  padding: 1px 7px;
  border-radius: var(--r-pill);
  background: var(--amber-soft);
  color: var(--amber-ink);
  font-size: var(--fs-12);
  font-weight: 700;
}

.pick-chip[aria-pressed="true"] {
  background: var(--green-soft);
  border-color: #a9d6b5;
  color: var(--green-ink);
}

.pick-chip--wide {
  justify-self: start;
  border-radius: var(--r-md);
}

/* ---- Record labour: who worked, and a line for each of them ------------------------------ */

.worker-pick {
  display: grid;
  gap: 10px;
}

.worker-add {
  justify-self: start;
}

.worker-new {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px dashed var(--line-strong);
  background: var(--surface-2);
}

.worker-new-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 8px;
}

.worker-new-actions {
  display: flex;
  gap: 8px;
}

.worker-lines {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}

.worker-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.worker-line:last-child {
  border-bottom: 0;
}

.worker-line.is-absent {
  background: var(--surface-2);
}

.worker-line.has-error {
  background: var(--red-soft);
}

.worker-line .field-error {
  grid-column: 1 / -1;
}

.worker-name {
  min-width: 0;
  font-size: var(--fs-15);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.worker-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.worker-inputs .input {
  width: 150px;
  min-height: 44px;
}

.worker-inputs .input.worker-people {
  width: 92px;
}

.worker-inputs .input-wrap .input {
  padding-right: 58px;
}

.worker-absent {
  flex: none;
  min-height: 44px;
}

.worker-absent[aria-pressed="true"] {
  background: var(--amber-soft);
  border-color: #f3dfae;
  color: var(--amber-ink);
}

/* ---- Log work: the before and after photos ----------------------------------------------- */

.photo-tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.photo-tile {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.photo-add {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 4px;
  min-height: 112px;
  padding: 12px;
  border-radius: var(--r-md);
  border: 1.5px dashed var(--line-strong);
  background: var(--surface-2);
  color: var(--ink-2);
  text-align: center;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.photo-add:hover {
  border-color: var(--green);
  background: var(--green-soft);
}

.photo-add .icon {
  width: 26px;
  height: 26px;
  color: var(--green);
}

.photo-add strong {
  color: var(--ink);
  font-size: var(--fs-15);
}

.photo-add span {
  font-size: var(--fs-13);
}

.photo-tile.has-error .photo-add {
  border-color: var(--red);
}

.photo-tile--set {
  grid-template-columns: 84px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 8px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
}

.photo-preview {
  width: 84px;
  height: 84px;
  border-radius: var(--r-sm);
  object-fit: cover;
  background: var(--surface-2);
}

.photo-info {
  display: grid;
  gap: 2px;
  min-width: 0;
  font-size: var(--fs-14);
}

.photo-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-2);
  font-size: var(--fs-13);
  font-weight: 600;
}

.photo-state .icon {
  width: 16px;
  height: 16px;
}

.photo-state--ok {
  color: var(--green-ink);
}

.photo-state--failed {
  color: var(--red-ink);
}

.photo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0 12px;
}

.photo-actions .link {
  min-height: 32px;
  font-size: var(--fs-14);
}

.link--danger {
  color: var(--red-ink);
}

/* The photos on an opened log */
.photo-shots {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.photo-shot {
  display: grid;
  gap: 6px;
  margin: 0;
}

.photo-shot figcaption {
  color: var(--ink-2);
  font-size: var(--fs-13);
  font-weight: 700;
  text-align: center;
}

.photo-frame {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-2);
  overflow: hidden;
}

.photo-frame a,
.photo-frame img {
  display: block;
  width: 100%;
  height: 100%;
}

.photo-frame img {
  object-fit: cover;
}

.photo-wait {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 8px;
  color: var(--ink-3);
  font-size: var(--fs-13);
  font-weight: 600;
  text-align: center;
}

.photo-wait .icon {
  width: 22px;
  height: 22px;
}

/* ---- Responsive ----------------------------------------------------------------------- */

@media (max-width: 999.98px) {
  .records-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 899.98px) {
  .records-grid {
    gap: 12px;
    margin-top: 12px;
  }

  .jobs-day {
    padding: 8px 16px;
  }
}

@media (max-width: 479.98px) {
  /* A phone: the output and the Absent button drop under the worker's name. */
  .worker-line {
    grid-template-columns: minmax(0, 1fr);
  }

  .worker-inputs .input-wrap,
  .worker-inputs > .input--select {
    flex: 1;
  }

  .worker-inputs .input {
    width: 100%;
  }

  .worker-inputs .input.worker-people {
    width: 88px;
  }

  .worker-new-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .photo-tile--set {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .photo-preview {
    width: 64px;
    height: 64px;
  }
}

/* ---- One-screen fit --------------------------------------------------------------------
 * From 1000px wide on landscape screens the list (and the by-worker card beside it) take the
 * height below the stats and scroll inside when they must.
 */
@media (min-width: 1000px) and (min-height: 560px) {
  .main.is-fit .records {
    flex: 1;
    min-height: 0;
  }

  .main.is-fit .records-grid {
    flex: 1;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
    gap: clamp(10px, 1.4vw, 20px);
    margin-top: clamp(6px, 1.1vh, 16px);
  }

  .main.is-fit .records-grid .jobs {
    margin-top: 0;
  }

  /* The list scrolls inside its card here, so the day stays in view above its records. */
  .main.is-fit .jobs-day {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: clamp(4px, 0.8vh, 8px) clamp(14px, 1.2vw, 22px);
  }
}

/* Between 900px and 999px the shell pins the frame to the viewport for fit screens, but these
 * screens are one column there, so they scroll inside the main area instead. */
@media (min-width: 900px) and (max-width: 999.98px) and (min-height: 560px) {
  .main.is-fit:has(.records) {
    display: block;
    overflow-y: auto;
  }
}
