/* Coach chat (screens/chat.js). The thread fills the space above the tab bar: header, messages that scroll, composer. */

.chat {
  position: fixed; top: 0; left: 0; right: 0; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; background: var(--page); z-index: 1;
}
.chat-head {
  display: flex; align-items: center; gap: var(--sp-md);
  padding: calc(env(safe-area-inset-top) + var(--sp-md)) var(--gutter) var(--sp-md);
  border-bottom: 1px solid var(--rule);
}
.chat-avatar {
  position: relative; flex: none; border-radius: 50%; overflow: hidden; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); font-weight: 600; line-height: 1;
}
.chat-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.chat-cover {
  margin: var(--sp-sm) var(--gutter) 0; padding: var(--sp-sm) var(--sp-md); border-radius: var(--r-control);
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--ink2); font-size: 14px;
}
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--sp-md) var(--gutter) var(--sp-lg); }
.chat-older { padding-bottom: var(--sp-md); }

/* States */
.chat-empty { margin: var(--sp-xxl) auto 0; max-width: 340px; text-align: center; }
.chat-loading > .caption { margin-bottom: var(--sp-md); }
.chat-skel-row { display: flex; margin-top: var(--sp-md); }
.chat-skel-row.mine { justify-content: flex-end; }
.chat-skel { height: 44px; width: 58%; border-radius: 18px; }
.chat-skel-row.mine .chat-skel { width: 42%; }

/* Messages */
.msg { display: flex; flex-direction: column; align-items: flex-start; margin-top: 6px; }
.msg.mine { align-items: flex-end; }
.msg.wide { align-items: stretch; }
.msg-sender { margin: var(--sp-md) 0 2px 4px; font-size: 13px; font-weight: 600; color: var(--ink2); }
.msg-time { margin: 2px 6px 0; font-size: 11px; color: var(--ink3); font-variant-numeric: tabular-nums; }
.bubble {
  max-width: min(82%, 420px); padding: 9px 14px; border-radius: 18px; background: var(--sunken); border: 1px solid var(--rule);
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; line-height: 1.38; cursor: pointer;
}
.msg.mine .bubble { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.bubble:focus-visible, .msg-media:focus-visible, .react-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.msg-stack { display: flex; flex-direction: column; gap: 4px; align-items: inherit; max-width: 100%; }
.msg-stack > .bubble { cursor: default; }

.msg-photo {
  display: block; width: 280px; max-width: 78vw; min-height: 180px; border-radius: 16px; overflow: hidden;
  background: var(--rule); border: 1px solid var(--rule);
}
.msg-photo.loaded { min-height: 0; background: none; }
.msg-photo img { display: block; width: 100%; max-height: 320px; object-fit: cover; }
.msg-photo-fail { display: block; padding: var(--sp-lg); }
.msg-video { width: 320px; max-width: 78vw; border-radius: 16px; overflow: hidden; background: #000; }
.msg-video video { display: block; width: 100%; aspect-ratio: 16 / 9; }
.msg-video > .caption { padding: var(--sp-md); background: var(--sunken); }

.msg-media {
  display: flex; align-items: center; gap: var(--sp-md); width: 320px; max-width: 82%; padding: 10px 14px; text-align: left;
  border-radius: 18px; border: 1px solid var(--rule); background: var(--sunken); cursor: pointer;
}
.msg-media .row-title, .msg-media .caption { display: block; }
.msg-glyph { width: 36px; height: 36px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); }
.msg-glyph svg { width: 18px; height: 18px; }
.msg.wide .msg-media { max-width: 100%; }

/* Goal and check-in cards */
.msg-card { width: 100%; padding: var(--sp-lg); border-radius: var(--r-card); background: var(--sunken); border: 1px solid var(--rule); }
.msg-card.goal { border-color: color-mix(in srgb, var(--accent) 35%, var(--rule)); }
.msg-card.checkin { border: 2px solid var(--accent); }
.checkin-eyebrow { color: var(--accent); }
.checkin-focus { margin: 0; font-size: 24px; font-weight: 600; line-height: 1.2; }
.goal-identity { font-style: italic; }
.goal-agreed { color: var(--accent); }
.card-section > .eyebrow { margin-bottom: 4px; }
.card-section > * + * { margin-top: 4px; }
.card-stats { display: flex; flex-wrap: wrap; gap: var(--sp-lg); }
.card-stat .value { font-size: 20px; }
.card-numbered { display: flex; align-items: flex-start; gap: var(--sp-sm); }
.card-numbered > .num { color: var(--accent); font-weight: 600; }
.card-dot {
  flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; margin-top: 1px;
  background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 600;
}

/* Reactions */
.msg-react:empty { display: none; }
.react-row { display: flex; gap: 4px; margin-top: 6px; padding: 4px; border-radius: 999px; background: var(--sunken); border: 1px solid var(--rule); }
.react-row button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: none; font-size: 20px; cursor: pointer; }
.react-row button:active { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.react-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.react-chip { min-height: 28px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--rule); background: var(--page); font-size: 13px; cursor: pointer; font-variant-numeric: tabular-nums; }
.react-chip.mine { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }

/* Composer */
.chat-composer { border-top: 1px solid var(--rule); padding: var(--sp-sm) var(--gutter); background: var(--page); }
.chat-composer > * + * { margin-top: var(--sp-sm); }
.chat-composer > [hidden] { display: none; }
.chat-error { font-size: 14px; }
.chat-blocked { padding: var(--sp-sm) 0; text-align: center; }
.chat-bar { display: flex; align-items: flex-end; gap: var(--sp-sm); }
.chat-input {
  flex: 1; min-width: 0; resize: none; min-height: 42px; max-height: 132px; padding: 10px 14px; border-radius: 21px;
  border: 1px solid var(--rule); background: var(--sunken); font-size: 16px; line-height: 1.35;
}
.chat-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.chat-icon {
  flex: none; width: 42px; height: 42px; border: 0; border-radius: 50%; display: grid; place-items: center;
  background: none; color: var(--accent); cursor: pointer;
}
.chat-icon svg { width: 24px; height: 24px; }
.chat-send { background: var(--accent); color: var(--on-accent); }
.chat-send svg { width: 20px; height: 20px; }
.chat-send[disabled] { opacity: .4; cursor: default; }
.chat-pending { display: flex; align-items: center; gap: var(--sp-md); }
.chat-thumb { width: 56px; height: 56px; flex: none; border-radius: 10px; object-fit: cover; }
.chat-thumb.skel { border-radius: 10px; }
