/* Shell behaviour of the layouts (loaded after app.css by layout/base.html):
   in-app navigation progress (js/nav.js), the page heading as focus target
   after navigation, and the reserved placeholder of dashboard embeds that
   could not be rendered server-side. Tokens only (see app.css). */

/* The heading receives focus after an in-app navigation (nav.js) so screen
   readers announce the new page; it is not interactive, so no focus ring. */
.app-topbar__title:focus { outline: none; }

/* Menu highlight: one box behind the active entry, as wide as the sidebar
   (edge to edge), moved by nav.js (CSSOM transform/height). It slides only
   while .is-moving (a click); first paint, resize and the mobile menu place
   it without motion. The active entry itself turns transparent above it.
   Without JavaScript the entry keeps its own (inset) background. */
.app-sidebar { isolation: isolate; } /* the box sits behind the entries, above the glass */
.nav-indicator {
  position: absolute; left: 0; right: 0; top: 0; z-index: -1;
  height: 0; opacity: 0; pointer-events: none;
  background: var(--accent-subtle);
}
.nav-indicator.is-on { opacity: 1; }
.nav-indicator.is-moving { transition: transform var(--vt-slide, 260ms) cubic-bezier(0.2, 0.8, 0.2, 1), height var(--vt-slide, 260ms) cubic-bezier(0.2, 0.8, 0.2, 1); }
.has-nav-indicator .nav-link.is-active,
.has-nav-indicator .nav-link[aria-current="page"],
.has-nav-indicator .nav-link.is-indicated,
.has-nav-indicator .nav-link.is-active:hover,
.has-nav-indicator .nav-link[aria-current="page"]:hover,
.has-nav-indicator .nav-link.is-indicated:hover { background: transparent; }
@media (prefers-reduced-motion: reduce) {
  .nav-indicator.is-moving { transition: none; }
}

/* Thin progress bar at the top while the next page loads (shown after
   150 ms, so fast navigations show nothing). */
.nav-progress {
  position: fixed; top: 0; left: 0; z-index: 200;
  width: 100%; height: 3px;
  background: var(--accent);
  transform-origin: 0 50%; transform: scaleX(0);
  opacity: 0; pointer-events: none;
}
.nav-progress.is-active { opacity: 1; animation: nav-progress 8s cubic-bezier(0.1, 0.6, 0.2, 1) forwards; }
@keyframes nav-progress { from { transform: scaleX(0.08); } to { transform: scaleX(0.92); } }
@media (prefers-reduced-motion: reduce) {
  .nav-progress.is-active { animation: none; transform: scaleX(0.6); }
}
#main[aria-busy="true"] { cursor: progress; }

/* Dashboard embed fallback (htmx load): reserve roughly a card's height and
   show skeleton lines instead of an empty strip that grows on load. */
.portal-embed__loading { min-height: 12rem; display: flex; flex-direction: column; gap: var(--space-3); }
.skeleton-line { display: block; height: 0.9rem; width: 100%; background: var(--surface-sunken); border: 1px solid var(--border); }
.skeleton-line--short { width: 60%; }

/* ---------- View transitions ----------
   Findings that shape these rules (Chromium, checked with frame captures):
   - An element with a view-transition-name is a backdrop root: frosted glass
     INSIDE it (cards in #main) loses the photo blur – during the transition
     and, if the name stays, for good. So names exist only while a transition
     runs, the photo is never named (it would leave the backdrop of the root
     snapshot), and only glass panels themselves or blocks without glass
     inside get a name.
   - A named glass element's frost is drawn on its ::view-transition-group,
     not on the snapshot image. Fading only the image would leave a frosted
     rectangle behind (or frost the old content under an invisible new one),
     so entering/leaving parts animate their GROUP (opacity + translate;
     translate composes with the group's own position transform).

   In-app (js/nav.js, <html data-ns-nav="forward|back">): the root snapshot –
   photo, sidebar, top bar – switches to the new state at once (no motion);
   the old content fades out, the new content fades in with a short slide
   (down the menu: up from below; back: down from above). The menu
   highlight and the page heading crossfade.

   Full page loads (login → 2FA → dashboard, logout, PRG within the app):
   cross-document transition. The photo is in both root snapshots and
   identical, so the root crossfade leaves it still. <html data-ns-from> (the
   layout the page came from, js/nav.js) tells entering from staying parts:
   the auth panel slides out to the right (or in, after logout), the sidebar
   and top bar slide in. Browsers without view transitions navigate as before. */
@view-transition { navigation: auto; }

