/* ═══════════════════════════════════════════════════════════════════════════
   docs.css — help hub + tutorial article styles
   ─────────────────────────────────────────────────────────────────────────
   Scoped entirely to /help.html and the rendered article pane. Pulls
   from shell.css's CSS custom properties so light/dark theme, accent
   color, and typography stay in sync with the rest of the app.

   Layout: fixed top bar + two-column shell (260px TOC + flex article).
   Typography: the article pane overrides shell.css body font sizing for
   readable long-form content without polluting any other page.
   ═══════════════════════════════════════════════════════════════════════════ */

/* NOTE: No global `body { … }` rule here. docs.css is now safe to
   include on non-hub pages that only need the <help-icon> + popup
   styles (e.g. nutrition.html). shell.css owns the body baseline;
   /help.html inherits it via its own <link> tag. */

/* ─── Top bar ─────────────────────────────────────────────────────── */

/* SPEC-DISC-2 R2e (owner, 2026-08-21) — the topbar's contents align with the
   PAGE CONTENT, not with the viewport edges. The bar itself still spans full
   width (its border and background are the frame); an inner rail carries the
   same max-width and horizontal padding as .hc (1180px / 22px) so the brand
   lands on the same left margin as the breadcrumb and the H1 beneath it. */
.docs-topbar {
  height: 56px; padding: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.docs-topbar-inner {
  display: flex; align-items: center; gap: 16px;
  height: 100%;
  max-width: 1180px; margin: 0 auto; padding: 0 22px;
}
.docs-brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none;
  font-weight: 700; font-size: 1rem; letter-spacing: -0.01em;
}
.docs-brand img { display: block; border-radius: 6px; }
.docs-brand-sub {
  color: var(--text-muted); font-weight: 500;
  margin-left: 2px;
}
.docs-search-wrap {
  display: flex; align-items: center; gap: 9px;
  flex: 1; max-width: 480px; min-width: 0;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px;
}
.docs-search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 116, 204, 0.18);
}
.docs-search-icon {
  flex: none; color: var(--text-muted);
  pointer-events: none;
}
.docs-search {
  width: 100%; height: 36px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 0 12px 0 36px;
  color: var(--text); font-family: inherit; font-size: 0.88rem;
}
.docs-search:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 116, 204, 0.18);
}
.docs-search[disabled] { opacity: 0.55; cursor: not-allowed; }
.docs-back-app {
  color: var(--text-muted); text-decoration: none;
  font-size: 0.82rem; font-weight: 500;
  white-space: nowrap;
}
.docs-back-app:hover { color: var(--accent); }

/* ─── Shell layout ────────────────────────────────────────────────── */

.docs-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 56px);
}

/* ─── TOC ─────────────────────────────────────────────────────────── */

.docs-toc {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  overflow-y: auto;
  /* Keep the sidebar visible while the article scrolls */
  position: sticky; top: 56px;
  max-height: calc(100vh - 56px);
}
.docs-toc-section { margin-bottom: 18px; }
.docs-toc-heading {
  font-size: 0.68rem; font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 6px 10px; margin-bottom: 2px;
}
.docs-toc ul {
  list-style: none; padding: 0; margin: 0;
}
.docs-toc li a {
  display: block; padding: 7px 10px;
  color: var(--text); text-decoration: none;
  border-radius: 7px;
  font-size: 0.88rem; line-height: 1.35;
  transition: background .12s, color .12s;
}
.docs-toc li a:hover { background: var(--surface2); }
.docs-toc li a.active {
  background: rgba(108, 116, 204, 0.14);
  color: var(--accent);
  font-weight: 600;
}
.docs-toc-loading,
.docs-toc-empty {
  padding: 10px 10px;
  font-size: 0.82rem; color: var(--text-muted);
  font-style: italic;
}

/* ─── Article pane ────────────────────────────────────────────────── */

.docs-article {
  padding: 32px 44px 80px;
  max-width: 820px;
  min-width: 0; /* Prevent overflow when long code lines render */
}

