/* Header utility row: Comments, Bookmarks, Write entry, Log out, with unread
   count badges on the first two. Markup: templates/shared/header.html.
   Linked after prosebox-unify, whose .loginbar icon rules this overrides.

   The four icons share one size, colour and weight. An icon with unread items
   is NOT darkened or bolded: the badge is the only unread marker. */

/* The header background as a variable, so the badge ring follows the theme.
   Keep in step with .header in headers/header-default and body.dark .header
   in theme-skins/dark.css. */
.header {
  --pb-header-bg: #fff;
  --pb-util-color: #8c8c8c;
  --pb-util-hover: #555;
  /* #2f73c0 on white text is 4.9:1. The legacy counter blue (#3498db) is
     3.2:1 and fails 4.5:1, so it is not reused. */
  --pb-util-badge-bg: #2f73c0;
}

body.dark .header {
  --pb-header-bg: #222;
  --pb-util-color: #999;
  --pb-util-hover: #fff;
}

.header .topbar ul.loginbar.pb-utilbar {
  display: flex;
  align-items: center;
  gap: 30px;
  /* With the topbar's own 8px this starts the icon row 14px from the top of
     the header, so a badge (6px above its icon) keeps 8px of clear space. */
  padding: 6px 0 0;
  list-style: none;
}

/* The icon row now ends 4px lower (6px more padding, a 2px smaller icon).
   The main nav is pulled up under it by the container's -40px bottom margin,
   so ease that by the same 4px: the gap between the icons and the nav is
   unchanged and the header is 4px taller. Logged in only (pb-header-util). */
@media (min-width: 992px) {
  .header.pb-header-util > .container {
    margin-bottom: -36px;
  }
}

.header .topbar ul.loginbar.pb-utilbar > li.pb-util-item {
  display: block;
  padding: 0;
  line-height: 1;
}

.header .topbar ul.loginbar > li > a.pb-util,
body.dark .header .topbar ul.loginbar > li > a.pb-util {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pb-util-color);
  text-decoration: none;
}

.header .topbar ul.loginbar > li > a.pb-util:hover,
.header .topbar ul.loginbar > li > a.pb-util:focus,
body.dark .header .topbar ul.loginbar > li > a.pb-util:hover,
body.dark .header .topbar ul.loginbar > li > a.pb-util:focus {
  color: var(--pb-util-hover);
}

/* The 19px box the badge is positioned against. Fixed size, so a badge (which
   is absolutely positioned) never changes the layout width of the link. */
.header .topbar .pb-util-icon {
  position: relative;
  display: block;
  width: 19px;
  height: 19px;
}

.header .topbar ul.loginbar li a.pb-util i.fa,
body.dark .header .topbar ul.loginbar li a.pb-util i.fa {
  display: block;
  width: 19px;
  padding: 0;
  color: inherit;
  font-size: 19px;
  font-weight: normal;
  line-height: 19px;
  text-align: center;
}

/* Anchored by its LEFT edge: a wider count grows to the right and never
   covers more of the icon. One digit is a circle (min-width = height). */
.header .topbar .pb-util-badge {
  position: absolute;
  top: -6px;
  left: 11px;
  box-sizing: border-box;
  height: 18px;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9999px;
  background: var(--pb-util-badge-bg);
  box-shadow: 0 0 0 2px var(--pb-header-bg);
  color: #fff;
  font-family: "Open Sans", Arial, sans-serif;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  letter-spacing: 0;
  text-align: center;
  text-transform: none;
  white-space: nowrap;
}

/* Mobile: each icon is a 48 x 44 tap target, icon centred, no gap between. */
@media (max-width: 991px) {
  .header .topbar ul.loginbar.pb-utilbar {
    gap: 0;
  }

  .header .topbar ul.loginbar > li > a.pb-util {
    width: 48px;
    height: 44px;
  }

  /* The row is a float that is now 44px tall, taller than the topbar's own
     box, so the menu button (also floated right) would be pushed to its left.
     Pull the row up into the topbar's 8px padding (all but 2px of it: the
     icon, centred in its 44px target, then starts 14.5px from the header top
     and its badge keeps 8px clear) and clear the button below it, with the
     button's own top margin dropped. */
  .header .topbar ul.loginbar.pb-utilbar {
    margin-top: -6px;
    padding-top: 0;
  }

  .header .navbar-toggle.pb-util-toggle {
    clear: right;
    margin-top: 0;
  }
}

/* ---- Counters moved hint (TEMPORARY) -------------------------------------
   A one-time pointer for members who knew the old boxed counters under the
   header: a ring pulses three times around the Comments and Bookmarks icons
   and a small note sits under them. Shown and dismissed by
   js/pb-counters-moved-*.js, which adds every class used here. Delete this
   whole block with COUNTERS_MOVED_ON (blog/context_processors.py). */

.header .topbar .pb-util-icon.pb-moved-ring::after {
  content: "";
  position: absolute;
  top: -8px;
  right: -8px;
  bottom: -8px;
  left: -8px;
  border: 2px solid var(--pb-moved-ring, #2f73c0);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  animation: pb-moved-pulse 1.4s ease-out 3;
}

@keyframes pb-moved-pulse {
  0% {
    transform: scale(0.8);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

/* The note hangs from the Comments item and is centred on the midpoint of
   the two icons: 19px icon + half the 30px gap. */
.header .topbar ul.loginbar.pb-utilbar > li.pb-moved-anchor {
  position: relative;
}

.header .topbar .pb-moved-note {
  --pb-moved-bg: #333;
  --pb-moved-fg: #fff;
  position: absolute;
  top: calc(100% + 16px);
  left: 34px;
  z-index: 1000;
  box-sizing: border-box;
  width: 208px;
  margin: 0;
  padding: 9px 12px;
  border: 0;
  border-radius: 6px;
  background: var(--pb-moved-bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  color: var(--pb-moved-fg);
  font-family: "Open Sans", Arial, sans-serif;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0;
  text-align: center;
  text-transform: none;
  white-space: normal;
  cursor: pointer;
  transform: translateX(-50%);
  animation: pb-moved-in 0.2s ease-out;
}

/* The badge blue is too dim as a thin ring on the dark header. */
body.dark .header .topbar .pb-util-icon.pb-moved-ring::after {
  --pb-moved-ring: #6aa5e8;
}

/* On the dark header a dark note would disappear, so it inverts. */
body.dark .header .topbar .pb-moved-note {
  --pb-moved-bg: #f2f2f2;
  --pb-moved-fg: #222;
}

.header .topbar .pb-moved-note::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  margin-left: -6px;
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--pb-moved-bg);
  border-left: 6px solid transparent;
}

@keyframes pb-moved-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Mobile: each icon is a 48px target with no gap, so the midpoint is 48px. */
@media (max-width: 991px) {
  .header .topbar .pb-moved-note {
    top: calc(100% + 6px);
    left: 48px;
  }
}

/* No motion: the note alone carries the message. */
@media (prefers-reduced-motion: reduce) {
  .header .topbar .pb-util-icon.pb-moved-ring::after,
  .header .topbar .pb-moved-note {
    animation: none;
  }
}
