/* ==========================================================================
   PeraMorphIQ - Components
   Header, footer, buttons, cards, badges, chips, avatars, forms, lightbox.
   Responsive rules live next to their component. No raw colour values.
   ========================================================================== */

/* ==========================================================================
   Buttons - three variants, replacing the six ad-hoc styles of the old site.
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
  text-align: center;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition),
    color var(--transition);
}

.btn--primary {
  background-color: var(--accent);
  color: var(--surface);
}

.btn--primary:hover {
  background-color: var(--accent-hover);
  color: var(--surface);
}

.btn--secondary {
  background-color: transparent;
  border-color: var(--rule-strong);
  color: var(--ink-900);
}

.btn--secondary:hover {
  border-color: var(--ink-900);
  color: var(--ink-900);
}

.btn--link {
  padding: 0;
  color: var(--accent);
  border: none;
  background: none;
}

.btn--link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn--sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

/* Standalone forward link, e.g. "View all research →" */
.link-forward {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--accent);
}

.link-forward::after {
  content: "\2192";
  transition: transform var(--transition);
}

.link-forward:hover::after {
  transform: translateX(3px);
}

/* ==========================================================================
   Badges and tags
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.3rem var(--space-2);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1.4;
  color: var(--ink-700);
  background-color: var(--surface);
  white-space: nowrap;
}

/* Status is conveyed by an outlined badge with a dot - never by hue. */
.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background-color: var(--ink-300);
  flex-shrink: 0;
}

.badge--active .badge__dot {
  background-color: var(--status-active);
}

.badge--completed .badge__dot {
  background-color: var(--status-complete);
}

.badge--active,
.badge--completed {
  color: var(--ink-900);
  border-color: var(--ink-300);
}

.badge--accent {
  border-color: var(--accent);
  color: var(--accent);
  background-color: var(--accent-weak);
}

.tag {
  display: inline-block;
  padding: 0.3rem var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--ink-500);
  background-color: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  white-space: nowrap;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ==========================================================================
   Filter chips
   ========================================================================== */

.chip {
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-pill);
  background-color: var(--surface);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--ink-700);
  transition: border-color var(--transition), background-color var(--transition),
    color var(--transition);
}

.chip:hover {
  border-color: var(--ink-900);
  color: var(--ink-900);
}

.chip[aria-pressed="true"] {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
}

/* All filters sit inside one bordered block. Previously the topic row lived
   outside it, so the bar's bottom rule cut between Status and Topic. */
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding-block: var(--space-5);
  border-block: var(--border);
  margin-bottom: var(--space-7);
}

.filter-bar__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-5);
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.filter-group__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--ink-500);
  margin-right: var(--space-1);
}

.filter-bar__spacer {
  margin-left: auto;
}

.result-count {
  font-size: var(--text-sm);
  color: var(--ink-500);
}

/* ==========================================================================
   Search field
   ========================================================================== */

.search {
  position: relative;
  min-width: 26rem;
  flex: 1 1 22rem;
  max-width: 36rem;
}

.search__input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background-color: var(--surface);
  font-size: var(--text-sm);
  color: var(--ink-900);
  transition: border-color var(--transition);
}

.search__input::placeholder {
  color: var(--ink-300);
}

.search__input:hover {
  border-color: var(--ink-300);
}

.search__input:focus {
  border-color: var(--accent);
}

/* ==========================================================================
   Card primitive - border-led, not shadow-led.
   ========================================================================== */

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background-color: var(--surface);
  border: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition), transform var(--transition);
}

.card:hover {
  border-color: var(--rule-strong);
  transform: translateY(-1px);
}

.card__media {
  position: relative;
  aspect-ratio: 16 / 9;
  background-color: var(--surface-3);
  overflow: hidden;
}

/* Covers here are architecture diagrams, not photographs. `contain` keeps the
   whole figure legible inside a consistent 16:9 box; `cover` cropped tall
   diagrams down to an empty middle band. */
.card__media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: var(--space-4);
}

.card__media--photo img {
  object-fit: cover;
  padding: 0;
}

/* Projects without a cover show the group mark instead: centred, at its own
   size, at full opacity. Sized to about a third of the media box so it reads
   as an identity mark rather than a stretched image. */
.card__media--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--surface-2);
}

.card__media--placeholder img {
  width: auto;
  height: 38%;
  max-width: 60%;
  padding: 0;
  object-fit: contain;
}

