/*
  💬 Help: the help chat's floating button and panel (web/help.js), ChefBoy's help.css on app.css's
  tokens and components (.chip, .btn), so light and dark follow the device. From 760 px wide the
  panel is a side sheet on the right (the page stays usable beside it); below that it's the whole
  screen. Responsive to 320 px.
*/

/*
  The "💬 Help" button, floating at the bottom right like DressBoy's: a round pill in the accent colour,
  clear of the notch and the home bar (safe area). There is no bottom bar. Over the page and the top
  bar (30). Hidden while ☰ is open (body.nav-open), not under it: the ☰ panel lives inside the top bar's
  stacking context at every width (on a computer at z-index -1, so it slides in "below the top nav/under it",
  Jared, 2026-11-23: navmenu.css), so it and its dim sit at the bar's 30, and at 45 the button would float
  undimmed over the dim, looking live while navmenu.js drops its click (a press off the panel only closes
  it). Under a box (60), the menus (70), the panel (72) and the toast (80).
  It steps out of the way while something else is up: a box or our OK / Cancel box, the 👤 menu or ☰,
  setup (its top-bar tools are hidden too: onboard.css), the panel itself, and logged out.
*/
.help-fab {
  position: fixed; z-index: 45;
  right: calc(1.1rem + env(safe-area-inset-right));
  bottom: calc(1.1rem + env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: .35rem; min-height: 2.75rem; padding: .65rem 1rem;
  font: 650 .9rem/1 var(--font); color: var(--accent-contrast); background: var(--accent);
  border: 0; border-radius: 999px; box-shadow: 0 6px 18px rgba(16, 24, 40, .22); cursor: pointer;
  transition: transform .12s ease-out, filter .12s;
}
.help-fab:hover { filter: brightness(1.08); }
.help-fab:active { transform: scale(.96); }
.help-fab:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 3px; }
@media (prefers-color-scheme: dark) { .help-fab { box-shadow: 0 6px 18px rgba(0, 0, 0, .5); } }
/* An answer arrived while the panel was closed: a dot on the button. */
.help-fab.has-new::after { content: ''; position: absolute; top: -2px; right: -2px; width: 11px; height: 11px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 2px var(--bg); }
/* ✨ An answer that finished while the chat was closed: its dot pops in once (✨ Full only; no pulse that goes on,
   and Subtle, Off and reduced motion just show it). Transform and opacity only, on the dot itself. */
