/* The header lives inside #header-root (a direct child of <body>). Sticky must
   live on this wrapper — not the inner <header> — so its containing block is the
   full-height <body> and it stays pinned through the whole scroll. */
#header-root {
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header {
  z-index: 100;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  height: 64px;
}

.header-inner {
  max-width: var(--container-xl);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--color-text-heading);
  text-decoration: none;
}

.header-logo:hover {
  text-decoration: none;
  color: var(--color-primary);
}

.header-logo svg {
  width: 28px;
  height: 28px;
}

.header-logo img {
  height: 40px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 24px;
}

/* On desktop the drawer header is hidden and the link wrapper is transparent
   so links become direct flex children of .header-nav (mobile overrides these). */
.header-nav-header {
  display: none;
}

.header-nav-links {
  display: contents;
}

.header-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color var(--motion-fast) var(--ease-standard);
  position: relative;
}

.header-nav a::after {
  content: '';
  position: absolute;
  bottom: 8px;
  left: 50%;
  width: 0;
  height: 2px;
  background: var(--color-primary-vivid);
  transition: all var(--motion-base) var(--ease-standard);
  transform: translateX(-50%);
  border-radius: 1px;
}

.header-nav a:hover {
  color: var(--color-primary);
}

.header-nav a:hover::after {
  width: 60%;
}

.header-nav a.active {
  color: var(--color-primary);
  font-weight: 600;
}

.header-nav a.active::after {
  width: 60%;
}

.header-nav a svg {
  display: none;
}

.mobile-nav-divider,
.mobile-nav-actions {
  display: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions .btn-outline {
  padding: 6px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-pill);
  border-color: var(--color-border);
  background: transparent;
  color: var(--color-text-muted);
  transition: all var(--motion-fast) var(--ease-standard);
}

.header-actions .btn-outline:hover {
  border-color: var(--color-primary-vivid);
  color: var(--color-primary-vivid);
  background: rgba(152, 32, 42, 0.04);
}

.header-actions .btn-primary {
  padding: 6px 20px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-pill);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
  transition: all var(--motion-fast) var(--ease-standard);
}

.header-actions .btn-primary:hover {
  background: #4A1317;
  border-color: #4A1317;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 12px 4px 4px;
  min-height: 44px;
  border-radius: var(--radius-pill);
  color: inherit;
  text-decoration: none;
  transition: background var(--motion-fast);
}

.header-user:hover {
  text-decoration: none;
}

.header-user:hover {
  background: var(--color-bg-soft);
}

.header-user-name {
  font-size: 0.85rem;
  font-weight: 600;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notification-bell {
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  color: inherit;
  text-decoration: none;
  transition: background var(--motion-fast);
}

.notification-bell:hover {
  background: var(--color-bg-soft);
}

.notification-bell svg {
  width: 22px;
  height: 22px;
  color: var(--color-text-muted);
}

.notification-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--color-primary-vivid);
  color: var(--color-text-inverse);
  font-size: 0.6rem;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--color-bg);
}

.header-backdrop {
  display: none;
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(26,26,26,0.4);
  z-index: 98;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.header-backdrop.open {
  display: block;
  opacity: 1;
}

.header-mobile-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-sm);
}

.header-mobile-toggle svg {
  width: 24px;
  height: 24px;
  color: var(--color-text-heading);
}

