/*
 * Sidebar navigation component: sections with collapsible groups, the scope
 * picker, the brand-row expand-all and rail toggles, the admin clock behind an (i) at the end of the nav, the collapsed "rail"
 * mode with its flyouts, and the mobile tab bar.
 *
 * @author Sander Tamaela
 * @created 2026-02-22
 * @modified 2026-10-06
 */

/* ── Accessibility: screen-reader-only utility ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.sr-only-focusable:focus {
  position: fixed;
  top: 4px;
  left: 4px;
  z-index: 100000;
  width: auto;
  height: auto;
  padding: 8px 16px;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  background: #fff;
  color: var(--blue-500);
  font-weight: 600;
  font-size: 14px;
  border: 2px solid var(--blue-500);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  text-decoration: none;
}

/* ── Body reset when sidebar is active ── */
body:has(.ofo-sidebar) {
  padding: 0;
}

/* Hide the old horizontal nav when sidebar is active */
body:has(.ofo-sidebar) > .ofo-nav {
  display: none;
}

/* ── Flex layout wrapper (sidebar + main) ── */
.ofo-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.ofo-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--gray-200);
  z-index: 200;
  display: flex;
  flex-direction: column;
  padding: 0;
}

/* Desktop, wide: the sidebar is one long column that scrolls with the page
   (no inner scroll box). The rail (below) is short and stays put instead. */
.ofo-sidebar-scroll {
  flex: 1;
  min-height: 0;
}

/* ── Main content area ── */
.ofo-main {
  flex: 1;
  min-width: 0;
}

/* Brand block at top of sidebar */
.ofo-sidebar-brand {
  height: 65px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px 0 20px;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.ofo-sidebar-brand-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}
/* Rail toggle, right of the brand name. */
.ofo-sidebar-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.ofo-sidebar-brand a {
  font-weight: 600;
  color: var(--gray-900);
  font-size: 16px;
  text-decoration: none;
  display: block;
  line-height: 1.1;
}
.ofo-sidebar-brand a:hover {
  text-decoration: none;
}

/* One-letter brand mark, shown only in the rail (see rail mode below). */
.ofo-sidebar-brand-mark {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--blue-500);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

.ofo-sidebar-tagline {
  font-size: 9px;
  color: var(--gray-400);
  font-weight: 400;
  letter-spacing: 0.03em;
  margin-top: 2px;
  display: block;
}

/* Nav area inside sidebar (scrolls with the picker in .ofo-sidebar-scroll) */
.ofo-sidebar-nav {
  padding: 12px 0;
}

/* ── Sections ── */
.ofo-sidebar-section {
  margin-bottom: 4px;
}

/* Section header (main item - clickable link + expand trigger) */
.ofo-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.ofo-sidebar-header:hover {
  background: var(--gray-50);
}

.ofo-sidebar-header a {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-400);
  text-decoration: none;
  flex: 1;
}

.ofo-sidebar-header a:hover {
  color: var(--gray-600);
  text-decoration: none;
}

/* Section is active (contains current page) */
.ofo-sidebar-section.active > .ofo-sidebar-header a {
  color: var(--blue-500);
}

/* Section icon (ofo_nav_icon), before the label; takes the label's colour. */
.ofo-sidebar-section-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 10px;
  color: var(--gray-400);
  border-radius: var(--radius-md);
  transition: color 0.15s, background 0.15s;
}
.ofo-sidebar-header:hover .ofo-sidebar-section-icon {
  color: var(--gray-600);
}
.ofo-sidebar-section.active > .ofo-sidebar-header .ofo-sidebar-section-icon {
  color: var(--blue-500);
}

/* Expand/collapse chevron */
.ofo-sidebar-chevron {
  font-size: 10px;
  color: var(--gray-400);
  transition: transform 0.2s;
  flex-shrink: 0;
  margin-left: 8px;
}

.ofo-sidebar-section.expanded > .ofo-sidebar-header .ofo-sidebar-chevron {
  transform: rotate(90deg);
}

