/*
 * Daily check-up component.
 *
 * Kept separate from app.css because the card, bottom sheet and five tap scales form one bounded
 * component. No animation library is needed: transform, opacity and colour transitions are enough
 * for immediate feedback and keep the interaction light on mobile GPUs.
 */

.daily-checkin-card {
  overflow: visible;
  scroll-margin-top: calc(var(--bar-h) + 16px);
}

.checkin-disclosure { margin: 0; }

.checkin-card-toggle {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  list-style: none;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.checkin-card-toggle::-webkit-details-marker { display: none; }

.checkin-card-heading {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.checkin-card-heading .eyebrow { margin: 0; }

.checkin-card-heading .card-h {
  display: block;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -.2px;
}

.checkin-card-toggle .checkin-state {
  align-self: start;
  justify-self: end;
}

.checkin-disclosure-mark {
  width: 7px;
  height: 7px;
  margin: -3px 1px 0 3px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 140ms ease;
}

.checkin-disclosure[open] .checkin-disclosure-mark { transform: rotate(225deg); }

.checkin-card-body { padding-top: 2px; }

/* On Home this sits inside the readiness block, so it is deliberately a little denser than the
   standalone editor card without shrinking touch targets or the bottom sheet. */
.daily-checkin-card--home {
  width: 100%;
  align-self: stretch;
  margin-top: 10px;
  padding: 17px 16px;
  border-radius: calc(var(--r) - 4px);
  text-align: left;
}

.daily-checkin-card--home .card-h { font-size: 21px; }
.daily-checkin-card--home .checkin-state {
  min-height: 29px;
  padding: 4px 8px;
  font-size: 11px;
}
.daily-checkin-card--home .checkin-intro {
  margin: 6px 0 12px;
  font-size: 13px;
  line-height: 1.45;
}
.daily-checkin-card--home .checkin-snapshot { margin-bottom: 10px; }
.daily-checkin-card--home .checkin-snapshot-item { padding: 7px 3px 6px; }

.checkin-card-head {
  align-items: flex-start;
  gap: 14px;
}

.checkin-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--cond);
  font-size: 12px;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: var(--mut);
  white-space: nowrap;
}

.checkin-state-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mut2);
}

.checkin-state.is-done {
  border-color: color-mix(in srgb, var(--ok) 38%, transparent);
  color: var(--ok);
}

.checkin-state.is-done .checkin-state-dot {
  background: var(--ok);
  box-shadow: 0 0 10px color-mix(in srgb, var(--ok) 60%, transparent);
}

.checkin-intro {
  max-width: 58ch;
  margin: 8px 0 16px;
  color: var(--mut);
  font-size: 14px;
  line-height: 1.55;
}

.checkin-snapshot {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 2px 0 14px;
}

.checkin-snapshot-item {
  min-width: 0;
  padding: 9px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  background: color-mix(in srgb, var(--surface-2) 82%, transparent);
}

.checkin-snapshot-item span {
  display: block;
  overflow: hidden;
  font-family: var(--cond);
  font-size: 12px;
  letter-spacing: .7px;
  text-overflow: ellipsis;
  text-transform: uppercase;
  color: var(--mut2);
}

.checkin-snapshot-item strong {
  display: block;
  margin-top: 3px;
  font-size: 16px;
  color: var(--ink);
}

.checkin-area-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 9px;
  margin: -2px 0 12px;
  font-size: 12px;
}

.checkin-area-summary-label {
  font-family: var(--cond);
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--mut2);
}

.checkin-area-summary-values { color: var(--ink); }

.checkin-caution {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-left: 2px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 9%, transparent);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.checkin-open {
  width: 100%;
  min-height: 48px;
  margin-top: 0;
}

/* Native dialog supplies focus trapping and Escape handling. Visually it behaves like a mobile
   bottom sheet, keeping the repeated controls close to the thumb. */
.checkin-dialog {
  width: min(100%, 720px);
  max-width: none;
  max-height: min(92dvh, 860px);
  margin: auto auto 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px 24px 0 0;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 -24px 64px rgba(0, 0, 0, .42);
}

