/* ===========================================================================
 * help.css — R290 (W8/U22 P0) — canonical tooltip + help drawer + (?) icon
 * styles. Loaded by kit/index.html AFTER pages.css so its rules win at equal
 * specificity. Mirrors the kit's existing design tokens (var(--fg-1),
 * --bg-app/--bg-surface/--bg-sunken, --border-1, --dnuv-blue-dark, --space-N,
 * --fs-N, --fw-N, --ease-standard). Dark mode flips automatically because all
 * surfaces read real theme tokens (no hardcoded #fff backgrounds, no phantom
 * --bg-1/--fg-0 — those were undefined and pinned the help UI to light).
 *
 * Provides:
 *   .dnuv-tooltip       — portaled tooltip element (created by _tooltip.js)
 *   .ctx-help           — small (?) icon button next to form labels
 *   .help-drawer        — full-height right-side drawer (Help search UI)
 *   .help-page          — full-width article page (route /help)
 *   .help-empty-link    — "Saiba como funciona" link inside empty states
 *
 * Mobile: .help-drawer goes full-screen below 720px; tooltips become inline
 * expandable text on touch devices via JS (no purely-CSS fallback needed
 * because _tooltip.js detects touch and switches to tap-toggle).
 * ============================================================================ */

/* ---------- Tooltip ---------- */
.dnuv-tooltip {
  position: absolute;
  z-index: 1100; /* above modal-backdrop (100) and help-fab (1000) but below toast (1200) */
  max-width: 320px;
  min-width: 60px;
  padding: 8px 10px;
  background: var(--fg-1, #0a1f5e);
  color: #fff;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(10, 31, 94, 0.18), 0 2px 6px rgba(10, 31, 94, 0.10);
  font-family: var(--font-sans, inherit);
  font-size: var(--fs-sm, 12px);
  line-height: 1.4;
  letter-spacing: -0.005em;
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 120ms var(--ease-standard, ease-out), transform 120ms var(--ease-standard, ease-out);
  left: -9999px;
  top: -9999px;
}
.dnuv-tooltip.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.dnuv-tooltip-body {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
}
.dnuv-tooltip-learn {
  display: inline-block;
  margin-top: 6px;
  font-size: var(--fs-xs, 11px);
  font-weight: var(--fw-600, 600);
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.dnuv-tooltip-learn:hover { color: #e6f0ff; }

/* Tail (arrow). 6px equilateral pointing toward the trigger. */
.dnuv-tooltip::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
}
.dnuv-tooltip[data-placement="top"]::after {
  bottom: -6px;
  border-top: 6px solid var(--fg-1, #0a1f5e);
}
.dnuv-tooltip[data-placement="bottom"]::after {
  top: -6px;
  border-bottom: 6px solid var(--fg-1, #0a1f5e);
}

/* Dark-mode contrast — tooltip stays dark, but uses the kit's surface-fg pair.
 * R391 (Wave-F help): `--fg-0` was a phantom token (never defined in
 * colors_and_type.css) so this fell to the literal fallback. Use the real
 * heading foreground `--fg-1` (light on dark in this block). */
[data-theme="dark"] .dnuv-tooltip {
  background: var(--bg-elevated, #1a2540);
  color: var(--fg-1, #e6ebf5);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
[data-theme="dark"] .dnuv-tooltip[data-placement="top"]::after { border-top-color: var(--bg-elevated, #1a2540); }
[data-theme="dark"] .dnuv-tooltip[data-placement="bottom"]::after { border-bottom-color: var(--bg-elevated, #1a2540); }

/* ---------- Contextual help (?) icon ---------- */
/*
 * Used as: <button class="ctx-help" type="button" aria-label="Sobre stream URL"
 *           data-tooltip="..." data-help-href="/help/troubleshoot-camera">
 *           <i data-lucide="circle-help"></i>
 *         </button>
 * Placed inside a <label> after the visible text. WCAG 1.4.11 — 3:1 contrast
 * is met against bg-1 by using --fg-3 (mid-tone neutral).
 */
.ctx-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--fg-3, #5b6478);
  border-radius: 50%;
  cursor: help;
  vertical-align: middle;
  transition: color 120ms, background 120ms;
}
.ctx-help i { width: 14px; height: 14px; }
.ctx-help:hover { color: var(--dnuv-blue-dark, #0a1f5e); background: rgba(10, 31, 94, 0.06); }
.ctx-help:focus-visible {
  outline: 2px solid var(--dnuv-blue-dark, #0a1f5e);
  outline-offset: 2px;
}

/* ---------- Help page (route /help) ---------- */
.help-page {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--space-6, 24px);
  padding: var(--space-6, 24px);
  min-height: calc(100vh - var(--topbar-h, 56px));
  /* R391 (Wave-F help): `--bg-1` was a phantom token → page was stuck on the
   * light literal. Use the real app-background token so dark mode applies. */
  background: var(--bg-app, #fafbfd);
}
.help-page-sidebar {
  /* R391: hardcoded #fff → real surface token so the sidebar flips in dark. */
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border-1, #e3e7ee);
  border-radius: 10px;
  padding: var(--space-4, 16px);
  height: max-content;
  position: sticky;
  top: var(--space-4, 16px);
}
.help-page-sidebar h3 {
  margin: 0 0 var(--space-3, 12px);
  font-size: var(--fs-small, 13px);
  font-weight: var(--fw-700, 700);
  color: var(--fg-1, #0a1f5e);
  letter-spacing: -0.005em;
}
.help-topic-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.help-topic-list a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: var(--fs-sm, 13px);
  color: var(--fg-2, #2b3344);
  text-decoration: none;
  transition: background 120ms, color 120ms;
}
.help-topic-list a:hover { background: var(--bg-sunken, #f3f5f8); color: var(--dnuv-blue-dark, #0a1f5e); }
.help-topic-list a.active {
  background: var(--dnuv-blue-dark, #0a1f5e);
  color: #fff;
  font-weight: var(--fw-600, 600);
}

.help-article {
  /* R391: hardcoded #fff → real surface token so the article flips in dark. */
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border-1, #e3e7ee);
  border-radius: 10px;
  padding: var(--space-6, 24px) var(--space-7, 32px);
  max-width: 820px;
}
.help-article h1 {
  margin: 0 0 var(--space-2, 8px);
  font-size: var(--fs-xxl, 28px);
  font-weight: var(--fw-700, 700);
  color: var(--fg-1, #0a1f5e);
  letter-spacing: -0.015em;
}
.help-article .help-meta {
  font-size: var(--fs-sm, 13px);
  color: var(--fg-4, #6c7689);
  margin-bottom: var(--space-5, 20px);
  padding-bottom: var(--space-3, 12px);
  border-bottom: 1px solid var(--border-1, #e3e7ee);
}
.help-article h2 {
  margin: var(--space-6, 24px) 0 var(--space-3, 12px);
  font-size: var(--fs-lg, 18px);
  font-weight: var(--fw-700, 700);
  color: var(--fg-1, #0a1f5e);
}
.help-article h3 {
  margin: var(--space-5, 20px) 0 var(--space-2, 8px);
  font-size: var(--fs-base, 15px);
  font-weight: var(--fw-700, 700);
  color: var(--fg-1, #0a1f5e);
}
.help-article p,
.help-article li {
  font-size: var(--fs-base, 15px);
  line-height: 1.6;
  color: var(--fg-2, #2b3344);
  margin: 0 0 var(--space-3, 12px);
}
.help-article ul,
.help-article ol {
  padding-left: var(--space-5, 20px);
  margin: 0 0 var(--space-4, 16px);
}
.help-article code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.92em;
  background: var(--bg-sunken, #f3f5f8);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--fg-1, #0a1f5e);
}
.help-article pre {
  background: var(--bg-sunken, #f3f5f8);
  border: 1px solid var(--border-1, #e3e7ee);
  border-radius: 8px;
  padding: var(--space-3, 12px);
  overflow-x: auto;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--fs-sm, 13px);
  line-height: 1.5;
}
.help-article a {
  color: var(--dnuv-blue-dark, #0a1f5e);
  text-decoration: underline;
  text-underline-offset: 2px;
}
/* R437 (B2, R1/R2): the stub was top-anchored (padding only), leaving a tall
   blank below it inside the article panel. Center it as a vertical stack that
   fills a comfortable slice of the panel so the mark+copy sit in the optical
   centre. `letter-spacing:-0.01em` tightens the loose default tracking the
   audit flagged on the heading ("Bem - vindo"). */
.help-article-stub {
  padding: var(--space-7, 32px);
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--fg-4, #6c7689);
  letter-spacing: -0.01em;
}
.help-article-stub .help-stub-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-3, 12px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-sunken, #f3f5f8);
  border-radius: 50%;
  color: var(--fg-3, #5b6478);
}

/* ---------- Help drawer (FAB-opened) ---------- */
.help-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 31, 94, 0.20);
  z-index: 1090;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms var(--ease-standard, ease-out);
}
.help-drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.help-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  max-width: 100vw;
  height: 100vh;
  /* R391: hardcoded #fff → real surface token so the FAB drawer flips in dark. */
  background: var(--bg-surface, #fff);
  border-left: 1px solid var(--border-1, #e3e7ee);
  box-shadow: -8px 0 32px rgba(10, 31, 94, 0.12);
  z-index: 1100;
  transform: translateX(100%);
  transition: transform 200ms var(--ease-standard, ease-out);
  display: flex;
  flex-direction: column;
}
.help-drawer.open { transform: none; }
.help-drawer-head {
  padding: var(--space-4, 16px) var(--space-4, 16px) var(--space-3, 12px);
  border-bottom: 1px solid var(--border-1, #e3e7ee);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3, 12px);
}
.help-drawer-head h2 {
  margin: 0;
  font-size: var(--fs-small, 13px);
  font-weight: var(--fw-700, 700);
  color: var(--fg-1, #0a1f5e);
  letter-spacing: -0.005em;
}
.help-drawer-close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--fg-3, #5b6478);
  cursor: pointer;
  font-size: var(--fs-xl, 20px);
  line-height: 1;
}
.help-drawer-close:hover { background: var(--bg-sunken, #f3f5f8); color: var(--fg-1, #0a1f5e); }

.help-drawer-search {
  padding: var(--space-3, 12px) var(--space-4, 16px);
  border-bottom: 1px solid var(--border-1, #e3e7ee);
}
.help-drawer-search input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-2, #d3d8e1);
  border-radius: 6px;
  font-family: inherit;
  font-size: var(--fs-sm, 13px);
}
.help-drawer-search input:focus {
  outline: 2px solid var(--dnuv-blue-dark, #0a1f5e);
  outline-offset: 1px;
  border-color: var(--dnuv-blue-dark, #0a1f5e);
}

.help-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3, 12px) var(--space-4, 16px) var(--space-4, 16px);
}
.help-drawer-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.help-drawer-list a {
  display: block;
  padding: 10px;
  border-radius: 6px;
  font-size: var(--fs-sm, 13px);
  color: var(--fg-2, #2b3344);
  text-decoration: none;
  border: 1px solid transparent;
}
.help-drawer-list a:hover {
  background: var(--bg-sunken, #f3f5f8);
  border-color: var(--border-1, #e3e7ee);
}
.help-drawer-list .help-drawer-topic-t {
  display: block;
  font-weight: var(--fw-600, 600);
  color: var(--fg-1, #0a1f5e);
  margin-bottom: 2px;
}
.help-drawer-list .help-drawer-topic-s {
  display: block;
  font-size: var(--fs-xs, 11px);
  color: var(--fg-4, #6c7689);
  line-height: 1.4;
}
.help-drawer-empty {
  text-align: center;
  padding: var(--space-5, 20px);
  color: var(--fg-4, #6c7689);
  font-size: var(--fs-sm, 13px);
}

/* Green dot on FAB when new articles are available. */
.help-fab.has-new::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dnuv-success, #0fba81);
  /* R391: ring matches the FAB surface (was hardcoded #fff). */
  border: 2px solid var(--bg-surface, #fff);
  box-shadow: 0 0 0 1px rgba(15, 186, 129, 0.4);
}
.help-fab { position: relative; }

/* ---------- Help page header + search (R390 C4 followup) ----------
 * C0 shipped the .help-page grid + .help-article-stub but the C4 rework of
 * Help.js introduced a page-level <header class="page-head help-head"> holding
 * the <h1> and an in-page <form class="help-search">. .help-head only needs to
 * let the search form sit on the header baseline next to the title; the rest of
 * the header styling comes from the shared .page-head rule. */
.help-head {
  align-items: center;
  gap: var(--space-4, 16px);
  flex-wrap: wrap;
}
.help-search {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 1 1 240px;
  max-width: 360px;
  min-width: 0;
}
/* R437 (B2, R1): Lucide replaces the placeholder `<i data-lucide>` with a
   generated inline `<svg>` at boot, so the original `.help-search i` selector
   went dead and the magnifier rendered as static flow content OUTSIDE the
   input box. Match both the pre-hydration `<i>` and the post-hydration `<svg>`
   so the absolute positioning (and the left inset that pairs with the input's
   30px left padding) applies in either state. */
.help-search i,
.help-search svg {
  position: absolute;
  left: 10px;
  width: 14px;
  height: 14px;
  color: var(--fg-3, #5b6478);
  pointer-events: none;
}
.help-search input {
  width: 100%;
  min-width: 0;
  padding: 8px 10px 8px 30px;
  border: 1px solid var(--border-1, #e3e7ee);
  border-radius: var(--radius-2, 8px);
  /* R391: `--bg-1` was a phantom token → input stuck light. Use --bg-app. */
  background: var(--bg-app, #fafbfd);
  color: var(--fg-1, #0a1f5e);
  font-family: inherit;
  font-size: var(--fs-sm, 13px);
}
.help-search input::placeholder { color: var(--fg-4, #6c7689); }
.help-search input:focus-visible {
  outline: none;
  border-color: var(--dnuv-blue-dark, #0a1f5e);
  box-shadow: var(--ring-focus, 0 0 0 3px rgba(10, 31, 94, 0.18));
}

/* Sidebar topic groups (C4 a11y #5) — each group is a <div> wrapping an <h2>
 * and a .help-topic-list <ul>. Separated by space + a hairline rule. */
.help-topic-group + .help-topic-group {
  margin-top: var(--space-4, 16px);
  padding-top: var(--space-4, 16px);
  border-top: 1px solid var(--border-1, #e3e7ee);
}
.help-topic-group h2 {
  margin: 0 0 var(--space-2, 8px);
  font-size: var(--fs-xs, 11px);
  font-weight: var(--fw-700, 700);
  text-transform: uppercase;
  letter-spacing: var(--ls-wide, 0.04em);
  color: var(--fg-4, #6c7689);
}

/* Transient "Carregando…" placeholder inside the article column. */
.help-loading {
  padding: var(--space-6, 24px);
  text-align: center;
  color: var(--fg-4, #6c7689);
  font-size: var(--fs-base, 15px);
}

/* "Nenhum tópico corresponde…" message under the sidebar list (role=status,
 * toggled via [hidden] by __helpFilterTopics). */
.help-search-empty {
  margin: var(--space-3, 12px) 0 0;
  padding: var(--space-3, 12px);
  text-align: center;
  color: var(--fg-4, #6c7689);
  font-size: var(--fs-sm, 13px);
}
.help-search-empty[hidden] { display: none; }

/* Back / retry link paragraph under a stub or error state. */
.help-stub-back {
  margin: var(--space-4, 16px) 0 0;
  font-size: var(--fs-sm, 13px);
  color: var(--fg-3, #5b6478);
}
.help-stub-back a {
  color: var(--dnuv-blue-dark, #0a1f5e);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: var(--fw-600, 600);
}
.help-stub-back a:focus-visible {
  outline: none;
  border-radius: var(--radius-1, 4px);
  box-shadow: var(--ring-focus, 0 0 0 3px rgba(10, 31, 94, 0.18));
}

/* Recoverable article-load error (C4 a11y #7 + copy #3) — a danger-toned
 * variant of .help-article-stub. Tints the mark with the danger foreground so
 * it reads as an error, not the neutral "Em construção" stub. */
.help-article-error .help-stub-mark {
  background: var(--color-danger-bg, #fdecec);
  color: var(--color-danger-fg, #7a1518);
}

/* ---------- Empty-state docs link (U22-P1-9 fix) ---------- */
.help-empty-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: var(--space-3, 12px);
  font-size: var(--fs-sm, 13px);
  color: var(--dnuv-blue-dark, #0a1f5e);
  text-decoration: none;
  font-weight: var(--fw-600, 600);
}
.help-empty-link:hover { text-decoration: underline; text-underline-offset: 2px; }
.help-empty-link i { width: 12px; height: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .help-page {
    grid-template-columns: 1fr;
    padding: var(--space-3, 12px);
    gap: var(--space-3, 12px);
  }
  .help-page-sidebar {
    position: static;
  }
  .help-article {
    padding: var(--space-4, 16px);
  }
  .help-drawer {
    width: 100vw;
    border-left: none;
  }
  .dnuv-tooltip {
    max-width: calc(100vw - 24px);
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .dnuv-tooltip,
  .help-drawer,
  .help-drawer-backdrop {
    transition: none;
  }
}
