/* coach.css — loaded by coach.html ONLY.
 *
 * The Coach page. base.css loads first and supplies the tokens, the reset and
 * the nav; everything below is this page's own. There is no footer on this
 * page (see the comment at the top of coach.html).
 *
 * The page is one screen: nav, then the chat filling the rest of the viewport
 * with no frame around it — the page itself is the surface. On phones it is the
 * whole page. Nothing outside the chat log scrolls.
 *
 * LIGHT, unlike the rest of the site. The palette is the landing page's cream
 * sections (#journey, #pricing): --cream ground, --cream-fg / --cream-fg2 text,
 * --rule-light hairlines, moss for the accents. The nav partial is built for a
 * dark page, so its colours are re-pointed below, scoped to this page only.
 *
 * SELF-CONTAINED BY DECISION. Nothing this page needs gets promoted into
 * base.css, even where another page happens to have a rule that looks the
 * same. If this file ends up duplicating something from home.css, that is the
 * intended trade: the landing page and this page are free to move
 * independently, and neither can break the other by accident.
 */


/* Visually hidden, still read aloud and still counted by search engines.
   Defined here rather than borrowing home.css's .sr-only — see the header. */
.coach-a11y {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}


/* ──────────────────── PAGE ────────────────────
   base.css paints <html> and <body> --ink. Both have to change: any
   overscroll, or anything that pokes past the body, shows <html>'s colour —
   which is exactly the grey strip this page used to have at the bottom. */
:root:has(body.coach-page) { background: var(--cream); }

body.coach-page {
  background: var(--cream); color: var(--cream-fg);
  /* No rubber-band bounce of the whole page on iOS — only the log scrolls. */
  overscroll-behavior: none;
}


/* ──────────────────── NAV, RE-POINTED FOR A LIGHT PAGE ────────────────────
   Same markup and behaviour as every other page (tools/partials/nav.html,
   js/nav.js); only the colours change. Every rule is prefixed with
   .coach-page, so none of it can leak. */
.coach-page .nav-brand { color: var(--cream-fg); }

.coach-page .nav-links-center a { color: var(--cream-fg2); }

.coach-page .nav-links-center a:hover { color: var(--cream-fg); }

.coach-page .nav-toggle span { background: var(--cream-fg); }

.coach-page .nav.solid,
.coach-page .nav.open {
  background: rgba(244,237,227,0.82);
  border-bottom-color: var(--rule-light);
}

@media (max-width: 860px) {
  .coach-page .nav-links-center {
    background: #FFFDF8;
    border-color: var(--rule-light);
    box-shadow: 0 18px 40px -16px rgba(16,30,29,0.28);
  }

  .coach-page .nav-links-center a { color: var(--cream-fg); }

  .coach-page .nav-links-center a:active { background: rgba(16,30,29,0.05); }
}


/* ──────────────────── STAGE ────────────────────
   Exactly one viewport tall, and the chat takes whatever the nav and the
   margins leave. dvh, not vh: on a phone vh is the height with the browser's
   toolbars HIDDEN, so a 100vh page puts its bottom edge — the input — under
   Safari's bottom bar. dvh tracks the toolbars as they appear and go.

   min-height on .coach-card (below) is what stops a very short window crushing
   the chat; the page scrolls instead. */
.coach-stage {
  display: flex; flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  /* Top clears the fixed nav (73px) with air to spare; the bottom margin
     matches it so the chat sits in the space rather than hanging off the
     nav. */
  padding: calc(120px + env(safe-area-inset-top)) 0 calc(64px + env(safe-area-inset-bottom));
}

.coach-stage > .container {
  flex: 1 1 auto; display: flex; flex-direction: column;
  width: 100%; min-height: 0;
}


/* ──────────────────── THE CHAT AREA ────────────────────
   No fill, no border, no shadow. The page is the surface; this box only sizes
   the chat to the space between the nav and the bottom margin. */
.coach-card {
  position: relative;
  display: flex; flex-direction: column;
  /* Fills the stage, but stops growing on very tall monitors — past this a
     chat stops looking like a conversation and starts looking like a void.
     The auto margins centre it once it hits the cap. */
  flex: 1 1 auto; min-height: 420px; max-height: 860px; margin-block: auto;
  /* The log scrolls inside this box and must not spill past it. */
  overflow: hidden;
}