/* Read-only badge for analyst role */
.ofo-sidebar-badge-readonly {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gray-500);
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  margin-left: auto;
  margin-right: 4px;
  white-space: nowrap;
}

/* ── Sub-items ── */
.ofo-sidebar-items {
  display: none;
  padding: 0 0 8px;
}

.ofo-sidebar-section.expanded > .ofo-sidebar-items {
  display: block;
}

.ofo-sidebar-item {
  display: block;
  padding: 7px 20px 7px 36px;
  font-size: 14px;
  color: var(--gray-600);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}

.ofo-sidebar-item:hover {
  background: var(--gray-50);
  color: var(--gray-900);
  text-decoration: none;
}

/* Active sub-item */
.ofo-sidebar-item.active {
  color: var(--blue-500);
  font-weight: 600;
  background: rgba(37, 99, 235, 0.04);
  border-left-color: var(--blue-500);
}

/* ── Accessibility: focus-visible outlines (keyboard only) ── */
.ofo-sidebar-header:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}
.ofo-sidebar-item:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: -2px;
}
/* Italic variant - generic flag for items that should read as utility/config
   rather than primary analytics surfaces. Currently unused (Brand Setup now
   uses the icon variant below) but kept available for future items. */
.ofo-sidebar-item-italic { font-style: italic; opacity: 0.85; }
.ofo-sidebar-item-italic.active { opacity: 1; }

/* Group sub-header inside a section's item list (e.g. Analytics -> Visibility /
   Citations & Sources). In the sidebar it is a button that opens and closes
   its group (.ofo-sidebar-group-toggle); in the rail flyout a plain label. */
.ofo-sidebar-subhead {
  padding: 10px 20px 4px 20px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gray-400);
}

/* Collapsible group: header button + its items. Collapsed groups show only
   the header line; the one holding the current page renders open. */
.ofo-sidebar-group-toggle {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 20px;
  margin: 0;
  border: 0;
  background: none;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.ofo-sidebar-group-toggle:hover {
  background: var(--gray-50);
  color: var(--gray-600);
}
.ofo-sidebar-group-toggle:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: -2px;
}
.ofo-sidebar-group-toggle .ofo-sidebar-chevron {
  font-size: 8px;
}
.ofo-sidebar-group.expanded > .ofo-sidebar-group-toggle .ofo-sidebar-chevron {
  transform: rotate(90deg);
}
.ofo-sidebar-group-items {
  display: none;
  padding-bottom: 4px;
}
.ofo-sidebar-group.expanded > .ofo-sidebar-group-items {
  display: block;
}

/* Icon variant - sub-items with a leading SVG (e.g. Brand Setup gear).
   Padding-left is reduced so the label still aligns with text-only siblings:
   14px padding + 14px icon + 8px gap = 36px (matches base .ofo-sidebar-item). */
.ofo-sidebar-item-with-icon {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 14px;
}
.ofo-sidebar-item-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  opacity: 0.7;
  /* Optically center the gear with text x-height (flex centers on line-box,
     which sits slightly above x-height because of descender space). */
  transform: translateY(0.5px);
}
.ofo-sidebar-item-with-icon:hover .ofo-sidebar-item-icon,
.ofo-sidebar-item-with-icon.active .ofo-sidebar-item-icon { opacity: 1; }
.ofo-tabbar-popover-item .ofo-sidebar-item-icon { margin-right: 6px; }
.ofo-sidebar-brand a:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── Top bar (slim, user menu only) ── */
.ofo-topbar {
  height: 65px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  gap: 16px;
}

/* ── Container adjustments for sidebar layout ── */
body:has(.ofo-sidebar) .container {
  border-radius: 0;
}

/* ── Env banner adjustment for sidebar ── */

body:has(.ofo-sidebar):has(.env-banner) .ofo-layout {
  padding-top: 26px;
}

/* -- Sidebar Context Selector (group + week dropdowns) -- */
.ofo-sidebar-context {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ofo-sidebar-context-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ofo-sidebar-context-field > label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gray-500);
}

