/*
 * ff-nav_mobile.css — Flowfinity KB v2 header, compact/collapsed (Phase 3)
 * Loaded by every KB page at (max-width: 1024px). The KB header carries more
 * items than the marketing nav (Browse topics + site links + demo CTA), so
 * the horizontal row stops fitting well below ~1024px; rather than let it
 * overflow the pill, the bar goes full-width and the right-hand cluster
 * collapses behind an accessible hamburger <button> (toggled by topmenu.v2.js
 * via .is-open — no checkbox hack, so screen readers get aria-expanded state).
 */

.ffkb-nav {
  top: 0;
  left: 0;
  transform: none;
  width: 100%;
  max-width: none;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  border-radius: 0;
  padding: 0 14px;
  /* viewport-fit=cover: keep the logo/hamburger clear of the notch /
     Dynamic Island in landscape (the FAB already does this). */
  padding-left: calc(14px + env(safe-area-inset-left, 0px));
  padding-right: calc(14px + env(safe-area-inset-right, 0px));
}

/* Foldable cover screens: the full brand row fits at 320px but not below;
   the logo alone still identifies the site. */
@media (max-width: 339px) {
  .ffkb-nav .ffkb-brand-tag { display: none; }
}

.ffkb-nav-wrap { height: 56px; }
.ffkb-nav .ffkb-logo { height: 30px; }
.ffkb-nav .ffkb-brand-tag {
  font-size: .9rem;
  padding-left: 10px;
}

/* Hamburger */
.ffkb-nav .ffkb-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;            /* WCAG 44px tap target */
  height: 44px;
  margin-left: auto;
  padding: 11px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 8px;
  box-sizing: border-box;
}
.ffkb-nav .ffkb-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: #334155;
  border-radius: 2px;
  transition: transform .2s ease, opacity .2s ease;
}
.ffkb-nav.is-open .ffkb-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.ffkb-nav.is-open .ffkb-toggle span:nth-child(2) { opacity: 0; }
.ffkb-nav.is-open .ffkb-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Collapsible sheet (drops below the bar; absolute child of the fixed nav) */
.ffkb-nav .ffkb-menu {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  margin-left: 0;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 10px;
  /* viewport-fit=cover: keep the menu items clear of the camera/notch in
     landscape — same safe-area treatment as the bar above and the sheet. */
  padding-left: calc(10px + env(safe-area-inset-left, 0px));
  padding-right: calc(10px + env(safe-area-inset-right, 0px));
  box-sizing: border-box;
  background: #fff;
  border-top: 1px solid rgb(0 0 0 / .08);
  box-shadow: 0 14px 32px rgb(0 0 0 / .14);
  /* vh first: browsers without dvh (Safari <15.4, Chrome <108) would drop
     the cap entirely and the bottom menu items would be unreachable. */
  max-height: calc(100vh - 56px);
  max-height: calc(100dvh - 56px);
  overflow-y: auto;
  display: none;
}
.ffkb-nav.is-open .ffkb-menu { display: flex; }

.ffkb-nav .ffkb-link,
.ffkb-nav .ffkb-topics-btn {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
  padding: 12px 14px;
  min-height: 44px;
  box-sizing: border-box;
  font-size: 1rem;
}

.ffkb-nav .ffkb-topics { width: 100%; }
.ffkb-nav .ffkb-topics-panel {
  position: static;
  width: 100%;
  margin-top: 4px;
  box-shadow: none;
  border: 1px solid rgb(0 0 0 / .08);
  border-radius: 12px;
}
.ffkb-nav .ffkb-topics-grid { grid-template-columns: 1fr; }
.ffkb-nav .ffkb-topic { min-height: 44px; }   /* touch tap target */

.ffkb-nav .ffkb-cta {
  width: 100%;
  text-align: center;
  margin: 8px 0 0;
  padding: 13px 16px;
}