/* Keyboard focus indicators for all interactive header controls */
.header-logo:focus-visible,
.header-nav a:focus-visible,
.notification-bell:focus-visible,
.header-user:focus-visible,
.header-mobile-toggle:focus-visible,
.header-nav-close:focus-visible {
  outline: 2px solid var(--color-primary-vivid);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.sidebar-mobile-toggle {
  display: none;
  background: var(--color-bg-soft);
  border: 1px solid var(--color-border);
  cursor: pointer;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 1rem;
  width: 100%;
}

.sidebar-mobile-toggle svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-mobile-toggle:hover {
  background: var(--color-grey-light);
}

.sidebar-header-mobile {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.75rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
}

.sidebar-close-btn:hover {
  background: var(--color-bg-soft);
}

.sidebar-close-btn svg {
  width: 20px;
  height: 20px;
  color: var(--color-text-muted);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(26,26,26,0.4);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.open {
  display: block;
  opacity: 1;
}

@media (max-width: 820px) {
  .header-nav {
    display: flex;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 300px;
    max-width: 85vw;
    background: var(--color-bg);
    padding: 0;
    gap: 0;
    flex-direction: column;
    z-index: 99;
    transform: translateX(100%);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    pointer-events: none;
    box-shadow: -8px 0 32px rgba(26,26,26,0.15);
    overflow-y: auto;
  }

  .header-nav.open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .header-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
  }

  .header-nav-header .header-logo-mobile img {
    height: 28px;
    width: auto;
  }

  .header-nav-close {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
  }

  .header-nav-close:hover {
    background: var(--color-bg-soft);
  }

  .header-nav-close svg {
    width: 24px;
    height: 24px;
  }

  .header-nav-links {
    display: flex;
    flex-direction: column;
    padding: 0.5rem;
    gap: 2px;
    flex: 1;
  }

  .header-nav-links a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--color-text);
    text-decoration: none;
    transition: background var(--motion-fast), color var(--motion-fast);
    opacity: 0;
    transform: translateX(12px);
  }

  .header-nav.open .header-nav-links a {
    animation: slideInLink 0.3s var(--ease-out) forwards;
  }

  .header-nav.open .header-nav-links a:nth-child(1) { animation-delay: 0.02s; }
  .header-nav.open .header-nav-links a:nth-child(2) { animation-delay: 0.05s; }
  .header-nav.open .header-nav-links a:nth-child(3) { animation-delay: 0.08s; }
  .header-nav.open .header-nav-links a:nth-child(4) { animation-delay: 0.11s; }
  .header-nav.open .header-nav-links a:nth-child(5) { animation-delay: 0.14s; }
  .header-nav.open .header-nav-links a:nth-child(6) { animation-delay: 0.17s; }
  .header-nav.open .header-nav-links a:nth-child(7) { animation-delay: 0.20s; }
  .header-nav.open .header-nav-links a:nth-child(8) { animation-delay: 0.23s; }
  .header-nav.open .header-nav-links a:nth-child(9) { animation-delay: 0.26s; }
  .header-nav.open .header-nav-links a:nth-child(10) { animation-delay: 0.29s; }

  @keyframes slideInLink {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: translateX(0); }
  }

  .header-nav-links a:hover,
  .header-nav-links a:active {
    background: var(--color-bg-soft);
    text-decoration: none;
    color: var(--color-primary);
  }

  .header-nav-links a.active {
    background: rgba(107, 29, 34, 0.08);
    color: var(--color-primary);
    font-weight: 600;
  }

  .header-nav-links a.active svg {
    color: var(--color-primary);
  }

  .header-nav-links a svg {
    display: inline-block;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--color-text-muted);
  }

  .header-nav-links .mobile-nav-divider {
    display: block;
    border-top: 1px solid var(--color-border);
    margin: 8px 0;
  }

  .header-nav-links .mobile-nav-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 0;
  }

  .mobile-nav-actions .btn {
    width: 100%;
    justify-content: center;
    padding: 14px;
    font-size: 0.95rem;
  }

  .header-backdrop {
    top: 0;
  }

  .header-mobile-toggle { display: flex; align-items: center; justify-content: center; }

  .header-actions .btn-outline,
  .header-actions .btn-primary {
    display: none;
  }

  .header-user .avatar-sm { width: 30px; height: 30px; font-size: 0.65rem; }
  .header-user-name { max-width: 80px; font-size: 0.8rem; }
  .header-logo img { max-width: 120px; height: 32px; }
  .header-actions { gap: 6px; }
  .header-inner { padding: 0 1rem; }
  .notification-bell { padding: 4px; }
  .notification-bell svg { width: 20px; height: 20px; }
  .notification-badge { width: 16px; height: 16px; font-size: 0.55rem; top: -1px; right: -1px; }

  .sidebar-mobile-toggle { display: flex; }
  .sidebar-header-mobile { display: flex; }

  #sidebar-root {
    position: relative;
    z-index: 1;
  }

  #sidebar-root .sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    background: var(--color-bg);
    border-right: 1px solid var(--color-border);
    padding: 1rem;
    overflow-y: auto;
    z-index: 92;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  #sidebar-root .sidebar.open {
    display: flex;
    transform: translateX(0);
  }

  body.menu-open {
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  .header-nav { width: 100%; max-width: 100%; }
  .header-logo img { max-width: 100px; height: 28px; }
  .header-user-name { display: none; }
  .header-actions .btn-outline,
  .header-actions .btn-primary {
    display: none;
  }
  .header-inner { padding: 0 0.75rem; }
  .header-links a { padding: 12px 14px; font-size: 0.9rem; }
}

/* ============================================================
   DASHBOARD SHELL — avoid duplicate navigation
   The left sidebar is the primary nav inside the dashboard, so the
   top-bar nav links are redundant. Keep the header slim (logo + bell +
   user) on desktop, and on mobile let the single header hamburger drawer
   carry the nav while the duplicate sidebar "Menu" toggle is hidden.
   ============================================================ */
@media (min-width: 821px) {
  body.has-dashboard-sidebar .header-nav { display: none; }
}

body.has-dashboard-sidebar .sidebar-mobile-toggle { display: none; }

