/* Chrome for shared-ui's PageHeader control. A sibling of one-web's rules, not a
   mirror: geometry uses the design system's spacing and type tokens, colour uses
   sites' own. See docs/superpowers/specs/2026-09-21-page-header-in-sites-design.md.

   There is deliberately no .page-header.is-sticky rule (§4): sites' header is
   tenant-built, variable in height and sometimes absent, so there is no
   --app-header-height to offset against. Calling PageHeader::sticky() here emits a
   class nothing styles, which degrades to a static header. */
.page-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding-block-end: var(--space-4);
  border-block-end: 1px solid var(--border-color);
}

.page-header-main {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.page-header-identity {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.page-header-path {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: var(--font-size-sm, 12px);
}

.page-header-crumb {
  font-weight: 500;
  color: color-mix(in srgb, var(--color-base-foreground) 65%, transparent);
  text-decoration: none;
}

.page-header-crumb:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.page-header-crumb.is-current {
  color: var(--color-base-foreground);
  font-weight: 600;
}

.page-header-crumb-separator {
  color: color-mix(in srgb, var(--color-base-foreground) 65%, transparent);
}

.page-header-title-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.page-header-title-row h1 {
  margin: 0;
  padding: 0;
  font-size: var(--font-size-xl, 24px);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-header-qualifier {
  font-weight: 500;
  opacity: 0.72;
  margin-inline-end: var(--space-2);
}

.page-header-count {
  font-family: var(--font-mono, monospace);
  font-size: var(--font-size-sm, 13px);
  color: color-mix(in srgb, var(--color-base-foreground) 65%, transparent);
}

.page-header-stat {
  margin-left: auto;
  flex-shrink: 0;
  text-align: right;
}

.page-header-stat .label {
  font-size: var(--font-size-sm, 12px);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--color-base-foreground) 65%, transparent);
}

.page-header-stat .value {
  margin-top: 0;
  font-family: var(--font-mono, monospace);
  font-size: var(--font-size-lg, 20px);
  font-weight: 600;
}

.page-header-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: var(--space-2);
  margin-left: auto;
}

.page-header-stat + .page-header-actions {
  margin-left: var(--space-4);
}

.page-header-overflow {
  display: inline-flex;
}

@media screen and (max-width: 1023px) {
  .page-header-action {
    display: none;
  }

  .page-header-main {
    flex-wrap: nowrap;
    align-items: center;
  }

  .page-header-main:has(.page-header-stat) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .page-header-main:has(.page-header-stat) .page-header-identity {
    grid-area: 1 / 1;
  }

  .page-header-main:has(.page-header-stat) .page-header-actions {
    grid-area: 1 / 2;
    margin-left: 0;
  }

  .page-header-stat {
    grid-area: 2 / 1 / 3 / -1;
    margin-left: 0;
    text-align: left;
  }

  .page-header-path {
    flex-wrap: nowrap;
  }

  .page-header-path > * {
    display: none;
  }

  .page-header-path > a.page-header-crumb:last-of-type {
    display: inline-flex;
    align-items: center;
  }

  .page-header-path > a.page-header-crumb:last-of-type::before {
    content: "\2039";
    margin-inline-end: var(--space-1);
  }

  .page-header-path:not(:has(a.page-header-crumb)) {
    display: none;
  }
}

/* Anchors the popover to the trigger. Keyed off the class rather than the id,
   because PageHeader derives that id from its element_id and it is therefore
   per-instance. Only the overflow variant is ported: nothing in sites builds a
   primary popover yet, and one-web's rule covers both. */
.page-header-overflow-popover {
  position-area: bottom span-left;
}

/* Desktop only, deliberately: below 1024px the secondary actions are hidden and
   mirrored into this popover, so hiding the trigger there would leave them
   unreachable. */
@media screen and (min-width: 1024px) {
  .page-header-actions:not(:has(.page-header-overflow-popover :is(a, button):not(.mobile-advanced-only))) .page-header-overflow {
    display: none;
  }
}

.popup-menu li:has(.mobile-advanced-only) {
  display: none;
}

@media screen and (max-width: 1023px) {
  .popup-menu li:has(.mobile-advanced-only) {
    display: list-item;
  }
}

/* Below 768px the actions become a bar fixed to the bottom of the screen, and the
   overflow popover a bottom sheet. Scoped out of smart-dialog, whose transform would
   make the dialog, not the viewport, the containing block of a fixed element. */
:root {
  --page-header-bar-height: 4.25rem;
}

@media screen and (max-width: 767px) {
  .page-header-actions:not(smart-dialog *):has(> *) {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 20;
    min-height: var(--page-header-bar-height);
    margin: 0;
    padding: var(--space-2) var(--space-4);
    background-color: var(--color-base);
    border-top: 1px solid var(--border-color);
  }

  .page-header-actions:not(smart-dialog *) > :not(.page-header-action, .page-header-overflow, [popover]) {
    display: flex;
    flex: 1;
    min-width: 0;
    order: -1;
  }

  .page-header-actions:not(smart-dialog *) > :not(.page-header-action, .page-header-overflow, [popover]) .button,
  .page-header-actions:not(smart-dialog *) > .button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 2.875rem;
  }

  .page-header-overflow-popover:not(smart-dialog *) {
    position-area: none;
    inset: auto 0 0 0;
    width: 100%;
    max-width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    margin: 0;
    border: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: var(--space-2) var(--space-2) var(--space-4);
    background-color: var(--color-base);
    color: var(--color-base-foreground);
  }

  .page-header-overflow-popover:not(smart-dialog *)::backdrop {
    background-color: rgba(0, 0, 0, 0.4);
  }

  .page-header-overflow-popover:not(smart-dialog *)::before {
    content: "";
    display: block;
    width: 2.25rem;
    height: 4px;
    margin: var(--space-1) auto var(--space-2);
    border-radius: var(--radius-round);
    background-color: var(--border-color);
  }

  .page-header-overflow-popover:not(smart-dialog *) .popup-menu {
    width: 100%;
    border: none;
  }

  .page-header-overflow-popover:not(smart-dialog *) .popup-menu li {
    min-height: 3rem;
    display: flex;
    align-items: center;
  }

  body:has(.page-header-actions:not(smart-dialog *) > *)::after {
    content: "";
    display: block;
    height: var(--page-header-bar-height);
  }
}