.ofo-sidebar-context-field select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  background-color: #fff;
  color: var(--gray-700);
  cursor: pointer;
  transition: border-color 0.15s;
}

.ofo-sidebar-context-field select:hover {
  border-color: var(--gray-300);
}

.ofo-sidebar-context-field select:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.ofo-sidebar-context-field select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: var(--gray-50);
}

.ofo-sidebar-context-loading {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 2px;
}

/* ── Multi-sub-group picker (replaces native <select multiple>) ── */
.ofo-multi-sub-picker {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: #fff;
  overflow: hidden;
}

.ofo-multi-sub-quickpicks {
  display: flex;
  gap: 6px;
  padding: 6px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.ofo-multi-sub-quick {
  appearance: none;
  flex: 1 1 auto;
  min-width: 0;
  background: #fff;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11px;
  font-family: inherit;
  font-weight: 500;
  color: var(--gray-700);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.ofo-multi-sub-quick:hover {
  background: var(--gray-100);
  border-color: var(--gray-400);
  color: var(--gray-900);
}

.ofo-multi-sub-quick:active {
  background: var(--gray-200);
}

.ofo-multi-sub-selected {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px;
  max-height: 96px; /* ~3 rows of chips, scrolls beyond */
  overflow-y: auto;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
}

.ofo-multi-sub-selected[hidden] {
  display: none;
}

.ofo-multi-sub-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 4px 2px 8px;
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  color: var(--gray-700);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.ofo-multi-sub-chip:hover {
  background: var(--gray-200);
  border-color: var(--gray-400);
  color: var(--gray-900);
}

.ofo-multi-sub-chip-label {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ofo-multi-sub-chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1;
  color: var(--gray-500);
}

.ofo-multi-sub-chip:hover .ofo-multi-sub-chip-x {
  color: var(--gray-700);
}

.ofo-multi-sub-list {
  display: flex;
  flex-direction: column;
  max-height: 192px; /* ~6 rows */
  overflow-y: auto;
}

.ofo-multi-sub-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 11px;
  font-weight: normal;
  color: var(--gray-700);
  cursor: pointer;
  border-bottom: 1px solid var(--gray-100);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* Heading above the Win-rate / Sentiment sets at the bottom of the list
   (lib/nav.php ofo_render_sub_picker). Same weight/colour pair as
   pages/visibility.css .brand-list-divider, at the list's 11px scale. */
.ofo-multi-sub-divider {
  /* The list is a scrolling flex column: without this the heading is squeezed
     to ~15px and its two lines are cut off. */
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: 100%;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  border-left: 0;
  border-right: 0;
  padding: 8px 10px 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-700);
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
  border-bottom: 1px solid var(--gray-100);
}
.ofo-multi-sub-divider:hover { background: var(--gray-100); color: var(--gray-900); }
.ofo-multi-sub-divider:focus-visible { outline: 2px solid var(--blue-500); outline-offset: -2px; }
.ofo-multi-sub-divider span {
  white-space: normal;   /* wrap in the narrow sidebar instead of being cut off */
  line-height: 1.35;
  font-weight: 400;
  color: var(--gray-500);
}

.ofo-multi-sub-row:last-child {
  border-bottom: none;
}

.ofo-multi-sub-row:hover {
  background: var(--gray-50);
}

.ofo-multi-sub-row input[type="checkbox"] {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--blue-500);
}

.ofo-multi-sub-row span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ofo-multi-sub-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
}

.ofo-multi-sub-count {
  font-size: 11px;
  color: var(--gray-500);
}

