/*
  The loading screen's stylesheet — the rules for app/spa-loading-template.html's markup
  (#esw-loader). Wired through nuxt.config `css`, so it ships inside the hashed entry
  stylesheet every shell links from <head> — ONE cached asset, instead of an inline <style>
  repeated into every prerendered route shell (the static prerender repeats the template
  per route: dist/<route>/index.html, dist-dev/, dist-gen/).

  KEEP IN STEP with the template's markup and the theme — light = mono ONE (index.css) +
  esw navy, dark = mono-custom-one.css `--esw-dark-*`.
*/
#esw-loader {
  --l-bg: oklch(0.973 0.007 268.55 / 0.72);
  --l-card: oklch(1 0 0 / 0.8);
  --l-border: oklch(0.928 0.011 269.54);
  --l-title: oklch(0.304 0.108 273.2);
  --l-text: oklch(0.551 0.023 264.36);
  --l-track: color-mix(in oklab, oklch(0.304 0.108 273.2) 12%, transparent);
  --l-fill: oklch(0.304 0.108 273.2);
  --l-logo-bg: oklch(0.304 0.108 273.2 / 0.08);
  --l-shadow: 0 1px 2px rgb(15 23 42 / 0.06), 0 10px 28px -8px rgb(15 23 42 / 0.18);
  /* The navbar cover: white in light (the bar's surface). */
  --l-cover: oklch(1 0 0);
}

/* The blur layer. Its own z-index, not the wrapper's: a z-index (or opacity) on
   #esw-loader would make it one stacking context and lift the cover above the blur. */
#esw-loader .esw-loader-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: var(--l-bg);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  backdrop-filter: blur(14px) saturate(1.15);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  transition: opacity 0.28s ease;
}

html.dark #esw-loader {
  --l-bg: oklch(0.145 0.025 274 / 0.72);
  --l-card: oklch(0.175 0.028 274 / 0.84);
  --l-border: color-mix(in oklab, oklch(0.94 0.008 274) 10%, transparent);
  --l-title: oklch(0.94 0.008 274);
  --l-text: oklch(0.69 0.025 274);
  --l-track: color-mix(in oklab, oklch(0.94 0.008 274) 10%, transparent);
  /* The dark theme's primary (oklch 0.48) is too dim on the dark card; the bar uses the
     dark link blue instead (the same lift --esw-link gets in dark). */
  --l-fill: oklch(0.78 0.11 255);
  --l-logo-bg: oklch(1 0 0);
  --l-shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 10px 28px -8px rgb(0 0 0 / 0.55);
  /* The navbar cover in dark: the dark top bar / sidebar navy (`--esw-dark-sidebar`). */
  --l-cover: oklch(0.124 0.057 274);
}

#esw-loader .esw-loader-cover {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 2000;
  height: 8%;
  background: var(--l-cover);
  /* Fade each layer, not the wrapper: opacity on #esw-loader would group the layers and
     drop the backdrop blur for the length of the fade. */
  transition: opacity 0.28s ease;
}

/* ---- The fake shell (see the template's markup comment). Layout values are the real shell's:
   SideNav.vue (240 / 64px rail, compact, navy in light, `--esw-dark-sidebar` in dark),
   Nav.vue (compact outlined bar, `--esw-topbar-h`), layouts/home.vue (p-3 page). The
   `esw-sidebar` / `esw-main` / `esw-topbar` classes pick up mono-custom-one.css's own
   rules (dark top-bar gradient, sidebar seam), so the two shells cannot drift apart. */
#esw-loader .esw-loader-shell {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1999;
  overflow: hidden;
  background: var(--background);
  color: var(--foreground);
  transition: opacity 0.28s ease;
  --l-side: 240px;
}

#esw-loader.has-shell .esw-loader-shell { display: block; }
#esw-loader.has-shell .esw-loader-cover { display: none; }

/* With a shell to show through it, the veil is lighter: the shell is meant to be SEEN. */
#esw-loader.has-shell .esw-loader-backdrop {
  --l-bg: oklch(0.973 0.007 268.55 / 0.38);
  -webkit-backdrop-filter: blur(5px) saturate(1.1);
  backdrop-filter: blur(5px) saturate(1.1);
}
html.dark #esw-loader.has-shell .esw-loader-backdrop { --l-bg: oklch(0.145 0.025 274 / 0.45); }

#esw-loader .esw-loader-shell[data-rail="collapsed"] { --l-side: 64px; }

#esw-loader .esw-loader-shell .esw-sidebar {
  --mono-sidebar-width: 240px;
  --mono-sidebar-rail-width: 64px;
  --esw-sidebar-ink: var(--primary-foreground);
}
html.dark #esw-loader .esw-loader-shell .esw-sidebar {
  --esw-sidebar-ink: var(--foreground);
  --mono-sidebar-bg: var(--esw-dark-sidebar);
}

/* The logo row (SideNav's `.esw-sidebar-header-row`). */
#esw-loader .esw-loader-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  height: calc(var(--esw-topbar-h, 3.5rem) - 1.2rem - 1px);
  color: var(--esw-sidebar-ink);
}
#esw-loader .esw-loader-brand img {
  height: 100%;
  width: auto;
  flex: none;
  border-radius: 0.5rem;
  background: color-mix(in oklab, white 15%, transparent);
  object-fit: contain;
  box-sizing: border-box;
}
html.dark #esw-loader .esw-loader-brand img { background: white; padding: 0.25rem; }
#esw-loader .esw-loader-brand span {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 700;
  font-size: 1rem;
}