:root {
  --vt-out: 120ms;
  --vt-in: 240ms;
  --vt-delay: 40ms;
  --vt-panel: 280ms;
  --vt-panel-out: 200ms;
  --vt-slide: 260ms;
  --vt-ease-in: cubic-bezier(0.4, 0, 1, 1);
  --vt-ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --vt-k-out-up: ns-vt-out-up;
  --vt-k-out-down: ns-vt-out-down;
  --vt-k-in-up: ns-vt-in-up;
  --vt-k-in-down: ns-vt-in-down;
  --vt-k-out-right: ns-vt-out-right;
  --vt-k-in-right: ns-vt-in-right;
  --vt-k-in-left: ns-vt-in-left;
}
/* Reduced motion: no movement, only a very short crossfade. (app.css's
   global reduced-motion rule does not reach the view-transition tree.) */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(ns-nav-ind) { animation: none !important; } /* the highlight jumps */
  :root {
    --vt-out: 90ms; --vt-in: 90ms; --vt-delay: 0ms; --vt-panel: 90ms; --vt-panel-out: 90ms;
    --vt-k-out-up: ns-vt-fade-out; --vt-k-out-down: ns-vt-fade-out; --vt-k-out-right: ns-vt-fade-out;
    --vt-k-in-up: ns-vt-fade-in; --vt-k-in-down: ns-vt-fade-in; --vt-k-in-right: ns-vt-fade-in; --vt-k-in-left: ns-vt-fade-in;
  }
}

@keyframes ns-vt-fade-out { to { opacity: 0; } }
@keyframes ns-vt-fade-in { from { opacity: 0; } }
@keyframes ns-vt-out-up { to { opacity: 0; translate: 0 -6px; } }
@keyframes ns-vt-out-down { to { opacity: 0; translate: 0 6px; } }
@keyframes ns-vt-in-up { from { opacity: 0; translate: 0 12px; } }
@keyframes ns-vt-in-down { from { opacity: 0; translate: 0 -12px; } }
@keyframes ns-vt-out-right { to { opacity: 0; translate: 32px 0; } }
@keyframes ns-vt-in-right { from { opacity: 0; translate: 32px 0; } }
@keyframes ns-vt-in-left { from { opacity: 0; translate: -24px 0; } }

/* Layers that keep their place: dev badge and photo credit stay above the
   moving content and switch at once. Unnamed they would be painted below
   it; named, groups that exist only in the new view (the entering content)
   are still stacked after them – hence the z-index. */
:root:active-view-transition .dev-badge { view-transition-name: ns-dev; }
:root:active-view-transition .photo-credit { view-transition-name: ns-credit; }
::view-transition-group(ns-dev), ::view-transition-group(ns-credit) { animation: none; z-index: 1; }
::view-transition-old(ns-dev), ::view-transition-old(ns-credit) { display: none; }
::view-transition-new(ns-dev), ::view-transition-new(ns-credit) { animation: none; }

/* ---- in-app navigation ---- */
html[data-ns-nav]::view-transition-old(root) { display: none; }
html[data-ns-nav]::view-transition-new(root) { animation: none; }

html[data-ns-nav] #main .glass,
html[data-ns-nav] #main > :not(:has(.glass)) { view-transition-name: match-element; view-transition-class: ns-in; }
html[data-ns-nav] #main[data-ns-leaving] .glass,
html[data-ns-nav] #main[data-ns-leaving] > :not(:has(.glass)) { view-transition-class: ns-out; }
html[data-ns-nav] .app-topbar__title { view-transition-name: ns-title; }
html[data-ns-nav] .nav-indicator.is-on { view-transition-name: ns-nav-ind; }
html[data-ns-nav] #app-nav { view-transition-name: ns-nav; }

html[data-ns-nav]::view-transition-old(.ns-out),
html[data-ns-nav]::view-transition-new(.ns-in) { animation: none; }
html[data-ns-nav]::view-transition-group(.ns-out) { animation: var(--vt-out) var(--vt-ease-in) both var(--vt-k-out-up); }
html[data-ns-nav]::view-transition-group(.ns-in) { animation: var(--vt-in) var(--vt-ease-out) var(--vt-delay) both var(--vt-k-in-up); }
html[data-ns-nav="back"]::view-transition-group(.ns-out) { animation-name: var(--vt-k-out-down); }
html[data-ns-nav="back"]::view-transition-group(.ns-in) { animation-name: var(--vt-k-in-down); }

/* Browsers with same-document view transitions but without
   view-transition-class / match-element (Firefox 144+): the content cannot be
   named, so the whole root crossfades – photo and shell are identical in both
   snapshots and stay still, the content crossfades. */
@supports not (view-transition-class: a) {
  /* same timing on both sides: identical pixels stay exactly still */
  html[data-ns-nav]::view-transition-old(root) { display: block; animation: var(--vt-in) ease both ns-vt-fade-out; }
  html[data-ns-nav]::view-transition-new(root) { animation: var(--vt-in) ease both ns-vt-fade-in; }
}

