/* =========================================================================
   Cabinhub News — PWA chrome (offline strip + update toast).

   Additive to styles.css: nothing here restyles an existing element, and every colour
   goes through the shared theme variables so the strip and the toast follow the page
   (light ground by default, dark under :root[data-theme="dark"]). Fallbacks are the
   newsroom's own palette, so the file is still correct if it is loaded alone.
   ========================================================================= */

:root {
  /* Read from the Ember token layer (css/tokens.css), with this lane's own contract
     names as the outer fallback so the file is still correct if it is loaded alone.
     Light is the default; both blocks below follow html[data-theme], so the strip and
     the toast move with the reader's real switch, not a private copy of the palette. */
  --cbn-bg: var(--bg, var(--paper, #F7F5F2));
  --cbn-surface: var(--surface, var(--canvas, #FFFFFF));
  --cbn-fg: var(--fg, var(--ink, #1C1714));
  --cbn-fg-2: var(--fg-2, var(--ink-soft, #514942));
  --cbn-fg-3: var(--fg-3, var(--ink-faint, #6D6259));
  --cbn-line: var(--line, var(--rule, rgba(28, 23, 20, 0.12)));
  --cbn-accent: var(--accent, #BC3E0D);
  --cbn-focus: var(--focus, #D64221);
}

:root[data-theme="dark"] {
  --cbn-bg: var(--bg, #15110E);
  --cbn-surface: var(--surface, #1E1915);
  --cbn-fg: var(--fg, #F3EEE9);
  --cbn-fg-2: var(--fg-2, #C9BFB6);
  --cbn-fg-3: var(--fg-3, #9F948A);
  --cbn-line: var(--line, #3A3129);
  --cbn-accent: var(--accent, #FA8054);   /* the lifted dark accent from tokens.css */
  --cbn-focus: var(--focus, #FF9C6B);
}

/* ------------------------------------------------------------ offline strip */

.cbn-offline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  /* Aligned to the page's own 1280px column and safe-area gutters, so the line sits under
     the filters rather than floating at the viewport edge. */
  padding: 0.55rem
    max(var(--pad-r, 1rem), calc((100% - 1280px) / 2 + var(--pad-r, 1rem)))
    0.55rem
    max(var(--pad-l, 1rem), calc((100% - 1280px) / 2 + var(--pad-l, 1rem)));
  background: var(--cbn-surface);
  color: var(--cbn-fg-2);
  border-bottom: 1px solid var(--cbn-line);
  font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif);
  font-size: 0.8125rem;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

.cbn-offline[hidden] { display: none; }

.cbn-offline__dot {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cbn-fg-3);
  /* A slow pulse is the only motion here and it stops for reduced-motion readers. */
  animation: cbn-offline-pulse 2.4s ease-in-out infinite;
}

.cbn-offline__text { min-width: 0; }

@keyframes cbn-offline-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* -------------------------------------------------------------- update toast */

.cbn-update {
  position: fixed;
  z-index: 60;
  left: max(1rem, env(safe-area-inset-left, 0px));
  bottom: max(1rem, calc(env(safe-area-inset-bottom, 0px) + 0.75rem));
  display: flex;
  align-items: center;
  gap: 0.9rem;
  max-width: min(26rem, calc(100vw - 2rem));
  padding: 0.6rem 0.6rem 0.6rem 1rem;
  background: var(--cbn-surface);
  color: var(--cbn-fg);
  border: 1px solid var(--cbn-line);
  border-left: 2px solid var(--cbn-accent);
  /* A toast floats over the page, so it takes the mid elevation tier
     (tokens.css) rather than a neutral-black one-off. Inline fallback as in
     palette.css: an unresolved var() in a shorthand becomes `unset`. */
  box-shadow:
    var(--bevel-top, inset 0 1px 0 rgba(255, 255, 255, 0.6)),
    var(--shadow-2, 0 18px 40px -28px rgba(0, 0, 0, 0.55));
  font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif);
  font-size: 0.8125rem;
  line-height: 1.3;
  animation: cbn-update-in 260ms cubic-bezier(0.22, 0.68, 0.16, 1) both;
}

.cbn-update[hidden] { display: none; }

dialog > .cbn-update {
  position: static;
  max-width: none;
  margin-top: 1rem;
  box-shadow: none;
}

dialog > .cbn-update button { min-width: 44px; min-height: 44px; }

.cbn-update__text { flex: 1 1 auto; min-width: 0; color: var(--cbn-fg-2); }

.cbn-update__action,
.cbn-update__dismiss {
  flex: none;
  appearance: none;
  border: 0;
  background: none;
  color: var(--cbn-accent);
  font: inherit;
  font-weight: 600;
  padding: 0.45rem 0.5rem;
  min-height: 32px;
  cursor: pointer;
  border-radius: 2px;
}

.cbn-update__dismiss {
  color: var(--cbn-fg-3);
  font-weight: 400;
  min-width: 32px;
}

.cbn-update__dismiss::before { content: "\00d7"; font-size: 1.1rem; line-height: 1; }

.cbn-update__action:focus-visible,
.cbn-update__dismiss:focus-visible {
  outline: 2px solid var(--cbn-focus);
  outline-offset: 2px;
}

.cbn-update__action:hover { text-decoration: underline; text-underline-offset: 2px; }

@keyframes cbn-update-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 480px) {
  .cbn-update {
    left: max(0.75rem, env(safe-area-inset-left, 0px));
    right: max(0.75rem, env(safe-area-inset-right, 0px));
    bottom: max(0.75rem, calc(env(safe-area-inset-bottom, 0px) + 0.5rem));
    max-width: none;
  }
}

/* Respect the reader: motion is decoration here, and it is the first thing to drop. */
@media (prefers-reduced-motion: reduce) {
  .cbn-offline__dot { animation: none; opacity: 0.8; }
  .cbn-update { animation: none; }
}

@media (forced-colors: active) {
  .cbn-update { border: 1px solid CanvasText; }
  .cbn-offline { border-bottom: 1px solid CanvasText; }
}

.cbn-offline__library { display:inline-flex; align-items:center; min-height:44px; color:inherit; text-underline-offset:.18em; }
