/* ---------------------------------------------------------------------------
   UlricCMS FEEL LAYER (2026-11-16). One small sheet shared by the public site,
   the CMS admin and Rosie OS, emitted by feel_tags() in core/helpers.php with
   its partner feel.js. Siblings: motion.css (scroll reveals), nav-busy.js (the
   top bar and the pressed control on a page load).

   What it owns:
     - the easing and duration tokens every new transition uses
     - press states (a 0.97 settle) and a visible focus ring
     - the cross-document page transition (a short fade, nothing more)
     - skeleton blocks (.skel) and the wireframe drawn over a page that is
       being left (.feel-skel, built by feel.js)
     - button states: data-state="pending|saved|failed" or aria-busy
     - the follow transform for swipe (prev/next) and sheet drag, and the
       pull-to-refresh pill

   THE RULE: NOTHING HERE HIDES CONTENT. The wireframe is an overlay above a
   dimmed page and is removed whenever the load stops (nav-busy clears
   html[data-navb]), on pageshow, and after 8 s whatever happened. Under
   prefers-reduced-motion every transform is off; opacity changes stay.
--------------------------------------------------------------------------- */

:root {
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --ease-in-out: cubic-bezier(.77, 0, .175, 1);
  --ease-drawer: cubic-bezier(.32, .72, 0, 1);
  --dur-press: 120ms;
  --dur-pop: 200ms;
  --dur-sheet: 320ms;
  --feel-skel-a: rgba(127, 127, 127, .10);
  --feel-skel-b: rgba(127, 127, 127, .20);
}

/* ---------- a filled red under white text ----------
   --danger is made to be read AS text, so in dark it is a light red (#F0574F)
   that white sits on at 3.4:1. A count badge or a "Delete, sure?" button is a
   red ground UNDER white text and takes this pair instead, one deep red in
   every look and mode (white on #B3261E is 6.5:1). */
