/* Shell Topbar — shared between Backstage and App */

.shell-topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--space-12);
  padding: 0 var(--space-4);
  background: var(--shell-topbar-bg, var(--color-surface-inset));
  border-bottom: 1px solid var(--shell-topbar-border, var(--color-border-default));
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  color: var(--shell-topbar-color, var(--color-text-primary));
}

/* App (front-end) override */
.app .shell-topbar {
  --shell-topbar-bg: var(--color-topbar-bg);
  --shell-topbar-border: var(--color-topbar-bg);
  --shell-topbar-color: var(--color-brand-text);
}

/* App dark-mode override — match the tray rail */
[data-theme="dark"] .app .shell-topbar {
  --shell-topbar-bg: #0d1117;
  --shell-topbar-border: var(--color-border-default);
  --shell-topbar-color: var(--color-text-primary);
}

/* Backstage override — red/destructive topbar */
.backstage .shell-topbar {
  --shell-topbar-bg: var(--color-destructive);
  --shell-topbar-border: var(--color-destructive-hover);
  --shell-topbar-color: #ffffff;
}

/* Brand */
.shell-topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.shell-topbar__logo {
  height: 2.25rem;
  width: auto;
}

.shell-topbar__logo--dark { display: none; }

[data-theme="dark"] .shell-topbar__logo--light { display: none; }
[data-theme="dark"] .shell-topbar__logo--dark { display: block; }

.shell-topbar__label {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  opacity: 0.75;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Actions (right side) */
.shell-topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* User dropdown wrapper */
.shell-topbar__user {
  position: relative;
}

/* Avatar button */
.shell-topbar__avatar {
  display: flex;
  align-items: center;
  padding: var(--space-1);
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  color: inherit;
  cursor: pointer;
  transition: opacity var(--duration-fast) var(--easing-default);
}

.shell-topbar__avatar:hover {
  opacity: 0.85;
}

.shell-topbar__avatar-text {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--space-8);
  height: var(--space-8);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-brand-text);
  background: var(--color-avatar-bg);
  border-radius: var(--radius-full);
}

/* Dropdown menu */
.shell-topbar__dropdown {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  min-width: 12rem;
  background: var(--color-surface-base);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  overflow: hidden;
}

.shell-topbar__dropdown-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
}

.shell-topbar__dropdown-header strong {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
}

.shell-topbar__dropdown-sub {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.shell-topbar__dropdown-divider {
  border: none;
  border-top: 1px solid var(--color-border-subtle);
}

.shell-topbar__dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  transition: background var(--duration-fast) var(--easing-default);
}

.shell-topbar__dropdown-item:hover {
  background: var(--color-surface-100);
  color: var(--color-text-primary);
}

.shell-topbar__dropdown-item--danger {
  color: var(--color-text-muted);
}

.shell-topbar__dropdown-item--danger:hover {
  color: var(--color-destructive);
}

/* Theme pill toggle inside dropdown */
.shell-topbar__dropdown-theme {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
}

.shell-topbar__dropdown-theme-label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.shell-topbar__theme-pill {
  display: flex;
  background: var(--color-surface-200);
  border-radius: var(--radius-full);
  padding: 2px;
  gap: 2px;
}

.shell-topbar__theme-pill-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--space-8);
  height: var(--space-6);
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--duration-fast) var(--easing-default);
}

.shell-topbar__theme-pill-btn:hover {
  color: var(--color-text-primary);
}

.shell-topbar__theme-pill-btn--active {
  background: var(--color-control-bg);
  color: var(--color-text-primary);
  box-shadow: var(--shadow-sm);
}

/* Help button
   rgba values are intentional — semi-transparent white overlays on the
   dynamically-colored topbar background (brand or destructive). No single
   semantic token can represent "white at N% opacity on an unknown bg." */
.shell-topbar__help-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  color: inherit;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--duration-fast) var(--easing-default),
              border-color var(--duration-fast) var(--easing-default);
  white-space: nowrap;
}

.shell-topbar__help-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.4);
}

.shell-topbar__help-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* --------------------------------------------------------------------------
   Tooltip — custom styled tooltip for rail icons
   -------------------------------------------------------------------------- */

.tooltip {
  position: fixed;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-surface-100);
  background: var(--color-text-primary);
  border-radius: var(--radius-md);
  white-space: nowrap;
  pointer-events: none;
  z-index: var(--z-tooltip, 60);
  box-shadow: var(--shadow-md);
}

/* --------------------------------------------------------------------------
   Theme Toggle — styled to match the avatar button in the topbar
   -------------------------------------------------------------------------- */

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--space-8);
  height: var(--space-8);
  padding: var(--space-1) var(--space-2);
  background: transparent;
  border: 1px solid var(--shell-topbar-avatar-border, var(--color-border-default));
  border-radius: var(--radius-md);
  color: inherit;
  cursor: pointer;
  transition: background var(--duration-fast) var(--easing-default),
              color var(--duration-fast) var(--easing-default);
}

.theme-toggle:hover {
  background: var(--shell-topbar-avatar-hover, var(--color-surface-200));
}
