/* ARCAVOTE: one header structure at every width.
   Wide screens show one row. Narrow windows, tablets and phones use a menu. */
.site-header .wrap {
  min-height: 72px;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 16px;
}
.site-header .brand { order: 1; flex: 0 0 auto; white-space: nowrap; }
.header-nav-shell {
  order: 2;
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
}
.site-header .main-nav { flex: 0 0 auto; gap: 16px; }
.site-header .main-nav a { white-space: nowrap; }
.site-header .search {
  order: 0;
  flex: 1 1 130px;
  min-width: 125px;
  max-width: 220px;
  margin-left: auto;
}
.site-header .header-actions {
  order: 0;
  display: flex;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0;
  width: auto;
}
.site-header .header-actions .btn:not(.btn-accent) {
  height: 42px;
  padding: 0 8px;
}
.site-header .header-actions .btn-accent { margin-left: 4px; padding: 0 12px; }
.header-tools {
  order: 3;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.menu-toggle { display: none; }

/* The 1360px breakpoint also covers snapped and side-by-side desktop windows.
   This avoids a second navigation line before it could appear. */
@media (max-width: 1359px) {
  .site-header .wrap {
    min-height: 68px;
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 12px;
    padding-top: 8px;
    padding-bottom: 8px;
  }
  .site-header .brand { min-width: 0; }
  .site-header .brand span { white-space: nowrap; }
  .header-tools { margin-left: auto; }
  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-width: 84px;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--line-3);
    border-radius: var(--r-btn);
    background: var(--panel);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
  }
  .menu-toggle:hover { color: var(--text); background: var(--panel-2); }
  .menu-bars {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 18px;
    gap: 4px;
  }
  .menu-bars span {
    display: block;
    height: 2px;
    width: 100%;
    border-radius: 2px;
    background: currentColor;
    transition: transform .15s ease, opacity .15s ease;
  }
  .menu-toggle[aria-expanded="true"] .menu-bars span:first-child { transform: translateY(6px) rotate(45deg); }
  .menu-toggle[aria-expanded="true"] .menu-bars span:nth-child(2) { opacity: 0; }
  .menu-toggle[aria-expanded="true"] .menu-bars span:last-child { transform: translateY(-6px) rotate(-45deg); }

  .header-nav-shell {
    position: absolute;
    z-index: 30;
    top: 100%;
    left: 0;
    right: 0;
    display: none;
    width: 100%;
    max-height: calc(100vh - 68px);
    max-height: calc(100dvh - 68px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 18px max(20px, calc((100vw - 1232px) / 2)) 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 18px 32px rgba(0,0,0,.13);
  }
  .header-nav-shell.is-open {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 16px;
  }
  .site-header .main-nav {
    order: 0;
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    min-width: 0;
    overflow: visible;
  }
  .site-header .main-nav a {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line-2);
    border-radius: var(--r-btn);
    color: var(--text-2);
    background: var(--panel-2);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
  }
  .site-header .main-nav a:hover {
    color: var(--text);
    background: var(--surface-hover);
    border-color: var(--line-3);
  }
  .site-header .main-nav a.active {
    border-color: var(--accent);
    color: var(--text);
    background: var(--panel-2);
  }
  .site-header .search {
    order: 0;
    width: 100%;
    flex: 0 0 auto;
    margin: 0;
    max-width: none;
    min-width: 0;
    min-height: 46px;
  }
  .site-header .header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    padding-top: 14px;
    border-top: 1px solid var(--line);
  }
  .site-header .header-actions .btn:not(.btn-accent) {
    min-height: 44px;
    height: auto;
    padding: 10px 14px;
    border: 1px solid var(--line-2);
    border-radius: var(--r-btn);
    background: var(--panel-2);
  }
  .site-header .header-actions .btn:not(.btn-accent):hover { background: var(--surface-hover); }
  .site-header .header-actions .btn-accent { min-height: 44px; margin-left: 0; }
  .site-header .header-actions .btn-text.active-link {
    box-shadow: none;
    color: var(--accent);
    border-color: var(--accent);
  }
  .site-header .header-actions .inline-form { display: inline-flex; }
}

@media (max-width: 620px) {
  .site-header .brand span { font-size: 18px; }
  .site-header .main-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .site-header .header-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .site-header .header-actions > .btn,
  .site-header .header-actions .inline-form,
  .site-header .header-actions .inline-form .btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-width: 0;
  }
  .site-header .header-actions > .btn-accent { grid-column: 1 / -1; }
}

@media (max-width: 430px) {
  .site-header .wrap { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .site-header .brand { gap: 6px; }
  .site-header .brand span { font-size: 17px; }
  .site-header .theme-toggle { min-width: 44px; width: 44px; padding: 0; }
  .site-header .theme-toggle-label { display: none; }
  .menu-toggle { min-width: 44px; width: 44px; padding: 0; }
  .menu-label { display: none; }
  .header-nav-shell { padding: 16px 12px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .menu-bars span { transition: none; }
}
