/*
 * ADS top bar: crisp vector branding and a transient account menu.
 * Loaded last so the header keeps one spatial system across every page.
 */
:root {
  --ads-header-blue: #0a84ff;
  --ads-header-blue-deep: #2563eb;
  --ads-header-text: #161617;
  --ads-header-secondary: #6e6e73;
  --ads-header-hairline: rgba(15, 23, 42, 0.1);
}

.topbar {
  position: relative;
  z-index: 150;
  background: rgba(248, 249, 251, 0.88) !important;
  border-bottom-color: var(--ads-header-hairline) !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.72) inset !important;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.topbar-brand {
  width: calc(var(--ta-sidebar-width) - 32px);
  min-width: calc(var(--ta-sidebar-width) - 32px) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0 !important;
  color: var(--ads-header-text) !important;
  text-decoration: none !important;
  -webkit-tap-highlight-color: transparent;
}

.topbar-brand:hover,
.topbar-brand:focus-visible {
  color: var(--ads-header-text) !important;
  text-decoration: none !important;
}

.topbar-brand:focus-visible {
  outline: 3px solid rgba(10, 132, 255, 0.2);
  outline-offset: 4px;
  border-radius: 8px;
}

.ads-header-logo {
  width: 136px;
  height: 44px;
  max-height: 44px;
  display: block;
  flex: 0 0 auto;
  align-self: flex-start;
  margin: 11px 0 0 !important;
  object-fit: contain;
  object-position: center;
  transform: none;
  user-select: none;
}

@media (min-width: 761px) {
  .ads-header-logo {
    position: relative !important;
    left: 0;
  }
}

.ads-header-symbol {
  display: none;
}

/* Desktop sidebar can fold into an icon rail without changing mobile navigation. */
.sidebar-toggle {
  position: static;
  z-index: auto;
  width: 36px;
  min-width: 36px;
  height: 32px;
  flex: 0 0 auto;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  box-shadow: none;
  color: #6e6e73;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 140ms ease-out, background-color 140ms ease-out, border-color 140ms ease-out, transform 100ms ease-out;
}

.sidebar-toggle:hover {
  background: rgba(118, 118, 128, 0.1);
  color: #3a3a3c;
  box-shadow: none;
}

.sidebar-toggle:active {
  transform: scale(0.96);
}

.sidebar-toggle:focus-visible {
  outline: 2px solid rgba(10, 132, 255, 0.28);
  outline-offset: 0;
}

.sidebar-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-toggle-icon {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 240ms cubic-bezier(.32, .72, 0, 1);
}

.nav > .nav-group-button:first-child .nav-group-chevron { margin-right: 0; }

.sidebar-foot {
  display: flex !important;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  width: 100%;
  min-width: 0;
  margin: auto 0 0 !important;
  padding: 0 !important;
  box-sizing: border-box;
}

.sidebar-foot > div {
  min-width: 0;
  flex: 0 0 auto;
  padding: 0 12px 8px;
}

.sidebar-foot::before {
  content: '';
  order: 1;
  width: 100%;
  height: 1px;
  margin: 0;
  background: rgba(60, 60, 67, 0.12);
  transform: translateY(1px);
}

.sidebar-foot > div { order: 0; }
.sidebar-foot > .sidebar-toggle {
  order: 2;
  align-self: flex-end;
  margin: 12px 10px 12px 0;
}

