/* ══════════════════════════════════════════════════════════════════════════
   ESTEEM ADMIN — COUNT BADGES
   Drop-in. Link this AFTER styles.css:
     <link rel="stylesheet" href="styles.css" />
     <link rel="stylesheet" href="dashboard-badges.css" />

   Covers every count indicator in the dashboard:
     .nav-count-badge   sidebar nav (Applications, etc.)
     .tab-count-badge   legacy badge injected by feature modules
     .topbar-badge      messages / notifications in the top bar

   Sizing is driven by data-digits, which Badges.js sets. Without that
   script the badges still render correctly — they just won't grow into a
   capsule for three-digit counts.
══════════════════════════════════════════════════════════════════════════ */

/* ── 1. Undo the flex stretch ─────────────────────────────────────────────
   .sidebar .nav-btn span { flex: 1 } in the page's inline styles catches
   the badge span too. These selectors carry higher specificity, so the
   badge sizes to its content instead of filling the row. */

.sidebar .nav-btn .nav-count-badge,
.sidebar .nav-btn .tab-count-badge {
  flex: 0 0 auto;
  margin-left: auto;
}

/* ── 2. Shared badge geometry ─────────────────────────────────────────── */

.nav-count-badge,
.tab-count-badge,
.topbar-badge {
  --badge-size: 19px;

  box-sizing: border-box;
  display: inline-grid;
  place-items: center;
  width: var(--badge-size);
  height: var(--badge-size);
  min-width: var(--badge-size);
  padding: 0;
  border: none;
  border-radius: 999px;

  font-family: var(--font, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
  font-size: 10.5px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;

  white-space: nowrap;
  overflow: hidden;
  user-select: none;
  transition: transform .18s cubic-bezier(.2,.9,.2,1.1), background .2s ease;
}

/* Two digits still fit the circle; three or more open into a capsule. */
.nav-count-badge[data-digits="3"],
.tab-count-badge[data-digits="3"],
.topbar-badge[data-digits="3"] {
  width: auto;
  padding: 0 6px;
  border-radius: 999px;
}

.nav-count-badge[data-digits="2"],
.tab-count-badge[data-digits="2"],
.topbar-badge[data-digits="2"] {
  font-size: 9.5px;
}

/* Hidden wins over any inline display left behind by older code. */
.nav-count-badge.hidden,
.tab-count-badge.hidden,
.topbar-badge.hidden {
  display: none !important;
}

/* ── 3. Sidebar nav badge — brand green ───────────────────────────────── */

.nav-count-badge,
.tab-count-badge {
  color: #fff;
  background: linear-gradient(145deg, #17916a 0%, #0b5238 100%);
  box-shadow:
    0 1px 2px rgba(11, 82, 56, .34),
    inset 0 1px 0 rgba(255, 255, 255, .28),
    inset 0 -1px 0 rgba(0, 0, 0, .08);
}

/* Needs attention — pending applications, unread items */
.nav-count-badge.is-alert,
.tab-count-badge.is-alert {
  background: linear-gradient(145deg, #fb5c74 0%, #be123c 100%);
  box-shadow:
    0 1px 2px rgba(190, 18, 60, .34),
    inset 0 1px 0 rgba(255, 255, 255, .3),
    inset 0 -1px 0 rgba(0, 0, 0, .08);
}

/* The badge tracks the row's state so it never looks detached */
.sidebar .nav-btn.active .nav-count-badge,
.sidebar .nav-btn.active .tab-count-badge {
  box-shadow:
    0 1px 3px rgba(11, 82, 56, .4),
    inset 0 1px 0 rgba(255, 255, 255, .34);
}

.sidebar .nav-btn:hover .nav-count-badge,
.sidebar .nav-btn:hover .tab-count-badge {
  transform: scale(1.06);
}

/* ── 4. Top bar badge — pinned to the icon corner ─────────────────────── */

.topbar-actions .topbar-icon-btn {
  overflow: visible;
}

.topbar-actions .topbar-icon-btn .topbar-badge {
  --badge-size: 18px;

  position: absolute;
  top: -5px;
  right: -5px;
  z-index: 2;

  color: #fff;
  background: linear-gradient(145deg, #fb5c74 0%, #be123c 100%);
  box-shadow:
    0 0 0 2px #fff,
    0 2px 6px rgba(190, 18, 60, .32),
    inset 0 1px 0 rgba(255, 255, 255, .3);
}

/* ── 5. Collapsed icon rail ───────────────────────────────────────────── */

@media (min-width: 1101px) {
  .admin-page.sidebar-collapsed .nav-count-badge,
  .admin-page.sidebar-collapsed .tab-count-badge {
    --badge-size: 16px;

    position: absolute;
    top: 5px;
    right: 6px;
    margin-left: 0;
    font-size: 9px;
    box-shadow:
      0 0 0 2px #fff,
      0 2px 5px rgba(11, 82, 56, .3),
      inset 0 1px 0 rgba(255, 255, 255, .28);
  }

  .admin-page.sidebar-collapsed .nav-count-badge.is-alert,
  .admin-page.sidebar-collapsed .tab-count-badge.is-alert {
    box-shadow:
      0 0 0 2px #fff,
      0 2px 5px rgba(190, 18, 60, .3),
      inset 0 1px 0 rgba(255, 255, 255, .3);
  }

  /* Three digits won't fit the rail — clamp to a tight capsule */
  .admin-page.sidebar-collapsed .nav-count-badge[data-digits="3"],
  .admin-page.sidebar-collapsed .tab-count-badge[data-digits="3"] {
    padding: 0 4px;
    font-size: 8.5px;
  }
}

/* ── 6. Count change ──────────────────────────────────────────────────── */

@keyframes badgeBump {
  0%   { transform: scale(1); }
  38%  { transform: scale(1.32); }
  100% { transform: scale(1); }
}

.nav-count-badge.is-bump,
.tab-count-badge.is-bump,
.topbar-badge.is-bump {
  animation: badgeBump .42s cubic-bezier(.2, .9, .2, 1.1);
}

/* First appearance shouldn't pop in flat */
@keyframes badgeEnter {
  from { opacity: 0; transform: scale(.6); }
  to   { opacity: 1; transform: scale(1); }
}

.nav-count-badge.is-enter,
.tab-count-badge.is-enter,
.topbar-badge.is-enter {
  animation: badgeEnter .26s cubic-bezier(.2, .9, .2, 1.1);
}

@media (prefers-reduced-motion: reduce) {
  .nav-count-badge,
  .tab-count-badge,
  .topbar-badge {
    transition: none !important;
    animation: none !important;
  }

  .sidebar .nav-btn:hover .nav-count-badge,
  .sidebar .nav-btn:hover .tab-count-badge {
    transform: none;
  }
}