/* ============================================================
   NBI ERP — interaction & motion layer
   Interaction ideas 02-21 (interaction-ideas.md). Layout and the
   design system live in nbi-erp.css and app.css; this file holds
   only motion, hover behaviour and the surfaces those need.

   TWO STANDING RULES, both learned the hard way:

   1. EVERY animation here is disabled under prefers-reduced-motion.
      No exceptions, no "this one is subtle enough".

   2. A reduced-motion block that changes background-image MUST also
      re-specify background-size AND background-position. Dropping
      from two layers to one truncates the base rule's comma lists to
      their FIRST value — sized and positioned for the travelling
      highlight — which parks the remaining layer off-screen. That is
      what hid the greeting entirely on item 00. It reads as correct
      in a diff and only the browser shows it.
   ============================================================ */

/* ---------- 02 · Command Center tiles assemble on entry ----------
   LOAD ONLY. The shell re-renders wholesale on every state change
   (account menu, nav menu, route), so a bare entry animation on
   .app-tile would replay on each one and turn a first-paint flourish
   into a twitch. The `intro` class is applied by renderHome for the
   FIRST home paint of a page load only; --i carries the tile index so
   the stagger is data, not a stack of nth-child rules. */
@keyframes nbiTileIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
/* FILL DIRECTION IS LOAD-BEARING — `backwards`, never `forwards`.

   A filled animation wins over normal declarations in the cascade. With
   `forwards` this rule kept applying its end state (transform: none) after it
   finished, and `.app-grid.intro .app-tile` (three classes) outranks
   `.app-tile:hover` (one class, one pseudo-class), so the item 04 hover lift
   was silently dead on the Command Center for as long as the grid still
   carried .intro. Nothing about the CSS looks wrong; the tile just does not
   move under the cursor.

   `backwards` fills the FROM state during the stagger delay — which is what
   stops the flash of un-animated tiles — and fills nothing once the animation
   is over, so the tile goes back to being governed by its own rules. Note this
   is also why there is no `opacity: 0` base declaration here: with `backwards`
   it would outlive the animation and leave every tile invisible. */
.app-grid.intro .app-tile {
  animation: nbiTileIn 500ms ease-out backwards;
  animation-delay: calc(var(--i, 0) * 40ms);
}
@media (prefers-reduced-motion: reduce) {
  /* `animation: none` alone. Do NOT add transform/opacity resets here: they
     would be normal declarations at this selector's higher specificity and
     would kill the item 04 hover lift for reduced-motion users, which is a
     motion preference, not a request for a dead interface. */
  .app-grid.intro .app-tile { animation: none; }
}

/* ---------- 11a · Ambient depth behind the hero ----------
   A conic gradient at 7% opacity turning once every 40 seconds. At that speed
   nothing is ever seen to move; what it does is stop the page reading as a
   static print, because the ground is never quite the same twice.

   Built only from colours already in the system — primary, cyan, blue tint —
   and it rotates by transform, so no gradient is recomputed per frame. It sits
   before .home-main in the DOM and .home-screen already clips overflow, so it
   is behind the greeting and cannot escape its box.

   SUBTLE BY DESIGN. If this reads as noticeable it is too strong: lower the
   opacity, do not speed it up. */
@keyframes nbiAura { to { transform: rotate(360deg); } }
.home-aura {
  position: absolute; top: -340px; left: -220px; width: 940px; height: 940px;
  border-radius: 50%; pointer-events: none; opacity: 0.07; z-index: 0;
  background: conic-gradient(from 0deg,
    var(--nbi-primary), var(--nbi-cyan), var(--nbi-blue-tint),
    var(--nbi-cyan), var(--nbi-primary));
  animation: nbiAura 40s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  /* The gradient stays — it is depth, not motion. Only the rotation stops.
     Nothing here touches background-image, so the multi-layer trap in the
     header does not apply; the whole declaration is the animation. */
  .home-aura { animation: none; }
}

/* ---------- 11b · The top bar firms up once the page moves ----------
   Below 8px of scroll the bar is part of the page. Past it, the bar is holding
   a boundary and says so with a firmer rule and a shallow shadow.

   The class goes on <body>, not on .topnav: the shell re-renders wholesale on
   every state change and any class set directly on the nav would be thrown
   away on the next render, leaving the bar flat halfway down a long list. body
   survives every render this app performs. */
.topnav { transition: border-bottom-color 160ms ease, box-shadow 160ms ease; }
body.scrolled .topnav {
  border-bottom-color: rgba(29,71,174,0.20);
  box-shadow: 0 6px 16px rgba(18,47,120,0.05);
}
@media (prefers-reduced-motion: reduce) {
  /* The firmer border still applies — it is information about position, not
     decoration. It simply arrives without the fade. */
  .topnav { transition: none; }
}

/* ---------- 17 · Record detail opens in a slide-over ----------
   Deliberately GENERIC. Buyer Master is the only list screen that exists today,
   but nothing here is about buyers: any list that wants a detail sheet renders
   its own content inside .sheet and gets the same behaviour. The classes are
   .sheet / .sheet-backdrop, never .buyer-anything.

   The list stays mounted behind the sheet, so returning to it is not a
   navigation and there is no scroll position to lose. The backdrop is blurred
   rather than blacked out for the same reason: the record you came from should
   still be legible as context. */
