/* ============================================================
   Body Signals - components
   One block per component. Nothing here reaches outside itself:
   no descendant selectors onto other components, no bare element
   selectors. That's what keeps specificity from collapsing later.
   ============================================================ */

/* ---- card -------------------------------------------------- */
.card {
  background: var(--c-paper);
  border: 1px solid var(--c-line);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  box-shadow: var(--e-card);
}
.card + .card { margin-top: var(--s-3); }
.card--flat   { background: transparent; border-style: dashed; box-shadow: none; }
.card--good   { background: var(--c-sage-tint);  border-color: #D8E0D2; }
.card--note   { background: var(--c-terra-tint); border-color: var(--c-terra-soft); }
.card--alert  { background: var(--c-danger-tint); border-color: #E8C9C6; }

/* ---- button ------------------------------------------------ */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  width: 100%;
  min-height: var(--tap);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  background: var(--c-sage-deep);
  color: var(--c-cream);
  font-size: var(--t-md);
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: transform var(--m-fast) var(--m-ease),
              opacity var(--m-fast) var(--m-ease);
}
.btn + .btn { margin-top: var(--s-2); }
.btn:active { transform: scale(0.985); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

.btn--ghost {
  background: transparent;
  color: var(--c-ink-soft);
  border: 1.5px solid var(--c-line);
  font-weight: 500;
}
.btn--terra { background: var(--c-terra); color: #fff; }
.btn--quiet { min-height: var(--tap-min); font-size: var(--t-sm); }

/* The urge button. Deliberately the largest thing on the home screen. */
.btn--urge {
  min-height: 76px;
  font-family: var(--f-display);
  font-size: 1.1875rem;
  font-weight: 600;
  background: var(--c-terra);
  color: #fff;
}

.btn__spinner {
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn__spinner { animation-duration: 2s; } }

/* ---- option list (single choice) ---------------------------- */
.opt {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: var(--tap-lg);
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-2);
  border: 1.5px solid var(--c-line);
  border-radius: var(--r-md);
  background: var(--c-paper);
  color: var(--c-ink);
  font-size: var(--t-md);
  font-weight: 600;
  text-align: left;
  transition: border-color var(--m-fast) var(--m-ease),
              background var(--m-fast) var(--m-ease);
}
.opt__dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--c-line);
  flex: 0 0 auto;
  transition: background var(--m-fast) var(--m-ease);
}
.opt__body { flex: 1 1 auto; }
.opt__hint {
  display: block;
  font-size: var(--t-xs);
  font-weight: 500;
  color: var(--c-ink-soft);
  margin-top: 2px;
}
.opt[aria-checked="true"] {
  border-color: var(--c-sage);
  background: var(--c-sage-tint);
  box-shadow: var(--e-sel);
}
.opt[aria-checked="true"] .opt__dot { background: var(--c-sage); }

/* ---- five-point tap scale ----------------------------------
   NOT a slider. Five discrete targets, 62px tall so the vertical
   dimension carries the target area when width is constrained. */
.scale { margin-bottom: var(--s-4); }
.scale__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-2);
  margin-bottom: var(--s-2);
}
.scale__name  { font-size: var(--t-base); font-weight: 600; }
.scale__value { font-size: var(--t-xs); color: var(--c-ink-soft); font-weight: 500; }
.scale__track { display: flex; gap: 5px; }
.scale__step {
  flex: 1 1 0;
  height: 62px;
  min-width: 0;
  border: 1.5px solid var(--c-line);
  border-radius: 13px;
  background: var(--c-paper);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--m-fast) var(--m-ease),
              background var(--m-fast) var(--m-ease);
}
.scale__bar {
  display: block;
  width: 16px;
  border-radius: var(--r-pill);
  background: var(--c-line-strong);
  transition: background var(--m-fast) var(--m-ease);
}
.scale__step[aria-checked="true"] {
  border-color: var(--c-sage);
  background: var(--c-sage-tint);
  box-shadow: var(--e-sel);
}
.scale__step[aria-checked="true"] .scale__bar { background: var(--c-sage); }
.scale__ends {
  display: flex;
  justify-content: space-between;
  margin-top: var(--s-1);
  font-size: 0.625rem;
  color: var(--c-ink-soft);
  font-weight: 500;
}

/* ---- accuracy trail (signature element) ---------------------
   One bar per day. Sage = read their body correctly.
   Terracotta-soft = missed. This is the thing that fills up. */
.trail {
  display: flex;
  gap: 5px;
  align-items: flex-end;
  height: 46px;
  margin: var(--s-2) 0 var(--s-1);
}
.trail__bar {
  flex: 1 1 0;
  min-width: 0;
  border-radius: 3px;
  background: var(--c-line);
  transition: height var(--m-base) var(--m-ease);
}
.trail__bar--hit  { background: var(--c-sage); }
.trail__bar--miss { background: var(--c-terra-soft); }
.trail__bar--todo { background: var(--c-line); opacity: 0.35; }

