/* =======================================================
   Jorstr Header Contract
   Shared top-level header regions and identity control.
   ======================================================= */

.jorstr-page-header {
  --jorstr-header-control-height: 40px;
  --jorstr-header-avatar-size: 30px;
  --jorstr-header-ring-size: 2px;
  --jorstr-header-success-soft: rgba(82, 210, 115, 0.42);
  --jorstr-header-success-ring: var(--jorstr-header-success, #52d273);

  display: grid;
  grid-template-columns:
    auto
    minmax(0, 1fr)
    auto
    auto;
  align-items: center;
  gap: 14px 20px;
  min-height: 88px;
}

.jorstr-header-brand,
.jorstr-header-nav,
.jorstr-header-context,
.jorstr-header-actions {
  min-width: 0;
}

.jorstr-header-brand {
  grid-column: 1;
}

.jorstr-header-nav,
.jorstr-header-context {
  grid-column: 2;
}

.jorstr-header-actions {
  grid-column: 3;
}

.jorstr-header-identity {
  grid-column: 4;
  justify-self: end;
  align-self: center;
  min-width: 0;
}

.jorstr-identity-control {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  max-width: min(260px, 38vw);
  min-height: var(--jorstr-header-control-height);
  padding: 5px 12px;
  border: 1px solid
    var(--jorstr-header-border, rgba(151, 128, 255, 0.34));
  border-radius: 999px;
  background:
    var(--jorstr-header-control-bg, rgba(31, 27, 45, 0.82));
  color: var(--jorstr-header-text, currentColor);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 750;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}

.jorstr-identity-control[data-capability-tooltip]::after {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  width: max-content;
  max-width: 220px;
  padding: 6px 9px;
  border: 1px solid
    var(--jorstr-header-border, rgba(151, 128, 255, 0.34));
  border-radius: 8px;
  background:
    var(--jorstr-header-tooltip-bg, rgba(20, 17, 31, 0.96));
  color: var(--jorstr-header-text, currentColor);
  box-shadow:
    0 10px 26px rgba(0, 0, 0, 0.24);
  content: attr(data-capability-tooltip);
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-2px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.jorstr-identity-control[data-capability-tooltip]:hover::after,
.jorstr-identity-control[data-capability-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.jorstr-identity-control:hover:not(:disabled),
.jorstr-identity-control:focus-visible {
  border-color:
    var(--jorstr-header-border-strong, rgba(151, 128, 255, 0.62));
  background:
    var(--jorstr-header-control-hover-bg, rgba(38, 33, 55, 0.94));
}

.jorstr-identity-control:disabled {
  cursor: default;
  opacity: 0.72;
}

.jorstr-identity-avatar {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: var(--jorstr-header-avatar-size);
  height: var(--jorstr-header-avatar-size);
  border-radius: 50%;
  background:
    var(--jorstr-header-avatar-bg, rgba(132, 104, 255, 0.2));
  color: var(--jorstr-header-avatar-text, #f4f1ff);
  font-size: 0.78rem;
  font-weight: 850;
  line-height: 1;
  overflow: hidden;
}

.jorstr-identity-control[data-capability-state="ready"] .jorstr-identity-avatar {
  box-shadow:
    0 0 0 var(--jorstr-header-ring-size)
      var(--jorstr-header-success-ring);
}

.jorstr-identity-control[data-capability-state="available"] .jorstr-identity-avatar {
  box-shadow:
    0 0 0 var(--jorstr-header-ring-size)
      var(--jorstr-header-success-soft);
  animation:
    jorstr-identity-available-pulse
      10s
      ease-out
      infinite;
}

.jorstr-identity-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.jorstr-identity-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes jorstr-identity-available-pulse {
  0%,
  78%,
  100% {
    box-shadow:
      0 0 0 var(--jorstr-header-ring-size)
        var(--jorstr-header-success-soft);
  }

  88% {
    box-shadow:
      0 0 0 var(--jorstr-header-ring-size)
        rgba(82, 210, 115, 0.66),
      0 0 0 6px
        rgba(82, 210, 115, 0.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  .jorstr-identity-control[data-capability-state="available"] .jorstr-identity-avatar {
    animation: none;
    box-shadow:
      0 0 0 var(--jorstr-header-ring-size)
        var(--jorstr-header-success-soft);
  }
}

@media (max-width: 720px) {
  .jorstr-page-header {
    grid-template-columns:
      minmax(0, 1fr)
      auto;
    min-height: 72px;
  }

  .jorstr-header-brand {
    grid-column: 1;
    grid-row: 1;
  }

  .jorstr-header-identity {
    grid-column: 2;
    grid-row: 1;
  }

  .jorstr-header-nav,
  .jorstr-header-context,
  .jorstr-header-actions {
    grid-column: 1 / -1;
  }

  .jorstr-identity-control {
    max-width: min(210px, 48vw);
  }
}
