/* ==========================================================================
   FUNDER — Motion system
   ==========================================================================
   ONE set of rules for how a selection moves, at every width, in every theme.

   The problem it solves: the homepage has five different "pick one of these"
   controls — the view switch, the fund-type segment, the metric tabs, the
   board's category tabs and its period tabs — and each one announced its new
   selection by turning a style off here and on over there. Nothing travelled.
   A reader had to find the selection again after every tap.

   THE PRIMITIVE: a sliding thumb.
   --------------------------------
   One absolutely-positioned element per control, sitting *behind* the
   options, that moves and resizes to the option that is now selected.
   fn-motion.js inserts it and writes exactly two custom properties per state
   change — --fn-slider-x and --fn-slider-w — measured ONCE, never per frame.

   Everything here is therefore:
     - transform for the travel (compositor; no layout, no paint)
     - width for the resize (one absolutely-positioned box, so it cannot
       reflow anything around it)
     - no JS during the animation at all

   RTL: the thumb is anchored to physical left:0 and translated by a physical
   offset, so direction is already handled by the measurement — there is no
   "flip the sign" branch to get wrong.

   Shapes come from the control (the thumb inherits a radius token); only the
   movement lives here.
   ========================================================================== */

:root {
  /* A spring with the overshoot of a real object and none of the bounce of a
     toy: it arrives at ~92% in a third of the duration, crosses by ~2%, and
     settles. Anything springier reads as a demo rather than as a control. */
  --fn-ease-spring: cubic-bezier(0.34, 1.16, 0.64, 1);
  --fn-dur-move: 260ms;

  /* The press. Deliberately shorter than the travel: the answer to a finger
     has to land before the eye starts following the thumb. */
  --fn-dur-press: 90ms;
  --fn-press-scale: 0.97;
}


/* --------------------------------------------------------------------------
   The thumb
   -------------------------------------------------------------------------- */

.fn-ui .fn-slider {
  position: relative;
}

.fn-ui .fn-slider__thumb {
  position: absolute;
  z-index: 0;
  left: 0;
  top: var(--fn-slider-top, 0px);
  height: var(--fn-slider-h, 100%);
  width: var(--fn-slider-w, 0px);
  margin: 0;
  padding: 0;
  list-style: none;
  pointer-events: none;
  border-radius: var(--fn-slider-radius, var(--fn-radius-pill));
  background: var(--fn-slider-bg, var(--fn-brand-soft));
  transform: translate3d(var(--fn-slider-x, 0px), 0, 0);
  transition:
    transform var(--fn-dur-move) var(--fn-ease-spring),
    width var(--fn-dur-move) var(--fn-ease-spring),
    opacity var(--fn-dur-fast) var(--fn-ease);
  opacity: 1;
}

/* Before the first measurement, and whenever a control has no selection,
   the thumb is not drawn — a zero-width pill at the start edge would be a
   visible artefact for one frame on every page load. */
.fn-ui .fn-slider__thumb:not(.is-ready) {
  opacity: 0;
}

/* The options have to sit above the thumb, which is painted behind them. */
.fn-ui .fn-slider > *:not(.fn-slider__thumb) {
  position: relative;
  z-index: 1;
}

/* The control draws the selected option's own background only while JS has
   not taken over. Once the thumb exists it owns the fill, and leaving both
   on would show the old block flashing under the travelling one.
   A view-switch tab under the mouse is let through: its thumb is an
   underline, not a fill, so nothing can flash, and on Soft the hover IS a
   backing (00-page.css). */
.fn-ui .fn-slider.is-sliding .fn-view-switch__opt:not(:hover),
.fn-ui .fn-slider.is-sliding .fn-data-segment__option {
  background: transparent !important;
  box-shadow: none !important;
}


/* --------------------------------------------------------------------------
   Per-control tuning — what the thumb looks like in each place
   -------------------------------------------------------------------------- */

/* View switch (ראשי / פיד / מבט מהיר / גליונות).
   ONE form at every width now: flat underline tabs. The phone used to get a
   segmented pill with a filled chip for the thumb; Udi asked for the flat,
   thin desktop language on mobile too, so the width gate is gone and the
   thumb is the travelling underline everywhere.

   The underline is the approved green at full strength. It is 2.5px rather
   than 2px because it is now the primary active signal on a phone as well,
   where it is read at arm's length. */
.fn-ui .fn-view-switch.fn-slider {
  --fn-slider-bg: var(--fn-interactive);
  --fn-slider-radius: 2px 2px 0 0;
  --fn-slider-h: 2.5px;
  /* Rides the container's bottom rule, same line the static ::after sat on. */
  --fn-slider-top: calc(100% - 2.5px);
}

