/*
 * Estate Check-in screen: the module hero and tinted stats (shared rules live in today.css),
 * the check-in card and the visits list (the shared list card, with rows as `.job--visit`).
 *
 * Layout: two columns from 1000px up (check-in card | visits); one column below. Fits the
 * viewport from 1000px on landscape screens; between 900px and 999px it scrolls inside main.
 */

.checkin {
  display: flex;
  flex-direction: column;
}

.hero-pill--date {
  padding: 0 18px;
}

/* ---- Two columns ---------------------------------------------------------------------- */

.checkin-grid {
  display: grid;
  grid-template-columns: clamp(340px, 34vw, 440px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  margin-top: 16px;
}

.checkin-grid .jobs {
  margin-top: 0;
}

/* Someone who only looks at the visits has no check-in card: the list takes the whole width. */
.checkin-grid--list {
  grid-template-columns: minmax(0, 1fr);
}

/* ---- Check-in card -------------------------------------------------------------------- */

.checkin-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.checkin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.checkin-title {
  font-size: var(--fs-24);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.checkin-body {
  display: grid;
  gap: 16px;
  padding: 18px 22px;
}

.field {
  display: grid;
  gap: 8px;
}

.field-label {
  color: var(--ink-2);
  font-size: var(--fs-14);
  font-weight: 600;
}

/* The estate picker as a full-width select */
.checkin-card .estate-picker {
  display: block;
}

.select-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-16);
  font-weight: 600;
  text-align: left;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.select-btn .estate-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-btn .icon {
  width: 20px;
  height: 20px;
  color: var(--green);
}

.select-btn .chev {
  color: var(--ink-3);
}

.select-btn:hover,
.select-btn[aria-expanded="true"] {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

/* Weather: four toggle tiles */
.weather-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.weather-btn {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-height: 64px;
  padding: 10px 6px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: var(--fs-13);
  font-weight: 600;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.weather-btn .icon {
  width: 24px;
  height: 24px;
}

.weather-btn:hover {
  background: var(--surface-2);
}

.weather-btn[aria-pressed="true"] {
  background: var(--green-soft);
  border-color: #a9d6b5;
  color: var(--green-ink);
}

/* Location box: idle, locating, inside the boundary, outside it */
.loc-box {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.loc-box--inside {
  background: #edf9ea;
  border-color: #d3eccf;
}

.loc-box--outside {
  background: var(--amber-soft);
  border-color: #f3dfae;
}

.loc-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-2);
  box-shadow: 0 1px 2px rgba(23, 29, 38, 0.05);
}

.loc-icon .icon {
  width: 20px;
  height: 20px;
}

.loc-box--inside .loc-icon {
  color: var(--green-bright);
}

.loc-box--outside .loc-icon {
  color: var(--amber);
}

.loc-box--locating .loc-icon .icon {
  animation: spin 1.2s linear infinite;
}

.loc-text {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}

.loc-text strong {
  font-size: var(--fs-15);
}

.loc-text span {
  color: var(--ink-2);
  font-size: var(--fs-13);
}

.loc-box .link {
  flex: none;
  min-height: 32px;
}

/* Notes */
.text-input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--fs-16);
}

.text-input::placeholder {
  color: var(--ink-3);
}

.text-input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: var(--focus);
}

/* The check-out sheet: a few words about the visit before leaving. */
.text-area {
  width: 100%;
  min-height: 110px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--fs-16);
  line-height: 1.4;
  resize: vertical;
}

.text-area::placeholder {
  color: var(--ink-3);
}

.text-area:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: var(--focus);
}

.checkout-sheet .sheet-title {
  font-size: var(--fs-20);
}

.checkout-sheet .sheet-lead {
  color: var(--ink-2);
  font-size: var(--fs-15);
}

.sheet-hint {
  margin-top: -6px;
  color: var(--ink-3);
  font-size: var(--fs-13);
}

/* What was done on a visit, under the estate name in the list. */
.visit-summary {
  margin-top: 4px;
  color: var(--ink-2);
  font-size: var(--fs-14);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.checkin-foot {
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding: 0 22px 20px;
}

.btn--block {
  width: 100%;
  min-height: 52px;
  font-size: var(--fs-16);
}

/* On site */
.onsite {
  display: grid;
  gap: 6px;
  padding: 16px 18px;
  border-radius: var(--r-md);
  background: #edf9ea;
  border: 1px solid #d3eccf;
}

.onsite-estate {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--fs-20);
  font-weight: 700;
}

.onsite-estate .icon {
  width: 22px;
  height: 22px;
  color: var(--green-bright);
}

.onsite-since {
  color: var(--ink-2);
  font-size: var(--fs-14);
}

.onsite-timer {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 6px;
}

.onsite-timer strong {
  color: var(--green-deep);
  font-size: var(--fs-34);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.onsite-timer span {
  color: var(--ink-2);
  font-size: var(--fs-14);
}

.detail-list {
  display: grid;
  margin: 0;
}

.detail-list > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: var(--fs-15);
}

.detail-list > div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.detail-list dt {
  flex: none;
  color: var(--ink-2);
  font-weight: 500;
}

