/* ==========================================================================
   inote — app shell (/app). Loaded after tokens.css and base.css.
   Owns: the page frame, bottom navigation / side rail, offline bar, splash,
   view enter fade, stacked sheets, the shared problem state.
   View-specific styles live in css/views/<view>.css.
   ========================================================================== */

:root {
  --nav-item-h: 64px;
  --nav-rail-w: 88px;
  --nav-h: 0px;       /* space the bottom navigation takes; 0 when hidden or when it is a side rail */
  --offline-h: 0px;   /* space the offline bar takes */
}

.has-nav {
  --nav-h: calc(var(--nav-item-h) + var(--safe-bottom));
}

.is-offline {
  --offline-h: calc(36px + var(--safe-top));
}

/* 1 ---- Frame ------------------------------------------------------------- */
/* No overflow on these three: the views' sticky top and bottom bars stick to the viewport. */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-view,
.view {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-view:focus,
.app-view:focus-visible {
  outline: none;
}

/* A view's .page fills what the navigation and the offline bar leave free. */
.view > .page {
  flex: 1 1 auto;
  min-height: calc(100vh - var(--nav-h) - var(--offline-h));
  min-height: calc(100dvh - var(--nav-h) - var(--offline-h));
}

/* The sticky thumb zone rests on top of the navigation, which already covers the safe area. */
.has-nav .bottom-bar {
  bottom: var(--nav-h);
  padding-bottom: var(--space-3);
}

/* Screens swap with a short fade: tabs are used all day, so nothing moves. */
.view {
  opacity: 1;
  transition: opacity var(--dur-1) var(--ease-soft);
}

@starting-style {
  .view {
    opacity: 0;
  }
}

/* 2 ---- Navigation -------------------------------------------------------- */

.app-nav {
  position: sticky;
  bottom: 0;
  z-index: var(--z-sticky);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 168px));
  justify-content: center;
  padding: 0 max(var(--space-2), var(--safe-right)) var(--safe-bottom) max(var(--space-2), var(--safe-left));
  border-top: 1px solid var(--line);
  background: rgb(var(--bg-rgb) / 0.9);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
}

.app-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--nav-item-h);
  border-radius: var(--radius-md);
  color: var(--ink-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  transition: color var(--dur-2) var(--ease-soft);
}

.app-nav-item:focus-visible {
  outline-offset: -4px;
}

.app-nav-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 32px;
  border-radius: var(--radius-full);
  transition:
    background-color var(--dur-2) var(--ease-soft),
    transform var(--dur-2) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .app-nav-item:hover {
    color: var(--ink);
  }

  .app-nav-item:hover .app-nav-icon {
    background: var(--surface-2);
  }
}

.app-nav-item:active .app-nav-icon {
  background: var(--accent-soft-2);
  transform: scale(0.94);
}

.app-nav-item[aria-current="page"] {
  color: var(--accent-strong);
}

.app-nav-item[aria-current="page"] .app-nav-icon {
  background: var(--accent-soft-2);
}

/* Desktop: the same three links become a rail in the free margin left of the 720px column. */
@media (min-width: 960px) {
  .has-nav {
    --nav-h: 0px;
  }

  .app-nav {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: calc(var(--z-sticky) + 1);
    grid-template-columns: none;
    grid-auto-rows: min-content;
    align-content: start;
    justify-content: stretch;
    gap: var(--space-1);
    width: var(--nav-rail-w);
    padding: var(--space-3) var(--space-2);
    border-top: 0;
    border-right: 1px solid var(--line);
    background: var(--bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .app-nav-item {
    min-height: 68px;
  }
}

/* 3 ---- Offline bar ------------------------------------------------------- */

.offline-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: calc(36px + var(--safe-top));
  padding: var(--safe-top) var(--gutter) 0;
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
}

.offline-bar::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--toast-err);
}

/* The listening screen is full-bleed and shows its own connection line. */
[data-route="listen"] .offline-bar {
  display: none;
}

[data-route="listen"].is-offline {
  --offline-h: 0px;
}

/* 4 ---- Splash, problem state, skip link, no-script ----------------------- */

.splash {
  flex: 1 1 auto;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-6);
  min-height: 100vh;
  min-height: 100dvh;
}

/* A fast start never shows the spinner at all. */
.splash .spinner {
  animation:
    spin 600ms linear infinite,
    splash-wait 300ms 450ms both;
}

@keyframes splash-wait {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.app-problem {
  display: grid;
  place-content: center;
}

.skip-link {
  position: fixed;
  top: calc(var(--safe-top) + var(--space-2));
  left: var(--space-2);
  z-index: var(--z-toast);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  transform: translateY(-200%);
  transition: transform var(--dur-2) var(--ease-out);
}

.skip-link:focus,
.skip-link:focus-visible {
  transform: translateY(0);
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: var(--z-toast);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-4);
  padding: var(--gutter);
  background: var(--bg);
  text-align: center;
}

/* 5 ---- Sheets: stacking, drag handle, confirm ---------------------------- */

/* A confirm opened from inside a sheet sits above it. */
.sheet-backdrop.is-stacked {
  z-index: calc(var(--z-sheet) + 1);
}

.sheet.is-stacked {
  z-index: calc(var(--z-sheet) + 2);
}

/* The handle and header are the grip for drag-to-dismiss (ui.js). */
.sheet-handle,
.sheet-header {
  touch-action: none;
}

.confirm-text {
  color: var(--ink-2);
}

.sheet-confirm .sheet-body {
  gap: var(--space-2);
  padding-bottom: var(--space-2);
}

/* 6 ---- Reduced motion ---------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .app-nav-item:active .app-nav-icon {
    transform: none;
  }

  .skip-link {
    transition: none;
  }
}