html[data-ns-nav]::view-transition-group(ns-title) { animation: none; }
html[data-ns-nav]::view-transition-old(ns-title) { animation: var(--vt-out) linear both ns-vt-fade-out; }
html[data-ns-nav]::view-transition-new(ns-title) { animation: var(--vt-out) linear var(--vt-out) both ns-vt-fade-in; }

/* Menu highlight (.nav-indicator, a plain box): its group slides from the
   old entry to the new one. The menu entries get their own group ABOVE it
   (z-index), so the labels stay readable and still while the box passes
   under them; they switch to the new state at once. */
html[data-ns-nav]::view-transition-group(ns-nav-ind) { animation-duration: var(--vt-slide); animation-timing-function: var(--vt-ease-out); }
html[data-ns-nav]::view-transition-old(ns-nav-ind) { display: none; }
html[data-ns-nav]::view-transition-new(ns-nav-ind) { animation: none; }
html[data-ns-nav]::view-transition-group(ns-nav) { animation: none; z-index: 1; }
html[data-ns-nav]::view-transition-old(ns-nav) { display: none; }
html[data-ns-nav]::view-transition-new(ns-nav) { animation: none; }

/* ---- full page loads (cross-document) ---- */
:root:active-view-transition:not([data-ns-nav]) .auth-panel { view-transition-name: ns-auth; }
:root:active-view-transition:not([data-ns-nav]) .app-sidebar { view-transition-name: ns-sidebar; }
:root:active-view-transition:not([data-ns-nav]) .app-topbar { view-transition-name: ns-topbar; }

::view-transition-old(root) { animation: var(--vt-out) var(--vt-ease-in) both ns-vt-fade-out; }
::view-transition-new(root) { animation: var(--vt-in) var(--vt-ease-out) both ns-vt-fade-in; }

/* On both pages (login → 2FA, app → app): stays, its content crossfades. */
::view-transition-group(ns-auth), ::view-transition-group(ns-sidebar), ::view-transition-group(ns-topbar) { animation-duration: var(--vt-in); }
/* On one page only: the group moves, its single snapshot does not fade on its own. */
::view-transition-old(ns-auth):only-child, ::view-transition-new(ns-auth):only-child,
::view-transition-old(ns-sidebar):only-child, ::view-transition-new(ns-sidebar):only-child,
::view-transition-old(ns-topbar):only-child, ::view-transition-new(ns-topbar):only-child { animation: none; }
/* Leaving the auth layout: the panel slides out to the right. */
html:not(:has(> body.layout-auth))::view-transition-group(ns-auth) { animation: var(--vt-panel-out) var(--vt-ease-in) both var(--vt-k-out-right); }
/* Coming to the auth layout from another layout: the panel slides in. */
html[data-ns-from]:not([data-ns-from="auth"]):has(> body.layout-auth)::view-transition-group(ns-auth) { animation: var(--vt-panel) var(--vt-ease-out) both var(--vt-k-in-right); }
/* Coming to the app layout: sidebar from the left, top bar from above. */
html[data-ns-from]:not([data-ns-from="app"]):has(> body.layout-app)::view-transition-group(ns-sidebar) { animation: var(--vt-panel) var(--vt-ease-out) var(--vt-delay) both var(--vt-k-in-left); }
html[data-ns-from]:not([data-ns-from="app"]):has(> body.layout-app)::view-transition-group(ns-topbar) { animation: var(--vt-panel) var(--vt-ease-out) var(--vt-delay) both var(--vt-k-in-down); }
/* Leaving the app layout: sidebar and top bar fade out. */
html:not(:has(> body.layout-app))::view-transition-group(ns-sidebar),
html:not(:has(> body.layout-app))::view-transition-group(ns-topbar) { animation: var(--vt-out) var(--vt-ease-in) both ns-vt-fade-out; }

/* ---- fallback without cross-document view transitions (Firefox, …) ----
   js/nav.js plays the same look with plain animations: "ns-leave*" on
   <html> while the submitted page animates out, "ns-from-<layout>" on the
   next page while its parts enter. Reduced motion: app.css switches all
   animations off, and nav.js does not delay the submit. */
html.ns-leave .layout-auth .auth-panel { animation: var(--vt-panel-out) var(--vt-ease-in) both ns-vt-out-right; }
html.ns-leave-content .layout-auth .auth-panel__content,
html.ns-leave .layout-app :is(.app-sidebar, .app-topbar, .app-content, .site-footer) { animation: var(--vt-out) var(--vt-ease-in) both ns-vt-fade-out; }