/* ============================================================
   PUBLIC MEGA-MENU HEADER (Phase 1) — SMERGERS-style two-row nav
   ============================================================ */
.pub-header { height: auto; display: block; }
.pub-topbar { border-bottom: 1px solid var(--color-border); }
.pub-topbar-inner {
  max-width: var(--container-xl);
  margin: 0 auto;
  padding: 10px 1.5rem;
  display: flex;
  align-items: center;
  gap: 20px;
}
.pub-header .header-logo img { height: 38px; }

/* Search box */
.pub-search {
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 540px;
  height: 42px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: var(--color-bg);
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
}
.pub-search:focus-within { border-color: var(--color-primary-vivid); box-shadow: 0 0 0 3px rgba(152,32,42,0.08); }
.pub-search-type {
  border: none;
  background: var(--color-bg-soft);
  padding: 0 12px;
  height: 100%;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  border-right: 1px solid var(--color-border);
  outline: none;
}
.pub-search-input {
  border: none;
  flex: 1;
  height: 100%;
  padding: 0 14px;
  font-size: 0.88rem;
  color: var(--color-text);
  outline: none;
  background: transparent;
  min-width: 0;
}
.pub-search-btn {
  border: none;
  background: var(--color-primary);
  color: #fff;
  width: 46px;
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--motion-fast);
}
.pub-search-btn:hover { background: #4A1317; }
.pub-search-btn svg { width: 18px; height: 18px; }

.pub-topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

/* Dropdowns (shared) */
.pub-dd { position: relative; }
.pub-dd-menu {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 32px rgba(26,26,26,0.14);
  padding: 6px;
  z-index: 120;
  display: none;
}
.pub-dd-menu-right { left: auto; right: 0; }
.pub-dd.open .pub-dd-menu { display: block; }
.pub-dd-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
  white-space: nowrap;
}
.pub-dd-menu a:hover { background: var(--color-bg-soft); color: var(--color-primary); }
.pub-dd-menu a svg { width: 16px; height: 16px; color: var(--color-text-muted); flex-shrink: 0; }
.pub-dd-userinfo { padding: 8px 12px 10px; border-bottom: 1px solid var(--color-border); margin-bottom: 4px; }
.pub-dd-username { font-weight: 700; font-size: 0.9rem; color: var(--color-text-heading); }
.pub-dd-useremail { font-size: 0.76rem; color: var(--color-text-muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pub-caret { margin-left: 2px; transition: transform var(--motion-fast); flex-shrink: 0; }
.pub-dd.open .pub-caret { transform: rotate(180deg); }

/* + Add Profile button */
.pub-add-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: #C77A12; color: #fff;
  border: none; cursor: pointer;
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  font-size: 0.82rem; font-weight: 700;
  font-family: inherit;
  transition: filter var(--motion-fast);
}
.pub-add-btn:hover { filter: brightness(1.08); }
.pub-add-btn svg { width: 15px; height: 15px; }
.pub-add-btn .pub-caret { width: 13px; height: 13px; }

/* Avatar toggle */
.pub-avatar-toggle { background: none; border: none; cursor: pointer; padding: 2px; border-radius: 50%; display: flex; }
.pub-avatar-toggle:hover { background: var(--color-bg-soft); }

/* Main nav row */
.pub-mainnav { background: var(--color-bg); border-bottom: 1px solid var(--color-border); }
.pub-mainnav-inner {
  max-width: var(--container-xl);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
}
.pub-nav-link {
  display: inline-flex; align-items: center;
  padding: 13px 14px;
  font-size: 0.86rem; font-weight: 500;
  color: var(--color-text); text-decoration: none;
  border: none; border-bottom: 2px solid transparent;
  background: none; cursor: pointer;
  font-family: inherit; line-height: 1;
}
.pub-nav-link:hover { color: var(--color-primary); }
.pub-nav-link.active { color: var(--color-primary); font-weight: 600; border-bottom-color: var(--color-primary); }

/* Desktop: hover opens dropdowns, hide the mobile drawer */
@media (min-width: 821px) {
  .pub-dd:hover .pub-dd-menu { display: block; }
  .pub-header .header-nav { display: none; }
}

/* Mobile */
@media (max-width: 820px) {
  .pub-search,
  .pub-mainnav,
  .pub-dd-add,
  .pub-auth-btn { display: none; }
  .pub-topbar-inner { padding: 0 1rem; height: 60px; gap: 10px; }
  .pub-topbar-actions { gap: 6px; }
  .pub-drawer-search { padding: 8px 8px 4px; }
  .pub-drawer-search .pub-search { display: flex; max-width: 100%; }
  .pub-drawer-label {
    padding: 10px 16px 4px;
    font-size: 0.7rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--color-text-muted);
  }
}