.card__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5);
  flex: 1;
}

.card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--ink-500);
}

.card__title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
}

.card__title a {
  color: var(--ink-900);
}

.card__title a:hover {
  color: var(--accent);
}

.card__text {
  font-size: var(--text-sm);
  color: var(--ink-500);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card__footer {
  margin-top: auto;
  padding-top: var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

/* Stretched link - makes the whole card clickable while keeping a single,
   correctly-labelled focusable element for keyboard and screen-reader users. */
.stretched-link::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* Anything that must stay clickable above a stretched link. */
.card__body .tag-list,
.card__above {
  position: relative;
  z-index: 2;
}

/* ==========================================================================
   Header + navigation
   ========================================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-h);
  display: flex;
  align-items: center;
  background-color: var(--surface);
  border-bottom: var(--border);
}

.site-header__inner {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
}

/* PeraMorphIQ sits under ESCAL and PeraCom, so the header carries all three:
   the group's own wordmark, a hairline, then the two parent-lab marks. */
.brand-lockup {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-width: 0;
}

.brand-lockup__rule {
  width: 1px;
  height: 2.8rem;
  background-color: var(--rule);
  flex-shrink: 0;
}

.parent-orgs {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

/* Shown in their own colours at full strength. The ESCAL artwork is white, so
   the header uses a dark-ink variant of it rather than a CSS filter; the hero
   uses the white original against the dark ground. */
.parent-orgs img {
  height: 2.2rem;
  width: auto;
  transition: opacity var(--transition);
}

.parent-orgs a:hover img {
  opacity: 0.75;
}

/* Below the drawer breakpoint the header only has room for the group's own
   mark; the affiliation is still stated in the hero and the footer. */
@media (max-width: 68em) {
  .brand-lockup__rule,
  .parent-orgs {
    display: none;
  }
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--ink-900);
  flex-shrink: 0;
}

.brand:hover {
  color: var(--ink-900);
}

.brand__mark {
  height: 3.2rem;
  width: auto;
}

.wordmark {
  font-family: var(--font-wordmark);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-normal);
  color: var(--ink-900);
  line-height: 1;
}

.site-nav__list {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.site-nav__link {
  position: relative;
  display: inline-block;
  padding-block: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--ink-700);
}

.site-nav__link:hover {
  color: var(--ink-900);
}

.site-nav__link[aria-current="page"] {
  color: var(--ink-900);
  font-weight: var(--weight-semibold);
}

/* The one accent mark in the header. */
.site-nav__link[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.6rem;
  height: 2px;
  background-color: var(--accent);
}

.site-header__cta {
  margin-left: var(--space-2);
}

.nav-toggle {
  display: none;
  width: 4rem;
  height: 4rem;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  flex-shrink: 0;
}

.nav-toggle__bar {
  display: block;
  width: 1.8rem;
  height: 1.5px;
  background-color: var(--ink-900);
  position: relative;
  transition: background-color var(--transition);
}

.nav-toggle__bar::before,
.nav-toggle__bar::after {
  content: "";
  position: absolute;
  left: 0;
  width: 1.8rem;
  height: 1.5px;
  background-color: var(--ink-900);
  transition: transform var(--transition), top var(--transition);
}

.nav-toggle__bar::before {
  top: -6px;
}
.nav-toggle__bar::after {
  top: 6px;
}

[data-nav-open="true"] .nav-toggle__bar {
  background-color: transparent;
}

[data-nav-open="true"] .nav-toggle__bar::before {
  top: 0;
  transform: rotate(45deg);
}

[data-nav-open="true"] .nav-toggle__bar::after {
  top: 0;
  transform: rotate(-45deg);
}

@media (max-width: 56em) {
  .nav-toggle {
    display: inline-flex;
  }

  .site-nav {
    position: fixed;
    inset: var(--header-h) 0 0 0;
    background-color: var(--surface);
    border-top: var(--border);
    padding: var(--space-6) var(--space-5);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform var(--transition-slow), visibility var(--transition-slow);
    overflow-y: auto;
    z-index: var(--z-drawer);
  }

  [data-nav-open="true"] .site-nav {
    transform: translateX(0);
    visibility: visible;
  }

  .site-nav__list {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }

  .site-nav__list li {
    border-bottom: var(--border);
  }

  .site-nav__link {
    display: block;
    padding: var(--space-4) 0;
    font-size: var(--text-md);
  }

  .site-nav__link[aria-current="page"]::after {
    display: none;
  }

  .site-nav__link[aria-current="page"] {
    color: var(--accent);
  }

  .site-header__cta {
    margin: var(--space-5) 0 0;
    width: 100%;
  }
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  background-color: var(--surface-inverse);
  color: var(--ink-inverse-muted);
  padding-block: var(--space-8) var(--space-5);
  margin-top: var(--space-9);
}

.site-footer a {
  color: var(--ink-inverse-muted);
}

.site-footer a:hover {
  color: var(--ink-inverse);
}

.site-footer__grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr 1.2fr;
  gap: var(--space-7);
  padding-bottom: var(--space-7);
  border-bottom: 1px solid var(--rule-inverse);
}