.checkin-dialog[open] {
  animation: checkin-sheet-in 180ms cubic-bezier(.2, .8, .2, 1);
}

.checkin-dialog::backdrop {
  background: rgba(0, 0, 0, .72);
  backdrop-filter: blur(3px);
}

.checkin-form {
  display: flex;
  flex-direction: column;
  max-height: min(92dvh, 860px);
}

.checkin-dialog-head {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 11px;
  border-bottom: 1px solid var(--line);
}

.checkin-dialog-head h2 {
  margin: 3px 0 0;
  font-size: clamp(23px, 6vw, 30px);
  line-height: 1.08;
}

.checkin-close {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -4px -4px 0 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--mut);
  background: transparent;
  font-size: 25px;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.checkin-close:active { transform: scale(.92); }
.checkin-close:hover { color: var(--ink); border-color: var(--accent-line); }
.checkin-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.checkin-progress {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  border-bottom: 1px solid var(--line);
}

.checkin-progress-bars {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.checkin-progress-bars span {
  height: 3px;
  border-radius: 4px;
  background: var(--line);
  transition: background-color 140ms ease, box-shadow 140ms ease;
}

.checkin-progress-bars span.is-complete {
  background: var(--accent);
  box-shadow: 0 0 9px var(--accent-soft);
}

.checkin-progress-count {
  min-width: 30px;
  font-family: var(--cond);
  font-size: 12px;
  letter-spacing: 1px;
  text-align: right;
  color: var(--mut);
}

.checkin-error { margin: 12px 20px 0; }

.checkin-metrics {
  min-height: 0;
  padding: 4px 20px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.checkin-metric {
  min-width: 0;
  margin: 0;
  padding: 16px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
}

.checkin-metric:last-child { border-bottom: 0; }

.checkin-metric legend {
  display: flex;
  width: 100%;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding: 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}

.checkin-metric legend small {
  color: var(--mut2);
  font-size: 12px;
  font-weight: 400;
  text-align: right;
}

.checkin-scale {
  display: grid;
  grid-template-columns: repeat(5, minmax(44px, 1fr));
  gap: 7px;
}

.checkin-choice {
  position: relative;
  min-width: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.checkin-choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.checkin-choice-face {
  display: grid;
  place-items: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--mut);
  font-family: var(--cond);
  font-size: 16px;
  font-weight: 600;
  transition: transform 120ms ease, color 140ms ease, border-color 140ms ease,
              background-color 140ms ease, box-shadow 140ms ease;
}

.checkin-choice:active .checkin-choice-face { transform: scale(.92); }
.checkin-choice input:focus-visible + .checkin-choice-face {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Low→high colours follow meaning, not the number: sleep/motivation improve to the right;
   fatigue/DOMS/stress become more adverse. */
.checkin-scale[data-direction="positive"] .checkin-choice:nth-child(1) { --checkin-level: var(--danger); }
.checkin-scale[data-direction="positive"] .checkin-choice:nth-child(2) { --checkin-level: var(--warn); }
.checkin-scale[data-direction="positive"] .checkin-choice:nth-child(3) { --checkin-level: var(--accent); }
.checkin-scale[data-direction="positive"] .checkin-choice:nth-child(4) { --checkin-level: var(--ok); }
.checkin-scale[data-direction="positive"] .checkin-choice:nth-child(5) { --checkin-level: var(--ok); }
.checkin-scale[data-direction="negative"] .checkin-choice:nth-child(1) { --checkin-level: var(--ok); }
.checkin-scale[data-direction="negative"] .checkin-choice:nth-child(2) { --checkin-level: var(--ok); }
.checkin-scale[data-direction="negative"] .checkin-choice:nth-child(3) { --checkin-level: var(--accent); }
.checkin-scale[data-direction="negative"] .checkin-choice:nth-child(4) { --checkin-level: var(--warn); }
.checkin-scale[data-direction="negative"] .checkin-choice:nth-child(5) { --checkin-level: var(--danger); }

.checkin-choice input:checked + .checkin-choice-face {
  border-color: var(--checkin-level);
  color: var(--checkin-level);
  background: color-mix(in srgb, var(--checkin-level) 14%, var(--surface-2));
  box-shadow: 0 0 16px color-mix(in srgb, var(--checkin-level) 18%, transparent);
  animation: checkin-choice-pop 150ms ease-out;
}

.checkin-scale-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: 12px;
  color: var(--mut2);
}

.checkin-doms-areas {
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.checkin-doms-areas[hidden] { display: none; }

.checkin-doms-areas p {
  margin: 0 0 9px;
  color: var(--mut);
  font-size: 12px;
}

.checkin-area-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.checkin-area-chip { position: relative; cursor: pointer; }
.checkin-area-chip input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.checkin-area-chip span {
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--mut);
  font-size: 12px;
  transition: transform 120ms ease, color 140ms ease, border-color 140ms ease,
              background-color 140ms ease;
}

.checkin-area-chip:active span { transform: scale(.94); }
.checkin-area-chip input:checked + span {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--accent-soft);
}
.checkin-area-chip input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.checkin-feedback {
  display: grid;
  gap: 7px;
  padding: 16px 0 4px;
}

.checkin-feedback label {
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}

.checkin-feedback textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  line-height: 1.45;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.checkin-feedback textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.checkin-feedback small {
  color: var(--mut2);
  font-size: 12px;
  line-height: 1.4;
}

.checkin-boundary {
  flex: 0 0 auto;
  margin: 0;
  padding: 10px 20px 0;
  border-top: 1px solid var(--line);
  color: var(--mut2);
  font-size: 12px;
  line-height: 1.4;
}

.checkin-save-row {
  flex: 0 0 auto;
  padding: 11px 20px calc(14px + env(safe-area-inset-bottom));
  background: var(--panel);
}

.checkin-submit {
  position: relative;
  width: 100%;
  min-height: 52px;
  margin: 0;
  overflow: hidden;
}

.checkin-submit:disabled {
  border-color: var(--line);
  background: var(--surface-2);
  box-shadow: none;
  color: var(--mut2);
  cursor: not-allowed;
  opacity: .72;
}

.checkin-save-mark {
  display: inline-grid;
  place-items: center;
  width: 0;
  opacity: 0;
  transform: scale(.4);
  transition: width 120ms ease, opacity 120ms ease, transform 120ms ease;
}

.checkin-submit.is-saving .checkin-save-mark {
  width: 18px;
  margin-left: 7px;
  opacity: 1;
  transform: scale(1);
}

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

@keyframes checkin-choice-pop {
  0% { transform: scale(.9); }
  70% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

@media (max-width: 520px) {
  .checkin-dialog { width: 100%; }
  .checkin-dialog-head, .checkin-progress { padding-left: 16px; padding-right: 16px; }
  .checkin-metrics { padding-left: 16px; padding-right: 16px; }
  .checkin-boundary, .checkin-save-row { padding-left: 16px; padding-right: 16px; }
  .checkin-metric legend { display: block; }
  .checkin-metric legend small { display: block; margin-top: 3px; text-align: left; }
  .checkin-scale { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .checkin-dialog[open],
  .checkin-choice input:checked + .checkin-choice-face {
    animation: none;
  }
  .checkin-close,
  .checkin-progress-bars span,
  .checkin-choice-face,
  .checkin-area-chip span,
  .checkin-save-mark {
    transition: none;
  }
}

/* Read-only Check-up history. Five small multiples keep opposite metric directions honest. */
.checkin-history {
  margin-top: 18px;
  overflow: hidden;
}

.checkin-history-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.checkin-history-head .eyebrow { margin: 0 0 4px; }
.checkin-history-head .card-h { margin: 0; }

.checkin-range {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
}

.checkin-range a {
  display: grid;
  place-items: center;
  min-height: 38px;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--mut);
  font-family: var(--cond);
  font-size: 11px;
  letter-spacing: .8px;
  text-decoration: none;
  text-transform: uppercase;
  white-space: nowrap;
  transition: color 140ms ease, border-color 140ms ease,
              background-color 140ms ease, box-shadow 140ms ease;
}

.checkin-range a:hover { color: var(--ink); }

.checkin-range a.is-active {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--accent-soft);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 24%, transparent);
}