/* login/2FA → app: sidebar from the left, top bar from above, content rises */
html.ns-from-auth .layout-app .app-sidebar { animation: var(--vt-panel) var(--vt-ease-out) var(--vt-delay) both ns-vt-in-left; }
html.ns-from-auth .layout-app .app-topbar { animation: var(--vt-panel) var(--vt-ease-out) var(--vt-delay) both ns-vt-in-down; }
html.ns-from-auth .layout-app :is(.app-content, .site-footer) { animation: var(--vt-in) var(--vt-ease-out) var(--vt-delay) both ns-vt-in-up; }
/* app → login (logout): the panel slides in */
html.ns-from-app .layout-auth .auth-panel { animation: var(--vt-panel) var(--vt-ease-out) both ns-vt-in-right; }
/* login → 2FA (same panel): its content fades in */
html.ns-from-auth .layout-auth .auth-panel__content { animation: var(--vt-in) var(--vt-ease-out) both ns-vt-fade-in; }

/* ---------- Blur bars behind the auth layout (js/loginbars.js) ----------
   Grey vertical bars drift over the photo. Each bar is one element covering
   the whole viewport with a constant blur and tint (custom properties set
   once by the script); per frame the script changes only its clip-path (the
   bar's range minus the panel's range). The elements never move or resize:
   that keeps the blur still (no shimmer, no flashing edges). Overlapping bars
   stack, so their blurs and tints add up. The container sits between the
   photo and the panel (z-index -1, after .bg-photo in the DOM) and must not
   be a backdrop root (no opacity, filter, transform or will-change on it),
   otherwise the bars would blur nothing. Narrow screens: none. */
.auth-bars {
  position: fixed; inset: 0; z-index: -1;
  overflow: hidden; pointer-events: none;
  contain: strict;
  --bar-grey: 128 132 138;
}
/* dark: OS dark unless the theme switcher forced light, or forced dark (app.css) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .auth-bars { --bar-grey: 70 74 80; }
}
:root[data-theme="dark"] .auth-bars { --bar-grey: 70 74 80; }
.auth-bars__bar {
  position: absolute; inset: 0;
  background-color: rgb(var(--bar-grey) / var(--bar-tint, 0.12));
  -webkit-backdrop-filter: blur(var(--bar-blur, 8px));
  backdrop-filter: blur(var(--bar-blur, 8px));
}
@media (max-width: 48rem) {
  .auth-bars { display: none; }
}
/* Fallback exit (no native view transitions): the bars fade out with the
   panel. Opacity on each bar, not on the container (backdrop root). */
html.ns-leave .auth-bars__bar { animation: var(--vt-panel-out) var(--vt-ease-in) both ns-vt-fade-out; }

/* ---------- Easter egg: draggable windows (js/konami.js) ----------
   html.ns-konami: the Konami code was typed; .konami-win: a window (glass
   panel in #main, the auth panel) that can be dragged. The offset is the
   "translate" property (CSSOM), so "transform" and the view-transition
   groups stay untouched. Moved windows stack above their neighbours (grid
   items and the flex auth panel honour z-index), the last one on top, below
   the sticky mobile bar (20) and the dev badge (50). */
.ns-konami .konami-win { cursor: grab; -webkit-touch-callout: none; }
.ns-konami .konami-win.is-konami-moved { position: relative; z-index: 2; }
.ns-konami .konami-win.is-konami-top { position: relative; z-index: 3; }
.ns-konami .konami-win.is-konami-lifted { cursor: grabbing; box-shadow: var(--glass-shadow), 0 18px 40px rgba(0, 0, 0, 0.28); }
html.ns-konami-dragging, html.ns-konami-dragging * { cursor: grabbing !important; -webkit-user-select: none; user-select: none; }
.konami-win.is-konami-wiggle { animation: ns-konami-wiggle 460ms ease-in-out; }
@keyframes ns-konami-wiggle {
  20% { rotate: -1.2deg; }
  45% { rotate: 1deg; }
  70% { rotate: -0.5deg; }
  100% { rotate: 0deg; }
}
.konami-toast {
  position: fixed; left: var(--space-4); right: var(--space-4); bottom: var(--space-5); z-index: 300;
  width: fit-content; max-width: 32rem; margin: 0 auto;
  padding: var(--space-2) var(--space-4);
  background: var(--surface-strong); color: var(--text);
  box-shadow: var(--glass-shadow);
  font-weight: 600; text-align: center;
  opacity: 0; translate: 0 12px; pointer-events: none;
  transition: opacity 180ms ease, translate 220ms var(--vt-ease-out);
}
.konami-toast.is-shown { opacity: 1; translate: 0 0; }
.konami-toast:empty { display: none; }
@media (prefers-reduced-motion: reduce) {
  .konami-win.is-konami-wiggle { animation: none; }
  .konami-toast { transition: none; translate: 0 0; }
}
