.dafa-search-modal-host { display: contents; }

/* Mobile keeps the original header; rail-only labels are progressive enhancement. */
.dafa-rail-tool-label,
.dafa-rail-login-icon,
.dafa-desktop-search-scope { display: none; }

/* Rail tools share the navigation's subtle hover feedback. */
@media (min-width: 1024px) {
  html[data-dafa-sidebar-tools] body { --dafa-header-height: 0px; }
  html[data-dafa-sidebar-tools] body .site-header {
    position: static;
    height: 0;
    min-height: 0;
    border: 0;
    padding: 0;
    background: transparent;
    box-shadow: none;
    transform: none;
  }
  html[data-dafa-sidebar-tools] .site-topbar { display: none; }
  html[data-dafa-sidebar-tools] .site-header .header-row { height: 0; min-height: 0; padding-block: 0; }
  html[data-dafa-sidebar-tools] .site-header .dafa-navigation-rail {
    top: var(--wp-admin--admin-bar--height, 0px);
    bottom: 0;
  }
  html[data-dafa-sidebar-tools] .dafa-navigation-rail .header-actions > .header-search {
    order: 0;
    flex: 0 0 auto;
    width: 100%;
    margin: 0;
  }
  html[data-dafa-sidebar-tools] .header-search__toggle {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    gap: 12px;
    border: 0;
    background: transparent;
    color: var(--dafa-text);
  }
  html[data-dafa-sidebar-tools] .header-search__toggle .dafa-desktop-search-label { font-size: 14px; font-weight: 500; line-height: 1.6; }
  html[data-dafa-sidebar-tools] .header-search__toggle .dafa-desktop-search-scope { display: inline; margin-left: auto; color: color-mix(in srgb, var(--dafa-text-soft) 60%, var(--dafa-surface)); font-size: 12px; font-weight: 400; line-height: 1.6; white-space: nowrap; }
  html[data-dafa-sidebar-tools] .header-search__toggle:hover { background: color-mix(in srgb, var(--dafa-text) 3%, var(--dafa-surface)); }
  html[data-dafa-sidebar-tools] .header-search__toggle svg { flex: 0 0 20px; }
  html[data-dafa-sidebar-tools] #site-navigation { padding-bottom: 12px; }
  html[data-dafa-sidebar-tools] .dafa-navigation-rail > .header-actions {
    flex: 0 0 auto;
    flex-direction: column;
    align-items: stretch;
    width: auto;
    gap: 4px;
    margin: 0 12px;
    padding: 12px 0 4px;
    border-top: 1px solid var(--dafa-border);
  }
  html[data-dafa-sidebar-tools] .header-actions > .header-auth-controls { order: -2; }
  html[data-dafa-sidebar-tools] .header-actions > .header-ai { order: -1; }
  html[data-dafa-sidebar-tools] .header-auth-controls > .header-user { order: -1; }
  html[data-dafa-sidebar-tools] .header-auth-controls { flex-direction: column; align-items: stretch; gap: 4px; }
  html[data-dafa-sidebar-tools] .header-auth-controls > :is(.header-user, .header-notice) { display: block; }
  html[data-dafa-sidebar-tools] .header-auth-controls:has(> .header-user) {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
    padding-bottom: 4px;
  }
  html[data-dafa-sidebar-tools] body .dafa-navigation-rail .header-actions > .header-ai,
  html[data-dafa-sidebar-tools] .header-auth-controls > .header-login-link,
  html[data-dafa-sidebar-tools] .header-auth-controls > .header-user > .header-user__toggle,
  html[data-dafa-sidebar-tools] .header-auth-controls > .header-notice > .header-notice__toggle {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex: 0 0 auto;
    width: 100%;
    height: 44px;
    min-height: 44px;
    padding: 10px 12px;
    gap: 12px;
    border: 0;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--dafa-text);
    background: transparent;
  }
  html[data-dafa-sidebar-tools] .header-actions > .header-ai svg,
  html[data-dafa-sidebar-tools] .dafa-rail-login-icon,
  html[data-dafa-sidebar-tools] .header-notice__toggle > svg { display: block; flex: 0 0 20px; width: 20px; height: 20px; }
  html[data-dafa-sidebar-tools] .header-auth-controls > .header-user > .header-user__toggle { width: 48px; height: 48px; min-height: 48px; padding: 4px; gap: 0; border-radius: 50%; }
  html[data-dafa-sidebar-tools] .header-user__toggle .header-user__avatar { flex: 0 0 40px; width: 40px; height: 40px; }
  html[data-dafa-sidebar-tools] .header-user__toggle > .dafa-rail-tool-label { display: none; }
  html[data-dafa-sidebar-tools].dafa-nav-collapsed .header-auth-controls > .header-user > .header-user__toggle { width: 100%; }
  html[data-dafa-sidebar-tools] .header-actions > .header-ai .dafa-ai-icon { margin: 0; }
  html[data-dafa-sidebar-tools] .dafa-rail-tool-label { display: inline; }
  html[data-dafa-sidebar-tools] .header-user__crown {
    left: 32px;
    right: auto;
    top: auto;
    bottom: 0;
    width: 16px;
    height: 16px;
    border: 1px solid var(--dafa-surface);
    border-radius: 50%;
    box-shadow: none;
  }
  html[data-dafa-sidebar-tools] .header-user__crown svg { width: 11px; height: 11px; }
  html[data-dafa-sidebar-tools] .header-auth-controls > .header-notice > .header-notice__toggle { width: 44px; height: 44px; min-height: 44px; justify-content: center; padding: 12px; gap: 0; }
  html[data-dafa-sidebar-tools] .header-notice__toggle > .dafa-rail-tool-label { display: none; }
  html[data-dafa-sidebar-tools].dafa-nav-collapsed .header-auth-controls:has(> .header-user) { flex-direction: column; align-items: stretch; gap: 4px; }
  html[data-dafa-sidebar-tools].dafa-nav-collapsed .header-auth-controls > .header-notice > .header-notice__toggle { width: 100%; }
  html[data-dafa-sidebar-tools].dafa-nav-collapsed .header-user__crown { left: calc(50% + 12px); }
  html[data-dafa-sidebar-tools] body .dafa-navigation-rail :is(.header-ai, .header-login-link, .header-user__toggle, .header-notice__toggle):hover {
    background: color-mix(in srgb, var(--dafa-text) 3%, var(--dafa-surface));
    color: var(--dafa-accent-strong);
  }
  html[data-dafa-sidebar-tools] .dafa-navigation-rail :is(button, a):focus-visible { outline: 2px solid var(--dafa-accent); outline-offset: -2px; }
  html[data-dafa-sidebar-tools] body .dafa-navigation-rail :is(.header-user__panel, .header-notice__panel) {
    position: fixed;
    top: auto !important;
    bottom: 12px;
    left: calc(var(--dafa-rail-width) + 8px) !important;
    right: auto !important;
    width: min(360px, calc(100vw - var(--dafa-rail-width) - 32px));
    max-height: calc(100dvh - var(--wp-admin--admin-bar--height, 0px) - 24px) !important;
  }
  html[data-dafa-sidebar-tools].dafa-nav-collapsed .header-search__toggle { justify-content: center; padding-inline: 0; }
  html[data-dafa-sidebar-tools].dafa-nav-collapsed .dafa-desktop-search-scope,
  html[data-dafa-sidebar-tools].dafa-nav-collapsed .dafa-desktop-search-label,
  html[data-dafa-sidebar-tools].dafa-nav-collapsed .dafa-rail-tool-label { display: none; }
  html[data-dafa-sidebar-tools].dafa-nav-collapsed body .dafa-navigation-rail .header-actions > .header-ai,
  html[data-dafa-sidebar-tools].dafa-nav-collapsed .header-auth-controls > .header-login-link,
  html[data-dafa-sidebar-tools].dafa-nav-collapsed .header-auth-controls > .header-user > .header-user__toggle,
  html[data-dafa-sidebar-tools].dafa-nav-collapsed .header-auth-controls > .header-notice > .header-notice__toggle {
    justify-content: center;
    gap: 0;
    padding-inline: 0;
    font-size: 0;
  }
}

/* Keep desktop controls reachable when the window has little vertical space. */
@media (min-width: 1024px) and (max-height: 560px) {
  html[data-dafa-sidebar-tools] .dafa-navigation-rail .site-branding { min-height: 64px; padding-block: 8px; }
  html[data-dafa-sidebar-tools] #site-navigation { padding-bottom: 4px; }
  html[data-dafa-sidebar-tools] .dafa-navigation-rail > .header-actions { gap: 0; padding-block: 8px 0; }
  html[data-dafa-sidebar-tools] .header-auth-controls:has(> .header-user) { margin-bottom: 0; padding-bottom: 0; }
  html[data-dafa-sidebar-tools].dafa-nav-collapsed .header-auth-controls:has(> .header-user) { gap: 0; }
  html[data-dafa-sidebar-tools] .dafa-navigation-rail > .dafa-rail-appearance { margin-bottom: 0; }
}