.checkin-range a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.checkin-history-intro {
  max-width: 68ch;
  margin: 12px 0 4px;
  color: var(--mut);
  font-size: 13px;
  line-height: 1.5;
}

.checkin-history-empty {
  margin-top: 18px;
  padding: 22px 18px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  text-align: center;
  color: var(--mut);
  background: color-mix(in srgb, var(--surface-2) 72%, transparent);
}

.checkin-history-empty p { margin: 0; }

.checkin-trend-list {
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.checkin-trend {
  --trend-color: var(--accent);
  padding: 19px 0 17px;
  border-bottom: 1px solid var(--line);
}

.checkin-trend--sleep,
.checkin-trend--motivation { --trend-color: var(--ok); }

.checkin-trend--fatigue,
.checkin-trend--stress { --trend-color: var(--warn); }

.checkin-trend--soreness { --trend-color: var(--danger); }

.checkin-trend-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 8px;
}

.checkin-trend-head h3 {
  margin: 0;
  color: var(--ink);
  font-size: 17px;
}

.checkin-trend-head span {
  color: var(--mut2);
  font-size: 11px;
  text-align: right;
}

.checkin-chart-wrap { min-width: 0; }

.checkin-chart {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 5;
  overflow: visible;
}

.checkin-chart-grid {
  stroke: var(--line);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  vector-effect: non-scaling-stroke;
}