.ofo-multi-sub-action-btns {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Instant hover tooltip for sub-group rows (positioned by sidebar-context.js,
   appended to <body> so it escapes the picker's overflow clipping). Mirrors
   the .ofo-tooltip shell so it reads as the same component. */
.ofo-subtip {
  position: absolute;
  z-index: 1000;
  max-width: 280px;
  padding: 6px 9px;
  background: #1f2937;
  color: #f9fafb;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 500;
  white-space: normal;
  word-break: break-word;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  animation: ofo-subtip-in 0.09s ease-out;
}

.ofo-subtip[hidden] {
  display: none;
}

@keyframes ofo-subtip-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ofo-multi-sub-search-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--gray-600);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.ofo-multi-sub-search-toggle:hover {
  background: var(--gray-100);
  border-color: var(--gray-400);
  color: var(--gray-900);
}

.ofo-multi-sub-search-toggle--active {
  background: var(--blue-500);
  border-color: var(--blue-500);
  color: #fff;
}

.ofo-multi-sub-search {
  padding: 6px;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
}

.ofo-multi-sub-search[hidden] {
  display: none;
}

.ofo-multi-sub-search-input {
  appearance: none;
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 12px;
  color: var(--gray-800);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: #fff;
}

.ofo-multi-sub-search-input:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 2px var(--blue-100, rgba(59, 130, 246, 0.2));
}

.ofo-multi-sub-search-input::placeholder {
  color: var(--gray-400);
}

