/* NOISE motion & finish (proposed, 2026-10-31).
   One presentation layer shared by every web workspace, the phone Lab and the Field app.
   It never changes data, research values, layout geometry or control order: it only adds
   cross-page continuity, press/hover response, dialog and menu entrances, label tips for
   icon-only controls and a quiet acoustic ambience in the workspace head.
   Loaded render-blocking in each document so both sides of a navigation opt in to the
   view transition. Every selector is wrapped in :where() so page styles always win.
   Motion follows the shared display preference (html[data-motion]) and the system
   reduced-motion setting; "reduced" keeps colour/opacity feedback and drops movement. */

@view-transition { navigation: auto; }

:root {
  --nm-out: cubic-bezier(.22, 1, .36, 1);
  --nm-in-out: cubic-bezier(.65, 0, .35, 1);
  /* A lightly damped spring (about 2% overshoot), close to the system "smooth" curves. */
  --nm-spring: linear(0, .0105, .0405 2.2%, .1576 4.6%, .3393 7.4%, .5506 10.7%, .7457 14.4%,
    .8913 18.4%, .9839 22.9%, 1.0193 26.6%, 1.0306 30.7%, 1.0247 35.6%, 1.0083 43.6%, .9995 53%, 1);
  --nm-fast: 140ms;
  --nm-base: 240ms;
  --nm-slow: 420ms;
}

/* ---------- Typography finish ---------- */
:where(html) {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
  font-optical-sizing: auto;
  -webkit-tap-highlight-color: transparent;
}
:where(h1, h2, h3, h4) { text-wrap: balance; }
:where(p, li, dd, figcaption, small) { text-wrap: pretty; }
:where(output, time, [data-numeric], .metric-value, td, th) { font-variant-numeric: tabular-nums; }

/* ---------- Scrollbars: thin, theme-aware, out of the way ---------- */
:where(html) { scrollbar-color: color-mix(in oklab, CanvasText 26%, transparent) transparent; }
:where(html[data-theme="dark"], html[data-lab-theme="dark"]) { scrollbar-color: rgb(255 255 255 / .22) transparent; }
:where(html[data-theme="light"], html[data-lab-theme="light"]) { scrollbar-color: rgb(0 0 0 / .24) transparent; }
:where(*) { scrollbar-width: thin; }

/* ---------- Press and hover response ---------- */
:where(button, [role="button"], summary, .btn, a[class], select, label:has(> input[type="checkbox"], > input[type="radio"])) {
  touch-action: manipulation;
}
@media (prefers-reduced-motion: no-preference) {
  :where(html:not([data-motion="reduced"])) :where(button, [role="button"], summary, .btn) {
    transition-property: background-color, border-color, color, box-shadow, opacity, scale, filter;
    transition-duration: var(--nm-base);
    transition-timing-function: var(--nm-out);
  }
  :where(html:not([data-motion="reduced"])) :where(button, [role="button"], .btn):where(:not(:disabled, [aria-disabled="true"])):active {
    scale: .97;
    transition-duration: 70ms;
  }
  /* Wide rows and cards press in place instead of shrinking visibly. */
  :where(html:not([data-motion="reduced"])) :where(summary, a[class], [role="option"], [role="tab"], [role="menuitem"]):where(:not([aria-disabled="true"])):active {
    filter: brightness(.94);
  }
}
:where(button, [role="button"], summary, .btn, a[class], select, input, textarea):focus-visible {
  outline-offset: 2px;
}
@media (prefers-reduced-motion: no-preference) {
  :where(html:not([data-motion="reduced"])) :where(button, [role="button"], summary, .btn, a[class], select, input, textarea):focus-visible {
    animation: nm-ring var(--nm-slow) var(--nm-spring);
  }
}
@keyframes nm-ring { from { outline-offset: 6px; } }

/* ---------- Dialogs, popovers, menus ---------- */
@media (prefers-reduced-motion: no-preference) {
  :where(html:not([data-motion="reduced"])) :where(dialog[open]) {
    animation: nm-surface-in var(--nm-slow) var(--nm-spring);
  }
  :where(html:not([data-motion="reduced"])) :where(dialog[open])::backdrop {
    animation: nm-fade-in var(--nm-base) var(--nm-out);
  }
  :where(html:not([data-motion="reduced"])) :where([popover]:popover-open:not(.nm-tip)) {
    animation: nm-pop-in var(--nm-base) var(--nm-out);
  }
  :where(html:not([data-motion="reduced"])) :where(details[open] > :not(summary)) {
    animation: nm-reveal var(--nm-base) var(--nm-out);
  }
  :where(html:not([data-motion="reduced"])) :where([role="alert"], [role="status"]:not(:empty), .toast, .notice) {
    animation: nm-reveal var(--nm-base) var(--nm-out);
  }
}
@media (prefers-reduced-motion: reduce) {
  :where(html:not([data-motion="full"])) :where(dialog[open], [popover]:popover-open) { animation: nm-fade-in var(--nm-fast) linear; }
}
:where(html[data-motion="reduced"]) :where(dialog[open], [popover]:popover-open) { animation: nm-fade-in var(--nm-fast) linear; }
/* Views and tab panels fade in as they appear (opacity only: no lingering transform,
   so fixed-position sheets inside them keep their geometry). */
