/* =============================================================================
   v1.325 INTERACT — click, hover, focus and loading feedback for every shell: staff pages, FieldApp, the customer
   portal, the partner / supplier / agent portals and the marketing site (approved: ui-mockups/PROPOSAL.md section 2).
   Calm: nothing lifts or bounces, a direct response stays under 240 ms, and prefers-reduced-motion keeps every state
   (bar, pending, busy, changed) while dropping the movement. Tokens only (sr/tokens.css); the marketing site, which
   has no kit tokens, sets --sr-progress itself (marketing-visuals.css). Pairs with assets/js/sr-interact.js.
   motion-rules.css (v1.234) and admin-motion.css stay as they are; this file adds the states they do not have.
   On staff pages it loads after motion-rules.css (includes/admin_footer.php), so its skeleton wins.
   ============================================================================= */

/* ---------- I1. the navigation bar (its CSS used to live in motion.css only, which moved pages do not load) ----------
   Teal, not orange (orange stays the main action). Hidden for a quick page: it fades in only when the next page has not
   arrived after 120 ms, then trickles toward 92 % and completes on pageshow. */
.page-progress-bar {
  --sr-progress: var(--sr-teal-400);
  position: fixed; top: 0; left: 0; z-index: 10070; height: 3px; width: 0; margin: 0;
  pointer-events: none; opacity: 0; border-radius: 0 2px 2px 0;
  background: var(--sr-progress);
  transition: opacity var(--sr-dur-fast, 120ms) linear;
}
[data-mode="dark"] .page-progress-bar { --sr-progress: var(--sr-teal-300); }
@media (prefers-color-scheme: dark) { [data-mode="auto"] .page-progress-bar { --sr-progress: var(--sr-teal-300); } }
.page-progress-bar.is-active {
  opacity: 1; transition: opacity 80ms linear 120ms;
  animation: srTrickle 12s cubic-bezier(0.1, 0.7, 0.2, 1) 120ms both;
}
.page-progress-bar.is-done {
  opacity: 0; width: 100%; animation: none;
  transition: width 160ms var(--sr-ease-out, ease-out), opacity 200ms linear 120ms;
}
@keyframes srTrickle { 0% { width: 0; } 8% { width: 35%; } 40% { width: 70%; } 100% { width: 92%; } }

/* ---------- I2. pressed, then pending ----------
   Pressed: a row tints and a card dips to 98.5 % for the moment the finger is down (no lift, no bounce).
   Pending: what was tapped keeps a small spinner until the next page paints (sr-interact.js), so a slow page reads as
   "working", not "frozen". Busy: a sent form's button keeps its label, shows a spinner and takes no second press. */
.sr-table tbody tr[data-href], a.sr-card, a.sr-kpi, .bd-card {
  transition: background-color var(--sr-dur-fast) var(--sr-ease), border-color var(--sr-dur-fast) var(--sr-ease),
    box-shadow var(--sr-dur-fast) var(--sr-ease), transform var(--sr-dur-fast) var(--sr-ease-out);
}
a.sr-card:active, a.sr-kpi:active, .bd-card:active { transform: scale(0.985); }
.sr-table tbody tr[data-href]:active > td, .sr-table tbody tr.is-pending > td { background: var(--sr-teal-50); }
[data-mode="dark"] .sr-table tbody tr[data-href]:active > td, [data-mode="dark"] .sr-table tbody tr.is-pending > td { background: var(--sr-surface-2); }
@media (prefers-color-scheme: dark) { [data-mode="auto"] .sr-table tbody tr[data-href]:active > td, [data-mode="auto"] .sr-table tbody tr.is-pending > td { background: var(--sr-surface-2); } }
:where(.btn--primary, .mobile-cta-bar .btn):active { transform: scale(0.985); } /* the marketing CTA: zero specificity, its own rules win */