/* ---- progress arc ------------------------------------------ */
.arc { display: flex; gap: 4px; margin: var(--s-2) 0 2px; }
.arc__seg { height: 5px; flex: 1 1 0; border-radius: var(--r-pill); background: var(--c-line); }
.arc__seg--done { background: var(--c-sage); }
.arc__seg--now  { background: var(--c-terra); }

/* ---- pill -------------------------------------------------- */
.pill {
  display: inline-block;
  font-size: 0.59375rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: var(--r-pill);
  background: var(--c-terra-soft);
  color: #8A4E33;
}
.pill--good { background: #DFE7DA; color: #3F5B3C; }
.pill--warn { background: #F0DAD8; color: #8A3B36; }

/* ---- key/value rows ---------------------------------------- */
.kv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  font-size: var(--t-sm);
  padding: var(--s-2) 0;
  border-bottom: 1px solid var(--c-line);
}
.kv:last-child { border-bottom: 0; }
.kv__value { font-weight: 600; }

/* ---- tab bar ----------------------------------------------- */
.tabs {
  position: fixed;
  inset: auto 0 0 0;
  z-index: var(--z-sheet);
  display: flex;
  max-width: var(--w-max);
  margin-inline: auto;
  background: var(--c-paper);
  border-top: 1px solid var(--c-line);
  padding-bottom: var(--safe-b);
}
.tabs__item {
  flex: 1 1 0;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.625rem;
  letter-spacing: 0.04em;
  font-weight: 500;
  color: var(--c-ink-soft);
}
.tabs__icon { font-size: 1rem; line-height: 1; }
.tabs__item[aria-current="page"] { color: var(--c-sage-deep); font-weight: 700; }

/* ---- toast ------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + var(--safe-b));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  max-width: calc(var(--w-max) - 2 * var(--pad-x));
  width: calc(100vw - 2 * var(--pad-x));
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  background: var(--c-forest);
  color: var(--c-on-dark);
  font-size: var(--t-sm);
  box-shadow: 0 8px 24px rgba(47, 62, 54, 0.28);
  animation: toast-in var(--m-base) var(--m-ease);
}
.toast__action {
  margin-left: auto;
  font-weight: 700;
  color: var(--c-terra-soft);
  text-decoration: underline;
  padding: var(--s-2);
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---- offline banner ----------------------------------------
   Reassuring, not alarming. Nothing is lost - it's queued. */
.offline {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  margin-bottom: var(--s-3);
  border-radius: var(--r-sm);
  background: var(--c-cream-2);
  color: var(--c-ink-soft);
  font-size: var(--t-xs);
  font-weight: 500;
}
.offline__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--c-terra); flex: 0 0 auto;
}

/* ---- skeleton (loading) ------------------------------------- */
.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--c-cream-2) 25%, #F5F1E8 50%, var(--c-cream-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background: var(--c-cream-2); }
}

/* ---- error state -------------------------------------------
   Errors say what happened and what to do. They do not apologise. */
.errorbox {
  padding: var(--s-4);
  border-radius: var(--r-md);
  border: 1px solid #E8C9C6;
  background: var(--c-danger-tint);
  color: var(--c-danger);
  font-size: var(--t-sm);
  line-height: var(--lh-body);
}
.errorbox__title { font-weight: 700; margin: 0 0 var(--s-1); }

/* ============================================================
   Urge flow
   ============================================================ */

/* ---- picker tiles ---- */
.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}
.tile {
  min-height: 84px;
  padding: var(--s-3);
  border: 1.5px solid var(--c-line);
  border-radius: 16px;
  background: var(--c-paper);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: var(--s-1);
  font-size: var(--t-base);
  font-weight: 600;
  line-height: 1.3;
  color: var(--c-ink);
  text-align: left;
  transition: border-color var(--m-fast) var(--m-ease), background var(--m-fast) var(--m-ease);
}
.tile:active { border-color: var(--c-terra); background: var(--c-terra-tint); }
.tile em {
  font-style: normal;
  font-size: 0.625rem;
  font-weight: 500;
  color: var(--c-ink-soft);
  letter-spacing: 0.02em;
}
.tile--wide {
  grid-column: 1 / -1;
  min-height: var(--tap-lg);
  flex-direction: row;
  align-items: center;
  justify-content: center;
  border-style: dashed;
  color: var(--c-ink-soft);
  font-weight: 500;
}

