/*
  A slim bar across the top of the viewport, over the page rather than in it.

  Fixed rather than part of the layout flow, and that is deliberate: the three layouts this appears
  in have nothing structurally in common — `space-layout` is a bare slot behind a full-screen
  canvas, `app-layout` is a centred column, `site-layout` has its own topbar — so anything that
  reflowed the page would have to be tuned three times and would still resize the space canvas
  underneath somebody mid-edit.

  Above the space toolbar's stacking context (9999) because a message about the network being off
  is not something to hide behind a tool palette.
*/

atomics-offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10001;
  display: block;
  /* The bar takes its own pointer events; the rest of the strip stays click-through so it never
     swallows a press meant for the page beneath it. */
  pointer-events: none;
}

atomics-offline-banner [bar] {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem max(0.9rem, env(safe-area-inset-left)) 0.6rem max(0.9rem, env(safe-area-inset-right));
  padding-top: max(0.6rem, env(safe-area-inset-top));
  background: var(--text, #0f0f0f);
  color: var(--background, #f0f0ef);
  font-size: 0.88rem;
  line-height: 1.4;
  box-shadow: 0 1px 12px rgb(0 0 0 / 18%);
}

atomics-offline-banner [bar][hidden] {
  display: none;
}

/*
  Airplane mode is a choice somebody made and reads as neutral; a lost connection is something that
  happened to them and gets a warmer note. Both are drawn from the theme's own two colours rather
  than a new palette, so the bar cannot clash with a theme it has never seen.
*/
atomics-offline-banner[mode='offline'] [bar] {
  background: color-mix(in srgb, var(--text, #0f0f0f), #b45309 55%);
  color: #fff;
}

atomics-offline-banner [dot] {
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  /* A slow pulse, because the state persists — a static dot reads as decoration. */
  animation: atomics-offline-banner-pulse 2.4s ease-in-out infinite;
}

@keyframes atomics-offline-banner-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  atomics-offline-banner [dot] {
    animation: none;
  }
}

atomics-offline-banner [message] {
  flex: 1 1 auto;
  margin: 0;
  min-width: 0;
  text-wrap: pretty;
}

atomics-offline-banner [actions] {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

atomics-offline-banner [action],
atomics-offline-banner [manage] {
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 0.75rem;
  border-radius: 100vmax;
  border: 1px solid color-mix(in srgb, currentColor, transparent 60%);
  background: transparent;
  color: inherit;
}

atomics-offline-banner [action]:hover,
atomics-offline-banner [manage]:hover {
  background: color-mix(in srgb, currentColor, transparent 88%);
}

atomics-offline-banner [action][hidden] {
  display: none;
}

atomics-offline-banner [action]:disabled {
  opacity: 0.5;
  cursor: progress;
}

atomics-offline-banner [dismiss] {
  font: inherit;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  opacity: 0.75;
}

atomics-offline-banner [dismiss]:hover {
  opacity: 1;
  background: color-mix(in srgb, currentColor, transparent 88%);
}

atomics-offline-banner :focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/*
  On a phone the sentence is the thing worth keeping. The link goes first — it is one tap further
  away on /install, which is reachable offline anyway — and the message wraps to two lines.
*/
@media (max-width: 620px) {
  atomics-offline-banner [bar] {
    align-items: flex-start;
    font-size: 0.82rem;
  }

  atomics-offline-banner [manage] {
    display: none;
  }
}