:root { --danger-fill: #B3261E; --on-danger-fill: #FFFFFF; }

/* ---------- placeholders ----------
   rosie.css paints placeholders --mute only inside .rosie and on textareas, so
   every other field in the dashboard and the OS fell to the browser's own grey
   (#757575), which is 3.8:1 on the light field and 4.0:1 on the dark one.
   --mute clears 4.5:1 on --sunken and --surface in every theme and mode.
   :where() keeps this at element weight, so a screen's own rule still wins. */
:where(body.os-tokens) ::placeholder { color: var(--mute); opacity: 1; }

/* ---------- chart tokens (--viz-*) ----------
   One set for every chart drawn in the site, the admin and the OS, so a chart
   follows Classic, Glass light and Glass dark (and a live switch) with no
   chart code of its own: stroke="var(--viz-line)", fill="var(--viz-area)".
     line / line-2  the series and its comparison (3:1+ on their ground)
     area           the fill under a line
     grid           hairlines; decorative, never the only cue
     axis           axis and label TEXT (4.5:1+, measured on every ground)
     tip-bg/-ink    the tooltip card and its text (13:1+)
   Classic follows html[data-mode]; Glass is keyed by body.os-glass, dark by
   default and light under data-mode="light", the same keys as the glass
   sheets. Measured 2026-11-16 over both gradient ends and the panel tints. */
:root {
  --viz-line: #B94C57; --viz-line-2: #857679; --viz-area: rgb(185 76 87 / .14);
  --viz-grid: rgb(34 37 42 / .12); --viz-axis: #5F565D;
  --viz-tip-bg: #2A2224; --viz-tip-ink: #FFFFFF;
}
html[data-mode="dark"] {
  --viz-line: #D3737C; --viz-line-2: #9B8E90; --viz-area: rgb(211 115 124 / .18);
  --viz-grid: rgb(246 239 239 / .14); --viz-axis: #B4A8AC;
  --viz-tip-bg: #F6EFEF; --viz-tip-ink: #22252A;
}
html:has(body.os-glass) {
  --viz-line: #D3737C; --viz-line-2: #9B8E90; --viz-area: rgb(211 115 124 / .20);
  --viz-grid: rgb(246 239 239 / .16); --viz-axis: #BFB2B6;
  --viz-tip-bg: rgb(38 20 28 / .94); --viz-tip-ink: #F6EFEF;
}
html[data-mode="light"]:has(body.os-glass) {
  --viz-line: #B94C57; --viz-line-2: #857679; --viz-area: rgb(185 76 87 / .16);
  --viz-grid: rgb(34 37 42 / .14); --viz-axis: #5F565D;
  --viz-tip-bg: rgb(255 255 255 / .94); --viz-tip-ink: #22252A;
}

/* ---------- page transition ---------- */
/* Cross-document view transitions (Chromium 126+, Safari 18.2+); browsers
   without them navigate as they always did. A 160 ms crossfade only: a slide
   on every page would be motion for its own sake. It is an opacity change, so
   it stays under reduced motion. */
@view-transition { navigation: auto; }
::view-transition-old(root),
::view-transition-new(root) { animation-duration: 160ms; animation-timing-function: var(--ease-out); }

/* ---------- press states ---------- */
html { -webkit-tap-highlight-color: transparent; }
:where(button, .btn, [role="tab"], .rx-chip, .os-tabs a, .os-chip, .chip):not(:disabled) {
  transition: transform var(--dur-press) var(--ease-out);
}
:where(button, .btn, [role="tab"], .rx-chip, .os-tabs a, .os-chip, .chip):not(:disabled):active {
  transform: scale(.97);
}
:where(a, button, .btn, [role="tab"], summary, input, select, textarea):focus-visible {
  outline: 2px solid var(--accent, var(--rose, #B76E79));
  outline-offset: 2px;
}

/* ---------- button states ---------- */
/* pending: dimmed with three dots after the label; saved and failed: a
   coloured ring that fades after feel.js clears the state (2.4 s). */
:where(button, .btn)[data-state="pending"],
:where(button, .btn)[aria-busy="true"] { cursor: progress; opacity: .75; }
:where(button, .btn)[data-state="pending"]::after {
  content: ""; display: inline-block; width: 1.1em; height: .3em; margin-left: .45em; vertical-align: middle;
  background: radial-gradient(circle closest-side, currentColor 90%, transparent) 0 50% / .3em .3em repeat-x;
  animation: feel-dots 1s steps(4) infinite;
}
:where(button, .btn)[data-state="saved"] { box-shadow: 0 0 0 2px var(--ok, #3F7D5A); transition: box-shadow var(--dur-pop) var(--ease-out); }
:where(button, .btn)[data-state="failed"] { box-shadow: 0 0 0 2px var(--danger, #B3261E); transition: box-shadow var(--dur-pop) var(--ease-out); }
@keyframes feel-dots { from { width: 0; } to { width: 1.2em; } }

/* ---------- skeletons ---------- */
.skel {
  display: block; border-radius: 8px; min-height: 12px;
  background: linear-gradient(90deg, var(--feel-skel-a) 25%, var(--feel-skel-b) 50%, var(--feel-skel-a) 75%) 0 0 / 300% 100%;
  animation: feel-shimmer 1.3s linear infinite;
}
@keyframes feel-shimmer { from { background-position: 100% 0; } to { background-position: -50% 0; } }

/* the wireframe over a page that is being left (feel.js): the old page dims,
   the shape of the next one draws above it. Never display:none on content. */
.feel-leaving { position: relative; }
.feel-leaving > :not(.feel-skel) { opacity: .35; transition: opacity var(--dur-pop) var(--ease-out); }
.feel-skel {
  position: absolute; inset: 0 0 auto 0; z-index: 5; pointer-events: none;
  display: grid; gap: 12px; padding: var(--feel-skel-pad, 16px) 0;
  animation: feel-in var(--dur-pop) var(--ease-out) both;
}
.feel-skel .r { display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: center; }
.feel-skel .r .skel:first-child { width: 40px; height: 40px; border-radius: 50%; }
.feel-skel .r div { display: grid; gap: 8px; }
.feel-skel .h { height: 28px; width: min(320px, 60%); }
.feel-skel .l { height: 12px; }
.feel-skel .l.s { width: 55%; }
.feel-skel .tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 12px; }
.feel-skel .tiles .skel { height: 120px; border-radius: 14px; }
.feel-skel .cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.feel-skel .cal .skel { height: 64px; border-radius: 10px; }
@keyframes feel-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- swipe and sheets ---------- */
[data-swipe-prev], [data-swipe-next] { touch-action: pan-y; }
.os-sheet-h, [data-feel-grab] { touch-action: none; }
.feel-drag { transition: none !important; }
.feel-settle { transition: transform var(--dur-pop) var(--ease-out) !important; }
.feel-sheet-settle { transition: transform var(--dur-sheet) var(--ease-drawer) !important; }

/* ---------- pull to refresh (standalone app only, feel.js) ---------- */
.feel-ptr {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 8px); z-index: 2147482000;
  transform: translate(-50%, -64px); padding: 8px 14px; border-radius: 999px; min-height: 36px;
  display: flex; align-items: center; gap: 8px; pointer-events: none;
  background: var(--surface, rgba(255, 255, 255, .92)); color: var(--text, #222);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .16); font: 600 13px/1.2 Inter, system-ui, sans-serif;
}
.feel-ptr.ready { color: var(--accent, var(--rose, #B76E79)); }
.feel-ptr.go { transform: translate(-50%, 0); transition: transform var(--dur-pop) var(--ease-out); }

/* ---------- toast (feel.js Feel.toast) ---------- */
.feel-toast {
  position: fixed; left: 50%; z-index: 2147482000; max-width: min(92vw, 440px);
  /* above the phone dock (the bar and Rosie over it, --dock-top in os.css and
     admin-ux.css, which already counts the safe area); elsewhere off the edge */
  bottom: calc(var(--dock-top, env(safe-area-inset-bottom, 0px)) + 16px);
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  padding: 12px 16px; border-radius: 14px; text-align: center;
  background: var(--text, #2A2224); color: var(--surface, #fff);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .22); font: 500 14px/1.4 Inter, system-ui, sans-serif;
  transition: opacity var(--dur-pop) var(--ease-out), transform var(--dur-pop) var(--ease-out);
}
.feel-toast.in { opacity: 1; transform: translate(-50%, 0); }

/* ---------- the look and the mode (modules/os/look.php + assets/look.js) ----------
   Two segmented controls in the app's profile menu and the dashboard's menu.
   Colours come from the frame's own tokens, so they are right in Classic,
   Glass light and Glass dark alike; every button is a 44px target. */
.feel-seg-g { display: grid; gap: 10px; padding: 10px 12px; }
.feel-seg { margin: 0; display: grid; grid-template-columns: 3.4em 1fr; align-items: center; gap: 8px; }
.feel-seg-l { font: 600 12px/1.2 Inter, system-ui, sans-serif; letter-spacing: .04em; color: var(--mute, var(--rail-mute, #5F565D)); }
.feel-seg-b {
  display: flex; padding: 3px; gap: 2px; border-radius: 12px; min-width: 0;
  background: color-mix(in srgb, currentColor 7%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 16%, transparent);
}
.feel-seg-b button {
  flex: 1 1 0; min-width: 0; min-height: 44px; padding: 0 8px; border: 0; border-radius: 9px;
  background: transparent; color: inherit; font: 500 13.5px/1 Inter, system-ui, sans-serif; cursor: pointer;
  transition: background-color var(--dur-pop) var(--ease-out), color var(--dur-pop) var(--ease-out);
}
.feel-seg-b button[aria-pressed="true"] { background: var(--accent, #B94C57); color: var(--on-accent, #fff); font-weight: 600; }
@media (hover: hover) {
  .feel-seg-b button[aria-pressed="false"]:hover { background: color-mix(in srgb, currentColor 9%, transparent); }
}
/* the dashboard's rail folded to icons has no room for words: the controls
   wait for the rail to open (one press), and Cmd-K still has them */
body.anav-mini aside .feel-seg-g { display: none; }
aside .feel-seg-l { color: var(--rail-mute, var(--mute)); }
/* Today's look-dependent blocks: wrappers that never take part in layout */
[data-look-slot] { display: contents; }

/* the crossfade of a live switch: a same-document View Transition, longer
   and softer than a page change; with no View Transitions, a short colour
   transition on everything while html.look-fade is on (look.js removes it
   after 300 ms, so it never slows normal use) */
html.look-swap::view-transition-old(root),
html.look-swap::view-transition-new(root) { animation-duration: 260ms; animation-timing-function: var(--ease-out); }
/* the View Transition IS the fade, so no element runs its own colour
   transition under it. Left on, a control inside a closed <details> (the
   brief's "All of them" chip, a folded row's ghost button) started its fade
   while its subtree was skipped, and the browser never ticked it: the chip
   kept the old mode's colours until a reload (Bea, 2026-11-16). */
html.look-swap *, html.look-swap *::before, html.look-swap *::after { transition: none !important; }
html.look-fade, html.look-fade *, html.look-fade *::before {
  transition: background-color 260ms var(--ease-out), color 260ms var(--ease-out), border-color 260ms var(--ease-out),
              box-shadow 260ms var(--ease-out), fill 260ms var(--ease-out), stroke 260ms var(--ease-out) !important;
}

@media (prefers-reduced-motion: reduce) {
  .feel-toast { transform: translate(-50%, 0); }
  :where(button, .btn, [role="tab"], .rx-chip, .os-tabs a, .os-chip, .chip):active { transform: none; }
  .skel, :where(button, .btn)[data-state="pending"]::after { animation: none; }
  .feel-settle, .feel-sheet-settle { transition: none !important; }
  .feel-ptr.go { transition: none; }
  .feel-seg-b button { transition: none; }
}

/* ---------- print: dark ink on white paper, in either look ----------
   The admin and the app only (body.os-tokens), never the public site.
   feel.js prints a dark page in its light mode (beforeprint flips
   html[data-mode] for the length of the print, afterprint puts it back), so
   Classic prints as Classic light and Glass as Glass light. What is left for
   this block: the paper itself, the gradient and the frost, the charts, and
   the floating furniture nobody wants on paper. The html[data-mode="dark"]
   rules are the fallback for a print that never sent beforeprint: whatever
   the theme painted, the ink turns dark and the grounds clear. */
@media print {
  html:has(body.os-tokens), body.os-tokens { background: #FFFFFF !important; color-scheme: light; }
  body.os-tokens.os-glass::before { display: none !important; }
  body.os-tokens *, body.os-tokens *::before, body.os-tokens *::after {
    -webkit-backdrop-filter: none !important; backdrop-filter: none !important;
  }
  html:has(body.os-tokens) {
    --viz-line: #B94C57 !important; --viz-line-2: #857679 !important; --viz-area: rgb(185 76 87 / .14) !important;
    --viz-grid: rgb(34 37 42 / .12) !important; --viz-axis: #5F565D !important;
    --viz-tip-bg: #2A2224 !important; --viz-tip-ink: #FFFFFF !important;
  }
  body.os-tokens .feel-toast, body.os-tokens .feel-ptr, body.os-tokens .feel-skel,
  body.os-tokens .ad-me { display: none !important; }
  html[data-mode="dark"] body.os-tokens * {
    color: #22252A !important; background-color: transparent !important;
    border-color: rgb(34 37 42 / .22) !important; text-shadow: none !important;
  }
  html[data-mode="dark"] body.os-tokens.os-glass *::before { background: none !important; }
}
