/*
 * The sheet: one <dialog> on the top layer. On phones it slides up from the bottom with a drag
 * handle; from 900px it sits in the middle of the screen. The job sheet's own pieces follow:
 * head, state line, note, facts, and the big buttons.
 */

.sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0;
  width: 100%;
  max-width: none;
  max-height: min(92dvh, 100%);
  padding: 0;
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 -12px 40px -16px rgba(2, 20, 12, 0.45);
  overflow: hidden;
}

.sheet[open] {
  display: flex;
  flex-direction: column;
  animation: sheet-up var(--dur) var(--ease);
}

.sheet::backdrop {
  background: rgba(2, 24, 14, 0.52);
}

.sheet-handle {
  flex: none;
  width: 44px;
  height: 5px;
  margin: 10px auto 2px;
  border-radius: 3px;
  background: var(--line-strong);
}

.sheet-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  background: var(--surface-2);
  color: var(--ink-2);
}

.sheet-close .icon {
  width: 20px;
  height: 20px;
}

.sheet-body {
  flex: 1;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 16px;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  overscroll-behavior: contain;
}

@keyframes sheet-up {
  from {
    transform: translateY(28px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@keyframes sheet-in {
  from {
    transform: translateY(10px) scale(0.98);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@media (min-width: 900px) {
  .sheet {
    inset: 0;
    margin: auto;
    width: min(540px, calc(100% - 48px));
    max-height: min(88vh, 780px);
    border-radius: 20px;
    box-shadow: var(--shadow-float);
  }

  .sheet[open] {
    animation-name: sheet-in;
  }

  .sheet-handle {
    display: none;
  }

  .sheet-body {
    gap: 18px;
    padding: 24px 26px 26px;
  }
}

/* ---- Job sheet ------------------------------------------------------------------------ */

.sheet-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-right: 44px;
}

.sheet-tile {
  width: 54px;
  height: 54px;
  border-radius: 16px;
}

.sheet-tile .icon {
  width: 28px;
  height: 28px;
}

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

.sheet-tile--started {
  background: var(--sky-soft);
  color: var(--sky-ink);
}

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

.sheet-head-text {
  min-width: 0;
}

.sheet-title {
  font-size: var(--fs-20);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.sheet-where {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  color: var(--ink-2);
  font-size: var(--fs-15);
}

.sheet-where .sep {
  color: var(--ink-3);
}

.sheet-state {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.sheet-state .chip {
  min-height: 32px;
  padding: 0 14px;
  font-size: var(--fs-15);
  font-weight: 700;
}

.sheet-state .progress {
  flex: 1;
  width: auto;
  min-width: 120px;
  height: 8px;
  border-radius: 4px;
}

.sheet-pct {
  color: var(--ink-2);
  font-weight: 700;
}

.sheet-note {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--amber-soft);
  color: var(--amber-ink);
  font-size: var(--fs-15);
  font-weight: 600;
}

.sheet-note--late {
  background: var(--red-soft);
  color: var(--red-ink);
}

.sheet-note .icon {
  width: 20px;
  height: 20px;
}

.sheet-facts {
  display: grid;
  margin: 0;
  border-top: 1px solid var(--line-soft);
}

.sheet-facts > div {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: var(--fs-15);
}

.sheet-facts dt {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  color: var(--ink-2);
}

.sheet-facts dt .icon {
  width: 18px;
  height: 18px;
  color: var(--ink-3);
}

.sheet-facts dd {
  min-width: 0;
  margin: 0 0 0 auto;
  text-align: right;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.sheet-actions {
  display: grid;
  gap: 10px;
}

.sheet-actions .btn--block {
  min-height: 54px;
  border-radius: 14px;
  font-size: var(--fs-16);
  font-weight: 700;
}

.sheet-actions .btn .icon {
  width: 22px;
  height: 22px;
}

.btn--amber {
  background: var(--amber-soft);
  color: var(--amber-ink);
  border: 1px solid #f3dfae;
}

.btn--amber:hover {
  background: #fdebc4;
}

.sheet-question {
  font-size: var(--fs-18);
  font-weight: 700;
}

.sheet-choices {
  display: grid;
  gap: 8px;
}

.sheet-choice {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 0 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: var(--fs-16);
  font-weight: 600;
  text-align: left;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.sheet-choice:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
}

.sheet-choice .icon {
  width: 22px;
  height: 22px;
  color: var(--ink-2);
}

.sheet-back {
  justify-self: start;
}

.sheet-steps {
  display: grid;
  gap: 8px;
  padding-bottom: 4px;
}

.sheet-steps-label {
  color: var(--ink-2);
  font-size: var(--fs-14);
  font-weight: 600;
}

.sheet-steps-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.sheet-step {
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: var(--fs-16);
  font-weight: 700;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.sheet-step:hover {
  background: var(--surface-2);
}

.sheet-step[aria-pressed="true"] {
  background: var(--sky-soft);
  border-color: #bcd6f5;
  color: var(--sky-ink);
}

.sheet-done {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--green-ink);
  font-weight: 600;
}

.sheet-done .icon {
  width: 22px;
  height: 22px;
}

@media (min-width: 600px) {
  .sheet-choices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---- Planning: the form, the button on a list head, and whose job a row is --------------- */

.plan-btn {
  flex: none;
  white-space: nowrap;
}

.jobs-head--plan .jobs-title {
  margin-right: auto;
}

@media (min-width: 640px) {
  /* Wide enough for one line: title, tabs, then the button in the corner. */
  .jobs-head--plan .plan-btn {
    order: 3;
  }
}

.job-who {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  font-weight: 700;
}

.job-who .icon {
  width: 15px;
  height: 15px;
  color: var(--ink-3);
}

.plan-form {
  display: grid;
  gap: 14px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--fs-16);
  font-weight: 600;
}

.input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: var(--focus);
}

.input:disabled {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--ink-3);
  cursor: not-allowed;
}

.input--select {
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234f575f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  text-overflow: ellipsis;
  cursor: pointer;
}

.input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.input[type="number"]::-webkit-inner-spin-button,
.input[type="number"]::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}

.input-wrap {
  position: relative;
}

.input-wrap .input {
  padding-right: 84px;
}

.input-unit {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  font-size: var(--fs-14);
  font-weight: 600;
  pointer-events: none;
}

.text-area--short {
  min-height: 72px;
}

.field--error .input,
.field--error .text-area {
  border-color: var(--red);
}

.field-error,
.field-hint {
  font-size: var(--fs-13);
}

.field-error {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--red-ink);
  font-weight: 600;
}

.field-error .icon {
  flex: none;
  width: 15px;
  height: 15px;
}

.field-hint {
  color: var(--ink-3);
}

.form-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--red-soft);
  color: var(--red-ink);
  font-size: var(--fs-14);
  font-weight: 600;
}