@keyframes nbiSheetIn   { from { transform: translateX(100%); } }
@keyframes nbiSheetFade { from { opacity: 0; } }
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(16,24,40,0.28);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: nbiSheetFade 200ms ease-out;
}
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: 460px; max-width: 100vw;
  display: flex; flex-direction: column;
  background: rgba(255,255,255,0.90);
  backdrop-filter: var(--nbi-glass-blur); -webkit-backdrop-filter: var(--nbi-glass-blur);
  border-left: 1px solid rgba(255,255,255,0.95);
  box-shadow: -20px 0 56px rgba(18,47,120,0.16);
  animation: nbiSheetIn 240ms cubic-bezier(0.2, 0.7, 0.3, 1);
}
/* ENTRY-ONLY (owner ruling, 26-Aug): the shell rebuilds root.innerHTML on
   every re-render, recreating this node — without this class each loader
   completion replayed the slide-in and the sheet read as flickering. The
   shell adds .sheet-entered on every render AFTER the first for a route. */
.sheet.sheet-entered, .sheet-backdrop.sheet-entered { animation: none; }

/* THE SHEET IS A CONTAINER (owner ruling, 26-Aug — the 4a layout finding):
   a 460px sheet is a deliberate choice, and the grids inside it must ask
   THEIR CONTAINER how wide it is, not the window — the 800px viewport media
   query never fires inside a narrow sheet on a wide monitor. This fixes the
   buyer detail identically, which shared the fault unopened. */
@container (max-width: 700px) {
  .field-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-page { padding: 14px 16px 32px; }
}

.sheet-head {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  padding: 12px 16px; border-bottom: 1px solid var(--nbi-line-100);
}
.sheet-title { font-size: var(--fs-card-title); font-weight: 700; color: var(--nbi-ink-900); }
.sheet-hint { margin-left: auto; font-size: var(--fs-meta); color: var(--nbi-ink-400); }
.sheet-close {
  width: 28px; height: 28px; flex-shrink: 0; border: 1px solid var(--nbi-line-200);
  background: #fff; border-radius: var(--r-sm); cursor: pointer; font-family: inherit;
  font-size: 15px; line-height: 1; color: var(--nbi-ink-600);
  display: grid; place-items: center;
}
.sheet-close:hover { border-color: var(--nbi-cyan); color: var(--nbi-ink-900); }
/* The sheet is the only thing that scrolls while it is open — the list behind
   keeps its own scroll position untouched, which is the entire point. */
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; container-type: inline-size; }
/* The DEMO DATA banner outranks the sheet on purpose. "These are not real
   records" is a safety marker and must never be covered by a panel that is
   showing one of those records — so the sheet starts below it rather than
   winning the z-index argument. 29px is the banner's own height: 7px padding
   top and bottom around a 15px line at --fs-body-s. */
body.demo-on .sheet, body.demo-on .sheet-backdrop { top: 29px; }
.sheet-body .mod-page { padding: 16px; }
@media (max-width: 520px) { .sheet { width: 100vw; } }
@media (prefers-reduced-motion: reduce) {
  /* The sheet still appears and still covers; it simply does not slide.
     No background-image is involved, so nothing to restate. */
  .sheet, .sheet-backdrop { animation: none; }
}

/* ---------- 20 · The login rings orbit ----------
   Nothing new is drawn. The dashed rings and the module pills were already on
   the screen; they simply start turning. Inner ring 64s clockwise, outer ring
   96s anticlockwise — opposite directions, and two durations that are not
   multiples of one another, so the two rings never settle into a pattern.

   THE LOCKUP AND THE FORM DO NOT MOVE. .login-card and the logo are siblings of
   the rings, not children, so no transform here can reach them. That is the
   whole reason the pills hang off the rings rather than the rings being a
   backdrop behind one big rotating layer.

   HOW A PILL STAYS UPRIGHT. Two counter-rotations, and they do different jobs:

     1. In .login-pill: rotate(--a) translateY(-r) rotate(calc(-1 * --a)) puts
        the pill at its angle on the ring and cancels the tilt that placing it
        there introduced. Static — it is layout, not motion.
     2. Here: the label spins against its own ring, same duration, opposite
        direction, so the ring's rotation is cancelled exactly. Same duration is
        not a nicety — a 1% mismatch is a full turn of drift every 100
        revolutions, and the text would slowly roll over.

   The ring keyframes restate translate(-50%, -50%) in BOTH steps. The centring
   lives in the transform, so a keyframe that sets only rotate() would drop it
   and fling the ring a quarter-screen down and right on the first frame. */
@keyframes nbiRingCW   { from { transform: translate(-50%, -50%) rotate(0deg); }
                         to   { transform: translate(-50%, -50%) rotate(360deg); } }
@keyframes nbiRingCCW  { from { transform: translate(-50%, -50%) rotate(0deg); }
                         to   { transform: translate(-50%, -50%) rotate(-360deg); } }
@keyframes nbiLabelCCW { from { transform: rotate(0deg); }  to { transform: rotate(-360deg); } }
@keyframes nbiLabelCW  { from { transform: rotate(0deg); }  to { transform: rotate(360deg); } }

.login-ring.r1 { animation: nbiRingCW  64s linear infinite; }
.login-ring.r2 { animation: nbiRingCCW 96s linear infinite; }
.login-ring.r1 .login-pill-label { animation: nbiLabelCCW 64s linear infinite; }
.login-ring.r2 .login-pill-label { animation: nbiLabelCW  96s linear infinite; }

@media (prefers-reduced-motion: reduce) {
  /* Both rings stop dead and the pills stay exactly where they sit at rest.
     The label counter-rotation stops too — it exists only to cancel a ring
     rotation that is no longer happening, and leaving it running would spin
     every label on a stationary ring, which is worse than the thing being
     avoided. */
  .login-ring.r1, .login-ring.r2,
  .login-ring.r1 .login-pill-label, .login-ring.r2 .login-pill-label { animation: none; }
}