/* ====================================================================== *
 * Phase 4 + 5 — compact-bar overrides (≤1024px) for the reader-experience
 * components, plus the mobile Browse button and bottom sheet.
 * ====================================================================== */

/* ---- 5A breadcrumb: full-width row directly under the 56px bar -------- */
.ffkb-v2-crumb {
  top: 56px;
  left: 0;
  transform: none;
  width: 100%;
  max-width: none;
}
.ffkb-v2-crumb ol {
  display: flex;
  width: 100%;
  box-sizing: border-box;   /* width:100% + padding must not pass the viewport */
  border-radius: 0;
  border: 0;
  border-bottom: 1px solid rgb(0 0 0 / .06);
  box-shadow: none;
  padding: 9px 14px;
  padding-left: calc(14px + env(safe-area-inset-left, 0px));
  padding-right: calc(14px + env(safe-area-inset-right, 0px));
}
/* Single line always: the middle (category) segment truncates first (plan 5A) */
.ffkb-v2-crumb li:nth-child(2) { flex: 0 1 auto; max-width: 38%; }
.ffkb-v2-crumb-art { flex: 1 1 auto; }

/* ---- 5D / end-block gutters ------------------------------------------- *
 * Tablet (770–1024px) keeps the desktop main.css 50px article gutter, so the
 * base ff-nav.css margins already align there. Phones (≤769px) switch to
 * main_mobile.css's 15px gutter — match it. */
@media (max-width: 769px) {
  .ffkb-v2-meta { margin: 6px 10px 4px 15px; }
  .ffkb-v2-end { margin: 36px 10px 8px 15px; }
  /* Narrow screens: give the question its own row so the Yes/No buttons
     wrap together beneath it instead of splitting mid-row. */
  .ffkb-v2-fb-legend { flex-basis: 100%; }
}

/* ---- Mobile viewport budget: nav + breadcrumb yield on scroll-down,
 * reappear together on scroll-up (class set by mainscreen.v2.js). The
 * 3px progress bar stays — it is essentially free. ---------------------- */
@media (max-width: 769px) {
  .ffkb-nav,
  .ffkb-v2-crumb { transition: transform 0.25s ease; }
  body.ffkb-v2-bars-hidden .ffkb-nav { transform: translateY(-105%); }
  body.ffkb-v2-bars-hidden .ffkb-v2-crumb { transform: translateY(calc(-100% - 60px)); }
  /* never hide the bar while its menu is open */
  body.ffkb-v2-bars-hidden .ffkb-nav.is-open { transform: none; }
}

/* ---- Phase 4 — floating "Browse" button ------------------------------- */
/* Plain bottom-right placement is the older-browser fallback; the env()
   lines anchor it above the iOS toolbar / safe-area where supported. */
.ffkb-v2-fab {
  position: fixed;
  right: 16px;
  bottom: 16px;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 980;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 18px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, rgb(155 10 0 / .97), rgb(205 14 0 / .97));
  color: #fff;
  font: 600 15px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  box-shadow: 0 6px 24px rgb(205 14 0 / .35), 0 2px 8px rgb(0 0 0 / .18);
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}
.ffkb-v2-fab svg { width: 17px; height: 17px; }
.ffkb-v2-fab:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
/* hidden while the on-screen keyboard or the sheet is up */
.ffkb-v2-fab.is-keyboard,
.ffkb-v2-fab.is-sheet-open {
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
}

/* ---- Phase 4 — bottom sheet (scroll-snap swipe surface) ---------------- */
/* Scroller = viewport-sized snap container. Stop 1: full-height spacer
   (sheet closed, scrollTop 0). Stop 2: the sheet, snapped to the bottom
   edge (open). Swipe-down dismissal is therefore native scrolling. */
html.ffkb-v2-lock,
html.ffkb-v2-lock body { overflow: hidden; }

.ffkb-v2-sheetwrap { display: block; }
.ffkb-v2-sheetwrap[hidden] { display: none; }