@media (min-width: 761px) {
  .sidebar {
    padding: 8px 0 0 !important;
    overflow: hidden;
  }

  .sidebar > .nav {
    min-width: 0;
    min-height: 0;
    padding-inline: 12px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .sidebar-foot {
    display: grid !important;
    grid-template-rows: auto 1px 52px;
    align-items: stretch;
    width: 100%;
    margin: auto 0 0 !important;
  }

  .sidebar-foot > div {
    grid-row: 1;
    padding: 0 12px 8px;
  }

  .sidebar-foot::before {
    grid-row: 2;
  }

  .sidebar-foot > .sidebar-toggle {
    grid-row: 3;
    align-self: center;
    justify-self: end;
    margin: 0 10px 0 0;
  }

  .sidebar,
  .workspace,
  .topbar,
  .topbar-brand {
    transition: none;
  }

  .app-shell.sidebar-collapsed .workspace {
    width: calc(100% - 64px) !important;
    margin-left: 64px !important;
  }

  .app-shell.sidebar-collapsed .topbar {
    width: calc(100% + 64px) !important;
    margin-left: -64px !important;
  }

  .app-shell.sidebar-collapsed .topbar-brand {
    width: 32px;
    min-width: 32px !important;
  }

  .app-shell.sidebar-collapsed .sidebar {
    padding-inline: 0 !important;
  }

  .app-shell.sidebar-collapsed .sidebar-toggle {
    width: 36px;
    min-width: 36px;
    height: 32px;
    padding: 0;
    margin: 0;
    align-self: center;
    transform: none;
  }

  .app-shell.sidebar-collapsed .sidebar-toggle:active {
    transform: scale(0.96);
  }

  .app-shell.sidebar-collapsed .sidebar-toggle-icon {
    transform: rotate(180deg);
  }

  .app-shell.sidebar-collapsed .nav {
    padding-top: 0;
    padding-inline: 7px;
  }

  .app-shell.sidebar-collapsed .nav-group-button {
    display: none !important;
  }

  .app-shell.sidebar-collapsed .nav-children,
  .app-shell.sidebar-collapsed .nav-children.hidden {
    display: grid !important;
    gap: 4px !important;
    margin: 0 0 5px !important;
    padding: 0 0 5px !important;
    border-bottom: 1px solid rgba(60, 60, 67, 0.1);
  }

  .app-shell.sidebar-collapsed .nav-children:last-of-type {
    border-bottom: 0;
  }

  .app-shell.sidebar-collapsed .nav-child,
  .app-shell.sidebar-collapsed .nav-standalone {
    width: 42px !important;
    min-width: 42px;
    height: 40px;
    min-height: 40px !important;
    justify-content: center;
    gap: 0 !important;
    margin: 0 auto !important;
    padding: 0 !important;
  }

  .app-shell.sidebar-collapsed .nav-label,
  .app-shell.sidebar-collapsed .sidebar-foot-label {
    display: none;
  }

  .app-shell.sidebar-collapsed .nav-icon {
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
  }

  .app-shell.sidebar-collapsed .nav-svg {
    width: 18px;
    height: 18px;
  }

  .app-shell.sidebar-collapsed .sidebar-foot {
    display: grid !important;
    grid-template-rows: auto 1px 52px;
    align-items: stretch;
    gap: 0;
    width: 100%;
    margin: auto 0 0 !important;
    padding: 0 !important;
  }

  .app-shell.sidebar-collapsed .sidebar-foot::before {
    width: 100%;
    margin: 0;
  }

  .app-shell.sidebar-collapsed .sidebar-foot > div {
    flex: 0 0 34px;
    width: 100%;
    height: 34px;
    padding: 0 0 8px;
    display: grid;
    place-items: center;
  }

  .app-shell.sidebar-collapsed .sidebar-foot > .sidebar-toggle {
    align-self: center;
    justify-self: center;
    margin: 0;
  }

  .app-shell.sidebar-collapsed .sidebar-foot .status-dot {
    margin: 0;
  }

  .app-shell.sidebar-collapsed .ads-header-logo {
    display: none;
  }

  .app-shell.sidebar-collapsed .ads-header-symbol {
    width: 32px;
    height: 32px;
    display: block;
    flex: 0 0 auto;
    border-radius: 9px;
    user-select: none;
  }
}

.topbar .account-menu {
  position: relative;
  gap: 8px;
  color: var(--ads-header-text);
}

.topbar .account-menu > * {
  flex: 0 0 auto;
}

.topbar .account-menu .vendor-code-copy {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(10, 132, 255, 0.2) !important;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.62) !important;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: background-color 140ms ease-out, border-color 140ms ease-out, transform 100ms ease-out;
}

.topbar .account-menu .vendor-code-copy:hover {
  border-color: rgba(10, 132, 255, 0.42) !important;
  background: rgba(255, 255, 255, 0.92) !important;
  text-decoration: none !important;
}

.topbar .account-menu .vendor-code-copy:active {
  transform: scale(0.98);
}

.account-popover-anchor {
  position: relative;
}

.topbar .account-popover-anchor {
  display: block !important;
}

.account-trigger {
  min-width: 0;
  height: 44px;
  display: grid;
  grid-template-columns: max-content max-content 14px;
  align-items: center;
  gap: 9px;
  padding: 4px 7px 4px 5px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ads-header-text) !important;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 140ms ease-out, transform 100ms ease-out;
}

.account-trigger:hover {
  background: rgba(0, 0, 0, 0.045);
  color: var(--ads-header-text) !important;
  text-decoration: none !important;
}

.account-trigger:active {
  transform: scale(0.985);
}

.account-trigger:focus-visible {
  outline: 3px solid rgba(10, 132, 255, 0.2);
  outline-offset: 1px;
}

.topbar .account-trigger .avatar {
  width: max-content;
  min-width: 34px;
  height: 34px;
  box-sizing: border-box;
  display: grid;
  margin: 0;
  padding: 0 9px;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 17px;
  background: linear-gradient(145deg, var(--ads-header-blue), var(--ads-header-blue-deep)) !important;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2), 0 0 0 1px rgba(37, 99, 235, 0.08);
  color: #fff !important;
  font-size: 11px;
  font-weight: 760;
  letter-spacing: -0.02em;
}

.topbar .account-trigger .avatar[data-avatar-length="1"],
.topbar .account-trigger .avatar[data-avatar-length="2"] {
  width: 34px;
  padding-inline: 0;
  border-radius: 50%;
}

.topbar .account-trigger .avatar[data-avatar-length="3"] {
  min-width: 48px;
  padding-inline: 7px;
  font-size: 10px;
  letter-spacing: 0.02em;
}

