/*
  💬 Help: the help chat's button and panel (web/help.js, DESIGN.md "Phase 8: 💬 Help chat").
  choreboy.css's tokens and components (.chip, .btn, .input), 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.

  WIRING: web/index.html loads it after work.css: <link rel="stylesheet" href="help.css">.
  (help.js's header has the rest.)
*/

/* The "💬 Help" chip in the top bar, before the 👤 account chip. */
.help-btn { position: relative; gap: .3rem; }
.help-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
/* An answer arrived while the panel was closed. */
.help-btn.has-new::after { content: ''; position: absolute; top: -2px; right: -2px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }

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

.help-panel {
  position: fixed; z-index: 360; /* over the task editor (300) and the account menu (330); under the toast (400) */
  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);
  animation: help-in .2s ease-out;
}
@keyframes help-in { from { opacity: 0; transform: translateX(1.25rem); } to { opacity: 1; transform: none; } }
/* A dialog open under it (the task 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-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 screens: 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: confirm your email first, 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.verify { background: var(--info-soft); color: var(--info); }
.help-note.busy { background: var(--warn-soft); color: var(--warn); }
.help-note.bad { background: var(--bad-soft); color: var(--bad); }

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

.help-form { display: flex; gap: .5rem; align-items: flex-end; padding: .7rem .75rem .4rem; border-top: 1px solid var(--border); flex-shrink: 0; }
.input.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-btn, body.logged-out .help-panel { display: none !important; }

/* ---------- 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);
    animation-name: help-up;
  }
  body.help-open { overflow: hidden; }
  .help-msg { max-width: 92%; }
  .input.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-btn-label { display: none; }
}
@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; }
  .help-dots i, .help-caret { animation: none; }
  .help-sugg-btn, .help-go, .help-follow-btn { transition: none; }
}
@media print {
  #help-btn, .help-panel { display: none !important; }
}
