:root { --context-bar-height: 4.75rem; }

@media screen {
  .member-shell--with-library-strip .context-bar {
    position: fixed;
    left: 0;
    right: 0;
    z-index: 280;
    top: var(--member-bar-offset);
  }
  .member-shell--with-library-strip .member-main { margin-top: var(--library-strip-height); }
}

/* One neutral context treatment, regardless of who owns the library. */
.context-bar {
  box-sizing: border-box;
  position: relative;
  display: flex;
  min-height: var(--context-bar-height);
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.5rem max(1.25rem, calc((100vw - 76rem) / 2));
  border-bottom: 1px solid var(--rule);
  color: var(--ink);
  background: var(--surface);
}

.context-bar__identity { display: flex; min-width: 0; max-width: min(30vw, 24rem); align-items: center; }
.context-bar__name { min-width: 0; overflow: hidden; font-family: var(--font-display); font-size: 1.35rem; line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }

.library-switcher { position: relative; min-width: 0; max-width: 100%; }
.library-switcher__button {
  display: inline-flex;
  min-width: 0;
  min-height: 44px;
  max-width: 100%;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.5rem;
  border: 1.5px solid transparent;
  border-radius: var(--radius-control);
  color: var(--ink);
  background: transparent;
  font: inherit;
  cursor: pointer;
}
.library-switcher__button:hover,
.library-switcher__button[aria-expanded="true"] { border-color: var(--selected-line); background: var(--selected-fill); }
.library-switcher__button:focus-visible,
.library-switcher__item:focus-visible,
.library-strip__tab:focus-visible { outline: 3px solid var(--selected-line); outline-offset: 2px; }
.library-switcher__title { min-width: 0; overflow: hidden; font-family: var(--font-display); font-size: 1.35rem; font-weight: 400; line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }
.library-switcher__chevron {
  flex: none;
  width: 0.55rem;
  height: 0.55rem;
  margin-top: -0.25rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}
.library-switcher__button[aria-expanded="true"] .library-switcher__chevron { margin-top: 0.2rem; transform: rotate(225deg); }
.library-switcher__menu {
  position: absolute;
  z-index: 330;
  top: calc(100% + 0.4rem);
  left: 0;
  display: grid;
  width: min(22.5rem, calc(100vw - 2rem));
  min-width: 15rem;
  max-height: min(60vh, 28rem);
  padding: 0.4rem;
  overflow-y: auto;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-floating);
}
.library-switcher__menu[hidden] { display: none; }
.library-switcher__item {
  display: flex;
  min-height: 44px;
  align-items: center;
  padding: 0.5rem 0.7rem;
  border: 1.5px solid transparent;
  border-radius: 0.4rem;
  color: var(--ink);
  text-decoration: none;
}
.library-switcher__item:hover { background: var(--row-hover); }
.library-switcher__item[aria-current="page"] { border-color: var(--selected-line); color: var(--selected-ink); background: var(--selected-fill); font-weight: 700; }

.library-strip__tabs {
  display: flex;
  min-width: 0;
  flex: 1 1 auto;
  overflow-x: auto;
  align-self: stretch;
  align-items: center;
  gap: 0.2rem;
}
.library-strip__tab {
  display: inline-flex;
  flex: none;
  min-height: 44px;
  align-items: center;
  padding: 0 0.75rem;
  border-bottom: 3px solid transparent;
  color: var(--ink);
  background: transparent;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}
.library-strip__tab:hover { color: var(--selected-ink); }
.library-strip__tab[aria-current="page"] { border-bottom-color: var(--selected-line); color: var(--selected-ink); }

.context-bar__task { display: flex; min-width: 0; align-items: center; gap: 0.55rem; font-weight: 700; }
.context-bar__done { display: inline-flex; min-height: 44px; align-items: center; padding: 0 1rem; border: 1.5px solid var(--selected-line); border-radius: var(--radius-control); color: var(--selected-ink); background: var(--selected-fill); font-weight: 700; text-decoration: none; }

/* Picking keeps its existing actions and source links. */
.context-bar__switch { display: flex; gap: 0.75rem; }
.context-bar__switch a { color: var(--selected-ink); }
.context-bar__switch a[aria-current="page"] { font-weight: 700; }
.context-picker-action { border: 2px solid var(--selected-line); color: var(--selected-ink); background: var(--selected-fill); }

@media (max-width: 45rem) {
  .member-shell--with-library-strip { --library-strip-height: 7rem; }
  :root { --context-bar-height: 7rem; }
  .context-bar { flex-wrap: wrap; align-content: center; gap: 0.2rem 0.75rem; padding: 0.35rem 1rem; }
  .context-bar__identity { flex: 1 1 100%; max-width: 100%; }
  .library-switcher { max-width: 100%; }
  .library-switcher__button { max-width: 100%; }
  .library-switcher__title { max-width: calc(100vw - 4.5rem); }
  .library-strip__tabs { width: 100%; flex-basis: 100%; overflow-x: auto; scrollbar-width: thin; }
  .library-strip__tab { flex: none; }
  .library-switcher__menu { position: fixed; top: auto; left: 1rem; width: calc(100vw - 2rem); max-width: none; }
  .context-bar__task { flex: 1 1 auto; }
}