.ofo-multi-sub-apply {
  appearance: none;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border: 1px solid var(--blue-500);
  border-radius: var(--radius-sm);
  background: var(--blue-500);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.ofo-multi-sub-apply:hover:not(:disabled) {
  background: var(--blue-600, #1d4ed8);
  border-color: var(--blue-600, #1d4ed8);
}

.ofo-multi-sub-apply:disabled {
  background: var(--gray-200);
  border-color: var(--gray-200);
  color: var(--gray-500);
  cursor: not-allowed;
}

/* ══════════════════════════════════════════════════════════════════════
   Mobile Context Bar - hidden on desktop, visible on mobile
   ══════════════════════════════════════════════════════════════════════ */

.ofo-mobile-context {
  display: none;
}

/* ══════════════════════════════════════════════════════════════════════
   Mobile Tab Bar - hidden on desktop, replaces sidebar on mobile
   ══════════════════════════════════════════════════════════════════════ */

.ofo-tabbar,
.ofo-tabbar-backdrop,
.ofo-tabbar-popover {
  display: none;
}

/* ── Mobile breakpoint ── */
@media (max-width: 767px) {
  /* Prevent body overflow so fixed tabbar stays within the viewport */
  .ofo-layout {
    position: relative;
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* Collapse sidebar to brand-only, overlaid on topbar area */
  .ofo-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: auto;
    border-right: none;
    background: transparent;
    z-index: 201;
    pointer-events: none;
  }

  .ofo-sidebar-brand {
    height: 48px;
    width: fit-content;
    border-bottom: none;
    padding: 0 12px;
    pointer-events: auto;
  }

  .ofo-sidebar-tagline {
    display: none;
  }

  .ofo-sidebar-nav {
    display: none;
  }

  .ofo-sidebar-tools,
  .ofo-sidebar-info {
    display: none !important;
  }

  body:has(.env-banner) .ofo-sidebar {
    top: 26px;
  }

  /* ── Tab bar ── */
  .ofo-tabbar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: #fff;
    border-top: 1px solid var(--gray-200);
    z-index: 500;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* Bottom padding so content isn't hidden behind tab bar */
  .ofo-main {
    padding-bottom: 72px;
  }

  /* ── Tab items (both <a> and <button>) ── */
  .ofo-tabbar-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    height: 100%;
    padding: 6px 0;
    background: none;
    border: none;
    color: var(--gray-400);
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s;
  }

  .ofo-tabbar-tab:hover {
    text-decoration: none;
  }
  .ofo-tabbar-tab:focus {
    text-decoration: none;
    outline: none;
  }
  .ofo-tabbar-tab:focus-visible {
    outline: 2px solid var(--blue-500);
    outline-offset: -2px;
    border-radius: var(--radius-sm);
  }

  .ofo-tabbar-tab.active {
    color: var(--blue-500);
  }

  .ofo-tabbar-tab svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }

  .ofo-tabbar-label {
    font-size: 10px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  /* ── Backdrop ── */
  .ofo-tabbar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 499;
  }

  .ofo-tabbar-backdrop.open {
    display: block;
  }

  /* ── Popover (bottom sheet above tab bar) ── */
  .ofo-tabbar-popover {
    position: fixed;
    bottom: calc(56px + env(safe-area-inset-bottom, 0));
    left: 8px;
    right: 8px;
    background: #fff;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 501;
    padding: 8px 0;
    /* Cap to visible viewport so long sections (e.g. Analytics with N items)
       can't grow off-screen and clip the top rows. dvh accounts for mobile
       browser chrome show/hide. 24px = breathing room from the very top. */
    max-height: calc(100dvh - 56px - env(safe-area-inset-bottom, 0) - 24px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Env banner (26px) eats further into the available space. */
  body:has(.env-banner) .ofo-tabbar-popover {
    max-height: calc(100dvh - 56px - 26px - env(safe-area-inset-bottom, 0) - 24px);
  }

  .ofo-tabbar-popover.open {
    display: block;
    animation: ofo-slide-up 0.2s ease-out;
  }

  @keyframes ofo-slide-up {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }

  .ofo-tabbar-popover-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-400);
    padding: 8px 16px 4px;
  }

  .ofo-tabbar-popover-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    font-size: 15px;
    color: var(--gray-700);
    text-decoration: none;
    min-height: 44px;
    transition: background 0.1s;
  }

  .ofo-tabbar-popover-item:hover {
    background: var(--gray-50);
    text-decoration: none;
  }

  .ofo-tabbar-popover-item.active {
    color: var(--blue-500);
    font-weight: 600;
  }

  /* Group sub-header inside the popover's item list. Divider above each group
   (except the first, which sits right under the section title). */
  .ofo-tabbar-popover-subhead {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gray-400);
    padding: 12px 16px 4px;
    margin-top: 4px;
    border-top: 1px solid var(--gray-100);
  }
  .ofo-tabbar-popover-title + .ofo-tabbar-popover-subhead {
    margin-top: 0;
    border-top: none;
    padding-top: 4px;
  }

  /* ── Compact topbar on mobile ── */
  .ofo-topbar {
    height: 48px;
    padding: 0 12px;
    /* Tighten icon-row spacing - the base 16px gap combined with each
       icon's 44x44 tap target makes consecutive icons feel disconnected.
       4px lets the row read as a tools group while the tap targets keep
       it touch-friendly. See navigation.css mobile @media for the
       paired margin-right: 0 on .topbar-notification. */
    gap: 4px;
  }

  .ofo-topbar .user-menu-email {
    display: none;
  }

  /* ── Landscape: compact icon-only tab bar ── */
  @media (orientation: landscape) {
    .ofo-tabbar {
      height: 44px;
    }

    .ofo-tabbar-label {
      display: none;
    }

    .ofo-main {
      padding-bottom: 60px;
    }

    .ofo-tabbar-popover {
      bottom: calc(44px + env(safe-area-inset-bottom, 0));
      max-height: calc(100dvh - 44px - env(safe-area-inset-bottom, 0) - 16px);
    }

    body:has(.env-banner) .ofo-tabbar-popover {
      max-height: calc(100dvh - 44px - 26px - env(safe-area-inset-bottom, 0) - 16px);
    }
  }

  /* Context selector is part of the sidebar nav, hidden on mobile with the sidebar */
  .ofo-sidebar-context {
    display: none;
  }

  /* ── Mobile context bar ── */
  .ofo-mobile-context {
    display: block;
    border-bottom: 1px solid var(--gray-200);
    background: #fff;
  }

  .ofo-mobile-context-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 40px;
    padding: 0 16px;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
  }

  .ofo-mobile-context-summary {
    font-size: 13px;
    color: var(--gray-600);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }

  .ofo-mobile-context-chevron {
    font-size: 14px;
    color: var(--gray-400);
    flex-shrink: 0;
    margin-left: 8px;
    transition: transform 0.2s;
  }

  .ofo-mobile-context.expanded .ofo-mobile-context-chevron {
    transform: rotate(180deg);
  }

  .ofo-mobile-context-panel {
    display: none;
    padding: 0 16px 12px;
    flex-direction: column;
    gap: 10px;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
  }

  .ofo-mobile-context.expanded .ofo-mobile-context-panel {
    display: flex;
  }

  .ofo-mobile-context-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
  }

  .ofo-mobile-context-field > label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gray-500);
  }

  .ofo-mobile-context-field select {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background-color: #fff;
    color: var(--gray-700);
    cursor: pointer;
    transition: border-color 0.15s;
  }

  .ofo-mobile-context-field select:focus {
    outline: none;
    border-color: var(--blue-500);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
  }

  .ofo-mobile-context-field select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--gray-50);
  }

  /* Multi-sub picker inside the mobile context panel - bigger tap targets */
  .ofo-mobile-context-field .ofo-multi-sub-row {
    padding: 10px 12px;
    font-size: 12px;
    font-weight: normal;
    min-height: 44px;
  }

  .ofo-mobile-context-field .ofo-multi-sub-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
  }

  .ofo-mobile-context-field .ofo-multi-sub-quickpicks {
    padding: 8px;
    gap: 6px;
  }

  .ofo-mobile-context-field .ofo-multi-sub-quick {
    padding: 10px 6px;
    font-size: 12px;
    min-height: 44px;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .ofo-mobile-context-field .ofo-multi-sub-selected {
    padding: 8px;
    gap: 6px;
    max-height: 120px;
  }

  .ofo-mobile-context-field .ofo-multi-sub-chip {
    padding: 6px 6px 6px 10px;
    font-size: 12px;
    min-height: 32px;
  }

  .ofo-mobile-context-field .ofo-multi-sub-chip-x {
    width: 18px;
    height: 18px;
    font-size: 16px;
  }

  .ofo-mobile-context-field .ofo-multi-sub-actions {
    padding: 8px 12px;
  }

  .ofo-mobile-context-field .ofo-multi-sub-apply {
    padding: 8px 16px;
    font-size: 13px;
    min-height: 36px;
  }
}

