/*
 * THE PLATFORM BOTTOM TAB BAR — Ask, Find, Fund, Close, Me.
 *
 * ONE FILE, SEVEN SITES. This is a byte-identical copy on every site in the
 * network (ordertitle.ai/shared, thegrowthcollective-ai/shared, and
 * public/shared on the four Next apps). Edit it in one place and copy it out;
 * do not fork it per site. Everything that differs between sites is passed in
 * as configuration by tabbar.js — the accent colour, which tab is current, and
 * where the current site's own tab points.
 *
 * ── PHONES ONLY ────────────────────────────────────────────────────────────
 * Every rule that draws anything lives inside `@media (max-width:640px)`.
 * Desktop keeps the full platform menu in the top bar and gets no bar at all —
 * not a hidden one, no bar. That is also why `--jdl-tabbar-h` is 0px by
 * default and only takes a real value inside the query: a page that subtracts
 * it from its own height (see the Ask AI splashes) subtracts nothing on a
 * laptop, with no media query of its own to keep in step with this one.
 *
 * ── HOW A PAGE MAKES ROOM FOR IT ───────────────────────────────────────────
 * Two modes, because the platform has two kinds of page.
 *
 *   fixed  (the default, for anything that scrolls) — the bar is pinned to the
 *          bottom of the viewport and the body gets `padding-bottom` so the
 *          last thing on the page can still be reached. It slides away as you
 *          scroll down and comes back as you scroll up.
 *
 *   flow   (for the Ask AI splashes, which are a fixed-height column with
 *          nothing scrolling) — the bar is an ordinary last row of that
 *          column. No pinning, no padding, no height arithmetic: the splash
 *          measures whatever is left, so when the bar is removed the splash
 *          grows back into the space by itself. Nothing on those pages
 *          scrolls, so there is nothing to hide it on either.
 *
 * ── z-index 40 IS DELIBERATELY LOW ─────────────────────────────────────────
 * The bar is page furniture, not an overlay. It must sit above ordinary
 * content and BELOW anything modal — the chat overlays on these sites run at
 * z-50 and up. A tab bar floating on top of a full-screen chat would cover the
 * composer, which is the one control that screen exists for. The bar also
 * takes itself off the page entirely on `jdl:chat-start` (see tabbar.js), so on
 * the screens where a conversation is in progress this never has to be fought
 * out in the stacking context at all.
 */

/* 0 unless the bar is actually on the page AND we are on a phone. Pages that
   subtract this from their own height can do so unconditionally. */
:root { --jdl-tabbar-h: 0px; }

/* Nothing at all above the phone breakpoint. */
.jdl-tabbar { display: none; }

