/* ============================================================
   OffGrid — Coach chat (extends site.css)
   ============================================================ */

html, body { height: 100%; }
body.chat-body { overflow: hidden; }

/* ---- auth gate (full chat = signed-in only) ---- */
.auth-gate { display: none; margin-bottom: 4px; }
.auth-gate .ag-card {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--bg-2); border: 1px solid var(--line-2);
  border-radius: 16px; padding: 14px 40px 14px 16px; position: relative;
}
.auth-gate .ag-close {
  position: absolute; top: 10px; right: 10px; width: 24px; height: 24px;
  border-radius: 7px; color: var(--ink-3); font-size: 13px; line-height: 1;
  display: grid; place-items: center;
}
.auth-gate .ag-close:hover { background: var(--bg-3); color: var(--ink); }
.auth-gate .ag-ic {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: grid; place-items: center; background: var(--bg-3); color: var(--acc);
}
.auth-gate .ag-ic svg { width: 20px; height: 20px; }
.auth-gate .ag-tx { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 180px; }
.auth-gate .ag-tx b { font-size: 15px; font-weight: 600; color: var(--ink); }
.auth-gate .ag-tx span { font-size: 13px; color: var(--ink-2); text-wrap: pretty; }
.auth-gate .ag-actions { display: flex; gap: 8px; flex: none; }

.chat-app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
}

/* ---- slim header --------------------------------------- */
.chat-head {
  display: flex; align-items: center; gap: 16px;
  height: 60px; padding: 0 clamp(14px, 3vw, 26px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  z-index: 5; flex: none;
}
.chat-head .brand .peak { width: 22px; height: 22px; }
.chat-head .brand .word { font-size: 17px; }
.chat-head .ch-tag { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); border-left: 1px solid var(--line-2); padding-left: 14px; margin-left: 2px; }
.chat-head .ch-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.chat-head .ch-btn { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; color: var(--ink-2); border: 1px solid var(--line-2); border-radius: 100px; padding: 8px 14px; transition: .15s; }
.chat-head .ch-btn:hover { color: var(--ink); border-color: var(--ink-3); }
.chat-head .ch-btn svg { width: 14px; height: 14px; }
.chat-head .ch-home { color: var(--ink-3); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; transition: color .15s; }
.chat-head .ch-home:hover { color: var(--ink); }
@media (max-width: 560px) { .chat-head .ch-home span, .chat-head .ch-btn span { display: none; } .chat-head .ch-tag { display: none; } }

/* ---- scroll area --------------------------------------- */
.chat-scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.chat-inner { max-width: 760px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 24px) 16px; }

/* ---- empty / welcome state ----------------------------- */
.welcome { padding: clamp(28px, 7vh, 72px) 0 10px; text-align: center; }
.welcome .wmark { width: 60px; height: 60px; border-radius: 18px; background: var(--acc); color: #04130a; display: grid; place-items: center; margin: 0 auto 24px; box-shadow: 0 0 50px -10px var(--acc-glow); }
.welcome .wmark svg { width: 32px; height: 32px; }
.welcome h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 700; letter-spacing: -0.035em; line-height: 1.05; text-wrap: balance; }
.welcome h1 .hl { color: var(--acc); }
.welcome p { color: var(--ink-2); font-size: 1.02rem; margin: 16px auto 0; max-width: 44ch; text-wrap: pretty; }

.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 34px; text-align: left; }
.qcard {
  display: flex; align-items: flex-start; gap: 13px;
  background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--r-m);
  padding: 18px 18px; cursor: pointer; transition: border-color .2s, transform .2s, background .2s;
}
.qcard:hover { border-color: var(--line-2); transform: translateY(-2px); background: var(--bg-2); }
.qcard .qi { width: 36px; height: 36px; border-radius: 10px; background: var(--bg-3); color: var(--acc); display: grid; place-items: center; flex: none; }
.qcard.o .qi { color: var(--acc-2); }
.qcard .qi svg { width: 19px; height: 19px; }
.qcard .qt { font-weight: 600; font-size: 14.5px; letter-spacing: -0.01em; }
.qcard .qd { color: var(--ink-3); font-size: 12.5px; margin-top: 3px; }
@media (max-width: 560px) { .quick-grid { grid-template-columns: 1fr; } }

