/*
  SHELL: the frame around every signed-in page (`.s-*`): top bar, primary nav, global search,
  account menu, flash, environment banner, footer. Plus the brand mark and the sign-up prompt,
  which the shell renders on every page.
*/

/* ---------- Brand mark (components/_brand) ---------- */

.c-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2-5);
  color: var(--color-text-strong);
  text-decoration: none;
  white-space: nowrap;
}

a.c-brand:hover {
  color: var(--color-text-strong);
  text-decoration: none;
}

.c-brand__mark {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: var(--color-brand-tile);
  color: var(--color-brand-core);
}

.c-brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.c-brand__name {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
}

.c-brand__tagline {
  margin-top: 2px;
  color: var(--color-text-subtle);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0.01em;
}

.c-brand--lg .c-brand__mark {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: var(--radius-lg);
}

.c-brand--lg .c-brand__mark svg {
  width: 1.5rem;
  height: 1.5rem;
}

.c-brand--lg .c-brand__name {
  font-size: var(--text-xl);
}

.c-brand--lg .c-brand__tagline {
  font-size: var(--text-xs);
}

/* ---------- Skip link ---------- */

.s-skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-action);
  color: var(--color-action-text);
  font-weight: var(--weight-semibold);
  transform: translateY(-200%);
}

.s-skip-link:focus-visible {
  transform: none;
  color: var(--color-action-text);
}

.s-main:focus {
  outline: none;
}

/* ---------- Top bar ---------- */

.s-topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.s-topbar__inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-6);
  height: var(--topbar-height);
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.s-nav__list {
  display: flex;
  align-items: center;
  gap: var(--space-0-5);
  padding: 0;
  list-style: none;
}

.s-nav__link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  height: 2.125rem;
  padding: 0 var(--space-2-5);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  text-decoration: none;
}

.s-nav__link:hover {
  background: var(--color-surface-sunken);
  color: var(--color-text-strong);
  text-decoration: none;
}

.s-nav__link[aria-current="page"],
.s-nav__link.is-active {
  background: var(--color-surface-accent);
  color: var(--color-text-accent);
  font-weight: var(--weight-semibold);
}

.s-nav__link[aria-expanded="true"] {
  background: var(--color-surface-sunken);
  color: var(--color-text-strong);
}

.s-nav__more svg {
  transition: transform var(--duration-fast) var(--ease-out);
}

.s-nav__more[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

/* The More menu is a mega menu: groups in columns, anchored to the top bar (not to its button,
   which sits too far right for a menu this wide) and centred under it. */
.s-nav .c-menu {
  position: static;
}

.s-more.c-menu__popover {
  top: calc(100% - var(--space-1));
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

.s-more {
  display: grid;
  grid-template-areas:
    "people science markets rwd"
    "regulatory science markets rwd";
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: auto 1fr;
  gap: var(--space-2) var(--space-3);
  width: min(68rem, calc(100vw - 2 * var(--gutter)));
  max-height: none;
  padding: var(--space-3);
}

.s-more__group[data-group="trials-sites-and-people"] { grid-area: people; }
.s-more__group[data-group="drugs-and-science"] { grid-area: science; }
.s-more__group[data-group="companies-and-markets"] { grid-area: markets; }
.s-more__group[data-group="regulatory-and-quality"] { grid-area: regulatory; }
.s-more__group[data-group="real-world-data"] { grid-area: rwd; }

.s-more__group ul {
  padding: 0;
  list-style: none;
}

/* Search: grows to fill the space between nav and account. */
.s-search {
  flex: 1 1 18rem;
  min-width: 12rem;
  max-width: 34rem;
  margin-left: auto;
}

.s-search .c-input {
  background: var(--color-surface-sunken);
  border-color: transparent;
}

.s-search .c-input:hover {
  border-color: var(--color-border-strong);
}

.s-search .c-input:focus-visible {
  background: var(--color-surface);
}

.s-search__unavailable {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1-5);
  color: var(--color-text-subtle);
  font-size: var(--text-sm);
}

.s-account__button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text-muted);
}

.s-account__button:hover .c-avatar,
.s-account__button[aria-expanded="true"] .c-avatar {
  box-shadow: 0 0 0 3px var(--color-surface-sunken);
}

.s-account__button:focus-visible {
  outline-offset: 2px;
  border-radius: var(--radius-pill);
}

.s-account__menu {
  width: 17rem;
}

.s-account__who {
  padding: var(--space-2) var(--space-2-5);
}

.s-theme {
  display: flex;
  margin: 0 var(--space-1) var(--space-1);
}

.s-theme .c-segmented__option {
  display: inline-flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  border: 0;
  background: transparent;
}

.s-theme .c-segmented__option[aria-pressed="true"] {
  background: var(--color-surface);
  box-shadow: var(--shadow-xs);
  color: var(--color-text-strong);
  font-weight: var(--weight-semibold);
}

.s-menu-toggle {
  display: none;
}

.s-mobile-nav {
  width: min(22rem, calc(100vw - 2 * var(--space-4)));
}