/* ──────────────────── HELP BUTTON + DISCLOSURE PANEL ────────────────────
   The chat's privacy disclosure lives in a panel hanging off a bubble button at the
   top right of the reading column. It is OPEN when the page loads (the markup
   ships without `hidden`) and "I understand" closes it; the bubble reopens it any
   time.

   Both sit on the column's right edge, not the box's: `right` uses the same
   formula as .chat-log's padding-inline, so the button, the end of the text and the
   send button line up vertically. Change one and change all three.

   While it is open the chat behind it dims and stops taking clicks. That is
   keyed on the panel's own `hidden` attribute with :has(), not on a class a
   script adds, so the first paint is already right — no flash of an undimmed
   chat before js/coach.js runs. */
.coach-info-toggle {
  position: absolute; top: 14px; z-index: 6;
  right: max(24px, calc((100% - var(--coach-measure)) / 2));
  width: 56px; height: 56px; padding: 3px; border-radius: 18px;
  display: grid; place-items: center; cursor: pointer;
  background: color-mix(in srgb, #8B5E3C 10%, var(--cream)); border: 1px solid var(--rule-light);
  box-shadow: 0 4px 14px -10px rgba(16,30,29,0.55);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease-out, filter .15s ease-out;
}

.coach-info-toggle img { display: block; width: 100%; height: 100%; object-fit: contain; }

.coach-info-toggle:hover { filter: drop-shadow(0 4px 7px rgba(16,30,29,0.18)); }

.coach-info-toggle[aria-expanded="true"] { border-color: #8B5E3C; }

.coach-info-toggle:active { transform: scale(.9); }

.coach-info-toggle:focus-visible,
.coach-info-ok:focus-visible,
.coach-info-links a:focus-visible {
  outline: 2px solid var(--moss-dark); outline-offset: 3px;
}


/* An opaque surface a step lighter than the page — it sits over live text and
   must not let it show through — with a faint moss wash from the top-left
   corner and a soft drop so it reads as lifted off the dimmed chat. */
.coach-info {
  position: absolute; z-index: 5;
  top: 78px;
  right: max(24px, calc((100% - var(--coach-measure)) / 2));
  width: min(380px, calc(100% - 48px));
  max-height: calc(100% - 78px); overflow-y: auto; overscroll-behavior: contain;
  padding: 22px 22px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--rule-light);
  background:
    linear-gradient(160deg, rgba(95,149,105,0.09), rgba(95,149,105,0) 55%),
    #FFFDF8;
  box-shadow: 0 22px 50px -24px rgba(16,30,29,0.35);
  color: var(--cream-fg2); font-size: 14px; line-height: 1.6;
  animation: coach-info-in .22s ease-out;
}

.coach-info[hidden] { display: none; }

@keyframes coach-info-in {
  from { opacity: 0; transform: translateY(-6px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

/* base.css styles every h2 as the serif display face. This is a dialog title
   inside a sans UI, so it gets the UI's own type. */
.coach-info-title {
  margin: 0 0 10px; padding-right: 8px;
  font-family: var(--sans); font-size: 17px; font-weight: 700;
  line-height: 1.3; letter-spacing: -0.01em; color: var(--cream-fg);
}

.coach-info .chat-note { margin: 0; max-width: none; }

.coach-info .chat-note strong { color: var(--cream-fg); font-weight: 600; }

.coach-info-links {
  margin: 14px 0 0; max-width: none;
  display: flex; flex-wrap: wrap; gap: 10px;
  font-size: 12.5px;
}

.coach-info-links a { color: var(--cream-fg2); text-decoration: none; }

.coach-info-links a:hover { color: var(--cream-fg); text-decoration: underline; text-underline-offset: 2px; }

.coach-info-ok { width: 100%; margin-top: 18px; }


/* The chat behind an open panel. */
.chat { transition: opacity .2s ease, filter .2s ease; }

.coach-card:has(> .coach-info:not([hidden])) > .chat {
  opacity: .3; filter: blur(2px); pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .coach-info { animation: none; }
  .chat { transition: none; }
  .coach-info-toggle { transition: none; }
}


/* ──────────────────── THE CHAT ────────────────────
   Wired to chat.js through #ai-chat-widget and the data-chat-* hooks. The
   markup and the interaction are the landing page's, unchanged: the log is
   bottom-anchored, the chips disappear after the first message, the dock
   floats over the conversation and the messages fade out behind it.

   What differs is measure. The chat area is ~1116px wide and a paragraph set
   to that is unreadable, so the conversation is centred in a fixed column and
   the rest of the width becomes margin. Both the log and the dock use the same
   column so the input lines up under the text.

   READ BEFORE DELETING ANY .msg-* RULE: chat.js builds every bubble in
   JavaScript — .msg-user and .msg-coach are even concatenated ('msg msg-' +
   role) — so none of these class names appear in the HTML and a search of the
   JS won't find those two either. Every dead-CSS tool will call this whole
   family unused and every one of them is wrong. Delete them and the page
   still looks perfect while the coach's replies render unstyled. */
.coach-card {
  /* The readable column the conversation is centred in — roughly 70
     characters at this size. The log and the dock both use it, so the input
     lines up exactly under the text. */
  --coach-measure: 660px;
}

/* base.css caps every <p> at 60ch. Inside the log that fights the measure
   above: the text stops wrapping well before the column ends and the input
   sits wider than the paragraphs it belongs to. One authority, not two —
   width here is the measure's job, and the bubble's own max-width for the
   visitor's messages. */
.chat-log p { max-width: none; }

.chat { position: relative; flex: 1 1 auto; min-height: 0; }

.chat-log {
  position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 24px;
  padding-block: 44px 168px;
  padding-inline: max(24px, calc((100% - var(--coach-measure)) / 2));
  scrollbar-width: none;
}

/* Once the chips are gone the dock is shorter, so the log gets its space back. */
.chat:has(.chat-chips[hidden]) .chat-log { padding-bottom: 132px; }

.chat-log::-webkit-scrollbar { width: 0; height: 0; }

/* The app's list is inverted — the conversation sits on the bottom edge. */
.chat-log > *:first-child { margin-top: auto; }


/* Decorative: messages fade out behind the floating dock instead of being
   hard-clipped by it. Both gradients are --cream (#F4EDE3) — the page colour,
   since the chat area has no fill of its own. Change the page colour and these
   have to change with it or the fade shows as a visible band. */
.chat-scrim-top, .chat-scrim-bottom {
  position: absolute; left: 0; right: 0; pointer-events: none; z-index: 2;
}

.chat-scrim-top {
  /* Tall enough to fade messages out before they reach the help button. */
  top: 0; height: 78px;
  background: linear-gradient(180deg, rgba(244,237,227,1) 0%, rgba(244,237,227,1) 30%, rgba(244,237,227,0) 100%);
}

.chat-scrim-bottom {
  bottom: 0; height: 150px;
  background: linear-gradient(0deg, rgba(244,237,227,1) 0%, rgba(244,237,227,0.92) 46%, rgba(244,237,227,0) 100%);
}


.chat-dock {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 3;
  padding-block: 30px 20px;
  padding-inline: max(24px, calc((100% - var(--coach-measure)) / 2));
}

.chat:has(.chat-chips[hidden]) .chat-dock { padding-top: 0; }


/* ---- messages: Boo introduces each reply, then the answer follows ---- */
.msg-coach {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  font-size: 16px; line-height: 23px; color: var(--cream-fg);
}

.msg-coach::before {
  content: ''; display: block; width: 136px; height: 102px;
  background: url('../assets/images/coach-boo-speaking.webp') center / contain no-repeat;
}

.msg-label { display: flex; align-items: center; gap: 8px; }

.msg-coach .msg-label i { display: none; }

.msg-label span { font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--moss-dark); }


.msg-body {
  display: flex; flex-direction: column; width: 100%; padding: 20px 22px;
  border: 1px solid var(--rule-light); border-radius: 20px 20px 20px 6px;
  background: #FFFDF8; box-shadow: 0 8px 28px -24px rgba(16,30,29,0.5);
}

.msg-body > * { margin: 0; }

/* 12px between blocks; a heading takes 24 above and gives 8 to whatever
   follows it — headings belong with their content. */
.msg-body > * + * { margin-top: 12px; }

.msg-body > .msg-h + * { margin-top: 8px; }

.msg-body > .msg-h { margin-top: 24px; font-size: 20px; line-height: 26px; font-weight: 600; }

.msg-body > .msg-h:first-child { margin-top: 0; }

.msg-body p { white-space: pre-wrap; }

.msg-list { display: flex; flex-direction: column; gap: 8px; }

.msg-li { display: flex; gap: 10px; }

.msg-li > .bullet { flex-shrink: 0; color: var(--cream-fg2); }

.msg-li.pending > .bullet { color: transparent; }

.msg-li > .t { flex: 1 1 auto; min-width: 0; }

/* The not-yet-typed tail: still occupies space, so nothing reflows as the
   reply types itself out. */
.pending { color: transparent; }

/* chat.js emits this for ==highlighted== spans. There is no rule for it
   anywhere in home.css, so on the landing page a highlight currently renders
   as plain text — this is the first place it actually gets styled. */
.msg-mark {
  background: rgba(95,149,105,0.20);
  border-radius: 4px;
  padding: 0 3px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}


.msg-user {
  align-self: flex-end; max-width: 85%; padding: 12px 16px; border-radius: 20px;
  background: linear-gradient(to bottom, var(--moss), var(--moss-dark));
  font-size: 16px; line-height: 22px; color: #fff;
}

.msg-user p { margin: 0; }

.msg-user p + p { margin-top: 8px; }


.msg-note { font-size: 14px; line-height: 20px; color: var(--cream-fg2); }

.msg-note p { margin: 0; }


/* "Coach is thinking…" — the app's quiet tempo, dots cycling 1→2→3. */
.msg-typing { font-size: 14px; font-style: italic; line-height: 20px; color: var(--cream-fg2); }


/* ---- the dock: suggested topics, then the input ---- */
.chat-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }

.chat-chips::-webkit-scrollbar { display: none; }

.chat-chips[hidden] { display: none; }

/* The dark page's chips use --moss-bright for the label; on cream that is too
   pale to read, so the label drops to --moss-dark and the border gradient
   darkens with it. */
.chat-chip {
  appearance: none; -webkit-appearance: none; font: inherit; cursor: pointer;
  flex-shrink: 0; white-space: nowrap;
  font-size: 13px; font-weight: 700; padding: 9px 16px; border-radius: 9999px;
  border: 1.5px solid transparent;
  /* The padding-box layer must match the page, or the pill shows a
     rectangle behind its rounded gradient border. */
  background: linear-gradient(var(--cream), var(--cream)) padding-box,
              linear-gradient(135deg, var(--moss), var(--moss-dark)) border-box;
  color: var(--moss-dark); transition: background-color .15s, filter .15s;
}

.chat-chip:hover {
  background: linear-gradient(#E6E6D6, #E6E6D6) padding-box,
              linear-gradient(135deg, var(--moss), var(--moss-dark)) border-box;
}


.chat-form { display: flex; gap: 10px; align-items: flex-end; }

.chat-form textarea {
  flex: 1; resize: none; font-family: var(--sans);
  /* 16px keeps iOS from zooming the page on focus — do not lower */
  font-size: 16px; line-height: 22px; min-height: 48px; max-height: 110px;
  padding: 12px 16px; border-radius: var(--radius-lg);
  background: #FFFDF8; color: var(--cream-fg);
  border: 1px solid rgba(16,30,29,0.14); outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.chat-form textarea::placeholder { color: rgba(16,30,29,0.42); }

.chat-form textarea:focus { border-color: var(--moss); box-shadow: 0 0 0 3px rgba(95,149,105,0.18); }

.chat-form textarea:disabled { opacity: .5; }


.chat-send {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 9999px;
  display: grid; place-items: center; cursor: pointer; font-size: 19px;
  color: #fff; border: 1px solid transparent;
  background: linear-gradient(to bottom, var(--moss), var(--moss-dark));
  transition: opacity .15s;
}

.chat-send:disabled { opacity: .4; cursor: not-allowed; }


/* ──────────────────── ICON GLYPHS ────────────────────
   The @font-face rules are in base.css, but every .ph-*:before glyph rule
   lives in home.css, which this page does not load — so the two icons here
   are declared again rather than promoted. Only these two are needed:
   ph-arrow-right on the send button, and ph-sparkle, which chat.js writes
   into every coach message label itself.

   The fonts are SUBSETTED. A ph- class with no rule renders as a blank box. */
.ph, .ph-fill {
  font-style: normal; font-weight: normal; font-variant: normal;
  text-transform: none; line-height: 1; letter-spacing: 0;
  font-feature-settings: "liga";
  font-variant-ligatures: discretionary-ligatures;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}

/* !important guards against browser extensions that override page fonts. */
.ph { font-family: "Phosphor" !important; }

.ph-fill { font-family: "Phosphor-Fill" !important; }

.ph.ph-arrow-right:before { content: "\e06c"; }

.ph-fill.ph-sparkle:before { content: "\e6a2"; }


/* ──────────────────── TABLET ────────────────────
   The nav collapses to its hamburger here; the chat keeps its margins. */
@media (max-width: 860px) {
  .coach-stage {
    padding: calc(96px + env(safe-area-inset-top)) 0 calc(32px + env(safe-area-inset-bottom));
  }
}


/* ──────────────────── PHONE: FULL PAGE ────────────────────
   The margins go away and the chat becomes the screen, the way it looks
   inside the app. A hairline under the nav keeps the bar reading as a header.

   Also applies to a phone held sideways (short, not narrow): at ~390px tall a
   chat with margins leaves no room for the conversation.

   Safe areas, edge by edge:
     top     the nav already pads itself for the notch / status bar
     bottom  the dock adds the home-indicator inset; the browser's own toolbar
             is kept clear by the stage being 100dvh (see STAGE above)
     sides   landscape notches — the log and the dock pad for them */
@media (max-width: 640px), (max-height: 500px) {
  .coach-stage {
    /* 65px is the nav bar's own height at this size: 44px toggle, 2×10px
       padding and its 1px (transparent) bottom border. */
    padding: calc(65px + env(safe-area-inset-top)) 0 0;
    height: 100vh;
    height: 100dvh;
  }

  .coach-stage > .container { max-width: none; padding-inline: 0; }

  .coach-card {
    min-height: 0; max-height: none; margin-block: 0;
    border-radius: 0; border: 0;
    border-top: 1px solid var(--rule-light);
  }

  /* 16px gutters on a phone held upright; the reading column again on a phone
     held sideways, where 16px gutters would run lines the full 900px. */
  .chat-log {
    padding-block: 28px 160px;
    padding-left: max(calc(16px + env(safe-area-inset-left)), calc((100% - var(--coach-measure)) / 2));
    padding-right: max(calc(16px + env(safe-area-inset-right)), calc((100% - var(--coach-measure)) / 2));
  }

  .chat:has(.chat-chips[hidden]) .chat-log { padding-bottom: 126px; }

  .chat-dock {
    padding-top: 26px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    padding-left: max(calc(16px + env(safe-area-inset-left)), calc((100% - var(--coach-measure)) / 2));
    padding-right: max(calc(16px + env(safe-area-inset-right)), calc((100% - var(--coach-measure)) / 2));
  }

  /* Same column edges as the log and the dock above. */
  .coach-info-toggle {
    top: 10px;
    right: max(calc(16px + env(safe-area-inset-right)), calc((100% - var(--coach-measure)) / 2));
    width: 52px; height: 52px;
  }

  .coach-info {
    top: 72px;
    left: max(calc(16px + env(safe-area-inset-left)), calc((100% - var(--coach-measure)) / 2));
    right: max(calc(16px + env(safe-area-inset-right)), calc((100% - var(--coach-measure)) / 2));
    width: auto; max-height: calc(100% - 70px);
    padding: 20px 18px 18px;
  }

  .chat-scrim-top { height: 72px; }

  .msg-coach { font-size: 15px; line-height: 22px; }

  .msg-coach::before { width: 116px; height: 87px; }

  .msg-body { padding: 16px 17px; }

  .msg-user { font-size: 15px; line-height: 21px; }

  .msg-body > .msg-h { font-size: 18px; line-height: 24px; }

  .chat-chip { padding: 8px 15px; }

  .chat-form textarea {
    /* Must stay 16px: anything smaller makes iOS zoom the page on focus.
       Only the height shrinks. */
    font-size: 16px; line-height: 21px; min-height: 46px;
  }

  .chat-send { width: 42px; height: 42px; }
}