/* ---- messages ------------------------------------------ */
.msgs { display: flex; flex-direction: column; gap: 22px; padding-top: 8px; }
.cmsg { display: flex; gap: 13px; }
.cmsg.user { justify-content: flex-end; }
.cmsg .av { width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center; }
.cmsg.ai .av { background: var(--acc); color: #04130a; }
.cmsg.ai .av svg { width: 17px; height: 17px; }
.cmsg.user .bubble {
  background: var(--acc-dim); border: 1px solid color-mix(in srgb, var(--acc) 26%, transparent);
  color: var(--ink); padding: 12px 16px; border-radius: 16px 16px 4px 16px;
  font-size: 15px; max-width: 78%; white-space: pre-wrap; word-break: break-word;
}
.cmsg.ai .content { max-width: 100%; font-size: 15px; color: var(--ink); padding-top: 3px; min-width: 0; }

/* markdown */
.content > *:first-child { margin-top: 0; }
.content > *:last-child { margin-bottom: 0; }
.content h1, .content h2, .content h3 { font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; margin: 20px 0 10px; }
.content h1 { font-size: 1.35rem; }
.content h2 { font-size: 1.18rem; }
.content h3 { font-size: 1.05rem; }
.content p { margin: 10px 0; line-height: 1.6; color: var(--ink); }
.content strong { font-weight: 700; color: var(--ink); }
.content em { font-style: italic; }
.content a { color: var(--acc); text-decoration: underline; text-underline-offset: 2px; }
.content ul, .content ol { margin: 10px 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }
.content li { line-height: 1.55; color: var(--ink); }
.content ul li { list-style: none; position: relative; }
.content ul li::before { content: ""; position: absolute; left: -16px; top: 9px; width: 6px; height: 6px; border-radius: 50%; background: var(--acc); }
.content ol { list-style: decimal; }
.content ol li::marker { color: var(--acc); font-family: var(--font-mono); font-weight: 600; }
.content code { font-family: var(--font-mono); font-size: .88em; background: var(--bg-3); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; }
.content pre { background: var(--bg-1); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; overflow-x: auto; margin: 12px 0; }
.content pre code { background: none; border: none; padding: 0; }
.content blockquote { border-left: 2px solid var(--acc); padding-left: 14px; color: var(--ink-2); margin: 12px 0; }
.content hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

/* tables (nutrition) */
.content .tbl-wrap { overflow-x: auto; margin: 14px 0; border: 1px solid var(--line); border-radius: 10px; }
.content table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 360px; }
.content thead th { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--bg-2); white-space: nowrap; }
.content tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.content tbody tr:last-child td { border-bottom: none; }
.content tbody tr:nth-child(even) td { background: rgba(255,255,255,.015); }

/* typing indicator */
.cmsg.ai.loading .content { display: flex; align-items: center; }
.typing-dots { display: inline-flex; gap: 5px; padding: 6px 0; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--acc); opacity: .5; animation: cblink 1.4s infinite both; }
.typing-dots i:nth-child(2){ animation-delay: .2s; }
.typing-dots i:nth-child(3){ animation-delay: .4s; }
@keyframes cblink { 0%,80%,100%{ opacity:.25; transform: translateY(0);} 40%{ opacity:1; transform: translateY(-4px);} }