@media (prefers-reduced-motion: no-preference) {
  :where(html:not([data-motion="reduced"])) :where(.content-view:not([hidden]), [role="tabpanel"]:not([hidden]), [data-sidebar-panel]:not([hidden])) {
    animation: nm-view-in 280ms var(--nm-out) backwards;
  }
}
@keyframes nm-view-in { from { opacity: 0; } }
@keyframes nm-surface-in { from { opacity: 0; scale: .965; translate: 0 10px; } }
@keyframes nm-pop-in { from { opacity: 0; scale: .98; translate: 0 -4px; } }
@keyframes nm-reveal { from { opacity: 0; translate: 0 -3px; } }
@keyframes nm-fade-in { from { opacity: 0; } }

/* ---------- Cross-page continuity ---------- */
::view-transition-group(root) { animation-duration: var(--nm-slow); }
/* The old page stays opaque underneath while the new one rises in, so no frame shows bare canvas. */
::view-transition-old(root) { animation: nm-hold var(--nm-slow) linear both; mix-blend-mode: normal; }
::view-transition-new(root) { animation: nm-enter var(--nm-slow) var(--nm-out) both; mix-blend-mode: normal; }
/* Persistent chrome holds still while the task area changes beneath it. */
:where(.wc-head, .lab-top, .shell-top, #appShell > header) { view-transition-name: nm-head; }
:where(.nm-rail-pill.nm-primary) { view-transition-name: nm-rail-pill; }
::view-transition-group(nm-head) { animation-duration: var(--nm-base); }
::view-transition-old(nm-head), ::view-transition-new(nm-head) { animation-duration: var(--nm-base); }
::view-transition-group(nm-rail-pill) { animation-duration: var(--nm-slow); animation-timing-function: var(--nm-spring); }
::view-transition-old(nm-rail-pill) { animation: none; opacity: 0; }
::view-transition-new(nm-rail-pill) { animation: none; }
@keyframes nm-hold { from, to { opacity: 1; } }
@keyframes nm-enter { from { opacity: 0; translate: 0 12px; } }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation-duration: 1ms !important; animation-delay: 0s !important; }
}
:root[data-motion="reduced"]::view-transition-group(*),
:root[data-motion="reduced"]::view-transition-old(*),
:root[data-motion="reduced"]::view-transition-new(*) { animation-duration: 1ms !important; }

/* Sliding selection pill for task rails: the active link keeps its text; only its
   highlight travels from the previous page's tab to the new one. */
:where(.nm-rail-host) { position: relative; }
.nm-rail-host { isolation: isolate; }
.nm-rail-pill {
  display: block;
  position: absolute; inset: -1px; z-index: -1; pointer-events: none;
  box-sizing: border-box;
}
.nm-rail-host[data-nm-pill] { background: transparent !important; background-image: none !important; border-color: transparent !important; box-shadow: none !important; }

/* ---------- Label tips for icon-only controls ---------- */
.nm-tip {
  position: fixed; inset: auto; margin: 0; z-index: 2147483000;
  max-width: min(18rem, calc(100vw - 16px));
  padding: .375rem .625rem;
  border: 1px solid rgb(255 255 255 / .12);
  border-radius: .5rem;
  background: rgb(18 20 22 / .86);
  color: #f3f4f1;
  font: 500 .8125rem/1.35 var(--noise-font-ui, "NOISE Inter", "NOISE Han Sans", system-ui, sans-serif);
  letter-spacing: .005em;
  box-shadow: 0 10px 30px -12px rgb(0 0 0 / .55), 0 1px 0 rgb(255 255 255 / .06) inset;
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
  pointer-events: none;
  overflow: visible;
  opacity: 0;
  translate: 0 var(--nm-tip-shift, 4px);
  scale: .96;
  transition: opacity 160ms var(--nm-out), translate 220ms var(--nm-out), scale 220ms var(--nm-out),
              overlay 160ms allow-discrete, display 160ms allow-discrete;
}
.nm-tip[data-side="below"] { --nm-tip-shift: -4px; }
.nm-tip:popover-open, .nm-tip.nm-tip-shown { opacity: 1; translate: 0 0; scale: 1; }
@starting-style { .nm-tip:popover-open { opacity: 0; translate: 0 var(--nm-tip-shift, 4px); scale: .96; } }
:where(html[data-theme="light"], html[data-lab-theme="light"]) .nm-tip {
  background: rgb(252 252 250 / .9); color: #15171a; border-color: rgb(0 0 0 / .1);
  box-shadow: 0 12px 30px -14px rgb(0 0 0 / .35), 0 1px 0 rgb(255 255 255 / .8) inset;
}
:where(html[data-motion="reduced"]) .nm-tip { translate: none; scale: none; transition-duration: 1ms; }

/* ---------- Acoustic ambience in workspace heads ---------- */
.nm-ambience {
  position: absolute; inset: 0; z-index: -1; width: 100%; height: 100%;
  pointer-events: none; opacity: 0;
  transition: opacity 1.2s var(--nm-out);
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 22%, #000 78%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 22%, #000 78%, transparent 100%);
}
.nm-ambience[data-ready] { opacity: 1; }
/* Painted above the head's own background and below every control (negative layer
   inside the head's isolated stacking context); no child is repositioned. */
.nm-ambience-host { isolation: isolate; }
@media print { .nm-ambience, .nm-tip { display: none !important; } }