/* Icon button, same values as the multi-sub search toggle above. */
.ofo-sidebar-rail-toggle,
.ofo-sidebar-expand-all,
.ofo-sidebar-context-rail {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: none;
  color: var(--gray-500);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.ofo-sidebar-rail-toggle:hover,
.ofo-sidebar-expand-all:hover,
.ofo-sidebar-context-rail:hover {
  background: var(--gray-100);
  border-color: var(--gray-300);
  color: var(--gray-900);
}
.ofo-sidebar-rail-toggle:active,
.ofo-sidebar-expand-all:active,
.ofo-sidebar-context-rail:active {
  background: var(--gray-200);
}
.ofo-sidebar-rail-toggle:focus-visible,
.ofo-sidebar-expand-all:focus-visible,
.ofo-sidebar-context-rail:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: 1px;
}

.ofo-sidebar-rail-icon-close,
.ofo-sidebar-rail-icon-open {
  display: inline-flex;
}
.ofo-sidebar-rail-icon-open {
  display: none;
}

/* Expand-all button: 24px wide so it fits beside the rail toggle without
   squeezing the brand name; the icon flips once everything is open. */
.ofo-sidebar-expand-all {
  width: 24px;
}
.ofo-sidebar-expand-icon,
.ofo-sidebar-collapse-icon {
  display: inline-flex;
}
.ofo-sidebar-collapse-icon,
.ofo-sidebar-expand-all.all-open .ofo-sidebar-expand-icon {
  display: none;
}
.ofo-sidebar-expand-all.all-open .ofo-sidebar-collapse-icon {
  display: inline-flex;
}