.checkin-chart-axis {
  fill: var(--mut2);
  font-family: var(--cond);
  font-size: 9px;
}

.checkin-chart-line {
  fill: none;
  stroke: var(--trend-color);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 4px color-mix(in srgb, var(--trend-color) 48%, transparent));
  vector-effect: non-scaling-stroke;
}

.checkin-chart-point {
  color: var(--trend-color);
  cursor: pointer;
  outline: none;
}

.checkin-chart-point-hit {
  fill: transparent;
  pointer-events: all;
}

.checkin-chart-point-core {
  fill: var(--panel);
  stroke: currentColor;
  stroke-width: 2;
  transition: r 120ms ease, fill 120ms ease, stroke-width 120ms ease;
  vector-effect: non-scaling-stroke;
}

.checkin-chart-point:hover .checkin-chart-point-core,
.checkin-chart-point:focus .checkin-chart-point-core,
.checkin-chart-point.is-selected .checkin-chart-point-core {
  r: 4.5px;
  fill: currentColor;
  stroke: var(--ink);
  stroke-width: 1.5;
}

.checkin-trend-dates {
  display: flex;
  justify-content: space-between;
  margin: -2px 1px 0 20px;
  color: var(--mut2);
  font-family: var(--cond);
  font-size: 10px;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.checkin-trend-tooltip {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 5px 8px;
  width: fit-content;
  max-width: 100%;
  margin: 10px 0 0 auto;
  padding: 7px 10px;
  border: 1px solid color-mix(in srgb, var(--trend-color) 44%, var(--line));
  border-radius: 9px;
  color: var(--mut);
  background: color-mix(in srgb, var(--surface-2) 92%, transparent);
  font-size: 12px;
}

.checkin-trend-tooltip strong { color: var(--trend-color); }

.checkin-trend-tooltip [data-checkin-trend-output-detail] {
  flex-basis: 100%;
  color: var(--ink);
}

.checkin-history-footnote {
  margin: 15px 0 0;
  color: var(--mut2);
  font-size: 11px;
  line-height: 1.45;
  text-align: center;
}

@media (max-width: 620px) {
  .checkin-history-head {
    display: grid;
    gap: 13px;
  }

  .checkin-range {
    width: 100%;
    grid-template-columns: repeat(3, 1fr);
  }

  .checkin-range a {
    min-width: 0;
    padding-inline: 7px;
  }

  .checkin-trend-head {
    display: grid;
    gap: 3px;
  }

  .checkin-trend-head span { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  .checkin-range a,
  .checkin-chart-point-core {
    transition: none;
  }
}