.form-error .icon {
  flex: none;
  width: 18px;
  height: 18px;
}

.plan-save {
  min-height: 54px;
  margin-top: 2px;
  border-radius: 14px;
  font-size: var(--fs-16);
  font-weight: 700;
}

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

@media (min-width: 900px) and (min-height: 560px) {
  .main.is-fit .plan-btn {
    min-height: clamp(30px, 4.8vh, 40px);
    padding: 0 clamp(10px, 1vw, 16px);
    font-size: clamp(0.8125rem, 1.9vh, 0.9375rem);
  }
}

/* ---- The job sheet for each role: instructions, looking only, planner buttons, history ---- */

.sheet-instructions {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--surface-2);
}

.sheet-instructions strong {
  color: var(--ink-2);
  font-size: var(--fs-13);
  font-weight: 700;
}

.sheet-instructions p {
  font-size: var(--fs-15);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.sheet-view-only {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--fs-15);
  font-weight: 600;
}

.sheet-view-only .icon {
  flex: none;
  width: 20px;
  height: 20px;
  color: var(--ink-3);
}

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

.sheet-planner .btn {
  min-height: 48px;
}

.sheet-planner .btn:only-child {
  grid-column: 1 / -1;
}

.btn--danger {
  background: var(--red);
  color: #fff;
}

.btn--danger:hover {
  background: var(--red-ink);
}

.btn--danger-soft {
  background: var(--surface);
  color: var(--red-ink);
  border: 1px solid #f3c9c6;
}

.btn--danger-soft:hover {
  background: var(--red-soft);
}

.sheet-history-host:empty,
.sheet-history-host[hidden] {
  display: none;
}

.sheet-history {
  display: grid;
  gap: 12px;
}

.sheet-history-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  font-size: var(--fs-14);
  font-weight: 700;
}

.sheet-history-title .icon {
  width: 17px;
  height: 17px;
  color: var(--ink-3);
}

.sheet-history-list {
  display: grid;
  gap: 12px;
  margin: 0 0 0 5px;
  padding: 0 0 0 16px;
  border-left: 2px solid var(--line);
  list-style: none;
}

.sheet-history-list li {
  position: relative;
}

.sheet-history-list li::before {
  content: "";
  position: absolute;
  left: -23px;
  top: 5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--green);
  background: var(--surface);
}

.sheet-history-list li:last-child::before {
  border-color: var(--line-strong);
}

.sheet-history-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 12px;
  font-size: var(--fs-14);
}

.sheet-history-line strong {
  font-weight: 700;
}

.sheet-history-line span {
  color: var(--ink-3);
}

.sheet-history-note {
  margin-top: 2px;
  color: var(--ink-2);
  font-size: var(--fs-14);
  overflow-wrap: anywhere;
}
