/* ============================================================
   NEXORA · App Theme / Global shell base
   Page-level structure for the application shell.
   (Landing base global.css is linked before this file and
   owns reset-adjacent concerns: selection, scrollbar,
   reveal keyframes, focus, reduced-motion.)
   ============================================================ */

body.app {
  background: var(--bg-page);
  background-attachment: scroll;
  overflow-x: hidden;
}

/* ---------- Content region around persistent chrome --------- */

/* Sidebar preference effects (toggled from Sidebar → Settings) */
html.sb-collapsed {
  --sb-slot: var(--sb-w-rail);
}

html.nx-compact {
  --content-gutter: 0.7rem;
  --card-pad: 0.95rem;
}

html.nx-compact .card {
  padding: var(--card-pad);
}

html.nx-compact .panel-head {
  margin-bottom: 0.75rem;
}

html.nx-reduced-motion *,
html.nx-reduced-motion *::before,
html.nx-reduced-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

html.nx-reduced-motion .reveal {
  opacity: 1;
  transform: none;
  filter: none;
}

.app-content {
  position: relative;
  z-index: 1;
  margin-left: calc(var(--sb-edge) + var(--sb-slot) + var(--content-gutter));
  margin-right: var(--content-gutter);
  margin-top: calc(var(--tb-top) + var(--tb-h) + 1.35rem);
  margin-bottom: 4rem;
  max-width: var(--app-maxw);
  width: auto;
  outline: none;
  transition:
    margin-left var(--sb-anim),
    margin-right var(--sb-anim),
    max-width var(--sb-anim);
  will-change: margin-left;
}

/* When sidebar collapses: expand content only to left, keep right gap tight */
html.sb-collapsed .app-content {
  margin-right: var(--content-gutter);
}

/* Shell pieces fade in together once partials are mounted */
#app-sidebar,
#app-topdock {
  opacity: 0;
  transition: opacity var(--shell-enter) var(--ease-out);
}

body.shell-ready #app-sidebar,
body.shell-ready #app-topdock {
  opacity: 1;
}

/* ---------- View swap transitions ------------------------------ */

.app-content.is-loading {
  pointer-events: none;
}

.app-content.view-in > * {
  animation: refresh-item 0.45s var(--ease-out) both;
}

.app-content.view-in > *:nth-child(2) { animation-delay: 0.04s; }
.app-content.view-in > *:nth-child(3) { animation-delay: 0.08s; }
.app-content.view-in > *:nth-child(4) { animation-delay: 0.12s; }
.app-content.view-in > *:nth-child(5) { animation-delay: 0.16s; }

/* ---------- Router loading shimmer ----------------------------- */

.app-content.is-loading::before {
  content: "";
  position: sticky;
  top: calc(var(--tb-top) + var(--tb-h) + 1.35rem);
  display: block;
  height: 2px;
  margin-bottom: 1rem;
  border-radius: var(--radius-full);
  background: var(--text-3);
  opacity: 0.3;
  animation: none;
}

/* ---------- Screen scaffolding -------------------------------- */

.screen {
  display: grid;
  gap: var(--content-gutter);
}

.screen-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

/* ---------- Shell geometry breakpoints -------------------------
   Rail vs. expanded is a user preference (see components/sidebar),
   so only the mobile bottom-bar layout is forced here.          */

@media (max-width: 767px) {
  :root {
    --tb-h: 56px;
    --tb-top: 0.65rem;
    --tb-side: clamp(0.75rem, 3vw, 1.25rem);
    --content-gutter: 0.85rem;
  }

  .app-content {
    margin-left: var(--tb-side);
    margin-right: var(--tb-side);
    margin-top: calc(var(--tb-top) + var(--tb-h) + 0.85rem);
    margin-bottom: 6rem; /* clear the bottom nav dock */
    max-width: 100%;
    width: auto;
    box-sizing: border-box;
  }

  .screen {
    gap: var(--content-gutter);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .screen-head {
    gap: 0.9rem;
    width: 100%;
    box-sizing: border-box;
  }
}