/* Welcome state before a topic is picked */
.docs-welcome { padding-top: 24px; }
.docs-welcome h1 {
  font-size: 2rem; font-weight: 700;
  letter-spacing: -0.02em; margin: 0 0 10px;
  color: var(--text);
}
.docs-lede {
  font-size: 1.05rem; line-height: 1.55;
  color: var(--text-muted); margin: 0 0 24px;
}
.docs-help-glyph {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 0.72rem; font-weight: 700;
  vertical-align: -4px;
}
.docs-welcome-hint {
  padding: 14px 18px;
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: 10px; color: var(--text-muted);
  font-size: 0.9rem; line-height: 1.5;
}

/* Error state (non-existent topic) */
.docs-error {
  padding: 28px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  text-align: center;
}
.docs-error h2 {
  font-size: 1.25rem; margin: 0 0 8px;
  color: var(--red);
}
.docs-error p {
  color: var(--text-muted); margin: 0 0 14px;
  font-size: 0.92rem; line-height: 1.5;
}
.docs-error-link {
  color: var(--accent); text-decoration: none;
  font-weight: 600;
}
.docs-error-link:hover { text-decoration: underline; }

/* ─── Article typography ──────────────────────────────────────────── */
/* Scoped to .docs-article-body so we don't leak styles into the welcome
   or error states, which have their own treatments above. */

.docs-article-meta {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 20px;
}
.docs-article-category {
  display: inline-block;
  padding: 2px 10px; border-radius: 999px;
  background: rgba(108, 116, 204, 0.14);
  color: var(--accent);
  font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.docs-article-tag {
  display: inline-block;
  padding: 2px 10px; border-radius: 999px;
  background: var(--surface2); color: var(--text-muted);
  font-size: 0.68rem; font-weight: 500;
  letter-spacing: 0.02em;
}

.docs-article-body h1 {
  font-size: 1.75rem; font-weight: 700;
  letter-spacing: -0.02em; line-height: 1.2;
  margin: 0 0 8px; color: var(--text);
}
.docs-article-body h2 {
  font-size: 1.25rem; font-weight: 700;
  letter-spacing: -0.01em; line-height: 1.3;
  margin: 28px 0 10px; color: var(--text);
  padding-top: 12px; border-top: 1px solid var(--border);
}
.docs-article-body h2:first-child {
  padding-top: 0; border-top: none; margin-top: 16px;
}
.docs-article-body h3 {
  font-size: 1.02rem; font-weight: 700;
  margin: 20px 0 8px; color: var(--text);
}
.docs-article-body p {
  font-size: 0.95rem; line-height: 1.62;
  color: var(--text); margin: 0 0 14px;
}
.docs-article-body ul,
.docs-article-body ol {
  padding-left: 22px; margin: 0 0 14px;
  font-size: 0.95rem; line-height: 1.62; color: var(--text);
}
.docs-article-body li { margin-bottom: 4px; }
.docs-article-body code {
  font-family: "SF Mono", "Monaco", "Menlo", ui-monospace, monospace;
  font-size: 0.86em;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px; color: var(--text);
}
.docs-article-body pre {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; overflow-x: auto;
  font-family: "SF Mono", "Monaco", "Menlo", ui-monospace, monospace;
  font-size: 0.84rem; line-height: 1.55;
  margin: 0 0 18px;
}
.docs-article-body pre code {
  background: none; border: none; padding: 0;
  font-size: inherit;
}
.docs-article-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 2px 14px; margin: 14px 0;
  color: var(--text-muted);
  background: rgba(108, 116, 204, 0.06);
  border-radius: 0 8px 8px 0;
}
.docs-article-body blockquote p:last-child { margin-bottom: 0; }
.docs-article-body a {
  color: var(--accent); text-decoration: none;
  border-bottom: 1px solid rgba(108, 116, 204, 0.35);
}
.docs-article-body a:hover { border-bottom-color: var(--accent); }
.docs-article-body hr {
  border: none; height: 1px; background: var(--border);
  margin: 26px 0;
}
.docs-article-body strong { color: var(--text); }