/* Below 80rem the four nav labels no longer fit beside the search: fold them into Menu. */
@media (max-width: 80rem) {
  .s-nav {
    display: none;
  }

  .s-menu-toggle {
    display: block;
    order: 3;
  }

  .s-topbar__inner {
    gap: var(--space-3);
  }

  .s-search {
    max-width: none;
  }
}

@media (max-width: 40rem) {
  .c-brand__tagline {
    display: none;
  }

  .s-topbar .c-brand__text {
    display: none;
  }
}

/* ---------- Environment banner, flash, sign-up prompt ---------- */

.s-env-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-1) var(--space-2);
  padding: var(--space-1-5) var(--gutter);
  border-bottom: 1px solid var(--color-info-border);
  background: var(--color-info-bg);
  color: var(--color-text);
  font-size: var(--text-sm);
}

/* The flash band (layouts/_flash): full-width surface strip with its own bottom padding and a
   divider, so a message never floats on the page background above a white hero. */
.s-flash {
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.s-flash__inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-4) var(--gutter);
}

.c-signup-prompt--banner {
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-accent);
}

.c-signup-prompt__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  max-width: var(--container-max);
  margin-inline: auto;
  padding: var(--space-2-5) var(--gutter);
}

.c-signup-prompt--inline .c-signup-prompt__inner {
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-accent);
}

.c-signup-prompt__icon {
  width: 1.125rem;
  height: 1.125rem;
  color: var(--color-text-accent);
}

.c-signup-prompt__copy {
  flex: 1 1 20rem;
  color: var(--color-text);
  font-size: var(--text-md);
}

.c-signup-prompt__note {
  margin-right: var(--space-1);
  font-weight: var(--weight-semibold);
}

.c-signup-prompt__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

.c-signup-prompt__link {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

/* ---------- Main and footer ---------- */

.s-main {
  min-height: calc(100vh - var(--topbar-height) - 8rem);
}

.s-footer {
  margin-top: var(--space-16);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.s-footer__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4) var(--space-8);
  max-width: var(--container-max);
  margin-inline: auto;
  padding: var(--space-6) var(--gutter);
}

.s-footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}

.s-footer__links a {
  display: inline-block;
  padding-block: var(--space-1-5);
  color: var(--color-text-muted);
}

/* A page that ends on a closing band (components/_closing_band) sits flush on the footer. */
.s-main:has(> .c-closing-band:last-child) + .s-footer {
  margin-top: 0;
}

.s-footer__links a:hover {
  color: var(--color-link-hover);
}

/* "Cookie settings" is a button (it opens the consent dialog, it goes nowhere) drawn like its sibling links. */
.s-footer__button {
  display: inline-block;
  padding: var(--space-1-5) 0;
  border: 0;
  background: none;
  color: var(--color-text-muted);
  font: inherit;
  cursor: pointer;
}

.s-footer__button:hover {
  color: var(--color-link-hover);
}

.s-footer__button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-xs);
}

.s-footer__legal {
  color: var(--color-text-subtle);
  font-size: var(--text-xs);
}

/* ---------- Public (signed-out) and access layouts ---------- */

/* The viewer-dependent header group of a cacheable landing page (#4344): both states ship, landing.js
   shows one. `display: contents` keeps the children laid out as direct flex items of the top bar. */
.s-public-account { display: contents; }
.s-public-account[hidden] { display: none; }

.s-public-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
}

/* Below 48rem the brand, theme toggle and Sign in already fill the bar, so the four section links
   take a second row of their own instead of being hidden: every public area stays one tap away. */
@media (max-width: 48rem) {
  .s-topbar--public .s-topbar__inner {
    flex-wrap: wrap;
    height: auto;
    gap: var(--space-1) var(--space-3);
    padding-block: var(--space-2);
  }

  .s-topbar--public .s-public-nav {
    order: 5;
    flex: 1 0 100%;
    flex-wrap: wrap;
    margin-left: calc(-1 * var(--space-2-5));
  }

  .s-topbar--public .c-brand {
    margin-right: auto;
  }
}

/* The signed-out sun/moon theme toggle (layouts/_public_theme_toggle). An icon button the size of
   the nav links; it shows the theme a click switches TO, and its aria-label says so in words. */
.s-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  margin-right: var(--space-2);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.s-theme-toggle[hidden] { display: none; }

.s-theme-toggle:hover {
  border-color: var(--color-border);
  color: var(--color-text);
}

.s-theme-toggle:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.s-theme-toggle__icon { display: inline-flex; }
.s-theme-toggle[data-effective="dark"] .s-theme-toggle__icon--to-dark,
.s-theme-toggle[data-effective="light"] .s-theme-toggle__icon--to-light,
.s-theme-toggle:not([data-effective]) .s-theme-toggle__icon--to-light { display: none; }

.s-access {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-12) var(--space-4) var(--space-16);
}

.s-access__header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.s-access__theme {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.s-access__theme .s-theme {
  margin: 0;
}

.s-access .s-flash {
  width: min(36rem, 100%);
  margin: 0 0 var(--space-4);
  border-bottom: 0;
  background: transparent;
}

.s-access .s-flash__inner {
  padding: 0;
}

.s-access__main {
  width: min(48rem, 100%);
}