.sr-pending-spin, tr.is-pending > td:first-child::after, :is(.sr-btn, [data-sr-busy])[aria-busy="true"]:not(.sr-is-busy)::after {
  content: ""; display: inline-block; flex: none; width: 0.9em; height: 0.9em; margin-left: 0.5em; vertical-align: -0.12em;
  border-radius: 50%; border: 2px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor;
  animation: srSpin 700ms linear infinite;
}
.sr-pending-spin { color: var(--sr-link, currentColor); }
tr.is-pending > td:first-child::after { color: var(--sr-link); }
:is(.sr-btn, [data-sr-busy])[aria-busy="true"] { pointer-events: none; cursor: progress; }
:is(.sr-btn, [data-sr-busy])[aria-busy="true"]:not(.sr-is-busy) { opacity: 0.85; }
@keyframes srSpin { to { transform: rotate(360deg); } }

/* ---------- I3. hover and focus: one quiet language ----------
   Hover = a stronger border and the level-2 shadow on cards, the surface-2 tint on rows; focus = the 2 px --sr-focus ring.
   Nothing moves on hover (motion-rules.css already stops the old lifts on .card / .bento-tile; this covers the kit). */
@media (hover: hover) {
  a.sr-card:hover, a.sr-kpi:hover, .bd-card:hover { border-color: var(--sr-line-strong); box-shadow: var(--sr-shadow-2); transform: none; }
  .sr-list > li:has(> a:hover) { background: var(--sr-surface-2); }
}
:where(.sr-table tbody tr[data-href], .bd-card, a.sr-card, a.sr-kpi):focus-visible { outline: 2px solid var(--sr-focus); outline-offset: 2px; }
.sr-table tbody tr:focus-within > td { background: var(--sr-surface-2); } /* the row whose link has the keyboard */

/* ---------- I4. skeletons on the tokens ----------
   motion-rules.css draws .sr-skel in fixed light greys, so it glowed white in dark mode; this one follows the theme
   (it loads after motion-rules.css). For panels that wait on a fetch: the control-room cards, the notification list,
   charts. A box with aria-busy="true" hides its .sr-skel-swap content while the skeleton shows. */
.sr-skel {
  display: block; height: 14px; border-radius: var(--sr-radius-sm);
  background: linear-gradient(90deg, var(--sr-surface-2) 0, var(--sr-line) 50%, var(--sr-surface-2) 100%);
  background-size: 300% 100%; animation: srSkelTok 1.4s ease-in-out infinite;
}
.sr-skel--line { height: 12px; }
.sr-skel--title { height: 18px; width: 40%; }
.sr-skel--block { height: 54px; }
.sr-skel--pill { height: 22px; width: 72px; border-radius: var(--sr-radius-pill); }
@keyframes srSkelTok { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
[aria-busy="true"] > .sr-skel-swap { display: none; }

/* ---------- I5. something changed: a row or card that was just saved or moved glows its success tint once ----------
   srFlash(el) or data-sr-flash on arrival (sr-interact.js). Reduced motion: a still green edge for a moment instead. */
.sr-flash { animation: srFlash 900ms var(--sr-ease-out) 1; }
@keyframes srFlash { 0% { background-color: var(--sr-success-bg); } 100% { background-color: transparent; } }

@media (prefers-reduced-motion: reduce) {
  .sr-flash { animation: none; box-shadow: inset 3px 0 0 var(--sr-success-ink); }
  .sr-skel { animation: none; }
  .page-progress-bar.is-active { animation: none; width: 60%; }
  .page-progress-bar.is-done { transition: opacity 200ms linear; }
  a.sr-card:active, a.sr-kpi:active, .bd-card:active, :where(.btn--primary, .mobile-cta-bar .btn):active { transform: none; }
  .sr-pending-spin, tr.is-pending > td:first-child::after, :is(.sr-btn, [data-sr-busy])[aria-busy="true"]:not(.sr-is-busy)::after { animation: none; border-color: currentColor; opacity: 0.5; }
}
@media print { .page-progress-bar { display: none !important; } }
