/* Help & Tool Finder — left-edge launcher + slide-in panel.
   Deterministic (no-LLM) finder backed by /api/chat-rules.php.
   Brand: crimson #8b2942, gold #c9a227. No italics anywhere. */

.htf {
  --htf-crimson: #8b2942;
  --htf-crimson-dark: #6f1f35;
  --htf-gold: #c9a227;
  --htf-ink: #1f2733;
  --htf-muted: #5c6570;
  --htf-line: #e2e6ea;
  --htf-bot-bg: #fbf3df;
  font-family: var(--font, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif);
}

/* ---- Launcher (left, lower-middle) ---- */
.htf__launcher {
  position: fixed;
  left: 0;
  top: 75%;
  transform: translateY(-50%);
  z-index: 1200;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0.6rem 0.95rem 0.6rem 0.7rem;
  border: 1px solid var(--htf-gold);
  border-left: 0;
  border-top-right-radius: 999px;
  border-bottom-right-radius: 999px;
  background: linear-gradient(135deg, var(--htf-crimson) 0%, var(--htf-crimson-dark) 100%);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
  transition: padding 0.15s ease, transform 0.15s ease;
}
.htf__launcher:hover { transform: translateY(-50%) translateX(2px); }
/* The help "?" icon — drawn in white so it reads on the crimson launcher. */
.htf__launcher-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  display: block;
  color: #fff;
}
.htf__launcher-icon svg { width: 100%; height: 100%; display: block; }
.htf__launcher-text { white-space: nowrap; }
.htf.is-open .htf__launcher,
.htf__launcher.is-hidden { display: none; }

/* ---- Panel ---- */
.htf__panel {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 1201;
  display: none;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 32px);
  background: #fff;
  border: 1px solid var(--htf-line);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}
.htf.is-open .htf__panel {
  display: flex;
  animation: htf-rise 0.18s ease;
}
@keyframes htf-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Header ---- */
.htf__head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 0.9rem;
  background: linear-gradient(135deg, var(--htf-crimson) 0%, var(--htf-crimson-dark) 100%);
  color: #fff;
  border-bottom: 2px solid var(--htf-gold);
}
.htf__avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  display: grid;
  place-items: center;
}
.htf__avatar svg { width: 22px; height: 22px; display: block; }
.htf__head-meta { flex: 1 1 auto; min-width: 0; }
.htf__title { margin: 0; font-size: 0.98rem; font-weight: 700; line-height: 1.2; }
.htf__sub { margin: 0; font-size: 0.76rem; color: rgba(255, 255, 255, 0.85); }
.htf__close {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.htf__close:hover { background: rgba(255, 255, 255, 0.28); }

/* ---- Body / messages ---- */
.htf__body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.9rem;
  background: #f8f9fb;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  -webkit-overflow-scrolling: touch;
}
.htf-msg {
  max-width: 88%;
  padding: 0.55rem 0.75rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-wrap: break-word;
}
.htf-msg--bot {
  align-self: flex-start;
  background: var(--htf-bot-bg);
  border: 1px solid var(--htf-line);
  color: var(--htf-ink);
  border-bottom-left-radius: 4px;
}
.htf-msg--user {
  align-self: flex-end;
  background: var(--htf-crimson);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

/* ---- Link cards ---- */
.htf-links { display: flex; flex-direction: column; gap: 0.45rem; margin-top: 0.55rem; }
.htf-link {
  display: block;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--htf-line);
  border-radius: 11px;
  padding: 0.5rem 0.65rem;
  background: #fff;
  transition: border-color 0.15s ease, transform 0.05s ease;
}
.htf-link:hover { border-color: var(--htf-crimson); }
.htf-link:active { transform: scale(0.99); }
.htf-link__title {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--htf-crimson);
}
.htf-link__title::after { content: "\2192"; margin-left: auto; opacity: 0.5; }
.htf-link__text { font-size: 0.8rem; color: var(--htf-muted); margin-top: 0.15rem; line-height: 1.4; }

/* ---- Quick-reply chips ---- */
.htf-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.55rem; }
.htf-chip {
  border: 1px solid var(--htf-crimson);
  color: var(--htf-crimson);
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  line-height: 1.2;
}
.htf-chip:hover { background: var(--htf-crimson); color: #fff; }

/* ---- Typing dots ---- */
.htf-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 0.55rem 0.7rem;
  background: var(--htf-bot-bg);
  border: 1px solid var(--htf-line);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.htf-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--htf-crimson);
  opacity: 0.4;
  animation: htf-blink 1.2s infinite both;
}
.htf-typing span:nth-child(2) { animation-delay: 0.2s; }
.htf-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes htf-blink {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* ---- Footer / composer ---- */
.htf__foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--htf-line);
  background: #fff;
  padding: 0.6rem;
}
.htf__row { display: flex; gap: 0.5rem; align-items: flex-end; }
.htf__input {
  flex: 1 1 auto;
  resize: none;
  min-height: 2.75rem;
  max-height: 7rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--htf-line);
  border-radius: 10px;
  font: inherit;
  /* 16px stops iOS Safari from auto-zooming on focus. */
  font-size: 16px;
  line-height: 1.35;
  color: var(--htf-ink);
  outline: none;
}
.htf__input:focus { border-color: var(--htf-crimson); }
.htf__send {
  flex: 0 0 auto;
  height: 2.75rem;
  min-width: 2.75rem;
  padding: 0 0.9rem;
  border: 0;
  border-radius: 10px;
  background: var(--htf-crimson);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
.htf__send:hover { background: var(--htf-crimson-dark); }
.htf__send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Mobile: full-screen panel ---- */
@media (max-width: 480px) {
  .htf__panel {
    left: 0;
    top: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    border: 0;
  }
  .htf__launcher-text { display: none; }
  .htf__launcher { padding: 0.7rem; }
  html.htf-open,
  html.htf-open body { overflow: hidden; height: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .htf.is-open .htf__panel { animation: none; }
  .htf-typing span { animation: none; }
}