.account-identity {
  min-width: 0;
  display: grid !important;
  gap: 2px;
  margin: 0 !important;
}

.topbar .account-identity strong,
.topbar .account-identity > span {
  max-width: none;
  display: block;
  margin: 0 !important;
  white-space: nowrap;
}

.topbar .account-identity strong {
  color: var(--ads-header-text) !important;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
}

.topbar .account-identity > span {
  color: var(--ads-header-secondary) !important;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.1;
}

.account-chevron {
  width: 12px;
  height: 12px;
  color: #8e8e93;
  transition: transform 180ms cubic-bezier(.2, .8, .2, 1);
}

.account-trigger[aria-expanded="true"] .account-chevron {
  transform: rotate(180deg);
}

.account-popover {
  position: absolute;
  z-index: 160;
  top: calc(100% + 7.5px);
  right: 0;
  width: 108px;
  box-sizing: border-box;
  padding: 5px;
  overflow: hidden;
  border: 1px solid var(--ta-glass-edge);
  border-radius: 11px;
  background: var(--ads-performance-popover-bg);
  box-shadow: var(--ta-shadow-glass);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-3px) scale(0.985);
  transform-origin: top right;
  transition: opacity 130ms ease-out, transform 180ms cubic-bezier(.2, .8, .2, 1);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.account-popover[hidden] {
  display: none !important;
}

.account-popover.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.account-popover-action {
  width: 100%;
  min-height: 34px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #1d1d1f !important;
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms ease-out, transform 90ms ease-out;
}

.account-popover-action:hover {
  background: rgba(118, 118, 128, 0.11);
  color: #1d1d1f !important;
  text-decoration: none !important;
}

.account-popover-action:active {
  transform: scale(0.985);
}

.account-popover-action:focus-visible {
  outline: 3px solid rgba(10, 132, 255, 0.18);
  outline-offset: -1px;
}

.account-popover-action > svg {
  width: 16px;
  height: 16px;
  justify-self: center;
  color: #5f6368;
}

.account-popover-action > span {
  min-width: 0;
  display: grid !important;
  gap: 2px;
  margin: 0 !important;
}

.topbar .account-popover-action strong,
.topbar .account-popover-action small {
  display: block;
  margin: 0;
}

.topbar .account-popover-action strong {
  color: inherit !important;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.topbar .account-popover-action small {
  color: #8e8e93;
  font-size: 9px;
  font-weight: 500;
  line-height: 1.25;
}

.account-popover-action.danger,
.account-popover-action.danger > svg,
.topbar .account-popover-action.danger strong {
  color: #d70015 !important;
}

.account-popover-separator {
  height: 1px;
  margin: 2px 5px;
  background: var(--ta-line);
}

@media (max-width: 760px) {
  .sidebar-toggle {
    display: none;
  }

  .topbar-brand {
    width: fit-content;
    min-width: 0;
    justify-content: flex-start;
  }

  .ads-header-logo {
    width: 136px;
    height: 44px;
    max-height: 44px;
    margin-top: 11px !important;
    transform: none;
  }

  .account-trigger {
    height: 42px;
    display: grid;
    grid-template-columns: max-content max-content 12px;
    gap: 7px;
    padding: 4px 6px 4px 4px;
  }

  .account-popover {
    position: fixed;
    top: 62px;
    right: 8px;
    width: min(108px, calc(100vw - 16px));
  }

  .account-popover-action {
    min-height: 44px;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding-inline: 9px !important;
  }

  .topbar .account-identity strong {
    font-size: 11px;
  }
}

@media (max-width: 420px) {
  .topbar .account-menu .vendor-code-copy {
    display: none !important;
  }

  .topbar .account-identity > span {
    display: none !important;
  }

  .account-identity {
    gap: 0;
  }

  .account-trigger {
    grid-template-columns: max-content max-content 10px;
    gap: 5px;
    padding-inline: 3px 4px;
  }

  .topbar .account-trigger .avatar {
    min-width: 32px;
    height: 32px;
  }

  .topbar .account-trigger .avatar[data-avatar-length="1"],
  .topbar .account-trigger .avatar[data-avatar-length="2"] {
    width: 32px;
  }

  .topbar .account-trigger .avatar[data-avatar-length="3"] {
    min-width: 46px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .account-trigger,
  .account-chevron,
  .account-popover,
  .account-popover-action,
  .topbar .account-menu .vendor-code-copy,
  .sidebar,
  .workspace,
  .topbar,
  .topbar-brand,
  .sidebar-toggle,
  .sidebar-toggle-icon {
    transition: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .topbar,
  .account-popover {
    background: #f8f9fb !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .account-popover {
    background: #fff !important;
  }
}

@media (prefers-contrast: more) {
  .topbar,
  .account-popover,
  .topbar .account-menu .vendor-code-copy {
    border-color: rgba(15, 23, 42, 0.32) !important;
  }
}