/* Skeleton blocks on the painted panel: tinted from the panel's ink, as SideNav's
   `.esw-menu-skeleton-row` (mono's default muted block clashes with the navy). */
#esw-loader .esw-sidebar [mono-pending] {
  --mono-skeleton-bg: color-mix(in oklab, var(--esw-sidebar-ink) 10%, transparent);
  --mono-skeleton-color: color-mix(in oklab, var(--esw-sidebar-ink) 22%, transparent);
}
#esw-loader .esw-loader-menu { display: flex; flex-direction: column; gap: 0.5rem; }
#esw-loader .esw-loader-menu-row { display: flex; align-items: center; gap: 0.75rem; height: 2.25rem; padding: 0 0.5rem; }
#esw-loader .esw-loader-menu-row > :first-child { width: 1.125rem; height: 1.125rem; flex: none; border-radius: 0.25rem; }
#esw-loader .esw-loader-menu-row > :last-child { height: 0.75rem; border-radius: 999px; }

/* Collapsed rail: icons only (SideNav hides `.esw-sidebar-label`). */
#esw-loader [data-rail="collapsed"] .esw-fake-label { display: none; }
#esw-loader [data-rail="collapsed"] .esw-loader-menu-row { justify-content: center; padding: 0; }

#esw-loader .esw-loader-shell .esw-main {
  position: relative;
  min-height: 100vh;
  padding-left: var(--l-side);
  --esw-sidebar-ssr-width: var(--l-side);
  box-sizing: border-box;
}

/* Nav.vue's full-bleed bar. */
#esw-loader .esw-loader-shell .esw-topbar {
  --mono-nav-radius: 0;
  --mono-nav-ring-width: 0;
  --mono-nav-bar-height: calc(var(--esw-topbar-h, 3.5rem) - 1px);
}
#esw-loader .esw-loader-shell [mono-start],
#esw-loader .esw-loader-shell [mono-end] { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
#esw-loader .esw-fake-title { width: 10rem; max-width: 45%; height: 1.25rem; border-radius: 0.375rem; }
#esw-loader .esw-loader-icon { width: 2.5rem; height: 2.5rem; flex: none; border-radius: 0.5rem; }
#esw-loader .esw-loader-icon.is-round { border-radius: 999px; }
#esw-loader .esw-loader-burger { display: none; }

#esw-loader .esw-loader-page { display: flex; flex-direction: column; gap: 0.75rem; padding: 0.75rem; }
#esw-loader .esw-loader-page-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}
#esw-loader .esw-loader-row { display: flex; flex-wrap: wrap; gap: 0.75rem; }
#esw-loader .esw-loader-row.is-tight { gap: 0.5rem; }
#esw-loader .esw-loader-col { display: flex; flex-direction: column; gap: 0.5rem; }
#esw-loader .esw-loader-page [mono-pending] { flex: none; border-radius: calc(var(--radius) - 2px); }

/* Below `md` the real sidebar is a closed overlay and the bar shows the menu button. */
@media (max-width: 767.98px) {
  #esw-loader .esw-loader-shell { --l-side: 0px; }
  #esw-loader .esw-loader-shell .esw-sidebar { display: none; }
  #esw-loader .esw-loader-burger { display: block; }
}

#esw-loader.is-done .esw-loader-shell,
#esw-loader.is-done .esw-loader-cover,
#esw-loader.is-done .esw-loader-backdrop {
  opacity: 0;
  pointer-events: none;
}

#esw-loader .esw-loader-card {
  width: min(12.5rem, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.625rem;
  padding: 1.125rem 1rem 1rem;
  border: 1px solid var(--l-border);
  border-radius: 0.75rem;
  background: var(--l-card);
  box-shadow: var(--l-shadow);
  box-sizing: border-box;
}

#esw-loader .esw-loader-logo {
  width: 2.75rem;
  height: 2.75rem;
  padding: 0.25rem;
  border-radius: 0.625rem;
  background: var(--l-logo-bg);
  object-fit: contain;
  box-sizing: border-box;
}

#esw-loader .esw-loader-title {
  margin: 0;
  color: var(--l-title);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Infinite bar, no numbers: a segment runs left → right out of the track, then comes back
   right → left, and repeats (`alternate`). */
#esw-loader .esw-loader-bar {
  position: relative;
  width: 100%;
  height: 0.25rem;
  overflow: hidden;
  border-radius: 999px;
  background: var(--l-track);
}

#esw-loader .esw-loader-bar::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40%;
  border-radius: inherit;
  background: var(--l-fill);
  animation: esw-loader-run 1.1s ease-in-out infinite alternate;
}

@keyframes esw-loader-run {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}

#esw-loader .esw-loader-label {
  margin: 0;
  color: var(--l-text);
  font-size: 0.6875rem;
}

@media (prefers-reduced-motion: reduce) {
  #esw-loader .esw-loader-shell,
  #esw-loader .esw-loader-cover,
  #esw-loader .esw-loader-backdrop { transition: none; }
  #esw-loader .esw-loader-bar::before { animation-duration: 2.5s; }
}
