/* ==========================================================================
   LAYOUT — site header, primary navigation + dropdowns, footer
   ========================================================================== */

/* ---- Header ---- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 900;
  height: var(--header-height);
  display: flex;
  align-items: center;
  background: var(--color-header-bg);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--color-border);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
}

/* ---- Brand mark ---- */
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-md);
  color: var(--color-text);
  min-width: 0;
  flex-shrink: 1;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.brand-name {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-name strong {
  font-size: var(--fs-sm);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-name span {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Primary nav ---- */
.primary-nav {
  display: flex;
}

.nav-list {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-3);
  font-weight: 600;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
}

.nav-link:hover,
.nav-link[aria-current="page"] {
  color: var(--color-accent);
}

.nav-link .caret {
  width: 14px;
  height: 14px;
  transition: transform var(--duration-fast) var(--ease-standard);
}

.nav-item.has-dropdown:hover .caret,
.nav-item.has-dropdown:focus-within .caret,
.nav-item.has-dropdown.is-open .caret {
  transform: rotate(180deg);
}

.nav-item {
  position: relative;
}

/* Desktop hover-flyout dropdown. Scoped to min-width so it can never
   conflict with the mobile in-flow dropdown below — these two are
   mutually exclusive by width, not just visually overridden, which
   avoids CSS specificity fights between them (a class selector here
   like ".nav-item.has-dropdown.is-open .dropdown-panel" is more specific
   than a plain ".dropdown-panel" reset inside the mobile media query, so
   without this width scoping the desktop transform can win even on
   mobile). */
@media (min-width: 901px) {
  .dropdown-panel {
    position: absolute;
    top: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(-6px);
    min-width: 240px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: var(--space-2);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--duration-fast) var(--ease-standard),
      transform var(--duration-fast) var(--ease-standard),
      visibility var(--duration-fast);
  }

  .nav-item.has-dropdown:hover .dropdown-panel,
  .nav-item.has-dropdown:focus-within .dropdown-panel,
  .nav-item.has-dropdown.is-open .dropdown-panel {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
  }
}

.dropdown-link {
  display: flex;
  flex-direction: column;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-weight: 600;
  font-size: var(--fs-sm);
}

.dropdown-link small {
  font-weight: 400;
  font-size: var(--fs-2xs);
  color: var(--color-text-subtle);
  margin-top: 2px;
}

.dropdown-link:hover {
  background: var(--color-surface);
  color: var(--color-accent);
}

/* ---- Header controls (theme toggle, search, mobile trigger) ---- */
.header-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: background-color var(--duration-fast) var(--ease-standard),
    color var(--duration-fast) var(--ease-standard);
}

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

.icon-btn svg { width: 20px; height: 20px; }

.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: inline-flex; }

.nav-toggle { display: none; }

/* ---- Narrow-phone header safety margin ----
   Three 42px icon buttons + a two-line brand lockup can outgrow very
   narrow screens (this is what was pushing the hamburger button
   off-screen). Reclaim space before that happens: drop the brand
   subtitle and shrink the icon buttons slightly. */
@media (max-width: 420px) {
  /* .brand-name span { display: none; } */
  .icon-btn { width: 38px; height: 38px; }
  .icon-btn svg { width: 18px; height: 18px; }
  .header-controls { gap: var(--space-1); }
  .site-header .container { gap: var(--space-3); }
}

/* ---- Mobile navigation ----
   Uses position:absolute (anchored to the sticky header, which is already
   a positioned ancestor) + a max-height reveal instead of
   position:fixed + transform. Combining fixed positioning with a
   transform on the same element causes real cross-browser containing-
   block bugs (the panel and its links can render measurably offset from
   the viewport edge) — this pattern avoids that entirely. */
@media (max-width: 900px) {
  .primary-nav {
    display: block;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    width: 100%;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    padding: 0 var(--container-pad);
    max-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    visibility: hidden;
    transition: max-height var(--duration-slow) var(--ease-standard),
      padding var(--duration-slow) var(--ease-standard),
      visibility 0s linear var(--duration-slow);
  }

  .primary-nav.is-open {
    max-height: calc(100vh - var(--header-height));
    padding: var(--space-5) var(--container-pad);
    visibility: visible;
    transition: max-height var(--duration-slow) var(--ease-standard),
      padding var(--duration-slow) var(--ease-standard),
      visibility 0s linear 0s;
  }

  .nav-list {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-1);
  }

  .nav-link {
    padding: var(--space-4);
    justify-content: space-between;
    border-bottom: 1px solid var(--color-border);
    width: 100%;
  }

  .dropdown-panel {
    position: static;
    transform: none;
    opacity: 1;
    visibility: visible;
    box-shadow: none;
    border: none;
    border-left: 2px solid var(--color-border-strong);
    background: var(--color-surface);
    display: none;
    min-width: 0;
    width: 100%;
    padding: var(--space-2) 0 var(--space-2) var(--space-3);
    margin: 0 0 var(--space-2);
  }

  .nav-item.has-dropdown.is-open .dropdown-panel { display: block; }

  .nav-toggle {
    display: inline-flex;
  }
}

/* ---- Back to top button ---- */
.back-to-top {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-7);
  z-index: 800;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-circle);
  background: var(--color-accent);
  color: var(--color-text-on-accent);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity var(--duration-base) var(--ease-standard),
    transform var(--duration-base) var(--ease-standard),
    visibility var(--duration-base),
    background-color var(--duration-fast) var(--ease-standard);
}

.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top:hover {
  background: var(--color-accent-hover);
  color: var(--color-text-on-accent);
}

.back-to-top svg {
  width: 20px;
  height: 20px;
}

@media (max-width: 900px) {
  .back-to-top {
    right: var(--space-4);
    bottom: var(--space-4);
    width: 44px;
    height: 44px;
  }
}
/* ---- Footer ---- */
.site-footer {
  background: var(--color-footer-bg);
  color: var(--color-footer-text);
  padding-block: var(--space-8) var(--space-6);
}

.footer-grid {
  display: grid;
  grid-template-columns: 1.4fr repeat(3, 1fr);
  gap: var(--space-7);
}

.footer-brand p {
  color: var(--color-footer-text);
  opacity: 0.75;
  max-width: 32ch;
  margin-top: var(--space-3);
}

.footer-heading {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--pciu-slate-400);
  margin-bottom: var(--space-4);
}

.footer-links li + li { margin-top: var(--space-2); }

.footer-links a {
  color: var(--color-footer-text);
  opacity: 0.85;
  font-size: var(--fs-sm);
}

.footer-links a:hover { opacity: 1; color: var(--pciu-blue-400); }

.footer-social {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.footer-social a {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-footer-text);
}

.footer-social a:hover { background: var(--pciu-blue-600); color: #fff; }
.footer-social svg { width: 17px; height: 17px; }

.footer-bottom {
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  /* padding-bottom: var(--space-6); */
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  justify-content: space-between;
  font-size: var(--fs-xs);
  opacity: 0.7;
}

.footer-bottom p{
  color: #fff;
}

@media (max-width: 800px) {
  .footer-grid {
    grid-template-columns: 1fr 1fr;
  }
  .footer-brand { grid-column: 1 / -1; }
}