/* ---- search sheet ---- */
.sheet__backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(47, 62, 54, 0.32);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in var(--m-base) var(--m-ease);
}
@keyframes fade-in { from { opacity: 0; } }
.sheet {
  width: 100%;
  max-width: var(--w-max);
  height: 88dvh;
  background: var(--c-paper);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--e-sheet);
  padding: var(--s-2) var(--pad-x) calc(var(--s-4) + var(--safe-b));
  display: flex;
  flex-direction: column;
  animation: sheet-up var(--m-base) var(--m-ease);
}
@keyframes sheet-up { from { transform: translateY(16px); } }
@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet__backdrop { animation: none; }
}
.sheet__grab {
  width: 42px; height: 4px;
  border-radius: var(--r-pill);
  background: var(--c-line);
  margin: 0 auto var(--s-3);
}
.sheet__search {
  min-height: 50px;
  border: 1.5px solid var(--c-line);
  border-radius: 14px;
  padding: 0 var(--s-4);
  background: var(--c-cream);
  color: var(--c-ink);
  margin-bottom: var(--s-3);
  width: 100%;
}
.sheet__list { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet__group {
  font-size: var(--t-label);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--c-terra);
  font-weight: 700;
  margin: var(--s-4) 0 var(--s-2);
  padding-bottom: var(--s-1);
  border-bottom: 1px solid var(--c-line);
}
.sheet__group:first-child { margin-top: 0; }
.sheet__item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: var(--tap);
  border-bottom: 1px solid #F1ECE2;
  font-size: var(--t-base);
  font-weight: 500;
  color: var(--c-ink);
  text-align: left;
}

/* ---- chips ---- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-bottom: var(--s-4);
}
.chip {
  min-height: var(--tap-min);
  padding: var(--s-2) var(--s-4);
  border: 1.5px solid var(--c-line);
  border-radius: var(--r-pill);
  background: var(--c-paper);
  color: var(--c-ink);
  font-size: var(--t-sm);
  font-weight: 500;
  transition: background var(--m-fast) var(--m-ease), border-color var(--m-fast) var(--m-ease);
}
.chip[aria-checked="true"] {
  background: var(--c-sage-deep);
  border-color: var(--c-sage-deep);
  color: var(--c-cream);
  font-weight: 600;
}

/* ---- the pause ----
   Dark, quiet, one thing on screen. The ring breathes at roughly six
   per minute so the interrupt and a real regulation skill are the same
   sixty seconds. */
.pause {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: var(--c-forest);
  color: var(--c-on-dark);
  padding: var(--s-6) var(--pad-x) calc(var(--s-6) + var(--safe-b));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-4);
  overflow-y: auto;
}
.pause__line {
  font-family: var(--f-display);
  font-size: 1.4375rem;
  line-height: 1.3;
  text-align: center;
  margin: 0;
  max-width: 22rem;
  text-wrap: balance;
}
.ring {
  width: 168px; height: 168px;
  border-radius: 50%;
  border: 2px solid rgba(200, 190, 170, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex: 0 0 auto;
}
.ring::after {
  content: '';
  position: absolute;
  inset: 16px;
  border-radius: 50%;
  border: 2px solid var(--c-sage);
  animation: breathe 10s ease-in-out infinite;   /* ~6 breaths/min */
}
@keyframes breathe {
  0%, 100% { transform: scale(0.72); opacity: 0.55; }
  40%      { transform: scale(1);    opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .ring::after { animation: none; transform: scale(0.88); }
}
.ring__count {
  font-family: var(--f-display);
  font-size: 2.75rem;
  position: relative;
  z-index: 2;
  font-variant-numeric: tabular-nums;
}
.pause__hint {
  font-size: var(--t-sm);
  line-height: 1.7;
  text-align: center;
  color: var(--c-on-dark-soft);
  margin: 0;
  max-width: 24rem;
}
.pause__swap {
  background: #3A4A40;
  border-color: #4A5A4F;
  color: var(--c-on-dark);
  width: 100%;
  max-width: 24rem;
}
.pause__swap .label { color: var(--c-terra-soft); }
.pause__skip {
  color: var(--c-on-dark-soft);
  border-color: #48513F;
  max-width: 24rem;
}

/* ============================================================
   Habit rows - "No" must look exactly like "Yes"
   ============================================================ */

.habit-row {
  background: var(--c-paper);
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  padding: var(--s-3);
  margin-bottom: var(--s-3);
}
.habit-row__name {
  display: block;
  font-size: var(--t-base);
  font-weight: 500;
  line-height: 1.35;
  margin-bottom: var(--s-3);
}
.habit-row__answers { display: flex; gap: var(--s-2); }
.answer {
  flex: 1 1 0;
  min-height: 52px;
  border: 1.5px solid var(--c-line);
  border-radius: 12px;
  background: var(--c-cream);
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--c-ink);
  transition: background var(--m-fast) var(--m-ease), border-color var(--m-fast) var(--m-ease);
}
/* Selected state is IDENTICAL for yes, some and no. No red, no green.
   The moment one answer looks worse than another, people stop giving
   the true one - and the streak counts honesty, not success. */
.answer[aria-checked="true"] {
  background: var(--c-sage-tint);
  border-color: var(--c-sage);
  color: var(--c-sage-deep);
  box-shadow: var(--e-sel);
}

/* ============================================================
   Coach
   ============================================================ */

.flag {
  border-left: 3px solid var(--c-danger);
  background: var(--c-danger-tint);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-3);
}
.flag--caution { border-left-color: var(--c-terra); background: var(--c-terra-tint); }
.flag--info    { border-left-color: var(--c-sage);  background: var(--c-sage-tint); }
.flag__title {
  font-size: var(--t-sm);
  font-weight: 700;
  color: var(--c-danger);
  margin: 0 0 var(--s-1);
}
.flag--caution .flag__title { color: var(--c-warn); }
.flag--info .flag__title    { color: var(--c-sage-deep); }
.flag__body { font-size: var(--t-sm); line-height: 1.55; margin: 0 0 var(--s-1); }