html[data-fx="full"] .help-fab.has-new::after { animation: help-dot-in .4s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes help-dot-in { from { opacity: 0; transform: scale(.2); } to { opacity: 1; transform: none; } }
/* 👆 A press on a touch screen: the suggestion and follow-up chips give a little (✨ Full: the separate `scale`, as
   fx.css does, so it never fights a transform), and only tint at Subtle. */
@media (hover: none) {
  html[data-fx="full"] .help-sugg-btn, html[data-fx="full"] .help-follow-btn { transition: scale .09s ease-out, border-color .12s, background .12s; }
  html[data-fx="full"] .help-sugg-btn:active, html[data-fx="full"] .help-follow-btn:active { scale: .98; }
  html[data-fx="subtle"] .help-sugg-btn:active, html[data-fx="subtle"] .help-follow-btn:active { background: var(--accent-soft); }
}
body.logged-out .help-fab, body.in-setup .help-fab, body.help-open .help-fab, body.modal-open .help-fab, body.nav-open .help-fab,
body:has(> .menu) .help-fab, body:has(> .dlg-layer) .help-fab { display: none; }
/* Room for it: the page's last row scrolls clear of it. */
body:not(.logged-out):not(.in-setup) .view { padding-bottom: calc(4.75rem + env(safe-area-inset-bottom)); }
/* A phone: the toast (with its ↶ Undo) and the 🔁 next-charge card sit above the button, not across it. */
@media (max-width: 720px) {
  body:not(.in-setup):not(.logged-out) .toast { bottom: calc(4.6rem + env(safe-area-inset-bottom)); }
  body:not(.in-setup):not(.logged-out) .spawned { bottom: calc(8rem + env(safe-area-inset-bottom)); }
}

/* ---------- the panel: a side sheet ---------- */

.help-panel {
  position: fixed; z-index: 72; /* over a box (60) and the menus (70); under the toast (80) and our OK / Cancel box (90) */
  top: .75rem; right: .75rem; bottom: .75rem; width: min(440px, calc(100vw - 1.5rem));
  display: flex; flex-direction: column;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  overflow: hidden; font: 15px/1.45 var(--font);
}
html[data-fx="full"] .help-panel { animation: help-in .2s ease-out; }
html[data-fx="subtle"] .help-panel { animation: help-fade .15s ease-out; }
@keyframes help-in { from { opacity: 0; transform: translateX(1.25rem); } to { opacity: 1; transform: none; } }
@keyframes help-fade { from { opacity: 0; } to { opacity: 1; } }
/* A box open under it (an editor) moves left to stay clear of it on wide screens. */
@media (min-width: 1100px) {
  body.help-open .modal { padding-right: calc(min(440px, 100vw) + 1.75rem); }
}

.help-head { display: flex; align-items: center; gap: .4rem; padding: .7rem .7rem .7rem 1rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.help-title { flex: 1; min-width: 0; margin: 0; font-size: 1.02rem; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.help-title:focus { outline: none; }
.help-new:disabled { visibility: hidden; }
.help-x { flex-shrink: 0; width: 2.1rem; height: 2.1rem; display: grid; place-items: center; padding: 0; border: 0; border-radius: 999px; background: none; color: var(--text-2); font: 600 1rem var(--font); cursor: pointer; }
.help-x:hover { background: var(--surface-2); color: var(--text); }

/* ---------- the conversation ---------- */

.help-log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 1rem; display: flex; flex-direction: column; gap: .65rem; }
.help-log:focus { outline: none; }

/* Before the first question: hello, and questions to start with. */
.help-hi { display: flex; flex-direction: column; gap: .75rem; }
.help-hi-text { margin: 0; color: var(--text-2); }
.help-sugg-h { margin: .25rem 0 0; font-size: .74rem; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.help-sugg { display: flex; flex-direction: column; gap: .4rem; }
.help-tour { margin-top: .8rem; align-self: flex-start; } /* 🎓 "Show me around" (tour.js), under the suggestions */
.help-sugg-btn { display: flex; align-items: flex-start; gap: .55rem; width: 100%; padding: .6rem .75rem; text-align: left; font: 550 .9rem/1.35 var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: border-color .12s, background .12s; }
.help-sugg-btn > span:first-child { flex-shrink: 0; opacity: .7; }
.help-sugg-btn:hover { border-color: var(--accent); background: var(--accent-soft); }

/* Messages. White space is kept (an answer's lines and lists), so help.js puts nothing between the tags. */
.help-msg { max-width: 88%; padding: .6rem .8rem; border-radius: 14px; font-size: .93rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.help-msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-contrast); border-bottom-right-radius: 4px; }
.help-msg.bot { align-self: flex-start; background: var(--surface-2); color: var(--text); border-bottom-left-radius: 4px; }
.help-msg b { font-weight: 700; }
/* An answer's go-there buttons (a fixed list of places: help.js) and the follow-up questions under it. */
.help-go { display: inline-flex; align-items: center; gap: .1rem; margin: .1rem 0; padding: .18rem .6rem; vertical-align: baseline; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; font: 650 .86rem/1.35 var(--font); color: var(--accent-text); background: var(--accent-soft); border: 1px solid transparent; border-radius: 999px; cursor: pointer; transition: border-color .12s, background .12s; }
.help-go:hover { border-color: var(--accent); }
.help-go:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.help-follow { align-self: flex-start; display: flex; flex-wrap: wrap; gap: .4rem; max-width: 100%; margin-top: -.2rem; }
.help-follow-btn { display: inline-flex; align-items: flex-start; gap: .4rem; max-width: 100%; padding: .38rem .7rem; text-align: left; font: 550 .84rem/1.3 var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; cursor: pointer; transition: border-color .12s, background .12s; overflow-wrap: anywhere; }
.help-follow-btn > span:first-child { flex-shrink: 0; opacity: .7; }
.help-follow-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
/* While it's written: a blinking caret after the text, or three dots before any arrives. */
.help-caret { display: inline-block; width: .5em; height: 1.05em; margin-left: 1px; vertical-align: -.15em; border-radius: 1px; background: var(--accent); animation: help-blink 1s steps(1) infinite; }
@keyframes help-blink { 50% { opacity: 0; } }
.help-dots { display: inline-flex; gap: 4px; padding: .3rem 0; }
.help-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: help-dot 1s infinite ease-in-out; }
.help-dots i:nth-child(2) { animation-delay: .15s; }
.help-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes help-dot { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* The API said no: today's limit or busy, or a problem. */
.help-note { display: flex; gap: .6rem; align-items: flex-start; padding: .7rem .85rem; border-radius: var(--radius); font-size: .88rem; line-height: 1.45; overflow-wrap: anywhere; }
.help-note b { font-weight: 700; }
.help-note-ico { flex-shrink: 0; line-height: 1.3; }
.help-note.busy { background: var(--warn-soft); color: var(--warn); }
.help-note.bad { background: var(--bad-soft); color: var(--bad-text); }

/* ---------- asking ---------- */

.help-form { display: flex; gap: .5rem; align-items: flex-end; padding: .7rem .75rem .4rem; border-top: 1px solid var(--border); flex-shrink: 0; }
textarea.help-q { flex: 1; resize: none; min-height: 2.6rem; max-height: 9rem; overflow-y: auto; line-height: 1.4; }
.help-send { flex-shrink: 0; min-height: 2.6rem; }
.help-foot { margin: 0; padding: 0 .9rem .75rem; font-size: .72rem; line-height: 1.4; color: var(--text-3); flex-shrink: 0; }
.help-keys { white-space: nowrap; }
@media (hover: none) { .help-keys { display: none; } } /* touch keyboards: the Send key */

/* Read by screen readers only. */
.help-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }

body.logged-out .help-fab, body.logged-out .help-panel { display: none !important; }
/* (Setup is a screen of its own: the button waits until it's done; the last card points at it.) */

/* ---------- phones: the whole screen ---------- */

@media (max-width: 759px) {
  .help-panel {
    /* help.js sets --help-vh / --help-top from the visible part of the screen (the keyboard takes the rest) */
    top: var(--help-top, 0); left: 0; right: 0; bottom: auto; width: 100%; height: var(--help-vh, 100%);
    border: 0; border-radius: 0; box-shadow: none;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  html[data-fx="full"] .help-panel { animation-name: help-up; }
  body.help-open { overflow: hidden; }
  .help-msg { max-width: 92%; }
  textarea.help-q { font-size: 16px; } /* smaller and iPhones zoom the page on focus */
}
@keyframes help-up { from { opacity: 0; transform: translateY(1rem); } to { opacity: 1; transform: none; } }
@media (max-width: 600px) {
  .help-fab { right: calc(.8rem + env(safe-area-inset-right)); bottom: calc(.8rem + env(safe-area-inset-bottom)); }
}
@media (max-width: 380px) {
  .help-head { padding-left: .8rem; }
  .help-log { padding: .8rem; }
  .help-form { padding-left: .6rem; padding-right: .6rem; }
  .help-foot { padding-left: .7rem; padding-right: .7rem; }
}

@media (prefers-reduced-motion: reduce) {
  .help-panel { animation: none !important; }
  .help-dots i, .help-caret { animation: none; }
  .help-sugg-btn, .help-go, .help-follow-btn, .help-fab { transition: none; }
  .help-fab:active { transform: none; }
  .help-fab.has-new::after { animation: none !important; }
  .help-sugg-btn:active, .help-follow-btn:active { scale: none !important; }
}
@media print {
  .help-fab, .help-panel { display: none !important; }
}