/* ─── Annotation callouts ─────────────────────────────────────────── */
/* Four flavors: note (default), tip, warn, step. Author invokes them
   via a markdown-friendly pattern the loader rewrites:
     > [!note] Body text
   OR authors can write raw HTML directly:
     <div class="docs-callout docs-callout-tip">…</div>
   Numbered step markers are for walk-throughs that reference a
   companion HTML snapshot. */

.docs-callout {
  display: flex; gap: 12px;
  padding: 12px 16px; margin: 16px 0;
  border-radius: 10px; border-left: 4px solid var(--accent);
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.docs-callout-icon {
  flex-shrink: 0; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.95rem; line-height: 1; margin-top: 1px;
  color: var(--accent);
}
.docs-callout-body {
  flex: 1; min-width: 0;
  font-size: 0.9rem; line-height: 1.55; color: var(--text);
}
.docs-callout-body > :first-child { margin-top: 0; }
.docs-callout-body > :last-child  { margin-bottom: 0; }

.docs-callout-tip    { border-left-color: var(--teal); }
.docs-callout-tip    .docs-callout-icon { color: var(--teal); }
.docs-callout-warn   { border-left-color: var(--gold); }
.docs-callout-warn   .docs-callout-icon { color: var(--gold); }
.docs-callout-danger { border-left-color: var(--red); }
.docs-callout-danger .docs-callout-icon { color: var(--red); }

.docs-step {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 14px 0; margin: 0;
}
.docs-step + .docs-step { border-top: 1px dashed var(--border); }
.docs-step-num {
  flex-shrink: 0; width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 0.82rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  margin-top: 1px;
}
.docs-step-body { flex: 1; min-width: 0; }

/* ─── Responsive ──────────────────────────────────────────────────── */

@media (max-width: 860px) {
  .docs-shell { grid-template-columns: 1fr; }
  .docs-toc {
    position: static; max-height: none;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .docs-article { padding: 24px 20px 60px; }
  .docs-back-app { display: none; }
}

/* Phones — the brand + search no longer fit on one 56px row (the long
   "Search guides, features, billing…" placeholder clipped past the right
   edge). Wrap the topbar and give the search its own full-width row. */
@media (max-width: 640px) {
  /* R2e — the flex rules moved with the flex container: .docs-topbar is now a
     plain full-width frame and .docs-topbar-inner is the row that wraps. */
  .docs-topbar { height: auto; }
  .docs-topbar-inner {
    flex-wrap: wrap; height: auto;
    padding: 10px 16px; row-gap: 10px; column-gap: 12px;
  }
  .docs-search-wrap { order: 3; flex-basis: 100%; max-width: none; }
}

/* ═══════════════════════════════════════════════════════════════════════
   <help-icon> custom element — the "?" glyph embedded alongside app UI
   ─────────────────────────────────────────────────────────────────────
   Intentionally small and muted so it never competes visually with the
   primary content next to it. Hover / focus bump it to accent purple so
   the affordance is clear.
   ═══════════════════════════════════════════════════════════════════════ */

help-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; box-sizing: border-box;
  border-radius: 50%;
  /* Default: subtle purple tint + accent-colored outline + accent glyph.
     ~8% accent over the underlying surface, not a solid accent fill —
     reads as "gray with a purple hint" rather than "button." Border at
     1.5px so the outline is visible against both page-body and card
     backgrounds without dominating. */
  background: rgba(108, 116, 204, 0.08);
  color: var(--accent);
  border: 1.5px solid var(--accent);
  font-family: inherit;
  font-size: 0.7rem; font-weight: 700; line-height: 1;
  cursor: pointer;
  user-select: none;
  vertical-align: middle;
  margin: 0 2px 0 6px;
  transition: background .15s ease, color .15s ease,
              border-color .15s ease, box-shadow .15s ease,
              transform .05s;
}
help-icon::before { content: "?"; }
/* Hover — solid accent fill, white glyph. */
help-icon:hover {
  background: var(--accent);
  color: #fff;
}
/* Keyboard focus — fill matches hover AND a ring is drawn so keyboard
   users can distinguish it from a mouse hover. :focus-visible gates the
   ring so clicks don't leave a stuck ring on the icon. */
help-icon:focus { outline: none; }
help-icon:focus-visible {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(108, 116, 204, 0.35);
}
/* Active/pressed — same fill, ~10% darker. The app doesn't define a
   --accent-pressed variable, so the value is the computed darker shade
   of --accent (#4c5199 → #3d417a). Update in tandem if --accent moves. */
help-icon:active {
  background: #3d417a;
  border-color: #3d417a;
  color: #fff;
  transform: scale(0.96);
}

/* ═══════════════════════════════════════════════════════════════════════
   HelpIcon popup — floating card anchored to a <help-icon>
   ─────────────────────────────────────────────────────────────────────
   Three-region layout: header (eyebrow + title + close), body (iconed
   outline rows), footer (primary CTA). Fixed-positioned via JS (see
   help-icon.js positionPopup); CSS owns visuals only.

   Design tokens reused from shell.css:
     --surface       — card background (white on light, dark panel on dark)
     --border        — divider + outline border
     --text          — primary text
     --text-muted    — secondary text
     --surface2      — subtle hover fill on the close button
     --accent        — primary purple (#4c5199)
     --radius (10px) — matches app's medium-radius tokens (cards/panels)

   Elevation: two-layer shadow — 1px crisp edge + 12px soft body. No
   existing app token matches the "floating panel" spec; this is a
   locally-defined value so the popup reads as hovering above the page.
   ═══════════════════════════════════════════════════════════════════════ */

.help-icon-popup {
  position: fixed;
  max-width: 380px; width: max-content; min-width: 280px;
  max-height: calc(100vh - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius, 10px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06),
              0 12px 24px rgba(0, 0, 0, 0.12);
  z-index: 2000;
  color: var(--text);
  font-family: inherit;
  outline: none;
  overflow: hidden;
  display: flex; flex-direction: column;
  animation: help-icon-popup-in .14s ease-out;
}
@keyframes help-icon-popup-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Header ──────────────────────────────────────────────────────── */
.help-icon-popup-header {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.help-icon-popup-header-text { flex: 1; min-width: 0; }
.help-icon-popup-eyebrow {
  font-size: 0.68rem; font-weight: 700;
  color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 3px;
}
.help-icon-popup-title {
  font-size: 1.08rem; font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em; line-height: 1.3;
}
.help-icon-popup-close {
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: transparent; border: none;
  color: var(--text-muted);
  cursor: pointer; padding: 0; font-family: inherit;
  transition: background .15s, color .15s;
}
.help-icon-popup-close svg { width: 16px; height: 16px; display: block; }
.help-icon-popup-close:hover {
  background: var(--surface2);
  color: var(--text);
}
.help-icon-popup-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ─── Body ────────────────────────────────────────────────────────── */
.help-icon-popup-body {
  padding: 16px;
  overflow-y: auto;
}
.help-icon-popup-item {
  display: flex; gap: 12px; align-items: flex-start;
}
.help-icon-popup-item + .help-icon-popup-item { margin-top: 14px; }
.help-icon-popup-item-icon {
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: 8px;
  /* Same 8% accent-tint used on the HelpIcon trigger itself. Keeps the
     on-brand feel consistent between trigger and popup chrome. */
  background: rgba(108, 116, 204, 0.08);
  color: var(--accent);
}
.help-icon-popup-item-icon svg { width: 20px; height: 20px; display: block; }
.help-icon-popup-item-text { flex: 1; min-width: 0; padding-top: 2px; }
.help-icon-popup-item-heading {
  font-size: 0.9rem; font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}
.help-icon-popup-item-description {
  font-size: 0.82rem; font-weight: 400;
  color: var(--text-muted);
  line-height: 1.45;
  margin-top: 2px;
}

/* Fallback render when the manifest entry has no outline — shows the
   plain snippet. Kept for the placeholder tutorial + any future
   manifest entries that skip the outline field. */
.help-icon-popup-snippet {
  font-size: 0.88rem; line-height: 1.55;
  color: var(--text-muted);
}

/* ─── Footer ──────────────────────────────────────────────────────── */
.help-icon-popup-footer {
  background: rgba(108, 116, 204, 0.08);
  border-top: 1px solid var(--border);
}
.help-icon-popup-cta {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  color: var(--accent);
  font-size: 0.88rem; font-weight: 500;
  text-decoration: none;
  transition: background .15s;
}
.help-icon-popup-cta:hover { background: rgba(108, 116, 204, 0.12); }
.help-icon-popup-cta:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 4px;
}

/* On phones the popup is never wider than the viewport minus an 8px
   clamp margin (JS enforces this too via positionPopup). */
@media (max-width: 420px) {
  .help-icon-popup { max-width: calc(100vw - 16px); }
}

/* ═══════════════════════════════════════════════════════════════════════
   Tutorial feedback block — rendered at the bottom of every article
   ─────────────────────────────────────────────────────────────────────
   Three states: prompt (thumbs up/down), comment-collect, thanks. The tutorial
   loader mounts this after the article body and toggles state classes
   on a single container.
   ═══════════════════════════════════════════════════════════════════════ */

.docs-feedback {
  margin-top: 36px; padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.docs-feedback-prompt {
  font-size: 0.92rem; font-weight: 600; color: var(--text);
  margin-bottom: 10px;
}
.docs-feedback-buttons {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.docs-feedback-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: inherit; font-size: 0.86rem; font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.docs-feedback-btn:hover {
  background: rgba(108, 116, 204, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}
.docs-feedback-btn.pressed {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.docs-feedback-comment {
  margin-top: 12px;
}
.docs-feedback-comment textarea {
  width: 100%; box-sizing: border-box;
  min-height: 76px; max-height: 220px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit; font-size: 0.92rem; line-height: 1.5;
  resize: vertical;
}
.docs-feedback-comment textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 116, 204, 0.18);
}
.docs-feedback-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 10px;
}
.docs-feedback-actions .docs-feedback-skip {
  background: transparent; border: none;
  color: var(--text-muted);
  font-family: inherit; font-size: 0.84rem;
  padding: 8px 10px; border-radius: 7px;
  cursor: pointer;
}
.docs-feedback-actions .docs-feedback-skip:hover { color: var(--text); }
.docs-feedback-actions .docs-feedback-submit {
  background: var(--accent); border: none;
  color: #fff;
  font-family: inherit; font-size: 0.86rem; font-weight: 600;
  padding: 8px 16px; border-radius: 8px;
  cursor: pointer;
}
.docs-feedback-actions .docs-feedback-submit:hover { filter: brightness(1.08); }
.docs-feedback-actions .docs-feedback-submit:disabled { opacity: 0.55; cursor: not-allowed; }
.docs-feedback-thanks {
  font-size: 0.9rem; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.docs-feedback-thanks::before { content: "✓"; color: var(--teal); font-weight: 700; }
.docs-feedback-error {
  font-size: 0.86rem; color: var(--red);
  margin-top: 8px;
}
/* State toggles — the loader flips exactly one of these classes on
   .docs-feedback so the other panes collapse. */
.docs-feedback[data-state="prompt"]  .docs-feedback-comment,
.docs-feedback[data-state="prompt"]  .docs-feedback-thanks { display: none; }
.docs-feedback[data-state="comment"] .docs-feedback-prompt,
.docs-feedback[data-state="comment"] .docs-feedback-buttons,
.docs-feedback[data-state="comment"] .docs-feedback-thanks { display: none; }
.docs-feedback[data-state="thanks"]  .docs-feedback-prompt,
.docs-feedback[data-state="thanks"]  .docs-feedback-buttons,
.docs-feedback[data-state="thanks"]  .docs-feedback-comment { display: none; }