@media (max-width: 56em) {
  .site-footer__grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-6);
  }
}

@media (max-width: 34em) {
  .site-footer__grid {
    grid-template-columns: 1fr;
  }
}

.site-footer .wordmark {
  color: var(--ink-inverse);
}

.site-footer__brand {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-width: 34rem;
}

.site-footer__tagline {
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.footer-col__title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--ink-inverse);
  margin-bottom: var(--space-4);
}

.footer-col ul {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.footer-col a,
.footer-col li {
  font-size: var(--text-sm);
}

.site-footer__bottom {
  padding-top: var(--space-5);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-xs);
}

/* ==========================================================================
   Person card
   ========================================================================== */

.person {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  text-align: left;
}

.person__photo {
  aspect-ratio: 1 / 1;
  width: 100%;
  object-fit: cover;
  border-radius: var(--radius);
  background-color: var(--surface-3);
  border: var(--border);
  filter: grayscale(1);
  transition: filter var(--transition);
}

.person:hover .person__photo {
  filter: grayscale(0);
}

.person__name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--ink-900);
  line-height: var(--leading-snug);
}

.person__role,
.person__meta {
  font-size: var(--text-xs);
  color: var(--ink-500);
}

.person__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  font-size: var(--text-xs);
}

.people-group + .people-group {
  margin-top: var(--space-8);
}

.people-group__title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--ink-500);
  padding-bottom: var(--space-3);
  border-bottom: var(--border);
  margin-bottom: var(--space-6);
}

/* ==========================================================================
   Lightbox
   ========================================================================== */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background-color: var(--scrim-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.lightbox img {
  max-width: 100%;
  max-height: 88vh;
  object-fit: contain;
  border-radius: var(--radius);
}

.lightbox__caption {
  position: absolute;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  color: var(--ink-inverse-muted);
  font-size: var(--text-sm);
  text-align: center;
  max-width: 60ch;
}

.lightbox__close {
  position: absolute;
  top: var(--space-5);
  right: var(--space-5);
  width: 4rem;
  height: 4rem;
  border-radius: var(--radius);
  color: var(--ink-inverse);
  font-size: var(--text-lg);
  line-height: 1;
  border: 1px solid var(--rule-inverse);
}

.lightbox__close:hover {
  background-color: var(--surface-inverse-2);
}

/* ==========================================================================
   Dialog (BibTeX)
   ========================================================================== */

.dialog {
  border: var(--border);
  border-radius: var(--radius);
  padding: 0;
  max-width: 68rem;
  width: calc(100% - var(--space-6));
  box-shadow: var(--shadow-md);
  color: var(--ink-700);
}

.dialog::backdrop {
  background-color: var(--scrim);
}

.dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: var(--border);
}

.dialog__title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
}

.dialog__body {
  padding: var(--space-5);
}

.dialog__body pre {
  background-color: var(--surface-2);
  border: var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  overflow-x: auto;
  font-size: var(--text-xs);
  line-height: var(--leading-snug);
  color: var(--ink-700);
  white-space: pre;
}

.dialog__foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: 0 var(--space-5) var(--space-5);
}

/* ==========================================================================
   Forms
   ========================================================================== */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--ink-900);
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--ink-500);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background-color: var(--surface);
  font-size: var(--text-sm);
  color: var(--ink-900);
  transition: border-color var(--transition);
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
}

.field textarea {
  resize: vertical;
  min-height: 12rem;
  line-height: var(--leading-normal);
}