.client-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: var(--tap-lg);
  padding: var(--s-3);
  background: var(--c-paper);
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  margin-bottom: var(--s-2);
  text-align: left;
}
.client-row__name {
  display: block;
  font-size: var(--t-base);
  font-weight: 600;
  line-height: 1.3;
}
.client-row__meta {
  display: block;
  margin-top: 2px;
  font-size: var(--t-xs);
  color: var(--c-ink-soft);
  font-weight: 500;
  line-height: 1.4;
}
.dot-alert {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--c-danger); flex: 0 0 auto;
}

/* ---- toggle switch ---- */
.toggle {
  width: 48px; height: 28px;
  border-radius: var(--r-pill);
  background: var(--c-line-strong);
  position: relative;
  flex: 0 0 auto;
  transition: background var(--m-fast) var(--m-ease);
}
.toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(47, 62, 54, 0.25);
  transition: transform var(--m-base) var(--m-ease);
}
.toggle--on { background: var(--c-sage); }
.toggle--on::after { transform: translateX(20px); }


/* ---- today's checklist ----
   State is carried by a mark AND by the wording, never by colour alone:
   a client who cannot distinguish sage from grey must still be able to
   tell what is done. */
.checkrow {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: var(--tap);
  padding: var(--s-2) 0;
  border-bottom: 1px solid var(--c-line);
  text-align: left;
}
.checkrow:last-of-type { border-bottom: 0; }
.checkrow__mark {
  width: 26px; height: 26px;
  border-radius: 50%;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 700;
  border: 1.5px solid var(--c-line-strong);
  background: var(--c-paper);
  color: var(--c-paper);
}
.checkrow__mark--done { background: var(--c-sage); border-color: var(--c-sage); color: #fff; }
.checkrow__mark--part { background: var(--c-terra-soft); border-color: var(--c-terra); color: #8A4E33; }
.checkrow__mark--none { opacity: 0.4; }
.checkrow__body   { flex: 1 1 auto; min-width: 0; }
.checkrow__label  { display: block; font-size: var(--t-base); font-weight: 600; line-height: 1.3; }
.checkrow__detail { display: block; font-size: var(--t-xs); color: var(--c-ink-soft); margin-top: 2px; }
.checkrow__go     { color: var(--c-ink-soft); font-size: 1.25rem; flex: 0 0 auto; }


/* ---- movement level indicator ----
   The current level shown as steps, so a change is visible the instant
   it lands rather than buried in a line of grey text. */
.levelbar {
  display: flex;
  gap: 4px;
  margin: var(--s-2) 0 var(--s-1);
}
.levelbar__step {
  flex: 1 1 0;
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--c-line);
}
.levelbar__step--past { background: var(--c-sage); opacity: 0.45; }
.levelbar__step--now  { background: var(--c-sage-deep); }
.levelbar__step--off  { background: var(--c-line); opacity: 0.35; }


/* ---- habit line on Today ----
   A row you can act on, not a label you can only read. */
.habit-line {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--s-2) 0;
  border-bottom: 1px solid var(--c-line);
  text-align: left;
}
.habit-line:last-of-type { border-bottom: 0; }
.habit-line__name {
  flex: 1 1 auto;
  font-size: var(--t-sm);
  line-height: 1.35;
  min-width: 0;
}
.habit-line__state {
  font-size: var(--t-xs);
  color: var(--c-ink-soft);
  font-weight: 500;
  white-space: nowrap;
}
/* "Logged: yes" and "Logged: no" look identical on purpose. The streak
   counts honest answers, so the visual language must not make one of
   them look like the wrong one. */
.habit-line__state--done { color: var(--c-sage-deep); font-weight: 600; }
.habit-line__go { color: var(--c-ink-soft); font-size: 1.125rem; flex: 0 0 auto; }