/* error */
.cmsg.error .content { color: var(--acc-2); }
.err-box { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; background: var(--bg-1); border: 1px solid color-mix(in srgb, var(--acc-2) 35%, transparent); border-radius: var(--r-m); padding: 16px 18px; }
.err-box .et { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--ink); font-size: 14.5px; }
.err-box .et svg { color: var(--acc-2); width: 18px; height: 18px; flex: none; }
.err-box .em { color: var(--ink-2); font-size: 14px; line-height: 1.5; }
.err-box .ecode { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; word-break: break-word; max-width: 100%; }
.err-box .retry { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 600; color: #04130a; background: var(--acc); border-radius: 100px; padding: 8px 16px; }
.err-box .retry svg { width: 14px; height: 14px; }

/* ---- input bar ----------------------------------------- */
.composer { flex: none; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.composer-inner { max-width: 760px; margin: 0 auto; padding: 14px clamp(16px, 4vw, 24px) 10px; }

/* quick chips (when conversation active) */
.chips-row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.chips-row.hide { display: none; }
.chips-row .chip { font-family: var(--font-mono); font-size: 12px; color: var(--ink-2); border: 1px solid var(--line-2); border-radius: 100px; padding: 7px 13px; cursor: pointer; transition: .15s; }
.chips-row .chip:hover { color: var(--ink); border-color: var(--acc); }

.input-shell {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 22px;
  padding: 8px 8px 8px 18px; transition: border-color .18s;
}
.input-shell:focus-within { border-color: var(--acc); }
.input-shell textarea {
  flex: 1; background: none; border: none; outline: none; resize: none;
  color: var(--ink); font-family: inherit; font-size: 15.5px; line-height: 1.5;
  max-height: 180px; padding: 9px 0; min-height: 24px;
}
.input-shell textarea::placeholder { color: var(--ink-3); }
.send-btn {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: var(--acc); color: #04130a; display: grid; place-items: center;
  transition: transform .15s, opacity .15s, background .15s;
}
.send-btn:hover:not(:disabled) { transform: scale(1.06); }
.send-btn:disabled { opacity: .35; cursor: not-allowed; }
.send-btn svg { width: 18px; height: 18px; }
.composer-note { text-align: center; font-size: 11.5px; color: var(--ink-3); margin-top: 9px; font-family: var(--font-mono); letter-spacing: .02em; padding: 0 8px; }

/* ============================================================
   VOICE MODE — header controls, avatar, mic, settings
   ============================================================ */

/* header icon buttons */
.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  border: 1px solid var(--line-2); color: var(--ink-2);
  display: grid; place-items: center; transition: .15s; position: relative;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-3); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.on { background: var(--acc); border-color: var(--acc); color: #04130a; }

/* settings popover */
.settings-pop {
  position: absolute; top: 56px; right: clamp(14px,3vw,26px);
  width: min(330px, calc(100vw - 28px));
  background: var(--bg-1); border: 1px solid var(--line-2); border-radius: var(--r-m);
  box-shadow: 0 30px 70px -30px rgba(0,0,0,.85);
  padding: 20px; z-index: 20;
  opacity: 0; transform: translateY(-8px); pointer-events: none; transition: .2s;
}
.settings-pop.open { opacity: 1; transform: none; pointer-events: auto; }
.settings-pop h4 { font-size: 12px; font-family: var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 14px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-top: 1px solid var(--line); }
.set-row:first-of-type { border-top: none; }
.set-row .sl { font-size: 14px; font-weight: 500; color: var(--ink); }
.set-row .sd { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

/* toggle switch */
.switch { width: 44px; height: 26px; border-radius: 100px; background: var(--bg-3); border: 1px solid var(--line-2); position: relative; cursor: pointer; flex: none; transition: background .18s, border-color .18s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink-3); transition: transform .18s, background .18s; }
.switch.on { background: var(--acc); border-color: var(--acc); }
.switch.on::after { transform: translateX(18px); background: #04130a; }

/* gender segmented */
.seg2 { display: inline-flex; border: 1px solid var(--line-2); border-radius: 100px; padding: 3px; }
.seg2 button { padding: 6px 14px; border-radius: 100px; font-size: 13px; font-weight: 600; color: var(--ink-3); transition: .15s; }
.seg2 button.on { background: var(--acc); color: #04130a; }

.set-select { width: 100%; margin-top: 8px; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 9px; color: var(--ink); font-family: inherit; font-size: 13px; padding: 9px 11px; outline: none; }
.set-select:focus { border-color: var(--acc); }

.tier-note { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--ink-3); line-height: 1.6; }
.tier-note b { color: var(--ink-2); font-weight: 600; }

/* ---- avatar stage -------------------------------------- */
.avatar-stage {
  flex: none; overflow: hidden; max-height: 0;
  border-bottom: 1px solid transparent;
  background: radial-gradient(120% 120% at 50% 0%, var(--acc-dim), transparent 60%), var(--bg-1);
  transition: max-height .35s cubic-bezier(.2,.8,.3,1), border-color .35s;
}
.avatar-stage.open { max-height: 320px; border-bottom-color: var(--line); }
.avatar-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 24px 16px 20px; }

.face-wrap { width: 132px; height: 132px; position: relative; border-radius: 28px; background: var(--bg-2); border: 1px solid var(--line-2); display: grid; place-items: center; transition: box-shadow .25s, border-color .25s; }
.face-wrap.speaking { border-color: color-mix(in srgb, var(--acc) 55%, transparent); box-shadow: 0 0 0 4px var(--acc-dim), 0 0 50px -12px var(--acc-glow); }
.face-wrap.listening { border-color: color-mix(in srgb, var(--acc-2) 55%, transparent); box-shadow: 0 0 0 4px var(--acc2-dim), 0 0 50px -12px rgba(255,106,44,.35); }
.face-wrap svg { width: 104px; height: 104px; }
.face { display: none; }
.face.show { display: block; }
.face .mouth { transform-origin: center; transition: transform .04s linear; }
.face .eyelid { transform-origin: center top; animation: blink 5.2s infinite; }
@keyframes blink { 0%,96%,100% { transform: scaleY(0); } 98% { transform: scaleY(1); } }

.voice-state { font-family: var(--font-mono); font-size: 11.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); display: inline-flex; align-items: center; gap: 8px; min-height: 16px; }
.voice-state .vd { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.voice-state.speaking { color: var(--acc); }
.voice-state.speaking .vd { background: var(--acc); animation: vpulse 1s infinite; }
.voice-state.listening { color: var(--acc-2); }
.voice-state.listening .vd { background: var(--acc-2); animation: vpulse .8s infinite; }
@keyframes vpulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.avatar-actions { display: flex; gap: 10px; }
.av-btn { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; border: 1px solid var(--line-2); border-radius: 100px; padding: 9px 16px; color: var(--ink); transition: .15s; }
.av-btn:hover { border-color: var(--acc); }
.av-btn.talk.on { background: var(--acc-2); border-color: var(--acc-2); color: #1a0a02; }
.av-btn svg { width: 15px; height: 15px; }

/* ---- mic button (composer) ----------------------------- */
.mic-btn {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  border: 1px solid var(--line-2); color: var(--ink-2);
  display: grid; place-items: center; transition: .15s; align-self: flex-end;
}
.mic-btn:hover { color: var(--ink); border-color: var(--ink-3); }
.mic-btn svg { width: 18px; height: 18px; }
.mic-btn.listening { background: #ff3b30; border-color: #ff3b30; color: #fff; animation: micpulse 1.2s infinite; }
.mic-btn.disabled { opacity: .35; cursor: not-allowed; }
@keyframes micpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,59,48,.5); } 50% { box-shadow: 0 0 0 9px rgba(255,59,48,0); } }

/* per-message speaker button */
.cmsg.ai .content { position: relative; }
.spk {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
  font-size: 12px; font-family: var(--font-mono); color: var(--ink-3);
  border: 1px solid var(--line); border-radius: 100px; padding: 5px 11px; transition: .15s;
}
.spk:hover { color: var(--acc); border-color: color-mix(in srgb, var(--acc) 40%, transparent); }
.spk.playing { color: var(--acc); border-color: var(--acc); }
.spk svg { width: 13px; height: 13px; }

/* scrollbar */
.chat-scroll::-webkit-scrollbar { width: 10px; }
.chat-scroll::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 100px; border: 3px solid var(--bg); }
.chat-scroll::-webkit-scrollbar-thumb:hover { background: #2a2a30; }