.ffkb-v2-sheet-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1290;
  background: #000;
  opacity: 0;                 /* driven by the drag position (JS) */
}
.ffkb-v2-sheet-scroller {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1300;
  overflow-y: auto;
  overscroll-behavior: none;  /* the swipe never chains into the page */
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: y mandatory;   /* always settles fully open or closed */
  scrollbar-width: none;
}
.ffkb-v2-sheet-scroller::-webkit-scrollbar { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .ffkb-v2-sheet-scroller { scroll-behavior: smooth; }
}
.ffkb-v2-sheet-spacer {
  height: 100%;
  scroll-snap-align: start;
}
.ffkb-v2-sheet {
  position: relative;
  scroll-snap-align: end;
  height: 80vh;
  height: 80svh;              /* stable when the iOS toolbar collapses */
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgb(0 0 0 / .25);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
/* Landscape phones: 80svh of a ~360px-tall viewport leaves the list a sliver.
   Go full-height there so the article list is actually readable/scrollable
   (radius 0: rounded top corners would show notches at the screen edge). */
@media (max-height: 500px) {
  .ffkb-v2-sheet {
    height: 100vh;
    height: 100svh;
    border-radius: 0;
  }
}
.ffkb-v2-sheet:focus { outline: none; }
.ffkb-v2-sheet-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  padding: 10px;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.ffkb-v2-sheet-handle span {
  display: block;
  width: 44px;
  height: 5px;
  border-radius: 999px;
  background: rgb(15 23 42 / .18);
}
.ffkb-v2-sheet-handle:focus-visible {
  outline: 2px solid #cd0e00;
  outline-offset: -6px;
  border-radius: 12px;
}
.ffkb-v2-sheet-head { padding: 0 20px 2px; }
.ffkb-v2-sheet-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #1e293b;
}
.ffkb-v2-sheet-count {
  margin: 3px 0 0;
  font-size: 13px;
  color: #64748b;
}
.ffkb-v2-sheet-filter {
  margin: 12px 20px;
  padding: 10px 14px;
  min-height: 44px;
  border: 1px solid rgb(15 23 42 / .14);
  border-radius: 12px;
  /* 16px minimum: anything smaller makes iOS Safari zoom the page on focus
     (and leave it zoomed). Same rule the hero search already follows. */
  font: 16px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: #1e293b;
  background: #f8fafc;
}
.ffkb-v2-sheet-filter:focus-visible { outline: 2px solid #cd0e00; outline-offset: 2px; }
.ffkb-v2-sheet-list {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;   /* list scroll never drags the sheet */
  -webkit-overflow-scrolling: touch;
  list-style: none;
  margin: 0;
  padding: 0 12px 16px;
}
.ffkb-v2-sheet-list li + li { border-top: 1px solid rgb(0 0 0 / .04); }
.ffkb-v2-sheet-list a {
  display: block;
  min-height: 44px;
  padding: 12px 10px;
  border-radius: 10px;
  color: #334155;
  font-size: 15px;
  line-height: 1.35;
  text-decoration: none;
}
.ffkb-v2-sheet-list a:focus-visible { outline: 2px solid #cd0e00; outline-offset: -2px; }
.ffkb-v2-sheet-list li.is-active a {
  color: #cd0e00;
  font-weight: 600;
  background: rgb(205 14 0 / .07);
}

/* ---- Reduced motion + forced colors ----------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .ffkb-nav,
  .ffkb-v2-crumb,
  .ffkb-v2-fab { transition: none !important; }
}
@media (forced-colors: active) {
  .ffkb-v2-fab { background: ButtonFace; color: ButtonText; border: 1px solid ButtonText; }
  .ffkb-v2-sheet { background: Canvas; border: 1px solid CanvasText; }
  .ffkb-v2-sheet-handle span { background: CanvasText; }
}