@media (max-width: 640px) {
  /* THE BAR'S OWN HEIGHT, defined unconditionally.

     It must NOT depend on the html.jdl-tabs class below. React restores the
     server-rendered className of <html> during hydration on any app that has
     not opted out with suppressHydrationWarning, which strips a class a script
     added before it ran -- and when the bar's height was var(--jdl-tabbar-h),
     that left the bar sitting in the DOM at ZERO HEIGHT. Visible while the page
     loaded, gone the moment it finished. The bar now sizes itself and only the
     page's reservation depends on the class. */
  :root {
    --jdl-tabbar-size: calc(54px + env(safe-area-inset-bottom, 0px));
  }

  /* Set on <html> by tabbar.js while the bar is mounted, and taken off again
     when a chat starts. This is what a PAGE reserves space with -- the bar
     itself no longer reads it, so losing the class can cost a page its padding
     but can never make the bar disappear. */
  html.jdl-tabs {
    --jdl-tabbar-h: var(--jdl-tabbar-size);
  }

  /* The pinned bar covers the bottom of the document, so the document is told
     to end that much higher.

     TWO WAYS TO OPT OUT, and they are deliberately separate things.
     `data-tabbar="flow"` opts out by construction: the bar is a row of the
     page's own column there and already takes its own space.
     `data-tabbar-pad="off"` is for a page that keeps the bar PINNED but has
     already made room for it some other way — jdldeals.ai's Ask AI route
     subtracts --jdl-tabbar-h from its shell's height, and padding under that
     shell would reserve the same 54px a second time and give the page a
     scrollbar it should not have.

     env(safe-area-inset-bottom) reads 0 on a site whose viewport meta has no
     viewport-fit=cover, which is harmless: the bar is then 54px, exactly as it
     was before the inset was asked for. */
  html.jdl-tabs body:not([data-tabbar='flow']):not([data-tabbar-pad='off']) {
    padding-bottom: var(--jdl-tabbar-h);
  }

  /* ── THE HOST ELEMENT IS DELIBERATELY DEFENSIVE ──────────────────────────
     This bar is appended to seven different sites, each with its own
     stylesheet, and a bare element selector in any of them reaches it. That is
     not hypothetical: thegrowthcollective.ai styles the bare `nav` element
     (position:sticky; top:0; z-index:60) for its own header, and while the bar
     was a <nav> it inherited that top:0 -- which, with bottom:0 also set,
     over-constrains a fixed box and pins it to the TOP of the screen. The bar
     appeared across the middle of the page instead of along the bottom.

     Two defences. The element is now <jdl-tabbar>, a name no site has a rule
     for, and every property a host stylesheet might plausibly set on a bar-like
     element is declared here rather than left to chance -- margin, padding,
     border on all four sides, inset, box-shadow, font. Anything not declared is
     something a site can still reach, so the list is deliberately longer than
     the bar strictly needs. */
  .jdl-tabbar {
    display: block;
    box-sizing: border-box;
    height: var(--jdl-tabbar-size);
    margin: 0;
    /* The safe-area inset is padding rather than extra height so the row of
       tabs stays 54px and only the gap below it grows on a notched phone. */
    padding: 0 0 env(safe-area-inset-bottom, 0px);
    /* Every side spelled out, so a stray top/left/right from a host stylesheet
       cannot fight the bottom:0 the fixed mode sets below. Longhands rather
       than the inset shorthand: same specificity, nothing to support. */
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    background: #fff;
    border: 0;
    border-top: 1px solid #E4EAF4;
    box-shadow: none;
    /* Inter where the site already loads it, the platform's system stack
       otherwise. Never inherited: the bar must look the same on all seven
       sites, including the two whose body font is not Inter. */
    font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    /* The accent of whichever site this is, handed over by tabbar.js. The
       fallback is the platform blue. */
    --jdl-tab-accent: #2C55F5;
    --jdl-tab-muted: #5A6478;
    z-index: 40;
  }

  .jdl-tabbar[data-mode='fixed'] {
    position: fixed;
    /* top:auto is as load-bearing as bottom:0 here -- see the note above. An
       over-constrained box (top AND bottom AND height) resolves in favour of
       top, which is how a host stylesheet's top:0 moved the whole bar to the
       top of the screen. */
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    /* Slides, rather than appearing and disappearing: a bar that blinks out
       under your thumb reads as a glitch. */
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
  }
  /* Scrolling down. translateY(100%) alone can leave the top border on screen
     as a hairline on fractional device pixel ratios, so it goes one pixel
     further than its own height. */
  .jdl-tabbar[data-mode='fixed'].is-down {
    transform: translateY(calc(100% + 1px));
  }

  /* A row of the page's own column. flex:none so a flex parent cannot squeeze
     it, position:relative so the Me panel can anchor to it. */
  .jdl-tabbar[data-mode='flow'] {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    flex: none;
  }

  @media (prefers-reduced-motion: reduce) {
    .jdl-tabbar[data-mode='fixed'] { transition: none; }
  }

  .jdl-tabs-row {
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    list-style: none;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    height: 54px;
  }

  /* A host stylesheet's bare `li` rule (markers, margins, line-height) must not
     reach the row either. */
  .jdl-tabs-row > li {
    margin: 0;
    padding: 0;
    list-style: none;
    display: block;
  }

  /* 54px tall and a fifth of the screen wide — comfortably past the 44px
     minimum at every width we test (360, 390, 430). */
  .jdl-tab {
    -webkit-appearance: none;
    appearance: none;
    border: 0;
    background: transparent;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 54px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font: inherit;
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.01em;
    color: var(--jdl-tab-muted);
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .jdl-tab svg {
    width: 21px;
    height: 21px;
    display: block;
    flex: none;
  }
  /* A pressed state, so a tap is acknowledged before the next page paints. */
  .jdl-tab:active { background: #F3F6FD; }
  .jdl-tab.is-on { color: var(--jdl-tab-accent); }
  .jdl-tab:focus-visible {
    outline: 2px solid var(--jdl-tab-accent);
    outline-offset: -3px;
  }
  .jdl-tab-lb {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* ── The Me panel ────────────────────────────────────────────────────────
     Me is the only tab that is not a place. It holds this site's account links
     plus the four corners of the network that do not get a tab of their own
     (Analyze, Grow, Invest, Refer), which is what the spec asks of it.

     It opens upward from the bar rather than as a sheet, because the slide-up
     sheet infrastructure is not built yet and a menu of eight links does not
     need it. Anchored to the right so it opens over the tab that summoned it. */
  .jdl-me {
    position: absolute;
    right: 8px;
    bottom: calc(100% - 1px);
    width: min(248px, calc(100vw - 16px));
    background: #fff;
    border: 1px solid #E4EAF4;
    border-radius: 14px;
    box-shadow: 0 -10px 30px -12px rgba(11, 18, 32, 0.3);
    padding: 6px;
    display: grid;
    gap: 1px;
  }
  .jdl-me[hidden] { display: none; }
  .jdl-me-h {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #8A93A6;
    padding: 8px 10px 4px;
  }
  .jdl-me a {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 40px;
    padding: 0 10px;
    border-radius: 9px;
    font-size: 13.5px;
    font-weight: 600;
    color: #0B1220;
    text-decoration: none;
  }
  .jdl-me a:active { background: #F3F6FD; }
  /* The coloured dot the whole platform marks a sibling site with. */
  .jdl-me a i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--d, #2C55F5);
    flex: none;
  }
}