/* The static underline is replaced by the travelling one. */
.fn-ui .fn-view-switch.is-sliding .fn-view-switch__opt::after,
.fn-ui .fn-cat-jump.is-sliding .fn-view-switch__opt::after {
  display: none;
}


/* Fund-type segment (קרנות מנוהלות / מחקות and friends). */
.fn-ui .fn-data-segment.fn-slider {
  --fn-slider-bg: var(--fn-bg-surface);
  --fn-slider-radius: var(--fn-radius-pill);
  --fn-slider-top: 2px;
  --fn-slider-h: calc(100% - 4px);
}

.fn-ui .fn-data-segment.is-sliding .fn-data-segment__option:has(input:checked) {
  box-shadow: none;
}

/* Metric tabs inside a data module — an underline, like the view switch.
   The thumb is an <li> here: a <span> is not valid inside a <ul>. */
.fn-ui .fn-data-tabs.fn-slider {
  --fn-slider-bg: var(--fn-interactive);
  --fn-slider-radius: 2px 2px 0 0;
  --fn-slider-h: 2px;
  --fn-slider-top: calc(100% - 2px);
}

.fn-ui .fn-data-tabs.is-sliding > li.active > a::after {
  background: transparent;
}


/* --------------------------------------------------------------------------
   Immediate touch feedback
   --------------------------------------------------------------------------
   Every one-of-many control answers the finger on its own, before and
   independently of whatever the selection is about to cost. This is the part
   that has to survive a slow network: the thumb may be waiting on a fetch,
   the press never is.
   -------------------------------------------------------------------------- */

.fn-ui .fn-view-switch__opt,
.fn-ui .fn-data-segment__option,
.fn-ui .fn-data-tabs > li > a,
.fn-ui .fn-data-metric__trigger {
  transition:
    color var(--fn-dur-fast) var(--fn-ease),
    transform var(--fn-dur-press) var(--fn-ease);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.fn-ui .fn-view-switch__opt:active,
.fn-ui .fn-data-segment__option:active,
.fn-ui .fn-data-tabs > li > a:active,
.fn-ui .fn-data-metric__trigger:active {
  transform: scale(var(--fn-press-scale));
}

/* A control whose content is still arriving says so on the control itself,
   not with a spinner somewhere else on the page. */
.fn-ui .fn-board[aria-busy="true"] .fn-board__table tbody {
  opacity: 0.45;
  transition: opacity var(--fn-dur-base) var(--fn-ease);
}


/* --------------------------------------------------------------------------
   Content transitions
   --------------------------------------------------------------------------
   Switching view replaces one block with another. Without this the swap is
   instant and the eye has nothing to follow, which reads as a page reload —
   the one thing this homepage goes out of its way not to do.

   Opacity and a 4px rise only. No scale, no blur, nothing that would force a
   large subtree through a filter, and short enough that it is over before a
   reader could call it waiting.
   -------------------------------------------------------------------------- */

@keyframes fn-view-in {
  from { opacity: 0; transform: translate3d(0, 4px, 0); }
  to   { opacity: 1; transform: none; }
}

@keyframes fn-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

html[data-fn-home-view="feed"] .fn-ui #fnChronoFeed,
html[data-fn-home-view="quick"] .fn-ui .fn-quick-block {
  animation: fn-view-in 220ms var(--fn-ease) both;
}

/* The ראשי view is the largest subtree on the page. It gets opacity only:
   a transform on a composition that tall is a full-size layer on a device
   that may not have the memory bandwidth for one. */
html:not([data-fn-home-view]) .fn-ui .fn-composed-home,
html[data-fn-home-view="editorial"] .fn-ui .fn-composed-home {
  animation: fn-fade-in 180ms var(--fn-ease) both;
}


/* --------------------------------------------------------------------------
   Reduced motion
   --------------------------------------------------------------------------
   The thumb still MOVES — it is the thing that says what is selected — it
   just arrives without travelling. Everything else stops.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .fn-ui .fn-slider__thumb {
    transition: none;
  }

  .fn-ui .fn-view-switch__opt,
  .fn-ui .fn-data-segment__option,
  .fn-ui .fn-data-tabs > li > a,
  .fn-ui .fn-data-metric__trigger {
    transition: none;
  }

  .fn-ui .fn-view-switch__opt:active,
  .fn-ui .fn-data-segment__option:active,
  .fn-ui .fn-data-tabs > li > a:active,
  .fn-ui .fn-data-metric__trigger:active {
    transform: none;
  }

  html[data-fn-home-view="feed"] .fn-ui #fnChronoFeed,
  html[data-fn-home-view="quick"] .fn-ui .fn-quick-block,
  html:not([data-fn-home-view]) .fn-ui .fn-composed-home,
  html[data-fn-home-view="editorial"] .fn-ui .fn-composed-home {
    animation: none;
  }
}