/* Collapsed scope picker: hidden in the wide sidebar (and on mobile), label too. */
.ofo-sidebar-context-rail,
.ofo-sidebar-context-rail-label {
  display: none;
}

/* ── Admin sidebar clock: a tooltip above the (i) at the end of the nav ── */
.ofo-sidebar-info {
  position: relative;
  padding: 16px 12px 12px;
}
.ofo-sidebar-info-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: none;
  color: var(--gray-400);
  cursor: help;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.ofo-sidebar-info-btn:hover,
.ofo-sidebar-info:focus-within .ofo-sidebar-info-btn {
  background: var(--gray-100);
  border-color: var(--gray-300);
  color: var(--gray-900);
}
.ofo-sidebar-info-btn:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: 1px;
}
.ofo-sidebar-clock {
  display: none;
  position: absolute;
  left: 12px;
  bottom: calc(100% - 8px);
  z-index: 300;
  white-space: nowrap;
  padding: 10px 12px;
  border: 1px solid var(--gray-200, #e5e7eb);
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  font-size: 10px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  color: var(--gray-500, #6b7280);
  flex-direction: column;
  gap: 6px;
}
.ofo-sidebar-info:hover .ofo-sidebar-clock,
.ofo-sidebar-info:focus-within .ofo-sidebar-clock {
  display: flex;
}
.ofo-clock-row {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.ofo-clock-lbl {
  color: var(--gray-400, #9ca3af);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.ofo-clock-val {
  color: var(--gray-600, #4b5563);
}

/* ======================================================================
   Rail mode - html.ofo-sidebar-rail, set before first paint from
   localStorage (ofo_render_sidebar). Desktop only: on mobile the tab bar
   takes over exactly as before and the class has no effect.
   ====================================================================== */
@media (min-width: 768px) {
  html.ofo-sidebar-rail .ofo-sidebar {
    width: 60px;
    position: sticky;
    top: 0;
    height: 100vh;
    align-self: flex-start;
  }
  html.ofo-sidebar-rail body:has(.env-banner) .ofo-sidebar {
    top: 26px;
    height: calc(100vh - 26px);
  }
  html.ofo-sidebar-rail .ofo-sidebar-scroll {
    overflow-y: auto;
    overflow-x: hidden;
  }

  /* Brand row stacks: the F mark, then the expand toggle under it. */
  html.ofo-sidebar-rail .ofo-sidebar-brand {
    height: auto;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    padding: 12px 0;
  }
  html.ofo-sidebar-rail .ofo-sidebar-brand-text {
    align-items: center;
  }
  html.ofo-sidebar-rail .ofo-sidebar-brand-mark {
    display: inline-flex;
  }
  /* Labels are visually hidden but still read out. */
  html.ofo-sidebar-rail .ofo-sidebar-brand-name,
  html.ofo-sidebar-rail .ofo-sidebar-header > a {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
  html.ofo-sidebar-rail .ofo-sidebar-tagline,
  html.ofo-sidebar-rail .ofo-sidebar-chevron,
  html.ofo-sidebar-rail .ofo-sidebar-header .ofo-sidebar-badge-readonly,
  html.ofo-sidebar-rail .ofo-sidebar-section > .ofo-sidebar-items,
  html.ofo-sidebar-rail .ofo-sidebar-clock {
    display: none;
  }

  /* Scope picker -> one icon button that opens the scope flyout. The fields
     are hidden only while they sit in the sidebar: js/sidebar-nav.js moves
     them into the flyout, where they render as in the wide sidebar. The
     loading line is toggled inline by sidebar-context.js, hence !important. */
  html.ofo-sidebar-rail .ofo-sidebar-context {
    align-items: center;
    padding: 12px 0;
  }
  html.ofo-sidebar-rail .ofo-sidebar .ofo-sidebar-context-field,
  html.ofo-sidebar-rail .ofo-sidebar .ofo-sidebar-context-loading {
    display: none !important;
  }
  /* Icon with a short scope label (-, All, Br, NB, 1, n) stacked under it,
     both centred in the 60px rail; the label never wraps or clips. */
  html.ofo-sidebar-rail .ofo-sidebar-context-rail {
    display: inline-flex;
    flex-direction: column;
    gap: 2px;
    width: 44px;
    height: auto;
    padding: 5px 0 4px;
  }
  /* Open state = the hover tile, like a section icon with its flyout open. */
  html.ofo-sidebar-rail .ofo-sidebar-context-rail.flyout-open {
    background: var(--gray-100);
    border-color: var(--gray-300);
    color: var(--gray-900);
  }
  html.ofo-sidebar-rail .ofo-sidebar-context-rail-label {
    display: block;
    max-width: 100%;
    font-size: 10px;
    font-weight: 500;
    line-height: 1.1;
    text-align: center;
    white-space: nowrap;
    color: inherit;
  }

  /* Section headers -> icon only, centred, with a hover/active tile. */
  html.ofo-sidebar-rail .ofo-sidebar-header {
    position: relative;
    justify-content: center;
    padding: 6px 0;
  }
  html.ofo-sidebar-rail .ofo-sidebar-header:hover {
    background: none;
  }
  html.ofo-sidebar-rail .ofo-sidebar-section-icon {
    width: 36px;
    height: 36px;
    margin-right: 0;
    color: var(--gray-500);
  }
  html.ofo-sidebar-rail .ofo-sidebar-header:hover .ofo-sidebar-section-icon,
  html.ofo-sidebar-rail .ofo-sidebar-section.flyout-open .ofo-sidebar-section-icon {
    background: var(--gray-100);
    color: var(--gray-900);
  }
  html.ofo-sidebar-rail .ofo-sidebar-section.active > .ofo-sidebar-header .ofo-sidebar-section-icon {
    background: rgba(37, 99, 235, 0.08);
    color: var(--blue-500);
  }
  /* A stopped Sheets sync inside a section: a dot on its icon, since the
     count itself only shows in the flyout. */
  html.ofo-sidebar-rail .ofo-sidebar-section:has(.ofo-sidebar-count) .ofo-sidebar-section-icon::after {
    content: "";
    position: absolute;
    top: 7px;
    left: calc(50% + 9px);
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--red-500);
  }

  html.ofo-sidebar-rail .ofo-sidebar-info,
  html.ofo-sidebar-rail .ofo-sidebar-expand-all {
    display: none;
  }
  html.ofo-sidebar-rail .ofo-sidebar-rail-icon-close {
    display: none;
  }
  html.ofo-sidebar-rail .ofo-sidebar-rail-icon-open {
    display: inline-flex;
  }
}

/* -- Rail flyout: one section's items next to its icon --
   Built by js/sidebar-nav.js from the section's own links, appended to
   <body> and position:fixed, so the sidebar's scroll box never clips it. */
.ofo-sidebar-flyout {
  position: fixed;
  z-index: 950;
  width: 240px;
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  padding: 6px 0 8px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.ofo-sidebar-flyout[hidden] {
  display: none;
}
.ofo-sidebar-flyout-title {
  display: flex;
  align-items: center;
  padding: 8px 16px 4px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-400);
}
.ofo-sidebar-flyout .ofo-sidebar-subhead {
  padding: 10px 16px 4px;
}
/* Same alignment rule as the sidebar: icon items line their text up with
   plain items (10px + 14px icon + 8px gap = 32px). */
.ofo-sidebar-flyout .ofo-sidebar-item {
  padding: 6px 16px 6px 32px;
}
.ofo-sidebar-flyout .ofo-sidebar-item-with-icon {
  padding-left: 10px;
}
/* Scope flyout: the real scope picker (moved in by js/sidebar-nav.js), as
   wide as the full sidebar and laid out like .ofo-sidebar-context. */
.ofo-sidebar-scope-flyout {
  width: 260px;
}
.ofo-sidebar-scope-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 16px 8px;
}
@media (max-width: 767px) {
  .ofo-sidebar-flyout {
    display: none;
  }
}