.detail-list dd {
  min-width: 0;
  margin: 0;
  text-align: right;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* A live dot inside a chip */
.chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* ---- Visit rows (the shared list card) ------------------------------------------------ */

.job--visit {
  grid-template-columns: auto minmax(0, 1.4fr) 192px minmax(120px, auto);
  grid-template-areas: "icon title meta status";
}

.job--visit[data-status="open"] .job-icon {
  background: var(--green-soft);
  color: var(--green-ink);
}

.job--visit[data-status="done"] .job-icon {
  background: #e2e7ed;
  color: #3a4b5b;
}

.job--visit .job-where {
  min-width: 0;
}

.visit-notes {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@container jobs (max-width: 900px) {
  .job--visit {
    grid-template-columns: auto minmax(0, 1fr) 168px minmax(100px, auto);
  }
}

@container jobs (max-width: 680px) {
  .job--visit {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "icon title status"
      "icon meta meta";
  }

  .job--visit .job-status {
    justify-self: end;
  }
}

/* ---- Responsive ----------------------------------------------------------------------- */

@media (max-width: 999.98px) {
  .checkin-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 899.98px) {
  .checkin-grid {
    gap: 12px;
    margin-top: 12px;
  }

  .checkin-head {
    padding: 14px 16px 12px;
  }

  .checkin-title {
    font-size: var(--fs-20);
  }

  .checkin-body {
    gap: 14px;
    padding: 14px 16px;
  }

  .checkin-foot {
    padding: 0 16px 16px;
  }
}

@media (max-width: 639.98px) {
  .loc-box .link {
    min-height: 40px;
  }
}

@media (max-width: 399.98px) {
  .weather-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .weather-btn {
    grid-template-columns: auto minmax(0, 1fr);
    justify-items: start;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 8px 12px;
  }
}

/* ---- One-screen fit --------------------------------------------------------------------
 * From 1000px wide on landscape screens the two columns share the height below the stats; the
 * check-in card and the visits list each scroll inside when they must.
 */
@media (min-width: 1000px) and (min-height: 560px) {
  .main.is-fit .checkin {
    flex: 1;
    min-height: 0;
  }

  .main.is-fit .checkin-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 .checkin-grid .jobs {
    margin-top: 0;
  }

  /* The card is as tall as its form, not as tall as the list; it scrolls inside only when the screen is short. */
  .main.is-fit .checkin-card {
    align-self: start;
    max-height: 100%;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .main.is-fit .checkin-head {
    padding: clamp(10px, 1.6vh, 18px) clamp(14px, 1.2vw, 22px) clamp(8px, 1.3vh, 14px);
  }

  .main.is-fit .checkin-title {
    font-size: clamp(1rem, 2.4vh, 1.5rem);
  }

  .main.is-fit .checkin-body {
    gap: clamp(8px, 1.4vh, 16px);
    padding: clamp(10px, 1.6vh, 18px) clamp(14px, 1.2vw, 22px);
  }

  .main.is-fit .field {
    gap: clamp(4px, 0.8vh, 8px);
  }

  .main.is-fit .field-label {
    font-size: clamp(0.75rem, 1.5vh, 0.875rem);
  }

  .main.is-fit .select-btn {
    min-height: clamp(36px, 5.4vh, 48px);
    font-size: clamp(0.8125rem, 1.8vh, 1rem);
  }

  .main.is-fit .weather-btn {
    gap: clamp(2px, 0.6vh, 6px);
    min-height: clamp(44px, 7.4vh, 64px);
    padding: clamp(6px, 1vh, 10px) 6px;
    font-size: clamp(0.6875rem, 1.4vh, 0.8125rem);
  }

  .main.is-fit .weather-btn .icon {
    width: clamp(18px, 2.8vh, 24px);
    height: clamp(18px, 2.8vh, 24px);
  }

  .main.is-fit .loc-box {
    min-height: clamp(44px, 6.8vh, 60px);
    padding: clamp(6px, 1vh, 10px) clamp(10px, 1vw, 14px);
  }

  .main.is-fit .loc-icon {
    width: clamp(28px, 4.2vh, 36px);
    height: clamp(28px, 4.2vh, 36px);
  }

  .main.is-fit .loc-text strong {
    font-size: clamp(0.8125rem, 1.7vh, 0.9375rem);
  }

  .main.is-fit .loc-text span {
    font-size: clamp(0.6875rem, 1.5vh, 0.8125rem);
  }

  .main.is-fit .text-input {
    min-height: clamp(36px, 5.4vh, 48px);
    font-size: clamp(0.8125rem, 1.8vh, 1rem);
  }

  .main.is-fit .checkin-foot {
    padding: 0 clamp(14px, 1.2vw, 22px) clamp(10px, 1.6vh, 20px);
  }

  .main.is-fit .btn--block {
    min-height: clamp(40px, 6vh, 52px);
    font-size: clamp(0.875rem, 1.8vh, 1rem);
  }

  .main.is-fit .onsite {
    padding: clamp(10px, 1.6vh, 16px) clamp(12px, 1.2vw, 18px);
  }

  .main.is-fit .onsite-timer strong {
    font-size: clamp(1.5rem, 4vh, 2.125rem);
  }

  .main.is-fit .detail-list > div {
    padding: clamp(6px, 1vh, 10px) 0;
    font-size: clamp(0.8125rem, 1.7vh, 0.9375rem);
  }
}

/* Between 900px and 999px the shell pins the frame to the viewport for fit screens, but the
 * check-in screen is one column there, so it scrolls inside the main area instead. */
@media (min-width: 900px) and (max-width: 999.98px) and (min-height: 560px) {
  .main.is-fit:has(.checkin) {
    display: block;
    overflow-y: auto;
  }
}
