/* ==========================================================================
   Slim Top Bar layout (STAFF-ONLY PREVIEW)
   ==========================================================================
   Every rule here is scoped under [data-ui-theme="topbar"], which base.html
   only sets when the signed-in user has Profile.layout_preference set to
   'topbar' (staff-only for now, see users/views.py). Inert for everyone else.

   One compact fixed bar (~48px): brand, grouped dropdown menus, search,
   notifications, profile. Dropdown menu colours are inherited from the global
   .site-header rules in modern-theme.css (light/dark), so only the bar
   itself and its controls are styled here. Bar keeps the brand gradient in
   both light and dark mode, same approach as the v2 glass navbar.
   ========================================================================== */

body[data-ui-theme="topbar"] {
  padding-top: 56px; /* 48px bar + small gap */
}

/* ---------- Bar ---------- */
[data-ui-theme="topbar"] .tb-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1030;
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--primary-500) 88%, transparent) 0%,
    color-mix(in srgb, var(--violet-600) 88%, transparent) 100%);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
}

[data-ui-theme="topbar"] .tb-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 48px;
  padding: 0 0.75rem;
  max-width: 1400px;
  margin: 0 auto;
}

[data-ui-theme="topbar"] .tb-brand {
  color: #ffffff;
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  white-space: nowrap;
  margin-right: 0.5rem;
}

[data-ui-theme="topbar"] .tb-brand:hover,
[data-ui-theme="topbar"] .tb-brand:focus {
  color: #ffffff;
  opacity: 0.9;
}

/* ---------- Hamburger (mobile only, sits at the far right) ---------- */
[data-ui-theme="topbar"] .tb-hamburger {
  background: transparent;
  border: 0;
  color: #ffffff;
  font-size: 1.15rem;
  padding: 0.35rem 0.5rem;
}

@media (max-width: 767.98px) {
  [data-ui-theme="topbar"] .tb-hamburger { order: 10; }
}

/* ---------- Collapse wrapper ----------
   Bootstrap hides .collapse until .show; on desktop we force it inline. */
@media (min-width: 768px) {
  [data-ui-theme="topbar"] .tb-collapse {
    display: flex !important;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    height: auto;
  }
}

@media (max-width: 767.98px) {
  [data-ui-theme="topbar"] .tb-collapse {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, var(--primary-600) 0%, var(--violet-600) 100%);
    padding: 0.75rem 1rem 1rem;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
    max-height: calc(100vh - 48px);
    overflow-y: auto;
  }
}

/* ---------- Nav links & group toggles ---------- */
[data-ui-theme="topbar"] .tb-nav {
  display: flex;
  align-items: center;
  gap: 2px;
}

[data-ui-theme="topbar"] .tb-link {
  display: inline-flex;
  align-items: center;
  color: rgba(255, 255, 255, 0.92);
  background: transparent;
  border: 0;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  white-space: nowrap;
}

[data-ui-theme="topbar"] .tb-link:hover,
[data-ui-theme="topbar"] .tb-link:focus {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.14);
}

[data-ui-theme="topbar"] .tb-link.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.2);
}

[data-ui-theme="topbar"] .tb-link:focus-visible,
[data-ui-theme="topbar"] .tb-icon-btn:focus-visible,
[data-ui-theme="topbar"] .tb-profile-btn:focus-visible,
[data-ui-theme="topbar"] .tb-hamburger:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 1px;
}

[data-ui-theme="topbar"] .tb-link-icon {
  margin-right: 0.35rem;
}

[data-ui-theme="topbar"] .tb-link.dropdown-toggle::after {
  margin-left: 0.35rem;
}

/* ---------- Right-side actions ---------- */
[data-ui-theme="topbar"] .tb-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}

[data-ui-theme="topbar"] .tb-icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.92);
  text-decoration: none;
  border: 0;
  background: transparent;
}

[data-ui-theme="topbar"] .tb-icon-btn:hover,
[data-ui-theme="topbar"] .tb-icon-btn:focus {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.14);
}

[data-ui-theme="topbar"] .tb-badge {
  position: absolute;
  top: 2px;
  right: 0;
  background: var(--danger-500);
  color: #ffffff;
  font-size: 0.62rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 5px;
  line-height: 1.2;
}

[data-ui-theme="topbar"] .tb-profile-btn {
  background: transparent;
  border: 0;
  padding: 2px;
  border-radius: 50%;
}

[data-ui-theme="topbar"] .tb-profile-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.5);
}

/* ---------- Search ---------- */
[data-ui-theme="topbar"] .tb-search {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 2px 8px 2px 12px;
}

[data-ui-theme="topbar"] .tb-search input {
  background: transparent;
  border: 0;
  outline: none;
  color: #ffffff;
  font-size: 0.85rem;
  width: 150px;
}

[data-ui-theme="topbar"] .tb-search input::placeholder {
  color: rgba(255, 255, 255, 0.65);
}

[data-ui-theme="topbar"] .tb-search-btn {
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.85);
  padding: 2px 4px;
}

[data-ui-theme="topbar"] .tb-search-mobile {
  width: 100%;
  margin-bottom: 0.5rem;
}

[data-ui-theme="topbar"] .tb-search-mobile input {
  flex: 1 1 auto;
  width: auto;
}

/* ---------- Populated menus ----------
   Menus never run past the bottom of the viewport; groups with many items
   (Posts, Parenting) spread over two columns on desktop. */
[data-ui-theme="topbar"] .tb-menu {
  max-height: calc(100vh - 64px);
  overflow-y: auto;
}

@media (min-width: 768px) {
  [data-ui-theme="topbar"] .dropdown-menu.tb-menu-wide {
    min-width: 27rem;
  }

  [data-ui-theme="topbar"] .dropdown-menu.tb-menu-wide.show {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

/* ---------- Mobile ---------- */
@media (max-width: 767.98px) {
  [data-ui-theme="topbar"] .tb-nav {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  [data-ui-theme="topbar"] .tb-link {
    width: 100%;
  }

  /* Menus expand inline inside the slide-down panel instead of floating.
     !important beats Popper's inline position/transform styles. */
  [data-ui-theme="topbar"] .tb-nav .dropdown-menu {
    position: static !important;
    transform: none !important;
    width: 100%;
    margin-top: 0.25rem;
  }
}
